Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2)

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


johnstul at us

Jul 1, 2012, 11:29 AM

Post #1 of 8 (1037 views)
Permalink
[PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2)

From: John Stultz <john.stultz [at] linaro>

Here's round two on this one.

As widely reported on the internet, some Linux systems after
the leapsecond was inserted are experiencing futex related load
spikes (usually connected to MySQL, Firefox, Thunderbird, Java, etc).

An apparent workaround for this issue is running:
$ date -s "`date`"

Credit: http://www.sheeri.com/content/mysql-and-leap-second-high-cpu-and-fix


To address this issue we do two things:
1) Fix the clock_was_set() call to remove the limitation that kept
us from calling it from update_wall_time().

2) Call clock_was_set() when we add/remove a leapsecond.

I've been able to reproduce the load spike using Thunderbird
when triggering a leap second and with this patch the issue
did not crop up.

NOTE: Some reports have been of a hard hang right at or before
the leapsecond. I've not been able to reproduce or diagnose
this, so this fix does not likely address the reported hard
hangs (unless they end up being connected to the futex/hrtimer
issue).


TODOs:
* Chase down the futex/hrtimer interaction to see if this could
be triggered in any other way.
* Get Tglx's input/ack
* Generate a backport for pre-v3.4 kernels


v2:
* Address the issue w/ calling clock_was_set from atomic context, pointed
out by Prarit and Ben.
* Rework fix so its simpler.


CC: Prarit Bhargava <prarit [at] redhat>
CC: stable [at] vger
CC: Thomas Gleixner <tglx [at] linutronix>
Reported-by: Jan Engelhardt <jengelh [at] inai>
Signed-off-by: John Stultz <johnstul [at] us>

John Stultz (2):
[RFC] Fix clock_was_set so it is safe to call from atomic
[RFC] Fix leapsecond triggered hrtimer/futex load spike issue

kernel/hrtimer.c | 16 +++++++++++++++-
kernel/time/timekeeping.c | 4 ++++
2 files changed, 19 insertions(+), 1 deletion(-)

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


john.stultz at linaro

Jul 1, 2012, 11:34 AM

Post #2 of 8 (1009 views)
Permalink
Re: [PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2) [In reply to]

On 07/01/2012 11:29 AM, John Stultz wrote:
> From: John Stultz <john.stultz [at] linaro>
>
> Here's round two on this one.
And again, attached is the test case I've been using to trigger
leapseconds, should anyone else want to help with testing the patches or
reproducing problems.

To build:
gcc leaptest.c -o leaptest -lrt

thanks
-john
Attachments: leaptest.c (2.03 KB)


jengelh at inai

Jul 1, 2012, 11:47 AM

Post #3 of 8 (1012 views)
Permalink
Re: [PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2) [In reply to]

On Sunday 2012-07-01 20:29, John Stultz wrote:
>
>An apparent workaround for this issue is running:
>$ date -s "`date`"
>
>Credit: http://www.sheeri.com/content/mysql-and-leap-second-high-cpu-and-fix

One can run the date call even while ntpd keeps running.

>TODOs:
>* Chase down the futex/hrtimer interaction to see if this could
>be triggered in any other way.
>* Get Tglx's input/ack
>* Generate a backport for pre-v3.4 kernels

It looks like 2.6.37.6 is not affected (on a system where ntpd is
running). That is to say, at least the mysqld instance on such a system
did not jump to high CPU usage. I did not try your testcase.c there,
since that would likely freak out the webapps - or the management.

Other reports on IRC include that 2.6.32-71.el6 (RHEL) is affected.
(Backporting gone wrong, *snicker* ;)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


johnstul at us

Jul 1, 2012, 3:05 PM

Post #4 of 8 (1005 views)
Permalink
Re: [PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2) [In reply to]

On 07/01/2012 11:29 AM, John Stultz wrote:
> TODOs:
> * Chase down the futex/hrtimer interaction to see if this could
> be triggered in any other way.

Ok, got a little more detailed diagnosis of what is going on figured out:

* Leap second occurs, CLOCK_REALTIME is set back one second.

* As clock_was_set() is not called, the hrtimer base.offset value for
CLOCK_REALTIME is not updated, thus its sense of wall time is one second
ahead of the timekeeping core's.

* At interrupt time (T), the hrtimer code expires all CLOCK_REALTIME
based timers set for T+1s and before, causing early expirations for
timers between T and T+1s since the hrtimer code's sense of time is one
second ahead.

* This causes all TIMER_ABSTIME CLOCK_REALTIME timers to expire one
second early.

* More problematically, all sub-second TIMER_ABSTIME CLOCK_REALTIME
timers will return immediately. If any such timer calls are done in a
loop (as commonly done with futex_wait or other timeouts), this will
cause load spikes in those applications.

* This state persists until clock_was_set() is called (most easily done
via settimeofday())


I've used the attached test case to demonstrate triggering a leap-second
and its effect on CLOCK_REALTIME hrtimers.

The test sets a leapsecond to trigger in 10 seconds, then in a loop
sleeps for half a second via clock_nanosleep, printing out the current
time, and the delta from the target wakeup time for 30 seconds.

When the leap second triggers, on affected machines you'll see the
output streams quickly, with negative diff values, as clock_nanosleep is
immediately returning.

To build:
gcc leaptest-timer.c -o leaptest-timer -lrt


I've reproduced this behaviour in kernel versions:
v3.5-rc4
v2.6.37
v2.6.32.59
(And quite likely all in-between).

I haven't been able to build or boot anything earlier with the distro on
my current test boxes, but I'm working to get older distro installed so
I can do further testing.

Likely has potentially been around
since:746976a301ac9c9aa10d7d42454f8d6cdad8ff2b in v2.6.22, as Ben Blum
and Jan Ceuleers already noted.

With my fix to call clock_was_set when we apply a leapsecond, I no
longer see the issue.

thanks
-john
Attachments: leaptest-timer.c (2.13 KB)


johnstul at us

Jul 1, 2012, 9:12 PM

Post #5 of 8 (986 views)
Permalink
Re: [PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2) [In reply to]

On 07/01/2012 11:29 AM, John Stultz wrote:
> TODOs:
> * Chase down the futex/hrtimer interaction to see if this could
> be triggered in any other way.
> * Get Tglx's input/ack
> * Generate a backport for pre-v3.4 kernels
So while still waiting for feedback on the clock_was_set() change, I
went ahead and generated backports for most of the stable kernels on
kernel.org.

Clearly these shouldn't go anywhere until the fix is upstream, but since
I assume there's a number of distro developers who are likely under
pressure to have a fix soon, I wanted to make them available so no one
is duplicating work.

You can find them here:
http://git.linaro.org/gitweb?p=people/jstultz/linux.git;a=summary

I did boot and test each of those kernels with my leaptest-timer.c test
successfully.

thanks
-john


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


prarit at redhat

Jul 2, 2012, 6:53 AM

Post #6 of 8 (962 views)
Permalink
Re: [PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2) [In reply to]

On 07/02/2012 12:12 AM, John Stultz wrote:
> On 07/01/2012 11:29 AM, John Stultz wrote:
>> TODOs:
>> * Chase down the futex/hrtimer interaction to see if this could
>> be triggered in any other way.
>> * Get Tglx's input/ack
>> * Generate a backport for pre-v3.4 kernels
> So while still waiting for feedback on the clock_was_set() change, I went ahead
> and generated backports for most of the stable kernels on kernel.org.
>

I've tested on a well-known enterprise distro ;), as well as it's more public
variant with the latest top-of-tree kernel + this second patchset across a
fairly wide selection of systems [AMD and Intel, large and small] and don't see
any issues.

(I haven't taken tglx's comments into account yet though ... this is just an
indication that the direction of the patch seems correct)

P.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


davej at redhat

Jul 2, 2012, 11:51 AM

Post #7 of 8 (956 views)
Permalink
Re: [PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2) [In reply to]

On Sun, Jul 01, 2012 at 09:12:59PM -0700, John Stultz wrote:
> On 07/01/2012 11:29 AM, John Stultz wrote:
> > TODOs:
> > * Chase down the futex/hrtimer interaction to see if this could
> > be triggered in any other way.
> > * Get Tglx's input/ack
> > * Generate a backport for pre-v3.4 kernels
> So while still waiting for feedback on the clock_was_set() change, I
> went ahead and generated backports for most of the stable kernels on
> kernel.org.
>
> Clearly these shouldn't go anywhere until the fix is upstream, but since
> I assume there's a number of distro developers who are likely under
> pressure to have a fix soon, I wanted to make them available so no one
> is duplicating work.
>
> You can find them here:
> http://git.linaro.org/gitweb?p=people/jstultz/linux.git;a=summary
>
> I did boot and test each of those kernels with my leaptest-timer.c test
> successfully.

I'm curious how the test that I did with the kernel patch,
or Richard Cochran's userspace test program didn't trigger this bug
when we tested last week.

any ideas what we missed ?

Dave

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


johnstul at us

Jul 2, 2012, 12:08 PM

Post #8 of 8 (958 views)
Permalink
Re: [PATCH 0/2][RFC] Potential fix for leapsecond caused futex issue (v2) [In reply to]

On 07/02/2012 11:51 AM, Dave Jones wrote:
> On Sun, Jul 01, 2012 at 09:12:59PM -0700, John Stultz wrote:
> > On 07/01/2012 11:29 AM, John Stultz wrote:
> > > TODOs:
> > > * Chase down the futex/hrtimer interaction to see if this could
> > > be triggered in any other way.
> > > * Get Tglx's input/ack
> > > * Generate a backport for pre-v3.4 kernels
> > So while still waiting for feedback on the clock_was_set() change, I
> > went ahead and generated backports for most of the stable kernels on
> > kernel.org.
> >
> > Clearly these shouldn't go anywhere until the fix is upstream, but since
> > I assume there's a number of distro developers who are likely under
> > pressure to have a fix soon, I wanted to make them available so no one
> > is duplicating work.
> >
> > You can find them here:
> > http://git.linaro.org/gitweb?p=people/jstultz/linux.git;a=summary
> >
> > I did boot and test each of those kernels with my leaptest-timer.c test
> > successfully.
>
> I'm curious how the test that I did with the kernel patch,
> or Richard Cochran's userspace test program didn't trigger this bug
> when we tested last week.

It likely did trigger the issue.

> any ideas what we missed ?

In order to observe this issue, you need to notice that CLOCK_REALTIME
timers are firing one second early. The issue does not affect
CLOCK_MONOTONIC timers. Its only most visible with applications that
make sub-second CLOCK_REALTIME timeouts in a loop (most reported cases
connected with futexs). So if such an application wasn't running, it
would be easy to overlook.

thanks
-john

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.