ia64/xen-unstable

changeset 5785:8d04aa7b4280

Simpler domid allocation.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jul 15 07:53:46 2005 +0000 (2005-07-15)
parents 1d026c7023d2
children 79bb7dfb8fc1
files xen/common/dom0_ops.c
line diff
     1.1 --- a/xen/common/dom0_ops.c	Thu Jul 14 23:48:06 2005 +0000
     1.2 +++ b/xen/common/dom0_ops.c	Fri Jul 15 07:53:46 2005 +0000
     1.3 @@ -39,55 +39,6 @@ static inline int is_free_domid(domid_t 
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -/*
     1.8 - * Allocate a free domain id. We try to reuse domain ids in a fairly low range,
     1.9 - * only expanding the range when there are no free domain ids. This is to keep 
    1.10 - * domain ids in a range depending on the number that exist simultaneously,
    1.11 - * rather than incrementing domain ids in the full 32-bit range.
    1.12 - */
    1.13 -static int allocate_domid(domid_t *pdom)
    1.14 -{
    1.15 -    static spinlock_t domid_lock = SPIN_LOCK_UNLOCKED;
    1.16 -    static domid_t curdom = 0;
    1.17 -    static domid_t topdom = 101;
    1.18 -    int err = 0;
    1.19 -    domid_t dom;
    1.20 -
    1.21 -    spin_lock(&domid_lock);
    1.22 -
    1.23 -    /* Try to use a domain id in the range 0..topdom, starting at curdom. */
    1.24 -    for ( dom = curdom + 1; dom != curdom; dom++ )
    1.25 -    {
    1.26 -        if ( dom == topdom )
    1.27 -            dom = 1;
    1.28 -        if ( is_free_domid(dom) )
    1.29 -            goto exit;
    1.30 -    }
    1.31 -
    1.32 -    /* Couldn't find a free domain id in 0..topdom, try higher. */
    1.33 -    for ( dom = topdom; dom < DOMID_FIRST_RESERVED; dom++ )
    1.34 -    {
    1.35 -        if ( is_free_domid(dom) )
    1.36 -        {
    1.37 -            topdom = dom + 1;
    1.38 -            goto exit;
    1.39 -        }
    1.40 -    }
    1.41 -
    1.42 -    /* No free domain ids. */
    1.43 -    err = -ENOMEM;
    1.44 -
    1.45 -  exit:
    1.46 -    if ( err == 0 )
    1.47 -    {
    1.48 -        curdom = dom;
    1.49 -        *pdom = dom;
    1.50 -    }
    1.51 -
    1.52 -    spin_unlock(&domid_lock);
    1.53 -    return err;
    1.54 -}
    1.55 -
    1.56  static void getdomaininfo(struct domain *d, dom0_getdomaininfo_t *info)
    1.57  {
    1.58      struct vcpu   *v;
    1.59 @@ -217,18 +168,33 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    1.60          domid_t        dom;
    1.61          struct vcpu   *v;
    1.62          unsigned int   i, cnt[NR_CPUS] = { 0 };
    1.63 +        static spinlock_t alloc_lock = SPIN_LOCK_UNLOCKED;
    1.64 +        static domid_t rover = 0;
    1.65  
    1.66 +        spin_lock(&alloc_lock);
    1.67  
    1.68          dom = op->u.createdomain.domain;
    1.69          if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) )
    1.70          {
    1.71              ret = -EINVAL;
    1.72              if ( !is_free_domid(dom) )
    1.73 -                break;
    1.74 +                goto alloc_out;
    1.75          }
    1.76 -        else if ( (ret = allocate_domid(&dom)) != 0 )
    1.77 +        else
    1.78          {
    1.79 -            break;
    1.80 +            for ( dom = rover + 1; dom != rover; dom++ )
    1.81 +            {
    1.82 +                if ( dom == DOMID_FIRST_RESERVED )
    1.83 +                    dom = 0;
    1.84 +                if ( is_free_domid(dom) )
    1.85 +                    break;
    1.86 +            }
    1.87 +
    1.88 +            ret = -ENOMEM;
    1.89 +            if ( dom == rover )
    1.90 +                goto alloc_out;
    1.91 +
    1.92 +            rover = dom;
    1.93          }
    1.94  
    1.95          /* Do an initial CPU placement. Pick the least-populated CPU. */
    1.96 @@ -249,11 +215,12 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    1.97                  pro = i;
    1.98  
    1.99          ret = -ENOMEM;
   1.100 -        if ( (d = do_createdomain(dom, pro)) == NULL )
   1.101 -            break;
   1.102 +        if ( (d = do_createdomain(dom, pro)) != NULL )
   1.103 +            ret = 0;
   1.104 +        
   1.105 +    alloc_out:
   1.106 +        spin_unlock(&alloc_lock);
   1.107  
   1.108 -        ret = 0;
   1.109 -        
   1.110          op->u.createdomain.domain = d->domain_id;
   1.111          copy_to_user(u_dom0_op, op, sizeof(*op));
   1.112      }