···6161 unsigned long util;6262 unsigned long max;6363 unsigned int flags;6464+6565+ /* The field below is for single-CPU policies only. */6666+#ifdef CONFIG_NO_HZ_COMMON6767+ unsigned long saved_idle_calls;6868+#endif6469};65706671static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);···9893{9994 struct cpufreq_policy *policy = sg_policy->policy;100959696+ if (sg_policy->next_freq == next_freq)9797+ return;9898+9999+ sg_policy->next_freq = next_freq;101100 sg_policy->last_freq_update_time = time;102101103102 if (policy->fast_switch_enabled) {104104- if (sg_policy->next_freq == next_freq) {105105- trace_cpu_frequency(policy->cur, smp_processor_id());106106- return;107107- }108108- sg_policy->next_freq = next_freq;109103 next_freq = cpufreq_driver_fast_switch(policy, next_freq);110104 if (next_freq == CPUFREQ_ENTRY_INVALID)111105 return;112106113107 policy->cur = next_freq;114108 trace_cpu_frequency(next_freq, smp_processor_id());115115- } else if (sg_policy->next_freq != next_freq) {116116- sg_policy->next_freq = next_freq;109109+ } else {117110 sg_policy->work_in_progress = true;118111 irq_work_queue(&sg_policy->irq_work);119112 }···195192 sg_cpu->iowait_boost >>= 1;196193}197194195195+#ifdef CONFIG_NO_HZ_COMMON196196+static bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu)197197+{198198+ unsigned long idle_calls = tick_nohz_get_idle_calls();199199+ bool ret = idle_calls == sg_cpu->saved_idle_calls;200200+201201+ sg_cpu->saved_idle_calls = idle_calls;202202+ return ret;203203+}204204+#else205205+static inline bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu) { return false; }206206+#endif /* CONFIG_NO_HZ_COMMON */207207+198208static void sugov_update_single(struct update_util_data *hook, u64 time,199209 unsigned int flags)200210{···216200 struct cpufreq_policy *policy = sg_policy->policy;217201 unsigned long util, max;218202 unsigned int next_f;203203+ bool busy;219204220205 sugov_set_iowait_boost(sg_cpu, time, flags);221206 sg_cpu->last_update = time;···224207 if (!sugov_should_update_freq(sg_policy, time))225208 return;226209210210+ busy = sugov_cpu_is_busy(sg_cpu);211211+227212 if (flags & SCHED_CPUFREQ_RT_DL) {228213 next_f = policy->cpuinfo.max_freq;229214 } else {230215 sugov_get_util(&util, &max);231216 sugov_iowait_boost(sg_cpu, &util, &max);232217 next_f = get_next_freq(sg_policy, util, max);218218+ /*219219+ * Do not reduce the frequency if the CPU has not been idle220220+ * recently, as the reduction is likely to be premature then.221221+ */222222+ if (busy && next_f < sg_policy->next_freq)223223+ next_f = sg_policy->next_freq;233224 }234225 sugov_update_commit(sg_policy, time, next_f);235226}236227237237-static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu,238238- unsigned long util, unsigned long max,239239- unsigned int flags)228228+static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu)240229{241230 struct sugov_policy *sg_policy = sg_cpu->sg_policy;242231 struct cpufreq_policy *policy = sg_policy->policy;243243- unsigned int max_f = policy->cpuinfo.max_freq;244232 u64 last_freq_update_time = sg_policy->last_freq_update_time;233233+ unsigned long util = 0, max = 1;245234 unsigned int j;246235247247- if (flags & SCHED_CPUFREQ_RT_DL)248248- return max_f;249249-250250- sugov_iowait_boost(sg_cpu, &util, &max);251251-252236 for_each_cpu(j, policy->cpus) {253253- struct sugov_cpu *j_sg_cpu;237237+ struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j);254238 unsigned long j_util, j_max;255239 s64 delta_ns;256240257257- if (j == smp_processor_id())258258- continue;259259-260260- j_sg_cpu = &per_cpu(sugov_cpu, j);261241 /*262242 * If the CPU utilization was last updated before the previous263243 * frequency update and the time elapsed between the last update···268254 continue;269255 }270256 if (j_sg_cpu->flags & SCHED_CPUFREQ_RT_DL)271271- return max_f;257257+ return policy->cpuinfo.max_freq;272258273259 j_util = j_sg_cpu->util;274260 j_max = j_sg_cpu->max;···303289 sg_cpu->last_update = time;304290305291 if (sugov_should_update_freq(sg_policy, time)) {306306- next_f = sugov_next_freq_shared(sg_cpu, util, max, flags);292292+ if (flags & SCHED_CPUFREQ_RT_DL)293293+ next_f = sg_policy->policy->cpuinfo.max_freq;294294+ else295295+ next_f = sugov_next_freq_shared(sg_cpu);296296+307297 sugov_update_commit(sg_policy, time, next_f);308298 }309299
+12
kernel/time/tick-sched.c
···993993 return ts->sleep_length;994994}995995996996+/**997997+ * tick_nohz_get_idle_calls - return the current idle calls counter value998998+ *999999+ * Called from the schedutil frequency scaling governor in scheduler context.10001000+ */10011001+unsigned long tick_nohz_get_idle_calls(void)10021002+{10031003+ struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);10041004+10051005+ return ts->idle_calls;10061006+}10071007+9961008static void tick_nohz_account_idle_ticks(struct tick_sched *ts)9971009{9981010#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE