From patchwork Fri Mar 14 10:00:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14016552 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7A92CC282EC for ; Fri, 14 Mar 2025 10:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yxXrWuszmkPt9+jWh/jp7RjsQBBCWLjTzHixGfM6EZE=; b=tE1YuNfpJ9vJVwifOQJquOtHHL LzebJ69jvuTxGHifIHuuBuY0aWAjUjS9YRCROkFTCMOHE31hSpIjOsSnLt+H2haWuKD/dD8DTR8yn UyYmiwgCZvhKbTg3qyjBzTQS03bnVs3QskOQfjaCGiEiT/PQ0MJpE55pQ3oJb7FJytaSmLwSymzfp ejVbv34P9vygOSI0I04uaKMjlSKZiNCA1fhPSl/1kPcs/Lq7WrHfyNiwQI4fI6PiqxPwj4PTPLIQN l9rLU9vrSgrpZl53cPYjj3lPjHrjc3AbM7+5qNqx8qmvsjPUNQt5ANRalHkUMfQ3N76oiplrcckV6 Em06Q7gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tt1wi-0000000DmPo-0AqC; Fri, 14 Mar 2025 10:07:16 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tt1qz-0000000Dl2O-1Ius for linux-arm-kernel@lists.infradead.org; Fri, 14 Mar 2025 10:01:22 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-549963b5551so1880883e87.2 for ; Fri, 14 Mar 2025 03:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741946479; x=1742551279; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yxXrWuszmkPt9+jWh/jp7RjsQBBCWLjTzHixGfM6EZE=; b=dWowXyth6zRH15jIsSaE48cvumegICj4UjhDaIlwvPBF5dDCf40S50tYfTqDYxZzLz HS2QGLcp1tBXpgu1dH7ITo1mFu8PlPSqCb1qlE/txf9n18EZBUsW0ozsSStIBRQtP8ua /PtNNPMNnwdbITXiVuUtNCTjMEUl6XicWLMmWuFjY5pfivbAiGBZ37KvK3MSIhKIuN/A F37hU4fFRE7dl+cpmCGWRrsOR16iNzVim8xtAlQmwikISMIEtEYY2dFn5XBSUJxJBHZl oJ6IWdxJcqPh84o0NjdhwYQAe5UgXxwR0fDnO9WrHnqaCf0ZtBERVlQxGovoKaFZ4CVp 1oAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741946479; x=1742551279; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yxXrWuszmkPt9+jWh/jp7RjsQBBCWLjTzHixGfM6EZE=; b=jPjz+2gXFBElfOCMpx9aAU+1eg/eDMc2a5kqhjL3wHa3CjhLgq94E3lFFldvvON5yc n76xXCgMFrc1yLFax8spPM57hLX1/u/ETKe/OEPV/Vv0EwERb7XIMnmB/IAJSv0MHV4d W8pInnTn9gaJ9Q6FUmXUpE4Nw1xKcdkd9esZuN6FYRn0t51YWYoxLRS2qQiS+xiiFM8l Op73X7qgF+A1Hs18DOAPXXJy1KKRFsujwlqNhDhlxfmac4zgoH1WIV8Zj6YdP4E5PCW5 5nngVGFtEkbOHFkNnwAWx6RepsHvUhLMqNWMoYiLM3RJy9GMjpogYwmomWenUhkIyYE1 1f/g== X-Forwarded-Encrypted: i=1; AJvYcCVvhjiW/f18aN4M63sSaJFfpJIGypLToPbee9vrqASoHSWJnYainm+tQxPcjVP5dtU5eY0oZEnfOxn6Tc1urgs1@lists.infradead.org X-Gm-Message-State: AOJu0YwmNL45eB+w4ncSQr5WzJFDhZymaJpsMk1F7vqDcZW+43qbClQ+ Tz45q/nSM+eGNED4+NfAq5VXcWd5sVfqgsHfot304nk37UkPyRf3kiKtT0HACA0= X-Gm-Gg: ASbGncsEkpyUO6uO9pteAOs87NBJbYH50bFAGe2dQ/fExTi/k67PtcHRDoKEcuFyA0c EVLhCHFbZzRS6mQn0rSaNnzsYR8BMzwZVL7cbOJ6To37IX4rZPSR+OePmTnI8FxCe+VpEXBnLhZ aN2y2K1ZJJJ8+JpxFvyV4Z6SYpZs0jL24omWog0GqZK8sqD5ANPhQMIWxItZ6L2GzV0Bsp/huzY gGNs4JOabRRML+x/AqMfCLKApyriesEldALbW/5k8/r2eQESdhHtpYy00mRi5va9MqUqvR9Oe6b /5PUO9whzKuhO9e7jKpPbGaiSXHRmUaxuqbPpv6wqktUb+cLTnnGKpvNdF/J30+FjTik1hpn4Sa JxcVDt/++VKEo5PtIYcvacXzRTRn10w== X-Google-Smtp-Source: AGHT+IGI4U+6gFVGvMxY7c2ZChVVcSTAYz3qWc9D46+/1FYmNXR+U/zCzRxHxW++97VulyB6QhEBRA== X-Received: by 2002:a05:6512:238d:b0:549:8d8d:2c62 with SMTP id 2adb3069b0e04-549c396e3d9mr653362e87.36.1741946479167; Fri, 14 Mar 2025 03:01:19 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30c3f0ea468sm5168221fa.41.2025.03.14.03.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 03:01:18 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , linux-pm@vger.kernel.org Cc: Lorenzo Pieralisi , Daniel Lezcano , Anup Patel , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] pmdomain: core: Add genpd helper to correct the usage/rejected counters Date: Fri, 14 Mar 2025 11:00:55 +0100 Message-ID: <20250314100103.1294715-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314100103.1294715-1-ulf.hansson@linaro.org> References: <20250314100103.1294715-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250314_030121_350486_07DE538D X-CRM114-Status: GOOD ( 15.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In the cpuidle-psci-domain case the ->power_off() callback is usually returning zero to indicate success. This is because the actual call to the PSCI FW to enter the selected domain-idlestate, needs to be done after the ->power_off() callback has returned. When the call to the PSCI FW fails, this leads to receiving an incorrect tracking of the usage/rejected counts for the selected domain-idlestate. In other words, the presented debug-statistics for genpd may look better than what the actually are. To allow a better correctness of the data, let's add a new genpd helper function, which enables the caller adjust the usage/rejected counters for a domain-idlestate, in cases of errors during power-off. Signed-off-by: Ulf Hansson --- drivers/pmdomain/core.c | 25 +++++++++++++++++++++++++ include/linux/pm_domain.h | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 9b2f28b34bb5..c79ef6e3ab85 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -728,6 +728,31 @@ int dev_pm_genpd_rpm_always_on(struct device *dev, bool on) } EXPORT_SYMBOL_GPL(dev_pm_genpd_rpm_always_on); +/** + * pm_genpd_inc_rejected() - Adjust the rejected/usage counts for an idle-state. + * + * @genpd: The PM domain the idle-state belongs to. + * @state_idx: The index of the idle-state that failed. + * + * In some special cases the ->power_off() callback is asynchronously powering + * off the PM domain, leading to that it may return zero to indicate success, + * even though the actual power-off could fail. To account for this correctly in + * the rejected/usage counts for the idle-state statistics, users can call this + * function to adjust the values. + * + * It is assumed that the users guarantee that the genpd doesn't get removed + * while this routine is getting called. + */ +void pm_genpd_inc_rejected(struct generic_pm_domain *genpd, + unsigned int state_idx) +{ + genpd_lock(genpd); + genpd->states[genpd->state_idx].rejected++; + genpd->states[genpd->state_idx].usage--; + genpd_unlock(genpd); +} +EXPORT_SYMBOL_GPL(pm_genpd_inc_rejected); + static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) { unsigned int state_idx = genpd->state_idx; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index d56a78af4af1..6e808aeecbcb 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -285,6 +285,8 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off); int pm_genpd_remove(struct generic_pm_domain *genpd); +void pm_genpd_inc_rejected(struct generic_pm_domain *genpd, + unsigned int state_idx); struct device *dev_to_genpd_dev(struct device *dev); int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); @@ -336,6 +338,10 @@ static inline int pm_genpd_remove(struct generic_pm_domain *genpd) return -EOPNOTSUPP; } +static inline void pm_genpd_inc_rejected(struct generic_pm_domain *genpd, + unsigned int state_idx) +{ } + static inline struct device *dev_to_genpd_dev(struct device *dev) { return ERR_PTR(-EOPNOTSUPP); From patchwork Fri Mar 14 10:00:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14016553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8176EC35FF1 for ; Fri, 14 Mar 2025 10:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JE+q5aCnF90doB2QrACuAQ2CKvBByABqrTNx0sOx31w=; b=jMpjZ4yml95Y25hRWrnQiHcrd1 5RrouvLNy3Jp4Kph4gA8ewuOXnalq/Zc38IB/ZX4rfRRjj2nO2jVD+77lz2xj9XjK7V8FFm+vHl9M facOfv6An/PjZE9Eu9KHfqckIT/b5+9l6AYv5MSXaLhlQucd/pd2rQJzyB+Jh38tqgIjyHPfaBGe4 Q69+Gp5QpZAJv0cnNC9Jzv47H4QKUYlJLVUKBcv09XY7cpjEzMJ2pW5qmUL7DuwpzA/mY/uQ6Ay6U ozvyTV57mouZIVWAOs5bKS6wzYxWBZdiQgP6qjdhD4qmbdW+nVfIwyxIbi8dzWaokGBneAmtmYCXt sw9lisiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tt1yM-0000000Dmit-2stH; Fri, 14 Mar 2025 10:08:58 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tt1r0-0000000Dl2a-0FPr for linux-arm-kernel@lists.infradead.org; Fri, 14 Mar 2025 10:01:23 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-30bf3f3539dso19089131fa.1 for ; Fri, 14 Mar 2025 03:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741946480; x=1742551280; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JE+q5aCnF90doB2QrACuAQ2CKvBByABqrTNx0sOx31w=; b=FgrqF4fwbLz1EFstVAxaYxFNpHz9Zf+Y+0hXuh526zKnvPXro7ujhBW3zHnIoK4MrG a9qVFXNS9sj0K6sg/ki/AqiCpXHB17HuaV+4RSvFHwwqFOG58my+4MQwWVDcBYTSG+NR O1RaFnP+ffmqPTaMr5Aj+rllSOYh7hFrH7sF9ILnZutVgqCH7oKftKjEHtYWOg7RVzye 86BG5QCuJvI5orN+2tz83SSiXwPiESG2bDZJxWW7VWUHR7o9+32kdY/1RWhIZ6/KTJ9C PGuMtP9fLP2kIZq88sZQUfi2VgJgj5VAeEzjdBwdC95r+RZJ3YiWkEV3q91jw85t8OP0 Ah2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741946480; x=1742551280; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JE+q5aCnF90doB2QrACuAQ2CKvBByABqrTNx0sOx31w=; b=P6QJxtEIQ87Fxn2eCM0IJZgfZ/pcNDo96blnInmcrPwzClNWSV+8oTxI3/T0ba5aeP GYFvGQ12u0nkF5BJlqmmKD831rEpLYGaz7zi+GZyNhPmEZIqZJSs3xxO2Sl8o0lBv2Dd Jk5XmP8q/GQiy1pXXe3rXf++hzwkV9muAmKW9/8xdTMJUC4AntddURsw5lJ2JgUxTeKL P0Eu3hsX/zl9k9LV60BwEnyRInqAGuxwyUC00Mx+IYjZgtKtvnPza45sZJN4YKH6EAIB nUN4Hu5K7T9EvOZidAPmPHUdCafS3x8GIat/Mwh+bkT/Lab8qiJMZnL83IJdpUhmGZ5L JvhA== X-Forwarded-Encrypted: i=1; AJvYcCWN1G+9aUE5GX14WuZbIE8fyaMryY1oxUrUstX17KG1mMjtD409wPHbDFXZGiRbdfUPFnkqyh+i577V1Ri9hK8x@lists.infradead.org X-Gm-Message-State: AOJu0YwmfzowbEt7GLjSEa2q+D8cCNc3YRneA+itovWBjfjNZ0MKJJu5 Bl3JWrxur0eBPyNLrTnfb+Ng8FWMGalTAefd9FgYrsxC7U3dVuIwTw5RvaghidQ= X-Gm-Gg: ASbGncsm12bwYqdL1Qmu88OQ/qNQgO/Tz8ucYlelWSE967ijtc4pFuNX6lLEFkTA0iw r0m5Tt4iCBh+O1IKsbdnAu2bCQUqMs2iCxdWYvU4gXDXQwJqJBDjkCYEP8/167s8rIFnEC+ndg9 opijSbtkddTYhRDwp6hjdMdDhVpT84MoMtpGnY2VOGbWKocnt0thhZpyficx5Wp2bl51V3kjJgS mlWrgpgsy1SLYlmGMPecsE5R2Xtl/fOtfJPStJC0qqFxlPhjXSdMuvtgQNE91s482kWW5HEGGiE xjoaL7btRsPv9YwVMdzlfn3NL27S6XWUW5fslmLtTGc+Evk1igiFZhOb8QDX2vxrq0pcF1Y+P4c KeUSxngRNCBsBt/u9vWQUnTxnQKlg3g== X-Google-Smtp-Source: AGHT+IGhYmFMbUeatQB/z6JS0kcTyMcIT1IzBAPuh4fApk2bCc0yDwcZPgTrJD62ufz1WRxkinRL3Q== X-Received: by 2002:a05:651c:1501:b0:30b:c36c:ba96 with SMTP id 38308e7fff4ca-30c4aa7711fmr7127431fa.1.1741946480268; Fri, 14 Mar 2025 03:01:20 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30c3f0ea468sm5168221fa.41.2025.03.14.03.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 03:01:19 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , linux-pm@vger.kernel.org Cc: Lorenzo Pieralisi , Daniel Lezcano , Anup Patel , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] cpuidle: psci: Move the per CPU variable domain_state to a struct Date: Fri, 14 Mar 2025 11:00:56 +0100 Message-ID: <20250314100103.1294715-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314100103.1294715-1-ulf.hansson@linaro.org> References: <20250314100103.1294715-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250314_030122_098021_85053072 X-CRM114-Status: GOOD ( 14.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org To prepare to extend the per CPU variable domain_state to include more data, let's move it into a struct. A subsequent change will add the new data. This change have no intended functional impact. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index dd8d776d6e39..1aff1ec555d5 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -36,19 +36,28 @@ struct psci_cpuidle_data { struct device *dev; }; +struct psci_cpuidle_domain_state { + u32 state; +}; + static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); -static DEFINE_PER_CPU(u32, domain_state); +static DEFINE_PER_CPU(struct psci_cpuidle_domain_state, psci_domain_state); static bool psci_cpuidle_use_syscore; static bool psci_cpuidle_use_cpuhp; void psci_set_domain_state(u32 state) { - __this_cpu_write(domain_state, state); + __this_cpu_write(psci_domain_state.state, state); } static inline u32 psci_get_domain_state(void) { - return __this_cpu_read(domain_state); + return __this_cpu_read(psci_domain_state.state); +} + +static inline void psci_clear_domain_state(void) +{ + __this_cpu_write(psci_domain_state.state, 0); } static __cpuidle int __psci_enter_domain_idle_state(struct cpuidle_device *dev, @@ -87,7 +96,7 @@ static __cpuidle int __psci_enter_domain_idle_state(struct cpuidle_device *dev, cpu_pm_exit(); /* Clear the domain state to start fresh when back from idle. */ - psci_set_domain_state(0); + psci_clear_domain_state(); return ret; } @@ -121,7 +130,7 @@ static int psci_idle_cpuhp_down(unsigned int cpu) if (pd_dev) { pm_runtime_put_sync(pd_dev); /* Clear domain state to start fresh at next online. */ - psci_set_domain_state(0); + psci_clear_domain_state(); } return 0; @@ -147,7 +156,7 @@ static void psci_idle_syscore_switch(bool suspend) /* Clear domain state to re-start fresh. */ if (!cleared) { - psci_set_domain_state(0); + psci_clear_domain_state(); cleared = true; } } From patchwork Fri Mar 14 10:00:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14016554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE3CCC282EC for ; Fri, 14 Mar 2025 10:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Suz7cKLNuXGtB0nBu0oVhma/Td/1dTahkXdO6vQ+7gU=; b=36ecoQ7u1Gh+X/Qi0bYXzbFdvq JeaUg+N6fZZiIJ8nYHUgJPe1BOk2yCEtM8p3/gXJEvp35LFEtw/hKRSQqJI+8idEyE8llbhMYBPGe UOMaHLH1K9RdaTE04JQhQhrOv2sG+4X2/u+ZjKd2CLI03q+DXwAljqKQlTSIkLNKaA6VRp6af3quv uWozuvLxu+d13Up0aqEXEVQ5HM+NQiErlH45w1c6fSc/Wmy3e2vfei9+cLYMyfOZNeSHoHJRlLViP gaWWjOcYaD8MW/xeMNgvO+qoKjJcXTy95UKk537RCPZQB4wFkIlsccqDtu9xdY57wGbPbyhanl5Gz xTDJF1XQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tt200-0000000Dn5j-3vJQ; Fri, 14 Mar 2025 10:10:40 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tt1r2-0000000Dl3e-1uOd for linux-arm-kernel@lists.infradead.org; Fri, 14 Mar 2025 10:01:25 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-30bef9b04adso19709291fa.1 for ; Fri, 14 Mar 2025 03:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741946482; x=1742551282; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Suz7cKLNuXGtB0nBu0oVhma/Td/1dTahkXdO6vQ+7gU=; b=LLeM70dpmYF0HBc3lpGbOzGe+Jv5zHAeok9fixzUq5ERS9Yxe6J1RjwENF7lb09GMM 1sIJsoa7y7PH84QnyJSknc8ZaN+0q6r80NeiXw8vO+ZuqbfUwsyFUWvk0NdfE3wMtrSF 0oSDpzyK0ihWN8dToebaPOmA3vJBXrnLFUKfKRlp5DdmL+4PezzbdyWw1mURmOeHw0GV KLFCQKUgKIDBAlC+nZl4doVTIkXFSuqpNyexMo6K5J2+f507wmTehACuvs8borCd+8tr 4ITwPt85sSGZjhGLkfxXbKKd0M+Al+uNrMC1oNfphXRByC2wy0UTEYN5POBjnwIvTILf V+cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741946482; x=1742551282; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Suz7cKLNuXGtB0nBu0oVhma/Td/1dTahkXdO6vQ+7gU=; b=JUarcIgUtbIy+qcwpmTP1spmUrz4Ma1HjuElXleS564wHvqEoO2ss6RgRKm7f5JQVi +Z6DATa0EkgbYI5JVGIpwPyF290IPD+jzLL8CbhL/r73WhioIl7JpEhyKcf6AHfUyCrf 6UvO2PkEOx1Bfb533XEiFw3uTiKsTiOmWiXrGcM++TDH6K/3xxlUTqoS5eP7aooaGaIx Dk8z4CnpaM6Mwj6bBcxnnp6d3lw9z4JvVdSzh5RM4NEBfA9JN2BSXRLhRP5tedInU2Op 6Xlw+trWYTunHon/Ft6mUD6rza7sjU/t7RO/pRRDCzIjDsc/1Et35CCQTUFZzpZFZyqM tQfg== X-Forwarded-Encrypted: i=1; AJvYcCWBbZqgW+2dyTrM3D0UG6GH0ysDSc9Ml/SfiIdKlX50X3/RvUE82Uj3ANJedzIpyJJOTp8jGAandzDLxUyLs6eP@lists.infradead.org X-Gm-Message-State: AOJu0YxcKCY+VG8uJum5EXIdSev3ubBJBhIJR2L4UDKN7ZexTHDkY9sL F8sQqkRU5qr9z3Cl6vPt/Pfmi1v305ccJQXIdxy9FPFHSWHcelGSFfqMEQ2LAWY= X-Gm-Gg: ASbGncsrhbdy90LqVraaM0SZmEAOG1k27lD3HllEMcoZfw3aH2aCQ7uZWfYTnSRkwdc ZEiZSrvUtK2xYB0SXxQ6FoqzVeS5QTNQK+czEnscwoEGzi9E0G7pgaTwrig9uvZZdXYijttWz+o YHXZkb0ArqODDrVBM0vx9QqPkNqRI5as0i6b77ZvJqm815W4Q96Je2Zbf3i8x1Z5s+F9PGyETuF jwWC9UW/r8+xD8Ha/WOeKUvwBwP9I/IGgjw8Lo7ytcZYyGhi8EGxDtxYXdSMiaCS57XemWvEowa emz/giP0HYDakBY0MQFAQ4/Czkua/Dhw5S/WJBkYc7uMwLZUSj1o0+y9lOS3GRXgfijrDX8E9Ou jIoG7UQ0MQmQvNJIHXEqU/Frtn/jtVw== X-Google-Smtp-Source: AGHT+IEY83oFunB8w4RCdXC7/PTR7yqMmBEg98GVtkrv9yV920cpuM7Rd10omcbDGDOuiGclAjQbOw== X-Received: by 2002:a05:651c:2101:b0:309:26e8:cb1a with SMTP id 38308e7fff4ca-30c4a8dcaaemr6886561fa.30.1741946482339; Fri, 14 Mar 2025 03:01:22 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30c3f0ea468sm5168221fa.41.2025.03.14.03.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 03:01:21 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , linux-pm@vger.kernel.org Cc: Lorenzo Pieralisi , Daniel Lezcano , Anup Patel , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] cpuidle: psci: Correct the domain-idlestate statistics in debugfs Date: Fri, 14 Mar 2025 11:00:57 +0100 Message-ID: <20250314100103.1294715-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314100103.1294715-1-ulf.hansson@linaro.org> References: <20250314100103.1294715-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250314_030124_494750_26748BBA X-CRM114-Status: GOOD ( 18.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When trying to enter a domain-idlestate, we may occasionally fail to enter the state, which is informed to us by psci_cpu_suspend_enter() returning an error-code. In these cases, our corresponding genpd->power_off() callback has already returned zero to indicate success, leading to getting in-correct domain-idlestate statistics in debugfs for the genpd in question. Let's fix this by making use of the new pm_genpd_inc_rejected() helper, as it allows us to correct the domain-idlestate statistics for this type of scenario. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 2 +- drivers/cpuidle/cpuidle-psci.c | 27 +++++++++++++++++---------- drivers/cpuidle/cpuidle-psci.h | 4 +++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index 5fb5228f6bf1..2041f59116ce 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -43,7 +43,7 @@ static int psci_pd_power_off(struct generic_pm_domain *pd) /* OSI mode is enabled, set the corresponding domain state. */ pd_state = state->data; - psci_set_domain_state(*pd_state); + psci_set_domain_state(pd, pd->state_idx, *pd_state); return 0; } diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 1aff1ec555d5..26a0885444c4 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -37,6 +37,8 @@ struct psci_cpuidle_data { }; struct psci_cpuidle_domain_state { + struct generic_pm_domain *pd; + unsigned int state_idx; u32 state; }; @@ -45,14 +47,14 @@ static DEFINE_PER_CPU(struct psci_cpuidle_domain_state, psci_domain_state); static bool psci_cpuidle_use_syscore; static bool psci_cpuidle_use_cpuhp; -void psci_set_domain_state(u32 state) +void psci_set_domain_state(struct generic_pm_domain *pd, unsigned int state_idx, + u32 state) { - __this_cpu_write(psci_domain_state.state, state); -} + struct psci_cpuidle_domain_state *ds = this_cpu_ptr(&psci_domain_state); -static inline u32 psci_get_domain_state(void) -{ - return __this_cpu_read(psci_domain_state.state); + ds->pd = pd; + ds->state_idx = state_idx; + ds->state = state; } static inline void psci_clear_domain_state(void) @@ -67,7 +69,8 @@ static __cpuidle int __psci_enter_domain_idle_state(struct cpuidle_device *dev, struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); u32 *states = data->psci_states; struct device *pd_dev = data->dev; - u32 state; + struct psci_cpuidle_domain_state *ds; + u32 state = states[idx]; int ret; ret = cpu_pm_enter(); @@ -80,9 +83,9 @@ static __cpuidle int __psci_enter_domain_idle_state(struct cpuidle_device *dev, else pm_runtime_put_sync_suspend(pd_dev); - state = psci_get_domain_state(); - if (!state) - state = states[idx]; + ds = this_cpu_ptr(&psci_domain_state); + if (ds->state) + state = ds->state; trace_psci_domain_idle_enter(dev->cpu, state, s2idle); ret = psci_cpu_suspend_enter(state) ? -1 : idx; @@ -95,6 +98,10 @@ static __cpuidle int __psci_enter_domain_idle_state(struct cpuidle_device *dev, cpu_pm_exit(); + /* Correct domain-idlestate statistics if we failed to enter. */ + if (ret == -1 && ds->state) + pm_genpd_inc_rejected(ds->pd, ds->state_idx); + /* Clear the domain state to start fresh when back from idle. */ psci_clear_domain_state(); return ret; diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h index ef004ec7a7c5..d29cbd796cd5 100644 --- a/drivers/cpuidle/cpuidle-psci.h +++ b/drivers/cpuidle/cpuidle-psci.h @@ -4,8 +4,10 @@ #define __CPUIDLE_PSCI_H struct device_node; +struct generic_pm_domain; -void psci_set_domain_state(u32 state); +void psci_set_domain_state(struct generic_pm_domain *pd, unsigned int state_idx, + u32 state); int psci_dt_parse_state_node(struct device_node *np, u32 *state); #endif /* __CPUIDLE_PSCI_H */ From patchwork Fri Mar 14 10:00:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 14016593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CE7BC282EC for ; Fri, 14 Mar 2025 10:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/QggTlpxLWEC50ONNabSeYB6RhPieGr2Z8I7fdFvhr8=; b=M/Lv0CmgXJSsgZGWnFkhNSxMcR RoHiOPkVUjpjN6ihVZOvwci3COI53CgIE10C1RGvgx4HnPdvotjuRtWHKJhjHxnGtHTGsPta5Iosv lM+wt6BBBhBCB5XW6pPGwxeKlgilx+PKZzpBDE8AoqcGkIhPYliLEOS1wrI661qOrfr81o8Lv0Gkt l+oSsxKSvJzsDfPov0drciTGAQdwJWEj36fVOC0MVrRu1kAYj4M0XmgDL7cAWvcab/wKw+fMWE2Qe O+6ZcHnTL2GVNRZdawa6TZ0zJNaoj/QMHpWfELH0tQf8VUU59vttaLLyP5FqdEGlO4E0/Q0545alC gpE2XwWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tt21f-0000000DndY-2bmF; Fri, 14 Mar 2025 10:12:23 +0000 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tt1r3-0000000Dl47-1u5G for linux-arm-kernel@lists.infradead.org; Fri, 14 Mar 2025 10:01:26 +0000 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-30bf7d0c15eso21041481fa.0 for ; Fri, 14 Mar 2025 03:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741946483; x=1742551283; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/QggTlpxLWEC50ONNabSeYB6RhPieGr2Z8I7fdFvhr8=; b=FRorXmRmy9bk1oky0B7ZTGwnSDiTs0fEbNIY9/XT7oQqkqsK91HTPqcHvzEsYnw5mf 4zq8f2bBGhqEEYAAg5QdSipnhXkp0Bb8hUpWqdx+HdoBgHVSeXMIkDGreluWNvXCheYo giryso1OljV44huJTpom068Mf/DEMmLpvuj3mQHOn3MGIhXaQat3OOuwPiuwS8hwhmF1 HapYBpqgbWD+mgSesPDTaseRnory/7bQYZUlmjpe4mvwFu/8QVsjQ9UUkWYhHC95XgUA UbmECML/rXP7NhxDBgWR7+VI9vN7bU2+JUducti0TdELMqlZeo+xItCk7j+Y/8vb3ffy EQ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741946483; x=1742551283; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/QggTlpxLWEC50ONNabSeYB6RhPieGr2Z8I7fdFvhr8=; b=BAWZ3grOAeLd8TcYlLfphfWSDDUO2VbfvSqzmNokMKrQ4YxXKrM2Nd0V8md7O4H3wj OGCnTKt+amGF91BoaxTtxjLFzO7yDC1WIw/cAnPmvGIXTt1mkHHu73jy6sMxBXH5z62T N8Px2O5ecmCduD992gmV+R9cV/HZjBDoT/v15JoP48uD7sIovCupCf2qwYiTXhURyKWX bWpZCZeafBd9dkBNZwh4jyPUXgGvVvJZvcuW/Wkbs7oE1e1jpllg9bnw6c+eO15HzSHK ASxsduv8XAvVm6rCXvXp7++nJ2hE6kkScste1/GlvqNhlAEkeIK9KrGNCal6v45ES08a PksQ== X-Forwarded-Encrypted: i=1; AJvYcCXnHT7KeKZWAphOhQg5s3TNeKQAqyS8+AkAkAw/LJpPckqSLCfpeo4ETST+b0WFlbPhasKTvr4D3L1rsTaXuDcj@lists.infradead.org X-Gm-Message-State: AOJu0YynehorEN4GZ1hYovYt8f18j+6RmPuqSf2FFR5zUD7xMoChQGQN Ib88yVWBGJbj0Cj7Vj5b5uSpUXEtqnVdxyoOuzoJxkJPq1O8n+CYuA2AVpR4O2g= X-Gm-Gg: ASbGncvjhlZsUNHF2AP3tuthmf2RYwieguhovgzNW/uBatn+1N9qJqqUg2T7g8Os9L8 pXJ4cLYSoQDg+MqoBxFtwlpBKH0eSkuNrz3Hw7KtNne7+ti63fTmN1em5Yqdhj6LL40alNB5is6 dys2p/VYJv4AWfscOPHLmOqm/onAayPxnmI/F0RGr2CU2SrnaUUmxTldeIrgh16rXcSyy0+bg+x ExE9M1yYv4oN5Z2Rsfa0vOwslQsj0aBnGuUzWxaosVuhatcRa4m34OJcyccJOOyEI+TWRXIBHIi c8nAY0w9KhA3nt/aBe1wjz7mD45rjqbkJzTUNI5droMhTHp+eNgfx8i3aqpFdedGFlWZZ3HviMg 2eYRWUCh2HRuiStm8ojE= X-Google-Smtp-Source: AGHT+IF3JWP6a57uvsfs3rKVvgBqgJHjNxLdTktMEECCgzMKQtOboYvvcrBZ2wGvWzv5dk6aRgujQw== X-Received: by 2002:a2e:88c9:0:b0:30b:8e06:86a3 with SMTP id 38308e7fff4ca-30c4a8665c1mr5313131fa.16.1741946483423; Fri, 14 Mar 2025 03:01:23 -0700 (PDT) Received: from uffe-tuxpro14.. (h-178-174-189-39.A498.priv.bahnhof.se. [178.174.189.39]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30c3f0ea468sm5168221fa.41.2025.03.14.03.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 03:01:22 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , linux-pm@vger.kernel.org Cc: Lorenzo Pieralisi , Daniel Lezcano , Anup Patel , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] pmdomain: core: Add residency reflection for domain-idlestates to debugfs Date: Fri, 14 Mar 2025 11:00:58 +0100 Message-ID: <20250314100103.1294715-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314100103.1294715-1-ulf.hansson@linaro.org> References: <20250314100103.1294715-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250314_030125_492583_6ACECD97 X-CRM114-Status: GOOD ( 19.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For regular cpuidle states we are reflecting over the selected/entered state to see if the sleep-duration meets the residency for the state. The output from the reflection is an "above" value to indicate the number of times the state was too deep and a "below" value for the number of times it was too shallow. Let's implement the similar thing for genpd's domain-idlestates along with genpd's governor and put the information in the genpd's debugfs. Signed-off-by: Ulf Hansson --- drivers/pmdomain/core.c | 40 ++++++++++++++++++++++++++++++++++--- drivers/pmdomain/governor.c | 2 ++ include/linux/pm_domain.h | 4 ++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index c79ef6e3ab85..3327de2f9ed2 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -304,10 +304,40 @@ static void genpd_update_accounting(struct generic_pm_domain *genpd) genpd->accounting_time = now; } + +static void genpd_reflect_residency(struct generic_pm_domain *genpd) +{ + struct genpd_governor_data *gd = genpd->gd; + struct genpd_power_state *state, *next_state; + unsigned int state_idx; + s64 sleep_ns, target_ns; + + if (!gd || !gd->reflect_residency) + return; + + sleep_ns = ktime_to_ns(ktime_sub(ktime_get(), gd->last_enter)); + state_idx = genpd->state_idx; + state = &genpd->states[state_idx]; + target_ns = state->power_off_latency_ns + state->residency_ns; + + if (sleep_ns < target_ns) { + state->above++; + } else if (state_idx < (genpd->state_count -1)) { + next_state = &genpd->states[state_idx + 1]; + target_ns = next_state->power_off_latency_ns + + next_state->residency_ns; + + if (sleep_ns >= target_ns) + state->below++; + } + + gd->reflect_residency = false; +} #else static inline void genpd_debug_add(struct generic_pm_domain *genpd) {} static inline void genpd_debug_remove(struct generic_pm_domain *genpd) {} static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {} +static inline void genpd_reflect_residency(struct generic_pm_domain *genpd) {} #endif static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd, @@ -982,6 +1012,9 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) if (genpd_status_on(genpd)) return 0; + /* Reflect over the entered idle-states residency for debugfs. */ + genpd_reflect_residency(genpd); + /* * The list is guaranteed not to change while the loop below is being * executed, unless one of the parents' .power_on() callbacks fiddles @@ -3517,7 +3550,7 @@ static int idle_states_show(struct seq_file *s, void *data) if (ret) return -ERESTARTSYS; - seq_puts(s, "State Time Spent(ms) Usage Rejected\n"); + seq_puts(s, "State Time Spent(ms) Usage Rejected Above Below\n"); for (i = 0; i < genpd->state_count; i++) { struct genpd_power_state *state = &genpd->states[i]; @@ -3537,9 +3570,10 @@ static int idle_states_show(struct seq_file *s, void *data) snprintf(state_name, ARRAY_SIZE(state_name), "S%-13d", i); do_div(idle_time, NSEC_PER_MSEC); - seq_printf(s, "%-14s %-14llu %-14llu %llu\n", + seq_printf(s, "%-14s %-14llu %-10llu %-10llu %-10llu %llu\n", state->name ?: state_name, idle_time, - state->usage, state->rejected); + state->usage, state->rejected, state->above, + state->below); } genpd_unlock(genpd); diff --git a/drivers/pmdomain/governor.c b/drivers/pmdomain/governor.c index d1a10eeebd16..c1e148657c87 100644 --- a/drivers/pmdomain/governor.c +++ b/drivers/pmdomain/governor.c @@ -392,6 +392,8 @@ static bool cpu_power_down_ok(struct dev_pm_domain *pd) if (idle_duration_ns >= (genpd->states[i].residency_ns + genpd->states[i].power_off_latency_ns)) { genpd->state_idx = i; + genpd->gd->last_enter = now; + genpd->gd->reflect_residency = true; return true; } } while (--i >= 0); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 6e808aeecbcb..0b18160901a2 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -142,6 +142,8 @@ struct genpd_governor_data { bool max_off_time_changed; ktime_t next_wakeup; ktime_t next_hrtimer; + ktime_t last_enter; + bool reflect_residency; bool cached_power_down_ok; bool cached_power_down_state_idx; }; @@ -153,6 +155,8 @@ struct genpd_power_state { s64 residency_ns; u64 usage; u64 rejected; + u64 above; + u64 below; struct fwnode_handle *fwnode; u64 idle_time; void *data;