cpufreq: schedutil: Examine the correct CPU when we update util
Subsystems (3)
PATCH 1/1 cpufreq: schedutil: Examine the correct CPU when we update util
Since:
4296f23ed cpufreq: schedutil: Fix per-CPU structure initialization in
sugov_start()
We lost the value of sg_cpu->cpu which is assigned during sugov_register. The memset in sugov_start overwrites it with zero.
This leads to always looking at the utilization of CPU0 instead of the one we just updated when we do a utilization update callback.
Let's fix this by consolidating the initialization code into sugov_start().
--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/sched/cpufreq_schedutil.c +1 -5
@@ -731,6 +731,7 @@ static int sugov_start(struct cpufreq_policy *policy) sg_cpu->sg_policy = sg_policy; sg_cpu->flags =SCHED_CPUFREQ_RT ; sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq; + sg_cpu->cpu = cpu; }for_each_cpu (cpu, policy->cpus) {
@@ -793,11 +794,6 @@ struct cpufreq_governor *cpufreq_default_governor(void)static int __init sugov_register (void ) { -int cpu; - -for_each_possible_cpu (cpu) -per_cpu (sugov_cpu, cpu).cpu = cpu; -return cpufreq_register_governor (&schedutil_gov); }fs_initcall (sugov_register);
Signature · 1 line
2.13.1.449.g02a2850
Viresh Kumar
maintainerQuoted 4 lines · Chris Redpath
Since:
4296f23edcpufreq: schedutil: Fix per-CPU structure initialization in
sugov_start()
Good catch but you pointed out to the wrong commit really.
674e75411fc2 ("sched: cpufreq: Allow remote cpufreq callbacks"
is the real culprit as that's where the 'cpu' field is added.
Quoted 10 lines
We lost the value of
sg_cpu->cpuwhich is assigned duringsugov_register. The memset insugov_startoverwrites it with zero.This leads to always looking at the utilization of CPU0 instead of the one we just updated when we do a utilization update callback.
Let's fix this by consolidating the initialization code into
sugov_start().Fixes 4296f23ed49a ("cpufreq: schedutil: Fix per-CPU structure initialization in sugov_start()")
Quoted 8 lines
Signed-off-by Chris Redpath <[email protected]>Reviewed-by Patrick Bellasi <[email protected]>Reviewed-by Brendan Jackman <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Viresh Kumar <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc 4.9+ <[email protected]>
This wouldn't be required now as it got merged in 4.14 only and Rafael should be able to get that as part of 4.14 itself.
kernel/sched/cpufreq_schedutil.c static int sugov_start(struct cpufreq_policy *policy) · line 734
Quoted 13 lines
--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/cpufreq_schedutil.c +1
-0@@ -731,6 +731,7 @@ static int sugov_start(struct cpufreq_policy *policy) sg_cpu->sg_policy = sg_policy; sg_cpu->flags =SCHED_CPUFREQ_RT ; sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq; + sg_cpu->cpu = cpu;
Maybe just move this below memset.
Quoted 5 lines
kernel/sched/cpufreq_schedutil.c +0
-0}for_each_cpu (cpu, policy->cpus) {@@ -793,11 +794,6 @@ struct cpufreq_governor *cpufreq_default_governor(void)
kernel/sched/cpufreq_schedutil.c struct cpufreq_governor *cpufreq_default_governor(void) · line 799
Quoted 10 lines
kernel/sched/cpufreq_schedutil.c +0
-5static int __init sugov_register (void ) { -int cpu; - -for_each_possible_cpu (cpu) -per_cpu (sugov_cpu, cpu).cpu = cpu; -return cpufreq_register_governor (&schedutil_gov); }fs_initcall (sugov_register);
Diff looks fine though.
Signature · 1 line
viresh
PATCH v2 1/1 cpufreq: schedutil: Examine the correct CPU when we update util
Since:4296f23ed cpufreq: schedutil: Fix per-CPU structure initialization in
sugov_start()
We lost the value of sg_cpu->cpu which is assigned during sugov_register. The memset in sugov_start overwrites it with zero.
The change here was triggered by the commit adding the remote update functionality.674e75411fc2 ("sched: cpufreq: Allow remote cpufreq callbacks")
This leads to always looking at the utilization of CPU0 instead of the one we just updated when we do a utilization update callback.
Let's fix this by consolidating the initialization code into sugov_start().
--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/sched/cpufreq_schedutil.c +1 -5
@@ -728,6 +728,7 @@ static int sugov_start(struct cpufreq_policy *policy)struct sugov_cpu *sg_cpu = &per_cpu (sugov_cpu, cpu);memset (sg_cpu,0 ,sizeof (*sg_cpu)); + sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; sg_cpu->flags =SCHED_CPUFREQ_RT ; sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
@@ -793,11 +794,6 @@ struct cpufreq_governor *cpufreq_default_governor(void)static int __init sugov_register (void ) { -int cpu; - -for_each_possible_cpu (cpu) -per_cpu (sugov_cpu, cpu).cpu = cpu; -return cpufreq_register_governor (&schedutil_gov); }fs_initcall (sugov_register);
Signature · 1 line
2.13.1.449.g02a2850
Viresh Kumar
maintainerQuoted 3 lines · Chris Redpath
Since:
4296f23edcpufreq: schedutil: Fix per-CPU structure initialization in
sugov_start()
This is still incorrect. This BUG has nothing to do with 4296f23ed AFAICT.
Quoted 51 lines
We lost the value of
sg_cpu->cpuwhich is assigned duringsugov_register. The memset insugov_startoverwrites it with zero.The change here was triggered by the commit adding the remote update functionality.
674e75411fc2("sched: cpufreq: Allow remote cpufreq callbacks")This leads to always looking at the utilization of CPU0 instead of the one we just updated when we do a utilization update callback.
Let's fix this by consolidating the initialization code into
sugov_start().Fixes 674e75411fc2 ("sched: cpufreq: Allow remote cpufreq callbacks")Signed-off-by Chris Redpath <[email protected]>Reviewed-by Patrick Bellasi <[email protected]>Reviewed-by Brendan Jackman <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Viresh Kumar <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/cpufreq_schedutil.c +1
-5@@ -728,6 +728,7 @@ static int sugov_start(struct cpufreq_policy *policy)struct sugov_cpu *sg_cpu = &per_cpu (sugov_cpu, cpu);memset (sg_cpu,0 ,sizeof (*sg_cpu)); + sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; sg_cpu->flags =SCHED_CPUFREQ_RT ; sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;@@ -793,11 +794,6 @@ struct cpufreq_governor *cpufreq_default_governor(void)static int __init sugov_register (void ) { -int cpu; - -for_each_possible_cpu (cpu) -per_cpu (sugov_cpu, cpu).cpu = cpu; -return cpufreq_register_governor (&schedutil_gov); }fs_initcall (sugov_register);Signature · 1 line
2.13.1.449.g02a2850
Signature · 1 line
viresh
Hi Viresh
Quoted 8 lines · Viresh Kumar
Quoted 3 lines · Chris Redpath
Since:
4296f23edcpufreq: schedutil: Fix per-CPU structure initialization in
sugov_start()This is still incorrect. This BUG has nothing to do with
4296f23edAFAICT.
According to my diff, this was the commit which switched from assigning the values directly (and not overwriting the cpu member, which was introduced in the other commit you reference) to using a memset and clearing the whole struct. I figured that the fix (which was for a different issue) inadvertently exposed this, which was what I was trying to convey here. I can remove this and just reference 674e75411fc2. It's clear that what's broken is the remote update.
I'll reply with a v3 shortly.
--Chris
Quoted 39 lines
Quoted 39 lines
We lost the value of
sg_cpu->cpuwhich is assigned duringsugov_register. The memset insugov_startoverwrites it with zero.The change here was triggered by the commit adding the remote update functionality.
674e75411fc2("sched: cpufreq: Allow remote cpufreq callbacks")This leads to always looking at the utilization of CPU0 instead of the one we just updated when we do a utilization update callback.
Let's fix this by consolidating the initialization code into
sugov_start().Fixes 674e75411fc2 ("sched: cpufreq: Allow remote cpufreq callbacks")Signed-off-by Chris Redpath <[email protected]>Reviewed-by Patrick Bellasi <[email protected]>Reviewed-by Brendan Jackman <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Viresh Kumar <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/cpufreq_schedutil.c +1
-0@@ -728,6 +728,7 @@ static int sugov_start(struct cpufreq_policy *policy)struct sugov_cpu *sg_cpu = &per_cpu (sugov_cpu, cpu);memset (sg_cpu,0 ,sizeof (*sg_cpu)); + sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; sg_cpu->flags =SCHED_CPUFREQ_RT ; sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;@@ -793,11 +794,6 @@ struct cpufreq_governor *cpufreq_default_governor(void)
Quoted 13 lines
Quoted 11 lines
kernel/sched/cpufreq_schedutil.c +0
-6static int __init sugov_register (void ) { -int cpu; - -for_each_possible_cpu (cpu) -per_cpu (sugov_cpu, cpu).cpu = cpu; -return cpufreq_register_governor (&schedutil_gov); }fs_initcall (sugov_register); --Quoted 1 line
2.13.1.449.g02a2850
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Viresh Kumar
maintainerQuoted 4 lines · Chris Redpath
According to my diff, this was the commit which switched from assigning the values directly (and not overwriting the cpu member, which was introduced in the other commit you reference) to using a memset and clearing the whole struct.
I understand what you want to convey here but the log says something else according to me. It says:
"Since: 4296f23ed cpufreq: schedutil: Fix per-CPU structure initialization in sugov_start(), We lost the value of sg_cpu->cpu which is assigned during sugov_register."
Reading this line it looks like sg_cpu->cpu was screwed up by 4296f23ed, which happened in 4.9. But the sg_cpu->cpu field itself got added in 4.14 and so I think we should write it differently.
If I were you, I wouldn't mention 4296f23ed here at all but just say that memset() is clearing the value of sg_cpu->cpu, fix that.
Thanks.
Signature · 1 line
viresh
PATCH v3 1/1 cpufreq: schedutil: Examine the correct CPU when we update util
After674e75411fc2 ("sched: cpufreq: Allow remote cpufreq callbacks")
We stopped always reading utilization for the cpu we are running the governor on, and instead read it for the cpu which we've been told has updated utilization. This is stored in sugov_cpu->cpu.
The value is set in sugov_register but we clear it in sugov_start which leads to always looking at the utilization of CPU0 instead of the correct one.
Let's fix this by consolidating the initialization code into sugov_start().
--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/sched/cpufreq_schedutil.c +1 -5
@@ -728,6 +728,7 @@ static int sugov_start(struct cpufreq_policy *policy)struct sugov_cpu *sg_cpu = &per_cpu (sugov_cpu, cpu);memset (sg_cpu,0 ,sizeof (*sg_cpu)); + sg_cpu->cpu = cpu; sg_cpu->sg_policy = sg_policy; sg_cpu->flags =SCHED_CPUFREQ_RT ; sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
@@ -793,11 +794,6 @@ struct cpufreq_governor *cpufreq_default_governor(void)static int __init sugov_register (void ) { -int cpu; - -for_each_possible_cpu (cpu) -per_cpu (sugov_cpu, cpu).cpu = cpu; -return cpufreq_register_governor (&schedutil_gov); }fs_initcall (sugov_register);
Signature · 1 line
2.13.1.449.g02a2850
Quoted 22 lines · Chris Redpath
After
674e75411fc2("sched: cpufreq: Allow remote cpufreq callbacks")We stopped always reading utilization for the cpu we are running the governor on, and instead read it for the cpu which we've been told has updated utilization. This is stored in
sugov_cpu->cpu.The value is set in
sugov_registerbut we clear it insugov_startwhich leads to always looking at the utilization of CPU0 instead of the correct one.Let's fix this by consolidating the initialization code into
sugov_start().Fixes 674e75411fc2 ("sched: cpufreq: Allow remote cpufreq callbacks")Signed-off-by Chris Redpath <[email protected]>Reviewed-by Patrick Bellasi <[email protected]>Reviewed-by Brendan Jackman <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Viresh Kumar <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>
Quoted 3 lines
--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Signature · 1 line
viresh
Hi Viresh, Rafael,
Without this patch, schedutil is totally broken for us - is there any chance at all this could go in 4.14 or is it just too late?
Best Regards,
Chris
Quoted 27 lines · Viresh Kumar
Quoted 22 lines · Chris Redpath
After
674e75411fc2("sched: cpufreq: Allow remote cpufreq callbacks")We stopped always reading utilization for the cpu we are running the governor on, and instead read it for the cpu which we've been told has updated utilization. This is stored in
sugov_cpu->cpu.The value is set in
sugov_registerbut we clear it insugov_startwhich leads to always looking at the utilization of CPU0 instead of the correct one.Let's fix this by consolidating the initialization code into
sugov_start().Fixes 674e75411fc2 ("sched: cpufreq: Allow remote cpufreq callbacks")Signed-off-by Chris Redpath <[email protected]>Reviewed-by Patrick Bellasi <[email protected]>Reviewed-by Brendan Jackman <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Viresh Kumar <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Quoted 3 lines
--- kernel/sched/cpufreq_schedutil.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
Quoted 2 lines
Acked-by Viresh Kumar <[email protected]>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Viresh Kumar
maintainerQuoted 5 lines · Chris Redpath
Hi Viresh, Rafael,
Without this patch, schedutil is totally broken for us - is there any chance at all this could go in 4.14 or is it just too late?
I see that Rafael has already applied it, but not sure if he is planning to send it for 4.14 (though he should IMHO, as it is a critical fix).
commit d62d813c0d71 ("cpufreq: schedutil: Examine the correct CPU when we update util")
--
viresh
Rafael J. Wysocki
maintainerQuoted 9 lines · Viresh Kumar
Quoted 5 lines · Chris Redpath
Hi Viresh, Rafael,
Without this patch, schedutil is totally broken for us - is there any chance at all this could go in 4.14 or is it just too late?
I see that Rafael has already applied it, but not sure if he is planning to send it for 4.14 (though he should IMHO, as it is a critical fix).
Yes, I am.
Thanks,
Rafael
Thanks guys, really appreciated!
--Chris
Quoted 16 lines · Rafael J. Wysocki
Quoted 9 lines · Viresh Kumar
Quoted 5 lines · Chris Redpath
Hi Viresh, Rafael,
Without this patch, schedutil is totally broken for us - is there any chance at all this could go in 4.14 or is it just too late?
I see that Rafael has already applied it, but not sure if he is planning to send it for 4.14 (though he should IMHO, as it is a critical fix).
Yes, I am.
Thanks,
Rafael