From patchwork Wed Sep 29 14:44:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 514855 Delivered-To: patches@linaro.org Received: by 2002:a05:6638:4087:0:0:0:0 with SMTP id m7csp96459jam; Wed, 29 Sep 2021 07:44:55 -0700 (PDT) X-Received: by 2002:a2e:4c09:: with SMTP id z9mr282671lja.241.1632926695436; Wed, 29 Sep 2021 07:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632926695; cv=none; d=google.com; s=arc-20160816; b=RWjMiP2JZldSB9pH/xKpMDaWxbb/E13ThebwfkvHAtCCVUOlt/Ylo/Chvvxr3bDDh1 ShiiloFhJ6bYJGtAlvKSw+lqoaww+BjOSTeyrq7Bhdl2bsY6ojITmlXZKrU4T0evTM+L /oSI4zhhR8ZkBWej3sLGm1Wd6/KhgId0fPiXMmsg+dDWOGU8remWnu78je3omQZ+6rT/ wKPJ5iBIX2f/2QjkAK26o/W10xzg3+9kWcuwrdEh1LoKTuC62+Jh4nR/w6czGJ82y1tU 1JTCyQiVegCQhhUmCjt34cUJTSWNYTeMB6CnVS+BapmJjcPgUWk3yoW2SJUcialnJFfE 84bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=ObMXohmKHbaPjr7B/fFVbkQWXBDEuU80sho6l7t/8yw=; b=cQCBoHVi0ftCxZG+bvZLb7LinKqggPoxLX8huM45dUfnQKcS0/pqjpedYjlPYUHgMD mia50PlFhW7SDTf/wwj0ziWQ0HLkkO+soQPLmB8XnYhJngSbk7cLwAHDJp7ySBSDnJkN d9XI9tbvo+NVOvIzKFvnReTnaIKl44NiqvOaqunJ37Ubi5PJsnbfIJ2NTzDiOxuuB5XX n0UW5vZ1geuHirB+lKxqZ3cfsd/wjEQkaXrtNF64PWqOdrp5/0RDIP44MPYt7srRvbIg mWkM2rU3rD+Ie38cb1ejU2E8hJBYGEcpeuVi+ook5u2jdrxio0iEvXUZjo9KUk/8BJ37 HZ7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qt3SQkMk; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id w22sor1262693ljw.22.2021.09.29.07.44.55 for (Google Transport Security); Wed, 29 Sep 2021 07:44:55 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qt3SQkMk; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ObMXohmKHbaPjr7B/fFVbkQWXBDEuU80sho6l7t/8yw=; b=Qt3SQkMkn9oR3E5nvk0LB4VlD/Iv+gDzeJ+mcn7bxpNqxdbSXJDEMFPiHamef5fq0L +897ot5UjYtarWL6Gmg6xEek1k2FYnC8jORoBkeZK5gW8jtAr6DUDVZTwphtYq+mIJUi VPgZyHmLs2EOX+QzqEIbQq1vX3oWOqO9Ql1b8dXpH5tFwwDzXM8lzLLlwDPFKgcq458N Guo+kNsNOetyHqsq8lUoxr7bnE1JsCDym3W6LrSseQHg1wIlSU62y0IOPIKHEb4reAqm awgPOphMhCT5uQeTxfN3eyPo63VGBSEnD3VOuLG/v6nLzdtAzkr4vQQzN69Ivyo9OhCE Qf/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ObMXohmKHbaPjr7B/fFVbkQWXBDEuU80sho6l7t/8yw=; b=Cam+89+GQ/4qx3zTfxNv78TSo8Y3sPvdfPynNGnPDugy7rRm4hFySAnm55TawLqGrj YWXm7kDGGnKru/GTPm1GwuyZAZrTVnkFa7nKqk7gbMjnTZPbw5AeZQDoD+jdkyGORQmM S1v9NT3PK2WDZA+g0fzBbDn4fLI4eKoHCkLdWf6FUqYhSHLeHUH5OU1YIKw+7CnpaWk6 pGpFQhMGqmh+8a1sfQNRzsRwpssk3MOXjNpbN7Gr73VPleN4tY1kOwCkSsY/f4olV6IA M2O9vw6Oot+rIXnEJuxrvE+chTbkT/UubA15R2HrhqR5koPFy2/W+/96RbbYBuKR5gnx nW6Q== X-Gm-Message-State: AOAM533Y840Ei+0zKz+UDOYHi42ymamKnFX4BDXbhbIl6UwJ0ryvZklq s2H08L6/hRntuLG14AuKse7EFboA X-Google-Smtp-Source: ABdhPJx14+UcR6O9ITJ5yjchMiAj7JKKZa40xBYE/WhHNCOiaiXO64w5lrJo/O5nbYoJcgAWu6tIQQ== X-Received: by 2002:a05:651c:50c:: with SMTP id o12mr352826ljp.86.1632926695013; Wed, 29 Sep 2021 07:44:55 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id g4sm9863ljk.64.2021.09.29.07.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 07:44:54 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , linux-pm@vger.kernel.org Cc: Maulik Shah , Peter Zijlstra , Vincent Guittot , Len Brown , Bjorn Andersson , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] cpuidle: Avoid calls to cpuidle_resume|pause() for s2idle Date: Wed, 29 Sep 2021 16:44:50 +0200 Message-Id: <20210929144451.113334-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210929144451.113334-1-ulf.hansson@linaro.org> References: <20210929144451.113334-1-ulf.hansson@linaro.org> MIME-Version: 1.0 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. 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(-) -- 2.25.1 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(); @@ -105,7 +104,6 @@ static void s2idle_enter(void) swait_event_exclusive(s2idle_wait_head, s2idle_state == S2IDLE_STATE_WAKE); - cpuidle_pause(); cpus_read_unlock(); raw_spin_lock_irq(&s2idle_lock); diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index d17b0a5ce6ac..3bc3a2c46731 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -158,6 +158,17 @@ static int call_cpuidle(struct cpuidle_driver *drv, struct cpuidle_device *dev, return cpuidle_enter(drv, dev, next_state); } +static void cpuidle_deepest_state(struct cpuidle_driver *drv, + struct cpuidle_device *dev, + u64 max_latency_ns) +{ + int next_state; + + tick_nohz_idle_stop_tick(); + next_state = cpuidle_find_deepest_state(drv, dev, max_latency_ns); + call_cpuidle(drv, dev, next_state); +} + /** * cpuidle_idle_call - the main idle function * @@ -189,6 +200,7 @@ static void cpuidle_idle_call(void) */ if (cpuidle_not_available(drv, dev)) { +default_idle: tick_nohz_idle_stop_tick(); default_idle_call(); @@ -204,25 +216,19 @@ static void cpuidle_idle_call(void) * timekeeping to prevent timer interrupts from kicking us out of idle * until a proper wakeup interrupt happens. */ + if (idle_should_enter_s2idle()) { + entered_state = call_cpuidle_s2idle(drv, dev); + if (entered_state <= 0) + cpuidle_deepest_state(drv, dev, U64_MAX); + goto exit_idle; + } - if (idle_should_enter_s2idle() || dev->forced_idle_latency_limit_ns) { - u64 max_latency_ns; - - if (idle_should_enter_s2idle()) { - - entered_state = call_cpuidle_s2idle(drv, dev); - if (entered_state > 0) - goto exit_idle; - - max_latency_ns = U64_MAX; - } else { - max_latency_ns = dev->forced_idle_latency_limit_ns; - } - - tick_nohz_idle_stop_tick(); + if (cpuidle_paused()) + goto default_idle; - next_state = cpuidle_find_deepest_state(drv, dev, max_latency_ns); - call_cpuidle(drv, dev, next_state); + if (dev->forced_idle_latency_limit_ns) { + cpuidle_deepest_state(drv, dev, + dev->forced_idle_latency_limit_ns); } else { bool stop_tick = true; From patchwork Wed Sep 29 14:44:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 514856 Delivered-To: patches@linaro.org Received: by 2002:a05:6638:4087:0:0:0:0 with SMTP id m7csp96480jam; Wed, 29 Sep 2021 07:44:57 -0700 (PDT) X-Received: by 2002:ac2:50da:: with SMTP id h26mr56717lfm.269.1632926696952; Wed, 29 Sep 2021 07:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632926696; cv=none; d=google.com; s=arc-20160816; b=z55+jRPMQUzfuj4rggfOU3ZqDY55cb80wGJZy6DDpcSN5BiAcWkYyJ2xkm0ubx771T bSYpIEycwzwK6+vKTNGRo3latcfA8QG/fsGi77mGXwj9Jun1Gdl9puU3QuSSfCpfQKmq Hm3123PfBpMzecU/dgU9I9w/YIktCRpvCZP4zJgPDkc67GzBtihG8EUS6fw1jKDN1xz7 4Pw81Xq40gUleNBk78FoGgEtZpqKCFntLST2ak5XKcFoJ7XoVwxkto38JZ+laNxZK7+w W9IvnuBOP/dpxm6rUoqFkVp0c6kKp9WjmSLH9NEyuTPRVRs29Ee6rXEcc+T874nuXcRY O/4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=jI512TbeQgh2FYrW2/MewJZ0e3lJuCvLMPJwgkXNatc=; b=08s1tK6ep0LzG9/lOqKtCsW9Ld6lvEoMmAz9eH5AFSOpJYKuDtc9iqn6C3bC8kOqMH cGgumbXK/Uo94YfidKtcI3S93oBEjqNl3b3AQOvbctOtpA1AjACljRVNQYZ/Pn3Pvg52 2mi16R/FwV3WAkx5oLTcUTPNoN1+F/183JhOJoYEsDKREfFnm9ry5TSK4N0dSLbnEr4x QADA6uTb39zR+EGzWMox17o3q39Efj2HsaiEhGWs4hJI43tpy/t8jhSNEAQsKJ5sLC3o mlXv6q9D3oIy/biGnhiOO14rN2CwlB/bzo0vwZtnTomeOK2XLHckxdVayuEUJtjZcRol KlUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uJy2BNUq; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id k5sor1238640ljj.71.2021.09.29.07.44.56 for (Google Transport Security); Wed, 29 Sep 2021 07:44:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uJy2BNUq; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jI512TbeQgh2FYrW2/MewJZ0e3lJuCvLMPJwgkXNatc=; b=uJy2BNUqQw+BJyvO/Zh9fJeegstwdqNEGh1Ckjo/E3TaoDaiOXk7emJ0v4f2cq+KdJ 1hyllL8m7Na7397VPTNeTYOUN0JKOnBSQqT8PXNvL6fvPM4etcvF3talSs1L4MuEOYIj ORbd+bs0RKplK3xfdWSlb2bNOVOOhgZlrmF3MBoh6zbhvqaDRNoirQ0dVCw478a/gPTD KhW6uj0uMsO19BubBS9i5MCUcjN5XHuFbSpOq8pmIR/xbQklgT2g0XgE6YslcomcAmF8 SbfkwV8g5cZcKPss9NjFJKsGNXUvNfYCRCd6i4kNP2AOIoRfLTgQ8MhZFmR4KoGMb274 b/sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jI512TbeQgh2FYrW2/MewJZ0e3lJuCvLMPJwgkXNatc=; b=muQP7RQb7WmBxQUj9Abvey/laYyRiuBvZMzO2kpbKs+Zu0wmdXW5rxEG66xyDJZsgw jeZr9G4NKDMLR5zDnDqGuSY8V8thuKlF1n4Asl60S5/gGq2TYMOYS+0BpFoVKghwUVWK tiyY4Isgu3GcAMaKvj8BM1HZF8G3kgJOPCRSot4/G5a1xB67lgOXVlWXTK2A+N0a8+29 B0nhsQHxG4lktrN1tsBUb1nj8Jvcp1tYCXFqbKdXXq+zi/AFdOWrHQkL8Vu4kyFeRPw2 cKWszd2sjIhfXOsZWag0WcTP3+e956BBgq/oRy0QrQeXJdV4BaCt5elknCQSOTGBsbIH LLLA== X-Gm-Message-State: AOAM533CwZ/JxBfOMbMmOExF7uOGU12GgNWHPXo51D0TMDlFaM0fe5ar wdNRyPQh8+Fp26cj4aX0OvBBlTFrwrRW37Vb X-Google-Smtp-Source: ABdhPJz81MaqezsB00jcBTdcVIWyNKeqSu5DcUQ8vyT5t7reV63l4XQLO+5zErmsmpzlDbBEZrvCpw== X-Received: by 2002:a2e:9a07:: with SMTP id o7mr302931lji.125.1632926696590; Wed, 29 Sep 2021 07:44:56 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id g4sm9863ljk.64.2021.09.29.07.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 07:44:55 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , linux-pm@vger.kernel.org Cc: Maulik Shah , Peter Zijlstra , Vincent Guittot , Len Brown , Bjorn Andersson , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] PM: sleep: Fix runtime PM based cpuidle support Date: Wed, 29 Sep 2021 16:44:51 +0200 Message-Id: <20210929144451.113334-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210929144451.113334-1-ulf.hansson@linaro.org> References: <20210929144451.113334-1-ulf.hansson@linaro.org> MIME-Version: 1.0 In the cpuidle-psci case, runtime PM in combination with the generic PM domain (genpd), may be used when entering/exiting an idlestate. More precisely, genpd relies on runtime PM to be enabled for the attached device (in this case it belongs to a CPU), to properly manage the reference counting of its PM domain. This works fine most of the time, but during system suspend in the dpm_suspend_late() phase, the PM core disables runtime PM for all devices. Beyond this point and until runtime PM becomes re-enabled in the dpm_resume_early() phase, calls to pm_runtime_get|put*() will fail. To make sure the reference counting in genpd becomes correct, we need to prevent cpuidle-psci from using runtime PM when it has been disabled for the device. Therefore, let's move the call to cpuidle_pause() from dpm_suspend_noirq() to dpm_suspend_late() - and cpuidle_resume() from dpm_resume_noirq() into dpm_resume_early(). Diagnosed-by: Maulik Shah Suggested-by: Maulik Shah Signed-off-by: Ulf Hansson --- drivers/base/power/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.25.1 Reviewed-by: Maulik Shah diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index cbea78e79f3d..1c753b651272 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -747,8 +747,6 @@ void dpm_resume_noirq(pm_message_t state) resume_device_irqs(); device_wakeup_disarm_wake_irqs(); - - cpuidle_resume(); } /** @@ -870,6 +868,7 @@ void dpm_resume_early(pm_message_t state) } mutex_unlock(&dpm_list_mtx); async_synchronize_full(); + cpuidle_resume(); dpm_show_time(starttime, state, 0, "early"); trace_suspend_resume(TPS("dpm_resume_early"), state.event, false); } @@ -1336,8 +1335,6 @@ int dpm_suspend_noirq(pm_message_t state) { int ret; - cpuidle_pause(); - device_wakeup_arm_wake_irqs(); suspend_device_irqs(); @@ -1467,6 +1464,7 @@ int dpm_suspend_late(pm_message_t state) int error = 0; trace_suspend_resume(TPS("dpm_suspend_late"), state.event, true); + cpuidle_pause(); mutex_lock(&dpm_list_mtx); pm_transition = state; async_error = 0;