From patchwork Tue Nov 15 04:04:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 5121 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 97CF323EF5 for ; Tue, 15 Nov 2011 04:04:59 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 8D202A181E6 for ; Tue, 15 Nov 2011 04:04:59 +0000 (UTC) Received: by mail-fx0-f52.google.com with SMTP id a26so64372faa.11 for ; Mon, 14 Nov 2011 20:04:59 -0800 (PST) Received: by 10.152.105.226 with SMTP id gp2mr15822857lab.28.1321329898496; Mon, 14 Nov 2011 20:04:58 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs24753lal; Mon, 14 Nov 2011 20:04:58 -0800 (PST) Received: by 10.50.135.40 with SMTP id pp8mr26529969igb.1.1321329896254; Mon, 14 Nov 2011 20:04:56 -0800 (PST) Received: from e2.ny.us.ibm.com (e2.ny.us.ibm.com. [32.97.182.142]) by mx.google.com with ESMTPS id lw3si5635789icb.139.2011.11.14.20.04.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Nov 2011 20:04:56 -0800 (PST) Received-SPF: pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.142 as permitted sender) client-ip=32.97.182.142; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jstultz@us.ibm.com designates 32.97.182.142 as permitted sender) smtp.mail=jstultz@us.ibm.com Received: from /spool/local by e2.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 14 Nov 2011 23:04:53 -0500 Received: from d01relay01.pok.ibm.com (9.56.227.233) by e2.ny.us.ibm.com (192.168.1.102) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 14 Nov 2011 23:04:21 -0500 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAF44KNx288504; Mon, 14 Nov 2011 23:04:20 -0500 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAF44KjN000348; Tue, 15 Nov 2011 02:04:20 -0200 Received: from kernel.beaverton.ibm.com ([9.47.67.96]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pAF44JIE032758; Tue, 15 Nov 2011 02:04:20 -0200 Received: by kernel.beaverton.ibm.com (Postfix, from userid 1056) id 0C1DF1E750B; Mon, 14 Nov 2011 20:04:18 -0800 (PST) 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-5112-0000-0000-00000208DB77 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: