[Olsr-dev] Broken TIME_DUE macro

Henning Rogge (spam-protected)
Wed Nov 18 08:13:03 CET 2009


After getting some sleep and reading your new mail, it seems that I was wrong 
yesterday... :(

On Tue November 17 2009 21:29:24 Jernej Kos wrote:
> On Tue, 2009-11-17 at 21:11 +0100, Henning Rogge wrote:
> > The old code is correct I think.
> >
> > olsr_cnf->system_tick_divider is the number of milliseconds per
> > clock tick
> 
> Well but as I understand it, the result of this expression:
> 
>   TIME_DUE(GET_TIMESTAMP(10000))
> 
> Should be 10000, right ? Since GET_TIMESTAMP returns a timestamp (in
> some abstract unit like clock ticks) 10000 msec in the future then
> TIME_DUE should return that there is exactly 10000 msec left until the
> timestamp is reached.
Yes it should.

> But the macro performs this computation wrongly and the result of this
> expression is quite different from 10000 - this can be seen simply by
> looking at the units of variables used in TIME_DUE expression:
> 
> s1                  [clock ticks = CT]
> now_times           [clock ticks = CT]
> system_tick_divider [ms/clock tick = ms/CT]
> 
> Now the resulting unit of this computation is undefined:
> 
>   (CT * ms/CT) - CT =
> = ms - CT = ???
> 
> So this macro is subtracting clock ticks from miliseconds. If we
> subtract before we multiply we actually get miliseconds as the resulting
> unit of TIME_DUE:
> 
>   (CT - CT) * ms/CT = ms
> 
> And this also gives the right result (number of miliseconds until the
> given timestamp - s1 - is reached). Either this or there is some
> fundamental flaw in my logic, if so please point it out :-)
Strange... fortunately the macro was only used in one place.

Can you maybe have a look at the new functions in src/scheduler.c that replace 
the old macros ? The new timer system just use internally a millisecond 
resolution time (not a clocktick one). The functions that replace the macros 
are olsr_getTimestamp(), olsr_getTimeDue() and olsr_getTimeDue().

Henning Rogge

-- 
Diplom-Informatiker Henning Rogge , Fraunhofer-Institut für
Kommunikation, Informationsverarbeitung und Ergonomie FKIE
Kommunikationssysteme (KOM)
Neuenahrer Straße 20, 53343 Wachtberg, Germany
Telefon +49 228 9435-263,   Fax +49 228 9435 685
mailto:(spam-protected) http://www.fkie.fraunhofer.de
GPG: E1C6 0914 490B 3909 D944 F80D 4487 C67C 55EC CFE0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.olsr.org/pipermail/olsr-dev/attachments/20091118/d3177b9b/attachment.sig>


More information about the Olsr-dev mailing list