ia64/xen-unstable
changeset 7367:d6e99066959a
Refactor domain/vcpu allocation to be more separated.
Signed-off-by: Keir Fraser <keir@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Wed Oct 12 17:01:38 2005 +0100 (2005-10-12) |
parents | af38c6b205f6 |
children | c81c8a2821aa |
files | xen/arch/x86/domain_build.c xen/common/dom0_ops.c xen/common/domain.c xen/common/schedule.c xen/include/xen/sched.h |
line diff
1.1 --- a/xen/arch/x86/domain_build.c Wed Oct 12 17:00:29 2005 +0100 1.2 +++ b/xen/arch/x86/domain_build.c Wed Oct 12 17:01:38 2005 +0100 1.3 @@ -560,7 +560,7 @@ int construct_dom0(struct domain *d, 1.4 d->shared_info->n_vcpu = num_online_cpus(); 1.5 1.6 for ( i = 1; i < d->shared_info->n_vcpu; i++ ) 1.7 - (void)alloc_vcpu(d, i); 1.8 + (void)alloc_vcpu(d, i, i % num_online_cpus()); 1.9 1.10 /* Set up monitor table */ 1.11 update_pagetables(v);
2.1 --- a/xen/common/dom0_ops.c Wed Oct 12 17:00:29 2005 +0100 2.2 +++ b/xen/common/dom0_ops.c Wed Oct 12 17:01:38 2005 +0100 2.3 @@ -224,7 +224,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op) 2.4 case DOM0_MAX_VCPUS: 2.5 { 2.6 struct domain *d; 2.7 - unsigned int i, max = op->u.max_vcpus.max; 2.8 + unsigned int i, max = op->u.max_vcpus.max, cpu; 2.9 2.10 ret = -EINVAL; 2.11 if ( max > MAX_VIRT_CPUS ) 2.12 @@ -250,8 +250,14 @@ long do_dom0_op(dom0_op_t *u_dom0_op) 2.13 2.14 ret = -ENOMEM; 2.15 for ( i = 0; i < max; i++ ) 2.16 - if ( (d->vcpu[i] == NULL) && (alloc_vcpu(d, i) == NULL) ) 2.17 - goto maxvcpu_out; 2.18 + { 2.19 + if ( d->vcpu[i] == NULL ) 2.20 + { 2.21 + cpu = (d->vcpu[i-1]->processor + 1) % num_online_cpus(); 2.22 + if ( alloc_vcpu(d, i, cpu) == NULL ) 2.23 + goto maxvcpu_out; 2.24 + } 2.25 + } 2.26 2.27 ret = 0; 2.28
3.1 --- a/xen/common/domain.c Wed Oct 12 17:00:29 2005 +0100 3.2 +++ b/xen/common/domain.c Wed Oct 12 17:01:38 2005 +0100 3.3 @@ -36,16 +36,11 @@ struct domain *do_createdomain(domid_t d 3.4 if ( (d = alloc_domain()) == NULL ) 3.5 return NULL; 3.6 3.7 - v = d->vcpu[0]; 3.8 + d->domain_id = dom_id; 3.9 3.10 atomic_set(&d->refcnt, 1); 3.11 - atomic_set(&v->pausecnt, 0); 3.12 - 3.13 - d->domain_id = dom_id; 3.14 - v->processor = cpu; 3.15 3.16 spin_lock_init(&d->big_lock); 3.17 - 3.18 spin_lock_init(&d->page_alloc_lock); 3.19 INIT_LIST_HEAD(&d->page_list); 3.20 INIT_LIST_HEAD(&d->xenpage_list); 3.21 @@ -63,10 +58,16 @@ struct domain *do_createdomain(domid_t d 3.22 return NULL; 3.23 } 3.24 3.25 + if ( (v = alloc_vcpu(d, 0, cpu)) == NULL ) 3.26 + { 3.27 + grant_table_destroy(d); 3.28 + evtchn_destroy(d); 3.29 + free_domain(d); 3.30 + return NULL; 3.31 + } 3.32 + 3.33 arch_do_createdomain(v); 3.34 3.35 - sched_add_domain(v); 3.36 - 3.37 if ( !is_idle_task(d) ) 3.38 { 3.39 write_lock(&domlist_lock); 3.40 @@ -370,8 +371,6 @@ int boot_vcpu(struct domain *d, int vcpu 3.41 if ( (rc = arch_set_info_guest(v, ctxt)) != 0 ) 3.42 return rc; 3.43 3.44 - sched_add_domain(v); 3.45 - 3.46 return rc; 3.47 } 3.48
4.1 --- a/xen/common/schedule.c Wed Oct 12 17:00:29 2005 +0100 4.2 +++ b/xen/common/schedule.c Wed Oct 12 17:01:38 2005 +0100 4.3 @@ -93,7 +93,8 @@ void free_domain(struct domain *d) 4.4 xfree(d); 4.5 } 4.6 4.7 -struct vcpu *alloc_vcpu(struct domain *d, unsigned int vcpu_id) 4.8 +struct vcpu *alloc_vcpu( 4.9 + struct domain *d, unsigned int vcpu_id, unsigned int cpu_id) 4.10 { 4.11 struct vcpu *v; 4.12 4.13 @@ -104,6 +105,7 @@ struct vcpu *alloc_vcpu(struct domain *d 4.14 4.15 v->domain = d; 4.16 v->vcpu_id = vcpu_id; 4.17 + v->processor = cpu_id; 4.18 atomic_set(&v->pausecnt, 0); 4.19 v->cpumap = CPUMAP_RUNANYWHERE; 4.20 4.21 @@ -116,18 +118,14 @@ struct vcpu *alloc_vcpu(struct domain *d 4.22 return NULL; 4.23 } 4.24 4.25 - if ( vcpu_id == 0 ) 4.26 - return v; 4.27 - 4.28 - v->vcpu_info = &d->shared_info->vcpu_data[vcpu_id]; 4.29 + sched_add_domain(v); 4.30 4.31 - d->vcpu[v->vcpu_id-1]->next_in_list = v; 4.32 - 4.33 - v->processor = (d->vcpu[0]->processor + 1) % num_online_cpus(); 4.34 - if ( test_bit(_VCPUF_cpu_pinned, &d->vcpu[0]->vcpu_flags) ) 4.35 - set_bit(_VCPUF_cpu_pinned, &v->vcpu_flags); 4.36 - 4.37 - set_bit(_VCPUF_down, &v->vcpu_flags); 4.38 + if ( vcpu_id != 0 ) 4.39 + { 4.40 + v->vcpu_info = &d->shared_info->vcpu_data[vcpu_id]; 4.41 + d->vcpu[v->vcpu_id-1]->next_in_list = v; 4.42 + set_bit(_VCPUF_down, &v->vcpu_flags); 4.43 + } 4.44 4.45 return v; 4.46 } 4.47 @@ -136,19 +134,10 @@ struct domain *alloc_domain(void) 4.48 { 4.49 struct domain *d; 4.50 4.51 - if ( (d = xmalloc(struct domain)) == NULL ) 4.52 - return NULL; 4.53 - 4.54 - memset(d, 0, sizeof(*d)); 4.55 - 4.56 - if ( alloc_vcpu(d, 0) == NULL ) 4.57 - goto out; 4.58 + if ( (d = xmalloc(struct domain)) != NULL ) 4.59 + memset(d, 0, sizeof(*d)); 4.60 4.61 return d; 4.62 - 4.63 - out: 4.64 - xfree(d); 4.65 - return NULL; 4.66 } 4.67 4.68 /*
5.1 --- a/xen/include/xen/sched.h Wed Oct 12 17:00:29 2005 +0100 5.2 +++ b/xen/include/xen/sched.h Wed Oct 12 17:01:38 2005 +0100 5.3 @@ -167,7 +167,8 @@ extern struct vcpu *idle_task[NR_CPUS]; 5.4 #define IDLE_DOMAIN_ID (0x7FFFU) 5.5 #define is_idle_task(_d) (test_bit(_DOMF_idle_domain, &(_d)->domain_flags)) 5.6 5.7 -struct vcpu *alloc_vcpu(struct domain *d, unsigned int vcpu_id); 5.8 +struct vcpu *alloc_vcpu( 5.9 + struct domain *d, unsigned int vcpu_id, unsigned int cpu_id); 5.10 5.11 struct domain *alloc_domain(void); 5.12 void free_domain(struct domain *d);