sleep() API behaves different between 2.4 and 2.6

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I have a simple program utilizing "sleep()" api to sleep 3 msec periodically.
I measured the time difference before calling the api and after it returns back.
The same application behaves differently running on Linux 2.4 and 2.6
In Linux 2.6.11, it takes about 3 msec, and running on Linux 2.4.20 it takes about 10 msec.
I have attached the program below, many thanks in advance.
 
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
 
#define TO_64(a) (a##LLU)
 
#define kUsecTimeScale TO_64(1000000)
typedef unsigned long long UInt64;
typedef unsigned long long TSTimestamp;
/*UInt64 TSTimestamp;*/
TSTimestamp GetUsecTimestampFromTimeval(struct timeval* pTimeval) {
    return ((((UInt64)pTimeval->tv_sec) * (UInt64)kUsecTimeScale) + ((UInt64)pTimeval->tv_usec)); }
 
TSTimestamp GetUsecTimestamp(void)
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return GetUsecTimestampFromTimeval(&tv);
}
void test()
{
struct timeval tvsel;
tvsel.tv_sec = 0;
tvsel.tv_usec = 3000;
static int counter = 0;
TSTimestamp t1, t2, diff;
 
t1 = GetUsecTimestamp();
select(0,NULL, NULL, NULL, &tvsel);
t2 = GetUsecTimestamp();
 
diff  =  t2 - t1;

printf("time slept: %llu %llu %llu\n", t1, t2, diff);
}

main()
{
int s = 1000;
while (s--)
        test();
}
Thanks

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux