[Olsr-dev] Broken TIME_DUE macro

Jernej Kos (spam-protected)
Tue Nov 17 21:29:24 CET 2009


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.

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 :-)

Best regards,
Jernej Kos.
-- 
Jernej Kos <(spam-protected)>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.olsr.org/pipermail/olsr-dev/attachments/20091117/01c0bc03/attachment.sig>


More information about the Olsr-dev mailing list