Skip to content

Commit d040e07

Browse files
Peng WangPeter Zijlstra
authored andcommitted
schied/fair: Skip calculating @contrib without load
Because of the: if (!load) runnable = running = 0; clause in ___update_load_sum(), all the actual users of @contrib in accumulate_sum(): if (load) sa->load_sum += load * contrib; if (runnable) sa->runnable_load_sum += runnable * contrib; if (running) sa->util_sum += contrib << SCHED_CAPACITY_SHIFT; don't happen, and therefore we don't care what @contrib actually is and calculating it is pointless. If we count the times when @load equals zero and not as below: if (load) { load_is_not_zero_count++; contrib = __accumulate_pelt_segments(periods, 1024 - sa->period_contrib,delta); } else load_is_zero_count++; As we can see, load_is_zero_count is much bigger than load_is_zero_count, and the gap is gradually widening: load_is_zero_count: 6016044 times load_is_not_zero_count: 244316 times 19:50:43 up 1 min, 1 user, load average: 0.09, 0.06, 0.02 load_is_zero_count: 7956168 times load_is_not_zero_count: 261472 times 19:51:42 up 2 min, 1 user, load average: 0.03, 0.05, 0.01 load_is_zero_count: 10199896 times load_is_not_zero_count: 278364 times 19:52:51 up 3 min, 1 user, load average: 0.06, 0.05, 0.01 load_is_zero_count: 14333700 times load_is_not_zero_count: 318424 times 19:54:53 up 5 min, 1 user, load average: 0.01, 0.03, 0.00 Perhaps we can gain some performance advantage by saving these unnecessary calculation. Signed-off-by: Peng Wang <rocking@linux.alibaba.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Vincent Guittot < vincent.guittot@linaro.org> Link: https://lkml.kernel.org/r/1576208740-35609-1-git-send-email-rocking@linux.alibaba.com
1 parent 60588bf commit d040e07

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

‎kernel/sched/pelt.c‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,20 @@ accumulate_sum(u64 delta, struct sched_avg *sa,
129129
* Step 2
130130
*/
131131
delta %= 1024;
132-
contrib = __accumulate_pelt_segments(periods,
133-
1024 - sa->period_contrib, delta);
132+
if (load) {
133+
/*
134+
* This relies on the:
135+
*
136+
* if (!load)
137+
* runnable = running = 0;
138+
*
139+
* clause from ___update_load_sum(); this results in
140+
* the below usage of @contrib to dissapear entirely,
141+
* so no point in calculating it.
142+
*/
143+
contrib = __accumulate_pelt_segments(periods,
144+
1024 - sa->period_contrib, delta);
145+
}
134146
}
135147
sa->period_contrib = delta;
136148

@@ -205,7 +217,9 @@ ___update_load_sum(u64 now, struct sched_avg *sa,
205217
* This means that weight will be 0 but not running for a sched_entity
206218
* but also for a cfs_rq if the latter becomes idle. As an example,
207219
* this happens during idle_balance() which calls
208-
* update_blocked_averages()
220+
* update_blocked_averages().
221+
*
222+
* Also see the comment in accumulate_sum().
209223
*/
210224
if (!load)
211225
runnable = running = 0;

0 commit comments

Comments
 (0)