blob: 626ddd4ffa4333723a405e639258c44d9dd55dd0 [file] [log] [blame]
Daniel Lezcano108c35a2018-12-03 11:29:29 +01001// SPDX-License-Identifier: GPL-2.0
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +02002/*
3 * CPUFreq governor based on scheduler-provided CPU utilization data.
4 *
5 * Copyright (C) 2016, Intel Corporation
6 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +02007 */
8
Viresh Kumar60f05e82016-05-18 17:55:28 +05309#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020011#include "sched.h"
12
Ingo Molnar325ea102018-03-03 12:20:47 +010013#include <trace/events/power.h>
14
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020015struct sugov_tunables {
Ingo Molnar97fb7a02018-03-03 14:01:12 +010016 struct gov_attr_set attr_set;
17 unsigned int rate_limit_us;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020018};
19
20struct sugov_policy {
Ingo Molnar97fb7a02018-03-03 14:01:12 +010021 struct cpufreq_policy *policy;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020022
Ingo Molnar97fb7a02018-03-03 14:01:12 +010023 struct sugov_tunables *tunables;
24 struct list_head tunables_hook;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020025
Ingo Molnar97fb7a02018-03-03 14:01:12 +010026 raw_spinlock_t update_lock; /* For shared policies */
27 u64 last_freq_update_time;
28 s64 freq_update_delay_ns;
29 unsigned int next_freq;
30 unsigned int cached_raw_freq;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020031
Ingo Molnar97fb7a02018-03-03 14:01:12 +010032 /* The next fields are only needed if fast switch cannot be used: */
33 struct irq_work irq_work;
34 struct kthread_work work;
35 struct mutex work_lock;
36 struct kthread_worker worker;
37 struct task_struct *thread;
38 bool work_in_progress;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020039
Ingo Molnar97fb7a02018-03-03 14:01:12 +010040 bool need_freq_update;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020041};
42
43struct sugov_cpu {
Ingo Molnar97fb7a02018-03-03 14:01:12 +010044 struct update_util_data update_util;
45 struct sugov_policy *sg_policy;
46 unsigned int cpu;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020047
Ingo Molnar97fb7a02018-03-03 14:01:12 +010048 bool iowait_boost_pending;
49 unsigned int iowait_boost;
50 unsigned int iowait_boost_max;
Patrick Bellasifd7d5282018-05-22 12:07:54 +010051 u64 last_update;
Steve Muckle5cbea462016-07-13 13:25:26 -070052
Vincent Guittot8cc90512018-06-28 17:45:08 +020053 unsigned long bw_dl;
Ingo Molnar97fb7a02018-03-03 14:01:12 +010054 unsigned long max;
Rafael J. Wysockib7eaf1a2017-03-22 00:08:50 +010055
Ingo Molnar97fb7a02018-03-03 14:01:12 +010056 /* The field below is for single-CPU policies only: */
Rafael J. Wysockib7eaf1a2017-03-22 00:08:50 +010057#ifdef CONFIG_NO_HZ_COMMON
Ingo Molnar97fb7a02018-03-03 14:01:12 +010058 unsigned long saved_idle_calls;
Rafael J. Wysockib7eaf1a2017-03-22 00:08:50 +010059#endif
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020060};
61
62static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);
63
64/************************ Governor internals ***********************/
65
66static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
67{
68 s64 delta_ns;
69
Viresh Kumar674e7542017-07-28 12:16:38 +053070 /*
71 * Since cpufreq_update_util() is called with rq->lock held for
Ingo Molnar97fb7a02018-03-03 14:01:12 +010072 * the @target_cpu, our per-CPU data is fully serialized.
Viresh Kumar674e7542017-07-28 12:16:38 +053073 *
Ingo Molnar97fb7a02018-03-03 14:01:12 +010074 * However, drivers cannot in general deal with cross-CPU
Viresh Kumar674e7542017-07-28 12:16:38 +053075 * requests, so while get_next_freq() will work, our
Viresh Kumarc49cbc12017-08-14 14:50:16 +053076 * sugov_update_commit() call may not for the fast switching platforms.
Viresh Kumar674e7542017-07-28 12:16:38 +053077 *
78 * Hence stop here for remote requests if they aren't supported
79 * by the hardware, as calculating the frequency is pointless if
80 * we cannot in fact act on it.
Viresh Kumarc49cbc12017-08-14 14:50:16 +053081 *
82 * For the slow switching platforms, the kthread is always scheduled on
83 * the right set of CPUs and any CPU can find the next frequency and
84 * schedule the kthread.
Viresh Kumar674e7542017-07-28 12:16:38 +053085 */
Viresh Kumarc49cbc12017-08-14 14:50:16 +053086 if (sg_policy->policy->fast_switch_enabled &&
Viresh Kumar03639972018-05-22 15:31:30 +053087 !cpufreq_this_cpu_can_update(sg_policy->policy))
Viresh Kumar674e7542017-07-28 12:16:38 +053088 return false;
89
Viresh Kumarecd28842018-05-09 16:05:24 +053090 if (unlikely(sg_policy->need_freq_update))
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020091 return true;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020092
93 delta_ns = time - sg_policy->last_freq_update_time;
Ingo Molnar97fb7a02018-03-03 14:01:12 +010094
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +020095 return delta_ns >= sg_policy->freq_update_delay_ns;
96}
97
Rafael J. Wysockia61dec72018-05-23 11:47:45 +020098static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time,
99 unsigned int next_freq)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200100{
Rafael J. Wysocki38d4ea22017-03-22 18:32:47 +0100101 if (sg_policy->next_freq == next_freq)
Rafael J. Wysockia61dec72018-05-23 11:47:45 +0200102 return false;
Rafael J. Wysocki38d4ea22017-03-22 18:32:47 +0100103
104 sg_policy->next_freq = next_freq;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200105 sg_policy->last_freq_update_time = time;
106
Rafael J. Wysockia61dec72018-05-23 11:47:45 +0200107 return true;
108}
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200109
Rafael J. Wysockia61dec72018-05-23 11:47:45 +0200110static void sugov_fast_switch(struct sugov_policy *sg_policy, u64 time,
111 unsigned int next_freq)
112{
113 struct cpufreq_policy *policy = sg_policy->policy;
114
115 if (!sugov_update_next_freq(sg_policy, time, next_freq))
116 return;
117
118 next_freq = cpufreq_driver_fast_switch(policy, next_freq);
119 if (!next_freq)
120 return;
121
122 policy->cur = next_freq;
123 trace_cpu_frequency(next_freq, smp_processor_id());
124}
125
126static void sugov_deferred_update(struct sugov_policy *sg_policy, u64 time,
127 unsigned int next_freq)
128{
129 if (!sugov_update_next_freq(sg_policy, time, next_freq))
130 return;
131
132 if (!sg_policy->work_in_progress) {
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200133 sg_policy->work_in_progress = true;
134 irq_work_queue(&sg_policy->irq_work);
135 }
136}
137
138/**
139 * get_next_freq - Compute a new frequency for a given cpufreq policy.
Viresh Kumar655cb1e2017-03-02 14:03:21 +0530140 * @sg_policy: schedutil policy object to compute the new frequency for.
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200141 * @util: Current CPU utilization.
142 * @max: CPU capacity.
143 *
144 * If the utilization is frequency-invariant, choose the new frequency to be
145 * proportional to it, that is
146 *
147 * next_freq = C * max_freq * util / max
148 *
149 * Otherwise, approximate the would-be frequency-invariant utilization by
150 * util_raw * (curr_freq / max_freq) which leads to
151 *
152 * next_freq = C * curr_freq * util_raw / max
153 *
154 * Take C = 1.25 for the frequency tipping point at (util / max) = 0.8.
Steve Muckle5cbea462016-07-13 13:25:26 -0700155 *
156 * The lowest driver-supported frequency which is equal or greater than the raw
157 * next_freq (as calculated above) is returned, subject to policy min/max and
158 * cpufreq driver limitations.
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200159 */
Viresh Kumar655cb1e2017-03-02 14:03:21 +0530160static unsigned int get_next_freq(struct sugov_policy *sg_policy,
161 unsigned long util, unsigned long max)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200162{
Steve Muckle5cbea462016-07-13 13:25:26 -0700163 struct cpufreq_policy *policy = sg_policy->policy;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200164 unsigned int freq = arch_scale_freq_invariant() ?
165 policy->cpuinfo.max_freq : policy->cur;
166
Steve Muckle5cbea462016-07-13 13:25:26 -0700167 freq = (freq + (freq >> 2)) * util / max;
168
Viresh Kumarecd28842018-05-09 16:05:24 +0530169 if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update)
Steve Muckle5cbea462016-07-13 13:25:26 -0700170 return sg_policy->next_freq;
Viresh Kumarecd28842018-05-09 16:05:24 +0530171
172 sg_policy->need_freq_update = false;
Viresh Kumar6c4f0fa2017-03-02 14:03:20 +0530173 sg_policy->cached_raw_freq = freq;
Steve Muckle5cbea462016-07-13 13:25:26 -0700174 return cpufreq_driver_resolve_freq(policy, freq);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200175}
176
Peter Zijlstra45f55192018-07-05 14:36:17 +0200177/*
178 * This function computes an effective utilization for the given CPU, to be
179 * used for frequency selection given the linear relation: f = u * f_max.
180 *
181 * The scheduler tracks the following metrics:
182 *
183 * cpu_util_{cfs,rt,dl,irq}()
184 * cpu_bw_dl()
185 *
186 * Where the cfs,rt and dl util numbers are tracked with the same metric and
187 * synchronized windows and are thus directly comparable.
188 *
189 * The cfs,rt,dl utilization are the running times measured with rq->clock_task
190 * which excludes things like IRQ and steal-time. These latter are then accrued
191 * in the irq utilization.
192 *
193 * The DL bandwidth number otoh is not a measured metric but a value computed
194 * based on the task model parameters and gives the minimal utilization
195 * required to meet deadlines.
196 */
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200197static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu)
Rafael J. Wysocki58919e82016-08-16 22:14:55 +0200198{
Juri Lellid18be452017-12-04 11:23:21 +0100199 struct rq *rq = cpu_rq(sg_cpu->cpu);
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200200 unsigned long util, irq, max;
Steve Muckle8314bc82016-08-26 11:40:47 -0700201
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200202 sg_cpu->max = max = arch_scale_cpu_capacity(NULL, sg_cpu->cpu);
203 sg_cpu->bw_dl = cpu_bw_dl(rq);
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100204
Vincent Guittot296b2ff2018-06-26 15:53:22 +0200205 if (rt_rq_is_runnable(&rq->rt))
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200206 return max;
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100207
Peter Zijlstra45f55192018-07-05 14:36:17 +0200208 /*
209 * Early check to see if IRQ/steal time saturates the CPU, can be
210 * because of inaccuracies in how we track these -- see
211 * update_irq_load_avg().
212 */
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200213 irq = cpu_util_irq(rq);
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200214 if (unlikely(irq >= max))
Vincent Guittot9033ea12018-06-28 17:45:10 +0200215 return max;
216
Peter Zijlstra45f55192018-07-05 14:36:17 +0200217 /*
218 * Because the time spend on RT/DL tasks is visible as 'lost' time to
219 * CFS tasks and we use the same metric to track the effective
220 * utilization (PELT windows are synchronized) we can directly add them
221 * to obtain the CPU's actual utilization.
222 */
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200223 util = cpu_util_cfs(rq);
224 util += cpu_util_rt(rq);
Vincent Guittot3ae117c2018-06-28 17:45:06 +0200225
Vincent Guittot9033ea12018-06-28 17:45:10 +0200226 /*
Peter Zijlstra45f55192018-07-05 14:36:17 +0200227 * We do not make cpu_util_dl() a permanent part of this sum because we
228 * want to use cpu_bw_dl() later on, but we need to check if the
229 * CFS+RT+DL sum is saturated (ie. no idle time) such that we select
230 * f_max when there is no idle time.
231 *
232 * NOTE: numerical errors or stop class might cause us to not quite hit
233 * saturation when we should -- something for later.
Vincent Guittot9033ea12018-06-28 17:45:10 +0200234 */
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200235 if ((util + cpu_util_dl(rq)) >= max)
Vincent Guittot9033ea12018-06-28 17:45:10 +0200236 return max;
Vincent Guittot8cc90512018-06-28 17:45:08 +0200237
Juri Lellid4edd662017-12-04 11:23:18 +0100238 /*
Peter Zijlstra45f55192018-07-05 14:36:17 +0200239 * There is still idle time; further improve the number by using the
240 * irq metric. Because IRQ/steal time is hidden from the task clock we
241 * need to scale the task numbers:
Vincent Guittot8cc90512018-06-28 17:45:08 +0200242 *
Peter Zijlstra45f55192018-07-05 14:36:17 +0200243 * 1 - irq
244 * U' = irq + ------- * U
245 * max
246 */
Vincent Guittot2e62c472018-07-19 14:00:06 +0200247 util = scale_irq_capacity(util, irq, max);
Peter Zijlstra45f55192018-07-05 14:36:17 +0200248 util += irq;
249
250 /*
Vincent Guittot8cc90512018-06-28 17:45:08 +0200251 * Bandwidth required by DEADLINE must always be granted while, for
252 * FAIR and RT, we use blocked utilization of IDLE CPUs as a mechanism
253 * to gracefully reduce the frequency when no tasks show up for longer
Patrick Bellasi8ecf04e2018-05-24 15:10:22 +0100254 * periods of time.
255 *
Peter Zijlstra45f55192018-07-05 14:36:17 +0200256 * Ideally we would like to set bw_dl as min/guaranteed freq and util +
257 * bw_dl as requested freq. However, cpufreq is not yet ready for such
258 * an interface. So, we only do the latter for now.
Juri Lellid4edd662017-12-04 11:23:18 +0100259 */
Peter Zijlstra45f55192018-07-05 14:36:17 +0200260 return min(max, util + sg_cpu->bw_dl);
Rafael J. Wysocki58919e82016-08-16 22:14:55 +0200261}
262
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100263/**
264 * sugov_iowait_reset() - Reset the IO boost status of a CPU.
265 * @sg_cpu: the sugov data for the CPU to boost
266 * @time: the update time from the caller
267 * @set_iowait_boost: true if an IO boost has been requested
268 *
269 * The IO wait boost of a task is disabled after a tick since the last update
270 * of a CPU. If a new IO wait boost is requested after more then a tick, then
271 * we enable the boost starting from the minimum frequency, which improves
272 * energy efficiency by ignoring sporadic wakeups from IO.
273 */
274static bool sugov_iowait_reset(struct sugov_cpu *sg_cpu, u64 time,
275 bool set_iowait_boost)
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200276{
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100277 s64 delta_ns = time - sg_cpu->last_update;
Joel Fernandesa5a08092017-07-23 08:54:25 -0700278
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100279 /* Reset boost only if a tick has elapsed since last request */
280 if (delta_ns <= TICK_NSEC)
281 return false;
Joel Fernandesa5a08092017-07-23 08:54:25 -0700282
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100283 sg_cpu->iowait_boost = set_iowait_boost
284 ? sg_cpu->sg_policy->policy->min : 0;
285 sg_cpu->iowait_boost_pending = set_iowait_boost;
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200286
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100287 return true;
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200288}
289
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100290/**
291 * sugov_iowait_boost() - Updates the IO boost status of a CPU.
292 * @sg_cpu: the sugov data for the CPU to boost
293 * @time: the update time from the caller
294 * @flags: SCHED_CPUFREQ_IOWAIT if the task is waking up after an IO wait
295 *
296 * Each time a task wakes up after an IO operation, the CPU utilization can be
297 * boosted to a certain utilization which doubles at each "frequent and
298 * successive" wakeup from IO, ranging from the utilization of the minimum
299 * OPP to the utilization of the maximum OPP.
300 * To keep doubling, an IO boost has to be requested at least once per tick,
301 * otherwise we restart from the utilization of the minimum OPP.
302 */
303static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
304 unsigned int flags)
305{
306 bool set_iowait_boost = flags & SCHED_CPUFREQ_IOWAIT;
307
308 /* Reset boost if the CPU appears to have been idle enough */
309 if (sg_cpu->iowait_boost &&
310 sugov_iowait_reset(sg_cpu, time, set_iowait_boost))
311 return;
312
313 /* Boost only tasks waking up after IO */
314 if (!set_iowait_boost)
315 return;
316
317 /* Ensure boost doubles only one time at each request */
318 if (sg_cpu->iowait_boost_pending)
319 return;
320 sg_cpu->iowait_boost_pending = true;
321
322 /* Double the boost at each request */
323 if (sg_cpu->iowait_boost) {
324 sg_cpu->iowait_boost <<= 1;
325 if (sg_cpu->iowait_boost > sg_cpu->iowait_boost_max)
326 sg_cpu->iowait_boost = sg_cpu->iowait_boost_max;
327 return;
328 }
329
330 /* First wakeup after IO: start with minimum boost */
331 sg_cpu->iowait_boost = sg_cpu->sg_policy->policy->min;
332}
333
334/**
335 * sugov_iowait_apply() - Apply the IO boost to a CPU.
336 * @sg_cpu: the sugov data for the cpu to boost
337 * @time: the update time from the caller
338 * @util: the utilization to (eventually) boost
339 * @max: the maximum value the utilization can be boosted to
340 *
341 * A CPU running a task which woken up after an IO operation can have its
342 * utilization boosted to speed up the completion of those IO operations.
343 * The IO boost value is increased each time a task wakes up from IO, in
344 * sugov_iowait_apply(), and it's instead decreased by this function,
345 * each time an increase has not been requested (!iowait_boost_pending).
346 *
347 * A CPU which also appears to have been idle for at least one tick has also
348 * its IO boost utilization reset.
349 *
350 * This mechanism is designed to boost high frequently IO waiting tasks, while
351 * being more conservative on tasks which does sporadic IO operations.
352 */
353static void sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time,
354 unsigned long *util, unsigned long *max)
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200355{
Joel Fernandes251accf2017-07-23 08:54:26 -0700356 unsigned int boost_util, boost_max;
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200357
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100358 /* No boost currently required */
Joel Fernandesa5a08092017-07-23 08:54:25 -0700359 if (!sg_cpu->iowait_boost)
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200360 return;
361
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100362 /* Reset boost if the CPU appears to have been idle enough */
363 if (sugov_iowait_reset(sg_cpu, time, false))
364 return;
365
366 /*
367 * An IO waiting task has just woken up:
368 * allow to further double the boost value
369 */
Joel Fernandesa5a08092017-07-23 08:54:25 -0700370 if (sg_cpu->iowait_boost_pending) {
371 sg_cpu->iowait_boost_pending = false;
372 } else {
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100373 /*
374 * Otherwise: reduce the boost value and disable it when we
375 * reach the minimum.
376 */
Joel Fernandesa5a08092017-07-23 08:54:25 -0700377 sg_cpu->iowait_boost >>= 1;
378 if (sg_cpu->iowait_boost < sg_cpu->sg_policy->policy->min) {
379 sg_cpu->iowait_boost = 0;
380 return;
381 }
382 }
383
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100384 /*
385 * Apply the current boost value: a CPU is boosted only if its current
386 * utilization is smaller then the current IO boost level.
387 */
Joel Fernandesa5a08092017-07-23 08:54:25 -0700388 boost_util = sg_cpu->iowait_boost;
389 boost_max = sg_cpu->iowait_boost_max;
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200390 if (*util * boost_max < *max * boost_util) {
391 *util = boost_util;
392 *max = boost_max;
393 }
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200394}
395
Rafael J. Wysockib7eaf1a2017-03-22 00:08:50 +0100396#ifdef CONFIG_NO_HZ_COMMON
397static bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu)
398{
Joel Fernandes466a2b42017-12-21 02:22:45 +0100399 unsigned long idle_calls = tick_nohz_get_idle_calls_cpu(sg_cpu->cpu);
Rafael J. Wysockib7eaf1a2017-03-22 00:08:50 +0100400 bool ret = idle_calls == sg_cpu->saved_idle_calls;
401
402 sg_cpu->saved_idle_calls = idle_calls;
403 return ret;
404}
405#else
406static inline bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu) { return false; }
407#endif /* CONFIG_NO_HZ_COMMON */
408
Claudio Scordinoe97a90f2018-03-13 11:35:40 +0100409/*
410 * Make sugov_should_update_freq() ignore the rate limit when DL
411 * has increased the utilization.
412 */
413static inline void ignore_dl_rate_limit(struct sugov_cpu *sg_cpu, struct sugov_policy *sg_policy)
414{
Vincent Guittot8cc90512018-06-28 17:45:08 +0200415 if (cpu_bw_dl(cpu_rq(sg_cpu->cpu)) > sg_cpu->bw_dl)
Claudio Scordinoe97a90f2018-03-13 11:35:40 +0100416 sg_policy->need_freq_update = true;
417}
418
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200419static void sugov_update_single(struct update_util_data *hook, u64 time,
Rafael J. Wysocki58919e82016-08-16 22:14:55 +0200420 unsigned int flags)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200421{
422 struct sugov_cpu *sg_cpu = container_of(hook, struct sugov_cpu, update_util);
423 struct sugov_policy *sg_policy = sg_cpu->sg_policy;
Rafael J. Wysocki58919e82016-08-16 22:14:55 +0200424 unsigned long util, max;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200425 unsigned int next_f;
Rafael J. Wysockib7eaf1a2017-03-22 00:08:50 +0100426 bool busy;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200427
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100428 sugov_iowait_boost(sg_cpu, time, flags);
Rafael J. Wysocki21ca6d22016-09-10 00:00:31 +0200429 sg_cpu->last_update = time;
430
Claudio Scordinoe97a90f2018-03-13 11:35:40 +0100431 ignore_dl_rate_limit(sg_cpu, sg_policy);
432
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200433 if (!sugov_should_update_freq(sg_policy, time))
434 return;
435
Rafael J. Wysockib7eaf1a2017-03-22 00:08:50 +0100436 busy = sugov_cpu_is_busy(sg_cpu);
437
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200438 util = sugov_get_util(sg_cpu);
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100439 max = sg_cpu->max;
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100440 sugov_iowait_apply(sg_cpu, time, &util, &max);
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100441 next_f = get_next_freq(sg_policy, util, max);
442 /*
443 * Do not reduce the frequency if the CPU has not been idle
444 * recently, as the reduction is likely to be premature then.
445 */
Viresh Kumarecd28842018-05-09 16:05:24 +0530446 if (busy && next_f < sg_policy->next_freq) {
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100447 next_f = sg_policy->next_freq;
Viresh Kumar07458f62017-11-08 20:23:55 +0530448
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100449 /* Reset cached freq as next_freq has changed */
450 sg_policy->cached_raw_freq = 0;
Rafael J. Wysocki58919e82016-08-16 22:14:55 +0200451 }
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100452
Rafael J. Wysockia61dec72018-05-23 11:47:45 +0200453 /*
454 * This code runs under rq->lock for the target CPU, so it won't run
455 * concurrently on two different CPUs for the same target and it is not
456 * necessary to acquire the lock in the fast switch case.
457 */
458 if (sg_policy->policy->fast_switch_enabled) {
459 sugov_fast_switch(sg_policy, time, next_f);
460 } else {
461 raw_spin_lock(&sg_policy->update_lock);
462 sugov_deferred_update(sg_policy, time, next_f);
463 raw_spin_unlock(&sg_policy->update_lock);
464 }
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200465}
466
Juri Lellid86ab9c2017-05-03 14:30:48 +0100467static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200468{
Steve Muckle5cbea462016-07-13 13:25:26 -0700469 struct sugov_policy *sg_policy = sg_cpu->sg_policy;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200470 struct cpufreq_policy *policy = sg_policy->policy;
Viresh Kumarcba1dfb2017-03-09 09:34:54 +0530471 unsigned long util = 0, max = 1;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200472 unsigned int j;
473
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200474 for_each_cpu(j, policy->cpus) {
Viresh Kumarcba1dfb2017-03-09 09:34:54 +0530475 struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200476 unsigned long j_util, j_max;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200477
Vincent Guittotdfa444d2018-06-28 17:45:11 +0200478 j_util = sugov_get_util(j_sg_cpu);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200479 j_max = j_sg_cpu->max;
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100480 sugov_iowait_apply(j_sg_cpu, time, &j_util, &j_max);
481
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200482 if (j_util * max > j_max * util) {
483 util = j_util;
484 max = j_max;
485 }
486 }
487
Viresh Kumar655cb1e2017-03-02 14:03:21 +0530488 return get_next_freq(sg_policy, util, max);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200489}
490
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100491static void
492sugov_update_shared(struct update_util_data *hook, u64 time, unsigned int flags)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200493{
494 struct sugov_cpu *sg_cpu = container_of(hook, struct sugov_cpu, update_util);
495 struct sugov_policy *sg_policy = sg_cpu->sg_policy;
496 unsigned int next_f;
497
498 raw_spin_lock(&sg_policy->update_lock);
499
Patrick Bellasifd7d5282018-05-22 12:07:54 +0100500 sugov_iowait_boost(sg_cpu, time, flags);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200501 sg_cpu->last_update = time;
502
Claudio Scordinoe97a90f2018-03-13 11:35:40 +0100503 ignore_dl_rate_limit(sg_cpu, sg_policy);
Viresh Kumarcba1dfb2017-03-09 09:34:54 +0530504
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200505 if (sugov_should_update_freq(sg_policy, time)) {
Peter Zijlstra8f111bc2017-12-20 16:26:12 +0100506 next_f = sugov_next_freq_shared(sg_cpu, time);
Rafael J. Wysockia61dec72018-05-23 11:47:45 +0200507
508 if (sg_policy->policy->fast_switch_enabled)
509 sugov_fast_switch(sg_policy, time, next_f);
510 else
511 sugov_deferred_update(sg_policy, time, next_f);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200512 }
513
514 raw_spin_unlock(&sg_policy->update_lock);
515}
516
517static void sugov_work(struct kthread_work *work)
518{
519 struct sugov_policy *sg_policy = container_of(work, struct sugov_policy, work);
Joel Fernandes (Google)152db032018-05-22 15:55:53 -0700520 unsigned int freq;
521 unsigned long flags;
522
523 /*
524 * Hold sg_policy->update_lock shortly to handle the case where:
525 * incase sg_policy->next_freq is read here, and then updated by
Rafael J. Wysockia61dec72018-05-23 11:47:45 +0200526 * sugov_deferred_update() just before work_in_progress is set to false
Joel Fernandes (Google)152db032018-05-22 15:55:53 -0700527 * here, we may miss queueing the new update.
528 *
529 * Note: If a work was queued after the update_lock is released,
Rafael J. Wysockia61dec72018-05-23 11:47:45 +0200530 * sugov_work() will just be called again by kthread_work code; and the
Joel Fernandes (Google)152db032018-05-22 15:55:53 -0700531 * request will be proceed before the sugov thread sleeps.
532 */
533 raw_spin_lock_irqsave(&sg_policy->update_lock, flags);
534 freq = sg_policy->next_freq;
535 sg_policy->work_in_progress = false;
536 raw_spin_unlock_irqrestore(&sg_policy->update_lock, flags);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200537
538 mutex_lock(&sg_policy->work_lock);
Joel Fernandes (Google)152db032018-05-22 15:55:53 -0700539 __cpufreq_driver_target(sg_policy->policy, freq, CPUFREQ_RELATION_L);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200540 mutex_unlock(&sg_policy->work_lock);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200541}
542
543static void sugov_irq_work(struct irq_work *irq_work)
544{
545 struct sugov_policy *sg_policy;
546
547 sg_policy = container_of(irq_work, struct sugov_policy, irq_work);
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530548
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530549 kthread_queue_work(&sg_policy->worker, &sg_policy->work);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200550}
551
552/************************** sysfs interface ************************/
553
554static struct sugov_tunables *global_tunables;
555static DEFINE_MUTEX(global_tunables_lock);
556
557static inline struct sugov_tunables *to_sugov_tunables(struct gov_attr_set *attr_set)
558{
559 return container_of(attr_set, struct sugov_tunables, attr_set);
560}
561
562static ssize_t rate_limit_us_show(struct gov_attr_set *attr_set, char *buf)
563{
564 struct sugov_tunables *tunables = to_sugov_tunables(attr_set);
565
566 return sprintf(buf, "%u\n", tunables->rate_limit_us);
567}
568
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100569static ssize_t
570rate_limit_us_store(struct gov_attr_set *attr_set, const char *buf, size_t count)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200571{
572 struct sugov_tunables *tunables = to_sugov_tunables(attr_set);
573 struct sugov_policy *sg_policy;
574 unsigned int rate_limit_us;
575
576 if (kstrtouint(buf, 10, &rate_limit_us))
577 return -EINVAL;
578
579 tunables->rate_limit_us = rate_limit_us;
580
581 list_for_each_entry(sg_policy, &attr_set->policy_list, tunables_hook)
582 sg_policy->freq_update_delay_ns = rate_limit_us * NSEC_PER_USEC;
583
584 return count;
585}
586
587static struct governor_attr rate_limit_us = __ATTR_RW(rate_limit_us);
588
589static struct attribute *sugov_attributes[] = {
590 &rate_limit_us.attr,
591 NULL
592};
593
594static struct kobj_type sugov_tunables_ktype = {
595 .default_attrs = sugov_attributes,
596 .sysfs_ops = &governor_sysfs_ops,
597};
598
599/********************** cpufreq governor interface *********************/
600
601static struct cpufreq_governor schedutil_gov;
602
603static struct sugov_policy *sugov_policy_alloc(struct cpufreq_policy *policy)
604{
605 struct sugov_policy *sg_policy;
606
607 sg_policy = kzalloc(sizeof(*sg_policy), GFP_KERNEL);
608 if (!sg_policy)
609 return NULL;
610
611 sg_policy->policy = policy;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200612 raw_spin_lock_init(&sg_policy->update_lock);
613 return sg_policy;
614}
615
616static void sugov_policy_free(struct sugov_policy *sg_policy)
617{
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200618 kfree(sg_policy);
619}
620
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530621static int sugov_kthread_create(struct sugov_policy *sg_policy)
622{
623 struct task_struct *thread;
Juri Lelli794a56e2017-12-04 11:23:20 +0100624 struct sched_attr attr = {
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100625 .size = sizeof(struct sched_attr),
626 .sched_policy = SCHED_DEADLINE,
627 .sched_flags = SCHED_FLAG_SUGOV,
628 .sched_nice = 0,
629 .sched_priority = 0,
Juri Lelli794a56e2017-12-04 11:23:20 +0100630 /*
631 * Fake (unused) bandwidth; workaround to "fix"
632 * priority inheritance.
633 */
634 .sched_runtime = 1000000,
635 .sched_deadline = 10000000,
636 .sched_period = 10000000,
637 };
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530638 struct cpufreq_policy *policy = sg_policy->policy;
639 int ret;
640
641 /* kthread only required for slow path */
642 if (policy->fast_switch_enabled)
643 return 0;
644
645 kthread_init_work(&sg_policy->work, sugov_work);
646 kthread_init_worker(&sg_policy->worker);
647 thread = kthread_create(kthread_worker_fn, &sg_policy->worker,
648 "sugov:%d",
649 cpumask_first(policy->related_cpus));
650 if (IS_ERR(thread)) {
651 pr_err("failed to create sugov thread: %ld\n", PTR_ERR(thread));
652 return PTR_ERR(thread);
653 }
654
Juri Lelli794a56e2017-12-04 11:23:20 +0100655 ret = sched_setattr_nocheck(thread, &attr);
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530656 if (ret) {
657 kthread_stop(thread);
Juri Lelli794a56e2017-12-04 11:23:20 +0100658 pr_warn("%s: failed to set SCHED_DEADLINE\n", __func__);
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530659 return ret;
660 }
661
662 sg_policy->thread = thread;
Dietmar Eggemann1b047222018-05-08 08:33:40 +0100663 kthread_bind_mask(thread, policy->related_cpus);
Viresh Kumar21ef5722016-11-15 13:53:23 +0530664 init_irq_work(&sg_policy->irq_work, sugov_irq_work);
665 mutex_init(&sg_policy->work_lock);
666
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530667 wake_up_process(thread);
668
669 return 0;
670}
671
672static void sugov_kthread_stop(struct sugov_policy *sg_policy)
673{
674 /* kthread only required for slow path */
675 if (sg_policy->policy->fast_switch_enabled)
676 return;
677
678 kthread_flush_worker(&sg_policy->worker);
679 kthread_stop(sg_policy->thread);
Viresh Kumar21ef5722016-11-15 13:53:23 +0530680 mutex_destroy(&sg_policy->work_lock);
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530681}
682
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200683static struct sugov_tunables *sugov_tunables_alloc(struct sugov_policy *sg_policy)
684{
685 struct sugov_tunables *tunables;
686
687 tunables = kzalloc(sizeof(*tunables), GFP_KERNEL);
688 if (tunables) {
689 gov_attr_set_init(&tunables->attr_set, &sg_policy->tunables_hook);
690 if (!have_governor_per_policy())
691 global_tunables = tunables;
692 }
693 return tunables;
694}
695
696static void sugov_tunables_free(struct sugov_tunables *tunables)
697{
698 if (!have_governor_per_policy())
699 global_tunables = NULL;
700
701 kfree(tunables);
702}
703
704static int sugov_init(struct cpufreq_policy *policy)
705{
706 struct sugov_policy *sg_policy;
707 struct sugov_tunables *tunables;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200708 int ret = 0;
709
710 /* State should be equivalent to EXIT */
711 if (policy->governor_data)
712 return -EBUSY;
713
Viresh Kumar4a71ce42016-11-15 13:53:21 +0530714 cpufreq_enable_fast_switch(policy);
715
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200716 sg_policy = sugov_policy_alloc(policy);
Viresh Kumar4a71ce42016-11-15 13:53:21 +0530717 if (!sg_policy) {
718 ret = -ENOMEM;
719 goto disable_fast_switch;
720 }
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200721
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530722 ret = sugov_kthread_create(sg_policy);
723 if (ret)
724 goto free_sg_policy;
725
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200726 mutex_lock(&global_tunables_lock);
727
728 if (global_tunables) {
729 if (WARN_ON(have_governor_per_policy())) {
730 ret = -EINVAL;
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530731 goto stop_kthread;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200732 }
733 policy->governor_data = sg_policy;
734 sg_policy->tunables = global_tunables;
735
736 gov_attr_set_get(&global_tunables->attr_set, &sg_policy->tunables_hook);
737 goto out;
738 }
739
740 tunables = sugov_tunables_alloc(sg_policy);
741 if (!tunables) {
742 ret = -ENOMEM;
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530743 goto stop_kthread;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200744 }
745
Viresh Kumaraa7519a2017-07-19 15:42:42 +0530746 tunables->rate_limit_us = cpufreq_policy_transition_delay_us(policy);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200747
748 policy->governor_data = sg_policy;
749 sg_policy->tunables = tunables;
750
751 ret = kobject_init_and_add(&tunables->attr_set.kobj, &sugov_tunables_ktype,
752 get_governor_parent_kobj(policy), "%s",
753 schedutil_gov.name);
754 if (ret)
755 goto fail;
756
Viresh Kumar8e2ddb02016-11-15 13:53:20 +0530757out:
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200758 mutex_unlock(&global_tunables_lock);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200759 return 0;
760
Viresh Kumar8e2ddb02016-11-15 13:53:20 +0530761fail:
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200762 policy->governor_data = NULL;
763 sugov_tunables_free(tunables);
764
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530765stop_kthread:
766 sugov_kthread_stop(sg_policy);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200767 mutex_unlock(&global_tunables_lock);
768
Jules Maselbas1b5d43cf2018-03-29 15:43:01 +0100769free_sg_policy:
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200770 sugov_policy_free(sg_policy);
Viresh Kumar4a71ce42016-11-15 13:53:21 +0530771
772disable_fast_switch:
773 cpufreq_disable_fast_switch(policy);
774
Viresh Kumar60f05e82016-05-18 17:55:28 +0530775 pr_err("initialization failed (error %d)\n", ret);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200776 return ret;
777}
778
Rafael J. Wysockie7888922016-06-02 23:24:15 +0200779static void sugov_exit(struct cpufreq_policy *policy)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200780{
781 struct sugov_policy *sg_policy = policy->governor_data;
782 struct sugov_tunables *tunables = sg_policy->tunables;
783 unsigned int count;
784
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200785 mutex_lock(&global_tunables_lock);
786
787 count = gov_attr_set_put(&tunables->attr_set, &sg_policy->tunables_hook);
788 policy->governor_data = NULL;
789 if (!count)
790 sugov_tunables_free(tunables);
791
792 mutex_unlock(&global_tunables_lock);
793
Viresh Kumar02a7b1e2016-11-15 13:53:22 +0530794 sugov_kthread_stop(sg_policy);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200795 sugov_policy_free(sg_policy);
Viresh Kumar4a71ce42016-11-15 13:53:21 +0530796 cpufreq_disable_fast_switch(policy);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200797}
798
799static int sugov_start(struct cpufreq_policy *policy)
800{
801 struct sugov_policy *sg_policy = policy->governor_data;
802 unsigned int cpu;
803
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100804 sg_policy->freq_update_delay_ns = sg_policy->tunables->rate_limit_us * NSEC_PER_USEC;
805 sg_policy->last_freq_update_time = 0;
Viresh Kumarecd28842018-05-09 16:05:24 +0530806 sg_policy->next_freq = 0;
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100807 sg_policy->work_in_progress = false;
808 sg_policy->need_freq_update = false;
809 sg_policy->cached_raw_freq = 0;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200810
811 for_each_cpu(cpu, policy->cpus) {
812 struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
813
Rafael J. Wysocki4296f232017-03-19 14:30:02 +0100814 memset(sg_cpu, 0, sizeof(*sg_cpu));
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100815 sg_cpu->cpu = cpu;
816 sg_cpu->sg_policy = sg_policy;
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100817 sg_cpu->iowait_boost_max = policy->cpuinfo.max_freq;
Vikram Mulukutlaab2f7cf2017-07-06 10:53:20 -0700818 }
819
820 for_each_cpu(cpu, policy->cpus) {
821 struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);
822
Rafael J. Wysocki4296f232017-03-19 14:30:02 +0100823 cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,
824 policy_is_shared(policy) ?
825 sugov_update_shared :
826 sugov_update_single);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200827 }
828 return 0;
829}
830
Rafael J. Wysockie7888922016-06-02 23:24:15 +0200831static void sugov_stop(struct cpufreq_policy *policy)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200832{
833 struct sugov_policy *sg_policy = policy->governor_data;
834 unsigned int cpu;
835
836 for_each_cpu(cpu, policy->cpus)
837 cpufreq_remove_update_util_hook(cpu);
838
839 synchronize_sched();
840
Viresh Kumar21ef5722016-11-15 13:53:23 +0530841 if (!policy->fast_switch_enabled) {
842 irq_work_sync(&sg_policy->irq_work);
843 kthread_cancel_work_sync(&sg_policy->work);
844 }
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200845}
846
Rafael J. Wysockie7888922016-06-02 23:24:15 +0200847static void sugov_limits(struct cpufreq_policy *policy)
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200848{
849 struct sugov_policy *sg_policy = policy->governor_data;
850
851 if (!policy->fast_switch_enabled) {
852 mutex_lock(&sg_policy->work_lock);
Viresh Kumarbf2be2d2016-05-18 17:55:31 +0530853 cpufreq_policy_apply_limits(policy);
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200854 mutex_unlock(&sg_policy->work_lock);
855 }
856
857 sg_policy->need_freq_update = true;
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200858}
859
860static struct cpufreq_governor schedutil_gov = {
Ingo Molnar97fb7a02018-03-03 14:01:12 +0100861 .name = "schedutil",
862 .owner = THIS_MODULE,
863 .dynamic_switching = true,
864 .init = sugov_init,
865 .exit = sugov_exit,
866 .start = sugov_start,
867 .stop = sugov_stop,
868 .limits = sugov_limits,
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200869};
870
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200871#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL
872struct cpufreq_governor *cpufreq_default_governor(void)
873{
874 return &schedutil_gov;
875}
Rafael J. Wysocki9bdcb442016-04-02 01:09:12 +0200876#endif
Rafael J. Wysocki58919e82016-08-16 22:14:55 +0200877
878static int __init sugov_register(void)
879{
880 return cpufreq_register_governor(&schedutil_gov);
881}
882fs_initcall(sugov_register);