]> xenbits.xensource.com Git - xen.git/commitdiff
xen: Changes to printk handling:
authorKeir Fraser <keir@xensource.com>
Thu, 4 Oct 2007 16:58:16 +0000 (17:58 +0100)
committerKeir Fraser <keir@xensource.com>
Thu, 4 Oct 2007 16:58:16 +0000 (17:58 +0100)
 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 <keir@xensource.com>
xen/arch/ia64/xen/xensetup.c
xen/arch/x86/time.c
xen/drivers/char/console.c
xen/include/asm-ia64/time.h
xen/include/asm-powerpc/time.h
xen/include/asm-x86/time.h
xen/include/xen/console.h

index a9ea832c5e75afecd9c6d442fa382daba155d664..af6598317e335d872c43ac8b0109123abf7e1c9e 100644 (file)
@@ -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) {
index d0f45fb0184e669c8ccd2cf0d0eaad7fcc996dcf..b00ee01aa3227a8de37310320d8a1d752fa57ef1 100644 (file)
@@ -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
index e4acd802b43923147b8c7ab735e9cf9545046ab7..e47225e7078514385fa0e9a409c0df1a1d620a73 100644 (file)
@@ -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");
index c55fb1fbc43e7f874a4d1b0ef9504c1d22964715..145af362382fc18f22d0f837ea576a244dfd8726 100644 (file)
@@ -1,2 +1,9 @@
+#ifndef _ASM_TIME_H_
+#define _ASM_TIME_H_
+
 #include <asm/linux/time.h>
 #include <asm/timex.h>
+
+#define wallclock_time() ((struct tm) { 0 })
+
+#endif /* _ASM_TIME_H_ */
index 239d93f357cbc0501f2d1d2d5d428a7346aa3fd5..8d8be263ef46955636063b8591deb8f45b841bf7 100644 (file)
@@ -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
index 23cbbf2b793d77575284099fec2dea895aaeb108..3ad0b0041efbeb763196392fc1c1d3f9e4cea2d9 100644 (file)
@@ -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__ */
index 7c786ab5df9328311cb26b3729449fa57f03bb1f..bb5fe07e937f9a8d7337fd1d84f6657598799004 100644 (file)
@@ -11,8 +11,6 @@
 #include <xen/guest_access.h>
 #include <public/xen.h>
 
-void set_printk_prefix(const char *prefix);
-
 long read_console_ring(XEN_GUEST_HANDLE(char), u32 *, int);
 
 void init_console(void);