All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: use cashed resolved frequency
@ 2025-11-18  6:46 Kaushlendra Kumar
  2025-11-18 12:00 ` Lukasz Luba
  0 siblings, 1 reply; 4+ messages in thread
From: Kaushlendra Kumar @ 2025-11-18  6:46 UTC (permalink / raw)
  To: rafael, viresh.kumar; +Cc: linux-pm, Kaushlendra Kumar

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-18 13:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18  6:46 [PATCH] cpufreq: use cashed resolved frequency Kaushlendra Kumar
2025-11-18 12:00 ` Lukasz Luba
2025-11-18 12:23   ` Rafael J. Wysocki
2025-11-18 13:30     ` Kumar, Kaushlendra

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.