Skip to content

Commit 4da42aa

Browse files
marcospspmladek
authored andcommitted
printk: nbcon: Export console_is_usable
The helper will be used on KDB code in the next commits. Reviewed-by: Petr Mladek <pmladek@suse.com> Reviewed-by: John Ogness <john.ogness@linutronix.de> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> Link: https://patch.msgid.link/20251016-nbcon-kgdboc-v6-1-866aac60a80e@suse.com Signed-off-by: Petr Mladek <pmladek@suse.com>
1 parent 48e3694 commit 4da42aa

2 files changed

Lines changed: 45 additions & 45 deletions

File tree

include/linux/console.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/irq_work.h>
2020
#include <linux/rculist.h>
2121
#include <linux/rcuwait.h>
22+
#include <linux/smp.h>
2223
#include <linux/types.h>
2324
#include <linux/vesa.h>
2425

@@ -605,13 +606,57 @@ extern bool nbcon_can_proceed(struct nbcon_write_context *wctxt);
605606
extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt);
606607
extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt);
607608
extern void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt);
609+
610+
/*
611+
* Check if the given console is currently capable and allowed to print
612+
* records. Note that this function does not consider the current context,
613+
* which can also play a role in deciding if @con can be used to print
614+
* records.
615+
*/
616+
static inline bool console_is_usable(struct console *con, short flags, bool use_atomic)
617+
{
618+
if (!(flags & CON_ENABLED))
619+
return false;
620+
621+
if ((flags & CON_SUSPENDED))
622+
return false;
623+
624+
if (flags & CON_NBCON) {
625+
/* The write_atomic() callback is optional. */
626+
if (use_atomic && !con->write_atomic)
627+
return false;
628+
629+
/*
630+
* For the !use_atomic case, @printk_kthreads_running is not
631+
* checked because the write_thread() callback is also used
632+
* via the legacy loop when the printer threads are not
633+
* available.
634+
*/
635+
} else {
636+
if (!con->write)
637+
return false;
638+
}
639+
640+
/*
641+
* Console drivers may assume that per-cpu resources have been
642+
* allocated. So unless they're explicitly marked as being able to
643+
* cope (CON_ANYTIME) don't call them until this CPU is officially up.
644+
*/
645+
if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME))
646+
return false;
647+
648+
return true;
649+
}
650+
608651
#else
609652
static inline void nbcon_cpu_emergency_enter(void) { }
610653
static inline void nbcon_cpu_emergency_exit(void) { }
611654
static inline bool nbcon_can_proceed(struct nbcon_write_context *wctxt) { return false; }
612655
static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) { return false; }
613656
static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { return false; }
614657
static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }
658+
static inline bool console_is_usable(struct console *con, short flags,
659+
bool use_atomic) { return false; }
615660
#endif
616661

617662
extern int console_set_on_cmdline;

kernel/printk/internal.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* internal.h - printk internal definitions
44
*/
55
#include <linux/console.h>
6-
#include <linux/percpu.h>
76
#include <linux/types.h>
87

98
#if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL)
@@ -112,47 +111,6 @@ bool nbcon_kthread_create(struct console *con);
112111
void nbcon_kthread_stop(struct console *con);
113112
void nbcon_kthreads_wake(void);
114113

115-
/*
116-
* Check if the given console is currently capable and allowed to print
117-
* records. Note that this function does not consider the current context,
118-
* which can also play a role in deciding if @con can be used to print
119-
* records.
120-
*/
121-
static inline bool console_is_usable(struct console *con, short flags, bool use_atomic)
122-
{
123-
if (!(flags & CON_ENABLED))
124-
return false;
125-
126-
if ((flags & CON_SUSPENDED))
127-
return false;
128-
129-
if (flags & CON_NBCON) {
130-
/* The write_atomic() callback is optional. */
131-
if (use_atomic && !con->write_atomic)
132-
return false;
133-
134-
/*
135-
* For the !use_atomic case, @printk_kthreads_running is not
136-
* checked because the write_thread() callback is also used
137-
* via the legacy loop when the printer threads are not
138-
* available.
139-
*/
140-
} else {
141-
if (!con->write)
142-
return false;
143-
}
144-
145-
/*
146-
* Console drivers may assume that per-cpu resources have been
147-
* allocated. So unless they're explicitly marked as being able to
148-
* cope (CON_ANYTIME) don't call them until this CPU is officially up.
149-
*/
150-
if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME))
151-
return false;
152-
153-
return true;
154-
}
155-
156114
/**
157115
* nbcon_kthread_wake - Wake up a console printing thread
158116
* @con: Console to operate on
@@ -204,9 +162,6 @@ static inline bool nbcon_legacy_emit_next_record(struct console *con, bool *hand
204162
static inline void nbcon_kthread_wake(struct console *con) { }
205163
static inline void nbcon_kthreads_wake(void) { }
206164

207-
static inline bool console_is_usable(struct console *con, short flags,
208-
bool use_atomic) { return false; }
209-
210165
#endif /* CONFIG_PRINTK */
211166

212167
extern bool have_boot_console;

0 commit comments

Comments
 (0)