[COMMON] printk: add supporting core number and process information
authorHosung Kim <hosung0.kim@samsung.com>
Fri, 12 Jun 2015 13:40:21 +0000 (22:40 +0900)
committerDonghyeok Choe <d7271.choe@samsung.com>
Tue, 15 May 2018 04:36:37 +0000 (13:36 +0900)
This commit adds supporting to output the core number and process
information. They are depending on as following configuration.
- CONFIG_PRINTK_PROCESS

Change-Id: I09698dc00e5acd1bb11b9a564fdc3f129c04b642
Signed-off-by: Hosung Kim <hosung0.kim@samsung.com>
Signed-off-by: Hyunki Koo <hyunki00.koo@samsung.com>
kernel/printk/printk.c
lib/Kconfig.debug

index 512f7c2baedd59bef5300e361c22e92b7a4845a0..c911f8f7fa2d3218ee34249c68788fad6c52ec9f 100644 (file)
@@ -359,6 +359,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)
@@ -423,7 +429,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)
@@ -550,6 +560,32 @@ static u32 msg_used_size(u16 text_len, u16 dict_len, u32 *pad_len)
        return size;
 }
 
+#ifdef CONFIG_PRINTK_PROCESS
+static bool printk_process = 1;
+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);
+}
+#else
+static bool printk_process = 0;
+static size_t print_process(const struct printk_log *msg, char *buf)
+{
+       return 0;
+}
+#endif
+module_param_named(process, printk_process, bool, S_IRUGO | S_IWUSR);
+
 /*
  * Define how much of the log buffer we could take at maximum. The value
  * must be greater than two. Note that only half of the buffer is available
@@ -628,6 +664,15 @@ 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 = smp_processor_id();
+               msg->in_interrupt = in_interrupt() ? 1 : 0;
+       }
+#endif
        /* insert message */
        log_next_idx += msg->len;
        log_next_seq++;
@@ -1240,6 +1285,7 @@ static size_t print_prefix(const struct printk_log *msg, bool syslog, char *buf)
        }
 
        len += print_time(msg->ts_nsec, buf ? buf + len : NULL);
+       len += print_process(msg, buf ? buf + len : NULL);
        return len;
 }
 
@@ -1689,6 +1735,7 @@ asmlinkage int vprintk_emit(int facility, int level,
        size_t text_len;
        enum log_flags lflags = 0;
        unsigned long flags;
+       int this_cpu;
        int printed_len;
        bool in_sched = false;
 
@@ -1702,6 +1749,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 
        /* This stops the holder of console_sem just where we want him */
        logbuf_lock_irqsave(flags);
+       this_cpu = smp_processor_id();
        /*
         * The printf needs to come first; we need the syslog
         * prefix which might be passed-in as a parameter.
index 62d0e25c054c6abaa8d82b767fb007cf21afc705..fc3c8906d2be66e0850c7ebe4652d4f51b1f181d 100644 (file)
@@ -30,6 +30,13 @@ config CONSOLE_LOGLEVEL_DEFAULT
          usage in the kernel. That is controlled by the MESSAGE_LOGLEVEL_DEFAULT
          option.
 
+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 MESSAGE_LOGLEVEL_DEFAULT
        int "Default message log level (1-7)"
        range 1 7