Strange results with changing HZ

Wojciech Kromer wojciech.kromer at dgt.com.pl
Mon Nov 21 18:44:15 EST 2005


My system is:
 - 2.4.25 kernel from denx.de
 - uclibc (gcc 3.4.2) + busybox
 - changed HZ to 1000
 - rebuild kernel only

AFAIR there souldn't be any need to recompile user apps.

I have strange results.
Sleep and timeout selects works fine, but alarm functions seems to be 
too fast.
For example included program or ping waits too short.



it is OK:

# time alarm_test
alarm fired after 0.099166s
real    0m 0.11s
user    0m 0.00s
sys     0m 0.00s
#
# time sleep 1
real    0m 1.01s
user    0m 0.00s
sys     0m 0.00s
# time sleep 10
real    0m 10.01s
user    0m 0.00s
sys     0m 0.00s


but:

# alarm_test
alarm fired after 0.099709s
# alarm_test
alarm fired after 0.099710s


------------------------------------ alarm_test.c :

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>

static void sighand(int sig)
{
}

int main()
{
 struct timeval tv1, tv2;
 sigset_t set;

 sigfillset(&set);
 sigdelset(&set, SIGALRM);
 sigdelset(&set, SIGINT);

 signal(SIGALRM, sighand);
 gettimeofday(&tv1, NULL);

 alarm(1);
 sigsuspend(&set);
 gettimeofday(&tv2, NULL);

 tv1.tv_sec = tv2.tv_sec - tv1.tv_sec - (tv2.tv_usec < tv1.tv_usec);
 tv1.tv_usec = tv2.tv_usec - tv1.tv_usec + (tv2.tv_usec < tv1.tv_usec) * 
1000000;

 printf("alarm fired after %ld.%06lds\n",
 tv1.tv_sec, tv1.tv_usec);

 return 0;
}





More information about the Linuxppc-embedded mailing list