cpufreq_cpu_get_raw() gets cpufreq policy only if the CPU is in
policy->cpus mask, which means the CPU is already online. But in some
cases, the policy is needed before the CPU is added to cpus mask. Add a
function to get the policy in these cases.
Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
---
drivers/cpufreq/cpufreq.c | 6 ++++++
include/linux/cpufreq.h | 5 +++++
2 files changed, 11 insertions(+)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index fc7eace8b65b..78ca68ea754d 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -198,6 +198,12 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
}
EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
+struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu)
+{
+ return per_cpu(cpufreq_cpu_data, cpu);
+}
+EXPORT_SYMBOL_GPL(cpufreq_cpu_policy);
+
unsigned int cpufreq_generic_get(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 95f3807c8c55..26b3c3310d5b 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -205,6 +205,7 @@ struct cpufreq_freqs {
#ifdef CONFIG_CPU_FREQ
struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu);
+struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu);
struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu);
void cpufreq_cpu_put(struct cpufreq_policy *policy);
#else
@@ -212,6 +213,10 @@ static inline struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
{
return NULL;
}
+static inline struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu)
+{
+ return NULL;
+}
static inline struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
{
return NULL;
--
2.33.0
On 19/08/2025 15:29, Lifeng Zheng wrote: > cpufreq_cpu_get_raw() gets cpufreq policy only if the CPU is in > policy->cpus mask, which means the CPU is already online. But in some > cases, the policy is needed before the CPU is added to cpus mask. Add a > function to get the policy in these cases. > LGTM. Reviewed-by: Jie Zhan <zhanjie9@hisilicon.com> > Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com> > --- > drivers/cpufreq/cpufreq.c | 6 ++++++ > include/linux/cpufreq.h | 5 +++++ > 2 files changed, 11 insertions(+) > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index fc7eace8b65b..78ca68ea754d 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -198,6 +198,12 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) > } > EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw); > > +struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu) > +{ > + return per_cpu(cpufreq_cpu_data, cpu); > +} > +EXPORT_SYMBOL_GPL(cpufreq_cpu_policy); > + > unsigned int cpufreq_generic_get(unsigned int cpu) > { > struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > index 95f3807c8c55..26b3c3310d5b 100644 > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -205,6 +205,7 @@ struct cpufreq_freqs { > > #ifdef CONFIG_CPU_FREQ > struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu); > +struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu); > struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu); > void cpufreq_cpu_put(struct cpufreq_policy *policy); > #else > @@ -212,6 +213,10 @@ static inline struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) > { > return NULL; > } > +static inline struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu) > +{ > + return NULL; > +} > static inline struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) > { > return NULL;
On Tue, Aug 19, 2025 at 9:30 AM Lifeng Zheng <zhenglifeng1@huawei.com> wrote: > > cpufreq_cpu_get_raw() gets cpufreq policy only if the CPU is in > policy->cpus mask, which means the CPU is already online. But in some > cases, the policy is needed before the CPU is added to cpus mask. Add a > function to get the policy in these cases. I'd prefer the subject to be somewhat shorter. For instance, something like cpufreq: Add new helper function returning cpufreq policy would suffice because the changelog explains the details. With that addressed Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org> > Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com> > --- > drivers/cpufreq/cpufreq.c | 6 ++++++ > include/linux/cpufreq.h | 5 +++++ > 2 files changed, 11 insertions(+) > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index fc7eace8b65b..78ca68ea754d 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -198,6 +198,12 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) > } > EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw); > > +struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu) > +{ > + return per_cpu(cpufreq_cpu_data, cpu); > +} > +EXPORT_SYMBOL_GPL(cpufreq_cpu_policy); > + > unsigned int cpufreq_generic_get(unsigned int cpu) > { > struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > index 95f3807c8c55..26b3c3310d5b 100644 > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -205,6 +205,7 @@ struct cpufreq_freqs { > > #ifdef CONFIG_CPU_FREQ > struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu); > +struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu); > struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu); > void cpufreq_cpu_put(struct cpufreq_policy *policy); > #else > @@ -212,6 +213,10 @@ static inline struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) > { > return NULL; > } > +static inline struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu) > +{ > + return NULL; > +} > static inline struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) > { > return NULL; > -- > 2.33.0 > >
On 2025/8/20 3:05, Rafael J. Wysocki wrote: > On Tue, Aug 19, 2025 at 9:30 AM Lifeng Zheng <zhenglifeng1@huawei.com> wrote: >> >> cpufreq_cpu_get_raw() gets cpufreq policy only if the CPU is in >> policy->cpus mask, which means the CPU is already online. But in some >> cases, the policy is needed before the CPU is added to cpus mask. Add a >> function to get the policy in these cases. > > I'd prefer the subject to be somewhat shorter. For instance, something like > > cpufreq: Add new helper function returning cpufreq policy > > would suffice because the changelog explains the details. > > With that addressed > > Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org> Thanks! Will shorten it in the next version. > >> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com> >> --- >> drivers/cpufreq/cpufreq.c | 6 ++++++ >> include/linux/cpufreq.h | 5 +++++ >> 2 files changed, 11 insertions(+) >> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >> index fc7eace8b65b..78ca68ea754d 100644 >> --- a/drivers/cpufreq/cpufreq.c >> +++ b/drivers/cpufreq/cpufreq.c >> @@ -198,6 +198,12 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) >> } >> EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw); >> >> +struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu) >> +{ >> + return per_cpu(cpufreq_cpu_data, cpu); >> +} >> +EXPORT_SYMBOL_GPL(cpufreq_cpu_policy); >> + >> unsigned int cpufreq_generic_get(unsigned int cpu) >> { >> struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); >> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h >> index 95f3807c8c55..26b3c3310d5b 100644 >> --- a/include/linux/cpufreq.h >> +++ b/include/linux/cpufreq.h >> @@ -205,6 +205,7 @@ struct cpufreq_freqs { >> >> #ifdef CONFIG_CPU_FREQ >> struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu); >> +struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu); >> struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu); >> void cpufreq_cpu_put(struct cpufreq_policy *policy); >> #else >> @@ -212,6 +213,10 @@ static inline struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) >> { >> return NULL; >> } >> +static inline struct cpufreq_policy *cpufreq_cpu_policy(unsigned int cpu) >> +{ >> + return NULL; >> +} >> static inline struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) >> { >> return NULL; >> -- >> 2.33.0 >> >> >
© 2016 - 2025 Red Hat, Inc.