I’ve used the code below to record time stamps (based on time from boot,
not time of day) and measure change of time. It seems to work fine.
Alec
#include <sys/neutrino.h>
#include <sys/syspage.h>
#include <sys/time.h>
#include <time.h>
#include <inttypes.h>
#include <pthread.h>
#define TIMEVAL_TO_SEC(tv) ( (double)(tv.tv_sec) + (
(double)(tv.tv_usec) * 1E-6 ) )
long cycpersec=0;
long timepercycle=0;
/********************************************************************
- ivl_timer_mark():
- This function fills the abs_time variable with the absolute
- time since the CPU was powered (secs). This function must
- be called before the ivl_timer_reset and ivl_timer_elapsed
- function calls.
**********************************************************************/
void ivl_timer_mark(double *abs_time)
{
uint64_t count;
if( cycpersec == 0 )
{
cycpersec = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
timepercycle = (long int)(1.0/(double)cycpersec);
}
count = ClockCycles();
*abs_time = (double)count/(double)cycpersec;
return;
}
/*****************************************************************************
- ivl_timer_reset():
- This function returns the elapsed time since this function or
- ivl_timer_mark has been called (secs). It also fills the abs_time
- variable with the absolute time since the CPU was powered.
*****************************************************************************/
double ivl_timer_reset(double *abs_time)
{
double old_time;
old_time = *abs_time;
ivl_timer_mark(abs_time);
return (*abs_time - old_time);
}
/*****************************************************************************
*
- This function returns the elapsed time (secs) since ivl_timer_mark or
- ivl_timer_reset has been called. It does not reset the counter or
- change abs_time.
*****************************************************************************/
double ivl_timer_elapsed(double *abs_time)
{
double now;
ivl_timer_mark(&now);
return(now - *abs_time);
}
Sunil Kittur wrote:
Bill Caroselli wrote:
Bill Caroselli <> qtps@earthlink.net> > wrote:
BC > Colin Burgess <> cburgess@qnx.com> > wrote:
BC > CB > If you are just trying to get the difference between two
times, then use BC > CB > the SYSPAGE_ENTRY(qtime)->nsec field - this
obviates the need for a BC > CB > kernel call.BC > I’m not looking for the difference in two times.
BC > I want to record a time stamp.
BC > Is there a convienence function to convert from
SYSPAGE_ENTRY(qtime) to
BC > a struct timespec?BC > If not, can I assume that the conversion is simply
BC > boot_time * 1000000000000 + nsec ?OK, I see that it is NOT that simple.
Is there a function that will do this?
nsec2timespec() converts a 64-bit nsec value to a timespec.Do you need the timespec to be time-of-day, or just a
monotonically increasing stamp since system boot?Sunil.