All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
To: rafael@kernel.org, viresh.kumar@linaro.org
Cc: linux-pm@vger.kernel.org,
	Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Subject: [PATCH] cpufreq: use cashed resolved frequency
Date: Tue, 18 Nov 2025 12:16:06 +0530	[thread overview]
Message-ID: <20251118064606.2777035-1-kaushlendra.kumar@intel.com> (raw)

Return a previously resolved frequency when the requested target
matches the policy cache to avoid repeated frequency-table lookups
This implementation reuses the existing cached_target_freq and
cached_resolved_idx fields maintained by __resolve_freq() and does not
introduce new state.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
 drivers/cpufreq/cpufreq.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 4472bb1ec83c..d90dcffac953 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -527,6 +527,15 @@ unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
 	unsigned int min = READ_ONCE(policy->min);
 	unsigned int max = READ_ONCE(policy->max);
 
+	/* If we recently resolved this target, return cached value.
+	 * This avoids repeated frequency table searches.
+	 */
+	if (likely(policy->cached_target_freq == target_freq &&
+		   policy->cached_resolved_idx != UINT_MAX &&
+		   policy->freq_table)) {
+		return policy->freq_table[policy->cached_resolved_idx].frequency;
+	}
+
 	/*
 	 * If this function runs in parallel with cpufreq_set_policy(), it may
 	 * read policy->min before the update and policy->max after the update
-- 
2.34.1


             reply	other threads:[~2025-11-18  6:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18  6:46 Kaushlendra Kumar [this message]
2025-11-18 12:00 ` [PATCH] cpufreq: use cashed resolved frequency Lukasz Luba
2025-11-18 12:23   ` Rafael J. Wysocki
2025-11-18 13:30     ` Kumar, Kaushlendra

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=20251118064606.2777035-1-kaushlendra.kumar@intel.com \
    --to=kaushlendra.kumar@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.