From 7ee27216bf039c6de27748903bff9511bdd4b067 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Thu, 4 Oct 2007 17:58:16 +0100 Subject: [PATCH] xen: Changes to printk handling: 1. Command-line option 'console_timestamps' adds a timestamp prefix to each line of Xen console output (x86 only, after CMOS has been interrogated). 2. Clean up prefix handling and vanity banner info. Signed-off-by: Keir Fraser --- xen/arch/ia64/xen/xensetup.c | 1 - xen/arch/x86/time.c | 12 +++++++++ xen/drivers/char/console.c | 46 ++++++++++++++++++++++------------ xen/include/asm-ia64/time.h | 7 ++++++ xen/include/asm-powerpc/time.h | 3 +++ xen/include/asm-x86/time.h | 3 +++ xen/include/xen/console.h | 2 -- 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/xen/arch/ia64/xen/xensetup.c b/xen/arch/ia64/xen/xensetup.c index a9ea832c5e..af6598317e 100644 --- a/xen/arch/ia64/xen/xensetup.c +++ b/xen/arch/ia64/xen/xensetup.c @@ -315,7 +315,6 @@ void __init start_kernel(void) #endif init_console(); - set_printk_prefix("(XEN) "); if (running_on_sim || ia64_boot_param->domain_start == 0 || ia64_boot_param->domain_size == 0) { diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c index d0f45fb018..b00ee01aa3 100644 --- a/xen/arch/x86/time.c +++ b/xen/arch/x86/time.c @@ -1038,6 +1038,18 @@ int dom0_pit_access(struct ioreq *ioreq) return 0; } +struct tm wallclock_time(void) +{ + uint64_t seconds; + + if ( !wc_sec ) + return (struct tm) { 0 }; + + seconds = NOW() + (wc_sec * 1000000000ull) + wc_nsec; + do_div(seconds, 1000000000); + return gmtime(seconds); +} + /* * Local variables: * mode: C diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index e4acd802b4..e47225e707 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -53,13 +53,15 @@ boolean_param("sync_console", opt_sync_console); static int opt_console_to_ring; boolean_param("console_to_ring", opt_console_to_ring); +/* console_timestamps: include a timestamp prefix on every Xen console line. */ +static int opt_console_timestamps; +boolean_param("console_timestamps", opt_console_timestamps); + #define CONRING_SIZE 16384 #define CONRING_IDX_MASK(i) ((i)&(CONRING_SIZE-1)) static char conring[CONRING_SIZE]; static unsigned int conringc, conringp; -static char printk_prefix[16] = ""; - static int sercon_handle = -1; static DEFINE_SPINLOCK(console_lock); @@ -448,6 +450,26 @@ static int printk_prefix_check(char *p, char **pp) ((loglvl < upper_thresh) && printk_ratelimit())); } +static void printk_start_of_line(void) +{ + struct tm tm; + char tstr[32]; + + __putstr("(XEN) "); + + if ( !opt_console_timestamps ) + return; + + tm = wallclock_time(); + if ( tm.tm_mday == 0 ) + return; + + snprintf(tstr, sizeof(tstr), "[%04u-%02u-%02u %02u:%02u:%02u] ", + 1900 + tm.tm_year, tm.tm_mon, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); + __putstr(tstr); +} + void printk(const char *fmt, ...) { static char buf[1024]; @@ -475,7 +497,7 @@ void printk(const char *fmt, ...) if ( do_print ) { if ( start_of_line ) - __putstr(printk_prefix); + printk_start_of_line(); __putstr(p); __putstr("\n"); } @@ -490,7 +512,7 @@ void printk(const char *fmt, ...) if ( do_print ) { if ( start_of_line ) - __putstr(printk_prefix); + printk_start_of_line(); __putstr(p); } start_of_line = 0; @@ -500,11 +522,6 @@ void printk(const char *fmt, ...) local_irq_restore(flags); } -void set_printk_prefix(const char *prefix) -{ - safe_strcpy(printk_prefix, prefix); -} - void __init init_console(void) { char *p; @@ -523,15 +540,12 @@ void __init init_console(void) serial_set_rx_handler(sercon_handle, serial_rx); /* HELLO WORLD --- start-of-day banner text. */ - printk(xen_banner()); - printk(" http://www.cl.cam.ac.uk/netos/xen\n"); - printk(" University of Cambridge Computer Laboratory\n\n"); - printk(" Xen version %d.%d%s (%s@%s) (%s) %s\n", + __putstr(xen_banner()); + printk("Xen version %d.%d%s (%s@%s) (%s) %s\n", xen_major_version(), xen_minor_version(), xen_extra_version(), xen_compile_by(), xen_compile_domain(), xen_compiler(), xen_compile_date()); - printk(" Latest ChangeSet: %s\n\n", xen_changeset()); - set_printk_prefix("(XEN) "); + printk("Latest ChangeSet: %s\n", xen_changeset()); if ( opt_sync_console ) { @@ -687,7 +701,7 @@ int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst) snprintf(lost_str, sizeof(lost_str), "%d", lost); /* console_lock may already be acquired by printk(). */ spin_lock_recursive(&console_lock); - __putstr(printk_prefix); + printk_start_of_line(); __putstr("printk: "); __putstr(lost_str); __putstr(" messages suppressed.\n"); diff --git a/xen/include/asm-ia64/time.h b/xen/include/asm-ia64/time.h index c55fb1fbc4..145af36238 100644 --- a/xen/include/asm-ia64/time.h +++ b/xen/include/asm-ia64/time.h @@ -1,2 +1,9 @@ +#ifndef _ASM_TIME_H_ +#define _ASM_TIME_H_ + #include #include + +#define wallclock_time() ((struct tm) { 0 }) + +#endif /* _ASM_TIME_H_ */ diff --git a/xen/include/asm-powerpc/time.h b/xen/include/asm-powerpc/time.h index 239d93f357..8d8be263ef 100644 --- a/xen/include/asm-powerpc/time.h +++ b/xen/include/asm-powerpc/time.h @@ -80,4 +80,7 @@ static inline u64 tb_to_ns(u64 tb) { return tb * (__nano(1) / timebase_freq); } + +#define wallclock_time() ((struct tm) { 0 }) + #endif diff --git a/xen/include/asm-x86/time.h b/xen/include/asm-x86/time.h index 23cbbf2b79..3ad0b0041e 100644 --- a/xen/include/asm-x86/time.h +++ b/xen/include/asm-x86/time.h @@ -31,4 +31,7 @@ int dom0_pit_access(struct ioreq *ioreq); int cpu_frequency_change(u64 freq); +struct tm; +struct tm wallclock_time(void); + #endif /* __X86_TIME_H__ */ diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 7c786ab5df..bb5fe07e93 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -11,8 +11,6 @@ #include #include -void set_printk_prefix(const char *prefix); - long read_console_ring(XEN_GUEST_HANDLE(char), u32 *, int); void init_console(void); -- 2.39.5