ia64/xen-unstable

changeset 6517:bbb21d688c7f

Implement event filtering command line options for xentrace.

Signed-off-by: Edwin Zhai <edwin.zhai@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
author adsharma@los-vmm.sc.intel.com
date Tue Aug 09 11:12:48 2005 -0800 (2005-08-09)
parents 455dff354413
children b1a41c400d5c
files tools/xentrace/xentrace.c xen/include/public/trace.h xen/include/xen/trace.h
line diff
     1.1 --- a/tools/xentrace/xentrace.c	Tue Aug 09 11:12:44 2005 -0800
     1.2 +++ b/tools/xentrace/xentrace.c	Tue Aug 09 11:12:48 2005 -0800
     1.3 @@ -45,6 +45,8 @@ typedef struct settings_st {
     1.4      char *outfile;
     1.5      struct timespec poll_sleep;
     1.6      unsigned long new_data_thresh;
     1.7 +    u32 evt_mask;
     1.8 +    u32 cpu_mask;
     1.9  } settings_t;
    1.10  
    1.11  settings_t opts;
    1.12 @@ -160,6 +162,41 @@ struct t_buf *map_tbufs(unsigned long tb
    1.13      return tbufs_mapped;
    1.14  }
    1.15  
    1.16 +/**
    1.17 + * set_mask - set the cpu/event mask in HV
    1.18 + * @mask:           the new mask 
    1.19 + * @type:           the new mask type,0-event mask, 1-cpu mask
    1.20 + *
    1.21 + */
    1.22 +void set_mask(u32 mask, int type)
    1.23 +{
    1.24 +    int ret;
    1.25 +    dom0_op_t op;                        /* dom0 op we'll build             */
    1.26 +    int xc_handle = xc_interface_open(); /* for accessing control interface */
    1.27 +
    1.28 +    op.cmd = DOM0_TBUFCONTROL;
    1.29 +    op.interface_version = DOM0_INTERFACE_VERSION;
    1.30 +    if (type == 1) { /* cpu mask */
    1.31 +        op.u.tbufcontrol.op  = DOM0_TBUF_SET_CPU_MASK;
    1.32 +        op.u.tbufcontrol.cpu_mask = mask;
    1.33 +        fprintf(stderr, "change cpumask to 0x%x\n", mask);
    1.34 +    }else if (type == 0) { /* event mask */
    1.35 +        op.u.tbufcontrol.op  = DOM0_TBUF_SET_EVT_MASK;
    1.36 +        op.u.tbufcontrol.evt_mask = mask;
    1.37 +        fprintf(stderr, "change evtmask to 0x%x\n", mask);
    1.38 +    }
    1.39 +
    1.40 +    ret = do_dom0_op(xc_handle, &op);
    1.41 +
    1.42 +    xc_interface_close(xc_handle);
    1.43 +
    1.44 +    if ( ret != 0 )
    1.45 +    {
    1.46 +        PERROR("Failure to get trace buffer pointer from Xen and set the new mask");
    1.47 +        exit(EXIT_FAILURE);
    1.48 +    }
    1.49 +
    1.50 +}
    1.51  
    1.52  /**
    1.53   * init_bufs_ptrs - initialises an array of pointers to the trace buffers
    1.54 @@ -341,6 +378,31 @@ int monitor_tbufs(FILE *logfile)
    1.55   * Various declarations / definitions GNU argp needs to do its work
    1.56   *****************************************************************************/
    1.57  
    1.58 +int parse_evtmask(char *arg, struct argp_state *state)
    1.59 +{
    1.60 +    settings_t *setup = (settings_t *)state->input;
    1.61 +    char *inval;
    1.62 +
    1.63 +    /* search filtering class */
    1.64 +    if (strcmp(arg, "gen") == 0){ 
    1.65 +        setup->evt_mask |= TRC_GEN;
    1.66 +    } else if(strcmp(arg, "sched") == 0){ 
    1.67 +        setup->evt_mask |= TRC_SCHED;
    1.68 +    } else if(strcmp(arg, "dom0op") == 0){ 
    1.69 +        setup->evt_mask |= TRC_DOM0OP;
    1.70 +    } else if(strcmp(arg, "vmx") == 0){ 
    1.71 +        setup->evt_mask |= TRC_VMX;
    1.72 +    } else if(strcmp(arg, "all") == 0){ 
    1.73 +        setup->evt_mask |= TRC_ALL;
    1.74 +    } else {
    1.75 +        setup->evt_mask = strtol(arg, &inval, 0);
    1.76 +        if ( inval == arg )
    1.77 +            argp_usage(state);
    1.78 +    }
    1.79 +
    1.80 +    return 0;
    1.81 +
    1.82 +}
    1.83  
    1.84  /* command parser for GNU argp - see GNU docs for more info */
    1.85  error_t cmd_parser(int key, char *arg, struct argp_state *state)
    1.86 @@ -366,6 +428,21 @@ error_t cmd_parser(int key, char *arg, s
    1.87              argp_usage(state);
    1.88      }
    1.89      break;
    1.90 +
    1.91 +    case 'c': /* set new cpu mask for filtering*/
    1.92 +    {
    1.93 +        char *inval;
    1.94 +        setup->cpu_mask = strtol(arg, &inval, 0);
    1.95 +        if ( inval == arg )
    1.96 +            argp_usage(state);
    1.97 +    }
    1.98 +    break;
    1.99 +    
   1.100 +    case 'e': /* set new event mask for filtering*/
   1.101 +    {
   1.102 +        parse_evtmask(arg, state);
   1.103 +    }
   1.104 +    break;
   1.105      
   1.106      case ARGP_KEY_ARG:
   1.107      {
   1.108 @@ -398,6 +475,14 @@ const struct argp_option cmd_opts[] =
   1.109        "Set sleep time, p, in milliseconds between polling the trace buffer "
   1.110        "for new data (default " xstr(POLL_SLEEP_MILLIS) ")." },
   1.111  
   1.112 +    { .name = "cpu-mask", .key='c', .arg="c",
   1.113 +      .doc = 
   1.114 +      "set cpu-mask " },
   1.115 +
   1.116 +    { .name = "evt-mask", .key='e', .arg="e",
   1.117 +      .doc = 
   1.118 +      "set evt-mask " },
   1.119 +
   1.120      {0}
   1.121  };
   1.122  
   1.123 @@ -430,9 +515,19 @@ int main(int argc, char **argv)
   1.124      opts.outfile = 0;
   1.125      opts.poll_sleep = millis_to_timespec(POLL_SLEEP_MILLIS);
   1.126      opts.new_data_thresh = NEW_DATA_THRESH;
   1.127 +    opts.evt_mask = 0;
   1.128 +    opts.cpu_mask = 0;
   1.129  
   1.130      argp_parse(&parser_def, argc, argv, 0, 0, &opts);
   1.131  
   1.132 +    if (opts.evt_mask != 0) { 
   1.133 +        set_mask(opts.evt_mask, 0);
   1.134 +    }
   1.135 +
   1.136 +    if (opts.cpu_mask != 0) {
   1.137 +        set_mask(opts.evt_mask, 1);
   1.138 +    }
   1.139 +
   1.140      if ( opts.outfile )
   1.141          outfd = open(opts.outfile, O_WRONLY | O_CREAT);
   1.142  
     2.1 --- a/xen/include/public/trace.h	Tue Aug 09 11:12:44 2005 -0800
     2.2 +++ b/xen/include/public/trace.h	Tue Aug 09 11:12:48 2005 -0800
     2.3 @@ -9,11 +9,21 @@
     2.4  #define __XEN_PUBLIC_TRACE_H__
     2.5  
     2.6  /* Trace classes */
     2.7 -#define TRC_GEN     0x00010000    /* General trace            */
     2.8 -#define TRC_SCHED   0x00020000    /* Xen Scheduler trace      */
     2.9 -#define TRC_DOM0OP  0x00040000    /* Xen DOM0 operation trace */
    2.10 -#define TRC_VMX     0x00080000    /* Xen VMX trace            */
    2.11 -#define TRC_ALL     0xffff0000
    2.12 +#define TRC_CLS_SHIFT 16
    2.13 +#define TRC_GEN     0x0001f000    /* General trace            */
    2.14 +#define TRC_SCHED   0x0002f000    /* Xen Scheduler trace      */
    2.15 +#define TRC_DOM0OP  0x0004f000    /* Xen DOM0 operation trace */
    2.16 +#define TRC_VMX     0x0008f000    /* Xen VMX trace            */
    2.17 +#define TRC_ALL     0xfffff000
    2.18 +
    2.19 +/* Trace subclasses */
    2.20 +#define TRC_SUBCLS_SHIFT 12
    2.21 +/* trace subclasses for VMX */
    2.22 +#define TRC_VMXEXIT  0x00081000   /* VMX exit trace            */
    2.23 +#define TRC_VMXTIMER 0x00082000   /* VMX timer trace           */
    2.24 +#define TRC_VMXINT   0x00084000   /* VMX interrupt trace       */
    2.25 +#define TRC_VMXIO    0x00088000   /* VMX io emulation trace  */
    2.26 +
    2.27  
    2.28  /* Trace events per class */
    2.29  
    2.30 @@ -31,9 +41,13 @@
    2.31  #define TRC_SCHED_T_TIMER_FN    (TRC_SCHED + 12)
    2.32  #define TRC_SCHED_DOM_TIMER_FN  (TRC_SCHED + 13)
    2.33  
    2.34 -#define TRC_VMX_VMEXIT          (TRC_VMX + 1)
    2.35 -#define TRC_VMX_VECTOR          (TRC_VMX + 2)
    2.36 -#define TRC_VMX_INT             (TRC_VMX + 3)
    2.37 +/* trace events per subclass */
    2.38 +#define TRC_VMX_VMEXIT          (TRC_VMXEXIT + 1)
    2.39 +#define TRC_VMX_VECTOR          (TRC_VMXEXIT + 2)
    2.40 +
    2.41 +#define TRC_VMX_TIMER_INTR      (TRC_VMXTIMER + 1)
    2.42 +
    2.43 +#define TRC_VMX_INT             (TRC_VMXINT + 1)
    2.44  
    2.45  /* This structure represents a single trace buffer record. */
    2.46  struct t_rec {
     3.1 --- a/xen/include/xen/trace.h	Tue Aug 09 11:12:44 2005 -0800
     3.2 +++ b/xen/include/xen/trace.h	Tue Aug 09 11:12:48 2005 -0800
     3.3 @@ -67,6 +67,15 @@ static inline int trace(u32 event, unsig
     3.4      if ( (tb_event_mask & event) == 0 )
     3.5          return 0;
     3.6  
     3.7 +    /* match class */
     3.8 +    if ( ((tb_event_mask >> TRC_CLS_SHIFT) & (event >> TRC_CLS_SHIFT)) == 0 )
     3.9 +        return 0;
    3.10 +
    3.11 +    /* then match subclass */
    3.12 +    if ( (((tb_event_mask >> TRC_SUBCLS_SHIFT) & 0xf )
    3.13 +                & ((event >> TRC_SUBCLS_SHIFT) & 0xf )) == 0 )
    3.14 +        return 0;
    3.15 +
    3.16      if ( (tb_cpu_mask & (1UL << smp_processor_id())) == 0 )
    3.17          return 0;
    3.18