gettimeofday(): Help please : SOURCES
sashti srinivasan
svasn_rtems at yahoo.com
Fri Mar 5 13:04:08 UTC 2004
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 youre looking for faster
http://search.yahoo.com
More information about the users
mailing list