Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Feb 2008 10:39:59 +0100
From:      "Heiko Wundram (Beenic)" <wundram@beenic.net>
To:        freebsd-hackers@freebsd.org
Subject:   Re: usleep
Message-ID:  <200802251039.59767.wundram@beenic.net>
In-Reply-To: <200802251440.56435.sharadc@in.niksun.com>
References:  <200802221558.42443.sharadc@in.niksun.com> <200802221437.48293.wundram@beenic.net> <200802251440.56435.sharadc@in.niksun.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Am Montag, 25. Februar 2008 10:10:56 schrieb Sharad Chandra:
> So does it mean, freebsd has limitation. sleeping will only work for its
> value more than 1 milli sec because % of +- error value is comparitivly
> low? I am curious to know, is there any method which sleeps for few
> microseconds. Some one please give me link where to look for "select".

No, this does not mean that FreeBSD has a limitation, but rather that FreeBSD 
is not a real-time operating system. You'll see the similar behaviour on 
pretty much any other operating system that is _not_ a RTOS (for example, 
Windows has a fixed resolution of non-Multimedia-Timers of around 10ms [where 
Multimedia Timers are a specific interface to sleep with a higher resolution, 
designed for Multimedia applications, but the resolution isn't that much 
higher, anyway], and on Linux, it also depends on the Tick-Frequency, similar 
to FreeBSD's HZ setting, but actually I don't know how the tickless 
Linux-kernel [which is implemented only in the latest versions, and not 
default anyway] behaves here).

There is no way (AFAIK) for a userland application to _sleep_ for a finer 
grained amount of time than a timeslice, except in a busy loop which calls 
gettimeofday or similar repeatedly to break when the "timeout" occurs, but 
even then you don't have a guarantee that you won't sleep longer, simply 
because the process might be preempted just before the timeout occurs because 
another process also wants its timeslice.

But, more specifically, why do you need to sleep for a short time in a user 
process anyway? Normally, you're blocking on some form of condition, which 
will "wake you up" as soon as the condition triggers and you can be scheduled 
(and in this "active scheduling" case the time-slice "rule" doesn't apply).

If you give some more info on what you're trying to do (and why you need such 
a high resolution sleep), maybe someone will be able to help you better and 
show you how to achieve what you're trying to do without blocking on a 
timeout.

-- 
Heiko Wundram
Product & Application Development



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802251039.59767.wundram>