ia64/xen-unstable

changeset 19414:2a373e32b04d

Add cpufreq actual average freq information to xenpm tools

Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Mar 20 08:49:17 2009 +0000 (2009-03-20)
parents 0fc0de02856a
children 4846d7ae75cd
files tools/misc/xenpm.c
line diff
     1.1 --- a/tools/misc/xenpm.c	Fri Mar 20 08:48:57 2009 +0000
     1.2 +++ b/tools/misc/xenpm.c	Fri Mar 20 08:49:17 2009 +0000
     1.3 @@ -222,6 +222,20 @@ static int get_pxstat_by_cpuid(int xc_fd
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +/* show cpu actual average freq information on CPU cpuid */
     1.8 +static int get_avgfreq_by_cpuid(int xc_fd, int cpuid, int *avgfreq)
     1.9 +{
    1.10 +    int ret = 0;
    1.11 +
    1.12 +    ret = xc_get_cpufreq_avgfreq(xc_fd, cpuid, avgfreq);
    1.13 +    if ( ret )
    1.14 +    {
    1.15 +        return errno;
    1.16 +    }
    1.17 +
    1.18 +    return 0;
    1.19 +}
    1.20 +
    1.21  static int show_pxstat_by_cpuid(int xc_fd, int cpuid)
    1.22  {
    1.23      int ret = 0;
    1.24 @@ -263,6 +277,7 @@ void pxstat_func(int argc, char *argv[])
    1.25  static uint64_t usec_start, usec_end;
    1.26  static struct xc_cx_stat *cxstat, *cxstat_start, *cxstat_end;
    1.27  static struct xc_px_stat *pxstat, *pxstat_start, *pxstat_end;
    1.28 +static int *avgfreq;
    1.29  static uint64_t *sum, *sum_cx, *sum_px;
    1.30  
    1.31  static void signal_int_handler(int signo)
    1.32 @@ -298,6 +313,9 @@ static void signal_int_handler(int signo
    1.33                                   pxstat_start[i].pt[j].residency;
    1.34      }
    1.35  
    1.36 +    for ( i = 0; i < max_cpu_nr; i++ )
    1.37 +        get_avgfreq_by_cpuid(xc_fd, i, &avgfreq[i]);
    1.38 +
    1.39      printf("Elapsed time (ms): %"PRIu64"\n", (usec_end - usec_start) / 1000UL);
    1.40      for ( i = 0; i < max_cpu_nr; i++ )
    1.41      {
    1.42 @@ -329,6 +347,7 @@ static void signal_int_handler(int signo
    1.43                          res / 1000000UL, 100UL * res / (double)sum_px[i]);
    1.44              }
    1.45          }
    1.46 +        printf("  Avg freq\t%d\tKHz\n", avgfreq[i]);
    1.47      }
    1.48  
    1.49      /* some clean up and then exits */
    1.50 @@ -342,6 +361,7 @@ static void signal_int_handler(int signo
    1.51      free(cxstat);
    1.52      free(pxstat);
    1.53      free(sum);
    1.54 +    free(avgfreq);
    1.55      xc_interface_close(xc_fd);
    1.56      exit(0);
    1.57  }
    1.58 @@ -384,9 +404,18 @@ void start_gather_func(int argc, char *a
    1.59          free(cxstat);
    1.60          return ;
    1.61      }
    1.62 +    avgfreq = malloc(sizeof(int) * max_cpu_nr);
    1.63 +    if ( avgfreq == NULL )
    1.64 +    {
    1.65 +        free(sum);
    1.66 +        free(cxstat);
    1.67 +        free(pxstat);
    1.68 +        return ;
    1.69 +    }
    1.70      memset(sum, 0, sizeof(uint64_t) * 2 * max_cpu_nr);
    1.71      memset(cxstat, 0, sizeof(struct xc_cx_stat) * 2 * max_cpu_nr);
    1.72      memset(pxstat, 0, sizeof(struct xc_px_stat) * 2 * max_cpu_nr);
    1.73 +    memset(avgfreq, 0, sizeof(int) * max_cpu_nr);
    1.74      sum_cx = sum;
    1.75      sum_px = sum + max_cpu_nr;
    1.76      cxstat_start = cxstat;
    1.77 @@ -405,6 +434,7 @@ void start_gather_func(int argc, char *a
    1.78      {
    1.79          get_cxstat_by_cpuid(xc_fd, i, &cxstat_start[i]);
    1.80          get_pxstat_by_cpuid(xc_fd, i, &pxstat_start[i]);
    1.81 +        get_avgfreq_by_cpuid(xc_fd, i, &avgfreq[i]);
    1.82      }
    1.83  
    1.84      if (signal(SIGINT, signal_int_handler) == SIG_ERR)
    1.85 @@ -413,6 +443,7 @@ void start_gather_func(int argc, char *a
    1.86          free(sum);
    1.87          free(pxstat);
    1.88          free(cxstat);
    1.89 +        free(avgfreq);
    1.90          return ;
    1.91      }
    1.92  
    1.93 @@ -424,6 +455,7 @@ void start_gather_func(int argc, char *a
    1.94              free(sum);
    1.95              free(pxstat);
    1.96              free(cxstat);
    1.97 +            free(avgfreq);
    1.98              return ;
    1.99          }
   1.100          alarm(timeout);