[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANCG0Gc2vAMO_5x8wYhA-=34n0vChrSdUvnd+Cf56MXfq2YFfQ@mail.gmail.com>
Date: Thu, 13 Mar 2025 02:21:41 -0500
From: Aaron Lu <ziqianlu@...edance.com>
To: Valentin Schneider <vschneid@...hat.com>, Ben Segall <bsegall@...gle.com>,
K Prateek Nayak <kprateek.nayak@....com>, Peter Zijlstra <peterz@...radead.org>,
Josh Don <joshdon@...gle.com>, Ingo Molnar <mingo@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>
Cc: linux-kernel@...r.kernel.org, Juri Lelli <juri.lelli@...hat.com>,
Dietmar Eggemann <dietmar.eggemann@....com>, Steven Rostedt <rostedt@...dmis.org>,
Mel Gorman <mgorman@...e.de>, Chengming Zhou <chengming.zhou@...ux.dev>,
Chuyi Zhou <zhouchuyi@...edance.com>
Subject: [RFC PATCH 4/7] sched/fair: Take care of migrated task for task based throttle
If a task is migrated to a new cpu, it is possible this task is not
throttled but the new cfs_rq is throttled or vice vesa. Take care of
these situations in enqueue path.
Note that we can't handle this in migrate_task_rq_fair() because there,
the dst cpu's rq lock is not held and things like checking if the new
cfs_rq needs throttle can be racy.
Signed-off-by: Aaron Lu <ziqianlu@...edance.com>
---
kernel/sched/fair.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 4a95fe3785e43..9e036f18d73e6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7051,6 +7051,23 @@ enqueue_task_fair(struct rq *rq, struct
task_struct *p, int flags)
assert_list_leaf_cfs_rq(rq);
hrtick_update(rq);
+
+ if (!cfs_bandwidth_used())
+ return;
+
+ /*
+ * This is for migrate_task_rq_fair(): the new_cpu's rq lock is not held
+ * in migrate_task_rq_fair() so we have to do these things in enqueue
+ * time when the dst cpu's rq lock is held. Doing this check in enqueue
+ * time also takes care of newly woken up tasks, e.g. a task wakes up
+ * into a throttled cfs_rq.
+ *
+ * It's possible the task has a throttle work added but this new cfs_rq
+ * is not in throttled hierarchy but that's OK, throttle_cfs_rq_work()
+ * will take care of it.
+ */
+ if (throttled_hierarchy(cfs_rq_of(&p->se)))
+ task_throttle_setup_work(p);
}
static void set_next_buddy(struct sched_entity *se);
--
2.39.5
Powered by blists - more mailing lists