All of lore.kernel.org
 help / color / mirror / Atom feed
* slow nanosleep?
@ 2010-09-08  7:45 Joakim Tjernlund
  2010-09-08  7:56 ` Eric Dumazet
  0 siblings, 1 reply; 17+ messages in thread
From: Joakim Tjernlund @ 2010-09-08  7:45 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel


Hi Thomas

while playing with nanosleep I noticed that it is slow
compared to select. This little test program shows what
the effect:
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#define NANO_SLEEP 1
main()
{
	struct timespec req, rem;
	struct timeval tv1, tv2, tv_res;
	int res;

	rem.tv_sec = 0;
	rem.tv_nsec = 0;

	req.tv_sec = 0;
	req.tv_nsec = 0;

	tv2.tv_sec = req.tv_sec;
	tv2.tv_usec = req.tv_nsec/1000;

	gettimeofday(&tv1, NULL);
#ifdef NANO_SLEEP
	res = nanosleep(&req, &rem);
#else
	res = select(0, NULL,NULL,NULL, &tv2);
#endif
	gettimeofday(&tv2, NULL);
	timersub(&tv2, &tv1, &tv_res);
#ifdef NANO_SLEEP
	printf("nanosleep\n");
#else
	printf("selectsleep\n");
#endif
	printf("req:%d :%d\n", (int)req.tv_sec, (int)req.tv_nsec/1000);
	printf("tv_res:%d :%d\n", (int)tv_res.tv_sec, (int)tv_res.tv_usec);
}
root@localhost ~ # ./nanosleep
nanosleep
req:0 :0
tv_res:0 :119
root@localhost ~ # ./selectsleep
selectsleep
req:0 :0
tv_res:0 :36


Isn't nanosleep to slow here? The min time is about 120 us compared
to select which is 36 us. I would expect nanosleep to be better than
select.

Kernel 2.6.35 with HIGH_RES timers on Powerpc(MPC8321, 266 MHz)
x86 shows the same effect.

    Jocke


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-09-08 14:38 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-08  7:45 slow nanosleep? Joakim Tjernlund
2010-09-08  7:56 ` Eric Dumazet
2010-09-08  8:04   ` Joakim Tjernlund
2010-09-08  8:24     ` Eric Dumazet
2010-09-08  9:12       ` Joakim Tjernlund
2010-09-08  9:51         ` Thomas Gleixner
2010-09-08 10:14           ` Eric Dumazet
2010-09-08 10:17             ` Thomas Gleixner
2010-09-08 12:11           ` Joakim Tjernlund
2010-09-08 12:43             ` Thomas Gleixner
2010-09-08 13:00               ` Peter Zijlstra
2010-09-08 13:44                 ` Joakim Tjernlund
2010-09-08 13:51                   ` Peter Zijlstra
2010-09-08 13:52                   ` Thomas Gleixner
2010-09-08 14:19                     ` Joakim Tjernlund
2010-09-08 14:30                       ` Thomas Gleixner
2010-09-08 14:33                         ` Joakim Tjernlund

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.