xen: cpupool support - hypervisor support of cpupools
PATCH 1/6 xen: cpupool support - hypervisor support of cpupools
Signed-off-by [email protected]
Signature · 5 lines
Juergen Gross Principal Developer Operating Systems TSP ES&S SWE OS6 Telephone: +49 (0) 89 636 47950 Fujitsu Technolgy Solutions e-mail: [email protected] Otto-Hahn-Ring 6 Internet: ts.fujitsu.com D-81739 Muenchen Company details: ts.fujitsu.com/imprint.html
xen/arch/x86/acpi/cpu_idle.c +5 -5
@@ -198,7 +198,7 @@ static void acpi_processor_idle(void)cpufreq_dbs_timer_suspend (); -sched_tick_suspend (); +sched_tick_suspend (smp_processor_id ());/* * sched_tick_suspend may raise TIMER_SOFTIRQ by __stop_timer, * which will break the later assumption of no sofirq pending,
@@ -216,7 +216,7 @@ static void acpi_processor_idle(void)if (softirq_pending (smp_processor_id ()) ) {local_irq_enable (); -sched_tick_resume (); +sched_tick_resume (smp_processor_id ());cpufreq_dbs_timer_resume ();return ; }
@@ -237,7 +237,7 @@ static void acpi_processor_idle(void)pm_idle_save (); elseacpi_safe_halt (); -sched_tick_resume (); +sched_tick_resume (smp_processor_id ());cpufreq_dbs_timer_resume ();return ; }
@@ -345,7 +345,7 @@ static void acpi_processor_idle(void)default :local_irq_enable (); -sched_tick_resume (); +sched_tick_resume (smp_processor_id ());cpufreq_dbs_timer_resume ();return ; }
@@ -357,7 +357,7 @@ static void acpi_processor_idle(void) cx->time += sleep_ticks; } -sched_tick_resume (); +sched_tick_resume (smp_processor_id ());cpufreq_dbs_timer_resume ();if ( cpuidle_current_governor->reflect )
xen/arch/x86/domain.c +28 -3
@@ -1412,7 +1412,13 @@ struct migrate_info {void (*saved_schedule_tail)(struct vcpu *);cpumask_t saved_affinity;unsigned int nest; +int borrowed; }; + +long continue_hypercall_on_cpu_dummy (void *data) +{ +return 0 ; +}static void continue_hypercall_on_cpu_helper (struct vcpu *v) {
@@ -1420,8 +1426,16 @@ static void continue_hypercall_on_cpu_hestruct migrate_info *info = v->arch.continue_info;cpumask_t mask = info->saved_affinity;void (*saved_schedule_tail)(struct vcpu *) = info->saved_schedule_tail; +int cpu =-1 ; regs->eax = info->func (info->data); + +if ( (info->nest ==0 ) && info->borrowed && + (cpu =cpupool_return_cpu (v->domain->cpupool) >=0 ) ) + { +continue_hypercall_on_cpu (cpu, continue_hypercall_on_cpu_dummy, + info->data); + }if ( info->nest-- ==0 ) {
@@ -1440,27 +1454,32 @@ int continue_hypercall_on_cpu(int cpu, lstruct migrate_info *info;cpumask_t mask =cpumask_of_cpu (cpu);int rc; +int borrowed =0 ;if ( cpu ==smp_processor_id () )return func (data); + borrowed =cpupool_borrow_cpu (v->domain->cpupool, cpu); + info = v->arch.continue_info;if ( info ==NULL ) { info = xmalloc(struct migrate_info); + rc = -ENOMEM ;if ( info ==NULL ) -return -ENOMEM ; + goto out; rc =vcpu_lock_affinity (v, &mask);if ( rc ) {xfree (info); -return rc; + goto out; } info->saved_schedule_tail = v->arch.schedule_tail; info->saved_affinity = mask; info->nest =0 ; + info->borrowed =0 ; v->arch.schedule_tail = continue_hypercall_on_cpu_helper; v->arch.continue_info = info;
@@ -1470,16 +1489,22 @@ int continue_hypercall_on_cpu(int cpu, lBUG_ON (info->nest !=0 ); rc =vcpu_locked_change_affinity (v, &mask);if ( rc ) -return rc; + goto out; info->nest++; } + info->borrowed += borrowed; info->func = func; info->data = data;/* Dummy return value will be overwritten by new schedule_tail. */ BUG_ON (!test_bit (SCHEDULE_SOFTIRQ , &softirq_pending (smp_processor_id ())));return 0 ; + +out: +if ( borrowed ) +cpupool_return_cpu (v->domain->cpupool); +return rc; }#define next_arg (fmt, args) ({ \
xen/arch/x86/domain_build.c +3 -2
@@ -9,6 +9,7 @@#include <xen/lib.h> #include <xen/ctype.h> #include <xen/sched.h> +#include <xen/sched-if.h> #include <xen/smp.h> #include <xen/delay.h> #include <xen/event.h>
@@ -706,13 +707,13 @@ int __init construct_dom0(shared_info (d, vcpu_info[i].evtchn_upcall_mask) =1 ;if ( opt_dom0_max_vcpus ==0 ) - opt_dom0_max_vcpus =num_online_cpus (); + opt_dom0_max_vcpus =num_cpupool_cpus (cpupool0);if ( opt_dom0_max_vcpus >MAX_VIRT_CPUS ) opt_dom0_max_vcpus =MAX_VIRT_CPUS ;printk ("Dom0 has maximum %u VCPUs\n" , opt_dom0_max_vcpus);for ( i =1 ; i < opt_dom0_max_vcpus; i++ ) - (void )alloc_vcpu (d, i, i %num_online_cpus ()); + (void )alloc_vcpu (d, i, i %num_cpupool_cpus (cpupool0));/* Set up CR3 value for write_ptbase */ if (paging_mode_enabled (d) )
xen/arch/x86/mm.c +2 -2
@@ -212,7 +212,7 @@ void __init arch_init_memory(void)* Any Xen-heap pages that we will allow to be mapped will have * their domain field set to dom_xen. */ - dom_xen =domain_create (DOMID_XEN , DOMCRF_dummy,0 ); + dom_xen =domain_create (DOMID_XEN ,CPUPOOLID_NONE , DOMCRF_dummy,0 );BUG_ON (dom_xen ==NULL );/*
@@ -220,7 +220,7 @@ void __init arch_init_memory(void)* This domain owns I/O pages that are within the range of the page_info * array. Mappings occur at the priv of the caller. */ - dom_io =domain_create (DOMID_IO , DOMCRF_dummy,0 ); + dom_io =domain_create (DOMID_IO ,CPUPOOLID_NONE , DOMCRF_dummy,0 );BUG_ON (dom_io ==NULL );/* First 1MB of RAM is historically marked as I/O. */
xen/arch/x86/setup.c +7 -2
@@ -2,6 +2,7 @@#include <xen/init.h> #include <xen/lib.h> #include <xen/sched.h> +#include <xen/sched-if.h> #include <xen/domain.h> #include <xen/serial.h> #include <xen/softirq.h>
@@ -232,7 +233,7 @@ static void __init init_idle_domain(void/* Domain creation requires that scheduler structures are initialised. */ scheduler_init (); - idle_domain =domain_create (IDLE_DOMAIN_ID ,0 ,0 ); + idle_domain =domain_create (IDLE_DOMAIN_ID ,CPUPOOLID_NONE ,0 ,0 );if ( (idle_domain ==NULL ) || (alloc_vcpu (idle_domain,0 ,0 ) ==NULL ) )BUG ();
@@ -995,8 +996,12 @@ void __init __start_xen(unsigned long mbif ( !tboot_protect_mem_regions () )panic ("Could not protect TXT memory regions\n" ); +/* Create initial cpupool 0. */ + cpupool0 =cpupool_create (0 ,NULL ); +if ( (cpupool0 ==NULL ) ||cpupool0_cpu_assign (cpupool0) ) +panic ("Error creating cpupool 0\n" );/* Create initial domain 0. */ - dom0 =domain_create (0 , DOMCRF_s3_integrity,DOM0_SSIDREF ); + dom0 =domain_create (0 ,0 , DOMCRF_s3_integrity,DOM0_SSIDREF );if ( (dom0 ==NULL ) || (alloc_vcpu (dom0,0 ,0 ) ==NULL ) )panic ("Error creating domain 0\n" );
xen/arch/x86/smpboot.c +3 -2
@@ -1265,7 +1265,7 @@ int __cpu_disable(void)/* It's now safe to remove this processor from the online map */ cpu_clear (cpu, cpu_online_map); -cpu_disable_scheduler (); +cpu_disable_scheduler (cpu,0 );return 0 ; }
@@ -1299,7 +1299,7 @@ int cpu_down(unsigned int cpu)int err =0 ;spin_lock (&cpu_add_remove_lock); -if (num_online_cpus () ==1 ) { +if (cpupool_cpu_remove (cpu)) { err = -EBUSY ; goto out; }
@@ -1451,6 +1451,7 @@ int __devinit __cpu_up(unsigned int cpu)process_pending_timers (); } +cpupool_cpu_add (cpu);cpufreq_add_cpu (cpu);return 0 ; }
xen/common/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-y += bitmap.o obj-y += bitmap.o +obj-y += cpupool.o obj-y += domctl.o obj-y += domain.o obj-y += event_channel.o
xen/common/domain.c +7 -2
@@ -187,7 +187,7 @@ struct vcpu *alloc_idle_vcpu(unsigned inreturn v; d = (vcpu_id ==0 ) ? -domain_create (IDLE_DOMAIN_ID ,0 ,0 ) : +domain_create (IDLE_DOMAIN_ID ,CPUPOOLID_NONE ,0 ,0 ) : idle_vcpu[cpu_id - vcpu_id]->domain;BUG_ON (d ==NULL );
@@ -198,7 +198,7 @@ struct vcpu *alloc_idle_vcpu(unsigned in }struct domain *domain_create ( -domid_t domid,unsigned int domcr_flags,ssidref_t ssidref) +domid_t domid,int poolid,unsigned int domcr_flags,ssidref_t ssidref) {struct domain *d, **pd;enum { INIT_xsm =1u <<0 , INIT_rangeset =1u <<1 , INIT_evtchn =1u <<2 ,
@@ -259,6 +259,9 @@ struct domain *domain_create( d->iomem_caps =rangeset_new (d,"I/O Memory" , RANGESETF_prettyprint_hex); d->irq_caps =rangeset_new (d,"Interrupts" ,0 );if ( (d->iomem_caps ==NULL ) || (d->irq_caps ==NULL ) ) + goto fail; + +if (cpupool_add_domain (d, poolid) !=0 ) goto fail;if (sched_init_domain (d) !=0 )
@@ -564,6 +567,8 @@ static void complete_domain_destroy(strusched_destroy_domain (d); +cpupool_rm_domain (d); +/* Free page used by xen oprofile buffer. */ free_xenoprof_pages (d);
xen/common/domctl.c +24 -6
@@ -11,6 +11,7 @@#include <xen/lib.h> #include <xen/mm.h> #include <xen/sched.h> +#include <xen/sched-if.h> #include <xen/domain.h> #include <xen/event.h> #include <xen/domain_page.h>
@@ -138,15 +139,18 @@ void getdomaininfo(struct domain *d, str info->max_pages = d->max_pages; info->shared_info_frame =mfn_to_gmfn (d,__pa (d->shared_info)>>PAGE_SHIFT ); + info->cpupool = d->cpupool ? d->cpupool->cpupool_id :CPUPOOLID_NONE ; +memcpy (info->handle, d->handle,sizeof (xen_domain_handle_t)); } -static unsigned int default_vcpu0_location (void ) +static unsigned int default_vcpu0_location (struct domain *dom) {struct domain *d;struct vcpu *v;unsigned int i, cpu, nr_cpus, *cnt;cpumask_t cpu_exclude_map; +cpumask_t online;/* Do an initial CPU placement. Pick the least-populated CPU. */ nr_cpus =last_cpu (cpu_possible_map) +1 ;
@@ -171,7 +175,8 @@ static unsigned int default_vcpu0_locatiif (cpus_weight (cpu_sibling_map[0 ]) >1 ) cpu =next_cpu (cpu, cpu_sibling_map[0 ]); cpu_exclude_map = cpu_sibling_map[0 ]; -for_each_online_cpu ( i ) + online = (dom->cpupool ==NULL ) ? cpu_online_map : dom->cpupool->cpu_valid; +for_each_cpu_mask (i, online) {if (cpu_isset (i, cpu_exclude_map) )continue ;
@@ -366,12 +371,13 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domcdomid_t dom;static domid_t rover =0 ;unsigned int domcr_flags; +int pool =0 ; ret = -EINVAL ;if ( supervisor_mode_kernel || (op->u.createdomain.flags & ~(XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap | - XEN_DOMCTL_CDF_s3_integrity)) ) + XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_pool)) )break ; dom = op->domain;
@@ -405,9 +411,11 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc domcr_flags |= DOMCRF_hap;if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_s3_integrity ) domcr_flags |= DOMCRF_s3_integrity; +if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_pool ) + pool = op->u.createdomain.cpupool; ret = -ENOMEM ; - d =domain_create (dom, domcr_flags, op->u.createdomain.ssidref); + d =domain_create (dom, pool, domcr_flags, op->u.createdomain.ssidref);if ( d ==NULL )break ;
@@ -426,6 +434,7 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc {struct domain *d;unsigned int i, max = op->u.max_vcpus.max, cpu; +cpumask_t online; ret = -ESRCH ;if ( (d =rcu_lock_domain_by_id (op->domain)) ==NULL )
@@ -455,14 +464,15 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc goto maxvcpu_out; ret = -ENOMEM ; + online = (d->cpupool ==NULL ) ? cpu_online_map : d->cpupool->cpu_valid;for ( i =0 ; i < max; i++ ) {if ( d->vcpu[i] !=NULL )continue ; cpu = (i ==0 ) ? -default_vcpu0_location () : -cycle_cpu (d->vcpu[i-1 ]->processor, cpu_online_map); +default_vcpu0_location (d) : +cycle_cpu (d->vcpu[i-1 ]->processor, online);if (alloc_vcpu (d, i, cpu) ==NULL ) goto maxvcpu_out;
@@ -890,6 +900,14 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc }break ; +case XEN_DOMCTL_cpupool_op: + { + ret =cpupool_do_domctl (op); +if ( (ret ==0 ) &©_to_guest (u_domctl, op,1 ) ) + ret = -EFAULT ; + } +break ; +default : ret =arch_do_domctl (op, u_domctl);break ;
xen/common/sched_credit.c +295 -136
853 lines not on this page · raw message
xen/common/sched_sedf.c +99 -43
245 lines not on this page · raw message
xen/common/schedule.c +222 -62
433 lines not on this page · raw message
xen/include/public/domctl.h +30 -0
@@ -59,7 +59,11 @@ struct xen_domctl_createdomain {/* Should domain memory integrity be verifed by tboot during Sx? */ #define _XEN_DOMCTL_CDF_s3_integrity 2#define XEN_DOMCTL_CDF_s3_integrity (1U<<_XEN_DOMCTL_CDF_s3_integrity) +/* cpupool is specified (0 otherwise) */ +#define _XEN_DOMCTL_CDF_pool 3 +#define XEN_DOMCTL_CDF_pool (1U<<_XEN_DOMCTL_CDF_pool)uint32_t flags; +uint32_t cpupool; };typedef struct xen_domctl_createdomain xen_domctl_createdomain_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_createdomain_t);
@@ -109,6 +113,7 @@ struct xen_domctl_getdomaininfo {uint32_t max_vcpu_id;/* Maximum VCPUID in use by this domain. */ uint32_t ssidref;xen_domain_handle_t handle; +uint32_t cpupool; };typedef struct xen_domctl_getdomaininfo xen_domctl_getdomaininfo_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_getdomaininfo_t);
@@ -645,6 +650,30 @@ typedef struct xen_domctl_hvmcontext_parXEN_GUEST_HANDLE_64 (uint8) buffer;/* OUT: buffer to write record into */ } xen_domctl_hvmcontext_partial_t;DEFINE_XEN_GUEST_HANDLE (xen_domctl_hvmcontext_partial_t); + +/* +* Move domain to specified cpupool. +*/ +#define XEN_DOMCTL_cpupool_op 56 +#define XEN_DOMCTL_CPUPOOL_OP_CREATE 1/* C */ +#define XEN_DOMCTL_CPUPOOL_OP_DESTROY 2/* D */ +#define XEN_DOMCTL_CPUPOOL_OP_INFO 3/* I */ +#define XEN_DOMCTL_CPUPOOL_OP_ADDCPU 4/* A */ +#define XEN_DOMCTL_CPUPOOL_OP_RMCPU 5/* R */ +#define XEN_DOMCTL_CPUPOOL_OP_MOVEDOMAIN 6/* M */ +#define XEN_DOMCTL_CPUPOOL_OP_FREEINFO 7/* F */ +#define XEN_DOMCTL_CPUPOOL_PAR_ANY 0xFFFFFFFF +struct xen_domctl_cpupool_op { +uint32_t op;/* IN */ +uint32_t cpupool_id;/* IN: CDIARM OUT: CI */ +uint32_t sched_id;/* IN: C OUT: I */ +uint32_t domid;/* IN: M */ +uint32_t cpu;/* IN: AR */ +uint32_t n_dom;/* OUT: I */ +struct xenctl_cpumap cpumap;/* OUT: IF */ +}; +typedef struct xen_domctl_cpupool_op xen_domctl_cpupool_op_t ; +DEFINE_XEN_GUEST_HANDLE (xen_domctl_cpupool_op_t);struct xen_domctl {
@@ -688,6 +717,7 @@ struct xen_domctl {struct xen_domctl_set_target set_target;struct xen_domctl_subscribe subscribe;struct xen_domctl_debug_op debug_op; +struct xen_domctl_cpupool_op cpupool_op;#if defined(__i386__) || defined(__x86_64__)struct xen_domctl_cpuid cpuid;#endif
xen/include/xen/sched-if.h +45 -14
88 lines not on this page · raw message
xen/include/xen/sched.h +26 -4
@@ -182,6 +182,7 @@ struct domain/* Scheduling. */ void *sched_priv;/* scheduler-specific data */ +struct cpupool *cpupool;struct domain *next_in_list;struct domain *next_in_hashbucket;
@@ -341,7 +342,7 @@ static inline struct domain *get_current }struct domain *domain_create ( -domid_t domid,unsigned int domcr_flags,ssidref_t ssidref); +domid_t domid,int poolid,unsigned int domcr_flags,ssidref_t ssidref);/* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */ #define _DOMCRF_hvm 0#define DOMCRF_hvm (1U<<_DOMCRF_hvm)
@@ -426,10 +427,11 @@ void sched_destroy_vcpu(struct vcpu *v);void sched_destroy_vcpu (struct vcpu *v);int sched_init_domain (struct domain *d);void sched_destroy_domain (struct domain *d); +void sched_move_domain (struct domain *d,struct cpupool *c);long sched_adjust (struct domain *,struct xen_domctl_scheduler_op *);int sched_id (void ); -void sched_tick_suspend (void ); -void sched_tick_resume (void ); +void sched_tick_suspend (unsigned int cpu); +void sched_tick_resume (unsigned int cpu);void vcpu_wake (struct vcpu *d);void vcpu_sleep_nosync (struct vcpu *d);void vcpu_sleep_sync (struct vcpu *d);
@@ -533,8 +535,13 @@ void domain_unpause_by_systemcontroller(void domain_unpause_by_systemcontroller (struct domain *d);void cpu_init (void ); +struct scheduler ; + +int schedule_init_global (char *name,struct scheduler *sched); +void schedule_deinit_global (struct scheduler *sched); +void schedule_cpu_switch (unsigned int cpu,struct cpupool *c);void vcpu_force_reschedule (struct vcpu *v); -void cpu_disable_scheduler (void ); +int cpu_disable_scheduler (unsigned int cpu,int lock);int vcpu_set_affinity (struct vcpu *v,cpumask_t *affinity);int vcpu_lock_affinity (struct vcpu *v,cpumask_t *affinity);int vcpu_locked_change_affinity (struct vcpu *v,cpumask_t *affinity);
@@ -560,6 +567,21 @@ extern enum cpufreq_controller {extern enum cpufreq_controller { FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen } cpufreq_controller; + +#define CPUPOOLID_NONE -1 + +struct cpupool *cpupool_create (int poolid,char *sched); +int cpupool_destroy (struct cpupool *c); +int cpupool0_cpu_assign (struct cpupool *c); +int cpupool_assign_ncpu (struct cpupool *c,int ncpu); +void cpupool_cpu_add (unsigned int cpu); +int cpupool_cpu_remove (unsigned int cpu); +int cpupool_borrow_cpu (struct cpupool *c,unsigned int cpu); +int cpupool_return_cpu (struct cpupool *c); +int cpupool_add_domain (struct domain *d,int poolid); +void cpupool_rm_domain (struct domain *d); +int cpupool_do_domctl (struct xen_domctl *op); +#define num_cpupool_cpus (c) (cpus_weight((c)->cpu_valid))#endif /* __SCHED_H__ */
xen/common/cpupool.c new file +698 -0
698 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel