Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp341119pxb; Wed, 6 Oct 2021 06:13:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyymaroOjieviPoUOwDP6BiJrAJZlCxChoDWfuFoK6bw+Xyoaen2n0YI03QO3LvOdlVYd7m X-Received: by 2002:a17:902:7246:b0:138:a6ed:66cc with SMTP id c6-20020a170902724600b00138a6ed66ccmr11038447pll.22.1633525987451; Wed, 06 Oct 2021 06:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633525987; cv=none; d=google.com; s=arc-20160816; b=mWTBNRRQiQZn9840NFtn86ZThJSLpg12meWtoMWJfvQtj5sSJo8doHMD9H9jlupS01 Qu68wCdK7A6PSl6IEpY9E5rNIClJJMyr6g4zB7xhaNG/78heLrqmwAZWF8NpWdtljUcN zi0Wf+DN4RPsetwY7RyaYBYO7TWqmpC76qC39tlgCP3zNcOxYpp04fAX1I8FNtXVPAnr UaTuwYB70Afa5N1b6lktlPQAqsBUqdJxAnOAY4V4iwGI0SVnOBIeMHA9bRVjnGXWBTiw rd8nhT2Z2Ehkcsvdg2Hb9NA7XyCIhck53h9fHO2GCXrQpAYNlj80K/bokw+yuNNEqH+b 5SpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mI7xxwj+mBUooKpJkWS2Vk+yUURNXRcCn/QPZmJzSqg=; b=dUja9niYOhhDjIu5lMeX5KMnXQeXWcBkbrEuu+K8X2xWFtguFiSkV44PX8X8zuH48H UY0n66eGgT+bP7d0pRhRi4Mbyl0MRBxPVMI3x22K6YmG6bsTUuz/GM6xkvaTgxD/ZhFN TtZ0Na8Jo/403OFYZohxqE6fXPurU1snXtPBukC5cx4hNSbfN/NYnakZLDO+Wj8lxOD/ T1M0lVhhdbwi22GJCSU3PNpwkfv6OB5lTP/mXI2taJK7+2OYRPc8GuQqmc4dg1dkCTRY ZFxL/dY5TUkN5P73usV7abITLaXUdOil/Ccl2ypy8lgwqOAslB3/PJs+wn4azv0vg78D 4prA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uCtda1JS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u2si5550950pjc.58.2021.10.06.06.12.47; Wed, 06 Oct 2021 06:13:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uCtda1JS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231585AbhJFNN2 (ORCPT + 99 others); Wed, 6 Oct 2021 09:13:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbhJFNN1 (ORCPT ); Wed, 6 Oct 2021 09:13:27 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0047C061749 for ; Wed, 6 Oct 2021 06:11:34 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id x27so10315030lfu.5 for ; Wed, 06 Oct 2021 06:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mI7xxwj+mBUooKpJkWS2Vk+yUURNXRcCn/QPZmJzSqg=; b=uCtda1JSEXExVjMHnUmKdQ3BIdH/nb6dx+16B2rJDTOTZ5L+dl9pwjI6McHaDVs76T r1HkEACDjrLpNOmu14fvl+hUkN9q6wOBhJ0BTAAtXuMJaz/TFQtFcFzd5E4+z8175ja+ Nt2gYmOP5PvihienZx6bgrpNTgupaskzZLSWzuEVkCpLsCdQXg9vGZww5gS8J4xinCB5 WO1IY02bURGqitQC6AYQn0pzgdJF5PA4fsyaKm8yQBtmbAWTiNWWUIvHkmYHmZWqUGuk cWPvvWxhbtG6QAvG70+OmH/hNgGUTGMFhs+zIRWrkkywsfGMqoL1520a7BNo0Jkq55Fe 0Wpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mI7xxwj+mBUooKpJkWS2Vk+yUURNXRcCn/QPZmJzSqg=; b=pADOqYqiLdFcYQdBoUJgve5k+ZHIFCyaJjlhxKCwjYRt8c2eI3Pe5WXxVGVoH+G7ow q6Sf8n382n7PeBWhawzEitAKHw7538qsMPpXg/wfDKmjB/+95vTWq9/0OFCJS60m8ikv sl8mgN218p7FEF1ABB4+SMCO7+Mqq26T72EztU5SdaZ4jwEItfsodvM9p6Tr0uqOZyJy deV77mdwi6AIPdJb64jjclWDHrEEUBlVGeeDi2/zSRTqh0+uI3Jo2ulmJxi2NIhF7HDZ aklZYBK9nY+Mma6W3GXr+2bmr97PxfDBOftfydKOfGNiQETy6fSDmP6okV+mythvtBxP 1CNQ== X-Gm-Message-State: AOAM530NK6FV+DtNBO0CR893db2FURcKK/RsYHvWLqJYannzpizbXD2M yOTkGKRCNm/c0rt8pFRTgMdwMksgkHGvmrcim8BiOA== X-Received: by 2002:a19:5f4b:: with SMTP id a11mr9618060lfj.373.1633525892201; Wed, 06 Oct 2021 06:11:32 -0700 (PDT) MIME-Version: 1.0 References: <20210929144451.113334-1-ulf.hansson@linaro.org> <20210929144451.113334-2-ulf.hansson@linaro.org> <07e6821c-c221-e90d-c977-4d6b55c1ab8d@codeaurora.org> In-Reply-To: <07e6821c-c221-e90d-c977-4d6b55c1ab8d@codeaurora.org> From: Ulf Hansson Date: Wed, 6 Oct 2021 15:10:55 +0200 Message-ID: Subject: Re: [PATCH 1/2] cpuidle: Avoid calls to cpuidle_resume|pause() for s2idle To: Maulik Shah Cc: "Rafael J . Wysocki" , Daniel Lezcano , Linux PM , Peter Zijlstra , Vincent Guittot , Len Brown , Bjorn Andersson , Linux ARM , Linux Kernel Mailing List , Srinivas Rao L Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 6 Oct 2021 at 12:22, Maulik Shah wrote: > > Hi, > > On 9/29/2021 8:14 PM, Ulf Hansson wrote: > > In s2idle_enter(), cpuidle_resume|pause() are invoked to re-allow calls to > > the cpuidle callbacks during s2idle operations. This is needed because > > cpuidle is paused in-between in dpm_suspend_noirq() and dpm_resume_noirq(). > > > > However, calling cpuidle_resume|pause() from s2idle_enter() looks a bit > > superfluous, as it also causes all CPUs to be waken up when the first CPU > > wakes up from s2idle. > > Thanks for the patch. This can be good optimization to avoid waking up > all CPUs always. > > > > > Therefore, let's drop the calls to cpuidle_resume|pause() from > > s2idle_enter(). To make this work, let's also adopt the path in the > > cpuidle_idle_call() to allow cpuidle callbacks to be invoked for s2idle, > > even if cpuidle has been paused. > > > > Signed-off-by: Ulf Hansson > > --- > > drivers/cpuidle/cpuidle.c | 7 ++++++- > > include/linux/cpuidle.h | 2 ++ > > kernel/power/suspend.c | 2 -- > > kernel/sched/idle.c | 40 ++++++++++++++++++++++----------------- > > 4 files changed, 31 insertions(+), 20 deletions(-) > > > > diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c > > index ef2ea1b12cd8..c76747e497e7 100644 > > --- a/drivers/cpuidle/cpuidle.c > > +++ b/drivers/cpuidle/cpuidle.c > > @@ -49,7 +49,12 @@ void disable_cpuidle(void) > > bool cpuidle_not_available(struct cpuidle_driver *drv, > > struct cpuidle_device *dev) > > { > > - return off || !initialized || !drv || !dev || !dev->enabled; > > + return off || !drv || !dev || !dev->enabled; > > +} > > + > > +bool cpuidle_paused(void) > > +{ > > + return !initialized; > > } > > > > /** > > diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h > > index fce476275e16..51698b385ab5 100644 > > --- a/include/linux/cpuidle.h > > +++ b/include/linux/cpuidle.h > > @@ -165,6 +165,7 @@ extern void cpuidle_pause_and_lock(void); > > extern void cpuidle_resume_and_unlock(void); > > extern void cpuidle_pause(void); > > extern void cpuidle_resume(void); > > +extern bool cpuidle_paused(void); > > extern int cpuidle_enable_device(struct cpuidle_device *dev); > > extern void cpuidle_disable_device(struct cpuidle_device *dev); > > extern int cpuidle_play_dead(void); > > @@ -204,6 +205,7 @@ static inline void cpuidle_pause_and_lock(void) { } > > static inline void cpuidle_resume_and_unlock(void) { } > > static inline void cpuidle_pause(void) { } > > static inline void cpuidle_resume(void) { } > > +static inline bool cpuidle_paused(void) {return true; } > > static inline int cpuidle_enable_device(struct cpuidle_device *dev) > > {return -ENODEV; } > > static inline void cpuidle_disable_device(struct cpuidle_device *dev) { } > > diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c > > index eb75f394a059..388a5de4836e 100644 > > --- a/kernel/power/suspend.c > > +++ b/kernel/power/suspend.c > > @@ -97,7 +97,6 @@ static void s2idle_enter(void) > > raw_spin_unlock_irq(&s2idle_lock); > > > > cpus_read_lock(); > > - cpuidle_resume(); > > > > /* Push all the CPUs into the idle loop. */ > > wake_up_all_idle_cpus(); > > wake_up_all_idle_cpus() will still cause all CPUs to be woken up when > first cpu wakes up. > > say for example, > 1. device goes to s2idle suspend. > 2. one CPU wakes up to handle irq (irq is not a wake irq but left > enabled at GIC because of IRQF_NOSUSPEND flag) so such irq will not > break suspend. > 3. The cpu handles the irq. > 4. same cpu don't break s2idle_loop() and goes to s2idle_enter() where > it wakes up all existing idle cpus due to wake_up_all_idle_cpus() > 5. all of CPUs again enter s2idle. > > to avoid waking up all CPUs in above case, something like below snip may > help (i have not tested yet), > > when CPUs are in s2idle_loop(), > > 1. set the s2idle state to enter. > 2. wake up all cpus from shallow state, so that they can re-enter > deepest state. > 3. Forever loop until a break with some wake irq. > 4. clear the s2idle state. > 5. wake up all cpus from deepest state so that they can now stay in > shallow state/running state. > > void s2idle_loop(void) > { > > + s2idle_state = S2IDLE_STATE_ENTER; > + /* Push all the CPUs to enter deepest available state */ > + wake_up_all_idle_cpus(); > for (;;) { > if (s2idle_ops && s2idle_ops->wake) { > if (s2idle_ops->wake()) > .. > s2idle_enter(); > } > + s2idle_state = S2IDLE_STATE_NONE; > + /* Push all the CPUs to enter default_idle() from this point */ > + wake_up_all_idle_cpus(); > } Overall, I follow your reasoning above and I think it makes sense to me, but maybe Rafael has some concerns about it. Even if the above code needs some polishing, the logic seems reasonable to me. I suggest you post a patch, based on top of my small series, so we can discuss your suggested improvements separately. Or just tell me, if you would like me to do it. > > Thanks, > Maulik Thanks for reviewing! [...] Kind regards Uffe