Add support for AArch64 AMUv1-based arch_freq_get_on_cpu
Subsystems (3)
v2 cover Add support for AArch64 AMUv1-based arch_freq_get_on_cpu
Introducing AArch64 specific version of arch_freq_get_on_cpu, cashing on existing implementation for FIE and AMUv1 support. Additionally wiring it up with cpufreq_verify_current_freq to hopefully eliminate issues when cpufreq_driver->get() returns frequency that is not entirely aligned.
The changes have been rather lightly (due to some limitations) tested on an FVP model.
v2:
- Splitting the patches
- Adding comment for full dyntick mode
- Plugging arch_freq_get_on_cpu into cpufreq_verify_current_freq instead of in show_cpuinfo_cur_freq to allow the framework to stay more in sync with potential freq changes
[1]
https://lore.kernel.org/lkml/[email protected]/
Beata Michalska (1):
arm64: Provide an AMU-based version of arch_freq_get_on_cpu
Sumit Gupta (1):
cpufreq: Wire-up arch-flavored freq info into
cpufreq_verify_current_freq
arch/arm64/kernel/topology.c | 39 ++++++++++++++++++++++++++++++++++++ drivers/cpufreq/cpufreq.c | 3 ++- 2 files changed, 41 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 arm64: Provide an AMU-based version of arch_freq_get_on_cpu
With the Frequency Invariance Engine (FIE) being already wired up with sched tick and making use of relevant (core counter and constant counter) AMU counters, getting the current frequency for a given CPU on supported platforms, can be achieved by utilizing the frequency scale factor which reflects an average CPU frequency for the last tick period length.
---
Notes:
Due to [1], if merged, there might be a need to modify the patch to accommodate changes [1] introduces:
freq = cpufreq_get_hw_max_freq(cpu) >> SCHED_CAPACITY_SHIFT to
freq = per_cpu(capacity_freq_ref, cpu); >> SCHED_CAPACITY_SHIFT
[1]
https://lore.kernel.org/linux-arm-kernel/20231121154349.GA1938@willie-the-truck/T/#mcb018d076dbce6f60ed2779634a9b6ffe622641e
arch/arm64/kernel/topology.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
arch/arm64/kernel/topology.c +39 -0
@@ -17,6 +17,7 @@#include <linux/cpufreq.h> #include <linux/init.h> #include <linux/percpu.h> +#include <linux/sched/isolation.h> #include <asm/cpu.h> #include <asm/cputype.h>
@@ -186,6 +187,44 @@ static void amu_scale_freq_tick(void)this_cpu_write (arch_freq_scale, (unsigned long )scale); } +unsigned int arch_freq_get_on_cpu (int cpu) +{ +unsigned int freq; +u64 scale; + +if (!cpumask_test_cpu (cpu, amu_fie_cpus)) +return 0 ; + +/* +* For those CPUs that are in full dynticks mode, try an alternative +* source for the counters (and thus freq scale), +* if available for given policy +*/ +if (!housekeeping_cpu (cpu,HK_TYPE_TICK )) { +struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); +int ref_cpu = nr_cpu_ids; + +if (cpumask_intersects (housekeeping_cpumask (HK_TYPE_TICK ), + policy->cpus)) + ref_cpu =cpumask_nth_and (cpu, policy->cpus, +housekeeping_cpumask (HK_TYPE_TICK )); +cpufreq_cpu_put (policy); +if (ref_cpu >= nr_cpu_ids) +return 0 ; + cpu = ref_cpu; + } + +/* +* Reversed computation to the one used to determine +* the arch_freq_scale value +* (see amu_scale_freq_tick for details) +*/ + scale =per_cpu (arch_freq_scale, cpu); + freq =cpufreq_get_hw_max_freq (cpu) >>SCHED_CAPACITY_SHIFT ; + freq *= scale; +return freq; +} +static struct scale_freq_data amu_sfd = { .source =SCALE_FREQ_SOURCE_ARCH , .set_freq_scale = amu_scale_freq_tick,
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] arm64: Provide an AMU-based version of arch_freq_get_on_cpu
Hi Beata,
Quoted 64 lines · Beata Michalska
With the Frequency Invariance Engine (FIE) being already wired up with sched tick and making use of relevant (core counter and constant counter) AMU counters, getting the current frequency for a given CPU on supported platforms, can be achieved by utilizing the frequency scale factor which reflects an average CPU frequency for the last tick period length.
Suggested-by Ionela Voinescu <[email protected]>Signed-off-by Beata Michalska <[email protected]>Reviewed-by Sudeep Holla <[email protected]>---
Notes:
Due to [1], if merged, there might be a need to modify the patch to accommodate changes [1] introduces:freq =
cpufreq_get_hw_max_freq(cpu)>>SCHED_CAPACITY_SHIFTto
freq =per_cpu(capacity_freq_ref, cpu); >>SCHED_CAPACITY_SHIFT
[1]
https://lore.kernel.org/linux-arm-kernel/20231121154349.GA1938@willie-the-truck/T/#mcb018d076dbce6f60ed2779634a9b6ffe622641earch/arm64/kernel/topology.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)arch/arm64/kernel/topology.c +24
-0@@ -17,6 +17,7 @@#include <linux/cpufreq.h> #include <linux/init.h> #include <linux/percpu.h> +#include <linux/sched/isolation.h> #include <asm/cpu.h> #include <asm/cputype.h> @@ -186,6 +187,44 @@ static void amu_scale_freq_tick(void)this_cpu_write (arch_freq_scale, (unsigned long )scale); } +unsigned int arch_freq_get_on_cpu (int cpu) +{ +unsigned int freq; +u64 scale; + +if (!cpumask_test_cpu (cpu, amu_fie_cpus)) +return 0 ; + +/* +* For those CPUs that are in full dynticks mode, try an alternative +* source for the counters (and thus freq scale), +* if available for given policy +*/ +if (!housekeeping_cpu (cpu,HK_TYPE_TICK )) { +struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); +int ref_cpu = nr_cpu_ids; + +if (cpumask_intersects (housekeeping_cpumask (HK_TYPE_TICK ), + policy->cpus)) + ref_cpu =cpumask_nth_and (cpu, policy->cpus, +housekeeping_cpumask (HK_TYPE_TICK )); +cpufreq_cpu_put (policy); +if (ref_cpu >= nr_cpu_ids)
arch/arm64/kernel/topology.c static void amu_scale_freq_tick(void) · line 222
Quoted 10 lines
arch/arm64/kernel/topology.c +10
-0+return 0 ; + cpu = ref_cpu; + } + +/* +* Reversed computation to the one used to determine +* the arch_freq_scale value +* (see amu_scale_freq_tick for details) +*/ + scale =per_cpu (arch_freq_scale, cpu);
Any reason for not using arch_scale_freq_capacity() here?
To me it seems a bit nicer to use the "official" function to return the frequency scale factor.
arch/arm64/kernel/topology.c static void amu_scale_freq_tick(void) · line 223
Quoted 1 line
arch/arm64/kernel/topology.c +1
-0+ freq =cpufreq_get_hw_max_freq (cpu) >>SCHED_CAPACITY_SHIFT ;
Given Vincent's patch at [1] I think here might be best to call arch_scale_freq_ref() instead. That's because the frequency scale factor will use that frequency as the maximum frequency in its calculations and we'd not want to use a different one here.
The annoyance is coping with capacity_freq_ref not having been set yet, and that would be easy if capacity_freq_ref was initialized to 0. Luckily with Vincent's changes it can now be 0. I'll comments on his patches and ask him to make this change.
So I think you can safely use arch_scale_freq_ref() here. If arch_scale_freq_ref() returns 0, arch_freq_get_on_cpu() will just return 0 as well.
arch/arm64/kernel/topology.c static void amu_scale_freq_tick(void) · line 224
Quoted 1 line
arch/arm64/kernel/topology.c +1
-0+ freq *= scale;
In some scenarios the frequencies visible to cpufreq might not look like actual frequencies, but some scaled abstract performance values. One example is cppc_cpufreq when one does not provide the optional frequency information in the CPC objects but just the performance information.
Therefore the maximum frequency seen here can be quite a small value, so it might be best to do the multiplication first and the shift after that.
Thanks,
Ionela.
Quoted 9 lines
arch/arm64/kernel/topology.c +3
-0+return freq; +} +static struct scale_freq_data amu_sfd = { .source =SCALE_FREQ_SOURCE_ARCH , .set_freq_scale = amu_scale_freq_tick,Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] arm64: Provide an AMU-based version of arch_freq_get_on_cpu
Quoted 80 lines · Ionela Voinescu
Hi Beata,
Quoted 64 lines · Beata Michalska
With the Frequency Invariance Engine (FIE) being already wired up with sched tick and making use of relevant (core counter and constant counter) AMU counters, getting the current frequency for a given CPU on supported platforms, can be achieved by utilizing the frequency scale factor which reflects an average CPU frequency for the last tick period length.
Suggested-by Ionela Voinescu <[email protected]>Signed-off-by Beata Michalska <[email protected]>Reviewed-by Sudeep Holla <[email protected]>---
Notes:
Due to [1], if merged, there might be a need to modify the patch to accommodate changes [1] introduces:freq =
cpufreq_get_hw_max_freq(cpu)>>SCHED_CAPACITY_SHIFTto
freq =per_cpu(capacity_freq_ref, cpu); >>SCHED_CAPACITY_SHIFT
[1]
https://lore.kernel.org/linux-arm-kernel/20231121154349.GA1938@willie-the-truck/T/#mcb018d076dbce6f60ed2779634a9b6ffe622641earch/arm64/kernel/topology.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)arch/arm64/kernel/topology.c +24
-0@@ -17,6 +17,7 @@#include <linux/cpufreq.h> #include <linux/init.h> #include <linux/percpu.h> +#include <linux/sched/isolation.h> #include <asm/cpu.h> #include <asm/cputype.h> @@ -186,6 +187,44 @@ static void amu_scale_freq_tick(void)this_cpu_write (arch_freq_scale, (unsigned long )scale); } +unsigned int arch_freq_get_on_cpu (int cpu) +{ +unsigned int freq; +u64 scale; + +if (!cpumask_test_cpu (cpu, amu_fie_cpus)) +return 0 ; + +/* +* For those CPUs that are in full dynticks mode, try an alternative +* source for the counters (and thus freq scale), +* if available for given policy +*/ +if (!housekeeping_cpu (cpu,HK_TYPE_TICK )) { +struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); +int ref_cpu = nr_cpu_ids; + +if (cpumask_intersects (housekeeping_cpumask (HK_TYPE_TICK ), + policy->cpus)) + ref_cpu =cpumask_nth_and (cpu, policy->cpus, +housekeeping_cpumask (HK_TYPE_TICK )); +cpufreq_cpu_put (policy); +if (ref_cpu >= nr_cpu_ids)arch/arm64/kernel/topology.c static void amu_scale_freq_tick(void) · line 222
Quoted 10 lines
arch/arm64/kernel/topology.c +10
-0+return 0 ; + cpu = ref_cpu; + } + +/* +* Reversed computation to the one used to determine +* the arch_freq_scale value +* (see amu_scale_freq_tick for details) +*/ + scale =per_cpu (arch_freq_scale, cpu);Any reason for not using
arch_scale_freq_capacity()here?
Quoted 3 lines
To me it seems a bit nicer to use the "official" function to return the frequency scale factor.
Noted.
Quoted 7 lines
arch/arm64/kernel/topology.c static void amu_scale_freq_tick(void) · line 223
Quoted 1 line
arch/arm64/kernel/topology.c +1
-0+ freq =cpufreq_get_hw_max_freq (cpu) >>SCHED_CAPACITY_SHIFT ;Given Vincent's patch at [1] I think here might be best to call
arch_scale_freq_ref()instead. That's because the frequency scale factor will use that frequency as the maximum frequency in its calculations and we'd not want to use a different one here.
OK.
Quoted 9 lines
The annoyance is coping with
capacity_freq_refnot having been set yet, and that would be easy ifcapacity_freq_refwas initialized to 0. Luckily with Vincent's changes it can now be 0. I'll comments on his patches and ask him to make this change.So I think you can safely use
arch_scale_freq_ref()here. Ifarch_scale_freq_ref()returns 0,arch_freq_get_on_cpu()will just return 0 as well.
Will do.
Quoted 9 lines
[1] https://lore.kernel.org/lkml/[email protected]/
arch/arm64/kernel/topology.c static void amu_scale_freq_tick(void) · line 224
Quoted 1 line
arch/arm64/kernel/topology.c +1
-0+ freq *= scale;In some scenarios the frequencies visible to cpufreq might not look like actual frequencies, but some scaled abstract performance values. One example is
cppc_cpufreqwhen one does not provide the optional frequency information in the CPC objects but just the performance information.
Quoted 3 lines
Therefore the maximum frequency seen here can be quite a small value, so it might be best to do the multiplication first and the shift after that.
Right, that was in v1! Must have mixed up things ending with stale data. Will address that in the next version - if one is out.
---
BR
Beata
Quoted 12 lines
Thanks,
Ionela.Quoted 9 lines
arch/arm64/kernel/topology.c +3
-0+return freq; +} +static struct scale_freq_data amu_sfd = { .source =SCALE_FREQ_SOURCE_ARCH , .set_freq_scale = amu_scale_freq_tick,Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] arm64: Provide an AMU-based version of arch_freq_get_on_cpu
In reply to Beata MichalskaHello Beata,
I tested this patch based on the discussion in [1] on an AmpereOne system when the system was mostly idle. The results below are when only I applied the first patch in this series to the kernel. I noticed that the frequency reported through scaling_cur_freq vs cpuinfo_cur_freq is quite different for some cores. When the cores are loaded using stress-ng, the scaling_cur_freq and cpuinfo_cur_freq values are quite similar.
Applying the second patch in this series causes the difference between scaling_cur_freq and cpuinfo_cur_freq to disappear, but calculating the core frequency based on the feedback_ctrs shows that the value is incorrect for both.
The kernel I compiled for testing is based on the Fedora 39 config file. These configs seem relevant to the discussion:
CONFIG_NO_HZ_COMMON=y
# CONFIG_HZ_PERIODIC is not set
# CONFIG_NO_HZ_IDLE is not setCONFIG_NO_HZ_FULL=yCONFIG_CONTEXT_TRACKING_USER=y
# CONFIG_CONTEXT_TRACKING_USER_FORCE is not setCONFIG_NO_HZ=y
[1]: https://lore.kernel.org/linux-arm-kernel/[email protected]/
Results:
cpu_num scaling_cur_freq cpuinfo_cur_freq [11]: 1874560 1000000 [12]: 2056158 1385000 [13]: 1974146 1000000 [21]: 1587518 1000000 [23]: 1593376 1000000
...
... skipping similar results for ~50 other cores for brevity
...
nohz_full=113-118
[113]: 1874560 1000000 [114]: 1968288 1000000 [115]: 1962430 1000000 [116]: 1871631 1000000 [117]: 1877489 1000000 [118]: 1877489 1000000 isolcpus=119-127 [119]: 2999296 1000000 [120]: 2999296 1000000 [121]: 2999296 1000000 [125]: 2999296 1000000 [126]: 2999296 1000000 [127]: 2999296 1000000
Thanks,
Vanshi
Quoted 90 lines · Beata Michalska
With the Frequency Invariance Engine (FIE) being already wired up with sched tick and making use of relevant (core counter and constant counter) AMU counters, getting the current frequency for a given CPU on supported platforms, can be achieved by utilizing the frequency scale factor which reflects an average CPU frequency for the last tick period length.
Suggested-by Ionela Voinescu <[email protected]>Signed-off-by Beata Michalska <[email protected]>Reviewed-by Sudeep Holla <[email protected]>---
Notes:
Due to [1], if merged, there might be a need to modify the patch to accommodate changes [1] introduces:freq =
cpufreq_get_hw_max_freq(cpu)>>SCHED_CAPACITY_SHIFTto
freq =per_cpu(capacity_freq_ref, cpu); >>SCHED_CAPACITY_SHIFT
[1]
https://lore.kernel.org/linux-arm-kernel/20231121154349.GA1938@willie-the-truck/T/#mcb018d076dbce6f60ed2779634a9b6ffe622641e
arch/arm64/kernel/topology.c| 39 ++++++++++++++++++++++++++++++++++++1 file changed, 39 insertions(+)arch/arm64/kernel/topology.c +39
-0@@ -17,6 +17,7 @@#include <linux/cpufreq.h> #include <linux/init.h> #include <linux/percpu.h> +#include <linux/sched/isolation.h> #include <asm/cpu.h> #include <asm/cputype.h> @@ -186,6 +187,44 @@ static void amu_scale_freq_tick(void)this_cpu_write (arch_freq_scale, (unsigned long )scale); } +unsigned int arch_freq_get_on_cpu (int cpu) +{ +unsigned int freq; +u64 scale; + +if (!cpumask_test_cpu (cpu, amu_fie_cpus)) +return 0 ; + +/* +* For those CPUs that are in full dynticks mode, try an alternative +* source for the counters (and thus freq scale), +* if available for given policy +*/ +if (!housekeeping_cpu (cpu,HK_TYPE_TICK )) { +struct cpufreq_policy *policy =cpufreq_cpu_get (cpu); +int ref_cpu = nr_cpu_ids; + +if (cpumask_intersects (housekeeping_cpumask (HK_TYPE_TICK ), + policy->cpus)) + ref_cpu =cpumask_nth_and (cpu, policy->cpus, +housekeeping_cpumask (HK_TYPE_TICK )); +cpufreq_cpu_put (policy); +if (ref_cpu >= nr_cpu_ids) +return 0 ; + cpu = ref_cpu; + } + +/* +* Reversed computation to the one used to determine +* the arch_freq_scale value +* (see amu_scale_freq_tick for details) +*/ + scale =per_cpu (arch_freq_scale, cpu); + freq =cpufreq_get_hw_max_freq (cpu) >>SCHED_CAPACITY_SHIFT ; + freq *= scale; +return freq; +} +static struct scale_freq_data amu_sfd = { .source =SCALE_FREQ_SOURCE_ARCH , .set_freq_scale = amu_scale_freq_tick,Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/2 cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
In reply to Beata MichalskaFrom: Sumit Gupta <[email protected]>
When available, use arch_freq_get_on_cpu to obtain current frequency (usually an average reported over given period of time)
to better align the cpufreq's view on the current state of affairs. This also automatically pulls in the update for cpuinfo_cur_freq sysfs attribute, aligning it with the scaling_cur_freq one, and thus providing consistent view on relevant platforms.
--- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +2 -1
@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);if (!new_freq)return 0 ;
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
Hi Beata, Sumit,
Quoted 21 lines · Beata Michalska
From: Sumit Gupta <[email protected]>
When available, use
arch_freq_get_on_cputo obtain current frequency (usually an average reported over given period of time)
to better align the cpufreq's view on the current state of affairs. This also automatically pulls in the update forcpuinfo_cur_freqsysfs attribute, aligning it with thescaling_cur_freqone, and thus providing consistent view on relevant platforms.Signed-off-by Sumit Gupta <[email protected]>[BM: Subject & commit msg]Signed-off-by Beata Michalska <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +0
-0
drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 6 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);
Given that arch_freq_get_on_cpu() is an average frequency, it does not seem right to me to trigger the sync & update process of cpufreq_verify_current_freq() based on it.
cpufreq_verify_current_freq() will at least modify the internal state of the policy and send PRE and POST notifications, if not do a full frequency update, based on this average frequency, which is likely different from the current frequency, even beyond the 1MHz threshold.
While I believe it's okay to return this average frequency in cpuinfo_cur_freq, I don't think it should be used as an indication of an accurate current frequency, which is what cpufreq_verify_current_freq() expects.
Sumit, can you give more details on the issue at [1] and why this change fixes it?
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Ionela.
Quoted 6 lines
drivers/cpufreq/cpufreq.c +0
-0if (!new_freq)return 0 ;Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
Hi Ionela,
Quoted 24 lines
drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 9 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);Given that
arch_freq_get_on_cpu()is an average frequency, it does not seem right to me to trigger the sync & update process ofcpufreq_verify_current_freq()based on it.
cpufreq_verify_current_freq()will at least modify the internal state of the policy and send PRE and POST notifications, if not do a full frequency update, based on this average frequency, which is likely different from the current frequency, even beyond the 1MHz threshold.While I believe it's okay to return this average frequency in
cpuinfo_cur_freq, I don't think it should be used as an indication of an accurate current frequency, which is whatcpufreq_verify_current_freq()expects.
Quoted 8 lines
Sumit, can you give more details on the issue at [1] and why this change fixes it?
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Ionela.
cpufreq_verify_current_freq() also updates 'policy->cur' in POST notification if the frequency from hardware has more delta (out of sync).
As the value from 'cpufreq_driver->get()' is not reliable due to [1],
calling the 'get' hook can update the 'policy->cur' with a wrong value when governor starts in cpufreq_start_governor(). And if the frequency is never changed after the governor starts during
boot e.g. when performance governor is set as default, then 'scaling_cur_freq' always returns wrong value.
Instead, the arch_freq_get_on_cpu() API updates 'policy->cur' with a more stable freq value.
[1] https://lore.kernel.org/lkml/[email protected]/
Best regards,
Sumit Gupta
Quoted 6 lines
Quoted 6 lines
drivers/cpufreq/cpufreq.c +0
-1if (!new_freq)return 0 ; --2.25.1
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
Hi Sumit,
Quoted 44 lines · Sumit Gupta
Hi Ionela,
Quoted 24 lines
drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 9 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);Given that
arch_freq_get_on_cpu()is an average frequency, it does not seem right to me to trigger the sync & update process ofcpufreq_verify_current_freq()based on it.
cpufreq_verify_current_freq()will at least modify the internal state of the policy and send PRE and POST notifications, if not do a full frequency update, based on this average frequency, which is likely different from the current frequency, even beyond the 1MHz threshold.While I believe it's okay to return this average frequency in
cpuinfo_cur_freq, I don't think it should be used as an indication of an accurate current frequency, which is whatcpufreq_verify_current_freq()expects.Quoted 8 lines
Sumit, can you give more details on the issue at [1] and why this change fixes it?
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Ionela.
cpufreq_verify_current_freq()also updates 'policy->cur' in POST notification if the frequency from hardware has more delta (out of sync).As the value from '
cpufreq_driver->get()' is not reliable due to [1], calling the 'get' hook can update the 'policy->cur' with a wrong value when governor starts incpufreq_start_governor().
And if the frequency is never changed after the governor starts during boot e.g. when performance governor is set as default, then 'scaling_cur_freq' always returns wrong value.
Quoted 4 lines
Instead, the
arch_freq_get_on_cpu()API updates 'policy->cur' with a more stable freq value.
Got it, many thanks!
As the code is right now in v2, arch_freq_get_on_cpu() is called on show_scaling_cur_freq(), so the problem you describe would not show up. policy->cur would still be incorrect, but 'scaling_cur_freq' would return the value from arch_freq_get_on_cpu().
Would it be enough if arch_freq_get_on_cpu() gets also called from show_cpuinfo_cur_freq() instead of cpufreq_verify_current_freq()?
Thanks,
Ionela.
Quoted 10 lines
Best regards,
Sumit GuptaQuoted 6 lines
Quoted 6 lines
drivers/cpufreq/cpufreq.c +0
-1if (!new_freq)return 0 ; --2.25.1
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
Quoted 62 lines · Ionela Voinescu
External email: Use caution opening links or attachments
Hi Sumit,
Quoted 44 lines · Sumit Gupta
Hi Ionela,
Quoted 24 lines
drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 9 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);Given that
arch_freq_get_on_cpu()is an average frequency, it does not seem right to me to trigger the sync & update process ofcpufreq_verify_current_freq()based on it.
cpufreq_verify_current_freq()will at least modify the internal state of the policy and send PRE and POST notifications, if not do a full frequency update, based on this average frequency, which is likely different from the current frequency, even beyond the 1MHz threshold.While I believe it's okay to return this average frequency in
cpuinfo_cur_freq, I don't think it should be used as an indication of an accurate current frequency, which is whatcpufreq_verify_current_freq()expects.Quoted 8 lines
Sumit, can you give more details on the issue at [1] and why this change fixes it?
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Ionela.
cpufreq_verify_current_freq()also updates 'policy->cur' in POST notification if the frequency from hardware has more delta (out of sync).As the value from '
cpufreq_driver->get()' is not reliable due to [1], calling the 'get' hook can update the 'policy->cur' with a wrong value when governor starts incpufreq_start_governor().
And if the frequency is never changed after the governor starts during boot e.g. when performance governor is set as default, then 'scaling_cur_freq' always returns wrong value.Quoted 4 lines
Instead, the
arch_freq_get_on_cpu()API updates 'policy->cur' with a more stable freq value.Got it, many thanks!
As the code is right now in v2,
arch_freq_get_on_cpu()is called onshow_scaling_cur_freq(), so the problem you describe would not show up.policy->curwould still be incorrect, but 'scaling_cur_freq' would return the value fromarch_freq_get_on_cpu().
Quoted 6 lines
Would it be enough if
arch_freq_get_on_cpu()gets also called fromshow_cpuinfo_cur_freq()instead ofcpufreq_verify_current_freq()?Thanks,
Ionela.
Yes.
I am not sure if making both the nodes 'scaling_cur_freq' and 'cpuinfo_cur_freq' same is fine?
Best Regards,
Sumit Gupta
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
Quoted 68 lines · Sumit Gupta
Quoted 65 lines · Ionela Voinescu
External email: Use caution opening links or attachments
Hi Sumit,
Quoted 44 lines · Sumit Gupta
Hi Ionela,
Quoted 24 lines
drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 9 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);Given that
arch_freq_get_on_cpu()is an average frequency, it does not seem right to me to trigger the sync & update process ofcpufreq_verify_current_freq()based on it.
cpufreq_verify_current_freq()will at least modify the internal state of the policy and send PRE and POST notifications, if not do a full frequency update, based on this average frequency, which is likely different from the current frequency, even beyond the 1MHz threshold.While I believe it's okay to return this average frequency in
cpuinfo_cur_freq, I don't think it should be used as an indication of an accurate current frequency, which is whatcpufreq_verify_current_freq()expects.Quoted 8 lines
Sumit, can you give more details on the issue at [1] and why this change fixes it?
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Ionela.
cpufreq_verify_current_freq()also updates 'policy->cur' in POST notification if the frequency from hardware has more delta (out of sync).As the value from '
cpufreq_driver->get()' is not reliable due to [1], calling the 'get' hook can update the 'policy->cur' with a wrong value when governor starts incpufreq_start_governor().
And if the frequency is never changed after the governor starts during boot e.g. when performance governor is set as default, then 'scaling_cur_freq' always returns wrong value.Quoted 4 lines
Instead, the
arch_freq_get_on_cpu()API updates 'policy->cur' with a more stable freq value.Got it, many thanks!
As the code is right now in v2,
arch_freq_get_on_cpu()is called onshow_scaling_cur_freq(), so the problem you describe would not show up.policy->curwould still be incorrect, but 'scaling_cur_freq' would return the value fromarch_freq_get_on_cpu().Would it be enough if
arch_freq_get_on_cpu()gets also called fromshow_cpuinfo_cur_freq()instead ofcpufreq_verify_current_freq()?
Quoted 7 lines
Quoted 3 lines
Thanks,
Ionela.Yes.
I am not sure if making both the nodes 'scaling_cur_freq' and 'cpuinfo_cur_freq' same is fine?
That would happen anyway if arch_freq_get_on_cpu() is called from cpufreq_verify_current_freq().
In principle, according to [1], it would be correct to use it for 'cpuinfo_cur_freq' and not 'scaling_cur_freq'. But the call from show_scaling_cur_freq() is already there before these patches, introduced a long time ago for x86.
The topic was discussed at [2] and the agreement so far was that it would be best to keep the behaviour the same for both x86 and arm.
I don't like going against the user-guide, but these patches don't actually go against the user-guide. The old call to arch_freq_get_on_cpu() from show_scaling_cur_freq() goes against it. But I agree that's something necessary to keep, as legacy for x86. Additionally, you also mentioned that you'd prefer to have a more accurate frequency returned for 'scaling_cur_freq'.
[1] https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
[2] https://lore.kernel.org/lkml/20230609043922.eyyqutbwlofqaddz@vireshk-i7/
Thanks,
Ionela.
Quoted 3 lines
Best Regards,
Sumit Gupta
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
Quoted 63 lines
Quoted 63 lines
Quoted 62 lines
Quoted 44 lines
Quoted 26 lines
drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 11 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);Given that
arch_freq_get_on_cpu()is an average frequency, it does not seem right to me to trigger the sync & update process ofcpufreq_verify_current_freq()based on it.
cpufreq_verify_current_freq()will at least modify the internal state of the policy and send PRE and POST notifications, if not do a full frequency update, based on this average frequency, which is likely different from the current frequency, even beyond the 1MHz threshold.While I believe it's okay to return this average frequency in
cpuinfo_cur_freq, I don't think it should be used as an indication of an accurate current frequency, which is whatcpufreq_verify_current_freq()expects.Quoted 8 lines
Sumit, can you give more details on the issue at [1] and why this change fixes it?
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Ionela.
cpufreq_verify_current_freq()also updates 'policy->cur' in POST notification if the frequency from hardware has more delta (out of sync).As the value from '
cpufreq_driver->get()' is not reliable due to [1], calling the 'get' hook can update the 'policy->cur' with a wrong value when governor starts incpufreq_start_governor().
And if the frequency is never changed after the governor starts during boot e.g. when performance governor is set as default, then 'scaling_cur_freq' always returns wrong value.Quoted 4 lines
Instead, the
arch_freq_get_on_cpu()API updates 'policy->cur' with a more stable freq value.Got it, many thanks!
As the code is right now in v2,
arch_freq_get_on_cpu()is called onshow_scaling_cur_freq(), so the problem you describe would not show up.policy->curwould still be incorrect, but 'scaling_cur_freq' would return the value fromarch_freq_get_on_cpu().Would it be enough if
arch_freq_get_on_cpu()gets also called fromshow_cpuinfo_cur_freq()instead ofcpufreq_verify_current_freq()?Thanks,
Ionela.
Quoted 7 lines
Quoted 3 lines
Yes.
I am not sure if making both the nodes 'scaling_cur_freq' and 'cpuinfo_cur_freq' same is fine?That would happen anyway if
arch_freq_get_on_cpu()is called fromcpufreq_verify_current_freq().
Yes, that will happen in both the cases.
Quoted 8 lines
In principle, according to [1], it would be correct to use it for '
cpuinfo_cur_freq' and not 'scaling_cur_freq'. But the call fromshow_scaling_cur_freq()is already there before these patches, introduced a long time ago for x86.The topic was discussed at [2] and the agreement so far was that it would be best to keep the behaviour the same for both x86 and arm.
Looking at the previous discussion in [2], seems to be fine.
Best Regards,
Sumit Gupta
Quoted 16 lines
I don't like going against the user-guide, but these patches don't actually go against the user-guide. The old call to
arch_freq_get_on_cpu()fromshow_scaling_cur_freq()goes against it. But I agree that's something necessary to keep, as legacy for x86. Additionally, you also mentioned that you'd prefer to have a more accurate frequency returned for 'scaling_cur_freq'.[1] https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
[2] https://lore.kernel.org/lkml/20230609043922.eyyqutbwlofqaddz@vireshk-i7/Thanks,
Ionela.Quoted 3 lines
Best Regards,
Sumit Gupta
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
In reply to Ionela VoinescuHi Ionela,
So sorry for relpying so late, lost if from my rader for a while ...
Quoted 35 lines · Ionela Voinescu
Hi Beata, Sumit,
Quoted 21 lines · Beata Michalska
From: Sumit Gupta <[email protected]>
When available, use
arch_freq_get_on_cputo obtain current frequency (usually an average reported over given period of time)
to better align the cpufreq's view on the current state of affairs. This also automatically pulls in the update forcpuinfo_cur_freqsysfs attribute, aligning it with thescaling_cur_freqone, and thus providing consistent view on relevant platforms.Signed-off-by Sumit Gupta <[email protected]>[BM: Subject & commit msg]Signed-off-by Beata Michalska <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +0
-0drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 6 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);Given that
arch_freq_get_on_cpu()is an average frequency, it does not seem right to me to trigger the sync & update process ofcpufreq_verify_current_freq()based on it.
Quoted 5 lines
cpufreq_verify_current_freq()will at least modify the internal state of the policy and send PRE and POST notifications, if not do a full frequency update, based on this average frequency, which is likely different from the current frequency, even beyond the 1MHz threshold.
Noted, will drop this change.
---
BR
Beata
Quoted 6 lines
While I believe it's okay to return this average frequency in
cpuinfo_cur_freq, I don't think it should be used as an indication of an accurate current frequency, which is whatcpufreq_verify_current_freq()expects.
Quoted 7 lines
Sumit, can you give more details on the issue at [1] and why this change fixes it?
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Ionela.
>
Quoted 6 lines
Quoted 6 lines
drivers/cpufreq/cpufreq.c +0
-0if (!new_freq)return 0 ;Signature · 1 line
2.25.1
Rafael J. Wysocki
maintainerRe: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
In reply to Beata MichalskaQuoted 6 lines · Beata Michalska
From: Sumit Gupta <[email protected]>
When available, use
arch_freq_get_on_cputo obtain current frequency (usually an average reported over given period of time) to better align the cpufreq's view on the current state of affairs.
And why is this a good idea?
Any problem statement?
Quoted 3 lines
This also automatically pulls in the update for
cpuinfo_cur_freqsysfs attribute, aligning it with thescaling_cur_freqone, and thus providing consistent view on relevant platforms.
I have no idea what the above is supposed to mean, sorry.
Quoted 12 lines
Signed-off-by Sumit Gupta <[email protected]>[BM: Subject & commit msg]Signed-off-by Beata Michalska <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +0
-0
drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 6 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);
Please don't use ?: in general and it is not even useful here AFAICS.
What would be wrong with
new_freq = arch_freq_get_on_cpu(policy->cpu);
if (!new_freq)
new_freq = cpufreq_driver->get(policy->cpu);
?
Quoted 4 lines
drivers/cpufreq/cpufreq.c +0
-1if (!new_freq)return 0 ; --
Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq
Apologies for extremely late reply, juggling too many things at time ....
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Beata Michalska
From: Sumit Gupta <[email protected]>
When available, use
arch_freq_get_on_cputo obtain current frequency (usually an average reported over given period of time) to better align the cpufreq's view on the current state of affairs.And why is this a good idea?
Apart from being problematic with an issue pointed at [1] (which will result in dropping the change in cpufreq) this was to keep the cpufreq core aware of potential frequency changes and take appropriate action (informing the governor) case it got out of sync.
Quoted 2 lines
Any problem statement?
The problem has been raised here [2]
Quoted 6 lines
Quoted 4 lines
This also automatically pulls in the update for
cpuinfo_cur_freqsysfs attribute, aligning it with thescaling_cur_freqone, and thus providing consistent view on relevant platforms.I have no idea what the above is supposed to mean, sorry.
Bad wording I guess. With this change both 'cpuinfo_cur_freq' and 'scaling_cur_freq' will use the arch_freq_get_on_cpu if available, and will use the same source of information (one depending on a platform).
Quoted 22 lines
Quoted 13 lines
Signed-off-by Sumit Gupta <[email protected]>[BM: Subject & commit msg]Signed-off-by Beata Michalska <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/cpufreq/cpufreq.c +0
-0drivers/cpufreq/cpufreq.c static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b · line 1760
Quoted 6 lines
drivers/cpufreq/cpufreq.c +2
-1@@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b {unsigned int new_freq; - new_freq = cpufreq_driver->get (policy->cpu); + new_freq =arch_freq_get_on_cpu (policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get (policy->cpu);Please don't use ?: in general and it is not even useful here AFAICS.
Quoted 7 lines
What would be wrong with
new_freq=arch_freq_get_on_cpu(policy->cpu);
if (!new_freq)new_freq = cpufreq_driver->get(policy->cpu);?
Nothing wrong with that.
---
[1] https://lore.kernel.org/all/ZWXy0h%[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
---
BR
Beata
Quoted 5 lines
Quoted 5 lines
drivers/cpufreq/cpufreq.c +0
-1if (!new_freq)return 0 ; --