Hi Lorenzo,

On Tue, Mar 07, 2017 at 03:01:11PM +0100, Lorenzo Ghiro wrote:
> I would like to know how to schedule an operation (write to file) with
> below-second frequency, any advise?
>
> (snip)
>
> However, running a Babel instance on my laptop, I notice that the main loop
> is performed with a strange frequency...sometimes approx 1Hz sometimes
> slower. Consequently, if I perform a check of how many microseconds are
> passed from the last loop iteration I miss the below-second deadline that I
> desire.
> 
> The main loop frequency that I notice is standard or anomalous?

This is the expected behaviour.  The main loop is not a busy-loop, it
blocks on the select() call in line 636.

If you look at the code, there are two ways the call to select() will
return:

- one socket has data to read (peer socket, kernel socket, local socket)
- the timer "tv" expires

This timer "tv" is computed as the minimum of various timeouts for
recurrent tasks performed by babeld.  This is done by the code before the
select() call.  Given all this, it is no surprise that the time interval
you see between two iterations of the main loop looks strange.

The cleanest way I see would be to use timerfd, as Toke suggested, and
integrate that in the list of file descriptors watched by select().  As a
perhaps simpler alternative, you could also integrate your recurrent task
in "tv" (i.e. set "tv" to be the minimum of "tv" and the time at which you
want your task to be run next).

Baptiste

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Babel-users mailing list
Babel-users@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/babel-users

Reply via email to