direct-io.hg

changeset 12225:fac36a01c06e

[XEN] Fix log-level printk logic for multi-line and partial-line printks.
Add support for switching to print-all mode, and use this for
debug-key output.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Nov 03 11:15:10 2006 +0000 (2006-11-03)
parents cfb1136ee8f7
children 2b36aeb896c6 2e8c68b0c973
files xen/common/keyhandler.c xen/drivers/char/console.c xen/include/xen/console.h
line diff
     1.1 --- a/xen/common/keyhandler.c	Fri Nov 03 10:52:29 2006 +0000
     1.2 +++ b/xen/common/keyhandler.c	Fri Nov 03 11:15:10 2006 +0000
     1.3 @@ -36,8 +36,10 @@ static void keypress_softirq(void)
     1.4  {
     1.5      keyhandler_t *h;
     1.6      unsigned char key = keypress_key;
     1.7 +    console_start_log_everything();
     1.8      if ( (h = key_table[key].u.handler) != NULL )
     1.9          (*h)(key);
    1.10 +    console_end_log_everything();
    1.11  }
    1.12  
    1.13  void handle_keypress(unsigned char key, struct cpu_user_regs *regs)
    1.14 @@ -46,8 +48,10 @@ void handle_keypress(unsigned char key, 
    1.15  
    1.16      if ( key_table[key].flags & KEYHANDLER_IRQ_CALLBACK )
    1.17      {
    1.18 +        console_start_log_everything();
    1.19          if ( (h = key_table[key].u.irq_handler) != NULL )
    1.20              (*h)(key, regs);
    1.21 +        console_end_log_everything();
    1.22      }
    1.23      else
    1.24      {
     2.1 --- a/xen/drivers/char/console.c	Fri Nov 03 10:52:29 2006 +0000
     2.2 +++ b/xen/drivers/char/console.c	Fri Nov 03 11:15:10 2006 +0000
     2.3 @@ -101,7 +101,7 @@ static void parse_guest_loglvl(char *s);
     2.4  custom_param("loglvl", parse_loglvl);
     2.5  custom_param("guest_loglvl", parse_guest_loglvl);
     2.6  
     2.7 -static int xen_startup = 1;
     2.8 +static atomic_t print_everything = ATOMIC_INIT(1);
     2.9  
    2.10  #define ___parse_loglvl(s, ps, lvlstr, lvlnum)          \
    2.11      if ( !strncmp((s), (lvlstr), strlen(lvlstr)) ) {    \
    2.12 @@ -380,7 +380,7 @@ long do_console_io(int cmd, int count, X
    2.13   * *****************************************************
    2.14   */
    2.15  
    2.16 -static inline void __putstr(const char *str)
    2.17 +static void __putstr(const char *str)
    2.18  {
    2.19      int c;
    2.20  
    2.21 @@ -393,18 +393,47 @@ static inline void __putstr(const char *
    2.22      }
    2.23  }
    2.24  
    2.25 +static int printk_prefix_check(char *p, char **pp)
    2.26 +{
    2.27 +    int loglvl = -1;
    2.28 +    int upper_thresh = xenlog_upper_thresh;
    2.29 +    int lower_thresh = xenlog_lower_thresh;
    2.30 +
    2.31 +    while ( (p[0] == '<') && (p[1] != '\0') && (p[2] == '>') )
    2.32 +    {
    2.33 +        switch ( p[1] )
    2.34 +        {
    2.35 +        case 'G':
    2.36 +            upper_thresh = xenlog_guest_upper_thresh;
    2.37 +            lower_thresh = xenlog_guest_lower_thresh;
    2.38 +            if ( loglvl == -1 )
    2.39 +                loglvl = XENLOG_GUEST_DEFAULT;
    2.40 +            break;
    2.41 +        case '0' ... '3':
    2.42 +            loglvl = p[1] - '0';
    2.43 +            break;
    2.44 +        }
    2.45 +        p += 3;
    2.46 +    }
    2.47 +
    2.48 +    if ( loglvl == -1 )
    2.49 +        loglvl = XENLOG_DEFAULT;
    2.50 +
    2.51 +    *pp = p;
    2.52 +
    2.53 +    return ((atomic_read(&print_everything) != 0) ||
    2.54 +            (loglvl < lower_thresh) ||
    2.55 +            ((loglvl < upper_thresh) && printk_ratelimit()));
    2.56 +} 
    2.57 +
    2.58  void printk(const char *fmt, ...)
    2.59  {
    2.60      static char   buf[1024];
    2.61 -    static int    start_of_line = 1;
    2.62 +    static int    start_of_line = 1, do_print;
    2.63  
    2.64      va_list       args;
    2.65      char         *p, *q;
    2.66      unsigned long flags;
    2.67 -    int           level = -1;
    2.68 -    int           upper_thresh = xenlog_upper_thresh;
    2.69 -    int           lower_thresh = xenlog_lower_thresh;
    2.70 -    int           print_regardless = xen_startup;
    2.71  
    2.72      /* console_lock can be acquired recursively from __printk_ratelimit(). */
    2.73      local_irq_save(flags);
    2.74 @@ -416,41 +445,18 @@ void printk(const char *fmt, ...)
    2.75  
    2.76      p = buf;
    2.77  
    2.78 -    while ( (p[0] == '<') && (p[1] != '\0') && (p[2] == '>') )
    2.79 -    {
    2.80 -        switch ( p[1] )
    2.81 -        {
    2.82 -        case 'G':
    2.83 -            upper_thresh = xenlog_guest_upper_thresh;
    2.84 -            lower_thresh = xenlog_guest_lower_thresh;
    2.85 -            if ( level == -1 )
    2.86 -                level = XENLOG_GUEST_DEFAULT;
    2.87 -            break;
    2.88 -        case '0' ... '3':
    2.89 -            level = p[1] - '0';
    2.90 -            break;
    2.91 -        }
    2.92 -        p += 3;
    2.93 -    }
    2.94 -
    2.95 -    if ( level == -1 )
    2.96 -        level = XENLOG_DEFAULT;
    2.97 -
    2.98 -    if ( !print_regardless )
    2.99 -    {
   2.100 -        if ( level >= upper_thresh )
   2.101 -            goto out;
   2.102 -        if ( (level >= lower_thresh) && (!printk_ratelimit()) )
   2.103 -            goto out;
   2.104 -    }
   2.105 -
   2.106      while ( (q = strchr(p, '\n')) != NULL )
   2.107      {
   2.108          *q = '\0';
   2.109          if ( start_of_line )
   2.110 -            __putstr(printk_prefix);
   2.111 -        __putstr(p);
   2.112 -        __putstr("\n");
   2.113 +            do_print = printk_prefix_check(p, &p);
   2.114 +        if ( do_print )
   2.115 +        {
   2.116 +            if ( start_of_line )
   2.117 +                __putstr(printk_prefix);
   2.118 +            __putstr(p);
   2.119 +            __putstr("\n");
   2.120 +        }
   2.121          start_of_line = 1;
   2.122          p = q + 1;
   2.123      }
   2.124 @@ -458,12 +464,16 @@ void printk(const char *fmt, ...)
   2.125      if ( *p != '\0' )
   2.126      {
   2.127          if ( start_of_line )
   2.128 -            __putstr(printk_prefix);
   2.129 -        __putstr(p);
   2.130 +            do_print = printk_prefix_check(p, &p);
   2.131 +        if ( do_print )
   2.132 +        {
   2.133 +            if ( start_of_line )
   2.134 +                __putstr(printk_prefix);
   2.135 +            __putstr(p);
   2.136 +        }
   2.137          start_of_line = 0;
   2.138      }
   2.139  
   2.140 - out:
   2.141      spin_unlock_recursive(&console_lock);
   2.142      local_irq_restore(flags);
   2.143  }
   2.144 @@ -524,7 +534,7 @@ void console_endboot(void)
   2.145      if ( opt_sync_console )
   2.146      {
   2.147          printk("**********************************************\n");
   2.148 -        printk("******* WARNING: CONSOLE OUTPUT IS SYCHRONOUS\n");
   2.149 +        printk("******* WARNING: CONSOLE OUTPUT IS SYNCHRONOUS\n");
   2.150          printk("******* This option is intended to aid debugging "
   2.151                 "of Xen by ensuring\n");
   2.152          printk("******* that all output is synchronously delivered "
   2.153 @@ -560,7 +570,17 @@ void console_endboot(void)
   2.154      switch_serial_input();
   2.155  
   2.156      /* Now we implement the logging thresholds. */
   2.157 -    xen_startup = 0;
   2.158 +    console_end_log_everything();
   2.159 +}
   2.160 +
   2.161 +void console_start_log_everything(void)
   2.162 +{
   2.163 +    atomic_inc(&print_everything);
   2.164 +}
   2.165 +
   2.166 +void console_end_log_everything(void)
   2.167 +{
   2.168 +    atomic_dec(&print_everything);
   2.169  }
   2.170  
   2.171  void console_force_unlock(void)
   2.172 @@ -577,12 +597,14 @@ void console_force_lock(void)
   2.173  
   2.174  void console_start_sync(void)
   2.175  {
   2.176 +    console_start_log_everything();
   2.177      serial_start_sync(sercon_handle);
   2.178  }
   2.179  
   2.180  void console_end_sync(void)
   2.181  {
   2.182      serial_end_sync(sercon_handle);
   2.183 +    console_end_log_everything();
   2.184  }
   2.185  
   2.186  void console_putc(char c)
   2.187 @@ -701,9 +723,10 @@ static void debugtrace_toggle(void)
   2.188      watchdog_disable();
   2.189      spin_lock_irqsave(&debugtrace_lock, flags);
   2.190  
   2.191 -    // dump the buffer *before* toggling, in case the act of dumping the
   2.192 -    // buffer itself causes more printk's...
   2.193 -    //
   2.194 +    /*
   2.195 +     * Dump the buffer *before* toggling, in case the act of dumping the
   2.196 +     * buffer itself causes more printk() invocations.
   2.197 +     */
   2.198      printk("debugtrace_printk now writing to %s.\n",
   2.199             !debugtrace_send_to_console ? "console": "buffer");
   2.200      if ( !debugtrace_send_to_console )
     3.1 --- a/xen/include/xen/console.h	Fri Nov 03 10:52:29 2006 +0000
     3.2 +++ b/xen/include/xen/console.h	Fri Nov 03 11:15:10 2006 +0000
     3.3 @@ -26,6 +26,9 @@ void console_force_lock(void);
     3.4  void console_start_sync(void);
     3.5  void console_end_sync(void);
     3.6  
     3.7 +void console_start_log_everything(void);
     3.8 +void console_end_log_everything(void);
     3.9 +
    3.10  /*
    3.11   * Steal output from the console. Returns +ve identifier, else -ve error.
    3.12   * Takes the handle of the serial line to steal, and steal callback function.