From patchwork Fri Mar 27 17:14:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 46433 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3797721585 for ; Fri, 27 Mar 2015 17:16:36 +0000 (UTC) Received: by lajy8 with SMTP id y8sf1859199laj.3 for ; Fri, 27 Mar 2015 10:16:35 -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=ZRgoVT2dZFfRTuRou8eRtG9a2qlCKacXNEYCuMf4YvQ=; b=C5FoZj7UjqCK9SzIUFHvzbEeT3ZJ/ekUpJjkOvl9b+6KyOfArcr5IqSNeU84YmiAdB 3mPQzfTmvzAxqsAXk1rbbZDX6OIhPta/57URazp906zdN6Jn4Cu6iakOLNWCgdzmM4Ig S8L/HlWhjYSBxwPdn7USm+0Xd8wsJADjoNxxMPuJrMaFPUz6EC7HubMe/5cKpmRiJ8wT TGsJUa9CIb1wwWZ18kaqMQbxBppGEZ/wBb78AKxj/fS+fmeq9wrQBtnisyvz93MMal8G McXGjaIzsEdK/Vhc1DMZwClTZBf6v58LXnwyHWNh+gZgJYsgN94BFo2OHpZAQsgiqwCV C0Hg== X-Gm-Message-State: ALoCoQmWk9aiEA965arKudP+WJp1UOmfmPqBzMnc7LtOhJ80erQDl6I5twMR/nPLS1bzidvSZe3M X-Received: by 10.112.130.71 with SMTP id oc7mr695098lbb.13.1427476595000; Fri, 27 Mar 2015 10:16:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.36 with SMTP id n4ls348176laj.27.gmail; Fri, 27 Mar 2015 10:16:34 -0700 (PDT) X-Received: by 10.112.12.134 with SMTP id y6mr18959895lbb.34.1427476594586; Fri, 27 Mar 2015 10:16:34 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id n1si1778820lae.91.2015.03.27.10.16.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Mar 2015 10:16:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labto5 with SMTP id to5so75771967lab.0 for ; Fri, 27 Mar 2015 10:16:34 -0700 (PDT) X-Received: by 10.152.26.201 with SMTP id n9mr18334892lag.29.1427476594472; Fri, 27 Mar 2015 10:16:34 -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 k9csp9881lbq; Fri, 27 Mar 2015 10:16:33 -0700 (PDT) X-Received: by 10.66.65.203 with SMTP id z11mr27609633pas.95.1427476591098; Fri, 27 Mar 2015 10:16:31 -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.16.28; Fri, 27 Mar 2015 10:16:31 -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 S932155AbbC0RP1 (ORCPT + 27 others); Fri, 27 Mar 2015 13:15:27 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:36338 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753482AbbC0RPG (ORCPT ); Fri, 27 Mar 2015 13:15:06 -0400 Received: by padcy3 with SMTP id cy3so101197315pad.3 for ; Fri, 27 Mar 2015 10:15:05 -0700 (PDT) X-Received: by 10.66.221.34 with SMTP id qb2mr37285030pac.42.1427476505392; Fri, 27 Mar 2015 10:15:05 -0700 (PDT) Received: from localhost ([122.167.118.120]) by mx.google.com with ESMTPSA id rd7sm2713092pdb.85.2015.03.27.10.15.04 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 27 Mar 2015 10:15:04 -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 3/3] clockevents: Switch state to ONESHOT_STOPPED for unused clockevent devices Date: Fri, 27 Mar 2015 22:44:29 +0530 Message-Id: <98b55223ab29cd5fb9b1f4a384cb7edd86578ea5.1427475606.git.viresh.kumar@linaro.org> 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.215.42 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: , Clockevent device can now be stopped by switching to ONESHOT_STOPPED state, to avoid getting spurious interrupts on a tickless CPU. Switch state to 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. In LOWRES mode we skip reprogramming the clockevent device in tick_nohz_stop_sched_tick() if expires == KTIME_MAX. In addition to that we must also switch the clockevent device to ONESHOT_STOPPED state to avoid all spurious interrupts that may follow. 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. There are two places here from which we reprogram the clockevent device or skip reprogramming it on expires == KTIME_MAX. Signed-off-by: Viresh Kumar --- kernel/time/hrtimer.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- kernel/time/tick-sched.c | 3 +++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 045ba7e2be6c..89d4b593dfc0 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -543,8 +543,19 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) if (cpu_base->hang_detected) return; - if (cpu_base->expires_next.tv64 != KTIME_MAX) + if (cpu_base->expires_next.tv64 != KTIME_MAX) { tick_program_event(cpu_base->expires_next, 1); + } else { + struct clock_event_device *dev = + __this_cpu_read(tick_cpu_device.evtdev); + /* + * Don't need clockevent device anymore, stop it. + * + * We reach here only for NOHZ_MODE_HIGHRES mode and we are + * guaranteed that no timers/hrtimers are enqueued on this cpu. + */ + clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED); + } } /* @@ -1312,9 +1323,36 @@ void hrtimer_interrupt(struct clock_event_device *dev) cpu_base->in_hrtirq = 0; raw_spin_unlock(&cpu_base->lock); - /* Reprogramming necessary ? */ - if (expires_next.tv64 == KTIME_MAX || - !tick_program_event(expires_next, 0)) { + if (expires_next.tv64 == KTIME_MAX) { + struct clock_event_device *dev = + __this_cpu_read(tick_cpu_device.evtdev); + + cpu_base->hang_detected = 0; + + /* + * Don't need clockevent device anymore, stop it. + * + * We reach here only for NOHZ_MODE_HIGHRES mode and we are + * guaranteed that no timers/hrtimers are enqueued on this cpu. + * + * Most of the scenarios will be covered by similar code + * present in hrtimer_force_reprogram(), as we always try to + * evaluate tick requirement on idle/irq exit and cancel + * tick-sched hrtimer when tick isn't required anymore. + * + * It is required here as well as a special case. + * + * Last hrtimer fires on a tickless CPU and doesn't rearm + * itself. tick_nohz_irq_exit() reevaluates next event and it + * gets expires == KTIME_MAX. Because tick was already stopped, + * and last expires == new_expires, we return early. And the + * clockevent device is never stopped. + */ + clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED); + return; + } + + if (!tick_program_event(expires_next, 0)) { cpu_base->hang_detected = 0; return; } diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 47c04edd07df..ff271a26fa4d 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -685,6 +685,9 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts, if (unlikely(expires.tv64 == KTIME_MAX)) { if (ts->nohz_mode == NOHZ_MODE_HIGHRES) hrtimer_cancel(&ts->sched_timer); + else + /* stop clock event device */ + clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED); goto out; }