NPTL, linuxthreads, and timers
From: Stéphane SARAGAGLIA (saragagliaREMOVEIT_at_ifrance.com)
Date: 12/29/04
- Previous message: Jonathan Bartlett: "Re: glibc's malloc: arenas and memory fragmentation?"
- Next in thread: Sebastien Decugis: "Re: NPTL, linuxthreads, and timers"
- Reply: Sebastien Decugis: "Re: NPTL, linuxthreads, and timers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Dec 2004 17:47:02 +0100
Hi all,
By testing accuracy of timers, I am using a piece of code wich prints
the time when a timer signal is received :
-------------------------- SOURCE BEGIN -----------------------
#define POSIX_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
static volatile sig_atomic_t timer_tick = 0;
void sigalarm(int signo)
{
struct timeval time0;
struct tm *ma_date;
gettimeofday(&time0, NULL);
ma_date = localtime( &time0.tv_sec );
printf("%02d:%02d:%02d.%03d ",
ma_date->tm_hour, ma_date->tm_min, ma_date->tm_sec,
(unsigned)(time0.tv_usec/1000));
}
int main(int argc, char *argv[])
{
clock_t clock = CLOCK_REALTIME;
int signum = SIGRTMAX;
int microsec = 100000;usec
int status;
struct timeval time0, time1;
double dt;
timer_t timer_id;
struct itimerspec ts;
struct sigevent se;
struct sigaction act;
sigset_t sigmask;
/* Command-line arguments: */
if (argc >= 2) microsec = atol(argv[1]);
/* Set up signal handler: */
sigfillset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = sigalarm;
sigaction(signum, &act, NULL);
/* Set up timer: */
memset(&se, 0, sizeof(se));
se.sigev_notify = SIGEV_SIGNAL;
se.sigev_signo = signum;
se.sigev_value.sival_int = 0;
if (timer_create(clock, &se, &timer_id) < 0) {
perror("timer_create");
return EXIT_FAILURE;
}
/* Start timer: */
ts.it_interval.tv_sec = microsec / 1000000;
ts.it_interval.tv_nsec = (microsec % 1000000) * 1000;
ts.it_value = ts.it_interval;
if (timer_settime(timer_id, 0, &ts, NULL) < 0) {
perror("timer_settime");
return EXIT_FAILURE;
}
while (1){
sleep(10);
}
timer_delete(timer_id);
return EXIT_SUCCESS;
}
-------------------------- SOURCE END -----------------------
When linuxthreads is selected with (setenv LD_ASSUME_KERNEL 2.4.27), the
display I obtain is (DISPLAY1) :
-------------------------- DISPLAY1 BEGIN -----------------------
date :17:25:10.662
date :17:25:10.762
date :17:25:10.863
date :17:25:10.963
date :17:25:11.063
date :17:25:11.163
date :17:25:11.263
date :17:25:11.363
date :17:25:11.462
date :17:25:11.562
-------------------------- DISPLAY1 END -----------------------
When NPTL is selected with (setenv LD_ASSUME_KERNEL "" (default)), the
display I obtain is (DISPLAY2) :
-------------------------- DISPLAY2 BEGIN -----------------------
date :17:28:14.203
date :17:28:14.304
date :17:28:14.405
date :17:28:14.506
date :17:28:14.607
date :17:28:14.708
date :17:28:14.809
date :17:28:14.910
date :17:28:15.011
date :17:28:15.112
-------------------------- DISPLAY2 END -----------------------
I would like to use NPTL, but the results displayed by DISPLAY2 are
alarming me... At first sight, we can see it seems there is a
cummulative time error.
Could someone tell me more about this ? Is there a error in the source ?
Is there a problem on librt.so library ?
Regards
- Previous message: Jonathan Bartlett: "Re: glibc's malloc: arenas and memory fragmentation?"
- Next in thread: Sebastien Decugis: "Re: NPTL, linuxthreads, and timers"
- Reply: Sebastien Decugis: "Re: NPTL, linuxthreads, and timers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|