Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Fix cpu_online_cores_map to return only online threads mask

Currently, cpu_online_cores_map returns a mask, which for every core with
at least one online thread, has the bit for thread 0 of the core set to 1,
and the bits for all other threads of the core set to 0. But thread 0 of
the core itself may not be online always. In such cases, if the returned
mask is used for IPI, then it'll cause IPIs to be skipped on cores where
the first thread is offline, because the IPI code refuses to send IPIs to
offline threads.

Fix this by setting the bit of the first online thread in the core.
This is done by fixing this in the underlying function
cpu_thread_mask_to_cores.

The result has the property that for all cores with online threads, there
is one bit set in the returned map. And further, all bits that are set in
the returned map correspond to online threads.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Reviewed-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
[ Changelog from Michael Ellerman <mpe@ellerman.id.au> ]
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Shreyas B. Prabhu and committed by
Michael Ellerman
e602ffb2 7978f76c

+8 -5
+8 -5
arch/powerpc/include/asm/cputhreads.h
··· 31 31 /* cpu_thread_mask_to_cores - Return a cpumask of one per cores 32 32 * hit by the argument 33 33 * 34 - * @threads: a cpumask of threads 34 + * @threads: a cpumask of online threads 35 35 * 36 - * This function returns a cpumask which will have one "cpu" (or thread) 36 + * This function returns a cpumask which will have one online cpu's 37 37 * bit set for each core that has at least one thread set in the argument. 38 38 * 39 39 * This can typically be used for things like IPI for tlb invalidations ··· 42 42 static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads) 43 43 { 44 44 cpumask_t tmp, res; 45 - int i; 45 + int i, cpu; 46 46 47 47 cpumask_clear(&res); 48 48 for (i = 0; i < NR_CPUS; i += threads_per_core) { 49 49 cpumask_shift_left(&tmp, &threads_core_mask, i); 50 - if (cpumask_intersects(threads, &tmp)) 51 - cpumask_set_cpu(i, &res); 50 + if (cpumask_intersects(threads, &tmp)) { 51 + cpu = cpumask_next_and(-1, &tmp, cpu_online_mask); 52 + if (cpu < nr_cpu_ids) 53 + cpumask_set_cpu(cpu, &res); 54 + } 52 55 } 53 56 return res; 54 57 }