public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: george anzinger <george@mvista.com>
To: Marcus Ramos <marcus@ansp.br>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: What is the precision of usleep ?
Date: Mon, 23 Apr 2001 09:20:29 -0700	[thread overview]
Message-ID: <3AE4564D.30141A58@mvista.com> (raw)
In-Reply-To: <3AE07A5A.C5BBE59C@ansp.br> <3AE2B6CC.1D1F8A10@mvista.com>

george anzinger wrote:
> 
> Marcus Ramos wrote:
> >
> > Hello,
> >
> > I am using usleep in an application under RH7 kernel 2.4.2. However,
> > when I bring its argument down to 20 miliseconds (20.000 microseconds)
> > or less, this seems to be ignored by the function (or the machine's hw
> > timer), which behaves as if 20 ms where its lowest acceptable value. How
> > can I measure the precision of usleep in my box ? I am currently using
> > an Dell GX110 PIII 866 MHz.
> >
> > Thanks in advance.
> > Marcus.
> 
> Well, first, your issue is resolution, not precision.  Current
> resolution on most all timers is 1/HZ.  So this should get a min.
> nanosleep of 10 ms.
> 
> So, could someone explain this line from sys_nanosleep() (
> kernel/timer.c):
> 
>         expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
> 
> It seems to me this should just be:
> 
>         expire = timespec_to_jiffies(&t)
> 
Oh darn!  Must NOT do posts at 4AM!  

The standard says nanosleep MUST wait at LEAST the requested time. 
Since we are dealing with a 1/HZ time resolution (tick) the actual time
waited MUST fall between 10 and 20 ms.  Depending on if your code is
synced to the system clock or not you may see times closer to one end of
this range.  If you are not synced to the clock the average wait should
be about 15 ms.  (Note, locking to the clock in some way is relatively
hard to get away from.  After all this is the same clock that is used
for time slicing.)

George

      reply	other threads:[~2001-04-23 16:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-20 18:05 What is the precision of usleep ? Marcus Ramos
2001-04-22 10:47 ` george anzinger
2001-04-23 16:20   ` george anzinger [this message]

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=3AE4564D.30141A58@mvista.com \
    --to=george@mvista.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcus@ansp.br \
    /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