From: "Jan Beulich" Subject: [PATCH] fix misc issues related to allowing support of more CPUs Date: Fri, 19 Sep 2008 14:01:59 +0100 Message-ID: <48D3BEE7.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This mainly means removing stack variables that (should) depend on NR_CPUS (other than cpumask_t ones) and adjusting certain array sizes. Includes a small improvement (I think) to last_cpu(), and a necessary conversion from BUG_ON() to WARN_ON() in vsnprintf(). There's at least one open tools issue: The 'xm vcpu-pin' path assumes a maximum of 64 CPU-s in many places. Signed-off-by: Jan Beulich Index: 2008-09-19/xen/arch/x86/nmi.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/arch/x86/nmi.c 2008-09-19 13:56:32.000000000 = +0200 +++ 2008-09-19/xen/arch/x86/nmi.c 2008-09-19 13:59:19.000000000 = +0200 @@ -96,7 +96,7 @@ int nmi_active; =20 int __init check_nmi_watchdog (void) { - unsigned int prev_nmi_count[NR_CPUS]; + static unsigned int __initdata prev_nmi_count[NR_CPUS]; int cpu; =20 if ( !nmi_watchdog ) Index: 2008-09-19/xen/arch/x86/smpboot.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/arch/x86/smpboot.c 2008-09-19 13:59:11.0000000= 00 +0200 +++ 2008-09-19/xen/arch/x86/smpboot.c 2008-09-19 13:59:19.000000000 = +0200 @@ -1121,7 +1121,7 @@ static void __init smp_boot_cpus(unsigne Dprintk("CPU present map: %lx\n", physids_coerce(phys_cpu_present_m= ap)); =20 kicked =3D 1; - for (bit =3D 0; kicked < NR_CPUS && bit < MAX_APICS; bit++) { + for (bit =3D 0; kicked < NR_CPUS && bit < NR_CPUS; bit++) { apicid =3D cpu_present_to_apicid(bit); /* * Don't even attempt to start the boot CPU! Index: 2008-09-19/xen/arch/x86/x86_32/domain_page.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/arch/x86/x86_32/domain_page.c 2008-09-19 = 13:56:32.000000000 +0200 +++ 2008-09-19/xen/arch/x86/x86_32/domain_page.c 2008-09-19 = 13:59:19.000000000 +0200 @@ -201,6 +201,9 @@ void *map_domain_page_global(unsigned lo =20 ASSERT(!in_irq() && local_irq_is_enabled()); =20 + /* At least half the ioremap space should be available to us. */ + BUILD_BUG_ON(IOREMAP_VIRT_START + (IOREMAP_MBYTES << 19) >=3D = FIXADDR_START); + spin_lock(&globalmap_lock); =20 idx =3D find_next_zero_bit(inuse, GLOBALMAP_BITS, inuse_cursor); Index: 2008-09-19/xen/common/domctl.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/common/domctl.c 2008-09-19 13:56:32.000000000 = +0200 +++ 2008-09-19/xen/common/domctl.c 2008-09-19 13:59:19.000000000 = +0200 @@ -145,16 +145,23 @@ static unsigned int default_vcpu0_locati { struct domain *d; struct vcpu *v; - unsigned int i, cpu, cnt[NR_CPUS] =3D { 0 }; + unsigned int i, cpu, nr_cpus, *cnt; cpumask_t cpu_exclude_map; =20 /* Do an initial CPU placement. Pick the least-populated CPU. */ - rcu_read_lock(&domlist_read_lock); - for_each_domain ( d ) - for_each_vcpu ( d, v ) - if ( !test_bit(_VPF_down, &v->pause_flags) ) - cnt[v->processor]++; - rcu_read_unlock(&domlist_read_lock); + nr_cpus =3D last_cpu(cpu_possible_map) + 1; + cnt =3D xmalloc_array(unsigned int, nr_cpus); + if ( cnt ) + { + memset(cnt, 0, nr_cpus * sizeof(*cnt)); + + rcu_read_lock(&domlist_read_lock); + for_each_domain ( d ) + for_each_vcpu ( d, v ) + if ( !test_bit(_VPF_down, &v->pause_flags) ) + cnt[v->processor]++; + rcu_read_unlock(&domlist_read_lock); + } =20 /* * If we're on a HT system, we only auto-allocate to a non-primary = HT. We=20 @@ -172,10 +179,12 @@ static unsigned int default_vcpu0_locati (cpus_weight(cpu_sibling_map[i]) > 1) ) continue; cpus_or(cpu_exclude_map, cpu_exclude_map, cpu_sibling_map[i]); - if ( cnt[i] <=3D cnt[cpu] ) + if ( !cnt || cnt[i] <=3D cnt[cpu] ) cpu =3D i; } =20 + xfree(cnt); + return cpu; } =20 Index: 2008-09-19/xen/common/keyhandler.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/common/keyhandler.c 2008-09-19 13:56:32.0000000= 00 +0200 +++ 2008-09-19/xen/common/keyhandler.c 2008-09-19 13:59:19.000000000 = +0200 @@ -172,7 +172,8 @@ static void dump_domains(unsigned char k struct domain *d; struct vcpu *v; s_time_t now =3D NOW(); - char tmpstr[100]; + static char tmpstr[4 * NR_CPUS]; + BUILD_BUG_ON(NR_CPUS > 10000); =20 printk("'%c' pressed -> dumping domain info (now=3D0x%X:%08X)\n", = key, (u32)(now>>32), (u32)now); Index: 2008-09-19/xen/common/sched_credit.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/common/sched_credit.c 2008-09-19 13:56:32.0000000= 00 +0200 +++ 2008-09-19/xen/common/sched_credit.c 2008-09-19 13:59:19.0000000= 00 +0200 @@ -1258,14 +1258,17 @@ csched_dump_pcpu(int cpu) struct csched_pcpu *spc; struct csched_vcpu *svc; int loop; + static char sibling_buf[(NR_CPUS / 32 + 1) * 9]; + static char core_buf[(NR_CPUS / 32 + 1) * 9]; =20 spc =3D CSCHED_PCPU(cpu); runq =3D &spc->runq; =20 - printk(" sort=3D%d, sibling=3D0x%lx, core=3D0x%lx\n", - spc->runq_sort_last, - cpu_sibling_map[cpu].bits[0], - cpu_core_map[cpu].bits[0]); + cpumask_scnprintf(sibling_buf, ARRAY_SIZE(sibling_buf), + cpu_sibling_map[cpu]); + cpumask_scnprintf(core_buf, ARRAY_SIZE(core_buf), cpu_core_map[cpu]); + printk(" sort=3D%d, sibling=3D%s, core=3D%s\n", + spc->runq_sort_last, sibling_buf, core_buf); =20 /* current VCPU */ svc =3D CSCHED_VCPU(per_cpu(schedule_data, cpu).curr); @@ -1292,6 +1295,7 @@ csched_dump(void) { struct list_head *iter_sdom, *iter_svc; int loop; + static char idlers_buf[(NR_CPUS / 32 + 1) * 9]; =20 printk("info:\n" "\tncpus =3D %u\n" @@ -1317,7 +1321,8 @@ csched_dump(void) CSCHED_TICKS_PER_TSLICE, CSCHED_TICKS_PER_ACCT); =20 - printk("idlers: 0x%lx\n", csched_priv.idlers.bits[0]); + cpumask_scnprintf(idlers_buf, ARRAY_SIZE(idlers_buf), csched_priv.idle= rs); + printk("idlers: %s\n", idlers_buf); =20 CSCHED_STATS_PRINTK(); =20 Index: 2008-09-19/xen/common/sched_sedf.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/common/sched_sedf.c 2008-09-19 13:56:32.0000000= 00 +0200 +++ 2008-09-19/xen/common/sched_sedf.c 2008-09-19 13:59:19.000000000 = +0200 @@ -1298,8 +1298,18 @@ static int sedf_adjust_weights(struct xe { struct vcpu *p; struct domain *d; - int sumw[NR_CPUS] =3D { 0 }; - s_time_t sumt[NR_CPUS] =3D { 0 }; + unsigned int nr_cpus =3D last_cpu(cpu_possible_map) + 1; + int *sumw =3D xmalloc_array(int, nr_cpus); + s_time_t *sumt =3D xmalloc_array(s_time_t, nr_cpus); + + if ( !sumw || !sumt ) + { + xfree(sumt); + xfree(sumw); + return -ENOMEM; + } + memset(sumw, 0, nr_cpus * sizeof(*sumw)); + memset(sumt, 0, nr_cpus * sizeof(*sumt)); =20 /* Sum across all weights. */ rcu_read_lock(&domlist_read_lock); @@ -1348,6 +1358,9 @@ static int sedf_adjust_weights(struct xe } rcu_read_unlock(&domlist_read_lock); =20 + xfree(sumt); + xfree(sumw); + return 0; } =20 @@ -1356,6 +1369,7 @@ static int sedf_adjust_weights(struct xe static int sedf_adjust(struct domain *p, struct xen_domctl_scheduler_op = *op) { struct vcpu *v; + int rc; =20 PRINT(2,"sedf_adjust was called, domain-id %i new period %"PRIu64" " "new slice %"PRIu64"\nlatency %"PRIu64" extra:%s\n", @@ -1411,8 +1425,9 @@ static int sedf_adjust(struct domain *p, } } =20 - if ( sedf_adjust_weights(op) ) - return -EINVAL; + rc =3D sedf_adjust_weights(op); + if ( rc ) + return rc; =20 for_each_vcpu ( p, v ) { Index: 2008-09-19/xen/common/vsprintf.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/common/vsprintf.c 2008-09-19 13:56:32.0000000= 00 +0200 +++ 2008-09-19/xen/common/vsprintf.c 2008-09-19 13:59:19.000000000 = +0200 @@ -272,7 +272,11 @@ int vsnprintf(char *buf, size_t size, co /* 'z' changed to 'Z' --davidm 1/25/99 */ =20 /* Reject out-of-range values early */ - BUG_ON((int)size < 0); + if ((int)size < 0 || (unsigned int)size !=3D size) { + static int warn =3D 1; + WARN_ON(warn); + return warn =3D 0; + } =20 str =3D buf; end =3D buf + size - 1; Index: 2008-09-19/xen/include/xen/cpumask.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-09-19.orig/xen/include/xen/cpumask.h 2008-09-19 13:56:32.0000000= 00 +0200 +++ 2008-09-19/xen/include/xen/cpumask.h 2008-09-19 13:59:19.0000000= 00 +0200 @@ -225,8 +225,10 @@ static inline int __next_cpu(int n, cons #define last_cpu(src) __last_cpu(&(src), NR_CPUS) static inline int __last_cpu(const cpumask_t *srcp, int nbits) { - int cpu, pcpu =3D NR_CPUS; - for (cpu =3D first_cpu(*srcp); cpu < NR_CPUS; cpu =3D next_cpu(cpu,= *srcp)) + int cpu, pcpu =3D cpus_weight(*srcp) - 1; + if (pcpu < 0) + pcpu =3D NR_CPUS; + for (cpu =3D pcpu; cpu < NR_CPUS; cpu =3D next_cpu(cpu, *srcp)) pcpu =3D cpu; return pcpu; }