From patchwork Tue Apr 17 10:46:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 10344761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC32660542 for ; Tue, 17 Apr 2018 10:47:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB53E28A4E for ; Tue, 17 Apr 2018 10:47:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFDB628A58; Tue, 17 Apr 2018 10:47:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1734628A29 for ; Tue, 17 Apr 2018 10:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ZrrYOGifIn/at4ebTZH0a+0kCazSDApwl9mtSxUr/Tk=; b=s0+ TODCkQjjS0EXKDaZcWrXojcZwa4/zE/CPpDCVdGF7r1jieNwbBvSnWycuVgBwsdCVJqDHos+8hYXV LMyveW6C8BR70IhCeFLAj3jo65s28nWhxbGMhNQQKn9GmG+kArbI+o+2AupnjEeJpD02m5pHk/tdI K1j5Yp9O+4xC2se9JxTisPCVAWOAU4BwWNGOFK+ac9kHXNLabO637Z8PS/cPFrjHjTbb53e/qlp7c cCV4xwfhSXLByawVhi7WkAX50qPYgTOFJMof2isLw9dNJO+MmSkZ0REaZF/CuMMDc8ntv+qSl27Ed /kf9SApsjzik5B5OFD7ny6C/JmLav2w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f8O8e-0006vT-VZ; Tue, 17 Apr 2018 10:47:04 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f8O8K-00063u-M8 for linux-arm-kernel@lists.infradead.org; Tue, 17 Apr 2018 10:47:00 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7] helo=dude.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1f8O85-0006wQ-C0; Tue, 17 Apr 2018 12:46:29 +0200 From: Lucas Stach To: Russell King , Daniel Lezcano Subject: [PATCH] arm/twd: avoid waking deeply sleeping CPUs for rate change notifier Date: Tue, 17 Apr 2018 12:46:27 +0200 Message-Id: <20180417104627.29643-1-l.stach@pengutronix.de> X-Mailer: git-send-email 2.16.3 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180417_034644_912645_0A4239E3 X-CRM114-Status: GOOD ( 14.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, patchwork-lst@pengutronix.de MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The current clock notifier sends an IPI to all CPUs, even if they are in deep sleep state with the local timer disabled and switched to tick broadcast. This needlessly cuts the CPU sleep times, as nothing is gained from updating a disabled TWDs rate. Keep track of the enabled TWDs and only send an IPI to those CPUs with an active local timer. As disabled TWDs may now miss a CPU frequency update we need to make sure to refresh the rate on re-enabling of the timer. Signed-off-by: Lucas Stach --- arch/arm/kernel/smp_twd.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index b30eafeef096..a3be30d30cc2 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c @@ -32,6 +32,8 @@ static struct clk *twd_clk; static unsigned long twd_timer_rate; static DEFINE_PER_CPU(bool, percpu_setup_called); +static cpumask_var_t active_twd_mask; + static struct clock_event_device __percpu *twd_evt; static unsigned int twd_features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; @@ -39,12 +41,24 @@ static int twd_ppi; static int twd_shutdown(struct clock_event_device *clk) { + cpumask_clear_cpu(smp_processor_id(), active_twd_mask); + writel_relaxed(0, twd_base + TWD_TIMER_CONTROL); return 0; } static int twd_set_oneshot(struct clock_event_device *clk) { + cpumask_set_cpu(smp_processor_id(), active_twd_mask); + + /* + * When going from shutdown to oneshot we might have missed some + * frequency updates if the CPU was sleeping. Make sure to update + * the timer frequency with the current rate. + */ + if (clockevent_state_shutdown(clk)) + clockevents_update_freq(clk, twd_timer_rate); + /* period set, and timer enabled in 'next_event' hook */ writel_relaxed(TWD_TIMER_CONTROL_IT_ENABLE | TWD_TIMER_CONTROL_ONESHOT, twd_base + TWD_TIMER_CONTROL); @@ -57,6 +71,16 @@ static int twd_set_periodic(struct clock_event_device *clk) TWD_TIMER_CONTROL_IT_ENABLE | TWD_TIMER_CONTROL_PERIODIC; + cpumask_set_cpu(smp_processor_id(), active_twd_mask); + + /* + * When going from shutdown to periodic we might have missed some + * frequency updates if the CPU was sleeping. Make sure to update + * the timer frequency with the current rate. + */ + if (clockevent_state_shutdown(clk)) + clockevents_update_freq(clk, twd_timer_rate); + writel_relaxed(DIV_ROUND_CLOSEST(twd_timer_rate, HZ), twd_base + TWD_TIMER_LOAD); writel_relaxed(ctrl, twd_base + TWD_TIMER_CONTROL); @@ -124,8 +148,8 @@ static int twd_rate_change(struct notifier_block *nb, * changing cpu. */ if (flags == POST_RATE_CHANGE) - on_each_cpu(twd_update_frequency, - (void *)&cnd->new_rate, 1); + on_each_cpu_mask(active_twd_mask, twd_update_frequency, + (void *)&cnd->new_rate, 1); return NOTIFY_OK; } @@ -326,6 +350,9 @@ static int __init twd_local_timer_common_register(struct device_node *np) { int err; + if (!zalloc_cpumask_var(&active_twd_mask, GFP_KERNEL)) + return -ENOMEM; + twd_evt = alloc_percpu(struct clock_event_device); if (!twd_evt) { err = -ENOMEM;