mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	Aaron Lu <ziqianlu@bytedance.com>, Josh Don <joshdon@google.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 2/5] sched/fair: Use throttled_csd_list for local unthrottle
Date: Thu, 28 May 2026 09:48:27 +0000	[thread overview]
Message-ID: <20260528094830.13291-3-kprateek.nayak@amd.com> (raw)
In-Reply-To: <20260528094830.13291-1-kprateek.nayak@amd.com>

When distribute_cfs_runtime() encounters a local cfs_rq, it adds it to a
local list and unthrottles it at the end, when it is done unthrottling
other cfs_rq(s) on cfs_b->throttled_cfs_rq until the bandwidth runs out.

Instead of using a local list, reuse the local CPU's
rq->throttled_csd_list and the __cfsb_csd_unthrottle() path for
unthrottle.

If this is the first cfs_rq to be queued on the "throttled_csd_list", it
prevents the need for a remote CPUs to interrupt this local CPU if they
themselves are performing async unthrottle.

If this is not the first cfs_rq on the list, there is an async unthrottle
operation pending on this local CPU and the unthrottle can be batched
together.

No functional changes intended.

Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
 kernel/sched/fair.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8c2a5a2f046d..23742d928b51 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6962,12 +6962,11 @@ static void unthrottle_cfs_rq_async(struct cfs_rq *cfs_rq)
 
 static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b)
 {
+	bool throttled = false, unthrottle_local = false;
 	int this_cpu = smp_processor_id();
 	u64 runtime, remaining = 1;
-	bool throttled = false;
-	struct cfs_rq *cfs_rq, *tmp;
+	struct cfs_rq *cfs_rq;
 	struct rq *rq;
-	LIST_HEAD(local_unthrottle);
 
 	guard(rcu)();
 
@@ -7010,28 +7009,27 @@ static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b)
 			}
 
 			/*
-			 * We currently only expect to be unthrottling
-			 * a single cfs_rq locally.
+			 * Allow a parallel async unthrottle to unthrottle
+			 * this cfs_rq too via __cfsb_csd_unthrottle().
+			 * If we are first, do it ourselves at the end and
+			 * save on an IPI from remote CPUs.
 			 */
-			WARN_ON_ONCE(!list_empty(&local_unthrottle));
-			list_add_tail(&cfs_rq->throttled_csd_list, &local_unthrottle);
+			unthrottle_local = list_empty(&rq->cfsb_csd_list);
+			list_add_tail(&cfs_rq->throttled_csd_list, &rq->cfsb_csd_list);
 			continue;
 		}
 
 		throttled = true;
 	}
 
-	list_for_each_entry_safe(cfs_rq, tmp, &local_unthrottle,
-				 throttled_csd_list) {
-		struct rq *rq = rq_of(cfs_rq);
-
-		guard(rq_lock_irqsave)(rq);
-
-		list_del_init(&cfs_rq->throttled_csd_list);
-		if (cfs_rq_throttled(cfs_rq))
-			unthrottle_cfs_rq(cfs_rq);
+	if (unthrottle_local) {
+		/*
+		 * Protect against an IPI that is also trying to flush
+		 * the unthrottled cfs_rq(s) from this CPU's csd_list.
+		 */
+		scoped_guard(irqsave)
+			__cfsb_csd_unthrottle(cpu_rq(this_cpu));
 	}
-	WARN_ON_ONCE(!list_empty(&local_unthrottle));
 
 	return throttled;
 }
-- 
2.43.0


  parent reply	other threads:[~2026-05-28  9:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28  9:48 [PATCH 0/5] sched/fair: Allow account_cfs_rq_runtime() to throttle current hierarchy K Prateek Nayak
2026-05-28  9:48 ` [PATCH 1/5] sched/fair: Convert cfs bandwidth throttling to use guards K Prateek Nayak
2026-05-28 21:46   ` Benjamin Segall
2026-05-28  9:48 ` K Prateek Nayak [this message]
2026-05-28 21:53   ` [PATCH 2/5] sched/fair: Use throttled_csd_list for local unthrottle Benjamin Segall
2026-05-28  9:48 ` [PATCH 3/5] sched/fair: Call update_curr() before unthrottling the hierarchy K Prateek Nayak
2026-05-28 22:03   ` Benjamin Segall
2026-06-01  3:52   ` Aaron Lu
2026-06-01  5:50     ` K Prateek Nayak
2026-06-01 11:27       ` Peter Zijlstra
2026-06-02  6:33         ` K Prateek Nayak
2026-05-28  9:48 ` [PATCH 4/5] sched/fair: Move the throttled tasks to a local list in tg_unthrottle_up() K Prateek Nayak
2026-05-28 22:14   ` Benjamin Segall
2026-05-28  9:48 ` [PATCH 5/5] sched/fair: Unify cfs_rq throttling via account_cfs_rq_runtime() K Prateek Nayak
2026-05-28 22:44   ` Benjamin Segall
2026-06-01 13:48   ` Peter Zijlstra
2026-06-02  7:01     ` K Prateek Nayak
2026-06-02  8:32       ` Peter Zijlstra
2026-06-02  8:57         ` K Prateek Nayak
2026-05-28 11:45 ` [PATCH 0/5] sched/fair: Allow account_cfs_rq_runtime() to throttle current hierarchy Peter Zijlstra
2026-06-01  6:18 ` Aaron Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260528094830.13291-3-kprateek.nayak@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=joshdon@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=ziqianlu@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®