From nobody Mon Jun 15 03:54:53 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F7E22C3252; Wed, 8 Apr 2026 03:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775617902; cv=none; b=cHDNBjkVbSEdsdeAMUMB27nUAOe+STXKUo4AlTfzwLJvHj5iR5vqgyHv1a2t/TbX3Uq1KWejsX+nvFrGoiU+ZZ/GGNrJUD3shVSVdPVDQH5oMO6rKn2faarrUAk/TH1LUzAKOJOFskpeIruMbW2LJ5md85TmG+zla3NMIspCPVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775617902; c=relaxed/simple; bh=yofZjsFxaLQ+c9RGnTnqBmRLsHmDsmJmd6NyCCvFuTk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QmjwLAZQE5Wn022wtAt2jmvrNu6rCCHeJN1NEWiO29/ZHCWfkjtZRrskUkKsUOO6QoR/A0gi1/iRBehaBZme9KkMKNB3cJRr4cq2zup1JJEmXKVZW+LxvL9W0liAYRw6maC02v/ForE1sBVER+q/sqDZ381oGiA8Mhd+Grh8PO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=krJ/veDg; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="krJ/veDg" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=T4VtYXI2IFQgDkkQ+hIpBs44BuCKsZd86Opn0mAnZr4=; b=krJ/veDga1acgKz9Sf9H62fMVf 7avWxgACZdb4B0LQtouslWoO5GO2nBMU8N7r3EDN/ivAy46l5ynx0gDCligspVwvGb8jQLZIq4R2X bvcUbmK2gbAVVT7B39ygbfJWcZAGo88AUcPA34nepIUswRYx5FxZqjnCffjfm4qdg4UH/zVqrIlDE rgjyzmh1sFaakQwMzgcvgIMBa0sx4hrshsb+3X4+Y9djebyWl31EuSQeLuUYHTz/qDaa0t5/uddnh uto3qwdf0hFBkQp9JYyd7yUOymh/TnHppSLhKLF751dZxXHU6zRrU2oaiBCWpDH1XLwgLSjq6loHY P0A5xO1g==; Received: from [58.29.145.179] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wAJKC-00DIXy-9X; Wed, 08 Apr 2026 05:11:29 +0200 From: Changwoo Min To: tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: kernel-dev@igalia.com, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] sched_ext: Extract scx_dump_cpu() from scx_dump_state() Date: Wed, 8 Apr 2026 12:11:12 +0900 Message-ID: <20260408031113.76005-2-changwoo@igalia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408031113.76005-1-changwoo@igalia.com> References: <20260408031113.76005-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out the per-CPU state dump logic from the for_each_possible_cpu loop in scx_dump_state() into a new scx_dump_cpu() helper to improve readability. No functional change. Signed-off-by: Changwoo Min --- kernel/sched/ext.c | 173 +++++++++++++++++++++++---------------------- 1 file changed, 90 insertions(+), 83 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index b757b853b42b..8f7d5c1556be 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -6190,6 +6190,95 @@ static void scx_dump_task(struct scx_sched *sch, } } =20 +static void scx_dump_cpu(struct scx_sched *sch, struct seq_buf *s, + struct scx_dump_ctx *dctx, int cpu, + bool dump_all_tasks) +{ + struct rq *rq =3D cpu_rq(cpu); + struct rq_flags rf; + struct task_struct *p; + struct seq_buf ns; + size_t avail, used; + char *buf; + bool idle; + + rq_lock_irqsave(rq, &rf); + + idle =3D list_empty(&rq->scx.runnable_list) && + rq->curr->sched_class =3D=3D &idle_sched_class; + + if (idle && !SCX_HAS_OP(sch, dump_cpu)) + goto next; + + /* + * We don't yet know whether ops.dump_cpu() will produce output + * and we may want to skip the default CPU dump if it doesn't. + * Use a nested seq_buf to generate the standard dump so that we + * can decide whether to commit later. + */ + avail =3D seq_buf_get_buf(s, &buf); + seq_buf_init(&ns, buf, avail); + + dump_newline(&ns); + dump_line(&ns, "CPU %-4d: nr_run=3D%u flags=3D0x%x cpu_rel=3D%d ops_qseq= =3D%lu ksync=3D%lu", + cpu, rq->scx.nr_running, rq->scx.flags, + rq->scx.cpu_released, rq->scx.ops_qseq, + rq->scx.kick_sync); + dump_line(&ns, " curr=3D%s[%d] class=3D%ps", + rq->curr->comm, rq->curr->pid, + rq->curr->sched_class); + if (!cpumask_empty(rq->scx.cpus_to_kick)) + dump_line(&ns, " cpus_to_kick : %*pb", + cpumask_pr_args(rq->scx.cpus_to_kick)); + if (!cpumask_empty(rq->scx.cpus_to_kick_if_idle)) + dump_line(&ns, " idle_to_kick : %*pb", + cpumask_pr_args(rq->scx.cpus_to_kick_if_idle)); + if (!cpumask_empty(rq->scx.cpus_to_preempt)) + dump_line(&ns, " cpus_to_preempt: %*pb", + cpumask_pr_args(rq->scx.cpus_to_preempt)); + if (!cpumask_empty(rq->scx.cpus_to_wait)) + dump_line(&ns, " cpus_to_wait : %*pb", + cpumask_pr_args(rq->scx.cpus_to_wait)); + if (!cpumask_empty(rq->scx.cpus_to_sync)) + dump_line(&ns, " cpus_to_sync : %*pb", + cpumask_pr_args(rq->scx.cpus_to_sync)); + + used =3D seq_buf_used(&ns); + if (SCX_HAS_OP(sch, dump_cpu)) { + ops_dump_init(&ns, " "); + SCX_CALL_OP(sch, SCX_KF_REST, dump_cpu, NULL, + dctx, cpu, idle); + ops_dump_exit(); + } + + /* + * If idle && nothing generated by ops.dump_cpu(), there's + * nothing interesting. Skip. + */ + if (idle && used =3D=3D seq_buf_used(&ns)) + goto next; + + /* + * $s may already have overflowed when $ns was created. If so, + * calling commit on it will trigger BUG. + */ + if (avail) { + seq_buf_commit(s, seq_buf_used(&ns)); + if (seq_buf_has_overflowed(&ns)) + seq_buf_set_overflow(s); + } + + if (rq->curr->sched_class =3D=3D &ext_sched_class && + (dump_all_tasks || scx_task_on_sched(sch, rq->curr))) + scx_dump_task(sch, s, dctx, rq->curr, '*'); + + list_for_each_entry(p, &rq->scx.runnable_list, scx.runnable_node) + if (dump_all_tasks || scx_task_on_sched(sch, p)) + scx_dump_task(sch, s, dctx, p, ' '); +next: + rq_unlock_irqrestore(rq, &rf); +} + /* * Dump scheduler state. If @dump_all_tasks is true, dump all tasks regard= less * of which scheduler they belong to. If false, only dump tasks owned by @= sch. @@ -6210,7 +6299,6 @@ static void scx_dump_state(struct scx_sched *sch, str= uct scx_exit_info *ei, }; struct seq_buf s; struct scx_event_stats events; - char *buf; int cpu; =20 guard(raw_spinlock_irqsave)(&scx_dump_lock); @@ -6250,88 +6338,7 @@ static void scx_dump_state(struct scx_sched *sch, st= ruct scx_exit_info *ei, dump_line(&s, "----------"); =20 for_each_possible_cpu(cpu) { - struct rq *rq =3D cpu_rq(cpu); - struct rq_flags rf; - struct task_struct *p; - struct seq_buf ns; - size_t avail, used; - bool idle; - - rq_lock_irqsave(rq, &rf); - - idle =3D list_empty(&rq->scx.runnable_list) && - rq->curr->sched_class =3D=3D &idle_sched_class; - - if (idle && !SCX_HAS_OP(sch, dump_cpu)) - goto next; - - /* - * We don't yet know whether ops.dump_cpu() will produce output - * and we may want to skip the default CPU dump if it doesn't. - * Use a nested seq_buf to generate the standard dump so that we - * can decide whether to commit later. - */ - avail =3D seq_buf_get_buf(&s, &buf); - seq_buf_init(&ns, buf, avail); - - dump_newline(&ns); - dump_line(&ns, "CPU %-4d: nr_run=3D%u flags=3D0x%x cpu_rel=3D%d ops_qseq= =3D%lu ksync=3D%lu", - cpu, rq->scx.nr_running, rq->scx.flags, - rq->scx.cpu_released, rq->scx.ops_qseq, - rq->scx.kick_sync); - dump_line(&ns, " curr=3D%s[%d] class=3D%ps", - rq->curr->comm, rq->curr->pid, - rq->curr->sched_class); - if (!cpumask_empty(rq->scx.cpus_to_kick)) - dump_line(&ns, " cpus_to_kick : %*pb", - cpumask_pr_args(rq->scx.cpus_to_kick)); - if (!cpumask_empty(rq->scx.cpus_to_kick_if_idle)) - dump_line(&ns, " idle_to_kick : %*pb", - cpumask_pr_args(rq->scx.cpus_to_kick_if_idle)); - if (!cpumask_empty(rq->scx.cpus_to_preempt)) - dump_line(&ns, " cpus_to_preempt: %*pb", - cpumask_pr_args(rq->scx.cpus_to_preempt)); - if (!cpumask_empty(rq->scx.cpus_to_wait)) - dump_line(&ns, " cpus_to_wait : %*pb", - cpumask_pr_args(rq->scx.cpus_to_wait)); - if (!cpumask_empty(rq->scx.cpus_to_sync)) - dump_line(&ns, " cpus_to_sync : %*pb", - cpumask_pr_args(rq->scx.cpus_to_sync)); - - used =3D seq_buf_used(&ns); - if (SCX_HAS_OP(sch, dump_cpu)) { - ops_dump_init(&ns, " "); - SCX_CALL_OP(sch, SCX_KF_REST, dump_cpu, NULL, - &dctx, cpu, idle); - ops_dump_exit(); - } - - /* - * If idle && nothing generated by ops.dump_cpu(), there's - * nothing interesting. Skip. - */ - if (idle && used =3D=3D seq_buf_used(&ns)) - goto next; - - /* - * $s may already have overflowed when $ns was created. If so, - * calling commit on it will trigger BUG. - */ - if (avail) { - seq_buf_commit(&s, seq_buf_used(&ns)); - if (seq_buf_has_overflowed(&ns)) - seq_buf_set_overflow(&s); - } - - if (rq->curr->sched_class =3D=3D &ext_sched_class && - (dump_all_tasks || scx_task_on_sched(sch, rq->curr))) - scx_dump_task(sch, &s, &dctx, rq->curr, '*'); - - list_for_each_entry(p, &rq->scx.runnable_list, scx.runnable_node) - if (dump_all_tasks || scx_task_on_sched(sch, p)) - scx_dump_task(sch, &s, &dctx, p, ' '); - next: - rq_unlock_irqrestore(rq, &rf); + scx_dump_cpu(sch, &s, &dctx, cpu, dump_all_tasks); } =20 dump_newline(&s); --=20 2.53.0 From nobody Mon Jun 15 03:54:53 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB70F34AB19; Wed, 8 Apr 2026 03:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775617904; cv=none; b=TlXIZTKx1IcqHcqkWAsRmV6PafdBB/O1oFFElJWbRu++y8oBz7l4Mw25PpDV18ZW7+yydTsKcpwPGzqurixj+ew+CKAVHGFF1wuQNMzlx6Kh7aJv0BeGwoTRoN5nsx3tS4tStguavJlhEKVzOo40oYn7745KCGj6Sv63qJqARv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775617904; c=relaxed/simple; bh=nlyYSPueSkl/8lHLDtFpXbWXOfEHiNME7NUG//wj59I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iyBANdhhhhwwOJfxQBJpJf4OCWjxNHfGHWf52BpcAo8E6sD9Y/M+KMbW+TU9QOAklSxw1qFHqF6WnyCdNwOgH3DlklxSACkIOWrApDNu7LTi32wvBm0YR8mDAygUEnPcx3ofhgIqyuooYthV7GQ2A3ACADIM9dsb+pFElBn4q70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=Qxc/i3QY; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="Qxc/i3QY" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qe5J3vuK1t3+/2lw61k0vIDuy0Vsms58ZkJwwnPZ13k=; b=Qxc/i3QYhgHG7GSMVoVl8G0Iu/ GQYhLZbKrlPYSGD/7dh3qSzlvwP5NDIvsoqujtsAGMV/YZKSfdVKfGfzn6myBaeeUjCPej/+t2ldY 1RCHj/nbX/XtuR14FVO16Q8KifkX1gTsnCqKL/HVBAGqgxbCvit+2j/SslUMdnVxy3Aktt0+BMMHD 16KmpAEM8/7bviXzycfhCM7IgFElNMKbUB/m0ljWiO/PmNHzRpte5PyeaP2EDz/mcVTFMKppdOoLG txWVC2uUneHpAAiR3o4GWhLjq+ORyqq5yXiw8jRGZCtuTcEIDmzWWa/FqX38JQ/ZTzkDxBeYNR7JO Ns65WMFA==; Received: from [58.29.145.179] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wAJKH-00DIY7-RL; Wed, 08 Apr 2026 05:11:34 +0200 From: Changwoo Min To: tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com Cc: kernel-dev@igalia.com, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] sched_ext: Dump the stall CPU first in watchdog exit Date: Wed, 8 Apr 2026 12:11:13 +0900 Message-ID: <20260408031113.76005-3-changwoo@igalia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408031113.76005-1-changwoo@igalia.com> References: <20260408031113.76005-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a watchdog timeout fires, the CPU where the stalled task was running is the most relevant piece of information for diagnosing the hang. However, if there are many CPUs, the dump can get truncated and the stall CPU's information may not appear in the output. Add a stall_cpu field to scx_exit_info, thread it through scx_vexit() and __scx_exit(), and populate it from cpu_of(rq) in check_rq_for_timeouts(). In scx_dump_state(), dump the stall CPU before iterating the rest so it always appears at the top of the output. Introduce a scx_exit() macro that wraps __scx_exit() with stall_cpu=3D0 for all non-stall exit paths, keeping call sites unchanged. Signed-off-by: Changwoo Min --- kernel/sched/ext.c | 31 ++++++++++++++++++++----------- kernel/sched/ext_internal.h | 3 +++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 8f7d5c1556be..671a1713aedb 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -200,24 +200,28 @@ static bool task_dead_and_done(struct task_struct *p); static void scx_kick_cpu(struct scx_sched *sch, s32 cpu, u64 flags); static void scx_disable(struct scx_sched *sch, enum scx_exit_kind kind); static bool scx_vexit(struct scx_sched *sch, enum scx_exit_kind kind, - s64 exit_code, const char *fmt, va_list args); + s64 exit_code, int stall_cpu, const char *fmt, + va_list args); =20 -static __printf(4, 5) bool scx_exit(struct scx_sched *sch, - enum scx_exit_kind kind, s64 exit_code, - const char *fmt, ...) +static __printf(5, 6) bool __scx_exit(struct scx_sched *sch, + enum scx_exit_kind kind, s64 exit_code, + int stall_cpu, const char *fmt, ...) { va_list args; bool ret; =20 va_start(args, fmt); - ret =3D scx_vexit(sch, kind, exit_code, fmt, args); + ret =3D scx_vexit(sch, kind, exit_code, stall_cpu, fmt, args); va_end(args); =20 return ret; } =20 +#define scx_exit(sch, kind, exit_code, fmt, args...) \ + __scx_exit(sch, kind, exit_code, 0, fmt, ##args) + #define scx_error(sch, fmt, args...) scx_exit((sch), SCX_EXIT_ERROR, 0, fm= t, ##args) -#define scx_verror(sch, fmt, args) scx_vexit((sch), SCX_EXIT_ERROR, 0, fmt= , args) +#define scx_verror(sch, fmt, args) scx_vexit((sch), SCX_EXIT_ERROR, 0, 0, = fmt, args) =20 #define SCX_HAS_OP(sch, op) test_bit(SCX_OP_IDX(op), (sch)->has_op) =20 @@ -3433,9 +3437,10 @@ static bool check_rq_for_timeouts(struct rq *rq) last_runnable + READ_ONCE(sch->watchdog_timeout)))) { u32 dur_ms =3D jiffies_to_msecs(jiffies - last_runnable); =20 - scx_exit(sch, SCX_EXIT_ERROR_STALL, 0, - "%s[%d] failed to run for %u.%03us", - p->comm, p->pid, dur_ms / 1000, dur_ms % 1000); + __scx_exit(sch, SCX_EXIT_ERROR_STALL, 0, cpu_of(rq), + "%s[%d] failed to run for %u.%03us", + p->comm, p->pid, dur_ms / 1000, + dur_ms % 1000); timed_out =3D true; break; } @@ -6337,8 +6342,11 @@ static void scx_dump_state(struct scx_sched *sch, st= ruct scx_exit_info *ei, dump_line(&s, "CPU states"); dump_line(&s, "----------"); =20 + /* Dump the stall CPU first, then dump the rest in order. */ + scx_dump_cpu(sch, &s, &dctx, ei->stall_cpu, dump_all_tasks); for_each_possible_cpu(cpu) { - scx_dump_cpu(sch, &s, &dctx, cpu, dump_all_tasks); + if (cpu !=3D ei->stall_cpu) + scx_dump_cpu(sch, &s, &dctx, cpu, dump_all_tasks); } =20 dump_newline(&s); @@ -6377,7 +6385,7 @@ static void scx_disable_irq_workfn(struct irq_work *i= rq_work) } =20 static bool scx_vexit(struct scx_sched *sch, - enum scx_exit_kind kind, s64 exit_code, + enum scx_exit_kind kind, s64 exit_code, int stall_cpu, const char *fmt, va_list args) { struct scx_exit_info *ei =3D sch->exit_info; @@ -6400,6 +6408,7 @@ static bool scx_vexit(struct scx_sched *sch, */ ei->kind =3D kind; ei->reason =3D scx_exit_reason(ei->kind); + ei->stall_cpu =3D stall_cpu; =20 irq_work_queue(&sch->disable_irq_work); return true; diff --git a/kernel/sched/ext_internal.h b/kernel/sched/ext_internal.h index b4f36d8b9c1d..a0a09e8f2ac2 100644 --- a/kernel/sched/ext_internal.h +++ b/kernel/sched/ext_internal.h @@ -93,6 +93,9 @@ struct scx_exit_info { /* %SCX_EXIT_* - broad category of the exit reason */ enum scx_exit_kind kind; =20 + /* CPU where a task stall happened. */ + int stall_cpu; + /* exit code if gracefully exiting */ s64 exit_code; =20 --=20 2.53.0