* Re: GPS Leap Second Scheduled!
@ 1998-09-09 4:46 Colin Plumb
1998-09-09 19:08 ` Theodore Y. Ts'o
0 siblings, 1 reply; 18+ messages in thread
From: Colin Plumb @ 1998-09-09 4:46 UTC (permalink / raw)
To: andrejp; +Cc: linux-kernel
Ulrich Windl wrote:
> The time in the kernel is seconds since the epoch. To insert a second
> means that we'll have to delay the next second for another second.
> The other solution seems to be a clib -> kernel interface that knows
> that a leap second is active now. Then the clib could possibly
> convert the seconds to xx:yy:60. (I hope I did not overlook something
> obvious).
And Andrej Presern replied:
>> Have you considered simply not scheduling any processes for one second and
>> adjusting the time accordingly? (if one second chunk is too big, you can do
>> it in several steps)
The problem is that POSIX is schizophrenic on the subject of leap seconds.
On the one hand, time() returns UTC time. On the other,
t = time();
sec = t % 60;
t /= 60;
min = t % 60;
t /= 60;
hr = t % 24;
t /= 24;
printf("UTC time is %lu days, %02u:%02u:%02u\n", (unsigned long)t, gr, min, sec);
is required to work (since so much code does it.)
Actually, I think Ulrich was present when I proposed a similar solution:
gettimeofday() will not return during 23:59:60. If a process calls
gettimeofday() during a leap second, then the call will sleep until 0:00:00
when it can return the correct result.
This horrified the real-time people. It is, however, strictly speaking,
completely correct.
The real-world solution (a.k.a kludge), is to stretch some number of
seconds to cover the n+1 seconds including the leap second. During
those seconds, gettimeofday() is incorrect, but the error is
well-defined, so two "good" implementations will return "close" values
and you can undo the fudging afterwards if desired.
The only trick is to define the number of seconds n, their position
relative to the leap second, and they type of stretching. Linear is
obvious, making the 60 seconds leading up to a leap second take 61/60
of the usual time, but you could define a polynomial with higher-order
continuity.
--
-Colin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: GPS Leap Second Scheduled!
1998-09-09 4:46 GPS Leap Second Scheduled! Colin Plumb
@ 1998-09-09 19:08 ` Theodore Y. Ts'o
0 siblings, 0 replies; 18+ messages in thread
From: Theodore Y. Ts'o @ 1998-09-09 19:08 UTC (permalink / raw)
To: Colin Plumb; +Cc: andrejp, linux-kernel
Date: Tue, 8 Sep 1998 22:46:25 -0600 (MDT)
From: Colin Plumb <colin@nyx.net>
The problem is that POSIX is schizophrenic on the subject of leap seconds.
On the one hand, time() returns UTC time.
Yep. See POSIX 4.5.1.2, 2.2.2.77, 2.2.2.24, and the rationale for
Epoch, found in B.2.2.2).
On the other,
t = time();
sec = t % 60;
t /= 60;
min = t % 60;
t /= 60;
hr = t % 24;
t /= 24;
printf("UTC time is %lu days, %02u:%02u:%02u\n", (unsigned long)t, gr, min, sec);
is required to work (since so much code does it.)
In fact, POSIX requires this (see 2.2.2.77).
Actually, I think Ulrich was present when I proposed a similar solution:
gettimeofday() will not return during 23:59:60. If a process calls
gettimeofday() during a leap second, then the call will sleep until 0:00:00
when it can return the correct result.
The other possibility is for gettimeofday() to return the same value for
23:59:60 and 00:00:00. This would also strictly speaking be correct.
time() is specified as returning "seconds since the Epoch", which is
defined as:
tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 +
(tm_year-70)*31536000 + ((tm_year-64)/4*86400)
where tm_sec, tm_min, tm_hour, etc. together form a Curridnated
Universal Time name.
Hence, the above equation would have the same value for 23:59:60 and
00:00:00 on the next day. Hence, time() should return the same value.
- Ted
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <19980914165757.A17479@tantalophile.demon.co.uk>]
* Re: GPS Leap Second Scheduled!
@ 1998-09-11 22:49 Ethan O'Connor
0 siblings, 0 replies; 18+ messages in thread
From: Ethan O'Connor @ 1998-09-11 22:49 UTC (permalink / raw)
To: R.E.Wolff; +Cc: linux-kernel, chris
Roger Wolff wrote:
>Chris Wedgwood wrote:
>> On Wed, Sep 09, 1998 at 02:13:42PM -0600, Colin Plumb wrote:
>>
>> > - gettimeofday() never returns the same value twice (documented BSD
>> > behaviour)
>>
>> Ouch... gettimeofday(2) only presently has usec resolution. I suspect
>> we can make this report the same value twice on really high end boxes
>> (667MHz Alpha maybe, 400Mhz Sparcs?), if not now, in a year or so.
>> Even a P.ii 600 or so can probably manage it.
>This is defined behaviour. On processors where gettimeofday can be
>called more than once in a microsecond (SMP systems, and fast
>systems), the kernel is required to keep a last-time-returned, and
>increment it and return that if the value calculated is below the
>stored value.
>If you have the results from two gettimeofday calls, you can always
>subtract them and divide by the result without checking for zero.
>That's what the spec says.
>A kernel will get into trouble if you keep on calling gettimeofday
>more than a million times a second.....
Modifying Chris's code to call gettimeofday() 4 times
the second time around and to print the usec values
for the four successive calls yields the following on
this system (SunOS 5.6, Ultra-IIi/333Mhz):
athena% a.out
213426
213426
213426
213427
athena% a.out
499126
499126
499127
499127
and even:
athena% a.out
947875
947875
947875
947875
Etc...
FWIW.
-Ethan O'Connor
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <no.id>]
* Re: GPS Leap Second Scheduled!
[not found] <no.id>
@ 1998-09-10 6:34 ` Jamie Lokier
1998-09-11 6:18 ` Michael Shields
0 siblings, 1 reply; 18+ messages in thread
From: Jamie Lokier @ 1998-09-10 6:34 UTC (permalink / raw)
To: linux-kernel
On Wed, Sep 09, 1998 at 09:35:59AM -0700, David Lang wrote:
> I am probably missing something, but can't you just ignore the leap second
> until you discover that the time is 1 sec off and then use the normal NTP
> procedure to get back to the exact time
Until the NTP procedure discovers and corrects this (a few minutes, plus
correction time), anything that expects synchronised time between
machines can go wrong.
Admittedly synchronisation isn't perfect anyway.
-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: GPS Leap Second Scheduled!
1998-09-10 6:34 ` Jamie Lokier
@ 1998-09-11 6:18 ` Michael Shields
0 siblings, 0 replies; 18+ messages in thread
From: Michael Shields @ 1998-09-11 6:18 UTC (permalink / raw)
To: Jamie Lokier; +Cc: linux-kernel
In article <19980910073422.A13283@tantalophile.demon.co.uk>,
Jamie Lokier <lkd@tantalophile.demon.co.uk> wrote:
> On Wed, Sep 09, 1998 at 09:35:59AM -0700, David Lang wrote:
> > I am probably missing something, but can't you just ignore the leap second
> > until you discover that the time is 1 sec off and then use the normal NTP
> > procedure to get back to the exact time
>
> Until the NTP procedure discovers and corrects this (a few minutes, plus
> correction time), anything that expects synchronised time between
> machines can go wrong.
NTP has the capability to know in advance that a leap second is
scheduled and act upon that at the correct time.
Check your logs the next time a leap second happens; xntpd does it.
--
Shields, CrossLink.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: GPS Leap Second Scheduled!
@ 1998-09-09 20:13 Colin Plumb
1998-09-09 23:45 ` Chris Wedgwood
0 siblings, 1 reply; 18+ messages in thread
From: Colin Plumb @ 1998-09-09 20:13 UTC (permalink / raw)
To: tytso; +Cc: andrejp, linux-kernel
> Hence, the above equation would have the same value for 23:59:60 and
> 00:00:00 on the next day. Hence, time() should return the same value.
The problem becomes more acute for gettimeofday() and the POSIX
ns-resolution equivalent, clock_gettime(CLOCK_REALTIME).
There are a few axioms that you'd like to have hold:
- time() and gettimeofday() return the same time as
clock_gettime(CLOCK_REALTIME), as far as precision permits.
- gettimeofday() never returns the same value twice (documented BSD behaviour)
- no clock ever runs backwards
This makes the handling of the tv_usec or tv_nsec parts of the time during
a leap second a bit problematic.
One option is to count twice.
One option is to count at half speed during 23:59:60 and 0:00:00.
One option is to use the curve y = 1/4*x^3 - 3/4*x^2 + x to interpolate
y smoothly from 0 to 1 as x goes from 0 to 2.
One option is to freeze the fractional part fr one of the two seconds.
One (pretty rude) option is to count tv_usec from -1000000 to -1
during 23:59:60. (tv_usec is a *signed* long.)
I don't know of a pretty way. What I'd like, as I said, is a defined kludge,
so that there is a defined mapping between struct timeval and struct timespec
and UTC in the vicinity of a leap second. This ensures that timestamps
collected on different machines can at least be compared, even if the
time intervals reported are incorrect. ("Why were my ping times
half of usual at midnight last night?")
--
-Colin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: GPS Leap Second Scheduled!
1998-09-09 20:13 Colin Plumb
@ 1998-09-09 23:45 ` Chris Wedgwood
1998-09-09 23:55 ` Chris Wedgwood
1998-09-10 8:36 ` Rogier Wolff
0 siblings, 2 replies; 18+ messages in thread
From: Chris Wedgwood @ 1998-09-09 23:45 UTC (permalink / raw)
To: Colin Plumb, tytso; +Cc: andrejp, linux-kernel
On Wed, Sep 09, 1998 at 02:13:42PM -0600, Colin Plumb wrote:
> - gettimeofday() never returns the same value twice (documented BSD
> behaviour)
Ouch... gettimeofday(2) only presently has usec resolution. I suspect
we can make this report the same value twice on really high end boxes
(667MHz Alpha maybe, 400Mhz Sparcs?), if not now, in a year or so.
Even a P.ii 600 or so can probably manage it.
Sure... this is fixable and not hard to fix, but it requires breaking
binary compatibility.
The attached code on a PPro 200 gives me results of 2 usecs, using a
P.II 300 and SYSENTER semantics, you can probably get this to less
that 1usec.
> I don't know of a pretty way. What I'd like, as I said, is a
> defined kludge, so that there is a defined mapping between struct
> timeval and struct timespec and UTC in the vicinity of a leap
> second.
I'm not sure about a sane kludge for mapping to/from the semantics we
already have, but how about we just declare the existing API buggy
under some (rare circumstances) and create a new one with flags to
show whether or not a leap second is currently under way, much the
same as is done for daylight savings time with time zones. (You can
have two 2:30ams, only one of which tough is DST, the other is
non-DST).
-Chris
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: GPS Leap Second Scheduled!
1998-09-09 23:45 ` Chris Wedgwood
@ 1998-09-09 23:55 ` Chris Wedgwood
1998-09-10 8:36 ` Rogier Wolff
1 sibling, 0 replies; 18+ messages in thread
From: Chris Wedgwood @ 1998-09-09 23:55 UTC (permalink / raw)
To: Colin Plumb, tytso; +Cc: andrejp, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 247 bytes --]
On Thu, Sep 10, 1998 at 11:45:15AM +1200, Chris Wedgwood wrote:
> The attached code on a PPro 200 gives me results of 2 usecs, using a
> P.II 300 and SYSENTER semantics, you can probably get this to less
> that 1usec.
Crap... here it is.
-cw
[-- Attachment #2: tv-test.c --]
[-- Type: text/plain, Size: 438 bytes --]
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
struct timeval t1,t2,t3,t4;
do{
/* warm caches */
gettimeofday(&t1,NULL);
gettimeofday(&t2,NULL);
gettimeofday(&t3,NULL);
gettimeofday(&t4,NULL);
gettimeofday(&t3,NULL);
gettimeofday(&t4,NULL);
}while(t3.tv_sec != t4.tv_sec); /* yuk */
printf("%d usecs difference!\n",(int)(t4.tv_usec - t3.tv_usec));
return 0;
}
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: GPS Leap Second Scheduled!
1998-09-09 23:45 ` Chris Wedgwood
1998-09-09 23:55 ` Chris Wedgwood
@ 1998-09-10 8:36 ` Rogier Wolff
1998-09-10 17:05 ` Oliver Xymoron
1 sibling, 1 reply; 18+ messages in thread
From: Rogier Wolff @ 1998-09-10 8:36 UTC (permalink / raw)
To: Chris Wedgwood; +Cc: colin, tytso, andrejp, linux-kernel
Chris Wedgwood wrote:
> On Wed, Sep 09, 1998 at 02:13:42PM -0600, Colin Plumb wrote:
>
> > - gettimeofday() never returns the same value twice (documented BSD
> > behaviour)
>
> Ouch... gettimeofday(2) only presently has usec resolution. I suspect
> we can make this report the same value twice on really high end boxes
> (667MHz Alpha maybe, 400Mhz Sparcs?), if not now, in a year or so.
> Even a P.ii 600 or so can probably manage it.
This is defined behaviour. On processors where gettimeofday can be
called more than once in a microsecond (SMP systems, and fast
systems), the kernel is required to keep a last-time-returned, and
increment it and return that if the value calculated is below the
stored value.
If you have the results from two gettimeofday calls, you can always
subtract them and divide by the result without checking for zero.
That's what the spec says.
A kernel will get into trouble if you keep on calling gettimeofday
more than a million times a second.....
Roger.
--
| The secret of success is sincerity. Once you can |R.E.Wolff@BitWizard.nl
| fake that, you've got it made. -- Jean Giraudoux | phone: +31-15-2137555
We write Linux device drivers for any device you may have! fax: ..-2138217
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: GPS Leap Second Scheduled!
1998-09-10 8:36 ` Rogier Wolff
@ 1998-09-10 17:05 ` Oliver Xymoron
1998-09-10 22:02 ` Ryan Moore
0 siblings, 1 reply; 18+ messages in thread
From: Oliver Xymoron @ 1998-09-10 17:05 UTC (permalink / raw)
To: Rogier Wolff; +Cc: Chris Wedgwood, colin, tytso, andrejp, linux-kernel
On Thu, 10 Sep 1998, Rogier Wolff wrote:
> Chris Wedgwood wrote:
> > On Wed, Sep 09, 1998 at 02:13:42PM -0600, Colin Plumb wrote:
> >
> > > - gettimeofday() never returns the same value twice (documented BSD
> > > behaviour)
> >
> > Ouch... gettimeofday(2) only presently has usec resolution. I suspect
> > we can make this report the same value twice on really high end boxes
> > (667MHz Alpha maybe, 400Mhz Sparcs?), if not now, in a year or so.
> > Even a P.ii 600 or so can probably manage it.
>
> This is defined behaviour. On processors where gettimeofday can be
> called more than once in a microsecond (SMP systems, and fast
> systems), the kernel is required to keep a last-time-returned, and
> increment it and return that if the value calculated is below the
> stored value.
Seems wrong to bother the kernel with this at all. Any complexity here
should be put in libc. After all, the problem is largely with the ANSI C
spec.
Also, putting any of this 'hide the leap second' logic in the kernel makes
it more difficult to later add a consistent interface to libc as the
information is now hidden in the kernel.
Finally, telling the kernel to schedule a leap second seems pretty ugly as
well.
--
"Love the dolphins," she advised him. "Write by W.A.S.T.E.."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: GPS Leap Second Scheduled!
1998-09-10 17:05 ` Oliver Xymoron
@ 1998-09-10 22:02 ` Ryan Moore
0 siblings, 0 replies; 18+ messages in thread
From: Ryan Moore @ 1998-09-10 22:02 UTC (permalink / raw)
To: Oliver Xymoron; +Cc: linux-kernel
On Thu, 10 Sep 1998, Oliver Xymoron wrote:
> Finally, telling the kernel to schedule a leap second seems pretty ugly as
> well.
Except that it's already doing it. At least it is if you're running ntpd
or xntpd. I've seen the Linux kernel do leap seconds on my machine
before.
In 2.0.35 at least, the code is in /usr/src/linux/kernel/sched.c
In function second_overflow().
The kernel even prints a log message:
printk(KERN_NOTICE "Clock: inserting leap second 23:59:60 UTC\n");
in one case and...
printk(KERN_NOTICE "Clock: deleting leap second 23:59:59 UTC\n");
in another.
--------------------------------
Ryan Moore rmoore@rmoore.i.seawood.org
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html
^ permalink raw reply [flat|nested] 18+ messages in thread
[parent not found: <299BBE59294E@rkdvmks1.ngate.uni-regensburg.de>]
end of thread, other threads:[~1998-09-17 8:43 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-09-09 4:46 GPS Leap Second Scheduled! Colin Plumb
1998-09-09 19:08 ` Theodore Y. Ts'o
[not found] <19980914165757.A17479@tantalophile.demon.co.uk>
[not found] ` <199809150603.XAA29073@cesium.transmeta.com>
[not found] ` <19980915100729.02790@albireo.ucw.cz>
[not found] ` <35FF1838.6E247F0C@his.com>
1998-09-17 11:51 ` Jan Echternach
-- strict thread matches above, loose matches on Subject: below --
1998-09-11 22:49 Ethan O'Connor
[not found] <no.id>
1998-09-10 6:34 ` Jamie Lokier
1998-09-11 6:18 ` Michael Shields
1998-09-09 20:13 Colin Plumb
1998-09-09 23:45 ` Chris Wedgwood
1998-09-09 23:55 ` Chris Wedgwood
1998-09-10 8:36 ` Rogier Wolff
1998-09-10 17:05 ` Oliver Xymoron
1998-09-10 22:02 ` Ryan Moore
[not found] <299BBE59294E@rkdvmks1.ngate.uni-regensburg.de>
[not found] ` <98090822315400.00819@soda>
1998-09-09 0:59 ` H. Peter Anvin
1998-09-09 8:00 ` Chris Wedgwood
[not found] ` <199809092149.RAA06993@hilfy.ece.cmu.edu>
1998-09-10 1:37 ` H. Peter Anvin
1998-09-10 15:05 ` Theodore Y. Ts'o
1998-09-12 19:57 ` Feuer
1998-09-09 16:35 ` David Lang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox