From 4214832392cb94f5ccd8f3bf460fcf11427f039b Mon Sep 17 00:00:00 2001 From: Tao Huang Date: Fri, 12 Nov 2021 11:05:18 +0800 Subject: [PATCH] printk: Introduce CONFIG_PRINTK_TIME_FROM_ARM_ARCH_TIMER Some examples for console output: Starting kernel ... [ 1.956071][ T0] Booting Linux on physical CPU 0x0000000000 [0x412fd050] Change-Id: I0ab5914349ad3e0028954c831c5e79d46fe2d420 Signed-off-by: Tao Huang --- kernel/printk/printk.c | 20 +++++++++++++++++++- lib/Kconfig.debug | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index de278ccc3940..6db82cd7fdaf 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -63,6 +63,24 @@ #include "braille.h" #include "internal.h" +#ifdef CONFIG_PRINTK_TIME_FROM_ARM_ARCH_TIMER +#include +static u64 get_local_clock(void) +{ + u64 ns; + + ns = arch_timer_read_counter() * 1000; + do_div(ns, 24); + + return ns; +} +#else +static inline u64 get_local_clock(void) +{ + return local_clock(); +} +#endif + int console_printk[4] = { CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */ MESSAGE_LOGLEVEL_DEFAULT, /* default_message_loglevel */ @@ -528,7 +546,7 @@ static int log_store(u32 caller_id, int facility, int level, if (ts_nsec > 0) r.info->ts_nsec = ts_nsec; else - r.info->ts_nsec = local_clock(); + r.info->ts_nsec = get_local_clock(); r.info->caller_id = caller_id; if (dev_info) memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info)); diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 3f4a695edd0d..19d31d3f859e 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -18,6 +18,10 @@ 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_TIME_FROM_ARM_ARCH_TIMER + bool "Timing from ARM architected timer" + depends on PRINTK_TIME && ARM_ARCH_TIMER && NO_GKI + config PRINTK_CALLER bool "Show caller information on printks" depends on PRINTK