Skip to content

Commit 38bef8e

Browse files
committed
smp: add set_nr_cpu_ids()
In preparation to support compile-time nr_cpu_ids, add a setter for the variable. This is a no-op for all arches. Signed-off-by: Yury Norov <[email protected]>
1 parent 53fc190 commit 38bef8e

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

arch/loongarch/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static void __init prefill_possible_map(void)
346346
for (; i < NR_CPUS; i++)
347347
set_cpu_possible(i, false);
348348

349-
nr_cpu_ids = possible;
349+
set_nr_cpu_ids(possible);
350350
}
351351
#endif
352352

arch/mips/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static void __init prefill_possible_map(void)
750750
for (; i < NR_CPUS; i++)
751751
set_cpu_possible(i, false);
752752

753-
nr_cpu_ids = possible;
753+
set_nr_cpu_ids(possible);
754754
}
755755
#else
756756
static inline void prefill_possible_map(void) {}

arch/x86/kernel/smpboot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ static void __init smp_sanity_check(void)
13161316
nr++;
13171317
}
13181318

1319-
nr_cpu_ids = 8;
1319+
set_nr_cpu_ids(8);
13201320
}
13211321
#endif
13221322

@@ -1569,7 +1569,7 @@ __init void prefill_possible_map(void)
15691569
possible = i;
15701570
}
15711571

1572-
nr_cpu_ids = possible;
1572+
set_nr_cpu_ids(possible);
15731573

15741574
pr_info("Allowing %d CPUs, %d hotplug CPUs\n",
15751575
possible, max_t(int, possible - num_processors, 0));

arch/x86/xen/smp_pv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static void __init _get_smp_config(unsigned int early)
179179
* hypercall to expand the max number of VCPUs an already
180180
* running guest has. So cap it up to X. */
181181
if (subtract)
182-
nr_cpu_ids = nr_cpu_ids - subtract;
182+
set_nr_cpu_ids(nr_cpu_ids - subtract);
183183
#endif
184184

185185
}

include/linux/cpumask.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
3939
#define nr_cpu_ids 1U
4040
#else
4141
extern unsigned int nr_cpu_ids;
42+
43+
static inline void set_nr_cpu_ids(unsigned int nr)
44+
{
45+
nr_cpu_ids = nr;
46+
}
4247
#endif
4348

4449
#ifdef CONFIG_CPUMASK_OFFSTACK

kernel/smp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ static int __init nrcpus(char *str)
10701070
int nr_cpus;
10711071

10721072
if (get_option(&str, &nr_cpus) && nr_cpus > 0 && nr_cpus < nr_cpu_ids)
1073-
nr_cpu_ids = nr_cpus;
1073+
set_nr_cpu_ids(nr_cpus);
10741074

10751075
return 0;
10761076
}
@@ -1097,7 +1097,7 @@ EXPORT_SYMBOL(nr_cpu_ids);
10971097
/* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
10981098
void __init setup_nr_cpu_ids(void)
10991099
{
1100-
nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
1100+
set_nr_cpu_ids(find_last_bit(cpumask_bits(cpu_possible_mask), NR_CPUS) + 1);
11011101
}
11021102

11031103
/* Called by boot processor to activate the rest. */

0 commit comments

Comments
 (0)