All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus
@ 2017-11-22  5:15 Madhavan Srinivasan
  2017-11-22  5:15 ` [PATCH v2 2/2] powerpc/perf: Fix IMC_MAX_PMU macro Madhavan Srinivasan
  2017-11-24  9:46 ` [1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus Michael Ellerman
  0 siblings, 2 replies; 5+ messages in thread
From: Madhavan Srinivasan @ 2017-11-22  5:15 UTC (permalink / raw)
  To: mpe; +Cc: linuxppc-dev, anju, Madhavan Srinivasan

"pmu_count" in opal_imc_counters_probe() is intended to hold
the number of successful nest imc pmu registerations. But
current code also counts other imc units like core_imc and
thread_imc. Patch add a check to count only nest imc pmus.

Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/opal-imc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index 21f6531fae20..b150f4deaccf 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -191,8 +191,10 @@ static int opal_imc_counters_probe(struct platform_device *pdev)
 			break;
 		}
 
-		if (!imc_pmu_create(imc_dev, pmu_count, domain))
-			pmu_count++;
+		if (!imc_pmu_create(imc_dev, pmu_count, domain)) {
+			if (domain == IMC_DOMAIN_NEST)
+				pmu_count++;
+		}
 	}
 
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] powerpc/perf: Fix IMC_MAX_PMU macro
  2017-11-22  5:15 [PATCH 1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus Madhavan Srinivasan
@ 2017-11-22  5:15 ` Madhavan Srinivasan
  2017-11-24  9:46   ` [v2,2/2] " Michael Ellerman
  2017-11-24  9:46 ` [1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus Michael Ellerman
  1 sibling, 1 reply; 5+ messages in thread
From: Madhavan Srinivasan @ 2017-11-22  5:15 UTC (permalink / raw)
  To: mpe; +Cc: linuxppc-dev, anju, Madhavan Srinivasan

IMC_MAX_PMU is used for static storage (per_nest_pmu_arr) which holds
nest pmu information. Current value for the macro is 32 based on
the initial number of nest pmu units supported by the nest microcode.
But going forward, microcode could support more nest units. Instead
of static storage, patch to fix the code to dynamically allocate an
array based on the number of nest imc units found in the device tree.

Fixes:8f95faaac56c1 ('powerpc/powernv: Detect and create IMC device')
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
---
Changelog v1:
 - Initialized pmu_units to avoid compilation warning

 arch/powerpc/include/asm/imc-pmu.h        |  6 +-----
 arch/powerpc/perf/imc-pmu.c               | 15 ++++++++++++---
 arch/powerpc/platforms/powernv/opal-imc.c | 16 ++++++++++++++++
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/asm/imc-pmu.h b/arch/powerpc/include/asm/imc-pmu.h
index 7f74c282710f..fad0e6ff460f 100644
--- a/arch/powerpc/include/asm/imc-pmu.h
+++ b/arch/powerpc/include/asm/imc-pmu.h
@@ -21,11 +21,6 @@
 #include <asm/opal.h>
 
 /*
- * For static allocation of some of the structures.
- */
-#define IMC_MAX_PMUS			32
-
-/*
  * Compatibility macros for IMC devices
  */
 #define IMC_DTB_COMPAT			"ibm,opal-in-memory-counters"
@@ -125,4 +120,5 @@ enum {
 extern int init_imc_pmu(struct device_node *parent,
 				struct imc_pmu *pmu_ptr, int pmu_id);
 extern void thread_imc_disable(void);
+extern int get_max_nest_dev(void);
 #endif /* __ASM_POWERPC_IMC_PMU_H */
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 74db696ef365..c40cb5f7ceaf 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -26,7 +26,7 @@
  */
 static DEFINE_MUTEX(nest_init_lock);
 static DEFINE_PER_CPU(struct imc_pmu_ref *, local_nest_imc_refc);
-static struct imc_pmu *per_nest_pmu_arr[IMC_MAX_PMUS];
+static struct imc_pmu **per_nest_pmu_arr;
 static cpumask_t nest_imc_cpumask;
 struct imc_pmu_ref *nest_imc_refc;
 static int nest_pmus;
@@ -286,13 +286,14 @@ static struct imc_pmu_ref *get_nest_pmu_ref(int cpu)
 static void nest_change_cpu_context(int old_cpu, int new_cpu)
 {
 	struct imc_pmu **pn = per_nest_pmu_arr;
-	int i;
 
 	if (old_cpu < 0 || new_cpu < 0)
 		return;
 
-	for (i = 0; *pn && i < IMC_MAX_PMUS; i++, pn++)
+	while (*pn) {
 		perf_pmu_migrate_context(&(*pn)->pmu, old_cpu, new_cpu);
+		pn++;
+	}
 }
 
 static int ppc_nest_imc_cpu_offline(unsigned int cpu)
@@ -1192,6 +1193,7 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
 		kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs);
 	kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]);
 	kfree(pmu_ptr);
+	kfree(per_nest_pmu_arr);
 	return;
 }
 
@@ -1216,6 +1218,13 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
 			return -ENOMEM;
 
 		/* Needed for hotplug/migration */
+		if (!per_nest_pmu_arr) {
+			per_nest_pmu_arr = kcalloc(get_max_nest_dev() + 1,
+						sizeof(struct imc_pmu *),
+						GFP_KERNEL);
+			if (!per_nest_pmu_arr)
+				return -ENOMEM;
+		}
 		per_nest_pmu_arr[pmu_index] = pmu_ptr;
 		break;
 	case IMC_DOMAIN_CORE:
diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index b150f4deaccf..465ea105b771 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -153,6 +153,22 @@ static void disable_core_pmu_counters(void)
 	put_online_cpus();
 }
 
+int get_max_nest_dev(void)
+{
+	struct device_node *node;
+	u32 pmu_units = 0, type;
+
+	for_each_compatible_node(node, NULL, IMC_DTB_UNIT_COMPAT) {
+		if (of_property_read_u32(node, "type", &type))
+			continue;
+
+		if (type == IMC_TYPE_CHIP)
+			pmu_units++;
+	}
+
+	return pmu_units;
+}
+
 static int opal_imc_counters_probe(struct platform_device *pdev)
 {
 	struct device_node *imc_dev = pdev->dev.of_node;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus
  2017-11-22  5:15 [PATCH 1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus Madhavan Srinivasan
  2017-11-22  5:15 ` [PATCH v2 2/2] powerpc/perf: Fix IMC_MAX_PMU macro Madhavan Srinivasan
@ 2017-11-24  9:46 ` Michael Ellerman
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2017-11-24  9:46 UTC (permalink / raw)
  To: Madhavan Srinivasan; +Cc: anju, linuxppc-dev, Madhavan Srinivasan

On Wed, 2017-11-22 at 05:15:38 UTC, Madhavan Srinivasan wrote:
> "pmu_count" in opal_imc_counters_probe() is intended to hold
> the number of successful nest imc pmu registerations. But
> current code also counts other imc units like core_imc and
> thread_imc. Patch add a check to count only nest imc pmus.
> 
> Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/de34787f1096cce38e2590be0013b4

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [v2,2/2] powerpc/perf: Fix IMC_MAX_PMU macro
  2017-11-22  5:15 ` [PATCH v2 2/2] powerpc/perf: Fix IMC_MAX_PMU macro Madhavan Srinivasan
@ 2017-11-24  9:46   ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2017-11-24  9:46 UTC (permalink / raw)
  To: Madhavan Srinivasan; +Cc: anju, linuxppc-dev, Madhavan Srinivasan

On Wed, 2017-11-22 at 05:15:39 UTC, Madhavan Srinivasan wrote:
> IMC_MAX_PMU is used for static storage (per_nest_pmu_arr) which holds
> nest pmu information. Current value for the macro is 32 based on
> the initial number of nest pmu units supported by the nest microcode.
> But going forward, microcode could support more nest units. Instead
> of static storage, patch to fix the code to dynamically allocate an
> array based on the number of nest imc units found in the device tree.
> 
> Fixes:8f95faaac56c1 ('powerpc/powernv: Detect and create IMC device')
> Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/73ce9aec65b17433e18163d07eb5cb

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus
@ 2017-11-10 20:39 Madhavan Srinivasan
  0 siblings, 0 replies; 5+ messages in thread
From: Madhavan Srinivasan @ 2017-11-10 20:39 UTC (permalink / raw)
  To: mpe; +Cc: linuxppc-dev, Madhavan Srinivasan

"pmu_count" in opal_imc_counters_probe() is intended to hold
the number of successful nest imc pmu registerations. But
current code also counts other imc units like core_imc and
thread_imc. Patch add a check to count only nest imc pmus.

Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/opal-imc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index 21f6531fae20..b150f4deaccf 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -191,8 +191,10 @@ static int opal_imc_counters_probe(struct platform_device *pdev)
 			break;
 		}
 
-		if (!imc_pmu_create(imc_dev, pmu_count, domain))
-			pmu_count++;
+		if (!imc_pmu_create(imc_dev, pmu_count, domain)) {
+			if (domain == IMC_DOMAIN_NEST)
+				pmu_count++;
+		}
 	}
 
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-24  9:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-22  5:15 [PATCH 1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus Madhavan Srinivasan
2017-11-22  5:15 ` [PATCH v2 2/2] powerpc/perf: Fix IMC_MAX_PMU macro Madhavan Srinivasan
2017-11-24  9:46   ` [v2,2/2] " Michael Ellerman
2017-11-24  9:46 ` [1/2] powerpc/perf: Fix pmu_count to count only nest imc pmus Michael Ellerman
  -- strict thread matches above, loose matches on Subject: below --
2017-11-10 20:39 [PATCH 1/2] " Madhavan Srinivasan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.