Skip to content

Commit ca6827d

Browse files
committed
cpufreq: schedutil: Add util to struct sg_cpu
Instead of passing util and max between functions while computing the utilization and capacity, store the former in struct sg_cpu (along with the latter and bw_dl). This will allow the current utilization value to be compared with the one obtained previously (which is requisite for some code changes to follow this one), but also it causes the code to look slightly more consistent and cleaner. Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Viresh Kumar <[email protected]>
1 parent a28b2bf commit ca6827d

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

kernel/sched/cpufreq_schedutil.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct sugov_cpu {
5353
unsigned int iowait_boost;
5454
u64 last_update;
5555

56+
unsigned long util;
5657
unsigned long bw_dl;
5758
unsigned long max;
5859

@@ -276,16 +277,15 @@ unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs,
276277
return min(max, util);
277278
}
278279

279-
static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu)
280+
static void sugov_get_util(struct sugov_cpu *sg_cpu)
280281
{
281282
struct rq *rq = cpu_rq(sg_cpu->cpu);
282-
unsigned long util = cpu_util_cfs(rq);
283283
unsigned long max = arch_scale_cpu_capacity(sg_cpu->cpu);
284284

285285
sg_cpu->max = max;
286286
sg_cpu->bw_dl = cpu_bw_dl(rq);
287-
288-
return schedutil_cpu_util(sg_cpu->cpu, util, max, FREQUENCY_UTIL, NULL);
287+
sg_cpu->util = schedutil_cpu_util(sg_cpu->cpu, cpu_util_cfs(rq), max,
288+
FREQUENCY_UTIL, NULL);
289289
}
290290

291291
/**
@@ -362,8 +362,6 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
362362
* sugov_iowait_apply() - Apply the IO boost to a CPU.
363363
* @sg_cpu: the sugov data for the cpu to boost
364364
* @time: the update time from the caller
365-
* @util: the utilization to (eventually) boost
366-
* @max: the maximum value the utilization can be boosted to
367365
*
368366
* A CPU running a task which woken up after an IO operation can have its
369367
* utilization boosted to speed up the completion of those IO operations.
@@ -377,18 +375,17 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
377375
* This mechanism is designed to boost high frequently IO waiting tasks, while
378376
* being more conservative on tasks which does sporadic IO operations.
379377
*/
380-
static unsigned long sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time,
381-
unsigned long util, unsigned long max)
378+
static void sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time)
382379
{
383380
unsigned long boost;
384381

385382
/* No boost currently required */
386383
if (!sg_cpu->iowait_boost)
387-
return util;
384+
return;
388385

389386
/* Reset boost if the CPU appears to have been idle enough */
390387
if (sugov_iowait_reset(sg_cpu, time, false))
391-
return util;
388+
return;
392389

393390
if (!sg_cpu->iowait_boost_pending) {
394391
/*
@@ -397,18 +394,19 @@ static unsigned long sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time,
397394
sg_cpu->iowait_boost >>= 1;
398395
if (sg_cpu->iowait_boost < IOWAIT_BOOST_MIN) {
399396
sg_cpu->iowait_boost = 0;
400-
return util;
397+
return;
401398
}
402399
}
403400

404401
sg_cpu->iowait_boost_pending = false;
405402

406403
/*
407-
* @util is already in capacity scale; convert iowait_boost
404+
* sg_cpu->util is already in capacity scale; convert iowait_boost
408405
* into the same scale so we can compare.
409406
*/
410-
boost = (sg_cpu->iowait_boost * max) >> SCHED_CAPACITY_SHIFT;
411-
return max(boost, util);
407+
boost = (sg_cpu->iowait_boost * sg_cpu->max) >> SCHED_CAPACITY_SHIFT;
408+
if (sg_cpu->util < boost)
409+
sg_cpu->util = boost;
412410
}
413411

414412
#ifdef CONFIG_NO_HZ_COMMON
@@ -439,9 +437,8 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
439437
{
440438
struct sugov_cpu *sg_cpu = container_of(hook, struct sugov_cpu, update_util);
441439
struct sugov_policy *sg_policy = sg_cpu->sg_policy;
442-
unsigned long util, max;
443-
unsigned int next_f;
444440
unsigned int cached_freq = sg_policy->cached_raw_freq;
441+
unsigned int next_f;
445442

446443
sugov_iowait_boost(sg_cpu, time, flags);
447444
sg_cpu->last_update = time;
@@ -451,10 +448,10 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
451448
if (!sugov_should_update_freq(sg_policy, time))
452449
return;
453450

454-
util = sugov_get_util(sg_cpu);
455-
max = sg_cpu->max;
456-
util = sugov_iowait_apply(sg_cpu, time, util, max);
457-
next_f = get_next_freq(sg_policy, util, max);
451+
sugov_get_util(sg_cpu);
452+
sugov_iowait_apply(sg_cpu, time);
453+
454+
next_f = get_next_freq(sg_policy, sg_cpu->util, sg_cpu->max);
458455
/*
459456
* Do not reduce the frequency if the CPU has not been idle
460457
* recently, as the reduction is likely to be premature then.
@@ -491,9 +488,10 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time)
491488
struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j);
492489
unsigned long j_util, j_max;
493490

494-
j_util = sugov_get_util(j_sg_cpu);
491+
sugov_get_util(j_sg_cpu);
492+
sugov_iowait_apply(j_sg_cpu, time);
493+
j_util = j_sg_cpu->util;
495494
j_max = j_sg_cpu->max;
496-
j_util = sugov_iowait_apply(j_sg_cpu, time, j_util, j_max);
497495

498496
if (j_util * max > j_max * util) {
499497
util = j_util;

0 commit comments

Comments
 (0)