linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [RFC] Potential fix for leapsecond caused futex related load spikes
@ 2012-07-01  9:36 John Stultz
  2012-07-01  9:42 ` John Stultz
  2012-07-01 12:00 ` Jan Ceuleers
  0 siblings, 2 replies; 12+ messages in thread
From: John Stultz @ 2012-07-01  9:36 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: John Stultz, stable, Thomas Gleixner

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

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

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

I believe this issue is due to the leapsecond being added without
calling clock_was_set() to notify the hrtimer subsystem of the
change. (Although I've not yet chased all the way down to the
hrtimer code to validate exactly what's going on there).

The workaround functions as it forces a clock_was_set()
call from settimeofday().

This fix adds some extra logic to track when a leapsecond
is added from update_wall_time() and calls clock_was_set()
once the timekeeper.lock is released.

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).

It had been a long day before I heard about this issue, so
my brain is a little mushy right now. Reviews and extra
testing would be greatly appreciated.

CC: stable@vger.kernel.org
CC: Thomas Gleixner <tglx@linutronix.de>
Reported-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: John Stultz <johnstul@us.ibm.com>
---
 kernel/time/timekeeping.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 6f46a00..e5da44f 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -942,7 +942,7 @@ static void timekeeping_adjust(s64 offset)
  *
  * Returns the unconsumed cycles.
  */
-static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
+static cycle_t logarithmic_accumulation(cycle_t offset, int shift, int* clockset)
 {
 	u64 nsecps = (u64)NSEC_PER_SEC << timekeeper.shift;
 	u64 raw_nsecs;
@@ -963,6 +963,8 @@ static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
 		leap = second_overflow(timekeeper.xtime.tv_sec);
 		timekeeper.xtime.tv_sec += leap;
 		timekeeper.wall_to_monotonic.tv_sec -= leap;
+		if (leap)
+			*clockset = 1;
 	}
 
 	/* Accumulate raw time */
@@ -994,6 +996,7 @@ static void update_wall_time(void)
 	struct clocksource *clock;
 	cycle_t offset;
 	int shift = 0, maxshift;
+	int clockset = 0;
 	unsigned long flags;
 
 	write_seqlock_irqsave(&timekeeper.lock, flags);
@@ -1026,7 +1029,7 @@ static void update_wall_time(void)
 	maxshift = (64 - (ilog2(ntp_tick_length())+1)) - 1;
 	shift = min(shift, maxshift);
 	while (offset >= timekeeper.cycle_interval) {
-		offset = logarithmic_accumulation(offset, shift);
+		offset = logarithmic_accumulation(offset, shift, &clockset);
 		if(offset < timekeeper.cycle_interval<<shift)
 			shift--;
 	}
@@ -1079,6 +1082,8 @@ static void update_wall_time(void)
 		leap = second_overflow(timekeeper.xtime.tv_sec);
 		timekeeper.xtime.tv_sec += leap;
 		timekeeper.wall_to_monotonic.tv_sec -= leap;
+		if (leap)
+			clockset = 1;
 	}
 
 	timekeeping_update(false);
@@ -1086,6 +1091,8 @@ static void update_wall_time(void)
 out:
 	write_sequnlock_irqrestore(&timekeeper.lock, flags);
 
+	if (clockset)
+		clock_was_set();
 }
 
 /**
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* Re: [PATCH] [RFC] Potential fix for leapsecond caused futex related load spikes
@ 2012-07-01 15:28 Prarit Bhargava
  2012-07-01 16:56 ` Prarit Bhargava
  0 siblings, 1 reply; 12+ messages in thread
From: Prarit Bhargava @ 2012-07-01 15:28 UTC (permalink / raw)
  To: john stultz, Linux Kernel

John,

I was hit by the futex issue as well.  I saw your patch and quickly did a test
with top-of-tree + your patch using your reproducer.  I end up with warnings
from the smp_call_function code followed by all sorts of deadlocks, etc.

I haven't had a chance to debug and will start doing so shortly ...

intel-canoepass-02 login: [  108.479555] Clock: inserting leap second 23:59:60 UTC
[  108.485199] ------------[ cut here ]------------
[  108.490368] WARNING: at kernel/smp.c:461 smp_call_function_many+0xbd/0x260()
[  108.498236] Hardware name: S2600CP
[  108.502060] Modules linked in: nfs nfs_acl auth_rpcgss fscache lockd sunrpc
kvm_intel igb coretemp kvm ixgbe ptp pps_core ioatdma mdio tpm_tis crc32c_intel
wmi joydev dca tpm lpc_ich ghash_clmulni_intel sb_edac mfd_core edac_core
i2c_i801 microcode pcspkr tpm_bios hid_generic isci libsas scsi_transport_sas
mgag200 i2c_algo_bit drm_kms_helper ttm drm i2c_core [last unloaded: scsi_wait_scan]
[  108.540561] Pid: 1328, comm: leaptest Not tainted 3.5.0-rc4+ #4
[  108.547169] Hypervisor: no hypervisor
[  108.551273] Call Trace:
[  108.554019]  <IRQ>  [<ffffffff8105814f>] warn_slowpath_common+0x7f/0xc0
[  108.561398]  [<ffffffff810581aa>] warn_slowpath_null+0x1a/0x20
[  108.567911]  [<ffffffff810b39bd>] smp_call_function_many+0xbd/0x260
[  108.574931]  [<ffffffff8107e960>] ? hrtimer_wakeup+0x30/0x30
[  108.581242]  [<ffffffff8107e960>] ? hrtimer_wakeup+0x30/0x30
[  108.587560]  [<ffffffff810b3cb2>] smp_call_function+0x22/0x30
[  108.593982]  [<ffffffff810b3d18>] on_each_cpu+0x28/0x70
[  108.599825]  [<ffffffff8107ef7c>] clock_was_set+0x1c/0x30
[  108.605847]  [<ffffffff810a71d5>] do_timer+0x315/0x570
[  108.611592]  [<ffffffff810adb18>] tick_do_update_jiffies64+0x78/0xc0
[  108.618680]  [<ffffffff810add28>] tick_sched_timer+0xb8/0xc0
[  108.624991]  [<ffffffff8107ed03>] __run_hrtimer+0x73/0x1d0
[  108.631111]  [<ffffffff810adc70>] ? tick_nohz_handler+0x110/0x110
[  108.637908]  [<ffffffff8107f5d7>] hrtimer_interrupt+0xd7/0x1f0
[  108.644447]  [<ffffffff81610c19>] smp_apic_timer_interrupt+0x69/0x99
[  108.651550]  [<ffffffff8160f98a>] apic_timer_interrupt+0x6a/0x70
[  108.658255]  <EOI>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-07-03 13:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-01  9:36 [PATCH] [RFC] Potential fix for leapsecond caused futex related load spikes John Stultz
2012-07-01  9:42 ` John Stultz
2012-07-01 12:00 ` Jan Ceuleers
  -- strict thread matches above, loose matches on Subject: below --
2012-07-01 15:28 Prarit Bhargava
2012-07-01 16:56 ` Prarit Bhargava
2012-07-01 17:28   ` John Stultz
2012-07-02 10:16     ` Richard Cochran
2012-07-02 16:58       ` John Stultz
2012-07-02 20:08       ` Sytse Wielinga
2012-07-03  9:23         ` Richard Cochran
2012-07-03 12:05           ` Sytse Wielinga
2012-07-03 13:41             ` Richard Cochran

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).