lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <cfd18e0f0806232208o1a7545a6kb6859584ba1c0586@mail.gmail.com>
Date:	Tue, 24 Jun 2008 07:08:36 +0200
From:	"Michael Kerrisk" <mtk.manpages@...glemail.com>
To:	"Bart Van Assche" <bart.vanassche@...il.com>
Cc:	"Michael Kerrisk" <mtk.manpages@...il.com>,
	lkml <linux-kernel@...r.kernel.org>,
	"Thomas Gleixner" <tglx@...utronix.de>,
	"john stultz" <johnstul@...ibm.com>, "Ingo Molnar" <mingo@...e.hu>,
	"Roman Zippel" <zippel@...ux-m68k.org>
Subject: Re: nanosleep() uses CLOCK_MONOTONIC, should be CLOCK_REALTIME?

On Mon, Jun 23, 2008 at 1:56 PM, Bart Van Assche
<bart.vanassche@...il.com> wrote:
> On Mon, Jun 23, 2008 at 11:48 AM, Michael Kerrisk
> <mtk.manpages@...glemail.com> wrote:
>> On Mon, Jun 23, 2008 at 10:34 AM, Bart Van Assche
>> <bart.vanassche@...il.com> wrote:
>>> On Sun, Jun 22, 2008 at 9:35 AM, Michael Kerrisk <mtk.manpages@...il.com> wrote:
>>>> The POSIX.1 specification of nanosleep() says:
>>>>
>>>>       But, except for the case of being interrupted by a signal, the
>>>>       suspension time shall not be less than the time  specified  by
>>>>       rqtp, as measured by the system clock CLOCK_REALTIME.
>>>>
>>>>
>>>> However, reading kernel/hrtimer.c:sys_nanosleep(), it appears that
>>>> CLOCK_MONOTONIC is used.
>>>>
>>>>    return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
>>>>
>>>> Is there a reason to use CLOCK_MONOTONIC, instead of CLOCK_REALTIME?  Is it
>>>> intentional?  If yes, then I should document this in the man-pages.  If not,
>>>> then it should be fixed.
>>>
>>> CLOCK_MONOTONIC works fine even if ntpd steps the clock forward or
>>> backward, CLOCK_REALTIME not. So the man page should be fixed.
>>
>> Thanks for your reply, but I'm not quite convinced yet.  The things
>> is: the Solaris man page also says "CLOCK_REALTIME".  (Of course that
>> man page may just be parroting the standard.)  Could there not be some
>> reasonable semantics for a nanosleep() that was based on
>> CLOCK_REALTIME?
>
> Sorry, but I don't think that a nanosleep() based on CLOCK_REALTIME
> would have reasonable semantics. The first line of the description in
> nanosleep()'s manpage says:
> "nanosleep()  delays  the  execution  of  the program for at least the
> time specified in *req". So you really need CLOCK_MONOTONIC and not
> CLOCK_REALTIME.

I don't think it's sufficient to quote the man page here ;-).  That
sentence is really just an abridged version of the sentence that I
quoted from the spec at the start of this thread:

#       But, except for the case of being interrupted by a signal, the
#       suspension time shall not be less than the time  specified  by
#       rqtp, as measured by the system clock CLOCK_REALTIME.

I assume that the author of the man page simply neglected to mention
which clock the syscall measures by.

> The reason why CLOCK_REALTIME is mentioned is probably because other
> POSIX man pages define three types of clocks: real, virtual and
> profiiling. See e.g. the getitimer() man page
> (http://www.opengroup.org/onlinepubs/009695399/functions/setitimer.html).
> And an overview of all clock types defined by POSIX can be found here:
> http://www.opengroup.org/onlinepubs/000095399/functions/clock_getres.html.

I don't *think* this really provides a rationale for why POSIX talks
of CLOCK_REALTIME rather than CLOCK_MONOTONIC when specifying
nanosleep().


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ