Skip to content

Commit 1a8f088

Browse files
kjain101mpe
authored andcommitted
powerpc/perf/hv-24x7: Add cpu hotplug support
Patch here adds cpu hotplug functions to hv_24x7 pmu. A new cpuhp_state "CPUHP_AP_PERF_POWERPC_HV_24x7_ONLINE" enum is added. The online callback function updates the cpumask only if its empty. As the primary intention of adding hotplug support is to designate a CPU to make HCALL to collect the counter data. The offline function test and clear corresponding cpu in a cpumask and update cpumask to any other active cpu. Signed-off-by: Kajol Jain <[email protected]> Reviewed-by: Gautham R. Shenoy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e978a3c commit 1a8f088

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

arch/powerpc/perf/hv-24x7.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ static int interface_version;
3131
/* Whether we have to aggregate result data for some domains. */
3232
static bool aggregate_result_elements;
3333

34+
static cpumask_t hv_24x7_cpumask;
35+
3436
static bool domain_is_valid(unsigned domain)
3537
{
3638
switch (domain) {
@@ -1641,6 +1643,45 @@ static struct pmu h_24x7_pmu = {
16411643
.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
16421644
};
16431645

1646+
static int ppc_hv_24x7_cpu_online(unsigned int cpu)
1647+
{
1648+
if (cpumask_empty(&hv_24x7_cpumask))
1649+
cpumask_set_cpu(cpu, &hv_24x7_cpumask);
1650+
1651+
return 0;
1652+
}
1653+
1654+
static int ppc_hv_24x7_cpu_offline(unsigned int cpu)
1655+
{
1656+
int target;
1657+
1658+
/* Check if exiting cpu is used for collecting 24x7 events */
1659+
if (!cpumask_test_and_clear_cpu(cpu, &hv_24x7_cpumask))
1660+
return 0;
1661+
1662+
/* Find a new cpu to collect 24x7 events */
1663+
target = cpumask_last(cpu_active_mask);
1664+
1665+
if (target < 0 || target >= nr_cpu_ids) {
1666+
pr_err("hv_24x7: CPU hotplug init failed\n");
1667+
return -1;
1668+
}
1669+
1670+
/* Migrate 24x7 events to the new target */
1671+
cpumask_set_cpu(target, &hv_24x7_cpumask);
1672+
perf_pmu_migrate_context(&h_24x7_pmu, cpu, target);
1673+
1674+
return 0;
1675+
}
1676+
1677+
static int hv_24x7_cpu_hotplug_init(void)
1678+
{
1679+
return cpuhp_setup_state(CPUHP_AP_PERF_POWERPC_HV_24x7_ONLINE,
1680+
"perf/powerpc/hv_24x7:online",
1681+
ppc_hv_24x7_cpu_online,
1682+
ppc_hv_24x7_cpu_offline);
1683+
}
1684+
16441685
static int hv_24x7_init(void)
16451686
{
16461687
int r;
@@ -1685,6 +1726,11 @@ static int hv_24x7_init(void)
16851726
if (r)
16861727
return r;
16871728

1729+
/* init cpuhotplug */
1730+
r = hv_24x7_cpu_hotplug_init();
1731+
if (r)
1732+
return r;
1733+
16881734
r = perf_pmu_register(&h_24x7_pmu, h_24x7_pmu.name, -1);
16891735
if (r)
16901736
return r;

include/linux/cpuhotplug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ enum cpuhp_state {
181181
CPUHP_AP_PERF_POWERPC_CORE_IMC_ONLINE,
182182
CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE,
183183
CPUHP_AP_PERF_POWERPC_TRACE_IMC_ONLINE,
184+
CPUHP_AP_PERF_POWERPC_HV_24x7_ONLINE,
184185
CPUHP_AP_WATCHDOG_ONLINE,
185186
CPUHP_AP_WORKQUEUE_ONLINE,
186187
CPUHP_AP_RCUTREE_ONLINE,

0 commit comments

Comments
 (0)