From patchwork Fri Mar 27 17:14:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 46432 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8228821585 for ; Fri, 27 Mar 2015 17:16:31 +0000 (UTC) Received: by lbbug6 with SMTP id ug6sf12075700lbb.3 for ; Fri, 27 Mar 2015 10:16:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=t10eb2CeZp72u0h+LTvi7r2T9JeqZqpRd8LVyDDQDhI=; b=QLoB+1aFNd3hGdUvLZPYgTVi68Z41mFX+o5F6Hb1q2wRFawLuR3Ltl2EqbRpy+820Y HRx7TXWYdYSWVHLBS0MPGSEb8WiGFL297C5ARQOXJvCYvqaFGGVhXfM48etX3rLxapte ZI6AZSaQj+JYZ/FqwSWfELIWmhetid5jfYohfHZcK/dzwcHxjnNTn+iaw4cGH7xP7b4y 3jW/ngfExP+aFnBlCKUD4T2LrgxPafJsPEh9OW1h9xI1pO/IRA9CvSWsX7zmwmQj0FjD 6e6RaE0sbIp6cwmSTq0CjX9a15sYErCbSIAPyxeELPHFf9h6egeazY4mkFfi2Lx/nEI4 sH9w== X-Gm-Message-State: ALoCoQnXGdUCz2USgljCVE2eSKGwsypaV2J5m+3aBRAdTsiJcvg6+9AgSIl81BbddORCkOemssEh X-Received: by 10.112.122.97 with SMTP id lr1mr3771921lbb.5.1427476590213; Fri, 27 Mar 2015 10:16:30 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.200 with SMTP id d8ls365374laa.34.gmail; Fri, 27 Mar 2015 10:16:30 -0700 (PDT) X-Received: by 10.112.168.163 with SMTP id zx3mr17567633lbb.46.1427476590040; Fri, 27 Mar 2015 10:16:30 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id dc8si1783380lad.65.2015.03.27.10.16.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Mar 2015 10:16:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbcmq2 with SMTP id mq2so68397188lbc.0 for ; Fri, 27 Mar 2015 10:16:29 -0700 (PDT) X-Received: by 10.152.120.134 with SMTP id lc6mr18356312lab.72.1427476589774; Fri, 27 Mar 2015 10:16:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp9839lbq; Fri, 27 Mar 2015 10:16:28 -0700 (PDT) X-Received: by 10.68.248.98 with SMTP id yl2mr36485952pbc.41.1427476587885; Fri, 27 Mar 2015 10:16:27 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si3645293pda.134.2015.03.27.10.15.57; Fri, 27 Mar 2015 10:16:27 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753513AbbC0RPI (ORCPT + 27 others); Fri, 27 Mar 2015 13:15:08 -0400 Received: from mail-pd0-f170.google.com ([209.85.192.170]:36696 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753095AbbC0RPB (ORCPT ); Fri, 27 Mar 2015 13:15:01 -0400 Received: by pdcp1 with SMTP id p1so10672151pdc.3 for ; Fri, 27 Mar 2015 10:15:01 -0700 (PDT) X-Received: by 10.68.221.226 with SMTP id qh2mr37398937pbc.1.1427476501256; Fri, 27 Mar 2015 10:15:01 -0700 (PDT) Received: from localhost ([122.167.118.120]) by mx.google.com with ESMTPSA id su5sm2719714pbc.38.2015.03.27.10.14.59 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 27 Mar 2015 10:15:00 -0700 (PDT) From: Viresh Kumar To: Ingo Molnar , Peter Zijlstra , Thomas Gleixner Cc: linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, Kevin Hilman , Daniel Lezcano , Preeti U Murthy , Frederic Weisbecker , Viresh Kumar Subject: [PATCH 2/3] clockevents: Restart clockevent device before using it again Date: Fri, 27 Mar 2015 22:44:28 +0530 Message-Id: X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Next commit would update clockevents core to switch clockevent devices to ONESHOT_STOPPED state to avoid getting spurious interrupts on a tickless CPU. Before programming the clockevent device for next event, we must switch its state to ONESHOT. Switch state back to ONESHOT from ONESHOT_STOPPED at following places: 1.) NOHZ_MODE_LOWRES Mode Timers & hrtimers are dependent on tick for their working in this mode and the only place from where clockevent device is programmed is the tick-code. Two routines can restart ticks in LOWRES mode: tick_nohz_restart() and tick_nohz_stop_sched_tick(). 2.) NOHZ_MODE_HIGHRES Mode Tick & timers are dependent on hrtimers for their working in this mode and the only place from where clockevent device is programmed is the hrtimer-code. Only hrtimer_reprogram() is responsible for programming the clockevent device for next event, if the clockevent device is stopped earlier. And updating that alone is sufficient here. To make sure we haven't missed any corner case, add a WARN() for the case where we try to reprogram clockevent device while we aren't configured in ONESHOT_STOPPED state. Signed-off-by: Viresh Kumar --- kernel/time/clockevents.c | 4 ++++ kernel/time/hrtimer.c | 5 +++++ kernel/time/tick-sched.c | 14 +++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index 04f6c3433f8e..e95896fd21fd 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c @@ -335,6 +335,10 @@ int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, if (dev->state == CLOCK_EVT_STATE_SHUTDOWN) return 0; + /* We must be in ONESHOT state here */ + WARN_ONCE(dev->state != CLOCK_EVT_STATE_ONESHOT, "Current state: %d\n", + dev->state); + /* Shortcut for clockevent devices that can deal with ktime. */ if (dev->features & CLOCK_EVT_FEAT_KTIME) return dev->set_next_ktime(expires, dev); diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index bee0c1f78091..045ba7e2be6c 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -566,6 +566,7 @@ static int hrtimer_reprogram(struct hrtimer *timer, { struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); ktime_t expires = ktime_sub(hrtimer_get_expires(timer), base->offset); + struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); int res; WARN_ON_ONCE(hrtimer_get_expires_tv64(timer) < 0); @@ -610,6 +611,10 @@ static int hrtimer_reprogram(struct hrtimer *timer, if (cpu_base->hang_detected) return 0; + /* Switchback to ONESHOT state */ + if (unlikely(dev->state == CLOCK_EVT_STATE_ONESHOT_STOPPED)) + clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT); + /* * Clockevents returns -ETIME, when the event was in the past. */ diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index a4c4edac4528..47c04edd07df 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -694,8 +694,14 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts, /* Check, if the timer was already in the past */ if (hrtimer_active(&ts->sched_timer)) goto out; - } else if (!tick_program_event(expires, 0)) + } else { + /* Switchback to ONESHOT state */ + if (unlikely(dev->state == CLOCK_EVT_STATE_ONESHOT_STOPPED)) + clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT); + + if (!tick_program_event(expires, 0)) goto out; + } /* * We are past the event already. So we crossed a * jiffie boundary. Update jiffies and raise the @@ -873,6 +879,8 @@ ktime_t tick_nohz_get_sleep_length(void) static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) { + struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); + hrtimer_cancel(&ts->sched_timer); hrtimer_set_expires(&ts->sched_timer, ts->last_tick); @@ -887,6 +895,10 @@ static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) if (hrtimer_active(&ts->sched_timer)) break; } else { + /* Switchback to ONESHOT state */ + if (likely(dev->state == CLOCK_EVT_STATE_ONESHOT_STOPPED)) + clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT); + if (!tick_program_event( hrtimer_get_expires(&ts->sched_timer), 0)) break;