From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756132Ab1KOEFB (ORCPT ); Mon, 14 Nov 2011 23:05:01 -0500 Received: from e4.ny.us.ibm.com ([32.97.182.144]:35064 "EHLO e4.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755765Ab1KOEEy (ORCPT ); Mon, 14 Nov 2011 23:04:54 -0500 From: John Stultz To: LKML Cc: John Stultz , Thomas Gleixner , Eric Dumazet , Richard Cochran Subject: [PATCH 15/16] time: Update tiemkeeper structure using a local shadow Date: Mon, 14 Nov 2011 20:04:05 -0800 Message-Id: <1321329846-14755-16-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.7.3.2.146.gca209 In-Reply-To: <1321329846-14755-1-git-send-email-john.stultz@linaro.org> References: <1321329846-14755-1-git-send-email-john.stultz@linaro.org> x-cbid: 11111504-3534-0000-0000-000001E29A24 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Uses a local shadow structure to update the timekeeper. This reduces the timekeeper.lock hold time. WARNING: This introduces a race, but the window might be provably so small as to not be observable. This patch needs lots more math and comments to validate that assumption. CC: Thomas Gleixner CC: Eric Dumazet CC: Richard Cochran Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 45 +++++++++++++++++++++++++-------------------- 1 files changed, 25 insertions(+), 20 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 7870a0e..ba595a3 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -940,6 +940,7 @@ static cycle_t logarithmic_accumulation(struct timekeeper *tk, cycle_t offset, static void update_wall_time(void) { struct clocksource *clock; + struct timekeeper tk; cycle_t offset; int shift = 0, maxshift; unsigned long flags; @@ -951,10 +952,13 @@ static void update_wall_time(void) if (unlikely(timekeeping_suspended)) goto out; - clock = timekeeper.clock; + tk = timekeeper; + write_sequnlock_irqrestore(&timekeeper.lock, flags); + + clock = tk.clock; #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET - offset = timekeeper.cycle_interval; + offset = tk.cycle_interval; #else offset = (clock->read(clock) - clock->cycle_last) & clock->mask; #endif @@ -967,19 +971,19 @@ static void update_wall_time(void) * chunk in one go, and then try to consume the next smaller * doubled multiple. */ - shift = ilog2(offset) - ilog2(timekeeper.cycle_interval); + shift = ilog2(offset) - ilog2(tk.cycle_interval); shift = max(0, shift); /* Bound shift to one less then what overflows tick_length */ maxshift = (64 - (ilog2(ntp_tick_length())+1)) - 1; shift = min(shift, maxshift); - while (offset >= timekeeper.cycle_interval) { - offset = logarithmic_accumulation(&timekeeper, offset, shift); - if(offset < timekeeper.cycle_interval<= tk.cycle_interval) { + offset = logarithmic_accumulation(&tk, offset, shift); + if(offset < tk.cycle_interval<= - (NSEC_PER_SEC << timekeeper.shift))) { - timekeeper.xtime_nsec -= NSEC_PER_SEC << timekeeper.shift; - timekeeper.xtime_sec++; + if (unlikely(tk.xtime_nsec >= (NSEC_PER_SEC << tk.shift))) { + tk.xtime_nsec -= NSEC_PER_SEC << tk.shift; + tk.xtime_sec++; second_overflow(); } + write_seqlock_irqsave(&timekeeper.lock, flags); + + timekeeper = tk; timekeeping_update(&timekeeper, false); out: -- 1.7.3.2.146.gca209