Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b130ad5 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds
Browse files

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: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ac036f95
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -690,7 +690,7 @@ void __init smp_init_cpus(void)
				      acpi_parse_gic_cpu_interface, 0);
				      acpi_parse_gic_cpu_interface, 0);


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


	if (!bootcpu_valid) {
	if (!bootcpu_valid) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -224,7 +224,7 @@ void __init allocate_pacas(void)
	paca = __va(memblock_alloc_base(paca_size, PAGE_SIZE, limit));
	paca = __va(memblock_alloc_base(paca_size, PAGE_SIZE, limit));
	memset(paca, 0, paca_size);
	memset(paca, 0, paca_size);


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


	allocate_lppacas(nr_cpu_ids, limit);
	allocate_lppacas(nr_cpu_ids, limit);
+1 −1
Original line number Original line Diff line number Diff line
@@ -551,7 +551,7 @@ void __init smp_setup_cpu_maps(void)
		if (maxcpus > nr_cpu_ids) {
		if (maxcpus > nr_cpu_ids) {
			printk(KERN_WARNING
			printk(KERN_WARNING
			       "Partition configured for %d cpus, "
			       "Partition configured for %d cpus, "
			       "operating system maximum is %d.\n",
			       "operating system maximum is %u.\n",
			       maxcpus, nr_cpu_ids);
			       maxcpus, nr_cpu_ids);
			maxcpus = nr_cpu_ids;
			maxcpus = nr_cpu_ids;
		} else
		} else
+2 −2
Original line number Original line Diff line number Diff line
@@ -511,13 +511,13 @@ static bool xive_parse_provisioning(struct device_node *np)
static void xive_native_setup_pools(void)
static void xive_native_setup_pools(void)
{
{
	/* Allocate a pool big enough */
	/* Allocate a pool big enough */
	pr_debug("XIVE: Allocating VP block for pool size %d\n", nr_cpu_ids);
	pr_debug("XIVE: Allocating VP block for pool size %u\n", nr_cpu_ids);


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


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


+1 −1
Original line number Original line Diff line number Diff line
@@ -1200,7 +1200,7 @@ static void __init validate_hv(void)
	 * We use a struct cpumask for this, so it must be big enough.
	 * We use a struct cpumask for this, so it must be big enough.
	 */
	 */
	if ((smp_height * smp_width) > nr_cpu_ids)
	if ((smp_height * smp_width) > nr_cpu_ids)
		early_panic("Hypervisor %d x %d grid too big for Linux NR_CPUS %d\n",
		early_panic("Hypervisor %d x %d grid too big for Linux NR_CPUS %u\n",
			    smp_height, smp_width, nr_cpu_ids);
			    smp_height, smp_width, nr_cpu_ids);
#endif
#endif


Loading