All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Thomas Gleixner <tglx@kernel.org>,
	Waiman Long <longman@redhat.com>
Cc: "Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"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>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Ridong Chen" <ridong.chen@linux.dev>,
	"Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Srivatsa S . Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
	"Guopeng Zhang" <guopeng.zhang@linux.dev>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Guopeng Zhang" <zhangguopeng@kylinos.cn>
Subject: [RFC PATCH 2/3] sched: Allow isolated CPUs as a last resort during CPU freeze
Date: Wed, 22 Jul 2026 19:52:37 +0800	[thread overview]
Message-ID: <20260722115238.351821-3-guopeng.zhang@linux.dev> (raw)
In-Reply-To: <20260722115238.351821-1-guopeng.zhang@linux.dev>

From: Guopeng Zhang <zhangguopeng@kylinos.cn>

task_cpu_fallback_mask() normally excludes domain-isolated CPUs. During
CPU freeze, however, every CPU except the suspend primary is taken
offline. If the primary CPU is excluded from HK_TYPE_DOMAIN, the normal
fallback mask eventually contains no active CPU and select_fallback_rq()
can exhaust its fallback states.

When CPU freeze is in progress and the normal fallback mask contains no
active CPU, use task_cpu_possible_mask() as a temporary last resort if it
still contains an active CPU. select_fallback_rq() will select only an
active CPU from that mask, while architecture-specific task CPU
capability constraints remain intact.

Keep the normal housekeeping fallback while it contains an active CPU.
The temporary affinity is preserved and restored by the preceding
change.

Fixes: bf5b0c27fad2 ("sched: Switch the fallback task allowed cpumask to HK_TYPE_DOMAIN")
Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
 kernel/sched/core.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 8160d3287ad9..5f8ffded1a20 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2806,8 +2806,10 @@ do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx)
 static DEFINE_RAW_SPINLOCK(cpu_fallback_lock);
 static bool cpu_fallback_active;
 
-static bool mark_cpu_fallback(struct task_struct *p)
+static bool mark_cpu_fallback(struct task_struct *p,
+			      const struct cpumask **fallback_mask)
 {
+	const struct cpumask *possible_mask;
 	unsigned long flags;
 	bool temporary = false;
 
@@ -2817,6 +2819,11 @@ static bool mark_cpu_fallback(struct task_struct *p)
 	raw_spin_lock_irqsave(&cpu_fallback_lock, flags);
 	if (cpu_fallback_active) {
 		p->migration_flags |= MDF_CPUHP_FALLBACK;
+		if (!cpumask_intersects(*fallback_mask, cpu_active_mask)) {
+			possible_mask = task_cpu_possible_mask(p);
+			if (cpumask_intersects(possible_mask, cpu_active_mask))
+				*fallback_mask = possible_mask;
+		}
 		temporary = true;
 	}
 	raw_spin_unlock_irqrestore(&cpu_fallback_lock, flags);
@@ -2842,7 +2849,7 @@ void set_cpus_allowed_force(struct task_struct *p, const struct cpumask *new_mas
 	};
 
 	scoped_guard (__task_rq_lock, p) {
-		if (mark_cpu_fallback(p))
+		if (mark_cpu_fallback(p, &ac.new_mask))
 			ac.flags = 0;
 		do_set_cpus_allowed(p, &ac);
 	}
-- 
2.43.0


  parent reply	other threads:[~2026-07-22 11:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 11:52 [RFC PATCH 0/3] sched: Handle CPU freeze without active domain housekeeping CPUs Guopeng Zhang
2026-07-22 11:52 ` [RFC PATCH 1/3] sched: Preserve user affinity across frozen CPU fallback Guopeng Zhang
2026-07-22 11:52 ` Guopeng Zhang [this message]
2026-07-22 11:52 ` [RFC PATCH 3/3] sched/topology: Tear down domains without active domain housekeeping CPUs Guopeng Zhang

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=20260722115238.351821-3-guopeng.zhang@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=bsegall@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=frederic@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=peterz@infradead.org \
    --cc=ridong.chen@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=srivatsa.bhat@linux.vnet.ibm.com \
    --cc=tglx@kernel.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=zhangguopeng@kylinos.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.