[RFC PATCH 3/5] sched/fair: Update overloaded mask in presence of pushable task

From: K Prateek Nayak
Date: Wed Apr 09 2025 - 07:19:18 EST


In presence of pushable tasks on the CPU, set it on the newly introduced
"overloaded+mask" in sched_domain_shared struct. This will be used by
the newidle balance to limit the scanning to these overloaded CPUs since
they contain tasks that could be run on the newly idle target.

Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
---
kernel/sched/fair.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 98d3ed2078cd..834fcdd15cac 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8559,6 +8559,24 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
return target;
}

+static inline void update_overloaded_mask(int cpu, bool contains_pushable)
+{
+ struct sched_domain_shared *sd_share = rcu_dereference(per_cpu(sd_llc_shared, cpu));
+ cpumask_var_t overloaded_mask;
+
+ if (!sd_share)
+ return;
+
+ overloaded_mask = sd_share->overloaded_mask;
+ if (!overloaded_mask)
+ return;
+
+ if (contains_pushable)
+ cpumask_set_cpu(cpu, overloaded_mask);
+ else
+ cpumask_clear_cpu(cpu, overloaded_mask);
+}
+
static inline bool fair_push_task(struct task_struct *p)
{
if (!task_on_rq_queued(p))
@@ -8606,11 +8624,17 @@ static inline void fair_queue_pushable_tasks(struct rq *rq)
static void fair_remove_pushable_task(struct rq *rq, struct task_struct *p)
{
plist_del(&p->pushable_tasks, &rq->cfs.pushable_tasks);
+
+ if (!has_pushable_tasks(rq))
+ update_overloaded_mask(rq->cpu, false);
}

static void fair_add_pushable_task(struct rq *rq, struct task_struct *p)
{
if (fair_push_task(p)) {
+ if (!has_pushable_tasks(rq))
+ update_overloaded_mask(rq->cpu, true);
+
plist_del(&p->pushable_tasks, &rq->cfs.pushable_tasks);
plist_node_init(&p->pushable_tasks, p->prio);
plist_add(&p->pushable_tasks, &rq->cfs.pushable_tasks);
--
2.34.1