cpufreq: Call transition notifier only once for each policy
Subsystems (6)
Viresh Kumar
maintainercover cpufreq: Call transition notifier only once for each policy
Currently we call the cpufreq transition notifiers once for each CPU of the policy->cpus cpumask, which isn't that efficient. This patchset tries to simplify that by adding another field in struct cpufreq_freqs, cpus, so the callback has all the information available with a single call for each policy.
I have tested this on arm64 platform and is compile tested for other platforms. This has gone through 0-day testing as well, I have pushed my branch over a week back to the public tree which gets tested by 0-day bot.
FWIW, it maybe possible to make the callback implementation more efficient now that they are called only once for each policy, but this patchset only did the minimum amount of changes to make sure we don't end up breaking otherwise working code.
--
viresh
Viresh Kumar (7):
cpufreq: Pass policy->related_cpus to transition notifiers
ARM: smp: Update cpufreq transition notifier to handle multiple CPUs
ARM: twd: Update cpufreq transition notifier to handle multiple CPUs
sparc64: Update cpufreq transition notifier to handle multiple CPUs x86/tsc: Update cpufreq transition notifier to handle multiple CPUs
KVM: x86: Update cpufreq transition notifier to handle multiple CPUs
cpufreq: Call transition notifiers only once for each policy
arch/arm/kernel/smp.c | 23 ++++++++++++++--------- arch/arm/kernel/smp_twd.c | 9 ++++++--- arch/sparc/kernel/time_64.c | 28 ++++++++++++++++------------ arch/x86/kernel/tsc.c | 31 ++++++++++++++++++++----------- arch/x86/kvm/x86.c | 31 ++++++++++++++++++++----------- drivers/cpufreq/cpufreq.c | 19 ++++++++++--------- include/linux/cpufreq.h | 2 +- 7 files changed, 87 insertions(+), 56 deletions(-)
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Viresh Kumar
maintainerPATCH 1/7 cpufreq: Pass policy->related_cpus to transition notifiers
Currently we call these notifiers once for each CPU of the policy->cpus cpumask, which isn't that efficient.
This patch adds a cpumask pointer to struct cpufreq_freqs and copies policy->related_cpus to it. The notifiers will have information about all the affected CPUs now with the first call itself and once all the notifier callbacks are updated to use the new field, we can remove the "cpu" field from struct cpufreq_freqs and call the notifier only once per policy.
Some of the transition notifier users use per-cpu data to read and store their data and they rely on it being correct. With CPU offline/online sequences we may end up with using stale data for those CPUs (which are offlined/onlined). In order to avoid such corner cases, this patch uses policy->related_cpus instead of policy->cpus.
--- drivers/cpufreq/cpufreq.c | 1 + include/linux/cpufreq.h | 1 + 2 files changed, 2 insertions(+)
drivers/cpufreq/cpufreq.c +1 -0
@@ -311,6 +311,7 @@ static void cpufreq_notify_transition(struct cpufreq_policy *policy,if (cpufreq_disabled ())return ; + freqs->cpus = policy->related_cpus; freqs->flags = cpufreq_driver->flags;pr_debug ("notification %u of frequency transition to %u kHz\n" , state, freqs->new);
include/linux/cpufreq.h +1 -0
@@ -43,6 +43,7 @@ enum cpufreq_table_sorting { };struct cpufreq_freqs { +struct cpumask *cpus;unsigned int cpu;/* cpu nr */ unsigned int old;unsigned int new;
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Viresh Kumar
maintainerPATCH 2/7 ARM: smp: Update cpufreq transition notifier to handle multiple CPUs
In reply to Viresh KumarThe cpufreq core currently calls the cpufreq transition notifier callback once for each affected CPU. This is going to change soon and the cpufreq core will call the callback only once for each cpufreq policy. The callback must look at the newly added field in struct cpufreq_freqs, "cpus", which contains policy->related_cpus (both online/offline CPUs) and perform per-cpu actions for them if any.
This patch updates cpufreq_callback() to use the new "cpus" field.
--- arch/arm/kernel/smp.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
arch/arm/kernel/smp.c +14 -9
@@ -758,15 +758,19 @@ static int cpufreq_callback(struct notifier_block *nb, unsigned long val, void *data) { struct cpufreq_freqs *freq = data; -int cpu = freq->cpu; +int cpu, first =cpumask_first (freq->cpus); +unsigned int lpj;if (freq->flags &CPUFREQ_CONST_LOOPS )return NOTIFY_OK ; -if (!per_cpu (l_p_j_ref, cpu)) { -per_cpu (l_p_j_ref, cpu) = -per_cpu (cpu_data, cpu).loops_per_jiffy; -per_cpu (l_p_j_ref_freq, cpu) = freq->old; +if (!per_cpu (l_p_j_ref, first)) { +for_each_cpu (cpu, freq->cpus) { +per_cpu (l_p_j_ref, cpu) = +per_cpu (cpu_data, cpu).loops_per_jiffy; +per_cpu (l_p_j_ref_freq, cpu) = freq->old; + } +if (!global_l_p_j_ref) { global_l_p_j_ref = loops_per_jiffy; global_l_p_j_ref_freq = freq->old;
@@ -778,10 +782,11 @@ static int cpufreq_callback(struct notifier_block *nb, loops_per_jiffy =cpufreq_scale (global_l_p_j_ref, global_l_p_j_ref_freq, freq->new); -per_cpu (cpu_data, cpu).loops_per_jiffy = -cpufreq_scale (per_cpu (l_p_j_ref, cpu), -per_cpu (l_p_j_ref_freq, cpu), - freq->new); + + lpj =cpufreq_scale (per_cpu (l_p_j_ref, first), +per_cpu (l_p_j_ref_freq, first), freq->new); +for_each_cpu (cpu, freq->cpus) +per_cpu (cpu_data, cpu).loops_per_jiffy = lpj; }return NOTIFY_OK ; }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Viresh Kumar
maintainerPATCH 3/7 ARM: twd: Update cpufreq transition notifier to handle multiple CPUs
In reply to Viresh KumarThe cpufreq core currently calls the cpufreq transition notifier callback once for each affected CPU. This is going to change soon and the cpufreq core will call the callback only once for each cpufreq policy. The callback must look at the newly added field in struct cpufreq_freqs, "cpus", which contains policy->related_cpus (both online/offline CPUs) and perform per-cpu actions for them if any.
This patch updates twd_cpufreq_transition() to use the new "cpus" field and run twd_update_frequency() for each online CPU present in the freqs->cpus.
--- arch/arm/kernel/smp_twd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm/kernel/smp_twd.c +6 -3
@@ -162,15 +162,18 @@ static int twd_cpufreq_transition(struct notifier_block *nb, unsigned long state, void *data) { struct cpufreq_freqs *freqs = data; +int cpu;/* * The twd clock events must be reprogrammed to account for the new * frequency. The timer is local to a cpu, so cross-call to the * changing cpu. */ -if (state ==CPUFREQ_POSTCHANGE ) -smp_call_function_single (freqs->cpu, twd_update_frequency, -NULL ,1 ); +if (state !=CPUFREQ_POSTCHANGE ) +return NOTIFY_OK ; + +for_each_cpu_and (cpu, freqs->cpus, cpu_online_mask) +smp_call_function_single (cpu, twd_update_frequency,NULL ,1 );return NOTIFY_OK ; }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Viresh Kumar
maintainerPATCH 4/7 sparc64: Update cpufreq transition notifier to handle multiple CPUs
In reply to Viresh KumarThe cpufreq core currently calls the cpufreq transition notifier callback once for each affected CPU. This is going to change soon and the cpufreq core will call the callback only once for each cpufreq policy. The callback must look at the newly added field in struct cpufreq_freqs, "cpus", which contains policy->related_cpus (both online/offline CPUs) and perform per-cpu actions for them if any.
This patch updates sparc64_cpufreq_notifier() to use the new "cpus" field and update per-cpu data for all the related CPUs.
--- arch/sparc/kernel/time_64.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
arch/sparc/kernel/time_64.c +16 -12
@@ -653,19 +653,23 @@ static int sparc64_cpufreq_notifier(struct notifier_block *nb, unsigned long val void *data) {struct cpufreq_freqs *freq = data; -unsigned int cpu = freq->cpu; -struct freq_table *ft = &per_cpu (sparc64_freq_table, cpu); +unsigned int cpu; +struct freq_table *ft; -if (!ft->ref_freq) { - ft->ref_freq = freq->old; - ft->clock_tick_ref =cpu_data (cpu).clock_tick; - } -if ((val ==CPUFREQ_PRECHANGE && freq->old < freq->new) || - (val ==CPUFREQ_POSTCHANGE && freq->old > freq->new)) { -cpu_data (cpu).clock_tick = -cpufreq_scale (ft->clock_tick_ref, - ft->ref_freq, - freq->new); +for_each_cpu (cpu, freq->cpus) { + ft = &per_cpu (sparc64_freq_table, cpu); + +if (!ft->ref_freq) { + ft->ref_freq = freq->old; + ft->clock_tick_ref =cpu_data (cpu).clock_tick; + } + +if ((val ==CPUFREQ_PRECHANGE && freq->old < freq->new) || + (val ==CPUFREQ_POSTCHANGE && freq->old > freq->new)) { +cpu_data (cpu).clock_tick = +cpufreq_scale (ft->clock_tick_ref, ft->ref_freq, + freq->new); + } }return 0 ;
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Viresh Kumar
maintainerPATCH 5/7 x86/tsc: Update cpufreq transition notifier to handle multiple CPUs
In reply to Viresh KumarThe cpufreq core currently calls the cpufreq transition notifier callback once for each affected CPU. This is going to change soon and the cpufreq core will call the callback only once for each cpufreq policy. The callback must look at the newly added field in struct cpufreq_freqs, "cpus", which contains policy->related_cpus (both online/offline CPUs) and perform per-cpu actions for them if any.
This patch updates time_cpufreq_notifier() to use the new "cpus" field, update per-cpu data for all the related CPUs and call set_cyc2ns_scale() for all online related_cpus.
--- arch/x86/kernel/tsc.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
arch/x86/kernel/tsc.c +20 -11
@@ -956,28 +956,37 @@ static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data) {struct cpufreq_freqs *freq = data; -unsigned long *lpj; - - lpj = &boot_cpu_data.loops_per_jiffy; -#ifdef CONFIG_SMP -if (!(freq->flags &CPUFREQ_CONST_LOOPS )) - lpj = &cpu_data (freq->cpu).loops_per_jiffy; -#endif +bool boot_cpu = !IS_ENABLED (CONFIG_SMP ) || freq->flags &CPUFREQ_CONST_LOOPS ; +unsigned long lpj; +int cpu;if (!ref_freq) { ref_freq = freq->old; - loops_per_jiffy_ref = *lpj; tsc_khz_ref = tsc_khz; + +if (boot_cpu) + loops_per_jiffy_ref = boot_cpu_data.loops_per_jiffy; +else + loops_per_jiffy_ref =cpu_data (cpumask_first (freq->cpus)).loops_per_jiffy; } +if ((val ==CPUFREQ_PRECHANGE && freq->old < freq->new) || (val ==CPUFREQ_POSTCHANGE && freq->old > freq->new)) { - *lpj =cpufreq_scale (loops_per_jiffy_ref, ref_freq, freq->new); - + lpj =cpufreq_scale (loops_per_jiffy_ref, ref_freq, freq->new); tsc_khz =cpufreq_scale (tsc_khz_ref, ref_freq, freq->new); +if (!(freq->flags &CPUFREQ_CONST_LOOPS ))mark_tsc_unstable ("cpufreq changes" ); -set_cyc2ns_scale (tsc_khz, freq->cpu,rdtsc ()); +if (boot_cpu) { + boot_cpu_data.loops_per_jiffy = lpj; + }else { +for_each_cpu (cpu, freq->cpus) +cpu_data (cpu).loops_per_jiffy = lpj; + } + +for_each_cpu_and (cpu, freq->cpus, cpu_online_mask) +set_cyc2ns_scale (tsc_khz, cpu,rdtsc ()); }return 0 ;
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Viresh Kumar
maintainerPATCH 6/7 KVM: x86: Update cpufreq transition notifier to handle multiple CPUs
In reply to Viresh KumarThe cpufreq core currently calls the cpufreq transition notifier callback once for each affected CPU. This is going to change soon and the cpufreq core will call the callback only once for each cpufreq policy. The callback must look at the newly added field in struct cpufreq_freqs, "cpus", which contains policy->related_cpus (both online/offline CPUs) and perform per-cpu actions for them if any.
This patch updates kvmclock_cpufreq_notifier() to use the new "cpus" field and perform the per-cpu activity for all online CPUs in this cpumask.
--- arch/x86/kvm/x86.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
arch/x86/kvm/x86.c +20 -11
@@ -6648,10 +6648,8 @@ static void kvm_hyperv_tsc_notifier(void) }#endif -static int kvmclock_cpufreq_notifier (struct notifier_block *nb,unsigned long val, -void *data) +static void __kvmclock_cpufreq_notifier (struct cpufreq_freqs *freq,int cpu) { -struct cpufreq_freqs *freq = data;struct kvm *kvm;struct kvm_vcpu *vcpu;int i, send_ipi =0 ;
@@ -6695,17 +6693,12 @@ static int kvmclock_cpufreq_notifier(struct notifier_block *nb, unsigned long va* */ -if (val ==CPUFREQ_PRECHANGE && freq->old > freq->new) -return 0 ; -if (val ==CPUFREQ_POSTCHANGE && freq->old < freq->new) -return 0 ; - -smp_call_function_single (freq->cpu, tsc_khz_changed, freq,1 ); +smp_call_function_single (cpu, tsc_khz_changed, freq,1 );spin_lock (&kvm_lock);list_for_each_entry (kvm, &vm_list, vm_list) {kvm_for_each_vcpu (i, vcpu, kvm) { -if (vcpu->cpu != freq->cpu) +if (vcpu->cpu != cpu)continue ;kvm_make_request (KVM_REQ_CLOCK_UPDATE , vcpu);if (vcpu->cpu !=smp_processor_id ())
@@ -6727,8 +6720,24 @@ static int kvmclock_cpufreq_notifier(struct notifier_block *nb, unsigned long va* guest context is entered kvmclock will be updated, * so the guest will not see stale values. */ -smp_call_function_single (freq->cpu, tsc_khz_changed, freq,1 ); +smp_call_function_single (cpu, tsc_khz_changed, freq,1 ); } +} + +static int kvmclock_cpufreq_notifier (struct notifier_block *nb,unsigned long val, +void *data) +{ +struct cpufreq_freqs *freq = data; +int cpu; + +if (val ==CPUFREQ_PRECHANGE && freq->old > freq->new) +return 0 ; +if (val ==CPUFREQ_POSTCHANGE && freq->old < freq->new) +return 0 ; + +for_each_cpu_and (cpu, freq->cpus, cpu_online_mask) +__kvmclock_cpufreq_notifier (freq, cpu); +return 0 ; }
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Viresh Kumar
maintainerPATCH 7/7 cpufreq: Call transition notifiers only once for each policy
In reply to Viresh KumarNow that all the transition notifier callbacks are updated to not rely on freqs->cpu and perform actions for all CPUs in the freqs->cpus field, it is time to get rid of freqs->cpu field and call the notifiers only once for each cpufreq policy.
--- drivers/cpufreq/cpufreq.c | 18 +++++++++--------- include/linux/cpufreq.h | 1 - 2 files changed, 9 insertions(+), 10 deletions(-)
drivers/cpufreq/cpufreq.c +9 -9
@@ -306,6 +306,8 @@ static void cpufreq_notify_transition(struct cpufreq_policy *policy,struct cpufreq_freqs *freqs, unsigned int state) { + int cpu; +BUG_ON (irqs_disabled ());if (cpufreq_disabled ())
@@ -331,10 +333,8 @@ static void cpufreq_notify_transition(struct cpufreq_policy *policy, } } -for_each_cpu (freqs->cpu, policy->cpus) { -srcu_notifier_call_chain (&cpufreq_transition_notifier_list, -CPUFREQ_PRECHANGE , freqs); - } +srcu_notifier_call_chain (&cpufreq_transition_notifier_list, +CPUFREQ_PRECHANGE , freqs);adjust_jiffies (CPUFREQ_PRECHANGE , freqs);break ;
@@ -344,11 +344,11 @@ static void cpufreq_notify_transition(struct cpufreq_policy *policy,pr_debug ("FREQ: %u - CPUs: %*pbl\n" , freqs->new,cpumask_pr_args (policy->cpus)); -for_each_cpu (freqs->cpu, policy->cpus) { -trace_cpu_frequency (freqs->new, freqs->cpu); -srcu_notifier_call_chain (&cpufreq_transition_notifier_list, -CPUFREQ_POSTCHANGE , freqs); - } +for_each_cpu (cpu, policy->cpus) +trace_cpu_frequency (freqs->new, cpu); + +srcu_notifier_call_chain (&cpufreq_transition_notifier_list, +CPUFREQ_POSTCHANGE , freqs);cpufreq_stats_record_transition (policy, freqs->new); policy->cur = freqs->new;
include/linux/cpufreq.h +0 -1
@@ -44,7 +44,6 @@ enum cpufreq_table_sorting {struct cpufreq_freqs {struct cpumask *cpus; -unsigned int cpu;/* cpu nr */ unsigned int old;unsigned int new;u8 flags;/* flags of cpufreq_driver, see below. */
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
Rafael J. Wysocki
maintainerQuoted 3 lines · Viresh Kumar
Currently we call the cpufreq transition notifiers once for each CPU of the
policy->cpuscpumask, which isn't that efficient.
Why isn't it efficient?
Transitions are per-policy anyway, so if something needs to be done for each CPU in the policy, it doesn't matter too much which part of the code carries out the iteration.
I guess some notifiers need to know what other CPUs there are in the policy? If so, then why?
Quoted 3 lines
This patchset tries to simplify that by adding another field in struct
cpufreq_freqs, cpus, so the callback has all the information available with a single call for each policy.
Well, you can argue that the core is simplified by it somewhat, but the notifiers aren't. They actually get more complex, conceptually too, because they now need to worry about offline vs online CPUs etc.
Also I wonder why you decided to pass a cpumask in freqs instead of just passing a policy pointer. If you change things from per-CPU to per-policy, passing the whole policy seems more natural.
Rafael J. Wysocki
maintainerRe: [PATCH 5/7] x86/tsc: Update cpufreq transition notifier to handle multiple CPUs
In reply to Viresh KumarQuoted 52 lines · Viresh Kumar
The cpufreq core currently calls the cpufreq transition notifier callback once for each affected CPU. This is going to change soon and the cpufreq core will call the callback only once for each cpufreq policy. The callback must look at the newly added field in struct
cpufreq_freqs, "cpus", which containspolicy->related_cpus(both online/offline CPUs) and perform per-cpu actions for them if any.This patch updates
time_cpufreq_notifier()to use the new "cpus" field, update per-cpu data for all the related CPUs and callset_cyc2ns_scale()for all onlinerelated_cpus.Signed-off-by Viresh Kumar <[email protected]>--- arch/x86/kernel/tsc.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)arch/x86/kernel/tsc.c +10
-10@@ -956,28 +956,37 @@ static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data) {struct cpufreq_freqs *freq = data; -unsigned long *lpj; - - lpj = &boot_cpu_data.loops_per_jiffy; -#ifdef CONFIG_SMP -if (!(freq->flags &CPUFREQ_CONST_LOOPS )) - lpj = &cpu_data (freq->cpu).loops_per_jiffy; -#endif +bool boot_cpu = !IS_ENABLED (CONFIG_SMP ) || freq->flags &CPUFREQ_CONST_LOOPS ; +unsigned long lpj; +int cpu;if (!ref_freq) { ref_freq = freq->old; - loops_per_jiffy_ref = *lpj; tsc_khz_ref = tsc_khz; + +if (boot_cpu) + loops_per_jiffy_ref = boot_cpu_data.loops_per_jiffy; +else + loops_per_jiffy_ref =cpu_data (cpumask_first (freq->cpus)).loops_per_jiffy; } +if ((val ==CPUFREQ_PRECHANGE && freq->old < freq->new) || (val ==CPUFREQ_POSTCHANGE && freq->old > freq->new)) { - *lpj =cpufreq_scale (loops_per_jiffy_ref, ref_freq, freq->new); - + lpj =cpufreq_scale (loops_per_jiffy_ref, ref_freq, freq->new);
arch/x86/kernel/tsc.c static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, · line 984
Quoted 10 lines
arch/x86/kernel/tsc.c +5
-1tsc_khz =cpufreq_scale (tsc_khz_ref, ref_freq, freq->new); +if (!(freq->flags &CPUFREQ_CONST_LOOPS ))mark_tsc_unstable ("cpufreq changes" ); -set_cyc2ns_scale (tsc_khz, freq->cpu,rdtsc ()); +if (boot_cpu) { + boot_cpu_data.loops_per_jiffy = lpj; + }else { +for_each_cpu (cpu, freq->cpus)
This needs to iterate over policy->cpus or you change the behavior.
Not that it will matter a lot (x86 in one CPU per policy anyway in the vast majority of cases), but it is a change nevertheless. Moreover, I'm not even sure if doing that for offline CPUs makes sense.
Quoted 9 lines
arch/x86/kernel/tsc.c +5
-1+cpu_data (cpu).loops_per_jiffy = lpj; + } + +for_each_cpu_and (cpu, freq->cpus, cpu_online_mask) +set_cyc2ns_scale (tsc_khz, cpu,rdtsc ()); }return 0 ; --
Rafael J. Wysocki
maintainerQuoted 19 lines · Rafael J. Wysocki
Quoted 3 lines · Viresh Kumar
Currently we call the cpufreq transition notifiers once for each CPU of the
policy->cpuscpumask, which isn't that efficient.Why isn't it efficient?
Transitions are per-policy anyway, so if something needs to be done for each CPU in the policy, it doesn't matter too much which part of the code carries out the iteration.
I guess some notifiers need to know what other CPUs there are in the policy? If so, then why?
Quoted 3 lines
This patchset tries to simplify that by adding another field in struct
cpufreq_freqs, cpus, so the callback has all the information available with a single call for each policy.
Quoted 7 lines
Well, you can argue that the core is simplified by it somewhat, but the notifiers aren't. They actually get more complex, conceptually too, because they now need to worry about offline vs online CPUs etc.
Also I wonder why you decided to pass a cpumask in freqs instead of just passing a policy pointer. If you change things from per-CPU to per-policy, passing the whole policy seems more natural.
It also looks to me like all that needs to be one patch, or you have the ugly transition situation in which notifiers are still invoked for each CPU, but they assume to be invoked once per policy.
Viresh Kumar
maintainerRe: [PATCH 5/7] x86/tsc: Update cpufreq transition notifier to handle multiple CPUs
In reply to Rafael J. WysockiQuoted 7 lines · Rafael J. Wysocki
arch/x86/kernel/tsc.c static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, · line 984
Quoted 5 lines · Viresh Kumar
arch/x86/kernel/tsc.c +4
-1-set_cyc2ns_scale (tsc_khz, freq->cpu,rdtsc ()); +if (boot_cpu) { + boot_cpu_data.loops_per_jiffy = lpj; + }else { +for_each_cpu (cpu, freq->cpus)
Quoted 5 lines
This needs to iterate over
policy->cpusor you change the behavior.Not that it will matter a lot (x86 in one CPU per policy anyway in the vast majority of cases), but it is a change nevertheless. Moreover, I'm not even sure if doing that for offline CPUs makes sense.
Okay.
Signature · 1 line
viresh
Viresh Kumar
maintainerQuoted 10 lines · Rafael J. Wysocki
Quoted 3 lines · Viresh Kumar
Currently we call the cpufreq transition notifiers once for each CPU of the
policy->cpuscpumask, which isn't that efficient.Why isn't it efficient?
Transitions are per-policy anyway, so if something needs to be done for each CPU in the policy, it doesn't matter too much which part of the code carries out the iteration.
Even if per-cpu iteration has to be done at some place, we are avoiding function calls here and the code/locking in the notifier layer as well. Will get more such info into changelog.
Quoted 2 lines
I guess some notifiers need to know what other CPUs there are in the policy? If so, then why?
You mean about the offline CPUs? I mentioned the rationale in 1/7. It is to avoid bugs where we may end up using a stale value if the CPUs are offlined/onlined regularly.
Quoted 7 lines
Quoted 3 lines
This patchset tries to simplify that by adding another field in struct
cpufreq_freqs, cpus, so the callback has all the information available with a single call for each policy.Well, you can argue that the core is simplified by it somewhat, but the notifiers aren't. They actually get more complex, conceptually too, because they now need to worry about offline vs online CPUs etc.
24 different parts of the kernel register for transition notifiers and only 5 required update here, the other 19 don't need to do per-cpu stuff and they also get benefited by this work. Those routines will get called only once now, instead of once per every CPU of the policy.
Quoted 3 lines
Also I wonder why you decided to pass a cpumask in freqs instead of just passing a policy pointer. If you change things from per-CPU to per-policy, passing the whole policy seems more natural.
I did that because they don't need to use the other fields of the policy today and that doesn't look likely in near future as well.
I can do that if you want, but not sure why more information should be provided than required.
Signature · 1 line
viresh
Viresh Kumar
maintainerQuoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 3 lines · Viresh Kumar
Currently we call the cpufreq transition notifiers once for each CPU of the
policy->cpuscpumask, which isn't that efficient.Why isn't it efficient?
Transitions are per-policy anyway, so if something needs to be done for each CPU in the policy, it doesn't matter too much which part of the code carries out the iteration.
I guess some notifiers need to know what other CPUs there are in the policy? If so, then why?
Quoted 3 lines
This patchset tries to simplify that by adding another field in struct
cpufreq_freqs, cpus, so the callback has all the information available with a single call for each policy.Well, you can argue that the core is simplified by it somewhat, but the notifiers aren't. They actually get more complex, conceptually too, because they now need to worry about offline vs online CPUs etc.
Quoted 7 lines
Quoted 3 lines
Also I wonder why you decided to pass a cpumask in freqs instead of just passing a policy pointer. If you change things from per-CPU to per-policy, passing the whole policy seems more natural.
It also looks to me like all that needs to be one patch, or you have the ugly transition situation in which notifiers are still invoked for each CPU, but they assume to be invoked once per policy.
I assumed that calling something like set_cyc2ns_scale() in x86 multiple times for each CPU shouldn't be that bad even if the frequency changes only once, but such things may actually have side-effects. I should merged them all.
Signature · 1 line
viresh
Rafael J. Wysocki
maintainerQuoted 17 lines · Viresh Kumar
Quoted 10 lines · Rafael J. Wysocki
Quoted 3 lines · Viresh Kumar
Currently we call the cpufreq transition notifiers once for each CPU of the
policy->cpuscpumask, which isn't that efficient.Why isn't it efficient?
Transitions are per-policy anyway, so if something needs to be done for each CPU in the policy, it doesn't matter too much which part of the code carries out the iteration.
Even if per-cpu iteration has to be done at some place, we are avoiding function calls here and the code/locking in the notifier layer as well. Will get more such info into changelog.
Quoted 6 lines
Quoted 2 lines
I guess some notifiers need to know what other CPUs there are in the policy? If so, then why?
You mean about the offline CPUs? I mentioned the rationale in 1/7. It is to avoid bugs where we may end up using a stale value if the CPUs are offlined/onlined regularly.
I'm not really convinced about this. CPU online really should take care of updating everything anyway.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
This patchset tries to simplify that by adding another field in struct
cpufreq_freqs, cpus, so the callback has all the information available with a single call for each policy.
Quoted 8 lines
Quoted 3 lines
Well, you can argue that the core is simplified by it somewhat, but the notifiers aren't. They actually get more complex, conceptually too, because they now need to worry about offline vs online CPUs etc.
24 different parts of the kernel register for transition notifiers and only 5 required update here, the other 19 don't need to do per-cpu stuff and they also get benefited by this work. Those routines will get called only once now, instead of once per every CPU of the policy.
This is a much better rationale for the change than the one given originally IMO. :-)
Quoted 6 lines
Quoted 3 lines
Also I wonder why you decided to pass a cpumask in freqs instead of just passing a policy pointer. If you change things from per-CPU to per-policy, passing the whole policy seems more natural.
I did that because they don't need to use the other fields of the policy today and that doesn't look likely in near future as well.
But some of them need to combine the new cpumask with cpu_online_mask() to get what would be policy->cpus effectively. That would be avoidable if you passed the policy pointer to them.
Viresh Kumar
maintainerQuoted 4 lines · Rafael J. Wysocki
On Thu, Mar 14, 2019 at 11:16 AM Viresh Kumar <[email protected]> wrote:
But some of them need to combine the new cpumask withcpu_online_mask()to get what would bepolicy->cpuseffectively. That would be avoidable if you passed the policy pointer to them.
Right, that's what I also thought after your previous email. Will pass the policy pointer instead.
Signature · 1 line
viresh
Re: [PATCH 4/7] sparc64: Update cpufreq transition notifier to handle multiple CPUs
In reply to Viresh KumarFrom: Viresh Kumar <[email protected]>
Date: Thu, 14 Mar 2019 12:12:50 +0530
Quoted 11 lines
The cpufreq core currently calls the cpufreq transition notifier callback once for each affected CPU. This is going to change soon and the cpufreq core will call the callback only once for each cpufreq policy. The callback must look at the newly added field in struct
cpufreq_freqs, "cpus", which containspolicy->related_cpus(both online/offline CPUs) and perform per-cpu actions for them if any.This patch updates
sparc64_cpufreq_notifier()to use the new "cpus" field and update per-cpu data for all the related CPUs.Signed-off-by Viresh Kumar <[email protected]>