ia64/xen-unstable

changeset 8612:d783bdd14f2e

Remove the free_vcpu() interface I added in the preceding
changeset. It makes no sense, since an allocated VCPU
cannot be freed at any arbitrary point because individual
VCPUs are not refcounted.

Instead extend free_domain() slightly so it really does do
the reverse of alloc_vcpu() for every allocated VCPU.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Jan 14 23:40:09 2006 +0100 (2006-01-14)
parents 1ccc28e075ba
children a9ead230cc60
files xen/common/domain.c xen/common/schedule.c xen/include/xen/sched.h
line diff
     1.1 --- a/xen/common/domain.c	Sat Jan 14 23:16:43 2006 +0100
     1.2 +++ b/xen/common/domain.c	Sat Jan 14 23:40:09 2006 +0100
     1.3 @@ -66,7 +66,7 @@ struct domain *domain_create(domid_t dom
     1.4      d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex);
     1.5      d->irq_caps   = rangeset_new(d, "Interrupts", 0);
     1.6      if ( (d->iomem_caps == NULL) || (d->irq_caps == NULL) )
     1.7 -        goto fail5;
     1.8 +        goto fail4; /* NB. alloc_vcpu() is undone in free_domain() */
     1.9  
    1.10      if ( !is_idle_domain(d) )
    1.11      {
    1.12 @@ -84,8 +84,6 @@ struct domain *domain_create(domid_t dom
    1.13  
    1.14      return d;
    1.15  
    1.16 - fail5:
    1.17 -    free_vcpu(v);
    1.18   fail4:
    1.19      arch_domain_destroy(d);
    1.20   fail3:
     2.1 --- a/xen/common/schedule.c	Sat Jan 14 23:16:43 2006 +0100
     2.2 +++ b/xen/common/schedule.c	Sat Jan 14 23:40:09 2006 +0100
     2.3 @@ -73,15 +73,29 @@ static struct scheduler ops;
     2.4  /* Per-CPU periodic timer sends an event to the currently-executing domain. */
     2.5  static struct timer t_timer[NR_CPUS]; 
     2.6  
     2.7 +struct domain *alloc_domain(void)
     2.8 +{
     2.9 +    struct domain *d;
    2.10 +
    2.11 +    if ( (d = xmalloc(struct domain)) != NULL )
    2.12 +        memset(d, 0, sizeof(*d));
    2.13 +
    2.14 +    return d;
    2.15 +}
    2.16 +
    2.17  void free_domain(struct domain *d)
    2.18  {
    2.19 +    struct vcpu *v;
    2.20      int i;
    2.21  
    2.22 +    for_each_vcpu ( d, v )
    2.23 +        sched_rem_domain(v);
    2.24 +
    2.25      SCHED_OP(free_task, d);
    2.26  
    2.27      for ( i = MAX_VIRT_CPUS-1; i >= 0; i-- )
    2.28 -        if ( d->vcpu[i] != NULL )
    2.29 -            free_vcpu_struct(d->vcpu[i]);
    2.30 +        if ( (v = d->vcpu[i]) != NULL )
    2.31 +            free_vcpu_struct(v);
    2.32  
    2.33      xfree(d);
    2.34  }
    2.35 @@ -105,46 +119,24 @@ struct vcpu *alloc_vcpu(
    2.36      v->cpu_affinity = is_idle_domain(d) ?
    2.37          cpumask_of_cpu(cpu_id) : CPU_MASK_ALL;
    2.38  
    2.39 -    d->vcpu[vcpu_id] = v;
    2.40 +    if ( (vcpu_id != 0) && !is_idle_domain(d) )
    2.41 +        set_bit(_VCPUF_down, &v->vcpu_flags);
    2.42  
    2.43      if ( SCHED_OP(alloc_task, v) < 0 )
    2.44      {
    2.45 -        d->vcpu[vcpu_id] = NULL;
    2.46          free_vcpu_struct(v);
    2.47          return NULL;
    2.48      }
    2.49  
    2.50 -    sched_add_domain(v);
    2.51 -
    2.52 +    d->vcpu[vcpu_id] = v;
    2.53      if ( vcpu_id != 0 )
    2.54 -    {
    2.55          d->vcpu[v->vcpu_id-1]->next_in_list = v;
    2.56 -        if ( !is_idle_domain(d) )
    2.57 -            set_bit(_VCPUF_down, &v->vcpu_flags);
    2.58 -    }
    2.59 +
    2.60 +    sched_add_domain(v);
    2.61  
    2.62      return v;
    2.63  }
    2.64  
    2.65 -void free_vcpu(struct vcpu *v)
    2.66 -{
    2.67 -    /* NB. Rest of destruction is done in free_domain(). */
    2.68 -    sched_rem_domain(v);
    2.69 -}
    2.70 -
    2.71 -struct domain *alloc_domain(void)
    2.72 -{
    2.73 -    struct domain *d;
    2.74 -
    2.75 -    if ( (d = xmalloc(struct domain)) != NULL )
    2.76 -        memset(d, 0, sizeof(*d));
    2.77 -
    2.78 -    return d;
    2.79 -}
    2.80 -
    2.81 -/*
    2.82 - * Add and remove a domain
    2.83 - */
    2.84  void sched_add_domain(struct vcpu *v) 
    2.85  {
    2.86      /* Initialise the per-domain timer. */
     3.1 --- a/xen/include/xen/sched.h	Sat Jan 14 23:16:43 2006 +0100
     3.2 +++ b/xen/include/xen/sched.h	Sat Jan 14 23:40:09 2006 +0100
     3.3 @@ -181,7 +181,6 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
     3.4  
     3.5  struct vcpu *alloc_vcpu(
     3.6      struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
     3.7 -void free_vcpu(struct vcpu *v);
     3.8  
     3.9  struct domain *alloc_domain(void);
    3.10  void free_domain(struct domain *d);