From patchwork Tue Jul 10 22:43:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john stultz X-Patchwork-Id: 9936 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 A18C123E57 for ; Tue, 10 Jul 2012 22:44:00 +0000 (UTC) Received: from mail-yw0-f51.google.com (mail-yw0-f51.google.com [209.85.213.51]) by fiordland.canonical.com (Postfix) with ESMTP id 5BA0CA18938 for ; Tue, 10 Jul 2012 22:44:00 +0000 (UTC) Received: by yhnn12 with SMTP id n12so581744yhn.38 for ; Tue, 10 Jul 2012 15:43:49 -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=U7EdodTHWwqfSzSwomBk8a53igVhObrrQ6WiTNintnA=; b=Nu/84tMU64FdQXGDPrf5snUhTvEyz2kYtAAvrvQff6P71nv/oMJ5cSfjTMcjmE2pny 4avUnplBLsBr4k8mg8RoSpEgNhqVsiRArudKWR66BvlUTJgKaIQgogISAsADXUutzuYq 4+SLSevuxzjk3Qwe9BgJ7ant4y18VUF962K1nhztC+zUZwq4nq80aJPUHma15FFsVpF7 VISdEPpZbzQprFDZ7Sp90mFtRNM6YpwklbN47LbRj/lB/T16g5dEa/qAKdpSKcX0S8Nb rrbnfBeKNGNLKCEuThHyWpXTRpEwiY7hrxdC2lKtfYEYCyR0FfzMoNc8zrIyVHZ+5Ob/ 3oVg== Received: by 10.50.193.196 with SMTP id hq4mr12619831igc.57.1341960229616; Tue, 10 Jul 2012 15:43:49 -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.235.202 with SMTP id kh10csp1483ibb; Tue, 10 Jul 2012 15:43:49 -0700 (PDT) Received: by 10.68.218.103 with SMTP id pf7mr73681791pbc.67.1341960228803; Tue, 10 Jul 2012 15:43:48 -0700 (PDT) Received: from e31.co.us.ibm.com (e31.co.us.ibm.com. [32.97.110.149]) by mx.google.com with ESMTPS id vz5si892839pbc.269.2012.07.10.15.43.48 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 Jul 2012 15:43:48 -0700 (PDT) Received-SPF: pass (google.com: domain of johnstul@us.ibm.com designates 32.97.110.149 as permitted sender) client-ip=32.97.110.149; Authentication-Results: mx.google.com; spf=pass (google.com: domain of johnstul@us.ibm.com designates 32.97.110.149 as permitted sender) smtp.mail=johnstul@us.ibm.com Received: from /spool/local by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Jul 2012 16:43:47 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Jul 2012 16:43:45 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 8EB263E4005B for ; Tue, 10 Jul 2012 22:43:44 +0000 (WET) Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6AMhiWo278862 for ; Tue, 10 Jul 2012 16:43:44 -0600 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6AMinbw013601 for ; Tue, 10 Jul 2012 16:44:49 -0600 Received: from kernel.stglabs.ibm.com ([9.114.214.19]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6AMiji4013399; Tue, 10 Jul 2012 16:44:48 -0600 From: John Stultz To: Linux Kernel Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Prarit Bhargava , stable@vger.kernel.org, John Stultz Subject: [PATCH 3/6] timekeeping: Maintain ktime_t based offsets for hrtimers Date: Tue, 10 Jul 2012 18:43:21 -0400 Message-Id: <1341960205-56738-4-git-send-email-johnstul@us.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1341960205-56738-1-git-send-email-johnstul@us.ibm.com> References: <1341960205-56738-1-git-send-email-johnstul@us.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12071022-7282-0000-0000-00000AC95BC0 X-Gm-Message-State: ALoCoQmxUpaYnm2UqSNkq5Ys8HuoLl0dOGgxdkUp51cl03W4eKyXJJmA7czv8wWXxQ+bRSw2mIiG From: Thomas Gleixner 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. CC: Ingo Molnar CC: Peter Zijlstra CC: Prarit Bhargava CC: Thomas Gleixner CC: stable@vger.kernel.org Signed-off-by: Thomas Gleixner 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 a413e59..1c038da 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); } @@ -604,6 +619,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); @@ -612,6 +628,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 @@ -630,8 +652,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)); }