From patchwork Tue Jul 17 06:39:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john stultz X-Patchwork-Id: 10025 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 7A2E923E56 for ; Tue, 17 Jul 2012 06:40:54 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 49EE2A185E8 for ; Tue, 17 Jul 2012 06:40:54 +0000 (UTC) Received: by mail-gg0-f180.google.com with SMTP id f1so51840ggn.11 for ; Mon, 16 Jul 2012 23:40:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-content-scanned:x-cbid:x-gm-message-state; bh=4Rn9cx1RrmzcKqsMv3281uDOdZHabZuKFASgp4lCVIE=; b=HeZAvqxG1PpyE9l0QgCFYhDaSkDk92dbS7AP2maHWix8ecuK30oKqfBlBZuljrKI8m 7QdjtNrcVZNuQzj28ezErapUbAUPxVHin5CH0WbsOZq7KICmgW2aHdTX8lc76Z3R2LIl GSGcjfnwrB1yb+dE9rrvDLVr6ofXWorcynEK/OgdKo7JYJjgZcwQyy7fXRMHrTT9JZ/v 8zPaUDJ8U3HYLySsHr2RR9Bn1/p36w1qZqlnyYEL+Ua2Rb2fdWf+TrRUEN5yazt6LSvQ Dh+gfJSLVT32PkE5SAWnNZl7vYneWd1AH/2ZiD2nF5tvNTtYSz1G7+gbDs0egcFnElNQ sBHA== Received: by 10.50.160.198 with SMTP id xm6mr458795igb.0.1342507253839; Mon, 16 Jul 2012 23:40:53 -0700 (PDT) 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.231.241.2 with SMTP id lc2csp15748ibb; Mon, 16 Jul 2012 23:40:52 -0700 (PDT) Received: by 10.43.70.71 with SMTP id yf7mr653283icb.14.1342507252907; Mon, 16 Jul 2012 23:40:52 -0700 (PDT) Received: from e38.co.us.ibm.com (e38.co.us.ibm.com. [32.97.110.159]) by mx.google.com with ESMTPS id pw4si15206831igc.30.2012.07.16.23.40.52 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 23:40:52 -0700 (PDT) Received-SPF: pass (google.com: domain of johnstul@us.ibm.com designates 32.97.110.159 as permitted sender) client-ip=32.97.110.159; Authentication-Results: mx.google.com; spf=pass (google.com: domain of johnstul@us.ibm.com designates 32.97.110.159 as permitted sender) smtp.mail=johnstul@us.ibm.com Received: from /spool/local by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Jul 2012 00:40:52 -0600 Received: from d01dlp03.pok.ibm.com (9.56.224.17) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 17 Jul 2012 00:40:12 -0600 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id A646AC9005A for ; Tue, 17 Jul 2012 02:40:11 -0400 (EDT) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6H6eBEh386440 for ; Tue, 17 Jul 2012 02:40:11 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6HCB4U7020907 for ; Tue, 17 Jul 2012 08:11:04 -0400 Received: from kernel.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6HCB4c9020889; Tue, 17 Jul 2012 08:11:04 -0400 From: John Stultz To: stable@vger.kernel.org Cc: Thomas Gleixner , John Stultz , Prarit Bhargava , Linux Kernel Subject: [PATCH 3/7] 3.4.x: timekeeping: Maintain ktime_t based offsets for hrtimers Date: Tue, 17 Jul 2012 02:39:52 -0400 Message-Id: <1342507196-54327-4-git-send-email-johnstul@us.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1342507196-54327-1-git-send-email-johnstul@us.ibm.com> References: <1342507196-54327-1-git-send-email-johnstul@us.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12071706-5518-0000-0000-00000616E0F8 X-Gm-Message-State: ALoCoQkAqdBwMtBI2FOsqONiaFBa3Nc7MMHdIzzzxxQo9X/JMlBOHFsJq8+0I6qcC8W8091IdME9 From: Thomas Gleixner This is a backport of 5b9fe759a678e05be4937ddf03d50e950207c1c0 We need to update the hrtimer clock offsets from the hrtimer interrupt context. To avoid conversions from timespec to ktime_t maintain a ktime_t based representation of those offsets in the timekeeper. This puts the conversion overhead into the code which updates the underlying offsets and provides fast accessible values in the hrtimer interrupt. Signed-off-by: Thomas Gleixner Signed-off-by: John Stultz Reviewed-by: Ingo Molnar Acked-by: Peter Zijlstra Acked-by: Prarit Bhargava Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/1341960205-56738-4-git-send-email-johnstul@us.ibm.com Signed-off-by: Thomas Gleixner Cc: Prarit Bhargava Cc: Thomas Gleixner Cc: Linux Kernel Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 9588f0c..615ec8d 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -70,6 +70,12 @@ struct timekeeper { /* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock. */ struct timespec raw_time; + /* Offset clock monotonic -> clock realtime */ + ktime_t offs_real; + + /* Offset clock monotonic -> clock boottime */ + ktime_t offs_boot; + /* Seqlock for all timekeeper values */ seqlock_t lock; }; @@ -172,6 +178,14 @@ static inline s64 timekeeping_get_ns_raw(void) return clocksource_cyc2ns(cycle_delta, clock->mult, clock->shift); } +static void update_rt_offset(void) +{ + struct timespec tmp, *wtm = &timekeeper.wall_to_monotonic; + + set_normalized_timespec(&tmp, -wtm->tv_sec, -wtm->tv_nsec); + timekeeper.offs_real = timespec_to_ktime(tmp); +} + /* must hold write on timekeeper.lock */ static void timekeeping_update(bool clearntp) { @@ -179,6 +193,7 @@ static void timekeeping_update(bool clearntp) timekeeper.ntp_error = 0; ntp_clear(); } + update_rt_offset(); update_vsyscall(&timekeeper.xtime, &timekeeper.wall_to_monotonic, timekeeper.clock, timekeeper.mult); } @@ -606,6 +621,7 @@ void __init timekeeping_init(void) } set_normalized_timespec(&timekeeper.wall_to_monotonic, -boot.tv_sec, -boot.tv_nsec); + update_rt_offset(); timekeeper.total_sleep_time.tv_sec = 0; timekeeper.total_sleep_time.tv_nsec = 0; write_sequnlock_irqrestore(&timekeeper.lock, flags); @@ -614,6 +630,12 @@ void __init timekeeping_init(void) /* time in seconds when suspend began */ static struct timespec timekeeping_suspend_time; +static void update_sleep_time(struct timespec t) +{ + timekeeper.total_sleep_time = t; + timekeeper.offs_boot = timespec_to_ktime(t); +} + /** * __timekeeping_inject_sleeptime - Internal function to add sleep interval * @delta: pointer to a timespec delta value @@ -632,8 +654,7 @@ static void __timekeeping_inject_sleeptime(struct timespec *delta) timekeeper.xtime = timespec_add(timekeeper.xtime, *delta); timekeeper.wall_to_monotonic = timespec_sub(timekeeper.wall_to_monotonic, *delta); - timekeeper.total_sleep_time = timespec_add( - timekeeper.total_sleep_time, *delta); + update_sleep_time(timespec_add(timekeeper.total_sleep_time, *delta)); }