Skip to content

Commit 80da94a

Browse files
Madhavan Srinivasangregkh
authored andcommitted
powerpc/perf: Fix IMC_MAX_PMU macro
commit 73ce9ae upstream. 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 <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Cc: Andrew Donnellan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 97b858b commit 80da94a

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

arch/powerpc/include/asm/imc-pmu.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
#include <linux/io.h>
2121
#include <asm/opal.h>
2222

23-
/*
24-
* For static allocation of some of the structures.
25-
*/
26-
#define IMC_MAX_PMUS 32
27-
2823
/*
2924
* Compatibility macros for IMC devices
3025
*/
@@ -125,4 +120,5 @@ enum {
125120
extern int init_imc_pmu(struct device_node *parent,
126121
struct imc_pmu *pmu_ptr, int pmu_id);
127122
extern void thread_imc_disable(void);
123+
extern int get_max_nest_dev(void);
128124
#endif /* __ASM_POWERPC_IMC_PMU_H */

arch/powerpc/perf/imc-pmu.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
static DEFINE_MUTEX(nest_init_lock);
2828
static DEFINE_PER_CPU(struct imc_pmu_ref *, local_nest_imc_refc);
29-
static struct imc_pmu *per_nest_pmu_arr[IMC_MAX_PMUS];
29+
static struct imc_pmu **per_nest_pmu_arr;
3030
static cpumask_t nest_imc_cpumask;
3131
struct imc_pmu_ref *nest_imc_refc;
3232
static int nest_pmus;
@@ -286,13 +286,14 @@ static struct imc_pmu_ref *get_nest_pmu_ref(int cpu)
286286
static void nest_change_cpu_context(int old_cpu, int new_cpu)
287287
{
288288
struct imc_pmu **pn = per_nest_pmu_arr;
289-
int i;
290289

291290
if (old_cpu < 0 || new_cpu < 0)
292291
return;
293292

294-
for (i = 0; *pn && i < IMC_MAX_PMUS; i++, pn++)
293+
while (*pn) {
295294
perf_pmu_migrate_context(&(*pn)->pmu, old_cpu, new_cpu);
295+
pn++;
296+
}
296297
}
297298

298299
static int ppc_nest_imc_cpu_offline(unsigned int cpu)
@@ -1212,6 +1213,7 @@ static void imc_common_cpuhp_mem_free(struct imc_pmu *pmu_ptr)
12121213
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs);
12131214
kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]);
12141215
kfree(pmu_ptr);
1216+
kfree(per_nest_pmu_arr);
12151217
return;
12161218
}
12171219

@@ -1236,6 +1238,13 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
12361238
return -ENOMEM;
12371239

12381240
/* Needed for hotplug/migration */
1241+
if (!per_nest_pmu_arr) {
1242+
per_nest_pmu_arr = kcalloc(get_max_nest_dev() + 1,
1243+
sizeof(struct imc_pmu *),
1244+
GFP_KERNEL);
1245+
if (!per_nest_pmu_arr)
1246+
return -ENOMEM;
1247+
}
12391248
per_nest_pmu_arr[pmu_index] = pmu_ptr;
12401249
break;
12411250
case IMC_DOMAIN_CORE:

arch/powerpc/platforms/powernv/opal-imc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ static void disable_core_pmu_counters(void)
159159
put_online_cpus();
160160
}
161161

162+
int get_max_nest_dev(void)
163+
{
164+
struct device_node *node;
165+
u32 pmu_units = 0, type;
166+
167+
for_each_compatible_node(node, NULL, IMC_DTB_UNIT_COMPAT) {
168+
if (of_property_read_u32(node, "type", &type))
169+
continue;
170+
171+
if (type == IMC_TYPE_CHIP)
172+
pmu_units++;
173+
}
174+
175+
return pmu_units;
176+
}
177+
162178
static int opal_imc_counters_probe(struct platform_device *pdev)
163179
{
164180
struct device_node *imc_dev = pdev->dev.of_node;

0 commit comments

Comments
 (0)