Skip to contentSkip to conversation

introduce and use nr_cpu_ids and nr_cpumask_bits

PATCH In review Jan Beulich 1 participant 1 message Oct 20, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/12 introduce and use nr_cpu_ids and nr_cpumask_bits

The former is the runtime equivalent of NR_CPUS (and users of NR_CPUS, where necessary, get adjusted accordingly), while the latter is for the sole use of determining the allocation size when dynamically allocating CPU masks (done later in this series).

Adjust accessors to use either of the two to bound their bitmap operations - which one gets used depends on whether accessing the bits in the gap between nr_cpu_ids and nr_cpumask_bits is benign but more efficient.

xen/arch/x86/acpi/cpu_idle.c +1 -1
@@ -900,7 +900,7 @@ int get_cpu_id(u32 acpi_id)
     if ( apic_id == BAD_APICID )
         return -1;
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for ( i = 0; i < nr_cpu_ids; i++ )
     {
         if ( apic_id == x86_cpu_to_apicid[i] )
             return i;
xen/arch/x86/acpi/cpufreq/cpufreq.c +1 -1
@@ -209,7 +209,7 @@ static u32 get_cur_val(const cpumask_t *
 
     if (!cpumask_test_cpu(cpu, mask))
         cpu = cpumask_first(mask);
-    if (cpu >= NR_CPUS || !cpu_online(cpu))
+    if (cpu >= nr_cpu_ids || !cpu_online(cpu))
         return 0;
 
     policy = per_cpu(cpufreq_cpu_policy, cpu);
xen/arch/x86/acpi/lib.c +1 -1
@@ -95,7 +95,7 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, 
 
 	if (!(acpi_id + 1))
 		c = &boot_cpu_data;
-	else if (cpu >= NR_CPUS || !cpu_online(cpu))
+	else if (cpu >= nr_cpu_ids || !cpu_online(cpu))
 		return -EINVAL;
 	else
 		c = cpu_data + cpu;
xen/arch/x86/cpu/common.c +1 -1
@@ -532,7 +532,7 @@ void __cpuinit detect_ht(struct cpuinfo_
 		printk(KERN_INFO  "CPU: Hyper-Threading is disabled\n");
 	} else if (c->x86_num_siblings > 1 ) {
 
-		if (c->x86_num_siblings > NR_CPUS) {
+		if (c->x86_num_siblings > nr_cpu_ids) {
 			printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", c->x86_num_siblings);
 			c->x86_num_siblings = 1;
 			return;
xen/arch/x86/cpu/mcheck/mce.c +2 -2
@@ -1487,7 +1487,7 @@ long do_mca(XEN_GUEST_HANDLE(xen_mc_t) u
         mc_msrinject = &op->u.mc_msrinject;
         target = mc_msrinject->mcinj_cpunr;
 
-        if (target >= NR_CPUS)
+        if (target >= nr_cpu_ids)
             return x86_mcerr("do_mca inject: bad target", -EINVAL);
 
         if (!cpu_online(target))
@@ -1514,7 +1514,7 @@ long do_mca(XEN_GUEST_HANDLE(xen_mc_t) u
         mc_mceinject = &op->u.mc_mceinject;
         target = mc_mceinject->mceinj_cpunr;
 
-        if (target >= NR_CPUS)
+        if (target >= nr_cpu_ids)
             return x86_mcerr("do_mca #MC: bad target", -EINVAL);
 
         if (!cpu_online(target))
xen/arch/x86/microcode.c +1 -1
@@ -126,7 +126,7 @@ static long do_microcode_update(void *_i
         info->error = error;
 
     info->cpu = next_cpu(info->cpu, cpu_online_map);
-    if ( info->cpu < NR_CPUS )
+    if ( info->cpu < nr_cpu_ids )
         return continue_hypercall_on_cpu(info->cpu, do_microcode_update, info);
 
     error = info->error;
xen/arch/x86/mpparse.c +29 -4
@@ -28,6 +28,7 @@
 #include <asm/mtrr.h>
 #include <asm/mpspec.h>
 #include <asm/io_apic.h>
+#include <asm/setup.h>
 
 #include <mach_apic.h>
 #include <mach_mpparse.h>
@@ -61,10 +62,31 @@ unsigned int __read_mostly boot_cpu_phys
 
 /* Internal processor count */
 static unsigned int __devinitdata num_processors;
+static unsigned int __initdata disabled_cpus;
 
 /* Bitmask of physically existing CPUs */
 physid_mask_t phys_cpu_present_map;
 
+void __init set_nr_cpu_ids(unsigned int max_cpus)
+{
+	if (!max_cpus)
+		max_cpus = num_processors + disabled_cpus;
+	if (max_cpus > NR_CPUS)
+		max_cpus = NR_CPUS;
+	else if (!max_cpus)
+		max_cpus = 1;
+	printk(XENLOG_INFO "SMP: Allowing %u CPUs (%d hotplug CPUs)\n",
+	       max_cpus, max_t(int, max_cpus - num_processors, 0));
+	nr_cpu_ids = max_cpus;
+
+#ifndef nr_cpumask_bits
+	nr_cpumask_bits = (max_cpus + (BITS_PER_LONG - 1)) &
+			  ~(BITS_PER_LONG - 1);
+	printk(XENLOG_DEBUG "NR_CPUS:%u nr_cpumask_bits:%u\n",
+	       NR_CPUS, nr_cpumask_bits);
+#endif
+}
+
 /*
  * Intel MP BIOS table parsing routines:
  */
@@ -90,8 +112,11 @@ static int __devinit MP_processor_info_x
 {
  	int ver, apicid, cpu = 0;
  	
-	if (!(m->mpc_cpuflag & CPU_ENABLED))
+	if (!(m->mpc_cpuflag & CPU_ENABLED)) {
+		if (!hotplug)
+			++disabled_cpus;
 		return -EINVAL;
+	}
 
 	apicid = mpc_apic_id(m, apicidx);
 
@@ -115,9 +140,9 @@ static int __devinit MP_processor_info_x
 
 	set_apicid(apicid, &phys_cpu_present_map);
 
-	if (num_processors >= NR_CPUS) {
-		printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
-			"  Processor ignored.\n", NR_CPUS);
+	if (num_processors >= nr_cpu_ids) {
+		printk(KERN_WARNING "WARNING: NR_CPUS limit of %u reached."
+			"  Processor ignored.\n", nr_cpu_ids);
 		return -ENOSPC;
 	}
 
xen/arch/x86/numa.c +3 -3
@@ -198,7 +198,7 @@ void __init numa_init_array(void)
 	   CPUs, as the number of CPUs is not known yet. 
 	   We round robin the existing nodes. */
 	rr = first_node(node_online_map);
-	for (i = 0; i < NR_CPUS; i++) {
+	for (i = 0; i < nr_cpu_ids; i++) {
 		if (cpu_to_node[i] != NUMA_NO_NODE)
 			continue;
  		numa_set_node(i, rr);
@@ -280,7 +280,7 @@ void __init numa_initmem_init(unsigned l
 	memnodemap = _memnodemap;
 	nodes_clear(node_online_map);
 	node_set_online(0);
-	for (i = 0; i < NR_CPUS; i++)
+	for (i = 0; i < nr_cpu_ids; i++)
 		numa_set_node(i, 0);
 	node_to_cpumask[0] = cpumask_of_cpu(0);
 	setup_node_bootmem(0, (u64)start_pfn << PAGE_SHIFT, (u64)end_pfn << PAGE_SHIFT);
@@ -335,7 +335,7 @@ static __init int numa_setup(char *opt) 
 void __init init_cpu_to_node(void)
 {
 	int i, node;
- 	for (i = 0; i < NR_CPUS; i++) {
+ 	for (i = 0; i < nr_cpu_ids; i++) {
 		u32 apicid = x86_cpu_to_apicid[i];
 		if (apicid == BAD_APICID)
 			continue;
xen/arch/x86/oprofile/nmi_int.c +1 -1
@@ -127,7 +127,7 @@ static void nmi_save_registers(void * du
 static void free_msrs(void)
 {
 	int i;
-	for (i = 0; i < NR_CPUS; ++i) {
+	for (i = 0; i < nr_cpu_ids; ++i) {
 		xfree(cpu_msrs[i].counters);
 		cpu_msrs[i].counters = NULL;
 		xfree(cpu_msrs[i].controls);
xen/arch/x86/platform_hypercall.c +1 -1
@@ -442,7 +442,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
             break;
         }
 
-        if ( (g_info->xen_cpuid >= NR_CPUS) ||
+        if ( (g_info->xen_cpuid >= nr_cpu_ids) ||
              !cpu_present(g_info->xen_cpuid) )
         {
             g_info->flags |= XEN_PCPU_FLAGS_INVALID;
xen/arch/x86/setup.c +15 -7
@@ -51,7 +51,7 @@ static bool_t __initdata opt_nosmp;
 boolean_param("nosmp", opt_nosmp);
 
 /* maxcpus: maximum number of CPUs to activate. */
-static unsigned int __initdata max_cpus = NR_CPUS;
+static unsigned int __initdata max_cpus;
 integer_param("maxcpus", max_cpus);
 
 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
@@ -230,7 +230,7 @@ static void __init normalise_cpu_order(v
          * Among identical longest-prefix matches, pick the smallest APIC ID.
          */
         for ( j = next_cpu(i, cpu_present_map);
-              j < NR_CPUS;
+              j < nr_cpu_ids;
               j = next_cpu(j, cpu_present_map) )
         {
             diff = x86_cpu_to_apicid[j] ^ apicid;
@@ -246,9 +246,9 @@ static void __init normalise_cpu_order(v
         }
 
         /* If no match then there must be no CPUs remaining to consider. */
-        if ( min_cpu >= NR_CPUS )
+        if ( min_cpu >= nr_cpu_ids )
         {
-            BUG_ON(next_cpu(i, cpu_present_map) < NR_CPUS);
+            BUG_ON(next_cpu(i, cpu_present_map) < nr_cpu_ids);
             break;
         }
 
@@ -1203,6 +1203,17 @@ void __init __start_xen(unsigned long mb
     if ( smp_found_config )
         get_smp_config();
 
+    if ( opt_nosmp )
+    {
+        max_cpus = 0;
+        set_nr_cpu_ids(1);
+    }
+    else
+    {
+        set_nr_cpu_ids(max_cpus);
+        max_cpus = nr_cpu_ids;
+    }
+
 #ifdef CONFIG_X86_64
     /* Low mappings were only needed for some BIOS table parsing. */
     zap_low_mappings();
@@ -1254,9 +1265,6 @@ void __init __start_xen(unsigned long mb
     acpi_mmcfg_init();
 #endif
 
-    if ( opt_nosmp )
-        max_cpus = 0;
-
     iommu_setup();    /* setup iommu if available */
 
     smp_prepare_cpus(max_cpus);
xen/arch/x86/smpboot.c +1 -1
@@ -535,7 +535,7 @@ int alloc_cpu_id(void)
     int cpu;
     cpus_complement(tmp_map, cpu_present_map);
     cpu = first_cpu(tmp_map);
-    return (cpu < NR_CPUS) ? cpu : -ENODEV;
+    return (cpu < nr_cpu_ids) ? cpu : -ENODEV;
 }
 
 static int do_boot_cpu(int apicid, int cpu)
xen/arch/x86/srat.c +1 -1
@@ -447,7 +447,7 @@ int __init acpi_scan_nodes(u64 start, u6
 			continue;
 		setup_node_bootmem(i, nodes[i].start, nodes[i].end);
 	}
-	for (i = 0; i < NR_CPUS; i++) { 
+	for (i = 0; i < nr_cpu_ids; i++) {
 		if (cpu_to_node[i] == NUMA_NO_NODE)
 			continue;
 		if (!node_isset(cpu_to_node[i], nodes_parsed))
xen/arch/x86/sysctl.c +1 -1
@@ -82,7 +82,7 @@ long arch_do_sysctl(
         pi->nr_cpus = num_online_cpus();
         pi->nr_nodes = num_online_nodes();
         pi->max_node_id = MAX_NUMNODES-1;
-        pi->max_cpu_id = NR_CPUS-1;
+        pi->max_cpu_id = nr_cpu_ids - 1;
         pi->total_pages = total_pages;
         pi->free_pages = avail_domheap_pages();
         pi->scrub_pages = 0;
xen/arch/x86/tboot.c +1 -1
@@ -248,7 +248,7 @@ static int mfn_in_guarded_stack(unsigned
     void *p;
     int i;
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for ( i = 0; i < nr_cpu_ids; i++ )
     {
         if ( !stack_base[i] )
             continue;
xen/arch/x86/traps.c +1 -1
@@ -3412,7 +3412,7 @@ static void __set_intr_gate(unsigned int
 {
     int i;
     /* Keep secondary tables in sync with IRQ updates. */
-    for ( i = 1; i < NR_CPUS; i++ )
+    for ( i = 1; i < nr_cpu_ids; i++ )
         if ( idt_tables[i] != NULL )
             _set_gate(&idt_tables[i][n], 14, dpl, addr);
     _set_gate(&idt_table[n], 14, dpl, addr);
xen/common/cpu.c +8 -2
@@ -6,6 +6,12 @@
 #include <xen/sched.h>
 #include <xen/stop_machine.h>
 
+unsigned int __read_mostly nr_cpu_ids = NR_CPUS;
+#ifndef nr_cpumask_bits
+unsigned int __read_mostly nr_cpumask_bits
+    = BITS_TO_LONGS(NR_CPUS) * BITS_PER_LONG;
+#endif
+
 /*
  * cpu_bit_bitmap[] is a special, "compressed" data structure that
  * represents all NR_CPUS bits binary values of 1<<nr.
@@ -80,7 +86,7 @@ int cpu_down(unsigned int cpu)
     if ( !cpu_hotplug_begin() )
         return -EBUSY;
 
-    if ( (cpu >= NR_CPUS) || (cpu == 0) || !cpu_online(cpu) )
+    if ( (cpu >= nr_cpu_ids) || (cpu == 0) || !cpu_online(cpu) )
     {
         cpu_hotplug_done();
         return -EINVAL;
@@ -122,7 +128,7 @@ int cpu_up(unsigned int cpu)
     if ( !cpu_hotplug_begin() )
         return -EBUSY;
 
-    if ( (cpu >= NR_CPUS) || cpu_online(cpu) || !cpu_present(cpu) )
+    if ( (cpu >= nr_cpu_ids) || cpu_online(cpu) || !cpu_present(cpu) )
     {
         cpu_hotplug_done();
         return -EINVAL;
xen/common/cpupool.c +2 -2
@@ -489,7 +489,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
         if ( cpu == XEN_SYSCTL_CPUPOOL_PAR_ANY )
             cpu = first_cpu(cpupool_free_cpus);
         ret = -EINVAL;
-        if ( cpu >= NR_CPUS )
+        if ( cpu >= nr_cpu_ids )
             goto addcpu_out;
         ret = -EBUSY;
         if ( !cpu_isset(cpu, cpupool_free_cpus) )
@@ -517,7 +517,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
         cpu = op->cpu;
         if ( cpu == XEN_SYSCTL_CPUPOOL_PAR_ANY )
             cpu = last_cpu(c->cpu_valid);
-        ret = (cpu < NR_CPUS) ? cpupool_unassign_cpu(c, cpu) : -EINVAL;
+        ret = (cpu < nr_cpu_ids) ? cpupool_unassign_cpu(c, cpu) : -EINVAL;
         cpupool_put(c);
     }
     break;
xen/common/domain.c +1 -1
@@ -1023,7 +1023,7 @@ int continue_hypercall_on_cpu(
 {
     struct migrate_info *info;
 
-    if ( (cpu >= NR_CPUS) || !cpu_online(cpu) )
+    if ( (cpu >= nr_cpu_ids) || !cpu_online(cpu) )
         return -EINVAL;
 
     info = this_cpu(continue_info);
xen/common/kexec.c +1 -1
@@ -296,7 +296,7 @@ static int kexec_get_cpu(xen_kexec_range
     int nr = range->nr;
     int nr_bytes = 0;
 
-    if ( nr < 0 || nr >= NR_CPUS || !cpu_online(nr) )
+    if ( nr < 0 || nr >= nr_cpu_ids || !cpu_online(nr) )
         return -EINVAL;
 
     nr_bytes += sizeof_note("CORE", sizeof(ELF_Prstatus));
xen/common/keyhandler.c +1 -1
@@ -98,7 +98,7 @@ void dump_execstate(struct cpu_user_regs
         return;
 
     cpu = cycle_cpu(cpu, dump_execstate_mask);
-    if ( cpu < NR_CPUS )
+    if ( cpu < nr_cpu_ids )
     {
         smp_send_state_dump(cpu);
         return;
xen/common/sched_credit.c +1 -1
@@ -374,7 +374,7 @@ csched_alloc_pdata(const struct schedule
 
     INIT_LIST_HEAD(&spc->runq);
     spc->runq_sort_last = prv->runq_sort;
-    spc->idle_bias = NR_CPUS - 1;
+    spc->idle_bias = nr_cpu_ids - 1;
     if ( per_cpu(schedule_data, cpu).sched_priv == NULL )
         per_cpu(schedule_data, cpu).sched_priv = spc;
 
xen/common/sched_credit2.c +1 -1
@@ -2071,7 +2071,7 @@ csched_init(struct scheduler *ops)
     INIT_LIST_HEAD(&prv->sdom);
 
     /* But un-initialize all runqueues */
-    for ( i=0; i<NR_CPUS; i++)
+    for ( i = 0; i < nr_cpu_ids; i++ )
     {
         prv->runq_map[i] = -1;
         prv->rqd[i].id = -1;
xen/common/sched_sedf.c +1 -1
@@ -1201,7 +1201,7 @@ static void sedf_wake(const struct sched
       routine. Try to avoid unnecessary runs but:
       Save approximation: Always switch to scheduler!*/
     ASSERT(d->processor >= 0);
-    ASSERT(d->processor < NR_CPUS);
+    ASSERT(d->processor < nr_cpu_ids);
     ASSERT(per_cpu(schedule_data, d->processor).curr);
 
     if ( should_switch(per_cpu(schedule_data, d->processor).curr, d, now) )
xen/common/schedule.c +1 -1
@@ -1353,7 +1353,7 @@ void __init scheduler_init(void)
     idle_domain = domain_create(DOMID_IDLE, 0, 0);
     BUG_ON(idle_domain == NULL);
     idle_domain->vcpu = idle_vcpu;
-    idle_domain->max_vcpus = NR_CPUS;
+    idle_domain->max_vcpus = nr_cpu_ids;
     if ( alloc_vcpu(idle_domain, 0, 0) == NULL )
         BUG();
     if ( ops.alloc_pdata &&
xen/common/sysctl.c +1 -1
@@ -183,7 +183,7 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
         uint32_t i, nr_cpus;
         struct xen_sysctl_cpuinfo cpuinfo;
 
-        nr_cpus = min_t(uint32_t, op->u.getcpuinfo.max_cpus, NR_CPUS);
+        nr_cpus = min(op->u.getcpuinfo.max_cpus, nr_cpu_ids);
 
         ret = xsm_getcpuinfo();
         if ( ret )
xen/drivers/acpi/pmstat.c +1 -1
@@ -53,7 +53,7 @@ int do_get_pm_info(struct xen_sysctl_get
     int ret = 0;
     const struct processor_pminfo *pmpt;
 
-    if ( !op || (op->cpuid >= NR_CPUS) || !cpu_online(op->cpuid) )
+    if ( !op || (op->cpuid >= nr_cpu_ids) || !cpu_online(op->cpuid) )
         return -EINVAL;
     pmpt = processor_pminfo[op->cpuid];
 
xen/include/asm-x86/setup.h +2 -0
@@ -20,6 +20,8 @@ int nsc_init_cpu(void);
 int centaur_init_cpu(void);
 int transmeta_init_cpu(void);
 
+void set_nr_cpu_ids(unsigned int max_cpus);
+
 void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
 void arch_init_memory(void);
 void subarch_init_memory(void);
xen/include/xen/cpumask.h +73 -36

269 lines not on this page · raw message

introduce and use nr_cpu_ids and nr_cpumask_bits

The former is the runtime equivalent of NR_CPUS (and users of NR_CPUS, where necessary, get adjusted accordingly), while the latter is for the sole use of determining the allocation size when dynamically allocating CPU masks (done later in this series).

Adjust accessors to use either of the two to bound their bitmap operations - which one gets used depends on whether accessing the bits in the gap between nr_cpu_ids and nr_cpumask_bits is benign but more efficient.

xen/arch/x86/acpi/cpu_idle.c +1 -1
@@ -900,7 +900,7 @@ int get_cpu_id(u32 acpi_id)
     if ( apic_id == BAD_APICID )
         return -1;
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for ( i = 0; i < nr_cpu_ids; i++ )
     {
         if ( apic_id == x86_cpu_to_apicid[i] )
             return i;
xen/arch/x86/acpi/cpufreq/cpufreq.c +1 -1
@@ -209,7 +209,7 @@ static u32 get_cur_val(const cpumask_t *
 
     if (!cpumask_test_cpu(cpu, mask))
         cpu = cpumask_first(mask);
-    if (cpu >= NR_CPUS || !cpu_online(cpu))
+    if (cpu >= nr_cpu_ids || !cpu_online(cpu))
         return 0;
 
     policy = per_cpu(cpufreq_cpu_policy, cpu);
xen/arch/x86/acpi/lib.c +1 -1
@@ -95,7 +95,7 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, 
 
 	if (!(acpi_id + 1))
 		c = &boot_cpu_data;
-	else if (cpu >= NR_CPUS || !cpu_online(cpu))
+	else if (cpu >= nr_cpu_ids || !cpu_online(cpu))
 		return -EINVAL;
 	else
 		c = cpu_data + cpu;
xen/arch/x86/cpu/common.c +1 -1
@@ -532,7 +532,7 @@ void __cpuinit detect_ht(struct cpuinfo_
 		printk(KERN_INFO  "CPU: Hyper-Threading is disabled\n");
 	} else if (c->x86_num_siblings > 1 ) {
 
-		if (c->x86_num_siblings > NR_CPUS) {
+		if (c->x86_num_siblings > nr_cpu_ids) {
 			printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", c->x86_num_siblings);
 			c->x86_num_siblings = 1;
 			return;
xen/arch/x86/cpu/mcheck/mce.c +2 -2
@@ -1487,7 +1487,7 @@ long do_mca(XEN_GUEST_HANDLE(xen_mc_t) u
         mc_msrinject = &op->u.mc_msrinject;
         target = mc_msrinject->mcinj_cpunr;
 
-        if (target >= NR_CPUS)
+        if (target >= nr_cpu_ids)
             return x86_mcerr("do_mca inject: bad target", -EINVAL);
 
         if (!cpu_online(target))
@@ -1514,7 +1514,7 @@ long do_mca(XEN_GUEST_HANDLE(xen_mc_t) u
         mc_mceinject = &op->u.mc_mceinject;
         target = mc_mceinject->mceinj_cpunr;
 
-        if (target >= NR_CPUS)
+        if (target >= nr_cpu_ids)
             return x86_mcerr("do_mca #MC: bad target", -EINVAL);
 
         if (!cpu_online(target))
xen/arch/x86/microcode.c +1 -1
@@ -126,7 +126,7 @@ static long do_microcode_update(void *_i
         info->error = error;
 
     info->cpu = next_cpu(info->cpu, cpu_online_map);
-    if ( info->cpu < NR_CPUS )
+    if ( info->cpu < nr_cpu_ids )
         return continue_hypercall_on_cpu(info->cpu, do_microcode_update, info);
 
     error = info->error;
xen/arch/x86/mpparse.c +29 -4
@@ -28,6 +28,7 @@
 #include <asm/mtrr.h>
 #include <asm/mpspec.h>
 #include <asm/io_apic.h>
+#include <asm/setup.h>
 
 #include <mach_apic.h>
 #include <mach_mpparse.h>
@@ -61,10 +62,31 @@ unsigned int __read_mostly boot_cpu_phys
 
 /* Internal processor count */
 static unsigned int __devinitdata num_processors;
+static unsigned int __initdata disabled_cpus;
 
 /* Bitmask of physically existing CPUs */
 physid_mask_t phys_cpu_present_map;
 
+void __init set_nr_cpu_ids(unsigned int max_cpus)
+{
+	if (!max_cpus)
+		max_cpus = num_processors + disabled_cpus;
+	if (max_cpus > NR_CPUS)
+		max_cpus = NR_CPUS;
+	else if (!max_cpus)
+		max_cpus = 1;
+	printk(XENLOG_INFO "SMP: Allowing %u CPUs (%d hotplug CPUs)\n",
+	       max_cpus, max_t(int, max_cpus - num_processors, 0));
+	nr_cpu_ids = max_cpus;
+
+#ifndef nr_cpumask_bits
+	nr_cpumask_bits = (max_cpus + (BITS_PER_LONG - 1)) &
+			  ~(BITS_PER_LONG - 1);
+	printk(XENLOG_DEBUG "NR_CPUS:%u nr_cpumask_bits:%u\n",
+	       NR_CPUS, nr_cpumask_bits);
+#endif
+}
+
 /*
  * Intel MP BIOS table parsing routines:
  */
@@ -90,8 +112,11 @@ static int __devinit MP_processor_info_x
 {
  	int ver, apicid, cpu = 0;
  	
-	if (!(m->mpc_cpuflag & CPU_ENABLED))
+	if (!(m->mpc_cpuflag & CPU_ENABLED)) {
+		if (!hotplug)
+			++disabled_cpus;
 		return -EINVAL;
+	}
 
 	apicid = mpc_apic_id(m, apicidx);
 
@@ -115,9 +140,9 @@ static int __devinit MP_processor_info_x
 
 	set_apicid(apicid, &phys_cpu_present_map);
 
-	if (num_processors >= NR_CPUS) {
-		printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
-			"  Processor ignored.\n", NR_CPUS);
+	if (num_processors >= nr_cpu_ids) {
+		printk(KERN_WARNING "WARNING: NR_CPUS limit of %u reached."
+			"  Processor ignored.\n", nr_cpu_ids);
 		return -ENOSPC;
 	}
 
xen/arch/x86/numa.c +3 -3
@@ -198,7 +198,7 @@ void __init numa_init_array(void)
 	   CPUs, as the number of CPUs is not known yet. 
 	   We round robin the existing nodes. */
 	rr = first_node(node_online_map);
-	for (i = 0; i < NR_CPUS; i++) {
+	for (i = 0; i < nr_cpu_ids; i++) {
 		if (cpu_to_node[i] != NUMA_NO_NODE)
 			continue;
  		numa_set_node(i, rr);
@@ -280,7 +280,7 @@ void __init numa_initmem_init(unsigned l
 	memnodemap = _memnodemap;
 	nodes_clear(node_online_map);
 	node_set_online(0);
-	for (i = 0; i < NR_CPUS; i++)
+	for (i = 0; i < nr_cpu_ids; i++)
 		numa_set_node(i, 0);
 	node_to_cpumask[0] = cpumask_of_cpu(0);
 	setup_node_bootmem(0, (u64)start_pfn << PAGE_SHIFT, (u64)end_pfn << PAGE_SHIFT);
@@ -335,7 +335,7 @@ static __init int numa_setup(char *opt) 
 void __init init_cpu_to_node(void)
 {
 	int i, node;
- 	for (i = 0; i < NR_CPUS; i++) {
+ 	for (i = 0; i < nr_cpu_ids; i++) {
 		u32 apicid = x86_cpu_to_apicid[i];
 		if (apicid == BAD_APICID)
 			continue;
xen/arch/x86/oprofile/nmi_int.c +1 -1
@@ -127,7 +127,7 @@ static void nmi_save_registers(void * du
 static void free_msrs(void)
 {
 	int i;
-	for (i = 0; i < NR_CPUS; ++i) {
+	for (i = 0; i < nr_cpu_ids; ++i) {
 		xfree(cpu_msrs[i].counters);
 		cpu_msrs[i].counters = NULL;
 		xfree(cpu_msrs[i].controls);
xen/arch/x86/platform_hypercall.c +1 -1
@@ -442,7 +442,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
             break;
         }
 
-        if ( (g_info->xen_cpuid >= NR_CPUS) ||
+        if ( (g_info->xen_cpuid >= nr_cpu_ids) ||
              !cpu_present(g_info->xen_cpuid) )
         {
             g_info->flags |= XEN_PCPU_FLAGS_INVALID;
xen/arch/x86/setup.c +15 -7
@@ -51,7 +51,7 @@ static bool_t __initdata opt_nosmp;
 boolean_param("nosmp", opt_nosmp);
 
 /* maxcpus: maximum number of CPUs to activate. */
-static unsigned int __initdata max_cpus = NR_CPUS;
+static unsigned int __initdata max_cpus;
 integer_param("maxcpus", max_cpus);
 
 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
@@ -230,7 +230,7 @@ static void __init normalise_cpu_order(v
          * Among identical longest-prefix matches, pick the smallest APIC ID.
          */
         for ( j = next_cpu(i, cpu_present_map);
-              j < NR_CPUS;
+              j < nr_cpu_ids;
               j = next_cpu(j, cpu_present_map) )
         {
             diff = x86_cpu_to_apicid[j] ^ apicid;
@@ -246,9 +246,9 @@ static void __init normalise_cpu_order(v
         }
 
         /* If no match then there must be no CPUs remaining to consider. */
-        if ( min_cpu >= NR_CPUS )
+        if ( min_cpu >= nr_cpu_ids )
         {
-            BUG_ON(next_cpu(i, cpu_present_map) < NR_CPUS);
+            BUG_ON(next_cpu(i, cpu_present_map) < nr_cpu_ids);
             break;
         }
 
@@ -1203,6 +1203,17 @@ void __init __start_xen(unsigned long mb
     if ( smp_found_config )
         get_smp_config();
 
+    if ( opt_nosmp )
+    {
+        max_cpus = 0;
+        set_nr_cpu_ids(1);
+    }
+    else
+    {
+        set_nr_cpu_ids(max_cpus);
+        max_cpus = nr_cpu_ids;
+    }
+
 #ifdef CONFIG_X86_64
     /* Low mappings were only needed for some BIOS table parsing. */
     zap_low_mappings();
@@ -1254,9 +1265,6 @@ void __init __start_xen(unsigned long mb
     acpi_mmcfg_init();
 #endif
 
-    if ( opt_nosmp )
-        max_cpus = 0;
-
     iommu_setup();    /* setup iommu if available */
 
     smp_prepare_cpus(max_cpus);
xen/arch/x86/smpboot.c +1 -1
@@ -535,7 +535,7 @@ int alloc_cpu_id(void)
     int cpu;
     cpus_complement(tmp_map, cpu_present_map);
     cpu = first_cpu(tmp_map);
-    return (cpu < NR_CPUS) ? cpu : -ENODEV;
+    return (cpu < nr_cpu_ids) ? cpu : -ENODEV;
 }
 
 static int do_boot_cpu(int apicid, int cpu)
xen/arch/x86/srat.c +1 -1
@@ -447,7 +447,7 @@ int __init acpi_scan_nodes(u64 start, u6
 			continue;
 		setup_node_bootmem(i, nodes[i].start, nodes[i].end);
 	}
-	for (i = 0; i < NR_CPUS; i++) { 
+	for (i = 0; i < nr_cpu_ids; i++) {
 		if (cpu_to_node[i] == NUMA_NO_NODE)
 			continue;
 		if (!node_isset(cpu_to_node[i], nodes_parsed))
xen/arch/x86/sysctl.c +1 -1
@@ -82,7 +82,7 @@ long arch_do_sysctl(
         pi->nr_cpus = num_online_cpus();
         pi->nr_nodes = num_online_nodes();
         pi->max_node_id = MAX_NUMNODES-1;
-        pi->max_cpu_id = NR_CPUS-1;
+        pi->max_cpu_id = nr_cpu_ids - 1;
         pi->total_pages = total_pages;
         pi->free_pages = avail_domheap_pages();
         pi->scrub_pages = 0;
xen/arch/x86/tboot.c +1 -1
@@ -248,7 +248,7 @@ static int mfn_in_guarded_stack(unsigned
     void *p;
     int i;
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for ( i = 0; i < nr_cpu_ids; i++ )
     {
         if ( !stack_base[i] )
             continue;
xen/arch/x86/traps.c +1 -1
@@ -3412,7 +3412,7 @@ static void __set_intr_gate(unsigned int
 {
     int i;
     /* Keep secondary tables in sync with IRQ updates. */
-    for ( i = 1; i < NR_CPUS; i++ )
+    for ( i = 1; i < nr_cpu_ids; i++ )
         if ( idt_tables[i] != NULL )
             _set_gate(&idt_tables[i][n], 14, dpl, addr);
     _set_gate(&idt_table[n], 14, dpl, addr);
xen/common/cpu.c +8 -2
@@ -6,6 +6,12 @@
 #include <xen/sched.h>
 #include <xen/stop_machine.h>
 
+unsigned int __read_mostly nr_cpu_ids = NR_CPUS;
+#ifndef nr_cpumask_bits
+unsigned int __read_mostly nr_cpumask_bits
+    = BITS_TO_LONGS(NR_CPUS) * BITS_PER_LONG;
+#endif
+
 /*
  * cpu_bit_bitmap[] is a special, "compressed" data structure that
  * represents all NR_CPUS bits binary values of 1<<nr.
@@ -80,7 +86,7 @@ int cpu_down(unsigned int cpu)
     if ( !cpu_hotplug_begin() )
         return -EBUSY;
 
-    if ( (cpu >= NR_CPUS) || (cpu == 0) || !cpu_online(cpu) )
+    if ( (cpu >= nr_cpu_ids) || (cpu == 0) || !cpu_online(cpu) )
     {
         cpu_hotplug_done();
         return -EINVAL;
@@ -122,7 +128,7 @@ int cpu_up(unsigned int cpu)
     if ( !cpu_hotplug_begin() )
         return -EBUSY;
 
-    if ( (cpu >= NR_CPUS) || cpu_online(cpu) || !cpu_present(cpu) )
+    if ( (cpu >= nr_cpu_ids) || cpu_online(cpu) || !cpu_present(cpu) )
     {
         cpu_hotplug_done();
         return -EINVAL;
xen/common/cpupool.c +2 -2
@@ -489,7 +489,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
         if ( cpu == XEN_SYSCTL_CPUPOOL_PAR_ANY )
             cpu = first_cpu(cpupool_free_cpus);
         ret = -EINVAL;
-        if ( cpu >= NR_CPUS )
+        if ( cpu >= nr_cpu_ids )
             goto addcpu_out;
         ret = -EBUSY;
         if ( !cpu_isset(cpu, cpupool_free_cpus) )
@@ -517,7 +517,7 @@ int cpupool_do_sysctl(struct xen_sysctl_
         cpu = op->cpu;
         if ( cpu == XEN_SYSCTL_CPUPOOL_PAR_ANY )
             cpu = last_cpu(c->cpu_valid);
-        ret = (cpu < NR_CPUS) ? cpupool_unassign_cpu(c, cpu) : -EINVAL;
+        ret = (cpu < nr_cpu_ids) ? cpupool_unassign_cpu(c, cpu) : -EINVAL;
         cpupool_put(c);
     }
     break;
xen/common/domain.c +1 -1
@@ -1023,7 +1023,7 @@ int continue_hypercall_on_cpu(
 {
     struct migrate_info *info;
 
-    if ( (cpu >= NR_CPUS) || !cpu_online(cpu) )
+    if ( (cpu >= nr_cpu_ids) || !cpu_online(cpu) )
         return -EINVAL;
 
     info = this_cpu(continue_info);
xen/common/kexec.c +1 -1
@@ -296,7 +296,7 @@ static int kexec_get_cpu(xen_kexec_range
     int nr = range->nr;
     int nr_bytes = 0;
 
-    if ( nr < 0 || nr >= NR_CPUS || !cpu_online(nr) )
+    if ( nr < 0 || nr >= nr_cpu_ids || !cpu_online(nr) )
         return -EINVAL;
 
     nr_bytes += sizeof_note("CORE", sizeof(ELF_Prstatus));
xen/common/keyhandler.c +1 -1
@@ -98,7 +98,7 @@ void dump_execstate(struct cpu_user_regs
         return;
 
     cpu = cycle_cpu(cpu, dump_execstate_mask);
-    if ( cpu < NR_CPUS )
+    if ( cpu < nr_cpu_ids )
     {
         smp_send_state_dump(cpu);
         return;
xen/common/sched_credit.c +1 -1
@@ -374,7 +374,7 @@ csched_alloc_pdata(const struct schedule
 
     INIT_LIST_HEAD(&spc->runq);
     spc->runq_sort_last = prv->runq_sort;
-    spc->idle_bias = NR_CPUS - 1;
+    spc->idle_bias = nr_cpu_ids - 1;
     if ( per_cpu(schedule_data, cpu).sched_priv == NULL )
         per_cpu(schedule_data, cpu).sched_priv = spc;
 
xen/common/sched_credit2.c +1 -1
@@ -2071,7 +2071,7 @@ csched_init(struct scheduler *ops)
     INIT_LIST_HEAD(&prv->sdom);
 
     /* But un-initialize all runqueues */
-    for ( i=0; i<NR_CPUS; i++)
+    for ( i = 0; i < nr_cpu_ids; i++ )
     {
         prv->runq_map[i] = -1;
         prv->rqd[i].id = -1;
xen/common/sched_sedf.c +1 -1
@@ -1201,7 +1201,7 @@ static void sedf_wake(const struct sched
       routine. Try to avoid unnecessary runs but:
       Save approximation: Always switch to scheduler!*/
     ASSERT(d->processor >= 0);
-    ASSERT(d->processor < NR_CPUS);
+    ASSERT(d->processor < nr_cpu_ids);
     ASSERT(per_cpu(schedule_data, d->processor).curr);
 
     if ( should_switch(per_cpu(schedule_data, d->processor).curr, d, now) )
xen/common/schedule.c +1 -1
@@ -1353,7 +1353,7 @@ void __init scheduler_init(void)
     idle_domain = domain_create(DOMID_IDLE, 0, 0);
     BUG_ON(idle_domain == NULL);
     idle_domain->vcpu = idle_vcpu;
-    idle_domain->max_vcpus = NR_CPUS;
+    idle_domain->max_vcpus = nr_cpu_ids;
     if ( alloc_vcpu(idle_domain, 0, 0) == NULL )
         BUG();
     if ( ops.alloc_pdata &&
xen/common/sysctl.c +1 -1
@@ -183,7 +183,7 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
         uint32_t i, nr_cpus;
         struct xen_sysctl_cpuinfo cpuinfo;
 
-        nr_cpus = min_t(uint32_t, op->u.getcpuinfo.max_cpus, NR_CPUS);
+        nr_cpus = min(op->u.getcpuinfo.max_cpus, nr_cpu_ids);
 
         ret = xsm_getcpuinfo();
         if ( ret )
xen/drivers/acpi/pmstat.c +1 -1
@@ -53,7 +53,7 @@ int do_get_pm_info(struct xen_sysctl_get
     int ret = 0;
     const struct processor_pminfo *pmpt;
 
-    if ( !op || (op->cpuid >= NR_CPUS) || !cpu_online(op->cpuid) )
+    if ( !op || (op->cpuid >= nr_cpu_ids) || !cpu_online(op->cpuid) )
         return -EINVAL;
     pmpt = processor_pminfo[op->cpuid];
 
xen/include/asm-x86/setup.h +2 -0
@@ -20,6 +20,8 @@ int nsc_init_cpu(void);
 int centaur_init_cpu(void);
 int transmeta_init_cpu(void);
 
+void set_nr_cpu_ids(unsigned int max_cpus);
+
 void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
 void arch_init_memory(void);
 void subarch_init_memory(void);
xen/include/xen/cpumask.h +73 -36

269 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel