[Olsr-dev] olsr strange behaving / nearly no outgoing packets [partly solved]
Henning Rogge
(spam-protected)
Mon Aug 13 17:23:17 CEST 2012
Yes, it is...
and its definitely a compiler bug! You should file a bug report.
I do not like the volatile thing at all, because it prevents the
working compilers from optimizing the variables away.
Henning Rogge
On Mon, Aug 13, 2012 at 5:17 PM, Lars Kruse <(spam-protected)> wrote:
> Hi,
>
>> > Besides this approach I don't see any other options for further
>> > investigations. Or what would you say?
>>
>> Maybe we could just add a new variable and calculate the return value in
>> two steps. Most compilers should optimize the variable away anyways.
>>
>> uint32_t ms;
>>
>> ....
>>
>> t = (tv.tv_sec - first_tv.tv_sec) * 1000;
>> ms = (tv.tv_usec - first_tv.tv_usec) / 1000;
>>
>> return t + ms;
>> }
>>
>> Does this help ?
>
> Almost - but thanks for the hint!
>
>
> The following patch fixes it:
>
> --- olsrd-0.6.2.orig/src/scheduler.c 2012-08-13 14:59:43.000000000 +0200
> +++ olsrd-0.6.2/src/scheduler.c 2012-08-13 15:00:46.000000000 +0200
> @@ -87,7 +87,7 @@ static uint32_t
> olsr_times(void)
> {
> struct timeval tv;
> - uint32_t t;
> + volatile uint32_t t, ms;
>
> if (gettimeofday(&tv, NULL) != 0) {
> olsr_exit("OS clock is not working, have to shut down OLSR", 1);
> @@ -114,7 +114,9 @@ olsr_times(void)
> return t;
> }
> last_tv = tv;
> - return (tv.tv_sec - first_tv.tv_sec) * 1000 + (tv.tv_usec -
> first_tv.tv_usec) / 1000;
> + t = (tv.tv_sec - first_tv.tv_sec) * 1000;
> + ms = (tv.tv_usec - first_tv.tv_usec) / 1000;
> + return t + ms;
> }
>
> /**
>
>
>
> It seems that the "volatile" keyword prevents the compiler from doing evil
> things. This is ugly! :(
>
> cheers,
> Lars
>
> --
> Olsr-dev mailing list
> (spam-protected)
> https://lists.olsr.org/mailman/listinfo/olsr-dev
--
Steven Hawkings about cosmic inflation: "An increase of billions of
billions of percent in a tiny fraction of a second. Of course, that
was before the present government."
More information about the Olsr-dev
mailing list