mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: Roman Zippel <zippel@linux-m68k.org>,
	Bart Van Assche <bart.vanassche@gmail.com>,
	Michael Kerrisk <mtk.manpages@gmail.com>,
	lkml <linux-kernel@vger.kernel.org>,
	john stultz <johnstul@us.ibm.com>, Ingo Molnar <mingo@elte.hu>
Subject: Re: nanosleep() uses CLOCK_MONOTONIC, should be CLOCK_REALTIME?
Date: Wed, 25 Jun 2008 08:13:57 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.1.10.0806250809030.3297@apollo.tec.linutronix.de> (raw)
In-Reply-To: <cfd18e0f0806232239w78546747p8fb899f614c89496@mail.gmail.com>

On Tue, 24 Jun 2008, Michael Kerrisk wrote:
> > If you check the man page for clock_settime, it specifically
> > mentions that pending relative timer (including nanosleep) aren't affected
> > by the changed time, thus if CLOCK_MONOTONIC and CLOCK_REALTIME advance
> > equally, it doesn't matter which you use for relative timer.
> 
> Well, I was going to say that that's just a man page, and man page
> authors are fallible ;-).  But then I went and had a look at the POSIX
> spec for clock_settime().  It includes the following paragraph:
> 
>        Setting the value of the CLOCK_REALTIME  clock  via  clock_set-
>        time() shall have no effect on threads that are blocked waiting
>        for a relative time service based upon  this  clock,  including
>        the  nanosleep()  function;  nor  on the expiration of relative
>        timers  based  upon  this  clock.   Consequently,  these   time
>        services  shall  expire  when  the  requested relative interval
>        elapses, independently of the new or old value of the clock.
> 
> So that rather flatly contradicts the alternative semantics that I
> suggested were possible in my reply to Bart a few minutes ago.
> 
> So in my reading of things now, it looks as though the Linux
> implementation is probably fine, since the fact that relative
> timers/sleeps are explicitly unaffected by jumps in CLOCK_REALTIME
> means that the semantics are effectively the same as if the relative
> interval was measured against CLOCK_MONOTONIC (unless the two clocks
> counted time at different rates; not sure if that  would be possible
> in theory, but certainly seems very unlikely in practice).

We use CLOCK_MONOTONIC for the relative timeouts simply to avoid
trickery vs. clock_settime(CLOCK_REALTIME). That's an kernel internal
implementation detail which does not have any visible effect to the
user space interface.

CLOCK_MONOTONIC and CLOCK_REALTIME are using the same timebase
internally and therefor we can safely use CLOCK_MONOTONIC for the
relative timeouts.

Thanks,

	tglx

  parent reply	other threads:[~2008-06-25  6:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-22  7:35 Michael Kerrisk
2008-06-23  8:34 ` Bart Van Assche
2008-06-23  9:48   ` Michael Kerrisk
2008-06-23 11:56     ` Bart Van Assche
2008-06-24  5:08       ` Michael Kerrisk
2008-06-24  5:18       ` Michael Kerrisk
2008-06-23 12:43     ` Roman Zippel
2008-06-24  5:39       ` Michael Kerrisk
2008-06-24  8:01         ` Bart Van Assche
2008-06-24  8:27           ` Michael Kerrisk
2008-06-24  9:27             ` Bart Van Assche
2008-06-24  9:31               ` Michael Kerrisk
2008-06-25  6:13         ` Thomas Gleixner [this message]
2008-06-25  6:16           ` Michael Kerrisk

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=alpine.LFD.1.10.0806250809030.3297@apollo.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=bart.vanassche@gmail.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mtk.manpages@gmail.com \
    --cc=mtk.manpages@googlemail.com \
    --cc=zippel@linux-m68k.org \
    /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

Powered by JetHome