nanosleep
hrm - im confiused now - how can you do a n NANO second delay when the resolution is 10 mili seconds ?
forgive my ignorance and my persistant "stupid" questions :)
----- Original Message -----
From: "H. Peter Anvin" <[email protected]>
Date: 9 Apr 2002 22:47:42 -0700
To: [email protected]
Subject: Re: nanosleep
Quoted 43 lines
Followup to: <[email protected]> By author: "mark manning" <[email protected]> In newsgroup: linux.dev.kernelQuoted 8 lines
thanx - how much of a difference should i expect - i know the syscall is asking for at least the required ammount but that the task switcher might not give me control back for a while after the requested delay but i was expecting to be a little closer to what i had asked for - this isnt critical of corse but i would like to know what to expect.
Read the man page:
BUGS
The current implementation of nanosleep is based on the normal kernel timer mechanism, which has a resolution of 1/HZ s (i.e, 10 ms on Linux/i386 and 1 ms on Linux/Alpha). Therefore, nanosleep pauses always for at least the speci fied time, however it can take up to 10 ms longer than specified until the process becomes runnable again. For the same reason, the value returned in case of a delivered signal in *rem is usually rounded to the next larger mul tiple of 1/HZ s.As some applications require much more precise pauses (e.g., in order to control some time-critical hardware), nanosleep is also capable of short high-precision pauses. If the process is scheduled under a real-time policy like
SCHED_FIFOorSCHED_RR, then pauses of up to 2 ms will be performed as busy waits with microsecond precision.-hpa
Signature · 8 lines
<[email protected]> at work, <[email protected]> in private! "Unix gives you enough rope to shoot yourself in the foot." http://www.zytor.com/~hpa/puzzle.txt <[email protected]> - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Signature · 4 lines
_______________________________________________ Get your free email from http://www.fastermail.com Powered by Outblaze
Quoted 2 lines · mark manning
hrm - im confiused now - how can you do a n NANO second delay when the resolution is 10 mili seconds ?
Uh, you can't - that was his point.
You can try, and you will certainly sleep at least that long, but any time given modulo 10ms is out the door ...
Like I said, check out the high resolution timers project.
Robert Love
Quoted 5 lines · Robert Love
Quoted 2 lines · mark manning
hrm - im confiused now - how can you do a n NANO second delay when the resolution is 10 mili seconds ?
Uh, you can't - that was his point.
Well there is a cheap trick if you catch what the man page says.
Quoted 2 lines
You can try, and you will certainly sleep at least that long, but any time given modulo 10ms is out the door ...
Make all your calls to nanasleep be less than 2ms, and loop through as many as you need until you are under 2ms.
Don't do it for too long because you get no other use out of your machine while your doing this but it does work.
Followup to: <[email protected]> By author: andrew may <[email protected]> In newsgroup: linux.dev.kernel
Quoted 7 lines
Make all your calls to nanasleep be less than 2ms, and loop through as many as you need until you are under 2ms.
Don't do it for too long because you get no other use out of your machine while your doing this but it does work.
If you want to busy-wait, you might as well do it in userspace (use RDTSC.)
Maybe a future version of the kernel will have more flexible scheduling.
-hpa
Signature · 3 lines
<[email protected]> at work, <[email protected]> in private! "Unix gives you enough rope to shoot yourself in the foot." http://www.zytor.com/~hpa/puzzle.txt <[email protected]>