[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <OF5074952F.1B97B2B8-ONC1257798.002C51D7-C1257798.002C63A4@transmode.se>
Date: Wed, 8 Sep 2010 10:04:50 +0200
From: Joakim Tjernlund <joakim.tjernlund@...nsmode.se>
To: Eric Dumazet <eric.dumazet@...il.com>
Cc: linux-kernel@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>
Subject: Re: slow nanosleep?
Eric Dumazet <eric.dumazet@...il.com> wrote on 2010/09/08 09:56:40:
>
> 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@...alhost ~ # ./nanosleep
> > nanosleep
> > req:0 :0
> > tv_res:0 :119
> > root@...alhost ~ # ./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 */
That makes litte difference:
root@...alhost ~ # ./nanosleep
nanosleep
req:0 :0
tv_res:0 :112
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists