[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20241227-sched-use-printk_deferred_once-v1-1-5da85cb38da2@quicinc.com>
Date: Fri, 27 Dec 2024 17:27:10 +0800
From: Maria Yu <quic_aiquny@...cinc.com>
To: Ingo Molnar <mingo@...hat.com>, Peter Zijlstra <peterz@...radead.org>,
Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot
<vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>,
"Mel
Gorman" <mgorman@...e.de>,
Valentin Schneider <vschneid@...hat.com>
CC: Ingo Molnar <mingo@...nel.org>, <linux-kernel@...r.kernel.org>,
<kernel@...cinc.com>, Maria Yu <quic_aiquny@...cinc.com>
Subject: [PATCH] sched: Use printk_deferred_once() instead of WARN_ONCE()
A deadlock is observed when WARN_ONCE() uses printk() inside the scheduler
logic. printk_deferred_once() is a WARN_ONCE() similar special printk
facility for the scheduler to avoid unnecessary deadlocks.
One of the deadlock stacks looks like this:
queued_spin_lock_slowpath() --
//waiting on uart_port_lock which is already hold by current cpu
queued_spin_lock(inline)
do_raw_spin_lock(inline)
__raw_spin_lock_irqsave(inline)
_raw_spin_lock_irqsave()
qcom_geni_serial_console_write()
call_console_driver(inline)
console_emit_next_record()
console_flush_all(inline)
console_unlock()
vprintk_emit()
vprintk_default()
vprintk()
_printk()
__warn_printk()
rq_pin_lock(inline)
rq_lock_irqsave(inline)
.
wake_up_process(inline)
wake_up_worker(inline)
insert_work(inline)
__queue_work()
queue_work_on()
queue_work(inline)
tty_flip_buffer_push()
handle_rx_console()
qcom_geni_serial_handle_rx(inline)
qcom_geni_serial_isr() --
//acquired uart_port_lock
__handle_irq_event_percpu()
handle_irq_event_percpu(inline)
handle_irq_event()
.
After the change, the SCHED_WARN_ON(x) printout appears as follows:
[ x.xxxxxx] WARNING: ------------[ cut here ]------------
[ x.xxxxxx] WARNING: x
Fixes: 9148a3a10e0b ("sched/debug: Add SCHED_WARN_ON()")
Signed-off-by: Maria Yu <quic_aiquny@...cinc.com>
---
kernel/sched/sched.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index aef716c41edba8a6ec7d88db121fe0a9934b5264..863004630ad793c21272566f186d2fbee7fcc95b 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -92,7 +92,16 @@ struct cpuidle_state;
#include "cpudeadline.h"
#ifdef CONFIG_SCHED_DEBUG
-# define SCHED_WARN_ON(x) WARN_ONCE(x, #x)
+# define deferred_warn_on(fmt, ...) \
+ printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
+# define SCHED_WARN_ON(x) ({\
+ int __ret_warn_on = !!(x); \
+ if (unlikely(__ret_warn_on)) { \
+ deferred_warn_on(CUT_HERE); \
+ deferred_warn_on(#x); \
+ } \
+ unlikely(__ret_warn_on); \
+})
#else
# define SCHED_WARN_ON(x) ({ (void)(x), 0; })
#endif
---
base-commit: af98d8a36a963e758e84266d152b92c7b51d4ecb
change-id: 20241226-sched-use-printk_deferred_once-2275b3a2575e
Best regards,
--
Maria Yu <quic_aiquny@...cinc.com>
Powered by blists - more mailing lists