ia64/xen-unstable

changeset 4636:10b57175d4e2

bitkeeper revision 1.1367 (4269220d42QVzUVVn9-Tn1tb9fNSWw)

Remove memory and cpu parameters from DOM0_CREATEDOMAIN, and remove
DOM0_SETINITIALMEM. You can get the same effect via PINCPU,
SETMAXMEM, and do_mem_op(increase_reservation).
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Apr 22 16:10:53 2005 +0000 (2005-04-22)
parents 18a8f5216548
children 7c4ca91ec3ce
files tools/libxc/xc.h tools/libxc/xc_domain.c tools/libxc/xc_private.h xen/arch/ia64/dom0_ops.c xen/arch/x86/dom0_ops.c xen/common/dom0_ops.c xen/common/dom_mem_ops.c xen/common/domain.c xen/include/asm-ia64/mm.h xen/include/public/dom0_ops.h
line diff
     1.1 --- a/tools/libxc/xc.h	Fri Apr 22 09:17:26 2005 +0000
     1.2 +++ b/tools/libxc/xc.h	Fri Apr 22 16:10:53 2005 +0000
     1.3 @@ -353,10 +353,6 @@ int xc_physinfo(int xc_handle,
     1.4  int xc_sched_id(int xc_handle,
     1.5                  int *sched_id);
     1.6  
     1.7 -int xc_domain_setinitialmem(int xc_handle,
     1.8 -                            u32 domid, 
     1.9 -                            unsigned int initial_memkb);
    1.10 -
    1.11  int xc_domain_setmaxmem(int xc_handle,
    1.12                          u32 domid, 
    1.13                          unsigned int max_memkb);
     2.1 --- a/tools/libxc/xc_domain.c	Fri Apr 22 09:17:26 2005 +0000
     2.2 +++ b/tools/libxc/xc_domain.c	Fri Apr 22 16:10:53 2005 +0000
     2.3 @@ -14,22 +14,42 @@ int xc_domain_create(int xc_handle,
     2.4                       float cpu_weight,
     2.5                       u32 *pdomid)
     2.6  {
     2.7 -    int err;
     2.8 +    int err, errno_saved;
     2.9      dom0_op_t op;
    2.10  
    2.11      op.cmd = DOM0_CREATEDOMAIN;
    2.12      op.u.createdomain.domain = (domid_t)*pdomid;
    2.13 -    op.u.createdomain.memory_kb = mem_kb;
    2.14 -    op.u.createdomain.cpu = cpu;
    2.15 +    if ( (err = do_dom0_op(xc_handle, &op)) != 0 )
    2.16 +        return err;
    2.17 +
    2.18 +    *pdomid = (u16)op.u.createdomain.domain;
    2.19 +
    2.20 +    if ( (cpu != -1) &&
    2.21 +         ((err = xc_domain_pincpu(xc_handle, *pdomid, cpu)) != 0) )
    2.22 +        goto fail;
    2.23  
    2.24 -    if ( (err = do_dom0_op(xc_handle, &op)) == 0 )
    2.25 +    if ( (err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight)) != 0 )
    2.26 +        goto fail;
    2.27 +
    2.28 +    if ( (err = xc_domain_setmaxmem(xc_handle, *pdomid, mem_kb)) != 0 )
    2.29 +        goto fail;
    2.30 +
    2.31 +    if ( (err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation,
    2.32 +                              NULL, mem_kb/4, 0, *pdomid)) != (mem_kb/4) )
    2.33      {
    2.34 -        *pdomid = (u16)op.u.createdomain.domain;
    2.35 -        
    2.36 -         err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight);
    2.37 +        if ( err > 0 )
    2.38 +            errno = ENOMEM;
    2.39 +        err = -1;
    2.40 +        goto fail;
    2.41      }
    2.42  
    2.43      return err;
    2.44 +
    2.45 + fail:
    2.46 +    errno_saved = errno;
    2.47 +    (void)xc_domain_destroy(xc_handle, *pdomid);
    2.48 +    errno = errno_saved;
    2.49 +    return err;
    2.50  }    
    2.51  
    2.52  
    2.53 @@ -213,18 +233,6 @@ int xc_domain_setcpuweight(int xc_handle
    2.54      return ret;
    2.55  }
    2.56  
    2.57 -
    2.58 -int xc_domain_setinitialmem(int xc_handle,
    2.59 -                            u32 domid, 
    2.60 -                            unsigned int initial_memkb)
    2.61 -{
    2.62 -    dom0_op_t op;
    2.63 -    op.cmd = DOM0_SETDOMAININITIALMEM;
    2.64 -    op.u.setdomaininitialmem.domain = (domid_t)domid;
    2.65 -    op.u.setdomaininitialmem.initial_memkb = initial_memkb;
    2.66 -    return do_dom0_op(xc_handle, &op);
    2.67 -}
    2.68 -
    2.69  int xc_domain_setmaxmem(int xc_handle,
    2.70                          u32 domid, 
    2.71                          unsigned int max_memkb)
     3.1 --- a/tools/libxc/xc_private.h	Fri Apr 22 09:17:26 2005 +0000
     3.2 +++ b/tools/libxc/xc_private.h	Fri Apr 22 16:10:53 2005 +0000
     3.3 @@ -72,7 +72,7 @@ static inline int do_xen_hypercall(int x
     3.4  
     3.5  static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
     3.6  {
     3.7 -    int ret = -1, retries = 0;
     3.8 +    int ret = -1, errno_saved;
     3.9      privcmd_hypercall_t hypercall;
    3.10  
    3.11      op->interface_version = DOM0_INTERFACE_VERSION;
    3.12 @@ -86,26 +86,19 @@ static inline int do_dom0_op(int xc_hand
    3.13          goto out1;
    3.14      }
    3.15  
    3.16 - again:
    3.17      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
    3.18      {
    3.19 -        if ( (errno == EAGAIN) && (retries++ < 10) )
    3.20 -        {
    3.21 -            /*
    3.22 -             * This was added for memory allocation, where we can get EAGAIN
    3.23 -             * if memory is unavailable because it is on the scrub list.
    3.24 -             */
    3.25 -            sleep(1);
    3.26 -            goto again;
    3.27 -        }
    3.28          if ( errno == EACCES )
    3.29              fprintf(stderr, "Dom0 operation failed -- need to"
    3.30                      " rebuild the user-space tool set?\n");
    3.31 -        goto out2;
    3.32      }
    3.33  
    3.34 - out2: (void)munlock(op, sizeof(*op));
    3.35 - out1: return ret;
    3.36 +    errno_saved = errno;
    3.37 +    (void)munlock(op, sizeof(*op));
    3.38 +    errno = errno_saved;
    3.39 +
    3.40 + out1:
    3.41 +    return ret;
    3.42  }
    3.43  
    3.44  static inline int do_dom_mem_op(int            xc_handle,
    3.45 @@ -117,7 +110,8 @@ static inline int do_dom_mem_op(int     
    3.46  {
    3.47      privcmd_hypercall_t hypercall;
    3.48      long ret = -EINVAL;
    3.49 -	
    3.50 +    int errno_saved;
    3.51 +
    3.52      hypercall.op     = __HYPERVISOR_dom_mem_op;
    3.53      hypercall.arg[0] = (unsigned long)memop;
    3.54      hypercall.arg[1] = (unsigned long)extent_list;
    3.55 @@ -125,7 +119,8 @@ static inline int do_dom_mem_op(int     
    3.56      hypercall.arg[3] = (unsigned long)extent_order;
    3.57      hypercall.arg[4] = (unsigned long)domid;
    3.58  
    3.59 -    if ( mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0 )
    3.60 +    if ( (extent_list != NULL) && 
    3.61 +         (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) )
    3.62      {
    3.63          PERROR("Could not lock memory for Xen hypercall");
    3.64          goto out1;
    3.65 @@ -134,12 +129,18 @@ static inline int do_dom_mem_op(int     
    3.66      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
    3.67      {
    3.68  	fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
    3.69 -                    " rebuild the user-space tool set?\n",ret,errno);
    3.70 -        goto out2;
    3.71 +                " rebuild the user-space tool set?\n",ret,errno);
    3.72      }
    3.73  
    3.74 - out2: (void)munlock(extent_list, nr_extents*sizeof(unsigned long));
    3.75 - out1: return ret;
    3.76 +    if ( extent_list != NULL )
    3.77 +    {
    3.78 +        errno_saved = errno;
    3.79 +        (void)munlock(extent_list, nr_extents*sizeof(unsigned long));
    3.80 +        errno = errno_saved;
    3.81 +    }
    3.82 +
    3.83 + out1:
    3.84 +    return ret;
    3.85  }    
    3.86  
    3.87  static inline int do_mmuext_op(
    3.88 @@ -150,7 +151,8 @@ static inline int do_mmuext_op(
    3.89  {
    3.90      privcmd_hypercall_t hypercall;
    3.91      long ret = -EINVAL;
    3.92 -	
    3.93 +    int errno_saved;
    3.94 +
    3.95      hypercall.op     = __HYPERVISOR_mmuext_op;
    3.96      hypercall.arg[0] = (unsigned long)op;
    3.97      hypercall.arg[1] = (unsigned long)nr_ops;
    3.98 @@ -167,11 +169,14 @@ static inline int do_mmuext_op(
    3.99      {
   3.100  	fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
   3.101                      " rebuild the user-space tool set?\n",ret,errno);
   3.102 -        goto out2;
   3.103      }
   3.104  
   3.105 - out2: (void)munlock(op, nr_ops*sizeof(*op));
   3.106 - out1: return ret;
   3.107 +    errno_saved = errno;
   3.108 +    (void)munlock(op, nr_ops*sizeof(*op));
   3.109 +    errno = errno_saved;
   3.110 +
   3.111 + out1:
   3.112 +    return ret;
   3.113  }    
   3.114  
   3.115  
     4.1 --- a/xen/arch/ia64/dom0_ops.c	Fri Apr 22 09:17:26 2005 +0000
     4.2 +++ b/xen/arch/ia64/dom0_ops.c	Fri Apr 22 16:10:53 2005 +0000
     4.3 @@ -24,8 +24,6 @@
     4.4  #define TRC_DOM0OP_ENTER_BASE  0x00020000
     4.5  #define TRC_DOM0OP_LEAVE_BASE  0x00030000
     4.6  
     4.7 -extern unsigned int alloc_new_dom_mem(struct domain *, unsigned int);
     4.8 -
     4.9  static int msr_cpu_mask;
    4.10  static unsigned long msr_addr;
    4.11  static unsigned long msr_lo;
     5.1 --- a/xen/arch/x86/dom0_ops.c	Fri Apr 22 09:17:26 2005 +0000
     5.2 +++ b/xen/arch/x86/dom0_ops.c	Fri Apr 22 16:10:53 2005 +0000
     5.3 @@ -26,8 +26,6 @@
     5.4  #define TRC_DOM0OP_ENTER_BASE  0x00020000
     5.5  #define TRC_DOM0OP_LEAVE_BASE  0x00030000
     5.6  
     5.7 -extern unsigned int alloc_new_dom_mem(struct domain *, unsigned int);
     5.8 -
     5.9  static int msr_cpu_mask;
    5.10  static unsigned long msr_addr;
    5.11  static unsigned long msr_lo;
     6.1 --- a/xen/common/dom0_ops.c	Fri Apr 22 09:17:26 2005 +0000
     6.2 +++ b/xen/common/dom0_ops.c	Fri Apr 22 16:10:53 2005 +0000
     6.3 @@ -19,7 +19,6 @@
     6.4  #include <xen/physdev.h>
     6.5  #include <public/sched_ctl.h>
     6.6  
     6.7 -extern unsigned int alloc_new_dom_mem(struct domain *, unsigned int);
     6.8  extern long arch_do_dom0_op(dom0_op_t *op, dom0_op_t *u_dom0_op);
     6.9  extern void arch_getdomaininfo_ctxt(
    6.10      struct exec_domain *, full_execution_context_t *);
    6.11 @@ -153,9 +152,12 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    6.12  
    6.13      case DOM0_CREATEDOMAIN:
    6.14      {
    6.15 -        struct domain *d;
    6.16 -        unsigned int   pro;
    6.17 -        domid_t        dom;
    6.18 +        struct domain      *d;
    6.19 +        unsigned int        pro;
    6.20 +        domid_t             dom;
    6.21 +        struct exec_domain *ed;
    6.22 +        unsigned int        i, ht, cnt[NR_CPUS] = { 0 };
    6.23 +
    6.24  
    6.25          dom = op->u.createdomain.domain;
    6.26          if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) )
    6.27 @@ -165,46 +167,32 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    6.28                  break;
    6.29          }
    6.30          else if ( (ret = allocate_domid(&dom)) != 0 )
    6.31 +        {
    6.32              break;
    6.33 -
    6.34 -        if ( op->u.createdomain.cpu == -1 )
    6.35 -        {
    6.36 -            /* Do an initial placement. Pick the least-populated CPU. */
    6.37 -            struct domain *d;
    6.38 -            struct exec_domain *ed;
    6.39 -            unsigned int i, ht, cnt[NR_CPUS] = { 0 };
    6.40 +        }
    6.41  
    6.42 -            read_lock(&domlist_lock);
    6.43 -            for_each_domain ( d ) {
    6.44 -                for_each_exec_domain ( d, ed )
    6.45 -                    cnt[ed->processor]++;
    6.46 -            }
    6.47 -            read_unlock(&domlist_lock);
    6.48 -
    6.49 -            /* If we're on a HT system, we only use the first HT for dom0,
    6.50 -               other domains will all share the second HT of each CPU.
    6.51 -	       Since dom0 is on CPU 0, we favour high numbered CPUs in
    6.52 -	       the event of a tie */
    6.53 -            ht = opt_noht ? 1 : ht_per_core;
    6.54 -            pro = ht-1;
    6.55 -            for ( i = pro; i < smp_num_cpus; i += ht )
    6.56 -		if ( cnt[i] <= cnt[pro] )
    6.57 -		    pro = i;
    6.58 -        }
    6.59 -        else
    6.60 -            pro = op->u.createdomain.cpu % smp_num_cpus;
    6.61 +        /* Do an initial CPU placement. Pick the least-populated CPU. */
    6.62 +        read_lock(&domlist_lock);
    6.63 +        for_each_domain ( d )
    6.64 +            for_each_exec_domain ( d, ed )
    6.65 +                cnt[ed->processor]++;
    6.66 +        read_unlock(&domlist_lock);
    6.67 +        
    6.68 +        /*
    6.69 +         * If we're on a HT system, we only use the first HT for dom0, other 
    6.70 +         * domains will all share the second HT of each CPU. Since dom0 is on 
    6.71 +	     * CPU 0, we favour high numbered CPUs in the event of a tie.
    6.72 +         */
    6.73 +        ht = opt_noht ? 1 : ht_per_core;
    6.74 +        pro = ht-1;
    6.75 +        for ( i = pro; i < smp_num_cpus; i += ht )
    6.76 +            if ( cnt[i] <= cnt[pro] )
    6.77 +                pro = i;
    6.78  
    6.79          ret = -ENOMEM;
    6.80          if ( (d = do_createdomain(dom, pro)) == NULL )
    6.81              break;
    6.82  
    6.83 -        ret = alloc_new_dom_mem(d, op->u.createdomain.memory_kb);
    6.84 -        if ( ret != 0 ) 
    6.85 -        {
    6.86 -            domain_kill(d);
    6.87 -            break;
    6.88 -        }
    6.89 -
    6.90          ret = 0;
    6.91          
    6.92          op->u.createdomain.domain = d->id;
    6.93 @@ -416,33 +404,14 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    6.94      }
    6.95      break;
    6.96  
    6.97 -    case DOM0_SETDOMAININITIALMEM:
    6.98 -    {
    6.99 -        struct domain *d; 
   6.100 -        ret = -ESRCH;
   6.101 -        d = find_domain_by_id(op->u.setdomaininitialmem.domain);
   6.102 -        if ( d != NULL )
   6.103 -        { 
   6.104 -            /* should only be used *before* domain is built. */
   6.105 -            if ( !test_bit(DF_CONSTRUCTED, &d->d_flags) )
   6.106 -                ret = alloc_new_dom_mem( 
   6.107 -                    d, op->u.setdomaininitialmem.initial_memkb );
   6.108 -            else
   6.109 -                ret = -EINVAL;
   6.110 -            put_domain(d);
   6.111 -        }
   6.112 -    }
   6.113 -    break;
   6.114 -
   6.115      case DOM0_SETDOMAINMAXMEM:
   6.116      {
   6.117          struct domain *d; 
   6.118          ret = -ESRCH;
   6.119 -        d = find_domain_by_id( op->u.setdomainmaxmem.domain );
   6.120 +        d = find_domain_by_id(op->u.setdomainmaxmem.domain);
   6.121          if ( d != NULL )
   6.122          {
   6.123 -            d->max_pages = 
   6.124 -                (op->u.setdomainmaxmem.max_memkb+PAGE_SIZE-1)>> PAGE_SHIFT;
   6.125 +            d->max_pages = op->u.setdomainmaxmem.max_memkb >> (PAGE_SHIFT-10);
   6.126              put_domain(d);
   6.127              ret = 0;
   6.128          }
     7.1 --- a/xen/common/dom_mem_ops.c	Fri Apr 22 09:17:26 2005 +0000
     7.2 +++ b/xen/common/dom_mem_ops.c	Fri Apr 22 16:10:53 2005 +0000
     7.3 @@ -41,8 +41,8 @@ alloc_dom_mem(struct domain *d,
     7.4      struct pfn_info *page;
     7.5      unsigned long    i;
     7.6  
     7.7 -    if ( unlikely(!array_access_ok(extent_list, nr_extents,
     7.8 -                                   sizeof(*extent_list))) )
     7.9 +    if ( (extent_list != NULL) && 
    7.10 +         !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
    7.11          return start_extent;
    7.12  
    7.13      if ( (extent_order != 0) && !IS_CAPABLE_PHYSDEV(current->domain) )
    7.14 @@ -62,7 +62,8 @@ alloc_dom_mem(struct domain *d,
    7.15          }
    7.16  
    7.17          /* Inform the domain of the new page's machine address. */ 
    7.18 -        if ( unlikely(__put_user(page_to_pfn(page), &extent_list[i]) != 0) )
    7.19 +        if ( (extent_list != NULL) && 
    7.20 +             (__put_user(page_to_pfn(page), &extent_list[i]) != 0) )
    7.21              return i;
    7.22      }
    7.23  
    7.24 @@ -79,8 +80,7 @@ free_dom_mem(struct domain *d,
    7.25      struct pfn_info *page;
    7.26      unsigned long    i, j, mpfn;
    7.27  
    7.28 -    if ( unlikely(!array_access_ok(extent_list, nr_extents,
    7.29 -                                   sizeof(*extent_list))) )
    7.30 +    if ( !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
    7.31          return start_extent;
    7.32  
    7.33      for ( i = start_extent; i < nr_extents; i++ )
     8.1 --- a/xen/common/domain.c	Fri Apr 22 09:17:26 2005 +0000
     8.2 +++ b/xen/common/domain.c	Fri Apr 22 16:10:53 2005 +0000
     8.3 @@ -185,31 +185,6 @@ void domain_shutdown(u8 reason)
     8.4  }
     8.5  
     8.6  
     8.7 -unsigned int alloc_new_dom_mem(struct domain *d, unsigned int kbytes)
     8.8 -{
     8.9 -    unsigned int alloc_pfns, nr_pages;
    8.10 -    struct pfn_info *page;
    8.11 -
    8.12 -    nr_pages = (kbytes + ((PAGE_SIZE-1)>>10)) >> (PAGE_SHIFT - 10);
    8.13 -    d->max_pages = nr_pages; /* this can now be controlled independently */
    8.14 -
    8.15 -    /* Grow the allocation if necessary. */
    8.16 -    for ( alloc_pfns = d->tot_pages; alloc_pfns < nr_pages; alloc_pfns++ )
    8.17 -    {
    8.18 -        if ( unlikely((page = alloc_domheap_page(d)) == NULL) )
    8.19 -        {
    8.20 -            domain_relinquish_resources(d);
    8.21 -            return list_empty(&page_scrub_list) ? -ENOMEM : -EAGAIN;
    8.22 -        }
    8.23 -
    8.24 -        /* Initialise the machine-to-phys mapping for this page. */
    8.25 -        set_machinetophys(page_to_pfn(page), alloc_pfns);
    8.26 -    }
    8.27 -
    8.28 -    return 0;
    8.29 -}
    8.30 - 
    8.31 -
    8.32  /* Release resources belonging to task @p. */
    8.33  void domain_destruct(struct domain *d)
    8.34  {
     9.1 --- a/xen/include/asm-ia64/mm.h	Fri Apr 22 09:17:26 2005 +0000
     9.2 +++ b/xen/include/asm-ia64/mm.h	Fri Apr 22 16:10:53 2005 +0000
     9.3 @@ -161,7 +161,6 @@ static inline int get_page(struct pfn_in
     9.4  	dummy();
     9.5  }
     9.6  
     9.7 -// see alloc_new_dom_mem() in common/domain.c
     9.8  #define	set_machinetophys(_mfn, _pfn) do { } while(0);
     9.9  
    9.10  #ifdef MEMORY_GUARD
    10.1 --- a/xen/include/public/dom0_ops.h	Fri Apr 22 09:17:26 2005 +0000
    10.2 +++ b/xen/include/public/dom0_ops.h	Fri Apr 22 16:10:53 2005 +0000
    10.3 @@ -43,13 +43,9 @@ typedef struct sched_adjdom_cmd dom0_adj
    10.4  
    10.5  #define DOM0_CREATEDOMAIN      8
    10.6  typedef struct {
    10.7 -    /* IN parameters. */
    10.8 -    memory_t     memory_kb;
    10.9 -    u32          cpu;
   10.10      /* IN/OUT parameters. */
   10.11 -    /* If 0, domain is allocated. If non-zero use it unless in use. */
   10.12 -    domid_t      domain;
   10.13 -    /* OUT parameters. */
   10.14 +    /* Identifier for new domain (auto-allocate if zero is specified). */
   10.15 +    domid_t domain;
   10.16  } dom0_createdomain_t;
   10.17  
   10.18  #define DOM0_DESTROYDOMAIN     9
   10.19 @@ -267,13 +263,6 @@ typedef struct {
   10.20      dom0_shadow_control_stats_t stats;
   10.21  } dom0_shadow_control_t;
   10.22  
   10.23 -#define DOM0_SETDOMAININITIALMEM   27
   10.24 -typedef struct {
   10.25 -    /* IN variables. */
   10.26 -    domid_t     domain;
   10.27 -    memory_t    initial_memkb;
   10.28 -} dom0_setdomaininitialmem_t;
   10.29 -
   10.30  #define DOM0_SETDOMAINMAXMEM   28
   10.31  typedef struct {
   10.32      /* IN variables. */
   10.33 @@ -390,7 +379,6 @@ typedef struct {
   10.34          dom0_pcidev_access_t     pcidev_access;
   10.35          dom0_sched_id_t          sched_id;
   10.36          dom0_shadow_control_t    shadow_control;
   10.37 -        dom0_setdomaininitialmem_t setdomaininitialmem;
   10.38          dom0_setdomainmaxmem_t   setdomainmaxmem;
   10.39          dom0_getpageframeinfo2_t getpageframeinfo2;
   10.40          dom0_add_memtype_t       add_memtype;