From patchwork Tue Jul 17 22:05:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john stultz X-Patchwork-Id: 10093 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 3DBBA24036 for ; Tue, 17 Jul 2012 22:05:52 +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 0D657A1825B for ; Tue, 17 Jul 2012 22:05:51 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so1056593ghb.11 for ; Tue, 17 Jul 2012 15:05:51 -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=kX2QudJNaplJThZmscAu5ozz9eu6fSM4Dd4CyiGs+rE=; b=D3SQsVsm7FJbimSZ09TI4XJsWoIrja1r6YQz9libE0h5GQC5UlXNe6Rg5C0JXQ8Ezb i5mjx7QJkJhCp+zpn8PsXD5mbIbAQHot5Cv4BVAOINegjh2h8i4HFCAyfZR9WiwdJt3p keADV9eKgO/iZx1eYml8YCNj9POpVV7xDKv8nObYW56ilsBX+qUg8KoduIYddyv9kWrw kpo7o00TrWwPD+zHwSE4yWfOOSkAdLtT/TCGAJMqrcIKmGyaEEXUb2i9aZ/WX71+XYSQ HHBAW4hQtyQk/I1w7uiOFTb/CSvSEd1ykCDbahNJw2V3rBbPtH0y+wQ65xSeHXuULb44 JYdw== Received: by 10.50.46.232 with SMTP id y8mr187477igm.57.1342562751712; Tue, 17 Jul 2012 15:05:51 -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 lc2csp25042ibb; Tue, 17 Jul 2012 15:05:49 -0700 (PDT) Received: by 10.42.145.7 with SMTP id d7mr2440124icv.45.1342562748607; Tue, 17 Jul 2012 15:05:48 -0700 (PDT) Received: from e5.ny.us.ibm.com (e5.ny.us.ibm.com. [32.97.182.145]) by mx.google.com with ESMTPS id xs9si18236448igb.19.2012.07.17.15.05.48 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Jul 2012 15:05:48 -0700 (PDT) Received-SPF: pass (google.com: domain of johnstul@us.ibm.com designates 32.97.182.145 as permitted sender) client-ip=32.97.182.145; Authentication-Results: mx.google.com; spf=pass (google.com: domain of johnstul@us.ibm.com designates 32.97.182.145 as permitted sender) smtp.mail=johnstul@us.ibm.com Received: from /spool/local by e5.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Jul 2012 18:05:47 -0400 Received: from d01dlp03.pok.ibm.com (9.56.224.17) by e5.ny.us.ibm.com (192.168.1.105) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 17 Jul 2012 18:05:45 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 39F9CC90076 for ; Tue, 17 Jul 2012 18:05:44 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6HM5hrN46792730 for ; Tue, 17 Jul 2012 18:05:43 -0400 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 q6HM5hbQ022970 for ; Tue, 17 Jul 2012 19:05:43 -0300 Received: from kernel.stglabs.ibm.com (kernel.stglabs.ibm.com [9.114.214.19]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6HM5hMd022948; Tue, 17 Jul 2012 19:05:43 -0300 From: John Stultz To: stable@vger.kernel.org Cc: John Stultz , Thomas Gleixner , Prarit Bhargava , Linux Kernel Subject: [PATCH 05/11] 2.6.32.x: hrtimer: Provide clock_was_set_delayed() Date: Tue, 17 Jul 2012 18:05:29 -0400 Message-Id: <1342562735-55870-6-git-send-email-johnstul@us.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1342562735-55870-1-git-send-email-johnstul@us.ibm.com> References: <1342562735-55870-1-git-send-email-johnstul@us.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12071722-5930-0000-0000-000009F67FAD X-Gm-Message-State: ALoCoQkOEJkKVBlqCLuCQBqIW7exkR82sKud7PGfDNoFt+bvgd4foDxHa/Bi+YnZJ5UKBr6i9CUF This is a backport of f55a6faa384304c89cfef162768e88374d3312cb clock_was_set() cannot be called from hard interrupt context because it calls on_each_cpu(). For fixing the widely reported leap seconds issue it is necessary to call it from hard interrupt context, i.e. the timer tick code, which does the timekeeping updates. Provide a new function which denotes it in the hrtimer cpu base structure of the cpu on which it is called and raise the hrtimer softirq. We then execute the clock_was_set() notificiation from softirq context in run_hrtimer_softirq(). The hrtimer softirq is rarely used, so polling the flag there is not a performance issue. [ tglx: Made it depend on CONFIG_HIGH_RES_TIMERS. We really should get rid of all this ifdeffery ASAP ] Signed-off-by: John Stultz Reported-by: Jan Engelhardt 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-2-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 --- include/linux/hrtimer.h | 7 +++++++ kernel/hrtimer.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h index 040b679..a7f48af 100644 --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -159,6 +159,7 @@ struct hrtimer_clock_base { * and timers * @clock_base: array of clock bases for this cpu * @curr_timer: the timer which is executing a callback right now + * @clock_was_set: Indicates that clock was set from irq context. * @expires_next: absolute time of the next event which was scheduled * via clock_set_next_event() * @hres_active: State of high resolution mode @@ -171,6 +172,7 @@ struct hrtimer_clock_base { struct hrtimer_cpu_base { spinlock_t lock; struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES]; + unsigned int clock_was_set; #ifdef CONFIG_HIGH_RES_TIMERS ktime_t expires_next; int hres_active; @@ -280,6 +282,8 @@ extern void hrtimer_peek_ahead_timers(void); # define MONOTONIC_RES_NSEC HIGH_RES_NSEC # define KTIME_MONOTONIC_RES KTIME_HIGH_RES +extern void clock_was_set_delayed(void); + #else # define MONOTONIC_RES_NSEC LOW_RES_NSEC @@ -308,6 +312,9 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer) { return 0; } + +static inline void clock_was_set_delayed(void) { } + #endif extern ktime_t ktime_get(void); diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index a6e9d00..c4acec7 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c @@ -738,6 +738,19 @@ static int hrtimer_switch_to_hres(void) return 1; } +/* + * Called from timekeeping code to reprogramm the hrtimer interrupt + * device. If called from the timer interrupt context we defer it to + * softirq context. + */ +void clock_was_set_delayed(void) +{ + struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); + + cpu_base->clock_was_set = 1; + __raise_softirq_irqoff(HRTIMER_SOFTIRQ); +} + #else static inline int hrtimer_hres_active(void) { return 0; } @@ -1393,6 +1406,13 @@ void hrtimer_peek_ahead_timers(void) static void run_hrtimer_softirq(struct softirq_action *h) { + struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); + + if (cpu_base->clock_was_set) { + cpu_base->clock_was_set = 0; + clock_was_set(); + } + hrtimer_peek_ahead_timers(); }