The smaller the num value, the higher the log priority.
1. view loglevel
# cat /proc/sys/kernel/printk
9 4 1 7
9: console_loglevel, messages with a priority higher than this value are printed to the console
4: default_message_loglevel, default priority if printk without priority, for example: printk("hello")
1: minimum_console_loglevel, The minimum value at which the console log level can be set
7: default_console_loglevel, default console log level
linux/kernel/printk.c
int console_printk[4] = {
CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */
MESSAGE_LOGLEVEL_DEFAULT, /* default_message_loglevel */
CONSOLE_LOGLEVEL_MIN, /* minimum_console_loglevel */
CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */
};
all kernel log will be printed to console since console_loglevel is 9(>7).
Note, kernel will print all log which loglevel highter than console_loglevel, except dev_dbg. if we want to enable dev_dbg, make sure to definite DEBUG micro in corresponding driver module. so, every driver module can enable dev_dbg respectively.
2. modify loglevel
2.1 dts bootargs
arch/arm64/boot/dts/megvii/mc40_haps.dts
loglevel = 9
set console_loglevel(console_printk[0]) as 9
console_loglevel(console_printk[0]) will be equivalent to CONSOLE_LOGLEVEL_DEFAULT(default_console_loglevel) if there is no loglevel in bootargs.
like this:
# cat /proc/sys/kernel/printk
7 4 1 7
2.2 echo x > /proc/sys/kernel/printk
disable dev_dbg:
# echo 7 > /proc/sys/kernel/printk
# cat /proc/sys/kernel/printk
7 4 1 7
enable all log(include dev_dbg):
# echo 8 > /proc/sys/kernel/printk
# cat /proc/sys/kernel/printk
8 4 1 7
support this:
# echo 7 3 2 6 > /proc/sys/kernel/printk
# cat /proc/sys/kernel/printk
7 3 2 6
2.3 kernel config
1) Default console loglevel (1-15)
CONSOLE_LOGLEVEL_DEFAULT
Default loglevel to determine what will be printed on the console.
Setting a default here is equivalent to passing in loglevel=<x> in
the kernel bootargs. loglevel=<x> continues to override whatever
value is specified here as well.
2) Default message log level (1-7)
MESSAGE_LOGLEVEL_DEFAULT
Default log level for printk statements with no specified priority.
This was hard-coded to KERN_WARNING since at least 2.6.10 but folks
that are auditing their logs closely may want to set it to a lower priority.
2.4 a bad method
modify DEFAULT_CONSOLE_LOGLEVEL in kernel/printk/printk.c
3. dev_dbg
3.1 definition
include/linux/device.h
#if defined(CONFIG_DYNAMIC_DEBUG)
#define dev_dbg(dev, format, ...) \
do { \
dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
} while (0)
#elif defined(DEBUG)
#define dev_dbg(dev, format, arg...) \
dev_printk(KERN_DEBUG, dev, format, ##arg)
#else
#define dev_dbg(dev, format, arg...) \
({ \
if (0) \
dev_printk(KERN_DEBUG, dev, format, ##arg); \
})
#endif
1) if CONFIG_DYNAMIC_DEBUG
see chapter 4.
2) if DEBUG
enable dev_dbg
3) else
disable dev_dbg
3.2 enable dev_dbg info
1) add micro DEBUG in driver module
add EXTRA_CFLAGS += -DDEBUG in Makefile of driver module
for example: enable dev_dbg in usb host driver
add add EXTRA_CFLAGS += -DDEBUG in drivers/usb/host/Makefile
Note, if we need to enable dev_dbg for one or several special file, we can add #define DEBUG 1 at start of file.
2) modify loglevel to print debug info
if we want print debug info on kernel booting phase: modify dts bootargs or kernel config
-
loglevel = 8 in bootargs
-
set "Default console loglevel" to 8 in kernel config
if not, modify /proc/sys/kernel/printk
-
echo 8 > /proc/sys/kernel/printk