[PATCH v2 3/3] sched/fair: Use rq in update_blocked_averages()

From: Pierre Gondois
Date: Mon Jan 15 2024 - 09:35:25 EST


update_blocked_averages() could receive a 'struct rq' instead of a
CPU number to avoid converting the CPU number to a 'struct rq'
multiple times.

Suggested-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Pierre Gondois <pierre.gondois@xxxxxxx>
---
kernel/sched/fair.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 97d9e0d32337..c70bb993f473 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9349,10 +9349,9 @@ static unsigned long task_h_load(struct task_struct *p)
}
#endif

-static void update_blocked_averages(int cpu)
+static void update_blocked_averages(struct rq *rq)
{
bool decayed = false, done = true;
- struct rq *rq = cpu_rq(cpu);
struct rq_flags rf;

rq_lock_irqsave(rq, &rf);
@@ -12026,7 +12025,7 @@ static bool update_nohz_stats(struct rq *rq)
if (!time_after(jiffies, READ_ONCE(rq->last_blocked_load_update_tick)))
return true;

- update_blocked_averages(cpu);
+ update_blocked_averages(rq);

return rq->has_blocked_load;
}
@@ -12286,7 +12285,7 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf)
raw_spin_rq_unlock(this_rq);

t0 = sched_clock_cpu(this_cpu);
- update_blocked_averages(this_cpu);
+ update_blocked_averages(this_rq);

rcu_read_lock();
for_each_domain(this_cpu, sd) {
@@ -12376,7 +12375,7 @@ static __latent_entropy void run_rebalance_domains(struct softirq_action *h)
return;

/* normal load balance */
- update_blocked_averages(this_rq->cpu);
+ update_blocked_averages(this_rq);
rebalance_domains(this_rq, idle);
}

--
2.25.1