Skip to content

Commit 9b130ad

Browse files
Alexey Dobriyantorvalds
authored andcommitted
treewide: make "nr_cpu_ids" unsigned
First, number of CPUs can't be negative number. Second, different signnnedness leads to suboptimal code in the following cases: 1) kmalloc(nr_cpu_ids * sizeof(X)); "int" has to be sign extended to size_t. 2) while (loff_t *pos < nr_cpu_ids) MOVSXD is 1 byte longed than the same MOV. Other cases exist as well. Basically compiler is told that nr_cpu_ids can't be negative which can't be deduced if it is "int". Code savings on allyesconfig kernel: -3KB add/remove: 0/0 grow/shrink: 25/264 up/down: 261/-3631 (-3370) function old new delta coretemp_cpu_online 450 512 +62 rcu_init_one 1234 1272 +38 pci_device_probe 374 399 +25 ... pgdat_reclaimable_pages 628 556 -72 select_fallback_rq 446 369 -77 task_numa_find_cpu 1923 1807 -116 Link: http://lkml.kernel.org/r/20170819114959.GA30580@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ac036f9 commit 9b130ad

File tree

17 files changed

+21
-21
lines changed

17 files changed

+21
-21
lines changed

arch/arm64/kernel/smp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ void __init smp_init_cpus(void)
690690
acpi_parse_gic_cpu_interface, 0);
691691

692692
if (cpu_count > nr_cpu_ids)
693-
pr_warn("Number of cores (%d) exceeds configured maximum of %d - clipping\n",
693+
pr_warn("Number of cores (%d) exceeds configured maximum of %u - clipping\n",
694694
cpu_count, nr_cpu_ids);
695695

696696
if (!bootcpu_valid) {

arch/powerpc/kernel/paca.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void __init allocate_pacas(void)
224224
paca = __va(memblock_alloc_base(paca_size, PAGE_SIZE, limit));
225225
memset(paca, 0, paca_size);
226226

227-
printk(KERN_DEBUG "Allocated %u bytes for %d pacas at %p\n",
227+
printk(KERN_DEBUG "Allocated %u bytes for %u pacas at %p\n",
228228
paca_size, nr_cpu_ids, paca);
229229

230230
allocate_lppacas(nr_cpu_ids, limit);

arch/powerpc/kernel/setup-common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ void __init smp_setup_cpu_maps(void)
551551
if (maxcpus > nr_cpu_ids) {
552552
printk(KERN_WARNING
553553
"Partition configured for %d cpus, "
554-
"operating system maximum is %d.\n",
554+
"operating system maximum is %u.\n",
555555
maxcpus, nr_cpu_ids);
556556
maxcpus = nr_cpu_ids;
557557
} else

arch/powerpc/sysdev/xive/native.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,13 @@ static bool xive_parse_provisioning(struct device_node *np)
511511
static void xive_native_setup_pools(void)
512512
{
513513
/* Allocate a pool big enough */
514-
pr_debug("XIVE: Allocating VP block for pool size %d\n", nr_cpu_ids);
514+
pr_debug("XIVE: Allocating VP block for pool size %u\n", nr_cpu_ids);
515515

516516
xive_pool_vps = xive_native_alloc_vp_block(nr_cpu_ids);
517517
if (WARN_ON(xive_pool_vps == XIVE_INVALID_VP))
518518
pr_err("XIVE: Failed to allocate pool VP, KVM might not function\n");
519519

520-
pr_debug("XIVE: Pool VPs allocated at 0x%x for %d max CPUs\n",
520+
pr_debug("XIVE: Pool VPs allocated at 0x%x for %u max CPUs\n",
521521
xive_pool_vps, nr_cpu_ids);
522522
}
523523

arch/tile/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ static void __init validate_hv(void)
12001200
* We use a struct cpumask for this, so it must be big enough.
12011201
*/
12021202
if ((smp_height * smp_width) > nr_cpu_ids)
1203-
early_panic("Hypervisor %d x %d grid too big for Linux NR_CPUS %d\n",
1203+
early_panic("Hypervisor %d x %d grid too big for Linux NR_CPUS %u\n",
12041204
smp_height, smp_width, nr_cpu_ids);
12051205
#endif
12061206

arch/x86/kernel/apic/apic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ static int allocate_logical_cpuid(int apicid)
20972097

20982098
/* Allocate a new cpuid. */
20992099
if (nr_logical_cpuids >= nr_cpu_ids) {
2100-
WARN_ONCE(1, "APIC: NR_CPUS/possible_cpus limit of %i reached. "
2100+
WARN_ONCE(1, "APIC: NR_CPUS/possible_cpus limit of %u reached. "
21012101
"Processor %d/0x%x and the rest are ignored.\n",
21022102
nr_cpu_ids, nr_logical_cpuids, apicid);
21032103
return -EINVAL;

arch/x86/kernel/setup_percpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void __init setup_per_cpu_areas(void)
168168
unsigned long delta;
169169
int rc;
170170

171-
pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n",
171+
pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%u nr_node_ids:%d\n",
172172
NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids);
173173

174174
/*

arch/x86/kernel/smpboot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ __init void prefill_possible_map(void)
14611461

14621462
/* nr_cpu_ids could be reduced via nr_cpus= */
14631463
if (possible > nr_cpu_ids) {
1464-
pr_warn("%d Processors exceeds NR_CPUS limit of %d\n",
1464+
pr_warn("%d Processors exceeds NR_CPUS limit of %u\n",
14651465
possible, nr_cpu_ids);
14661466
possible = nr_cpu_ids;
14671467
}

drivers/base/cpu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ static ssize_t print_cpus_offline(struct device *dev,
256256
buf[n++] = ',';
257257

258258
if (nr_cpu_ids == total_cpus-1)
259-
n += snprintf(&buf[n], len - n, "%d", nr_cpu_ids);
259+
n += snprintf(&buf[n], len - n, "%u", nr_cpu_ids);
260260
else
261-
n += snprintf(&buf[n], len - n, "%d-%d",
261+
n += snprintf(&buf[n], len - n, "%u-%d",
262262
nr_cpu_ids, total_cpus-1);
263263
}
264264

drivers/scsi/scsi_debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5465,7 +5465,7 @@ static int sdebug_driver_probe(struct device * dev)
54655465
return error;
54665466
}
54675467
if (submit_queues > nr_cpu_ids) {
5468-
pr_warn("%s: trim submit_queues (was %d) to nr_cpu_ids=%d\n",
5468+
pr_warn("%s: trim submit_queues (was %d) to nr_cpu_ids=%u\n",
54695469
my_name, submit_queues, nr_cpu_ids);
54705470
submit_queues = nr_cpu_ids;
54715471
}

0 commit comments

Comments
 (0)