From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Greg KH <gregkh@linuxfoundation.org>,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, John Stultz <johnstul@us.ibm.com>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Prarit Bhargava <prarit@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [ 22/23] hrtimer: Update hrtimer base offsets each hrtimer_interrupt
Date: Tue, 17 Jul 2012 17:12:15 -0700 [thread overview]
Message-ID: <20120717232331.136475970@linuxfoundation.org> (raw)
In-Reply-To: <20120717232329.276003806@linuxfoundation.org>
From: Greg KH <gregkh@linuxfoundation.org>
3.0-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Stultz <johnstul@us.ibm.com>
This is a backport of 5baefd6d84163443215f4a99f6a20f054ef11236
The update of the hrtimer base offsets on all cpus cannot be made
atomically from the timekeeper.lock held and interrupt disabled region
as smp function calls are not allowed there.
clock_was_set(), which enforces the update on all cpus, is called
either from preemptible process context in case of do_settimeofday()
or from the softirq context when the offset modification happened in
the timer interrupt itself due to a leap second.
In both cases there is a race window for an hrtimer interrupt between
dropping timekeeper lock, enabling interrupts and clock_was_set()
issuing the updates. Any interrupt which arrives in that window will
see the new time but operate on stale offsets.
So we need to make sure that an hrtimer interrupt always sees a
consistent state of time and offsets.
ktime_get_update_offsets() allows us to get the current monotonic time
and update the per cpu hrtimer base offsets from hrtimer_interrupt()
to capture a consistent state of monotonic time and the offsets. The
function replaces the existing ktime_get() calls in hrtimer_interrupt().
The overhead of the new function vs. ktime_get() is minimal as it just
adds two store operations.
This ensures that any changes to realtime or boottime offsets are
noticed and stored into the per-cpu hrtimer base structures, prior to
any hrtimer expiration and guarantees that timers are not expired early.
Signed-off-by: John Stultz <johnstul@us.ibm.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Prarit Bhargava <prarit@redhat.com>
Link: http://lkml.kernel.org/r/1341960205-56738-8-git-send-email-johnstul@us.ibm.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <johnstul@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/hrtimer.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -657,6 +657,14 @@ static inline int hrtimer_enqueue_reprog
return 0;
}
+static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
+{
+ ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset;
+ ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME].offset;
+
+ return ktime_get_update_offsets(offs_real, offs_boot);
+}
+
/*
* Retrigger next event is called after clock was set
*
@@ -665,22 +673,12 @@ static inline int hrtimer_enqueue_reprog
static void retrigger_next_event(void *arg)
{
struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
- struct timespec realtime_offset, xtim, wtm, sleep;
if (!hrtimer_hres_active())
return;
- /* Optimized out for !HIGH_RES */
- get_xtime_and_monotonic_and_sleep_offset(&xtim, &wtm, &sleep);
- set_normalized_timespec(&realtime_offset, -wtm.tv_sec, -wtm.tv_nsec);
-
- /* Adjust CLOCK_REALTIME offset */
raw_spin_lock(&base->lock);
- base->clock_base[HRTIMER_BASE_REALTIME].offset =
- timespec_to_ktime(realtime_offset);
- base->clock_base[HRTIMER_BASE_BOOTTIME].offset =
- timespec_to_ktime(sleep);
-
+ hrtimer_update_base(base);
hrtimer_force_reprogram(base, 0);
raw_spin_unlock(&base->lock);
}
@@ -710,7 +708,6 @@ static int hrtimer_switch_to_hres(void)
base->clock_base[i].resolution = KTIME_HIGH_RES;
tick_setup_sched_timer();
-
/* "Retrigger" the interrupt to get things going */
retrigger_next_event(NULL);
local_irq_restore(flags);
@@ -1264,7 +1261,7 @@ void hrtimer_interrupt(struct clock_even
dev->next_event.tv64 = KTIME_MAX;
raw_spin_lock(&cpu_base->lock);
- entry_time = now = ktime_get();
+ entry_time = now = hrtimer_update_base(cpu_base);
retry:
expires_next.tv64 = KTIME_MAX;
/*
@@ -1342,9 +1339,12 @@ retry:
* We need to prevent that we loop forever in the hrtimer
* interrupt routine. We give it 3 attempts to avoid
* overreacting on some spurious event.
+ *
+ * Acquire base lock for updating the offsets and retrieving
+ * the current time.
*/
raw_spin_lock(&cpu_base->lock);
- now = ktime_get();
+ now = hrtimer_update_base(cpu_base);
cpu_base->nr_retries++;
if (++retries < 3)
goto retry;
prev parent reply other threads:[~2012-07-18 0:14 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-17 23:24 [ 00/23] 3.0.38-stable review Greg KH
2012-07-18 0:02 ` [ 01/37] Remove easily user-triggerable BUG from generic_setlease Greg Kroah-Hartman
2012-07-18 0:02 ` [ 02/37] media: cx231xx: dont DMA to random addresses Greg Kroah-Hartman
2012-07-18 0:02 ` [ 03/37] hwmon: (it87) Preserve configuration register bits on init Greg Kroah-Hartman
2012-07-18 0:02 ` [ 04/37] block: fix infinite loop in __getblk_slow Greg Kroah-Hartman
2012-07-18 0:02 ` [ 05/37] media: dvb-core: Release semaphore on error path dvb_register_device() Greg Kroah-Hartman
2012-07-18 0:02 ` [ 06/37] mtd: nandsim: dont open code a do_div helper Greg Kroah-Hartman
2012-07-18 0:02 ` [ 07/37] md/raid1: fix use-after-free bug in RAID1 data-check code Greg Kroah-Hartman
2012-07-18 0:02 ` [ 08/37] ARM: SAMSUNG: fix race in s3c_adc_start for ADC Greg Kroah-Hartman
2012-07-18 0:02 ` [ 09/37] ACPICA: Fix possible fault in return package object repair code Greg Kroah-Hartman
2012-07-18 0:02 ` [ 10/37] cpufreq / ACPI: Fix not loading acpi-cpufreq driver regression Greg Kroah-Hartman
2012-07-18 0:02 ` [ 11/37] sched/nohz: Rewrite and fix load-avg computation -- again Greg Kroah-Hartman
2012-07-18 0:16 ` Jonathan Nieder
2012-07-20 17:04 ` Peter Zijlstra
2012-07-20 17:13 ` Jonathan Nieder
2012-07-20 17:25 ` Peter Zijlstra
2012-07-21 16:02 ` Doug Smythies
2012-07-18 0:02 ` [ 12/37] intel_ips: blacklist HP ProBook laptops Greg Kroah-Hartman
2012-07-18 0:02 ` [ 13/37] fifo: Do not restart open() if it already found a partner Greg Kroah-Hartman
2012-07-18 0:02 ` [ 14/37] rt2x00usb: fix indexes ordering on RX queue kick Greg Kroah-Hartman
2012-07-18 0:02 ` [ 15/37] e1000e: Correct link check logic for 82571 serdes Greg Kroah-Hartman
2012-07-18 0:02 ` [ 16/37] iwlegacy: always monitor for stuck queues Greg Kroah-Hartman
2012-07-18 0:02 ` [ 17/37] iwlegacy: dont mess up the SCD when removing a key Greg Kroah-Hartman
2012-07-18 0:02 ` [ 18/37] rpmsg: fix dependency on initialization order Greg Kroah-Hartman
2012-07-18 0:02 ` [ 19/37] mac80211: destroy assoc_data correctly if assoc fails Greg Kroah-Hartman
2012-07-18 0:02 ` [ 20/37] stmmac: Fix for nfs hang on multiple reboot Greg Kroah-Hartman
2012-07-18 0:02 ` [ 21/37] bonding: debugfs and network namespaces are incompatible Greg Kroah-Hartman
2012-07-18 0:02 ` [ 22/37] bonding: Manage /proc/net/bonding/ entries from the netdev events Greg Kroah-Hartman
2012-07-18 0:03 ` [ 23/37] Input: bcm5974 - Add support for 2012 MacBook Pro Retina Greg Kroah-Hartman
2012-07-18 0:03 ` [ 24/37] Input: xpad - handle all variations of Mad Catz Beat Pad Greg Kroah-Hartman
2012-07-18 0:03 ` [ 25/37] Input: xpad - add signature for Razer Onza Tournament Edition Greg Kroah-Hartman
2012-07-18 0:03 ` [ 26/37] Input: xpad - add Andamiro Pump It Up pad Greg Kroah-Hartman
2012-07-18 0:03 ` [ 27/37] HID: add support for 2012 MacBook Pro Retina Greg Kroah-Hartman
2012-07-18 0:03 ` [ 28/37] clk: Check parent for NULL in clk_change_rate Greg Kroah-Hartman
2012-07-18 0:03 ` [ 29/37] cfg80211: check iface combinations only when iface is running Greg Kroah-Hartman
2012-07-18 0:03 ` [ 30/37] hrtimer: Provide clock_was_set_delayed() Greg Kroah-Hartman
2012-07-18 0:03 ` [ 31/37] timekeeping: Fix leapsecond triggered load spike issue Greg Kroah-Hartman
2012-07-18 0:03 ` [ 32/37] timekeeping: Maintain ktime_t based offsets for hrtimers Greg Kroah-Hartman
2012-07-18 0:03 ` [ 33/37] hrtimers: Move lock held region in hrtimer_interrupt() Greg Kroah-Hartman
2012-07-18 0:03 ` [ 34/37] timekeeping: Provide hrtimer update function Greg Kroah-Hartman
2012-07-18 0:03 ` [ 35/37] hrtimer: Update hrtimer base offsets each hrtimer_interrupt Greg Kroah-Hartman
2012-07-18 0:03 ` [ 37/37] NFC: Export nfc.h to userland Greg Kroah-Hartman
2012-07-18 0:14 ` [ 01/37] Remove easily user-triggerable BUG from generic_setlease Greg KH
2012-07-18 13:36 ` Nick Bowler
2012-07-18 17:58 ` formail doing weird things (was: [ 01/37] Remove easily user-triggerable BUG from generic_setlease) Roland Eggner
2012-07-18 0:11 ` [ 01/23] hwmon: (it87) Preserve configuration register bits on init Greg Kroah-Hartman
2012-07-18 0:11 ` [ 02/23] block: fix infinite loop in __getblk_slow Greg Kroah-Hartman
2012-07-18 0:11 ` [ 03/23] media: dvb-core: Release semaphore on error path dvb_register_device() Greg Kroah-Hartman
2012-07-18 0:11 ` [ 04/23] mtd: nandsim: dont open code a do_div helper Greg Kroah-Hartman
2012-07-18 0:11 ` [ 05/23] ARM: SAMSUNG: fix race in s3c_adc_start for ADC Greg Kroah-Hartman
2012-07-18 0:11 ` [ 06/23] intel_ips: blacklist HP ProBook laptops Greg Kroah-Hartman
2012-07-18 0:12 ` [ 07/23] fifo: Do not restart open() if it already found a partner Greg Kroah-Hartman
2012-07-18 0:12 ` [ 08/23] rt2x00usb: fix indexes ordering on RX queue kick Greg Kroah-Hartman
2012-07-18 0:12 ` [ 09/23] e1000e: Correct link check logic for 82571 serdes Greg Kroah-Hartman
2012-07-18 0:12 ` [ 10/23] Input: xpad - add Andamiro Pump It Up pad Greg Kroah-Hartman
2012-07-18 0:12 ` [ 11/23] tcp: drop SYN+FIN messages Greg Kroah-Hartman
2012-07-18 0:12 ` [ 12/23] cfg80211: check iface combinations only when iface is running Greg Kroah-Hartman
2012-07-18 0:12 ` [ 13/23] ntp: Fix leap-second hrtimer livelock Greg Kroah-Hartman
2012-07-18 0:12 ` [ 14/23] ntp: Correct TAI offset during leap second Greg Kroah-Hartman
2012-07-18 0:12 ` [ 15/23] timekeeping: Fix CLOCK_MONOTONIC inconsistency during leapsecond Greg Kroah-Hartman
2012-07-18 0:12 ` [ 16/23] time: Move common updates to a function Greg Kroah-Hartman
2012-07-18 0:12 ` [ 17/23] hrtimer: Provide clock_was_set_delayed() Greg Kroah-Hartman
2012-07-18 0:12 ` [ 18/23] timekeeping: Fix leapsecond triggered load spike issue Greg Kroah-Hartman
2012-07-18 0:12 ` [ 19/23] timekeeping: Maintain ktime_t based offsets for hrtimers Greg Kroah-Hartman
2012-07-18 0:12 ` [ 20/23] hrtimers: Move lock held region in hrtimer_interrupt() Greg Kroah-Hartman
2012-07-18 0:12 ` [ 21/23] timekeeping: Provide hrtimer update function Greg Kroah-Hartman
2012-07-18 0:12 ` Greg Kroah-Hartman [this message]
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=20120717232331.136475970@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=prarit@redhat.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--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).