Remove redundant avg_idle check from sched_balance_newidle
RFC PATCH 1/1 Remove redundant avg_idle check from sched_balance_newidle
In sched_balance_newidle(), rq->avg_idle is checked against sd->max_newidle_lb_cost in two places. However these two conditional checks are logically duplicated:
sched_balance_newidle()
{
u64 curr_cost = 0;
[...]
(!get_rd_overloaded(this_rq->rd) ||
(sd && this_rq->avg_idle < sd->max_newidle_lb_cost)) [1] {
[...]
goto out;
}
[...]
sched_balance_update_blocked_averages(this_cpu);
for_each_domain(this_cpu, sd) {
[...]
if (this_rq->avg_idle < curr_cost + sd->max_newidle_lb_cost) [2]
break;
[...]
}[...]
out:
[...]
}
In the first for_each_domain() loop curr_cost is 0, so conditional check
[1] and [2] are same.
This patch removed conditional check [1]. After the patch, more cpu cycles might be spent in sched_balance_update_blocked_averages() if [1] is true. However benchmark shows the patch does not change performance.
Tested with schbench and Specjbb on AmpereOne CPU. The schbench command is:
./schbench -L -m 4 -M auto -t 256 -n 0 -r 0 -s 0
Signed-off-by Adam Li <[email protected]>
--- kernel/sched/fair.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/sched/fair.c +1 -2
@@ -12825,8 +12825,7 @@ static int sched_balance_newidle(struct rq *this_rq, struct rq_flags *rf)rcu_read_lock (); sd =rcu_dereference_check_sched_domain (this_rq->sd); -if (!get_rd_overloaded (this_rq->rd) || - (sd && this_rq->avg_idle < sd->max_newidle_lb_cost)) { +if (!get_rd_overloaded (this_rq->rd)) {if (sd)update_next_balance (sd, &next_balance);
Signature · 1 line
2.34.1