[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference helix::realtime

Title:Realtime Conference
Moderator:HELIX::LUNGER
Created:Mon Feb 24 1986
Last Modified:Mon Jun 02 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1241
Total number of notes:4452

1241.0. "clock_gettime" by CERN::GUGLIELMI () Tue May 06 1997 06:34

Hello,

we see a strange behavior of the routine clock_gettime(3). While doing
timing measurements on some ATM configuration, we decided to use 
clock_gettime instead of clock(3) to get more timing resolution. This is
the only difference between the versions, besides adding the -lrt option to
the compile command to include the library containing clock_gettime. The
results are very strange: they are from 2 to 3 times slower while using the
real-time environment. Is it possible to explain that?

I attach the code used for the measurements.

Regards,
Alberto Guglielmi.

 /*
 * timing-gettime.c, Kimmo Koski April 1997
 */

#include <stdio.h>
#include <assert.h>
#include <time.h>

#include "msg.h"
#include "timing.h"

long tsecs0, tsecs1;

/* start and stop timer */
void 
msg_timer_start(msg_clock_t *t)
{

  int ret;
  struct timespec tp;

  ret = clock_gettime(CLOCK_REALTIME, &tp);
  assert(ret != -1);

  *t = tp.tv_nsec;
  tsecs0  = tp.tv_sec;

}

void 
msg_timer_end(msg_clock_t *t)
{
  
  int ret;
  struct timespec tp;

  ret = clock_gettime(CLOCK_REALTIME, &tp);
  assert(ret != -1);

  *t = tp.tv_nsec;
  tsecs1  = tp.tv_sec;

}

/* report results */
void 
msg_timer_report(char *msg,
		 msg_clock_t *t0,
		 msg_clock_t *t1,
		 int count)
{

  double diff;

  diff = (double) ((tsecs1 - tsecs0) * 1000000000.0 + (*t1)) - (*t0);

  fprintf(stdout,"%d :: %s : Time = %f microseconds, count = %d "
	  "[measured by clock_gettime]\n",
	  process_id(),msg,diff/(1000*count),count); 
}


/*
 * $Id: timing-clock.c,v 1.2 1995/11/24 16:29:14 hauser Exp $
 */

#include <stdio.h>

#include "msg.h"
#include "timing.h"

/* start and stop timer */
void 
msg_timer_start(msg_clock_t *t)
{
  *t = clock();
}

void 
msg_timer_end(msg_clock_t *t)
{
  *t = clock();
}

/* report results */
void 
msg_timer_report(char *msg,
		 msg_clock_t *t0,
		 msg_clock_t *t1,
		 int count)
{
  double diff = (double )*t1 - (double )*t0;

  fprintf(stdout,"%d :: %s : Time = %f microseconds, count = %d "
	  "[measured by UNIX clock(3)]\n",
	  process_id(),msg,diff/count,count); 
}

T.RTitleUserPersonal
Name
DateLines
1241.1SMURF::DENHAMDigital UNIX KernelWed May 07 1997 11:265
    The clock() function is returning CPU time; the clock_gettime() retruns
    wall clock time. There's no necessary relationship there except, I
    susppose, that cpu time will never exceed wall time. Could this be
    the problem? You clearly have a measurement error, not a perfomance
    issue...
1241.2HELIX::SONTAKKEWed May 07 1997 13:058
    From the man pages:-
    
    "The clock() function returns the amount of processor time (in
    microseconds) used since the first call to clock()."
    
    This is little bit strange as it almost implies as if every call to
    clock() resets the amount of processor time.  Obviously, that can't be
    the case.