Issue with gettimeofday() in RTEMS 4.10;

João Rasta freakforever at
Fri Jan 28 14:11:57 UTC 2011


I'm using gettimeofday() to profile a function. For this i do:

        struct timeval tim;
        // *Get actual clock
        gettimeofday(&tim, NULL);
        double t1=tim.tv_sec+(tim.tv_usec/1000000.0);

        // *GNC Calculations starting point
        // *Calculations termination point

        // *Calculate elapsed time with GNC calculations.
        gettimeofday(&tim, NULL);
        double t2=tim.tv_sec+(tim.tv_usec/1000000.0);

        procDelay = (t2 - t1 + 0.0275);
        if (t1 > t2)
            printf(" WARNING %f > %f\n",t1,t2);

But sometimes t1 is larger than t2, which should not be possible since t2 is
allways measured after t1. For instance, the above code produces the
following when this issue happens:

WARNING 567996584.559981 > 567996584.550001

The above code runs in loop and this happens roughly once in an hour (just
an estimate). Is there any known overflow issue with the usec counter that i
should be aware? RTEMS is running with a LEON-3.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the users mailing list