From patchwork Tue Jul 10 22:43:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john stultz X-Patchwork-Id: 9937 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 B965323E57 for ; Tue, 10 Jul 2012 22:44:10 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7327AA188FA for ; Tue, 10 Jul 2012 22:44:10 +0000 (UTC) Received: by ghbz12 with SMTP id z12so656560ghb.11 for ; Tue, 10 Jul 2012 15:44:00 -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=5BNuPrL6HMsb02zK71JCwqiwBAeZYZVVAi2Mm4KeUwM=; b=oQZY+eRtqrvq2LKBG6QjlM1e1i/CBpCaKw/9cCnBw+r6vcCFasB4dt+7Hk7G76JG8o SDHWt975bltRnG8A9Lts+X2eiaOhlynsiOq9KaJCsuA3hzDfy4SZ7TQVpCDrRjA99ohV U7lY0dAqITUCW8yzF4OPGtfgGGzw1JdfLzJ+sslN6UYM7rguHjJ6pDUd1FxkOiKSIS5U r3inysDHyMV263vy36cP9h20CX/5ABpUj88Vj0BEvKKvoo7zgqVl/lhagV14OdoQ2JNF IHkiRFLzi5mPluqyCBJ7hBLZwikauMG3bysya3FyBoAWvNHU2K0eMzgLtZCFlke1FO2t CB7g== Received: by 10.42.68.65 with SMTP id w1mr317281ici.57.1341960239599; Tue, 10 Jul 2012 15:43:59 -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 kh10csp1485ibb; Tue, 10 Jul 2012 15:43:59 -0700 (PDT) Received: by 10.68.219.135 with SMTP id po7mr72302425pbc.149.1341960239005; Tue, 10 Jul 2012 15:43:59 -0700 (PDT) Received: from e39.co.us.ibm.com (e39.co.us.ibm.com. [32.97.110.160]) by mx.google.com with ESMTPS id vn4si915445pbc.202.2012.07.10.15.43.58 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 Jul 2012 15:43:58 -0700 (PDT) Received-SPF: pass (google.com: domain of johnstul@us.ibm.com designates 32.97.110.160 as permitted sender) client-ip=32.97.110.160; Authentication-Results: mx.google.com; spf=pass (google.com: domain of johnstul@us.ibm.com designates 32.97.110.160 as permitted sender) smtp.mail=johnstul@us.ibm.com Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Jul 2012 16:43:57 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e39.co.us.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Jul 2012 16:43:47 -0600 Received: from d03relay05.boulder.ibm.com (d03relay05.boulder.ibm.com [9.17.195.107]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 29D9119D8059 for ; Tue, 10 Jul 2012 22:43:46 +0000 (WET) Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d03relay05.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6AMhlA8260684 for ; Tue, 10 Jul 2012 16:43:47 -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 q6AMipMB013687 for ; Tue, 10 Jul 2012 16:44:51 -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 q6AMiji7013399; Tue, 10 Jul 2012 16:44:50 -0600 From: John Stultz To: Linux Kernel Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Prarit Bhargava , stable@vger.kernel.org, John Stultz Subject: [PATCH 5/6] timekeeping: Provide hrtimer update function Date: Tue, 10 Jul 2012 18:43:24 -0400 Message-Id: <1341960205-56738-7-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-4242-0000-0000-000002474F63 X-Gm-Message-State: ALoCoQnsxj6A+dxQbH9HQAqLRXkD112hO49jlH14znBafm+Nni+BB7w+wXspjS7ffu6k9hU/YF2o From: Thomas Gleixner To finally fix the infamous leap second issue and other race windows caused by functions which change the offsets between the various time bases (CLOCK_MONOTONIC, CLOCK_REALTIME and CLOCK_BOOTTIME) we need a function which atomically gets the current monotonic time and updates the offsets of CLOCK_REALTIME and CLOCK_BOOTTIME with minimalistic overhead. The previous patch which provides ktime_t offsets allows us to make this function almost as cheap as ktime_get() which is going to be replaced in 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 --- include/linux/hrtimer.h | 1 + kernel/time/timekeeping.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 4c3dac8..25b214e 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -323,6 +323,7 @@ extern ktime_t ktime_get(void); extern ktime_t ktime_get_real(void); extern ktime_t ktime_get_boottime(void); extern ktime_t ktime_get_monotonic_offset(void); +extern ktime_t ktime_get_update_offsets(ktime_t *offs_real, ktime_t *offs_boot); DECLARE_PER_CPU(struct tick_device, tick_cpu_device); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 1c038da..269b1fe 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1271,6 +1271,40 @@ void get_xtime_and_monotonic_and_sleep_offset(struct timespec *xtim, } while (read_seqretry(&timekeeper.lock, seq)); } +#ifdef CONFIG_HIGH_RES_TIMERS +/** + * ktime_get_update_offsets - hrtimer helper + * @offs_real: pointer to storage for monotonic -> realtime offset + * @offs_boot: pointer to storage for monotonic -> boottime offset + * + * Returns current monotonic time and updates the offsets + * Called from hrtimer_interupt() or retrigger_next_event() + */ +ktime_t ktime_get_update_offsets(ktime_t *offs_real, ktime_t *offs_boot) +{ + ktime_t now; + unsigned int seq; + u64 secs, nsecs; + + do { + seq = read_seqbegin(&timekeeper.lock); + + secs = timekeeper.xtime.tv_sec; + nsecs = timekeeper.xtime.tv_nsec; + nsecs += timekeeping_get_ns(); + /* If arch requires, add in gettimeoffset() */ + nsecs += arch_gettimeoffset(); + + *offs_real = timekeeper.offs_real; + *offs_boot = timekeeper.offs_boot; + } while (read_seqretry(&timekeeper.lock, seq)); + + now = ktime_add_ns(ktime_set(secs, 0), nsecs); + now = ktime_sub(now, *offs_real); + return now; +} +#endif + /** * ktime_get_monotonic_offset() - get wall_to_monotonic in ktime_t format */