linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Christoph Hellwig <hch@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"H.J. Lu" <hjl.tools@gmail.com>, Ingo Molnar <mingo@elte.hu>,
	Thomas Gleixner <tglx@linutronix.de>,
	Richard Kuo <rkuo@codeaurora.org>,
	Mark Salter <msalter@redhat.com>, Jonas Bonn <jonas@southpole.se>,
	Tobias Klauser <tklauser@distanz.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"H.J. Lu" <hjl.tools@gmail.com>
Subject: 64-bit time on 32-bit systems
Date: Wed, 08 Feb 2012 13:36:24 -0800	[thread overview]
Message-ID: <4F32EAD8.6020504@zytor.com> (raw)
In-Reply-To: <CA+55aFzEnGb3G2WeVNoS5e2D4poY5O6gJucnVnFRF51NUYkW8A@mail.gmail.com>

Resuming a long-stuck discussion...

On 08/31/2011 10:19 AM, Linus Torvalds wrote:
> On Wed, Aug 31, 2011 at 10:09 AM, H. Peter Anvin <hpa@zytor.com> wrote:
>>>
>>> I suspect only sane solution to this (having thought about it some
>>> more) is to just say "POSIX is f*^&ing wrong".
>>
>> Urk.  Someone had the bright idea of defining tv_nsec as "long" in the
>> standard, whereas tv_usec is suseconds_t.  F**** brilliant, and more
>> than a little bit stupid.
> 
> I think tv_nsec was just overlooked, and people thought "it has no
> legacy users that were 'int', so we'll just leave it at 'long', which
> is guaranteed to be enough for nanoseconds that only needs a range of
> 32 bits".
> 
> In contrast, tv_usec probably *does* have legacy users that are "int".
> 
> So POSIX almost certainly only looked backwards, and never thought
> about users who would need to make it "long long" for compatibility
> reasons.
> 
> The fact that *every*other*related*field* in POSIX/SuS has a typedef
> exactly for these kinds of reasons just shows how stupid that "long
> tv_nsec" thing is.
> 
> I suspect that on Linux we can just say "tv_nsec" is suseconds_t too.
> Then we can make time_t and suseconds_t just match, and be "__s64" on
> all new platforms.
> 

So I somewhat accidentally stumbled onto what appears to the the reason
for this while cleaning up posix_types.h last night.

The problem at hand seems to be that suseconds_t is 32 bits on SPARC64.
 This appears to be the case in both Linux and Solaris, which is
probably why struct timespec has "long" instead of suseconds_t (Sun
always have been prominent on the POSIX committee.)

As such, I don't think we can redefine struct timespec to have
suseconds_t for the nanosecond field, even on Linux.  We could define
snseconds_t, or we would have to do something really ugly like define a
padding field when on a 32-bit platform (which the kernel would then
have to ignore when reading from userspace by truncating the 64-bit
value rather than signaling an error if the upper 32 bits are set.)

snseconds_t seems semi-reasonable to me... I guess we'd have to push
that at the POSIX people.  Fortunately it shouldn't break anything to
have it be a wider type than is otherwise necessary.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


  parent reply	other threads:[~2012-02-08 21:37 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26 23:00 RFD: x32 ABI system call numbers H. Peter Anvin
2011-08-26 23:13 ` Linus Torvalds
2011-08-26 23:39   ` H. Peter Anvin
2011-08-27  0:36     ` Linus Torvalds
2011-08-27  0:43       ` Linus Torvalds
2011-08-27  0:53         ` H. Peter Anvin
2011-08-27  1:18           ` Linus Torvalds
2011-08-27  1:35             ` H. Peter Anvin
2011-08-27  1:45               ` Linus Torvalds
2011-08-27  1:12         ` H. Peter Anvin
2011-08-27  1:42           ` Linus Torvalds
2011-08-29 19:01             ` Geert Uytterhoeven
2011-08-29 19:03               ` H. Peter Anvin
2011-08-30  1:17               ` Ted Ts'o
2011-08-30  1:48               ` Linus Torvalds
2011-08-30  2:16                 ` Kyle Moffett
2011-08-30  4:45                   ` H. Peter Anvin
2011-08-30  7:06                     ` Geert Uytterhoeven
2011-08-30 12:18                       ` Arnd Bergmann
2011-08-30  7:09                   ` Andi Kleen
2011-08-30  9:56                     ` Alan Cox
2011-08-30  7:00                 ` Geert Uytterhoeven
2011-09-20 18:37                   ` Jan Engelhardt
2011-09-06 20:40         ` Florian Weimer
2011-08-27  0:57       ` H. Peter Anvin
2011-08-27  4:40         ` Christoph Hellwig
2011-08-29 15:04           ` Arnd Bergmann
2011-08-29 18:31             ` H. Peter Anvin
2011-08-30 12:09               ` Arnd Bergmann
2011-08-30 16:35                 ` H. Peter Anvin
2011-08-31 16:14                   ` Arnd Bergmann
2011-08-31 16:25                     ` H. Peter Anvin
2011-08-31 16:39                       ` Arnd Bergmann
2011-08-31 16:48                         ` Linus Torvalds
2011-08-31 19:18                           ` Arnd Bergmann
2011-08-31 19:44                             ` H. Peter Anvin
2011-08-31 19:54                               ` Alan Cox
2011-08-31 20:02                                 ` H. Peter Anvin
2011-08-31 20:55                                   ` Arnd Bergmann
2011-08-31 20:58                                     ` H. Peter Anvin
2011-08-31 19:49                             ` Geert Uytterhoeven
2011-08-31 16:46                     ` Linus Torvalds
2011-08-31 17:05                       ` H.J. Lu
2011-09-03  2:56                         ` H.J. Lu
2011-09-03  3:04                           ` Linus Torvalds
2011-09-03  4:02                             ` H.J. Lu
2011-09-03  4:29                               ` H. Peter Anvin
2011-09-03  4:44                                 ` H.J. Lu
2011-09-03  5:16                                   ` H. Peter Anvin
2011-09-03 14:11                                     ` H.J. Lu
2011-09-03  5:29                                   ` H. Peter Anvin
2011-09-03  8:41                                     ` Arnd Bergmann
2011-09-03 14:04                                       ` Valdis.Kletnieks
2011-09-03 16:40                                         ` H. Peter Anvin
2011-09-03 17:16                                           ` Valdis.Kletnieks
2011-09-03 17:22                                             ` H.J. Lu
2011-09-03 17:28                                               ` H. Peter Anvin
2011-09-03 17:27                                             ` H. Peter Anvin
2011-09-04 13:51                                               ` Valdis.Kletnieks
2011-09-04 15:17                                               ` Arnd Bergmann
2011-09-04 17:08                                                 ` Linus Torvalds
2011-09-04 18:40                                                 ` H.J. Lu
2011-09-04 19:06                                                   ` Arnd Bergmann
2011-09-04 19:31                                                     ` H.J. Lu
2011-09-04 21:13                                                       ` Arnd Bergmann
2011-09-04 21:25                                                         ` H.J. Lu
2011-09-04 21:41                                                           ` Arnd Bergmann
2011-09-04 22:13                                                             ` H.J. Lu
2011-09-05  7:48                                                               ` Arnd Bergmann
2011-09-05 15:11                                                                 ` H.J. Lu
2011-09-05 17:21                                                                   ` Arnd Bergmann
2011-09-05 19:34                                                                     ` H.J. Lu
2011-09-05 19:54                                                                       ` H.J. Lu
2011-09-05 19:59                                                                         ` H. Peter Anvin
2011-09-05 20:27                                                                           ` Arnd Bergmann
2011-09-09 21:02                                                                   ` H.J. Lu
2011-09-04 20:11                                                     ` H. Peter Anvin
2011-09-04 19:31                                                   ` richard -rw- weinberger
2011-09-04 19:32                                                     ` H.J. Lu
2011-09-03 14:15                                     ` H.J. Lu
2011-08-31 17:09                       ` H. Peter Anvin
2011-08-31 17:19                         ` Linus Torvalds
2011-08-31 17:38                           ` H. Peter Anvin
2011-09-01 11:35                             ` Arnd Bergmann
2011-10-01 19:38                               ` Jonas Bonn
2012-02-08 21:36                           ` H. Peter Anvin [this message]
2011-09-01 13:30                         ` Avi Kivity
2011-09-01 14:13                           ` H. Peter Anvin
2011-09-02  0:49                             ` Pedro Alves
2011-09-02  1:51                               ` H. Peter Anvin
2011-09-02  8:02                                 ` Arnd Bergmann
2011-09-02  8:42                                 ` Pedro Alves
2011-09-01  6:08                     ` Jonas Bonn
2011-09-02  6:17     ` Andy Lutomirski

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=4F32EAD8.6020504@zytor.com \
    --to=hpa@zytor.com \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=hch@infradead.org \
    --cc=hjl.tools@gmail.com \
    --cc=jonas@southpole.se \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=msalter@redhat.com \
    --cc=rkuo@codeaurora.org \
    --cc=tglx@linutronix.de \
    --cc=tklauser@distanz.ch \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).