summaryrefslogtreecommitdiffstats
path: root/debian/patches-rt/0031-printk-nbcon-Introduce-printing-kthreads.patch
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--debian/patches-rt/0031-printk-nbcon-Introduce-printing-kthreads.patch (renamed from debian/patches-rt/0030-printk-nbcon-Introduce-printing-kthreads.patch)77
1 files changed, 40 insertions, 37 deletions
diff --git a/debian/patches-rt/0030-printk-nbcon-Introduce-printing-kthreads.patch b/debian/patches-rt/0031-printk-nbcon-Introduce-printing-kthreads.patch
index 85792a75e2..8557ac1ea9 100644
--- a/debian/patches-rt/0030-printk-nbcon-Introduce-printing-kthreads.patch
+++ b/debian/patches-rt/0031-printk-nbcon-Introduce-printing-kthreads.patch
@@ -1,7 +1,7 @@
From: Thomas Gleixner <tglx@linutronix.de>
Date: Fri, 22 Sep 2023 14:12:21 +0000
-Subject: [PATCH 30/46] printk: nbcon: Introduce printing kthreads
-Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/6.9/older/patches-6.9-rt5.tar.xz
+Subject: [PATCH 31/48] printk: nbcon: Introduce printing kthreads
+Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/6.10/older/patches-6.10.2-rt14.tar.xz
Provide the main implementation for running a printer kthread
per nbcon console that is takeover/handover aware.
@@ -14,8 +14,8 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
include/linux/console.h | 26 ++++++
kernel/printk/internal.h | 26 ++++++
kernel/printk/nbcon.c | 196 +++++++++++++++++++++++++++++++++++++++++++++--
- kernel/printk/printk.c | 31 +++++++
- 4 files changed, 271 insertions(+), 8 deletions(-)
+ kernel/printk/printk.c | 34 ++++++++
+ 4 files changed, 275 insertions(+), 7 deletions(-)
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -29,7 +29,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
@@ -324,6 +325,8 @@ struct nbcon_write_context {
* @nbcon_seq: Sequence number of the next record for nbcon to print
- * @nbcon_driver_ctxt: Context available for driver non-printing operations
+ * @nbcon_device_ctxt: Context available for non-printing operations
* @pbufs: Pointer to nbcon private buffer
+ * @kthread: Printer kthread for this console
+ * @rcuwait: RCU-safe wait object for @kthread waking
@@ -42,11 +42,11 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
/**
+ * @write_thread:
+ *
-+ * NBCON callback to write out text in task context. (Optional)
++ * NBCON callback to write out text in task context.
+ *
-+ * This callback is called with the console already acquired. Any
-+ * additional driver synchronization should have been performed by
-+ * device_lock().
++ * This callback is called after device_lock() and with the nbcon
++ * console acquired. Any necessary driver synchronization should have
++ * been performed by the device_lock() callback.
+ *
+ * This callback is always called from task context but with migration
+ * disabled.
@@ -55,8 +55,8 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ * sections applies as with write_atomic(). The difference between
+ * this callback and write_atomic() is that this callback is used
+ * during normal operation and is always called from task context.
-+ * This provides drivers with a relatively relaxed locking context
-+ * for synchronizing output to the hardware.
++ * This allows drivers to operate in their own locking context for
++ * synchronizing output to the hardware.
+ */
+ void (*write_thread)(struct console *con, struct nbcon_write_context *wctxt);
+
@@ -66,7 +66,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
* NBCON callback to begin synchronization with driver code.
@@ -420,6 +444,8 @@ struct console {
atomic_long_t __private nbcon_seq;
- struct nbcon_context __private nbcon_driver_ctxt;
+ struct nbcon_context __private nbcon_device_ctxt;
struct printk_buffers *pbufs;
+ struct task_struct *kthread;
+ struct rcuwait rcuwait;
@@ -75,7 +75,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
#ifdef CONFIG_LOCKDEP
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
-@@ -90,6 +90,7 @@ enum nbcon_prio nbcon_get_default_prio(v
+@@ -92,6 +92,7 @@ enum nbcon_prio nbcon_get_default_prio(v
void nbcon_atomic_flush_pending(void);
bool nbcon_legacy_emit_next_record(struct console *con, bool *handover,
int cookie);
@@ -83,7 +83,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
/*
* Check if the given console is currently capable and allowed to print
-@@ -108,6 +109,8 @@ static inline bool console_is_usable(str
+@@ -110,6 +111,8 @@ static inline bool console_is_usable(str
if (flags & CON_NBCON) {
if (!con->write_atomic)
return false;
@@ -92,7 +92,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
} else {
if (!con->write)
return false;
-@@ -124,12 +127,35 @@ static inline bool console_is_usable(str
+@@ -126,12 +129,35 @@ static inline bool console_is_usable(str
return true;
}
@@ -142,7 +142,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
/**
* nbcon_emit_next_record - Emit a record in the acquired context
* @wctxt: The write context that will be handed to the write function
-+ * @use_atomic: True if the write_atomic callback is to be used
++ * @use_atomic: True if the write_atomic() callback is to be used
*
* Return: True if this context still owns the console. False if
* ownership was handed over or taken.
@@ -171,15 +171,14 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
} else {
/*
* This function should never be called for legacy consoles.
-@@ -936,6 +944,118 @@ static bool nbcon_emit_next_record(struc
+@@ -936,6 +944,120 @@ static bool nbcon_emit_next_record(struc
return nbcon_context_exit_unsafe(ctxt);
}
+/**
+ * nbcon_kthread_should_wakeup - Check whether a printer thread should wakeup
+ * @con: Console to operate on
-+ * @ctxt: The acquire context that contains the state
-+ * at console_acquire()
++ * @ctxt: The nbcon context from nbcon_context_try_acquire()
+ *
+ * Return: True if the thread should shutdown or if the console is
+ * allowed to print and a record is available. False otherwise.
@@ -213,6 +212,8 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+/**
+ * nbcon_kthread_func - The printer thread function
+ * @__console: Console to operate on
++ *
++ * Return: 0
+ */
+static int nbcon_kthread_func(void *__console)
+{
@@ -222,7 +223,6 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ .ctxt.prio = NBCON_PRIO_NORMAL,
+ };
+ struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt);
-+ unsigned long flags;
+ short con_flags;
+ bool backlog;
+ int cookie;
@@ -258,7 +258,9 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ con_flags = console_srcu_read_flags(con);
+
+ if (console_is_usable(con, con_flags)) {
-+ con->device_lock(con, &flags);
++ unsigned long lock_flags;
++
++ con->device_lock(con, &lock_flags);
+
+ /*
+ * Ensure this stays on the CPU to make handover and
@@ -277,7 +279,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ }
+ }
+
-+ con->device_unlock(con, flags);
++ con->device_unlock(con, lock_flags);
+ }
+
+ console_srcu_read_unlock(cookie);
@@ -290,7 +292,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
/* Track the nbcon emergency nesting per CPU. */
static DEFINE_PER_CPU(unsigned int, nbcon_pcpu_emergency_nesting);
static unsigned int early_nbcon_pcpu_emergency_nesting __initdata;
-@@ -1012,7 +1132,7 @@ static bool nbcon_atomic_emit_one(struct
+@@ -1012,7 +1134,7 @@ static bool nbcon_atomic_emit_one(struct
* The higher priority printing context takes over responsibility
* to print the pending records.
*/
@@ -299,7 +301,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
return false;
nbcon_context_release(ctxt);
-@@ -1113,7 +1233,7 @@ static int __nbcon_atomic_flush_pending_
+@@ -1113,7 +1235,7 @@ static int __nbcon_atomic_flush_pending_
* handed over or taken over. In both cases the context is no
* longer valid.
*/
@@ -308,23 +310,21 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
return -EAGAIN;
if (!ctxt->backlog) {
-@@ -1159,11 +1279,11 @@ static void nbcon_atomic_flush_pending_c
- local_irq_restore(flags);
+@@ -1172,10 +1294,10 @@ static void nbcon_atomic_flush_pending_c
/*
-- * If flushing was successful but more records are available, this
+ * If flushing was successful but more records are available, this
- * context must flush those remaining records because there is no
- * other context that will do it.
-+ * If flushing was successful but more records are available this
+ * context must flush those remaining records if the printer thread
-+ * is not available to do it.
++ * is not available do it.
*/
-- if (!err && prb_read_valid(prb, nbcon_seq_read(con), NULL)) {
-+ if (!err && !con->kthread && prb_read_valid(prb, nbcon_seq_read(con), NULL)) {
+- if (prb_read_valid(prb, nbcon_seq_read(con), NULL)) {
++ if (!con->kthread && prb_read_valid(prb, nbcon_seq_read(con), NULL)) {
stop_seq = prb_next_reserve_seq(prb);
goto again;
}
-@@ -1315,6 +1435,63 @@ void nbcon_cpu_emergency_flush(void)
+@@ -1332,6 +1454,63 @@ void nbcon_cpu_emergency_flush(void)
}
}
@@ -388,7 +388,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
/**
* nbcon_alloc - Allocate buffers needed by the nbcon console
* @con: Console to allocate buffers for
-@@ -1360,6 +1537,7 @@ void nbcon_init(struct console *con, u64
+@@ -1377,6 +1556,7 @@ void nbcon_init(struct console *con, u64
/* nbcon_alloc() must have been called and successful! */
BUG_ON(!con->pbufs);
@@ -396,7 +396,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
nbcon_seq_force(con, init_seq);
nbcon_state_set(con, &state);
}
-@@ -1372,6 +1550,7 @@ void nbcon_free(struct console *con)
+@@ -1389,6 +1569,7 @@ void nbcon_free(struct console *con)
{
struct nbcon_state state = { };
@@ -404,7 +404,7 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
nbcon_state_set(con, &state);
/* Boot consoles share global printk buffers. */
-@@ -1440,6 +1619,7 @@ void nbcon_driver_release(struct console
+@@ -1458,6 +1639,7 @@ void nbcon_device_release(struct console
*/
cookie = console_srcu_read_lock();
if (console_is_usable(con, console_srcu_read_flags(con)) &&
@@ -452,15 +452,15 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
if (!console_is_usable(con, flags))
continue;
any_usable = true;
-@@ -3314,9 +3331,23 @@ EXPORT_SYMBOL(console_stop);
+@@ -3326,9 +3343,26 @@ EXPORT_SYMBOL(console_stop);
void console_start(struct console *console)
{
+ short flags;
++ int cookie;
+
console_list_lock();
console_srcu_write_flags(console, console->flags | CON_ENABLED);
-+ flags = console->flags;
console_list_unlock();
+
+ /*
@@ -470,8 +470,11 @@ Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ */
+ synchronize_srcu(&console_srcu);
+
++ cookie = console_srcu_read_lock();
++ flags = console_srcu_read_flags(console);
+ if (flags & CON_NBCON)
+ nbcon_kthread_wake(console);
++ console_srcu_read_unlock(cookie);
+
__pr_flush(console, 1000, true);
}