mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: MyungJoo Ham <myungjoo.ham@samsung.com>,
	 Kyungmin Park <kyungmin.park@samsung.com>,
	 Chanwoo Choi <cw00.choi@samsung.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH] PM / devfreq: passive: Use the parent's frequency in update_devfreq()
Date: Tue, 01 Dec 2026 10:08:48 +0000	[thread overview]
Message-ID: <20261201-devfreq-passive-freq0-v1-1-e5e770518abc@gmail.com> (raw)

From: Arun Iyengar <aiyengar1990@gmail.com>

update_devfreq() calls the passive governor with freq 0, so a PM QoS,
sysfs min/max or OPP change on a passive device with a devfreq parent
sets it as if the parent ran at its lowest OPP.

Remember the parent's frequency from its transition notifier and use
it when freq is 0.

Fixes: 996133119f57 ("PM / devfreq: Add new passive governor")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
KUnit, qemu arm64 (KASAN, lockdep): a QoS change keeps the child at the
parent's frequency; unpatched it drops to the lowest OPP. No hardware test.

Claude (Anthropic) wrote the code and commit message; I reviewed both.
---
 drivers/devfreq/governor_passive.c | 22 ++++++++++++++++++++--
 include/linux/devfreq.h            |  2 ++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c
index d7feecd900f1..b0d2c788c29e 100644
--- a/drivers/devfreq/governor_passive.c
+++ b/drivers/devfreq/governor_passive.c
@@ -161,6 +161,10 @@ static int get_target_freq_with_devfreq(struct devfreq *devfreq,
 	unsigned long child_freq = ULONG_MAX;
 	int i, count;
 
+	/* update_devfreq() passes 0 */
+	if (!*freq)
+		*freq = p_data->parent_freq;
+
 	/* Get target freq via required opps */
 	child_freq = get_target_freq_by_required_opp(parent_devfreq->dev.parent,
 						parent_devfreq->opp_table,
@@ -372,11 +376,14 @@ static int devfreq_passive_notifier_call(struct notifier_block *nb,
 	mutex_lock_nested(&devfreq->lock, SINGLE_DEPTH_NESTING);
 	switch (event) {
 	case DEVFREQ_PRECHANGE:
-		if (parent->previous_freq > freq)
+		if (parent->previous_freq > freq) {
+			data->parent_freq = freq;
 			ret = devfreq_update_target(devfreq, freq);
+		}
 
 		break;
 	case DEVFREQ_POSTCHANGE:
+		data->parent_freq = freq;
 		if (parent->previous_freq < freq)
 			ret = devfreq_update_target(devfreq, freq);
 		break;
@@ -406,12 +413,23 @@ static int devfreq_passive_register_notifier(struct devfreq *devfreq)
 			= (struct devfreq_passive_data *)devfreq->data;
 	struct devfreq *parent = (struct devfreq *)p_data->parent;
 	struct notifier_block *nb = &p_data->nb;
+	int ret;
 
 	if (!parent)
 		return -EPROBE_DEFER;
 
 	nb->notifier_call = devfreq_passive_notifier_call;
-	return devfreq_register_notifier(parent, nb, DEVFREQ_TRANSITION_NOTIFIER);
+	ret = devfreq_register_notifier(parent, nb, DEVFREQ_TRANSITION_NOTIFIER);
+	if (ret)
+		return ret;
+
+	mutex_lock(&parent->lock);
+	mutex_lock_nested(&devfreq->lock, SINGLE_DEPTH_NESTING);
+	p_data->parent_freq = parent->previous_freq;
+	mutex_unlock(&devfreq->lock);
+	mutex_unlock(&parent->lock);
+
+	return 0;
 }
 
 static int devfreq_passive_event_handler(struct devfreq *devfreq,
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index 809ef29b9af5..df53adda9951 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -322,6 +322,7 @@ enum devfreq_parent_dev_type {
  * @nb:			the notifier block for DEVFREQ_TRANSITION_NOTIFIER or
  *			CPUFREQ_TRANSITION_NOTIFIER list.
  * @cpu_data_list:	the list of cpu frequency data for all cpufreq_policy.
+ * @parent_freq:	the last frequency of the parent devfreq device.
  *
  * The devfreq_passive_data have to set the devfreq instance of parent
  * device with governors except for the passive governor. But, don't need to
@@ -342,6 +343,7 @@ struct devfreq_passive_data {
 	struct devfreq *this;
 	struct notifier_block nb;
 	struct list_head cpu_data_list;
+	unsigned long parent_freq;
 };
 
 #if !defined(CONFIG_PM_DEVFREQ)

---
base-commit: e7c25197980f6edcf38a8167996eb4626a0a5c0d
change-id: 20261130-devfreq-passive-freq0-7632314a93f5

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>



                 reply	other threads:[~2026-12-01 10:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201-devfreq-passive-freq0-v1-1-e5e770518abc@gmail.com \
    --to=devnull+aiyengar1990.gmail.com@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=cw00.choi@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®