ia64/xen-unstable

changeset 9629:050ad9813cdb

Clean up xenoprof code a bit. The main remaining TODO is to
clean up the xenoprof hypercall interface.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Apr 07 11:00:28 2006 +0100 (2006-04-07)
parents 0037e3e4da08
children fb174770f426
files linux-2.6-xen-sparse/arch/i386/oprofile/Makefile linux-2.6-xen-sparse/arch/x86_64/oprofile/Makefile xen/arch/x86/domain.c xen/arch/x86/oprofile/nmi_int.c xen/arch/x86/oprofile/xenoprof.c xen/common/event_channel.c xen/include/public/xen.h xen/include/public/xenoprof.h xen/include/xen/sched.h xen/include/xen/xenoprof.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/oprofile/Makefile	Fri Apr 07 09:57:36 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/oprofile/Makefile	Fri Apr 07 11:00:28 2006 +0100
     1.3 @@ -6,7 +6,7 @@ DRIVER_OBJS = $(addprefix ../../../drive
     1.4  		oprofilefs.o oprofile_stats.o  \
     1.5  		timer_int.o )
     1.6  
     1.7 -ifdef CONFIG_X86_XEN
     1.8 +ifdef CONFIG_XEN
     1.9  oprofile-y				:= $(DRIVER_OBJS) xenoprof.o
    1.10  else 
    1.11  oprofile-y				:= $(DRIVER_OBJS) init.o backtrace.o
     2.1 --- a/linux-2.6-xen-sparse/arch/x86_64/oprofile/Makefile	Fri Apr 07 09:57:36 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/oprofile/Makefile	Fri Apr 07 11:00:28 2006 +0100
     2.3 @@ -11,7 +11,7 @@ DRIVER_OBJS = $(addprefix ../../../drive
     2.4  	oprofilefs.o oprofile_stats.o \
     2.5  	timer_int.o )
     2.6  
     2.7 -ifdef
     2.8 +ifdef CONFIG_XEN
     2.9  OPROFILE-y := xenoprof.o
    2.10  else
    2.11  OPROFILE-y := init.o backtrace.o
     3.1 --- a/xen/arch/x86/domain.c	Fri Apr 07 09:57:36 2006 +0100
     3.2 +++ b/xen/arch/x86/domain.c	Fri Apr 07 11:00:28 2006 +0100
     3.3 @@ -915,8 +915,6 @@ static void relinquish_memory(struct dom
     3.4      spin_unlock_recursive(&d->page_alloc_lock);
     3.5  }
     3.6  
     3.7 -extern void free_xenoprof_pages(struct domain *d);
     3.8 -
     3.9  void domain_relinquish_resources(struct domain *d)
    3.10  {
    3.11      struct vcpu *v;
     4.1 --- a/xen/arch/x86/oprofile/nmi_int.c	Fri Apr 07 09:57:36 2006 +0100
     4.2 +++ b/xen/arch/x86/oprofile/nmi_int.c	Fri Apr 07 11:00:28 2006 +0100
     4.3 @@ -45,31 +45,23 @@ extern size_t strlcpy(char *dest, const 
     4.4  
     4.5  int nmi_callback(struct cpu_user_regs *regs, int cpu)
     4.6  {
     4.7 -	int xen_mode = 0;
     4.8 -	int ovf;
     4.9 +	int xen_mode, ovf;
    4.10  
    4.11  	ovf = model->check_ctrs(cpu, &cpu_msrs[cpu], regs);
    4.12  	xen_mode = ring_0(regs);
    4.13 -	if ( ovf )
    4.14 -	{
    4.15 -		if ( is_active(current->domain) )
    4.16 -		{
    4.17 -			if ( !xen_mode )
    4.18 -			{
    4.19 -				send_guest_vcpu_virq(current, VIRQ_XENOPROF);
    4.20 -			} 
    4.21 -		}
    4.22 -	}
    4.23 +	if ( ovf && is_active(current->domain) && !xen_mode )
    4.24 +		send_guest_vcpu_virq(current, VIRQ_XENOPROF);
    4.25 +
    4.26  	return 1;
    4.27  }
    4.28   
    4.29   
    4.30 -static void nmi_cpu_save_registers(struct op_msrs * msrs)
    4.31 +static void nmi_cpu_save_registers(struct op_msrs *msrs)
    4.32  {
    4.33  	unsigned int const nr_ctrs = model->num_counters;
    4.34  	unsigned int const nr_ctrls = model->num_controls; 
    4.35 -	struct op_msr * counters = msrs->counters;
    4.36 -	struct op_msr * controls = msrs->controls;
    4.37 +	struct op_msr *counters = msrs->counters;
    4.38 +	struct op_msr *controls = msrs->controls;
    4.39  	unsigned int i;
    4.40  
    4.41  	for (i = 0; i < nr_ctrs; ++i) {
     5.1 --- a/xen/arch/x86/oprofile/xenoprof.c	Fri Apr 07 09:57:36 2006 +0100
     5.2 +++ b/xen/arch/x86/oprofile/xenoprof.c	Fri Apr 07 11:00:28 2006 +0100
     5.3 @@ -14,18 +14,18 @@
     5.4  
     5.5  int active_domains[MAX_OPROF_DOMAINS];
     5.6  int active_ready[MAX_OPROF_DOMAINS];
     5.7 -unsigned int adomains = 0;
     5.8 -unsigned int activated = 0;
     5.9 -struct domain *primary_profiler = NULL;
    5.10 +unsigned int adomains;
    5.11 +unsigned int activated;
    5.12 +struct domain *primary_profiler;
    5.13  int xenoprof_state = XENOPROF_IDLE;
    5.14  
    5.15 -u64 total_samples = 0;
    5.16 -u64 invalid_buffer_samples = 0;
    5.17 -u64 corrupted_buffer_samples = 0;
    5.18 -u64 lost_samples = 0;
    5.19 -u64 active_samples = 0;
    5.20 -u64 idle_samples = 0;
    5.21 -u64 others_samples = 0;
    5.22 +u64 total_samples;
    5.23 +u64 invalid_buffer_samples;
    5.24 +u64 corrupted_buffer_samples;
    5.25 +u64 lost_samples;
    5.26 +u64 active_samples;
    5.27 +u64 idle_samples;
    5.28 +u64 others_samples;
    5.29  
    5.30  
    5.31  extern int nmi_init(int *num_events, int *is_primary, char *cpu_type);
    5.32 @@ -39,16 +39,8 @@ extern void nmi_release_counters(void);
    5.33  
    5.34  int is_active(struct domain *d)
    5.35  {
    5.36 -    xenoprof_t *x = d->xenoprof;
    5.37 -    if ( x )
    5.38 -    {
    5.39 -        if ( x->domain_type == XENOPROF_DOMAIN_ACTIVE )
    5.40 -            return 1;
    5.41 -        else
    5.42 -            return 0;
    5.43 -    }
    5.44 -    else
    5.45 -        return 0;
    5.46 +    struct xenoprof *x = d->xenoprof;
    5.47 +    return ((x != NULL) && (x->domain_type == XENOPROF_DOMAIN_ACTIVE));
    5.48  }
    5.49  
    5.50  int is_profiled(struct domain *d)
    5.51 @@ -65,25 +57,24 @@ static void xenoprof_reset_stat(void)
    5.52      active_samples = 0;
    5.53      idle_samples = 0;
    5.54      others_samples = 0;
    5.55 -
    5.56 -    return;
    5.57  }
    5.58  
    5.59  static void xenoprof_reset_buf(struct domain *d)
    5.60  {
    5.61      int j;
    5.62 -    xenoprof_buf_t *buf;
    5.63 +    struct xenoprof_buf *buf;
    5.64  
    5.65 -    if ( !d->xenoprof )
    5.66 +    if ( d->xenoprof == NULL )
    5.67      {
    5.68 -        printk("xenoprof_reset_buf: ERROR - Unexpected Xenoprof NULL pointer \n");
    5.69 +        printk("xenoprof_reset_buf: ERROR - Unexpected "
    5.70 +               "Xenoprof NULL pointer \n");
    5.71          return;
    5.72      }
    5.73  
    5.74 -    for ( j=0; j<MAX_VIRT_CPUS; j++ )
    5.75 +    for ( j = 0; j < MAX_VIRT_CPUS; j++ )
    5.76      {
    5.77          buf = d->xenoprof->vcpu[j].buffer;
    5.78 -        if ( buf )
    5.79 +        if ( buf != NULL )
    5.80          {
    5.81              buf->event_head = 0;
    5.82              buf->event_tail = 0;
    5.83 @@ -93,62 +84,57 @@ static void xenoprof_reset_buf(struct do
    5.84  
    5.85  int active_index(struct domain *d)
    5.86  {
    5.87 -    int i;
    5.88 -    int id;
    5.89 +    int i, id = d->domain_id;
    5.90  
    5.91 -    id = d->domain_id;
    5.92 -    for ( i=0; i<adomains; i++ )
    5.93 +    for ( i = 0; i < adomains; i++ )
    5.94          if ( active_domains[i] == id )
    5.95 -        {
    5.96              return i;
    5.97 -        }
    5.98 +
    5.99      return -1;
   5.100  }
   5.101  
   5.102  int set_active(struct domain *d)
   5.103  {
   5.104      int ind;
   5.105 -    xenoprof_t *x;
   5.106 +    struct xenoprof *x;
   5.107  
   5.108      ind = active_index(d);
   5.109 -    if ( ind <0 )
   5.110 +    if ( ind < 0 )
   5.111          return -EPERM;
   5.112  
   5.113      x = d->xenoprof;
   5.114 -    if ( x )
   5.115 -    {
   5.116 -        x->domain_ready = 1;
   5.117 -        x->domain_type = XENOPROF_DOMAIN_ACTIVE;
   5.118 -        active_ready[ind] = 1;
   5.119 -        activated++;
   5.120 -        return 0;
   5.121 -    }
   5.122 -    else
   5.123 +    if ( x == NULL )
   5.124          return -EPERM;
   5.125 +
   5.126 +    x->domain_ready = 1;
   5.127 +    x->domain_type = XENOPROF_DOMAIN_ACTIVE;
   5.128 +    active_ready[ind] = 1;
   5.129 +    activated++;
   5.130 +
   5.131 +    return 0;
   5.132  }
   5.133  
   5.134  int reset_active(struct domain *d)
   5.135  {
   5.136      int ind;
   5.137 -    xenoprof_t *x;
   5.138 +    struct xenoprof *x;
   5.139  
   5.140      ind = active_index(d);
   5.141 -    if ( ind <0 )
   5.142 +    if ( ind < 0 )
   5.143          return -EPERM;
   5.144  
   5.145      x = d->xenoprof;
   5.146 -    if ( x )
   5.147 -    {
   5.148 -        x->domain_ready = 0;
   5.149 -        x->domain_type = XENOPROF_DOMAIN_IGNORED;
   5.150 -        active_ready[ind] = 0;
   5.151 -        activated--;
   5.152 -        if ( activated <= 0 )
   5.153 -            adomains = 0;
   5.154 -        return 0;
   5.155 -    }
   5.156 -    else
   5.157 +    if ( x == NULL )
   5.158          return -EPERM;
   5.159 +
   5.160 +    x->domain_ready = 0;
   5.161 +    x->domain_type = XENOPROF_DOMAIN_IGNORED;
   5.162 +    active_ready[ind] = 0;
   5.163 +    activated--;
   5.164 +    if ( activated <= 0 )
   5.165 +        adomains = 0;
   5.166 +
   5.167 +    return 0;
   5.168  }
   5.169  
   5.170  int set_active_domains(int num)
   5.171 @@ -157,13 +143,13 @@ int set_active_domains(int num)
   5.172      int i;
   5.173      struct domain *d;
   5.174  
   5.175 -    /* reset any existing active domains from previous runs */
   5.176 -    for ( i=0; i<adomains; i++ )
   5.177 +    /* Reset any existing active domains from previous runs. */
   5.178 +    for ( i = 0; i < adomains; i++ )
   5.179      {
   5.180          if ( active_ready[i] )
   5.181          {
   5.182              d = find_domain_by_id(active_domains[i]);
   5.183 -            if ( d )
   5.184 +            if ( d != NULL )
   5.185              {
   5.186                  reset_active(d);
   5.187                  put_domain(d);
   5.188 @@ -171,37 +157,33 @@ int set_active_domains(int num)
   5.189          }
   5.190      }
   5.191  
   5.192 -    adomains=num;
   5.193 +    adomains = num;
   5.194  
   5.195      /* Add primary profiler to list of active domains if not there yet */
   5.196      primary = active_index(primary_profiler);
   5.197      if ( primary == -1 )
   5.198      {
   5.199 -        /* return if there is no space left on list */
   5.200 +        /* Return if there is no space left on list. */
   5.201          if ( num >= MAX_OPROF_DOMAINS )
   5.202              return -E2BIG;
   5.203 -        else
   5.204 -        {
   5.205 -            active_domains[num] = primary_profiler->domain_id;
   5.206 -            num++;
   5.207 -        }
   5.208 +        active_domains[num] = primary_profiler->domain_id;
   5.209 +        num++;
   5.210      }
   5.211  
   5.212      adomains = num;
   5.213      activated = 0;
   5.214  
   5.215 -    for ( i=0; i<adomains; i++ )
   5.216 -    {
   5.217 +    for ( i = 0; i < adomains; i++ )
   5.218          active_ready[i] = 0;
   5.219 -    }
   5.220  
   5.221      return 0;
   5.222  }
   5.223  
   5.224 -void xenoprof_log_event(struct vcpu *vcpu, unsigned long eip, int mode, int event)
   5.225 +void xenoprof_log_event(
   5.226 +    struct vcpu *vcpu, unsigned long eip, int mode, int event)
   5.227  {
   5.228 -    xenoprof_vcpu_t *v;
   5.229 -    xenoprof_buf_t *buf;
   5.230 +    struct xenoprof_vcpu *v;
   5.231 +    struct xenoprof_buf *buf;
   5.232      int head;
   5.233      int tail;
   5.234      int size;
   5.235 @@ -213,14 +195,14 @@ void xenoprof_log_event(struct vcpu *vcp
   5.236      /* Count samples in idle separate from other unmonitored domains */
   5.237      if ( !is_profiled(vcpu->domain) )
   5.238      {
   5.239 -      others_samples++;
   5.240 -      return;
   5.241 +        others_samples++;
   5.242 +        return;
   5.243      }
   5.244  
   5.245      v = &vcpu->domain->xenoprof->vcpu[vcpu->vcpu_id];
   5.246  
   5.247      /* Sanity check. Should never happen */ 
   5.248 -    if ( !v->buffer )
   5.249 +    if ( v->buffer == NULL )
   5.250      {
   5.251          invalid_buffer_samples++;
   5.252          return;
   5.253 @@ -269,20 +251,19 @@ char *alloc_xenoprof_buf(struct domain *
   5.254      int i, order;
   5.255  
   5.256      /* allocate pages to store sample buffer shared with domain */
   5.257 -    order = get_order_from_pages(npages);
   5.258 -    rawbuf =  alloc_xenheap_pages(order);
   5.259 -    if( rawbuf == NULL )
   5.260 +    order  = get_order_from_pages(npages);
   5.261 +    rawbuf = alloc_xenheap_pages(order);
   5.262 +    if ( rawbuf == NULL )
   5.263      {
   5.264          printk("alloc_xenoprof_buf(): memory allocation failed\n");
   5.265          return 0;
   5.266      }
   5.267  
   5.268      /* Share pages so that kernel can map it */
   5.269 -    for ( i=0; i<npages; i++ )
   5.270 -    {
   5.271 -        share_xen_page_with_guest(virt_to_page(rawbuf + i * PAGE_SIZE), 
   5.272 -				  d, XENSHARE_writable);
   5.273 -    }
   5.274 +    for ( i = 0; i < npages; i++ )
   5.275 +        share_xen_page_with_guest(
   5.276 +            virt_to_page(rawbuf + i * PAGE_SIZE), 
   5.277 +            d, XENSHARE_writable);
   5.278  
   5.279      return rawbuf;
   5.280  }
   5.281 @@ -293,9 +274,9 @@ int alloc_xenoprof_struct(struct domain 
   5.282      int nvcpu, npages, bufsize, max_bufsize;
   5.283      int i;
   5.284  
   5.285 -    d->xenoprof = xmalloc(xenoprof_t);
   5.286 +    d->xenoprof = xmalloc(struct xenoprof);
   5.287  
   5.288 -    if ( !d->xenoprof )
   5.289 +    if ( d->xenoprof == NULL )
   5.290      {
   5.291          printk ("alloc_xenoprof_struct(): memory "
   5.292                  "allocation (xmalloc) failed\n");
   5.293 @@ -305,23 +286,23 @@ int alloc_xenoprof_struct(struct domain 
   5.294      memset(d->xenoprof, 0, sizeof(*d->xenoprof));
   5.295  
   5.296      nvcpu = 0;
   5.297 -    for_each_vcpu(d, v)
   5.298 +    for_each_vcpu ( d, v )
   5.299          nvcpu++;
   5.300  
   5.301      /* reduce buffer size if necessary to limit pages allocated */
   5.302 -    bufsize = sizeof(xenoprof_buf_t) +
   5.303 +    bufsize = sizeof(struct xenoprof_buf) +
   5.304          (max_samples - 1) * sizeof(struct event_log);
   5.305      max_bufsize = (MAX_OPROF_SHARED_PAGES * PAGE_SIZE) / nvcpu;
   5.306      if ( bufsize > max_bufsize )
   5.307      {
   5.308          bufsize = max_bufsize;
   5.309 -        max_samples = ( (max_bufsize - sizeof(xenoprof_buf_t)) /
   5.310 +        max_samples = ( (max_bufsize - sizeof(struct xenoprof_buf)) /
   5.311                          sizeof(struct event_log) ) + 1;
   5.312      }
   5.313  
   5.314      npages = (nvcpu * bufsize - 1) / PAGE_SIZE + 1;
   5.315      d->xenoprof->rawbuf = alloc_xenoprof_buf(d, npages);
   5.316 -    if ( !d->xenoprof->rawbuf )
   5.317 +    if ( d->xenoprof->rawbuf == NULL )
   5.318      {
   5.319          xfree(d->xenoprof);
   5.320          d->xenoprof = NULL;
   5.321 @@ -335,12 +316,12 @@ int alloc_xenoprof_struct(struct domain 
   5.322      d->xenoprof->domain_type = XENOPROF_DOMAIN_IGNORED;
   5.323  
   5.324      /* Update buffer pointers for active vcpus */
   5.325 -    i=0;
   5.326 -    for_each_vcpu(d, v)
   5.327 +    i = 0;
   5.328 +    for_each_vcpu ( d, v )
   5.329      {
   5.330          d->xenoprof->vcpu[v->vcpu_id].event_size = max_samples;
   5.331          d->xenoprof->vcpu[v->vcpu_id].buffer =
   5.332 -            (xenoprof_buf_t *)&d->xenoprof->rawbuf[i * bufsize];
   5.333 +            (struct xenoprof_buf *)&d->xenoprof->rawbuf[i * bufsize];
   5.334          d->xenoprof->vcpu[v->vcpu_id].buffer->event_size = max_samples;
   5.335          d->xenoprof->vcpu[v->vcpu_id].buffer->vcpu_id = v->vcpu_id;
   5.336  
   5.337 @@ -355,21 +336,21 @@ int alloc_xenoprof_struct(struct domain 
   5.338  
   5.339  void free_xenoprof_pages(struct domain *d)
   5.340  {
   5.341 -    xenoprof_t *x;
   5.342 +    struct xenoprof *x;
   5.343      int order;
   5.344  
   5.345      x = d->xenoprof;
   5.346 +    if ( x == NULL )
   5.347 +        return;
   5.348  
   5.349 -    if ( x )
   5.350 +    if ( x->rawbuf != NULL )
   5.351      {
   5.352 -        if ( x->rawbuf )
   5.353 -        {
   5.354 -            order = get_order_from_pages(x->npages);
   5.355 -            free_xenheap_pages(x->rawbuf, order);
   5.356 -        }
   5.357 -        xfree(x);
   5.358 -        d->xenoprof = NULL;
   5.359 +        order = get_order_from_pages(x->npages);
   5.360 +        free_xenheap_pages(x->rawbuf, order);
   5.361      }
   5.362 +
   5.363 +    xfree(x);
   5.364 +    d->xenoprof = NULL;
   5.365  }
   5.366  
   5.367  int xenoprof_init(int max_samples, xenoprof_init_result_t *init_result)
   5.368 @@ -386,13 +367,13 @@ int xenoprof_init(int max_samples, xenop
   5.369      if ( ret < 0 )
   5.370          goto err;
   5.371  
   5.372 -    /* we allocate xenoprof struct and buffers only at first time 
   5.373 -       xenoprof_init is called. Memory is then kept until domain is destroyed */
   5.374 -    if ( !d->xenoprof )
   5.375 -    {
   5.376 -        if ( (ret = alloc_xenoprof_struct(d, max_samples)) < 0 )
   5.377 -            goto err;
   5.378 -    }
   5.379 +    /*
   5.380 +     * We allocate xenoprof struct and buffers only at first time xenoprof_init
   5.381 +     * is called. Memory is then kept until domain is destroyed.
   5.382 +     */
   5.383 +    if ( (d->xenoprof == NULL) &&
   5.384 +         ((ret = alloc_xenoprof_struct(d, max_samples)) < 0) )
   5.385 +        goto err;
   5.386  
   5.387      xenoprof_reset_buf(d);
   5.388  
   5.389 @@ -420,11 +401,11 @@ int xenoprof_init(int max_samples, xenop
   5.390      return ret;
   5.391  }
   5.392  
   5.393 -#define PRIV_OP(op) ( (op == XENOPROF_set_active) \
   5.394 +#define PRIV_OP(op) ( (op == XENOPROF_set_active)       \
   5.395                     || (op == XENOPROF_reserve_counters) \
   5.396 -                   || (op == XENOPROF_setup_events) \
   5.397 -                   || (op == XENOPROF_start) \
   5.398 -                   || (op == XENOPROF_stop) \
   5.399 +                   || (op == XENOPROF_setup_events)     \
   5.400 +                   || (op == XENOPROF_start)            \
   5.401 +                   || (op == XENOPROF_stop)             \
   5.402                     || (op == XENOPROF_release_counters) \
   5.403                     || (op == XENOPROF_shutdown))
   5.404  
   5.405 @@ -432,7 +413,7 @@ int do_xenoprof_op(int op, unsigned long
   5.406  {
   5.407      int ret = 0;
   5.408  
   5.409 -    if ( PRIV_OP(op) && current->domain != primary_profiler )
   5.410 +    if ( PRIV_OP(op) && (current->domain != primary_profiler) )
   5.411      {
   5.412          printk("xenoprof: dom %d denied privileged operation %d\n",
   5.413                 current->domain->domain_id, op);
   5.414 @@ -468,9 +449,7 @@ int do_xenoprof_op(int op, unsigned long
   5.415          if ( xenoprof_state != XENOPROF_COUNTERS_RESERVED )
   5.416              return -EPERM;
   5.417          if ( adomains == 0 )
   5.418 -        {
   5.419              set_active_domains(0);
   5.420 -        }
   5.421  
   5.422          if ( copy_from_user((void *)&counter_config, (void *)arg1, 
   5.423                              arg2 * sizeof(struct op_counter_config)) )
   5.424 @@ -491,15 +470,12 @@ int do_xenoprof_op(int op, unsigned long
   5.425          break;
   5.426  
   5.427      case XENOPROF_start:
   5.428 +        ret = -EPERM;
   5.429          if ( (xenoprof_state == XENOPROF_READY) &&
   5.430               (activated == adomains) )
   5.431 -        {
   5.432              ret = nmi_start();
   5.433 -        }
   5.434 -        else 
   5.435 -            ret= -EPERM;
   5.436  
   5.437 -        if ( !ret )
   5.438 +        if ( ret == 0 )
   5.439              xenoprof_state = XENOPROF_PROFILING;
   5.440          break;
   5.441  
   5.442 @@ -518,18 +494,19 @@ int do_xenoprof_op(int op, unsigned long
   5.443          break;
   5.444  
   5.445      case XENOPROF_release_counters:
   5.446 +        ret = -EPERM;
   5.447          if ( (xenoprof_state == XENOPROF_COUNTERS_RESERVED) ||
   5.448               (xenoprof_state == XENOPROF_READY) )
   5.449          {
   5.450              xenoprof_state = XENOPROF_IDLE;
   5.451              nmi_release_counters();
   5.452              nmi_disable_virq();
   5.453 +            ret = 0;
   5.454          }
   5.455 -        else
   5.456 -            ret = -EPERM;
   5.457          break;
   5.458  
   5.459      case XENOPROF_shutdown:
   5.460 +        ret = -EPERM;
   5.461          if ( xenoprof_state == XENOPROF_IDLE )
   5.462          {
   5.463              activated = 0;
   5.464 @@ -537,8 +514,6 @@ int do_xenoprof_op(int op, unsigned long
   5.465              primary_profiler = NULL;
   5.466              ret = 0;
   5.467          }
   5.468 -        else 
   5.469 -            ret = -EPERM;
   5.470          break;
   5.471  
   5.472      default:
     6.1 --- a/xen/common/event_channel.c	Fri Apr 07 09:57:36 2006 +0100
     6.2 +++ b/xen/common/event_channel.c	Fri Apr 07 11:00:28 2006 +0100
     6.3 @@ -57,6 +57,7 @@ static int virq_is_global(int virq)
     6.4      {
     6.5      case VIRQ_TIMER:
     6.6      case VIRQ_DEBUG:
     6.7 +    case VIRQ_XENOPROF:
     6.8          rc = 0;
     6.9          break;
    6.10      default:
     7.1 --- a/xen/include/public/xen.h	Fri Apr 07 09:57:36 2006 +0100
     7.2 +++ b/xen/include/public/xen.h	Fri Apr 07 11:00:28 2006 +0100
     7.3 @@ -78,8 +78,8 @@
     7.4  #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
     7.5  #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
     7.6  #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
     7.7 -#define VIRQ_XENOPROF   7  /* XenOprofile interrupt: new sample available */
     7.8 -#define NR_VIRQS        9
     7.9 +#define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
    7.10 +#define NR_VIRQS        8
    7.11  
    7.12  /*
    7.13   * MMU-UPDATE REQUESTS
     8.1 --- a/xen/include/public/xenoprof.h	Fri Apr 07 09:57:36 2006 +0100
     8.2 +++ b/xen/include/public/xenoprof.h	Fri Apr 07 11:00:28 2006 +0100
     8.3 @@ -48,6 +48,7 @@ typedef struct xenoprof_buf {
     8.4      uint64_t lost_samples;
     8.5      struct event_log event_log[1];
     8.6  } xenoprof_buf_t;
     8.7 +DEFINE_GUEST_HANDLE(xenoprof_buf_t);
     8.8  
     8.9  typedef struct xenoprof_init_result {
    8.10      int32_t  num_events;
    8.11 @@ -57,7 +58,17 @@ typedef struct xenoprof_init_result {
    8.12      uint64_t buf_maddr;
    8.13      char cpu_type[XENOPROF_CPU_TYPE_SIZE];
    8.14  } xenoprof_init_result_t;
    8.15 +DEFINE_GUEST_HANDLE(xenoprof_init_result_t);
    8.16  
    8.17 +typedef struct xenoprof_counter_config {
    8.18 +    unsigned long count;
    8.19 +    unsigned long enabled;
    8.20 +    unsigned long event;
    8.21 +    unsigned long kernel;
    8.22 +    unsigned long user;
    8.23 +    unsigned long unit_mask;
    8.24 +} xenoprof_counter_config_t;
    8.25 +DEFINE_GUEST_HANDLE(xenoprof_counter_config_t);
    8.26  
    8.27  #endif /* __XEN_PUBLIC_XENOPROF_H__ */
    8.28  
     9.1 --- a/xen/include/xen/sched.h	Fri Apr 07 09:57:36 2006 +0100
     9.2 +++ b/xen/include/xen/sched.h	Fri Apr 07 11:00:28 2006 +0100
     9.3 @@ -157,8 +157,8 @@ struct domain
     9.4      /* Control-plane tools handle for this domain. */
     9.5      xen_domain_handle_t handle;
     9.6  
     9.7 -    /* pointer to xenoprof data (oprofile support) */
     9.8 -    xenoprof_t *xenoprof;
     9.9 +    /* OProfile support. */
    9.10 +    struct xenoprof *xenoprof;
    9.11  };
    9.12  
    9.13  struct domain_setup_info
    10.1 --- a/xen/include/xen/xenoprof.h	Fri Apr 07 09:57:36 2006 +0100
    10.2 +++ b/xen/include/xen/xenoprof.h	Fri Apr 07 11:00:28 2006 +0100
    10.3 @@ -20,13 +20,12 @@
    10.4  #define XENOPROF_READY             2
    10.5  #define XENOPROF_PROFILING         3
    10.6  
    10.7 -
    10.8 -typedef struct xenoprof_vcpu {
    10.9 +struct xenoprof_vcpu {
   10.10      int event_size;
   10.11 -    xenoprof_buf_t *buffer;
   10.12 -} xenoprof_vcpu_t;
   10.13 +    struct xenoprof_buf *buffer;
   10.14 +};
   10.15  
   10.16 -typedef struct xenoprof {
   10.17 +struct xenoprof {
   10.18      char* rawbuf;
   10.19      int npages;
   10.20      int nbuf;
   10.21 @@ -34,7 +33,10 @@ typedef struct xenoprof {
   10.22      int domain_type;
   10.23      int domain_ready;
   10.24      int is_primary;
   10.25 -    xenoprof_vcpu_t vcpu [MAX_VIRT_CPUS];
   10.26 -} xenoprof_t;
   10.27 +    struct xenoprof_vcpu vcpu [MAX_VIRT_CPUS];
   10.28 +};
   10.29 +
   10.30 +struct domain;
   10.31 +void free_xenoprof_pages(struct domain *d);
   10.32  
   10.33  #endif  /* __XEN__XENOPROF_H__ */