public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Marek Lindner <lindner_marek@yahoo.de>
To: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n@open-mesh.net>
Subject: Re: [B.A.T.M.A.N.] times wrapper
Date: Fri, 1 May 2009 15:55:43 +0800	[thread overview]
Message-ID: <200905011556.00288.lindner_marek@yahoo.de> (raw)
In-Reply-To: <4313f3060904300843ra2f7a71o37f39780a797cfd2@mail.gmail.com>

Hi,

> When I switched to batman, I saw that times() is used in it as well,
> so I made the patch attached.  So, if anyone sees packets fail to come
> from batman for 40 seconds, they might need this.

excellent finding! I immediately applied your patch.

For the curious reader:
When you develop a daemon that should do certain things in intervals (e.g. 
sending packets, removing dead nodes from the routing table, etc) you will 
need a reference clock to know when this interval is over. Using the system 
time as reference is the obvious solution which theoretically offers what you 
need. 

As often, reality is much harder: time synchronisation approaches (e.g. NTP), 
manually changed system time, winter / summer time switches, timezones, etc 
might encourage the daemon to improvised reactions (e.g. sending the messages 
of the last 3 years because ntp just finished the time sync).

A more stable reference clock can be found by using the times() system call. 
It returns "the number of clock ticks that have elapsed since an arbitrary 
point in the past" (often the uptime). The compelling advantage: it always 
increments although it overflows from time to time. 

Batman uses the times() function which has a bug that this patch deals with. I 
had a short look in the olsr code (0.5.6-r4) to see how this bug is being 
handled there. main.c line 896 reveals a function called olsr_times()

--- SNIP -->
clock_t
olsr_times(void)
{
  struct tms tms_buf;
  return times(&tms_buf);
}
<-- SNAP ---

which is called from vairous places that don't deal with this bug:

scheduler.c line 117
--- SNIP -->
void
olsr_scheduler(void)
{
 [..]
  /* Main scheduler loop */
  for (;;) {

    /*
     * Update the global timestamp. We are using a non-wallclock timer here
     * to avoid any undesired side effects if the system clock changes.
     */
    now_times = olsr_times();

    [..]

    /* We are done, sleep until the next scheduling interval. */
    olsr_scheduler_sleep(olsr_times() - now_times);
<-- SNAP ---

Regards,
Marek


      parent reply	other threads:[~2009-05-01  7:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-30 15:43 [B.A.T.M.A.N.] times wrapper Nathan Wharton
2009-04-30 16:27 ` L. Aaron Kaplan
2009-05-01  7:55 ` Marek Lindner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200905011556.00288.lindner_marek@yahoo.de \
    --to=lindner_marek@yahoo.de \
    --cc=b.a.t.m.a.n@open-mesh.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox