mirror of
https://github.com/torvalds/linux.git
synced 2026-06-07 14:04:54 +02:00
printk: add support show process information on printks
Change-Id: I34cf76388ceb2e1f6b6417638c82bf774641ebac Signed-off-by: Tao Huang <huangtao@rock-chips.com>
This commit is contained in:
parent
4b1fe5cca9
commit
da75c6afba
|
|
@ -364,6 +364,12 @@ struct printk_log {
|
|||
u8 facility; /* syslog facility */
|
||||
u8 flags:5; /* internal record flags */
|
||||
u8 level:3; /* syslog level */
|
||||
#ifdef CONFIG_PRINTK_PROCESS
|
||||
char process[16]; /* process name */
|
||||
pid_t pid; /* process id */
|
||||
u8 cpu; /* cpu id */
|
||||
u8 in_interrupt; /* interrupt context */
|
||||
#endif
|
||||
}
|
||||
#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
|
||||
__packed __aligned(4)
|
||||
|
|
@ -428,7 +434,11 @@ static u32 console_idx;
|
|||
static u64 clear_seq;
|
||||
static u32 clear_idx;
|
||||
|
||||
#ifdef CONFIG_PRINTK_PROCESS
|
||||
#define PREFIX_MAX 48
|
||||
#else
|
||||
#define PREFIX_MAX 32
|
||||
#endif
|
||||
#define LOG_LINE_MAX (1024 - PREFIX_MAX)
|
||||
|
||||
#define LOG_LEVEL(v) ((v) & 0x07)
|
||||
|
|
@ -497,6 +507,25 @@ static u32 log_next(u32 idx)
|
|||
return idx + msg->len;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PRINTK_PROCESS
|
||||
static bool printk_process = true;
|
||||
static size_t print_process(const struct printk_log *msg, char *buf)
|
||||
{
|
||||
if (!printk_process)
|
||||
return 0;
|
||||
|
||||
if (!buf)
|
||||
return snprintf(NULL, 0, "%c[%1d:%15s:%5d] ", ' ', 0, " ", 0);
|
||||
|
||||
return sprintf(buf, "%c[%1d:%15s:%5d] ",
|
||||
msg->in_interrupt ? 'I' : ' ',
|
||||
msg->cpu,
|
||||
msg->process,
|
||||
msg->pid);
|
||||
}
|
||||
module_param_named(process, printk_process, bool, 0644);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check whether there is enough free space for the given message.
|
||||
*
|
||||
|
|
@ -633,6 +662,16 @@ static int log_store(int facility, int level,
|
|||
memset(log_dict(msg) + dict_len, 0, pad_len);
|
||||
msg->len = size;
|
||||
|
||||
#ifdef CONFIG_PRINTK_PROCESS
|
||||
if (printk_process) {
|
||||
strncpy(msg->process, current->comm, sizeof(msg->process) - 1);
|
||||
msg->process[sizeof(msg->process) - 1] = '\0';
|
||||
msg->pid = task_pid_nr(current);
|
||||
msg->cpu = raw_smp_processor_id();
|
||||
msg->in_interrupt = in_interrupt() ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* insert message */
|
||||
log_next_idx += msg->len;
|
||||
log_next_seq++;
|
||||
|
|
@ -1250,6 +1289,9 @@ static size_t print_prefix(const struct printk_log *msg, bool syslog, char *buf)
|
|||
}
|
||||
|
||||
len += print_time(msg->ts_nsec, buf ? buf + len : NULL);
|
||||
#ifdef CONFIG_PRINTK_PROCESS
|
||||
len += print_process(msg, buf ? buf + len : NULL);
|
||||
#endif
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@ config PRINTK_TIME
|
|||
The behavior is also controlled by the kernel command line
|
||||
parameter printk.time=1. See Documentation/admin-guide/kernel-parameters.rst
|
||||
|
||||
config PRINTK_PROCESS
|
||||
bool "Show process information on printks"
|
||||
depends on PRINTK
|
||||
help
|
||||
Selecting this option causes process to be
|
||||
included in printk output. Or add printk.process=1 at boot-time.
|
||||
|
||||
config CONSOLE_LOGLEVEL_DEFAULT
|
||||
int "Default console loglevel (1-15)"
|
||||
range 1 15
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user