summaryrefslogtreecommitdiffstats
path: root/kernel/printk/nbcon.c
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2024-08-20 08:29:45 +0200
committerPetr Mladek <pmladek@suse.com>2024-08-21 14:56:24 +0200
commit06683a6649895ccf279c35ca2fb77fd7afb7a6c5 (patch)
tree355dc59dd507da00cf47fbc5fa0777d99ae95e99 /kernel/printk/nbcon.c
parentprintk: Add @flags argument for console_is_usable() (diff)
downloadlinux-06683a6649895ccf279c35ca2fb77fd7afb7a6c5.tar.xz
linux-06683a6649895ccf279c35ca2fb77fd7afb7a6c5.zip
printk: nbcon: Add helper to assign priority based on CPU state
Add a helper function to use the current state of the CPU to determine which priority to assign to the printing context. The EMERGENCY priority handling is added in a follow-up commit. It will use a per-CPU variable. Note: nbcon_device_try_acquire(), which is used by console drivers to acquire the nbcon console for non-printing activities, is hard-coded to always use NORMAL priority. Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20240820063001.36405-20-john.ogness@linutronix.de Signed-off-by: Petr Mladek <pmladek@suse.com>
Diffstat (limited to 'kernel/printk/nbcon.c')
-rw-r--r--kernel/printk/nbcon.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index e8ddcb6f7053..c6a9aa9f62f6 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -974,6 +974,25 @@ update_con:
}
/**
+ * nbcon_get_default_prio - The appropriate nbcon priority to use for nbcon
+ * printing on the current CPU
+ *
+ * Context: Any context.
+ * Return: The nbcon_prio to use for acquiring an nbcon console in this
+ * context for printing.
+ *
+ * The function is safe for reading per-CPU data in any context because
+ * preemption is disabled if the current CPU is in the panic state.
+ */
+enum nbcon_prio nbcon_get_default_prio(void)
+{
+ if (this_cpu_in_panic())
+ return NBCON_PRIO_PANIC;
+
+ return NBCON_PRIO_NORMAL;
+}
+
+/**
* nbcon_alloc - Allocate and init the nbcon console specific data
* @con: Console to initialize
*