On Thu 2022-04-07 22:20:30, Helge Deller wrote: > On 4/7/22 22:04, John Ogness wrote: > > On 2022-04-07, Helge Deller <deller@xxxxxx> wrote: > >> In my case - while I debug low-level kernel code - I then just need to > >> use pr_warn() or pr_emerg() and get it printed non-threadened. That's > >> sufficient for me. > > > > Actually, no. The loglevel does not determine if a message is direct > > printed or not. By "warn" I was referring to WARN_ON(condition). > > Oh, then there was a misunderstanding on my side. > > > If you are debugging low-level kernel code, you usually will _want_ > > threaded printing. The timestamps match the printk() call, so you will > > get accurate logs. And the runtime performance of your low-level kernel > > code will not be significantly affected by the printk() call. > > That really much depends on what you debug. > Currently I'm debugging some CPU hotplug stuff, and I really want my > debug info printed immediately, otherwise it's too late to analyze what's > going wrong. I can imaginge other use cases like trying to find memory > leaks are similiar. So, it is not about severity of the messages but about the context, in this case the suspend. We try to address this. 10th patch from this patchset adds: static inline bool allow_direct_printing(void) { return (!printk_kthreads_available || system_state > SYSTEM_RUNNING || oops_in_progress || atomic_read(&printk_prefer_direct)); } It means that printk() inside the SYSTEM_SUSPEND state will automatically try to handle the console directly. I intentionally mention "try" because printk() uses console_trylock(). It fails when anyone else already does the printing, including a kthread. trylock() is needed because printk() must be usable also in atomic context. It has worked this way for more than two decades. It came with SMP support. > > If for some reason you really want non-threaded printing, the patch we > > are discussing creates new functions to manually activate it: > > > > printk_prefer_direct_enter(); > > pr_info("debugging\n"); > > printk_prefer_direct_exit(); > > That's quite unhandy. At least I would have thought that pr_emerg() would > do that call sequence. > Wouldn't it make sense to make pr_emerg() work unthreadened, as it's > used quite seldom and only in special situations... It is true that pr_emerg() is relatively special. But I would really like to avoid a situation where developers use non-appropriate printk level just to get the message directly. Instead, we should allow using the direct context in some situation easily. We could also add a command line parameter to disable the kthreads completely. Best Regards, Petr