Issue with gettimeofday() in RTEMS 4.10;

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


Hi,

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
        Execute_gnc();
        // *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);
        else
            printf("%f\n",procDelay);

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.


Best,
JM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20110128/598aedae/attachment.html>


More information about the users mailing list