cpufreq: schedutil: Use idle_calls counter of the remote CPU

Since the recent remote cpufreq callback work, its possible that a cpufreq
update is triggered from a remote CPU. For single policies however, the current
code uses the local CPU when trying to determine if the remote sg_cpu entered
idle or is busy. This is incorrect. To remedy this, compare with the nohz tick
idle_calls counter of the remote CPU.

Fixes: 674e75411fc2 (sched: cpufreq: Allow remote cpufreq callbacks)
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Joel Fernandes <joelaf@google.com>
Cc: 4.14+ <stable@vger.kernel.org> # 4.14+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by Joel Fernandes and committed by Rafael J. Wysocki 466a2b42 464e1d5f

+15 -1
+1
include/linux/tick.h
··· 119 119 extern void tick_nohz_irq_exit(void); 120 120 extern ktime_t tick_nohz_get_sleep_length(void); 121 121 extern unsigned long tick_nohz_get_idle_calls(void); 122 + extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); 122 123 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); 123 124 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); 124 125 #else /* !CONFIG_NO_HZ_COMMON */
+1 -1
kernel/sched/cpufreq_schedutil.c
··· 244 244 #ifdef CONFIG_NO_HZ_COMMON 245 245 static bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu) 246 246 { 247 - unsigned long idle_calls = tick_nohz_get_idle_calls(); 247 + unsigned long idle_calls = tick_nohz_get_idle_calls_cpu(sg_cpu->cpu); 248 248 bool ret = idle_calls == sg_cpu->saved_idle_calls; 249 249 250 250 sg_cpu->saved_idle_calls = idle_calls;
+13
kernel/time/tick-sched.c
··· 986 986 } 987 987 988 988 /** 989 + * tick_nohz_get_idle_calls_cpu - return the current idle calls counter value 990 + * for a particular CPU. 991 + * 992 + * Called from the schedutil frequency scaling governor in scheduler context. 993 + */ 994 + unsigned long tick_nohz_get_idle_calls_cpu(int cpu) 995 + { 996 + struct tick_sched *ts = tick_get_tick_sched(cpu); 997 + 998 + return ts->idle_calls; 999 + } 1000 + 1001 + /** 989 1002 * tick_nohz_get_idle_calls - return the current idle calls counter value 990 1003 * 991 1004 * Called from the schedutil frequency scaling governor in scheduler context.