Skip to contentSkip to conversation

powerpc: A few misc cpumask changes

PATCH Applied Shrikanth Hegde 3 participants 8 messages Apr 27 – Jun 19 PowerPC

lore
Share & tools
lore

Shrikanth Hegde

author reviewer
#0 lore raw

v2 cover powerpc: A few misc cpumask changes

These are some miscellaneous code refactors around using cpumask APIs. They are mainly aimed at code simplification.

Changes since v1:
- Dropped the changes done in xive_find_target_in_mask. Those changes are done by Yury Norov already.
- Collected the tags. Thanks to Yury Norov.
- Added new patch to use cpumask_intersects instead of using temp_mask to achieve the same goal.
- Added new patch to print the warning when target CPU not found as discussed in [2]. This patch is kept separate since this adds a new warning in case of failure. So one may perceive it as functional change.

v1[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Based on tip/master at: (dffc5753ba4c "Merge branch into tip/master: 'timers/clocksource'")

Shrikanth Hegde (4):
powerpc: Use cpumask_next_wrap instead
powerpc: Simplify cpumask api usage for cpuinfo display powerpc/perf: Use cpumask_intersects api for checking disable path powerpc/xive: Add warning if target CPU not found

 arch/powerpc/kernel/irq.c             | 5 +----
 arch/powerpc/kernel/setup-common.c    | 7 ++-----
 arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
 arch/powerpc/perf/imc-pmu.c           | 6 ++----
 arch/powerpc/sysdev/xive/common.c     | 1 +
 5 files changed, 7 insertions(+), 16 deletions(-)
Signature · 1 line
2.47.3
author reviewer
#1 lore raw

PATCH v2 1/4 powerpc: Use cpumask_next_wrap instead

cpu = cpumask_next(cpu, mask)
if (cpu >= nr_cpu_ids)
cpu = cpumask_first(mask)

Above block is identical to:
cpu = cpumask_next_wrap(cpu, mask)

Replace it, No change in functionality or performance. Slightly simpler code.

---
 arch/powerpc/kernel/irq.c             | 5 +----
 arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
 2 files changed, 2 insertions(+), 7 deletions(-)
arch/powerpc/kernel/irq.c +1 -4
index a0e8b998c9b5..f69de08ad347 100644
@@ -370,10 +370,7 @@ int irq_choose_cpu(const struct cpumask *mask)
 do_round_robin:
 		raw_spin_lock_irqsave(&irq_rover_lock, flags);
 
-		irq_rover = cpumask_next(irq_rover, cpu_online_mask);
-		if (irq_rover >= nr_cpu_ids)
-			irq_rover = cpumask_first(cpu_online_mask);
-
+		irq_rover = cpumask_next_wrap(irq_rover, cpu_online_mask);
 		cpuid = irq_rover;
 
 		raw_spin_unlock_irqrestore(&irq_rover_lock, flags);
arch/powerpc/mm/book3s64/hash_utils.c +1 -3
index 9dc5889d6ecb..e4fcf929cb33 100644
@@ -1299,9 +1299,7 @@ static void stress_hpt_timer_fn(struct timer_list *timer)
 	if (!firmware_has_feature(FW_FEATURE_LPAR))
 		tlbiel_all();
 
-	next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask);
-	if (next_cpu >= nr_cpu_ids)
-		next_cpu = cpumask_first(cpu_online_mask);
+	next_cpu = cpumask_next_wrap(raw_smp_processor_id(), cpu_online_mask);
 	stress_hpt_timer.expires = jiffies + msecs_to_jiffies(10);
 	add_timer_on(&stress_hpt_timer, next_cpu);
 }
Signature · 1 line
2.47.3
author reviewer
#2 lore raw

PATCH v2 2/4 powerpc: Simplify cpumask api usage for cpuinfo display

In reply to Shrikanth Hegde

- cpumask_next can take -1 as valid argument. So simplify cpuinfo iterator.

- Use cpumask_last to find if this_cpu is last online CPU.

/proc/cpuinfo shows same info with patch.

---
 arch/powerpc/kernel/setup-common.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/powerpc/kernel/setup-common.c +2 -5
index 8a86b0efcb1c..aecabe9cf139 100644
@@ -323,7 +323,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 	seq_putc(m, '\n');
 
 	/* If this is the last cpu, print the summary */
-	if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids)
+	if (cpu_id == cpumask_last(cpu_online_mask))
 		show_cpuinfo_summary(m);
 
 	return 0;
@@ -331,10 +331,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 
 static void *c_start(struct seq_file *m, loff_t *pos)
 {
-	if (*pos == 0)	/* just in case, cpu 0 is not the first */
-		*pos = cpumask_first(cpu_online_mask);
-	else
-		*pos = cpumask_next(*pos - 1, cpu_online_mask);
+	*pos = cpumask_next(*pos - 1, cpu_online_mask);
 	if ((*pos) < nr_cpu_ids)
 		return (void *)(unsigned long)(*pos + 1);
 	return NULL;
Signature · 1 line
2.47.3
author reviewer
#3 lore raw

PATCH v2 3/4 powerpc/perf: Use cpumask_intersects api for checking disable path

In reply to Shrikanth Hegde

First online CPU in the node disables the nest counters by making an OPAL call. Any other CPU in that node, will bail out.

Instead of using a temporary mask to find out if any cpu in the node is visited or not, it is better to use the cpumask_intersects api to achieve the same.

Similarly a temporary cpumask is used to check if a core is already part of core_imc_cpumask. Use the same cpumask_intersects api there.

---
 arch/powerpc/perf/imc-pmu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/powerpc/perf/imc-pmu.c +2 -4
index c1563b4eaa94..e3822f36c419 100644
@@ -421,7 +421,6 @@ static int ppc_nest_imc_cpu_offline(unsigned int cpu)
 static int ppc_nest_imc_cpu_online(unsigned int cpu)
 {
 	const struct cpumask *l_cpumask;
-	static struct cpumask tmp_mask;
 	int res;
 
 	/* Get the cpumask of this node */
@@ -431,7 +430,7 @@ static int ppc_nest_imc_cpu_online(unsigned int cpu)
 	 * If this is not the first online CPU on this node, then
 	 * just return.
 	 */
-	if (cpumask_and(&tmp_mask, l_cpumask, &nest_imc_cpumask))
+	if (cpumask_intersects(l_cpumask, &nest_imc_cpumask))
 		return 0;
 
 	/*
@@ -647,14 +646,13 @@ static bool is_core_imc_mem_inited(int cpu)
 static int ppc_core_imc_cpu_online(unsigned int cpu)
 {
 	const struct cpumask *l_cpumask;
-	static struct cpumask tmp_mask;
 	int ret = 0;
 
 	/* Get the cpumask for this core */
 	l_cpumask = cpu_sibling_mask(cpu);
 
 	/* If a cpu for this core is already set, then, don't do anything */
-	if (cpumask_and(&tmp_mask, l_cpumask, &core_imc_cpumask))
+	if (cpumask_intersects(l_cpumask, &core_imc_cpumask))
 		return 0;
 
 	if (!is_core_imc_mem_inited(cpu)) {
Signature · 1 line
2.47.3
author reviewer
#4 lore raw

PATCH v2 4/4 powerpc/xive: Add warning if target CPU not found

In reply to Shrikanth Hegde

Add a warn_once to warn if the CPU target is not found. This could help to find about any such usecase.

This is a very rare case, which either means mask was empty or atomic update failed for all online CPUs. So it is worth printing that path for potential fix.

---
 arch/powerpc/sysdev/xive/common.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/sysdev/xive/common.c +1 -0
index c120be73d149..dadd1f46ec93 100644
@@ -564,6 +564,7 @@ static int xive_find_target_in_mask(const struct cpumask *mask,
 			return cpu;
 	}
 
+	WARN_ONCE(1, "target CPU not found in mask: %*pbl\n", cpumask_pr_args(mask));
 	return -1;
 }
 
Signature · 1 line
2.47.3
Reviewed-by on the v2 series
#5 lore raw
In reply to Shrikanth Hegde
Quoted 2 lines · Shrikanth Hegde

These are some miscellaneous code refactors around using cpumask APIs. They are mainly aimed at code simplification.

Quoted 31 lines

Changes since v1:
- Dropped the changes done in xive_find_target_in_mask. Those changes are done by Yury Norov already.
- Collected the tags. Thanks to Yury Norov.
- Added new patch to use cpumask_intersects instead of using temp_mask to achieve the same goal.
- Added new patch to print the warning when target CPU not found as discussed in [2]. This patch is kept separate since this adds a new warning in case of failure. So one may perceive it as functional change.

v1[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Based on tip/master at: (dffc5753ba4c "Merge branch into tip/master: 'timers/clocksource'")

Shrikanth Hegde (4):
powerpc: Use cpumask_next_wrap instead
powerpc: Simplify cpumask api usage for cpuinfo display powerpc/perf: Use cpumask_intersects api for checking disable path powerpc/xive: Add warning if target CPU not found

 arch/powerpc/kernel/irq.c             | 5 +----
 arch/powerpc/kernel/setup-common.c    | 7 ++-----
 arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
 arch/powerpc/perf/imc-pmu.c           | 6 ++----
 arch/powerpc/sysdev/xive/common.c     | 1 +
 5 files changed, 7 insertions(+), 16 deletions(-)
Signature · 1 line
2.47.3
author reviewer
#6 lore raw
In reply to Shrikanth Hegde

Hi Maddy, Christophe,

Quoted 2 lines

Based on tip/master at: (dffc5753ba4c "Merge branch into tip/master: 'timers/clocksource'")

Gentle Ping,
Still applies cleanly to today's tip master.

Quoted 6 lines

Shrikanth Hegde (4):
powerpc: Use cpumask_next_wrap instead
powerpc: Simplify cpumask api usage for cpuinfo display powerpc/perf: Use cpumask_intersects api for checking disable path powerpc/xive: Add warning if target CPU not found

Quoted 7 lines
  arch/powerpc/kernel/irq.c             | 5 +----
  arch/powerpc/kernel/setup-common.c    | 7 ++-----
  arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
  arch/powerpc/perf/imc-pmu.c           | 6 ++----
  arch/powerpc/sysdev/xive/common.c     | 1 +
  5 files changed, 7 insertions(+), 16 deletions(-)

Do you have any comments on this? Do you want me to resend with yury's tag?

maintainer Applied
#7 lore raw
In reply to Shrikanth Hegde
Quoted 14 lines · Shrikanth Hegde

These are some miscellaneous code refactors around using cpumask APIs. They are mainly aimed at code simplification.

Changes since v1:
- Dropped the changes done in xive_find_target_in_mask. Those changes are done by Yury Norov already.
- Collected the tags. Thanks to Yury Norov.
- Added new patch to use cpumask_intersects instead of using temp_mask to achieve the same goal.
- Added new patch to print the warning when target CPU not found as discussed in [2]. This patch is kept separate since this adds a new warning in case of failure. So one may perceive it as functional change.

Quoted 1 line

[...]

Applied to powerpc/next.

[1/4] powerpc: Use cpumask_next_wrap instead

      https://git.kernel.org/powerpc/c/1ca0c82bbc72e8e3de0a41e6dbf92473c00f3d1e
[2/4] powerpc: Simplify cpumask api usage for cpuinfo display
      https://git.kernel.org/powerpc/c/a66eab7a5d7decadad51b4204c6f2f0d8cf665d1
[3/4] powerpc/perf: Use cpumask_intersects api for checking disable path
      https://git.kernel.org/powerpc/c/1f8986fdae91880411a3be907879ba63973da100
[4/4] powerpc/xive: Add warning if target CPU not found
      https://git.kernel.org/powerpc/c/0521dbbc5710aca3b3d189747781761732289623

cheers