From: Eric Dumazet <eric.dumazet@gmail.com>
To: Joakim Tjernlund <joakim.tjernlund@transmode.se>
Cc: Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org
Subject: Re: slow nanosleep?
Date: Wed, 08 Sep 2010 09:56:40 +0200 [thread overview]
Message-ID: <1283932600.2880.1.camel@edumazet-laptop> (raw)
In-Reply-To: <OF71DD00AE.26643E4D-ONC1257798.00250630-C1257798.002A9748@transmode.se>
Le mercredi 08 septembre 2010 à 09:45 +0200, Joakim Tjernlund a écrit :
> 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.
>
You need :
#define PR_SET_TIMERSLACK 29
prctl(PR_SET_TIMERSLACK, 1); /* 1 nsec resolution, please */
next prev parent reply other threads:[~2010-09-08 7:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-08 7:45 Joakim Tjernlund
2010-09-08 7:56 ` Eric Dumazet [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1283932600.2880.1.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=joakim.tjernlund@transmode.se \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®