ia64/xen-unstable

changeset 12031:fd8036d06e10

[XEN] Implement log levels. It adds the thresholds and code to printk
to implement the thresholds.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
author kaf24@localhost.localdomain
date Fri Oct 27 18:52:55 2006 +0100 (2006-10-27)
parents e834d5b965d0
children 64100a77fd17
files xen/drivers/char/console.c xen/include/xen/config.h xen/include/xen/lib.h
line diff
     1.1 --- a/xen/drivers/char/console.c	Fri Oct 27 18:46:20 2006 +0100
     1.2 +++ b/xen/drivers/char/console.c	Fri Oct 27 18:52:55 2006 +0100
     1.3 @@ -58,6 +58,13 @@ static int sercon_handle = -1;
     1.4  
     1.5  static DEFINE_SPINLOCK(console_lock);
     1.6  
     1.7 +int xenlog_upper_thresh = XENLOG_UPPER_THRESHOLD;
     1.8 +int xenlog_lower_thresh = XENLOG_LOWER_THRESHOLD;
     1.9 +int xenlog_guest_upper_thresh = XENLOG_GUEST_UPPER_THRESHOLD;
    1.10 +int xenlog_guest_lower_thresh = XENLOG_GUEST_LOWER_THRESHOLD;
    1.11 +
    1.12 +static int xen_startup = 1;
    1.13 +
    1.14  /*
    1.15   * ********************************************************
    1.16   * *************** ACCESS TO CONSOLE RING *****************
    1.17 @@ -307,6 +314,10 @@ void printk(const char *fmt, ...)
    1.18      va_list       args;
    1.19      char         *p, *q;
    1.20      unsigned long flags;
    1.21 +    int           level = XENLOG_DEFAULT;
    1.22 +    int           upper_thresh = xenlog_upper_thresh;
    1.23 +    int           lower_thresh = xenlog_lower_thresh;
    1.24 +    int           print_regardless = xen_startup;
    1.25  
    1.26      spin_lock_irqsave(&console_lock, flags);
    1.27  
    1.28 @@ -315,6 +326,32 @@ void printk(const char *fmt, ...)
    1.29      va_end(args);        
    1.30  
    1.31      p = buf;
    1.32 +
    1.33 +    /* Is this print caused by a guest? */
    1.34 +    if ( strncmp("<G>", p, 3) == 0 )
    1.35 +    {
    1.36 +        upper_thresh = xenlog_guest_upper_thresh;
    1.37 +        lower_thresh = xenlog_guest_lower_thresh;
    1.38 +        level = XENLOG_GUEST_DEFAULT;
    1.39 +        p += 3;
    1.40 +    }
    1.41 +
    1.42 +    if ( (p[0] == '<') &&
    1.43 +         (p[1] >= '0') && (p[1] <= ('0' + XENLOG_MAX)) &&
    1.44 +         (p[2] == '>') )
    1.45 +    {
    1.46 +        level = p[1] - '0';
    1.47 +        p += 3;
    1.48 +    }
    1.49 +
    1.50 +    if ( !print_regardless )
    1.51 +    {
    1.52 +        if ( level > upper_thresh )
    1.53 +            goto out;
    1.54 +        if ( (level >= lower_thresh) && (!printk_ratelimit()) )
    1.55 +            goto out;
    1.56 +    }
    1.57 +
    1.58      while ( (q = strchr(p, '\n')) != NULL )
    1.59      {
    1.60          *q = '\0';
    1.61 @@ -334,6 +371,7 @@ void printk(const char *fmt, ...)
    1.62          start_of_line = 0;
    1.63      }
    1.64  
    1.65 + out:
    1.66      spin_unlock_irqrestore(&console_lock, flags);
    1.67  }
    1.68  
    1.69 @@ -419,6 +457,9 @@ void console_endboot(void)
    1.70  
    1.71      /* Serial input is directed to DOM0 by default. */
    1.72      switch_serial_input();
    1.73 +
    1.74 +    /* Now we implement the logging thresholds. */
    1.75 +    xen_startup = 0;
    1.76  }
    1.77  
    1.78  void console_force_unlock(void)
     2.1 --- a/xen/include/xen/config.h	Fri Oct 27 18:46:20 2006 +0100
     2.2 +++ b/xen/include/xen/config.h	Fri Oct 27 18:52:55 2006 +0100
     2.3 @@ -12,26 +12,119 @@
     2.4  #define EXPORT_SYMBOL(var)
     2.5  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
     2.6  
     2.7 -/* Linux syslog levels. */
     2.8 -#define KERN_NOTICE  ""
     2.9 -#define KERN_WARNING ""
    2.10 -#define KERN_DEBUG   ""
    2.11 -#define KERN_INFO    ""
    2.12 -#define KERN_ERR     ""
    2.13 -#define KERN_CRIT    ""
    2.14 -#define KERN_EMERG   ""
    2.15 -#define KERN_ALERT   ""
    2.16 +/*
    2.17 + * The following log levels are as follows:
    2.18 + *
    2.19 + *   XENLOG_ERR: Fatal errors, either Xen, Guest or Dom0
    2.20 + *               is about to crash.
    2.21 + *
    2.22 + *   XENLOG_WARNING: Something bad happened, but we can recover.
    2.23 + *
    2.24 + *   XENLOG_INFO: Interesting stuff, but not too noisy.
    2.25 + *
    2.26 + *   XENLOG_DEBUG: Use where ever you like. Lots of noise.
    2.27 + *
    2.28 + *
    2.29 + * Since we don't trust the guest operating system, we don't want
    2.30 + * it to allow for DoS by causing the HV to print out a lot of
    2.31 + * info, so where ever the guest has control of what is printed
    2.32 + * we use the XENLOG_GUEST to distinguish that the output is
    2.33 + * controled by the Guest.
    2.34 + *
    2.35 + * To make it easier on the typing, the above log levels all
    2.36 + * have a corresponding _G_ equivalent that appends the
    2.37 + * XENLOG_GUEST. (see the defines below).
    2.38 + *
    2.39 + */
    2.40 +#define XENLOG_ERR     "<0>"
    2.41 +#define XENLOG_WARNING "<1>"
    2.42 +#define XENLOG_INFO    "<2>"
    2.43 +#define XENLOG_DEBUG   "<3>"
    2.44 +
    2.45 +#define XENLOG_GUEST   "<G>"
    2.46 +
    2.47 +#define XENLOG_G_ERR     XENLOG_GUEST XENLOG_ERR
    2.48 +#define XENLOG_G_WARNING XENLOG_GUEST XENLOG_WARNING
    2.49 +#define XENLOG_G_INFO    XENLOG_GUEST XENLOG_INFO
    2.50 +#define XENLOG_G_DEBUG   XENLOG_GUEST XENLOG_DEBUG
    2.51 +
    2.52 +#define XENLOG_MAX 3
    2.53 +
    2.54 +/*
    2.55 + * To control the amount of printing, thresholds are added.
    2.56 + * These thresholds correspond to the above log levels.
    2.57 + * There's an upper and lower threshold for non-guests
    2.58 + * and Guest.  This works as follows:
    2.59 + *
    2.60 + * If printk log level > upper threshold
    2.61 + *   don't print anything
    2.62 + *
    2.63 + * If printk log level >= lower threshold
    2.64 + *   rate limit the print (keep the amount down)
    2.65 + *
    2.66 + * Otherwise, just print.
    2.67 + *
    2.68 + * Note, in the above algorithm, to never rate limit
    2.69 + * simply make the lower threshold greater than the upper.
    2.70 + * This way the output will never be rate limited.
    2.71 + *
    2.72 + * For example:
    2.73 + *   lower = 2; upper = 1;
    2.74 + *  This will always print ERR and WARNING messages
    2.75 + *  but will not print anything else.  Nothing is
    2.76 + *  rate limited.
    2.77 + */
    2.78 +/*
    2.79 + * Defaults:
    2.80 + *   For the HV, always print ERR and WARNING
    2.81 + *   but nothing for INFO and DEBUG.
    2.82 + *
    2.83 + *   For Guests, always rate limit ERR and WARNING
    2.84 + *   but never print for INFO and DEBUG.
    2.85 + */
    2.86 +#ifndef XENLOG_UPPER_THRESHOLD
    2.87 +#define XENLOG_UPPER_THRESHOLD 1
    2.88 +#endif
    2.89 +#ifndef XENLOG_LOWER_THRESHOLD
    2.90 +#define XENLOG_LOWER_THRESHOLD 2
    2.91 +#endif
    2.92 +#ifndef XENLOG_GUEST_UPPER_THRESHOLD
    2.93 +#define XENLOG_GUEST_UPPER_THRESHOLD 1
    2.94 +#endif
    2.95 +#ifndef XENLOG_GUEST_LOWER_THRESHOLD
    2.96 +#define XENLOG_GUEST_LOWER_THRESHOLD 0
    2.97 +#endif
    2.98 +
    2.99 +/*
   2.100 + * The XENLOG_DEFAULT is the default given to printks that
   2.101 + * do not have any print level associated to it.
   2.102 + */
   2.103 +#ifndef XENLOG_DEFAULT
   2.104 +#define XENLOG_DEFAULT 1 /* Warning */
   2.105 +#endif
   2.106 +#ifndef XENLOG_GUEST_DEFAULT
   2.107 +#define XENLOG_GUEST_DEFAULT 1 /* Warning */
   2.108 +#endif
   2.109 +
   2.110 +/*
   2.111 + * Some code is copied directly from Linux.
   2.112 + * Match some of the Linux log levels to Xen.
   2.113 + *  (Should these be Guest logs?? - SDR)
   2.114 + */
   2.115 +#define KERN_ERR       XENLOG_ERR
   2.116 +#define KERN_CRIT      XENLOG_ERR
   2.117 +#define KERN_EMERG     XENLOG_ERR
   2.118 +#define KERN_WARNING   XENLOG_WARNING
   2.119 +#define KERN_NOTICE    XENLOG_INFO
   2.120 +#define KERN_INFO      XENLOG_INFO
   2.121 +#define KERN_DEBUG     XENLOG_DEBUG
   2.122  
   2.123  /* Linux 'checker' project. */
   2.124  #define __iomem
   2.125  #define __user
   2.126  
   2.127 -#ifdef VERBOSE
   2.128  #define DPRINTK(_f, _a...) printk("(file=%s, line=%d) " _f, \
   2.129                             __FILE__ , __LINE__ , ## _a )
   2.130 -#else
   2.131 -#define DPRINTK(_f, _a...) ((void)0)
   2.132 -#endif
   2.133  
   2.134  #ifndef __ASSEMBLY__
   2.135  #include <xen/compiler.h>
     3.1 --- a/xen/include/xen/lib.h	Fri Oct 27 18:46:20 2006 +0100
     3.2 +++ b/xen/include/xen/lib.h	Fri Oct 27 18:52:55 2006 +0100
     3.3 @@ -58,6 +58,10 @@ extern void panic(const char *format, ..
     3.4  extern long vm_assist(struct domain *, unsigned int, unsigned int);
     3.5  extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
     3.6  extern int printk_ratelimit(void);
     3.7 +extern int xenlog_upper_thresh;
     3.8 +extern int xenlog_lower_thresh;
     3.9 +extern int xenlog_guest_upper_thresh;
    3.10 +extern int xenlog_guest_lower_thresh;
    3.11  
    3.12  /* vsprintf.c */
    3.13  extern int sprintf(char * buf, const char * fmt, ...)