ia64/xen-unstable

changeset 663:355a3d7a2a84

bitkeeper revision 1.378 (3f27c2beWNYX6OSWHkL7l2xJ5Qm9ng)

perfc_defn.h, perfc.h, lib.h, vsprintf.c, perfc.c:
Cleaned up Xen performance counter mechanism.
author kaf24@scramble.cl.cam.ac.uk
date Wed Jul 30 13:06:06 2003 +0000 (2003-07-30)
parents 4eedf9e718d3
children 8772d7598f1e
files xen/common/perfc.c xen/common/vsprintf.c xen/include/xeno/lib.h xen/include/xeno/perfc.h xen/include/xeno/perfc_defn.h
line diff
     1.1 --- a/xen/common/perfc.c	Mon Jul 28 13:22:08 2003 +0000
     1.2 +++ b/xen/common/perfc.c	Wed Jul 30 13:06:06 2003 +0000
     1.3 @@ -1,6 +1,3 @@
     1.4 -/*
     1.5 - * xen performance counters
     1.6 - */
     1.7  
     1.8  #include <xeno/lib.h>
     1.9  #include <xeno/smp.h>
    1.10 @@ -8,111 +5,63 @@
    1.11  #include <xeno/perfc.h>
    1.12  #include <xeno/keyhandler.h> 
    1.13  
    1.14 -/* used for different purposes in perfc.h and here */
    1.15 -#undef PERFCOUNTER
    1.16 -#undef PERFCOUNTER_CPU
    1.17 -#undef PERFCOUNTER_ARRAY
    1.18 -
    1.19 -#define PERFCOUNTER( var, name ) "[0]"name"\0",
    1.20 -#define PERFCOUNTER_CPU( var, name )  "C"name"\0",
    1.21 -#define PERFCOUNTER_ARRAY( var, name, size )  "["#size"]"name"\0",
    1.22 -
    1.23 -char* perfc_name[] = {
    1.24 +#undef  PERFCOUNTER
    1.25 +#undef  PERFCOUNTER_CPU
    1.26 +#undef  PERFCOUNTER_ARRAY
    1.27 +#define PERFCOUNTER( var, name )              { name, TYPE_SINGLE, 0 },
    1.28 +#define PERFCOUNTER_CPU( var, name )          { name, TYPE_CPU,    0 },
    1.29 +#define PERFCOUNTER_ARRAY( var, name, size )  { name, TYPE_ARRAY,  size },
    1.30 +static struct {
    1.31 +    char *name;
    1.32 +    enum { TYPE_SINGLE, TYPE_CPU, TYPE_ARRAY } type;
    1.33 +    int nr_elements;
    1.34 +} perfc_info[] = {
    1.35  #include <xeno/perfc_defn.h>
    1.36  };
    1.37  
    1.38 +#define NR_PERFCTRS (sizeof(perfc_info) / sizeof(perfc_info[0]))
    1.39 +
    1.40  struct perfcounter_t perfcounters;
    1.41  
    1.42 -void __perfc_print (unsigned long counter[], int offset)
    1.43 +void perfc_printall(u_char key, void *dev_id, struct pt_regs *regs)
    1.44  {
    1.45 -  int loop;
    1.46 -  int total_size = 0;
    1.47 -  int element_size = 0;
    1.48 -  int cpus = 0;
    1.49 -  int num = 0;
    1.50 -
    1.51 -  for (loop = 0; loop < sizeof(perfc_name) / sizeof(char *); loop++) {
    1.52 -      if (perfc_name[loop][0] == 'C') {
    1.53 -          element_size = NR_CPUS;
    1.54 -          cpus = 1;
    1.55 -      } else {
    1.56 -          num = sscanf (perfc_name[loop], "[%d]", &element_size);
    1.57 -      }
    1.58 -
    1.59 -      total_size += element_size == 0 ? 1 : element_size;
    1.60 -      if (total_size > offset) break;
    1.61 -  }
    1.62 -  if (loop == sizeof(perfc_name) / sizeof(char *)) {
    1.63 -      printf ("error: couldn't find variable\n"); 
    1.64 -      return;
    1.65 -  }
    1.66 -  if (element_size == 0) {                              /* single counter */
    1.67 -      printf ("%10lu  0x%08lx  %s\n", counter[0], counter[0],
    1.68 -              perfc_name[loop] + 2 + num);
    1.69 -  } else if (cpus) {                                    /* counter per CPU  */
    1.70 -      for (loop = 0; loop < smp_num_cpus; loop++) {
    1.71 -          printf ("%10lu  0x%08lx  cpu[%02d] %s\n", 
    1.72 -                  counter[loop], counter[loop], 
    1.73 -                  loop, perfc_name[loop]);
    1.74 -      }
    1.75 -      
    1.76 -  } else {                                             /* show entire array */
    1.77 -      for (loop = 0; loop < element_size; loop++) {
    1.78 -          printf ("%10lu  0x%08lx  %s:%d\n", 
    1.79 -                  counter[loop], counter[loop], 
    1.80 -                  perfc_name[loop] + 2 + num, loop);
    1.81 -      }
    1.82 -  }
    1.83 -  return;
    1.84 -}
    1.85 -
    1.86 -void perfc_printall (u_char key, void *dev_id, struct pt_regs *regs)
    1.87 -{
    1.88 -    int loop, idx;
    1.89 -    int element_size;
    1.90 -    int cpus=0;
    1.91 -    int num = 0;
    1.92 +    int i, j;
    1.93      s_time_t now = NOW();
    1.94      unsigned long *counters = (unsigned long *)&perfcounters;
    1.95  
    1.96 -    printf ("xen performance counters: now=0x%08X%08X\n",
    1.97 -            (u32)(now>>32), (u32)now);
    1.98 -
    1.99 -    for (loop = 0; loop < sizeof(perfc_name) / sizeof(char *); loop++) {
   1.100 +    printk("Xen performance counters SHOW  (now = 0x%08X:%08X)\n",
   1.101 +           (u32)(now>>32), (u32)now);
   1.102  
   1.103 -        if (perfc_name[loop][0] == 'C') {
   1.104 -            element_size = NR_CPUS;
   1.105 -            cpus = 1;
   1.106 -        } else {
   1.107 -            num = sscanf (perfc_name[loop], "[%d]", &element_size);
   1.108 -        }
   1.109 -    
   1.110 -        for (idx = 0; idx < (element_size ? element_size : 1); idx++) {
   1.111 -            if (cpus) {
   1.112 -                if (idx < smp_num_cpus)
   1.113 -                    printf ("%10ld  0x%08lx  cpu[%02d] %s\n", 
   1.114 -                            *counters, *counters, idx, perfc_name[loop] + 1);
   1.115 -            } else if (element_size) {
   1.116 -                printf ("%10ld  0x%08lx  %s:%d\n", 
   1.117 -                        *counters, *counters, perfc_name[loop] + num + 2, idx);
   1.118 -            } else {
   1.119 -                printf ("%10ld  0x%08lx  %s\n", 
   1.120 -                        *counters, *counters, perfc_name[loop] + num + 2);
   1.121 -            }
   1.122 -            counters++;
   1.123 +    for ( i = 0; i < NR_PERFCTRS; i++ ) 
   1.124 +    {
   1.125 +        switch ( perfc_info[i].type )
   1.126 +        {
   1.127 +        case TYPE_SINGLE:
   1.128 +            printk("%10ld  0x%08lx  %s\n", 
   1.129 +                   counters[0], counters[0], perfc_info[i].name);
   1.130 +            counters += 1;
   1.131 +            break;
   1.132 +        case TYPE_CPU:
   1.133 +            for ( j = 0; j < smp_num_cpus; j++ )
   1.134 +                printk("%10ld  0x%08lx  %s[CPU %02d]\n",
   1.135 +                       counters[j], counters[j], perfc_info[i].name, j);
   1.136 +            counters += j;
   1.137 +            break;
   1.138 +        case TYPE_ARRAY:
   1.139 +            for ( j = 0; j < perfc_info[i].nr_elements; j++ )
   1.140 +                printk("%10ld  0x%08lx  %s[ARR %02d]\n",
   1.141 +                       counters[j], counters[j], perfc_info[i].name, j);
   1.142 +            counters += j;
   1.143 +            break;
   1.144          }
   1.145      }
   1.146 -
   1.147 -    //perfc_reset( key, dev_id, regs );
   1.148 -
   1.149 -    return;
   1.150  }
   1.151  
   1.152 -void perfc_reset (u_char key, void *dev_id, struct pt_regs *regs)
   1.153 +void perfc_reset(u_char key, void *dev_id, struct pt_regs *regs)
   1.154  {
   1.155      s_time_t now = NOW();
   1.156 -    printk ("xen performance counters reset: now=0x%08X%08X\n",
   1.157 -            (u32)(now>>32), (u32)now);
   1.158 -    memset (&perfcounters, 0, sizeof(perfcounters));
   1.159 +    printk("Xen performance counters RESET (now = 0x%08X:%08X)\n",
   1.160 +           (u32)(now>>32), (u32)now);
   1.161 +    memset(&perfcounters, 0, sizeof(perfcounters));
   1.162  }
   1.163  
     2.1 --- a/xen/common/vsprintf.c	Mon Jul 28 13:22:08 2003 +0000
     2.2 +++ b/xen/common/vsprintf.c	Wed Jul 30 13:06:06 2003 +0000
     2.3 @@ -509,205 +509,3 @@ int sprintf(char * buf, const char *fmt,
     2.4      return i;
     2.5  }
     2.6  
     2.7 -/**
     2.8 - * vsscanf - Unformat a buffer into a list of arguments
     2.9 - * @buf:	input buffer
    2.10 - * @fmt:	format of buffer
    2.11 - * @args:	arguments
    2.12 - */
    2.13 -int vsscanf(const char * buf, const char * fmt, va_list args)
    2.14 -{
    2.15 -    const char *str = buf;
    2.16 -    char *next;
    2.17 -    int num = 0;
    2.18 -    int qualifier;
    2.19 -    int base;
    2.20 -    int field_width = -1;
    2.21 -    int is_sign = 0;
    2.22 -
    2.23 -    while(*fmt && *str) {
    2.24 -        /* skip any white space in format */
    2.25 -        /* white space in format matchs any amount of
    2.26 -         * white space, including none, in the input.
    2.27 -         */
    2.28 -        if (isspace(*fmt)) {
    2.29 -            while (isspace(*fmt))
    2.30 -                ++fmt;
    2.31 -            while (isspace(*str))
    2.32 -                ++str;
    2.33 -        }
    2.34 -
    2.35 -        /* anything that is not a conversion must match exactly */
    2.36 -        if (*fmt != '%' && *fmt) {
    2.37 -            if (*fmt++ != *str++)
    2.38 -                break;
    2.39 -            continue;
    2.40 -        }
    2.41 -
    2.42 -        if (!*fmt)
    2.43 -            break;
    2.44 -        ++fmt;
    2.45 -		
    2.46 -        /* skip this conversion.
    2.47 -         * advance both strings to next white space
    2.48 -         */
    2.49 -        if (*fmt == '*') {
    2.50 -            while (!isspace(*fmt) && *fmt)
    2.51 -                fmt++;
    2.52 -            while (!isspace(*str) && *str)
    2.53 -                str++;
    2.54 -            continue;
    2.55 -        }
    2.56 -
    2.57 -        /* get field width */
    2.58 -        if (isdigit(*fmt))
    2.59 -            field_width = skip_atoi(&fmt);
    2.60 -
    2.61 -        /* get conversion qualifier */
    2.62 -        qualifier = -1;
    2.63 -        if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'Z') {
    2.64 -            qualifier = *fmt;
    2.65 -            fmt++;
    2.66 -        }
    2.67 -        base = 10;
    2.68 -        is_sign = 0;
    2.69 -
    2.70 -        if (!*fmt || !*str)
    2.71 -            break;
    2.72 -
    2.73 -        switch(*fmt++) {
    2.74 -        case 'c':
    2.75 -        {
    2.76 -            char *s = (char *) va_arg(args,char*);
    2.77 -            if (field_width == -1)
    2.78 -                field_width = 1;
    2.79 -            do {
    2.80 -                *s++ = *str++;
    2.81 -            } while(field_width-- > 0 && *str);
    2.82 -            num++;
    2.83 -        }
    2.84 -        continue;
    2.85 -        case 's':
    2.86 -        {
    2.87 -            char *s = (char *) va_arg(args, char *);
    2.88 -            if(field_width == -1)
    2.89 -                field_width = INT_MAX;
    2.90 -            /* first, skip leading white space in buffer */
    2.91 -            while (isspace(*str))
    2.92 -                str++;
    2.93 -
    2.94 -            /* now copy until next white space */
    2.95 -            while (*str && !isspace(*str) && field_width--) {
    2.96 -                *s++ = *str++;
    2.97 -            }
    2.98 -            *s = '\0';
    2.99 -            num++;
   2.100 -        }
   2.101 -        continue;
   2.102 -        case 'n':
   2.103 -            /* return number of characters read so far */
   2.104 -        {
   2.105 -            int *i = (int *)va_arg(args,int*);
   2.106 -            *i = str - buf;
   2.107 -        }
   2.108 -        continue;
   2.109 -        case 'o':
   2.110 -            base = 8;
   2.111 -            break;
   2.112 -        case 'x':
   2.113 -        case 'X':
   2.114 -            base = 16;
   2.115 -            break;
   2.116 -        case 'd':
   2.117 -        case 'i':
   2.118 -            is_sign = 1;
   2.119 -        case 'u':
   2.120 -            break;
   2.121 -        case '%':
   2.122 -            /* looking for '%' in str */
   2.123 -            if (*str++ != '%') 
   2.124 -                return num;
   2.125 -            continue;
   2.126 -        default:
   2.127 -            /* invalid format; stop here */
   2.128 -            return num;
   2.129 -        }
   2.130 -
   2.131 -        /* have some sort of integer conversion.
   2.132 -         * first, skip white space in buffer.
   2.133 -         */
   2.134 -        while (isspace(*str))
   2.135 -            str++;
   2.136 -
   2.137 -        if (!*str || !isdigit(*str))
   2.138 -            break;
   2.139 -
   2.140 -        switch(qualifier) {
   2.141 -        case 'h':
   2.142 -            if (is_sign) {
   2.143 -                short *s = (short *) va_arg(args,short *);
   2.144 -                *s = (short) simple_strtol(str,&next,base);
   2.145 -            } else {
   2.146 -                unsigned short *s = (unsigned short *) va_arg(args, unsigned short *);
   2.147 -                *s = (unsigned short) simple_strtoul(str, &next, base);
   2.148 -            }
   2.149 -            break;
   2.150 -        case 'l':
   2.151 -            if (is_sign) {
   2.152 -                long *l = (long *) va_arg(args,long *);
   2.153 -                *l = simple_strtol(str,&next,base);
   2.154 -            } else {
   2.155 -                unsigned long *l = (unsigned long*) va_arg(args,unsigned long*);
   2.156 -                *l = simple_strtoul(str,&next,base);
   2.157 -            }
   2.158 -            break;
   2.159 -        case 'L':
   2.160 -            if (is_sign) {
   2.161 -                long long *l = (long long*) va_arg(args,long long *);
   2.162 -                *l = simple_strtoll(str,&next,base);
   2.163 -            } else {
   2.164 -                unsigned long long *l = (unsigned long long*) va_arg(args,unsigned long long*);
   2.165 -                *l = simple_strtoull(str,&next,base);
   2.166 -            }
   2.167 -            break;
   2.168 -        case 'Z':
   2.169 -        {
   2.170 -            size_t *s = (size_t*) va_arg(args,size_t*);
   2.171 -            *s = (size_t) simple_strtoul(str,&next,base);
   2.172 -        }
   2.173 -        break;
   2.174 -        default:
   2.175 -            if (is_sign) {
   2.176 -                int *i = (int *) va_arg(args, int*);
   2.177 -                *i = (int) simple_strtol(str,&next,base);
   2.178 -            } else {
   2.179 -                unsigned int *i = (unsigned int*) va_arg(args, unsigned int*);
   2.180 -                *i = (unsigned int) simple_strtoul(str,&next,base);
   2.181 -            }
   2.182 -            break;
   2.183 -        }
   2.184 -        num++;
   2.185 -
   2.186 -        if (!next)
   2.187 -            break;
   2.188 -        str = next;
   2.189 -    }
   2.190 -    return num;
   2.191 -}
   2.192 -
   2.193 -/**
   2.194 - * sscanf - Unformat a buffer into a list of arguments
   2.195 - * @buf:	input buffer
   2.196 - * @fmt:	formatting of buffer
   2.197 - * @...:	resulting arguments
   2.198 - */
   2.199 -int sscanf(const char * buf, const char * fmt, ...)
   2.200 -{
   2.201 -    va_list args;
   2.202 -    int i;
   2.203 -
   2.204 -    va_start(args,fmt);
   2.205 -    i = vsscanf(buf,fmt,args);
   2.206 -    va_end(args);
   2.207 -    return i;
   2.208 -}
     3.1 --- a/xen/include/xeno/lib.h	Mon Jul 28 13:22:08 2003 +0000
     3.2 +++ b/xen/include/xeno/lib.h	Wed Jul 30 13:06:06 2003 +0000
     3.3 @@ -47,9 +47,6 @@ extern int snprintf(char * buf, size_t s
     3.4  	__attribute__ ((format (printf, 3, 4)));
     3.5  extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
     3.6  
     3.7 -extern int sscanf(const char *, const char *, ...)
     3.8 -	__attribute__ ((format (scanf,2,3)));
     3.9 -extern int vsscanf(const char *, const char *, va_list);
    3.10  long simple_strtol(const char *cp,char **endp,unsigned int base);
    3.11  unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);
    3.12  long long simple_strtoll(const char *cp,char **endp,unsigned int base);
     4.1 --- a/xen/include/xeno/perfc.h	Mon Jul 28 13:22:08 2003 +0000
     4.2 +++ b/xen/include/xeno/perfc.h	Wed Jul 30 13:06:06 2003 +0000
     4.3 @@ -37,7 +37,6 @@ struct perfcounter_t
     4.4  };
     4.5  
     4.6  extern struct perfcounter_t perfcounters;
     4.7 -extern char *perfc_name[];
     4.8  
     4.9  #define perfc_value(x)    perfcounters.x[0]
    4.10  #define perfc_valuec(x)   perfcounters.x[smp_processor_id()]
    4.11 @@ -52,7 +51,3 @@ extern char *perfc_name[];
    4.12  #define perfc_addc(x,y)   perfcounters.x[smp_processor_id()]+=(y)
    4.13  #define perfc_adda(x,y,z) perfcounters.x[y]+=(z)
    4.14  
    4.15 -#define perf_print(x) \
    4.16 -  __perfc_print(perfcounters.x, \
    4.17 -	        &perfcounters.x[0] - ((unsigned long *)&perfcounters))
    4.18 -
     5.1 --- a/xen/include/xeno/perfc_defn.h	Mon Jul 28 13:22:08 2003 +0000
     5.2 +++ b/xen/include/xeno/perfc_defn.h	Wed Jul 30 13:06:06 2003 +0000
     5.3 @@ -1,9 +1,7 @@
     5.4 +
     5.5  PERFCOUNTER_CPU( irqs,         "#interrupts" )
     5.6  PERFCOUNTER_CPU( irq_time,     "cycles spent in irq handler" )
     5.7  
     5.8 -PERFCOUNTER( blockio_tx,       "block io: messages received from tx queue" )
     5.9 -PERFCOUNTER( blockio_rx,       "block io: messages sent on rx queue" )
    5.10 -
    5.11  PERFCOUNTER_CPU( apic_timer,   "apic timer interrupts" )
    5.12  PERFCOUNTER_CPU( ac_timer_max, "ac_timer max error (ns)" )
    5.13  PERFCOUNTER_CPU( sched_irq,    "sched: timer" )