From ae35d194b404c8e2b26bcf2ce560b1c3b6a2a3b2 Mon Sep 17 00:00:00 2001 From: hq_guohongtao5_tmp Date: Fri, 21 Dec 2018 11:15:34 +0800 Subject: [PATCH] (CR):[facotry]:add utc time in prink add utc time in prink Change-Id: I2b464c0e88c435a3a7b4362b85b725bda14d9f8f Signed-off-by: hq_guohongtao5_tmp --- kernel/printk/printk.c | 38 ++++++++++++++++++++++++++++++++++++-- lib/Kconfig.debug | 7 +++++++ 2 files changed, 43 insertions(+), 2 deletions(-) mode change 100644 => 100755 kernel/printk/printk.c diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c old mode 100644 new mode 100755 index 5a3bb51dfbe2..aee7e32b8be3 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -51,7 +51,7 @@ #include #include - +#include #define CREATE_TRACE_POINTS #include @@ -431,7 +431,9 @@ static u32 console_idx; static u64 clear_seq; static u32 clear_idx; -#ifdef CONFIG_PRINTK_PROCESS +#ifdef CONFIG_PRINTK_UTC_TIME +#define PREFIX_MAX 100 +#elif defined(CONFIG_PRINTK_PROCESS) #define PREFIX_MAX 48 #else #define PREFIX_MAX 32 @@ -565,6 +567,7 @@ static u32 msg_used_size(u16 text_len, u16 dict_len, u32 *pad_len) #ifdef CONFIG_PRINTK_PROCESS static bool printk_process = 1; +#ifndef CONFIG_PRINTK_UTC_TIME static size_t print_process(const struct printk_log *msg, char *buf) { @@ -580,13 +583,16 @@ static size_t print_process(const struct printk_log *msg, char *buf) msg->process, msg->pid); } +#endif #else static bool printk_process = 0; +#ifndef CONFIG_PRINTK_UTC_TIME static size_t print_process(const struct printk_log *msg, char *buf) { return 0; } #endif +#endif module_param_named(process, printk_process, bool, S_IRUGO | S_IWUSR); #ifdef CONFIG_DEBUG_SNAPSHOT @@ -651,7 +657,20 @@ static u32 truncate_msg(u16 *text_len, u16 *trunc_msg_len, /* compute the size again, count also the warning message */ return msg_used_size(*text_len + *trunc_msg_len, 0, pad_len); } +#ifdef CONFIG_PRINTK_UTC_TIME +static void log_store_utc_time(char *buf, u32 buf_size, u16 *len) { + struct timespec ts; + struct rtc_time tm; + ts = current_kernel_time(); + rtc_time_to_tm(ts.tv_sec, &tm); + *len += snprintf(buf, buf_size, "[%lu:%.2d:%.2d %.2d:%.2d:%.2d.%09lu]", + 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,ts.tv_nsec); + *len += snprintf(buf + *len, buf_size-*len, "[pid:%d,cpu%d,%s]", + current->pid, smp_processor_id(), in_irq() ? "in irq" : current->comm); + return; +} +#endif /* insert record into the buffer, discard old ones, update heads */ static int log_store(int facility, int level, enum log_flags flags, u64 ts_nsec, @@ -661,7 +680,13 @@ static int log_store(int facility, int level, struct printk_log *msg; u32 size, pad_len; u16 trunc_msg_len = 0; +#ifdef CONFIG_PRINTK_UTC_TIME + char tmp_buf[100]; + u16 tmp_len = 0; + log_store_utc_time(tmp_buf, sizeof(tmp_buf), &tmp_len); + text_len += tmp_len; +#endif /* number of '\0' padding bytes to next message */ size = msg_used_size(text_len, dict_len, &pad_len); @@ -687,6 +712,13 @@ static int log_store(int facility, int level, /* fill message */ msg = (struct printk_log *)(log_buf + log_next_idx); memcpy(log_text(msg), text, text_len); +#ifdef CONFIG_PRINTK_UTC_TIME + memcpy(log_text(msg), tmp_buf, tmp_len); + memcpy(log_text(msg)+tmp_len, text, text_len-tmp_len); +#else + memcpy(log_text(msg), text, text_len); +#endif + msg->text_len = text_len; if (trunc_msg_len) { memcpy(log_text(msg) + text_len, trunc_msg, trunc_msg_len); @@ -1342,7 +1374,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); +#ifndef CONFIG_PRINTK_UTC_TIME len += print_process(msg, buf ? buf + len : NULL); +#endif return len; } diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index b5b4cecc8ef0..38ec15e7b08e 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -37,6 +37,13 @@ config PRINTK_PROCESS Selecting this option causes process to be included in printk output. Or add printk.process=1 at boot-time. +config PRINTK_UTC_TIME + bool "Show utc information on printks" + depends on PRINTK + help + Selecting this option causes utc to be + included in printk output. + config MESSAGE_LOGLEVEL_DEFAULT int "Default message log level (1-7)" range 1 7 -- 2.20.1