gettimeofday(): Help please : SOURCES

Joel Sherrill <joel@OARcorp.com> joel.sherrill at OARcorp.com
Fri Mar 5 14:28:55 UTC 2004


I have attached my version of the program with my own DoTest().
It compiles without warning and seems to report times
accurately.

FWIW the accuracy of the RTEMS timeofday is configurable
in number of microseconds.  It defaults to 10 milliseconds.
CONFIGURE_MICROSECONDS_PER_TICK is the macro.  When you
do a gettimeofday() it only looks at whole clock ticks and
does not touch the HW to determine any partial clock tick
amounts.

sashti srinivasan wrote:
> Hello,
> 
>    I approached the list with following problems:
> (1) "raw handler connexion failed" in pc386.(found to
> be because of usage of functions Timer_initialize(),
> Read_timer())
> (2) gettimeofday() returning constant value.
>    Please help me in getting them solved.  The
> relevant source code is as below.
> 
>   My main file is this.  This is intented to be used
> in both linux and rtems.  I think, I have more problem
> in the next file I used for time measurements.  Help
> me in getting the problems solved.
> 
> -------------------------------------------------------------
> /* Posix performance measurement suite
>  * S Srinivasan CS02M040, iitm
>  */
> #include <stdio.h>
> 
> #define FORCE_TIMEOFDAY
> #define FOR_RTEMS
> 
> /*
>  * The Declaration of main routine depends
>  * on the platform
>  */
> #ifdef FOR_RTEMS
> void * RtemsMain(void *arg)
> #else
> #ifdef FOR_UCLINUX
> int MainUclinux()
> #else
> int main(int argc, char **argv)
> #endif
> #endif
> {
>    DoTests();
>    exit(0);
> }
> 
> 
> 
> #ifdef FOR_RTEMS
> #include <bsp.h>
> 
> #define CONFIGURE_POSIX_INIT_THREAD_TABLE
> #define CONFIGURE_POSIX_INIT_THREAD_ENTRY_POINT 
> 
> (void*)RtemsMain
> 
> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
> 
> #define CONFIGURE_MAXIMUM_POSIX_THREADS 110
> #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 110
> #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 110
> #define CONFIGURE_MAXIMUM_TASKS 120
> 
> #define CONFIGURE_INIT
> 
> #include <confdefs.h>
> #endif
> --------------------------------------------------------------
> 
> The following is the file I use for timing
> measurement.  I use three functions.  StartWatch(),
> StopWatch(), ReadWatch().  The first and third are
> similar to Timer_initialize() and Read_timer() (used
> in tmtests) respectively.
> --------------------------------------------------------------
> 
> /* Routines used for time measurement *
>  * CS02M040 S Srinivasan IIT(M)       */
> 
> #define FORCE_TIMEOFDAY
> #define FOR_RTEMS
> 
> typedef struct
> {
>         struct timeval atStart;
>         struct timeval atStop;
>         struct timezone notUsed;
>         int watchRunning;
>         long currentTime;
>         char reportText[500][100];
>         int reportLocation;
> }SupportData;
> SupportData sd;
> 
> long TimeDifference(struct timeval tStart, struct
> timeval tEnd)
> {
> #ifndef FORCE_TIMEOFDAY
> #ifndef FOR_RTEMS
>         long seconds,microseconds;
>         seconds=tEnd.tv_sec-tStart.tv_sec;
>         microseconds=tEnd.tv_usec-tStart.tv_usec;
>         microseconds=microseconds+seconds*1000000;
>         return microseconds;
> #else
>         return sd.currentTime;
> #endif
> #else
>         long seconds,microseconds;
>         seconds=tEnd.tv_sec-tStart.tv_sec;
>         microseconds=tEnd.tv_usec-tStart.tv_usec;
>         microseconds=microseconds+seconds*1000000;
>         return microseconds;
> #endif
> }
> 
> void StartWatch()
> {
>         sd.watchRunning=1;
> #ifndef FORCE_TIMEOFDAY
> #ifndef FOR_RTEMS
>         gettimeofday(&sd.atStart,&sd.notUsed);
> #else
>         Timer_initialize();
> #endif
> #else
>         gettimeofday(&sd.atStart,&sd.notUsed);
> #endif
> }
> 
> void StopWatch()
> {
> #ifndef FORCE_TIMEOFDAY
> #ifndef FOR_RTEMS
>         gettimeofday(&sd.atStop,&sd.notUsed);
> #else
>         sd.currentTime=Read_timer();
> #endif
> #else
>         gettimeofday(&sd.atStop,&sd.notUsed);
> #endif
>         sd.watchRunning=0;
> }
> 
> long ReadWatch()
> {
>         if(sd.watchRunning==0)
>                 
> 
> sd.currentTime=TimeDifference(sd.atStart,sd.atStop);
>         else
>                 sd.currentTime=-1;
>         return sd.currentTime;
> }
> ------------------------------------------------------
> With Regards
> Srinivasan
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Search - Find what you’re looking for faster
> http://search.yahoo.com


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
    Support Available             (256) 722-9985

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.c
URL: <http://lists.rtems.org/pipermail/users/attachments/20040305/3742223d/attachment-0001.c>


More information about the users mailing list