powerpc/perf/hv-gpci: Add cpu hotplug support

Patch here adds cpu hotplug functions to hv_gpci pmu.
A new cpuhp_state "CPUHP_AP_PERF_POWERPC_HV_GPCI_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 <kjain@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201003074943.338618-4-kjain@linux.ibm.com
This commit is contained in:
Kajol Jain 2020-10-03 13:19:42 +05:30 committed by Michael Ellerman
parent 435387dd1f
commit dcb5cdf60a
2 changed files with 47 additions and 0 deletions

View file

@ -48,6 +48,8 @@ EVENT_DEFINE_RANGE_FORMAT(length, config1, 24, 31);
/* u32, byte offset */
EVENT_DEFINE_RANGE_FORMAT(offset, config1, 32, 63);
static cpumask_t hv_gpci_cpumask;
static struct attribute *format_attrs[] = {
&format_attr_request.attr,
&format_attr_starting_index.attr,
@ -266,6 +268,45 @@ static struct pmu h_gpci_pmu = {
.capabilities = PERF_PMU_CAP_NO_EXCLUDE,
};
static int ppc_hv_gpci_cpu_online(unsigned int cpu)
{
if (cpumask_empty(&hv_gpci_cpumask))
cpumask_set_cpu(cpu, &hv_gpci_cpumask);
return 0;
}
static int ppc_hv_gpci_cpu_offline(unsigned int cpu)
{
int target;
/* Check if exiting cpu is used for collecting gpci events */
if (!cpumask_test_and_clear_cpu(cpu, &hv_gpci_cpumask))
return 0;
/* Find a new cpu to collect gpci events */
target = cpumask_last(cpu_active_mask);
if (target < 0 || target >= nr_cpu_ids) {
pr_err("hv_gpci: CPU hotplug init failed\n");
return -1;
}
/* Migrate gpci events to the new target */
cpumask_set_cpu(target, &hv_gpci_cpumask);
perf_pmu_migrate_context(&h_gpci_pmu, cpu, target);
return 0;
}
static int hv_gpci_cpu_hotplug_init(void)
{
return cpuhp_setup_state(CPUHP_AP_PERF_POWERPC_HV_GPCI_ONLINE,
"perf/powerpc/hv_gcpi:online",
ppc_hv_gpci_cpu_online,
ppc_hv_gpci_cpu_offline);
}
static int hv_gpci_init(void)
{
int r;
@ -286,6 +327,11 @@ static int hv_gpci_init(void)
return -ENODEV;
}
/* init cpuhotplug */
r = hv_gpci_cpu_hotplug_init();
if (r)
return r;
/* sampling not supported */
h_gpci_pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;

View file

@ -183,6 +183,7 @@ enum cpuhp_state {
CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE,
CPUHP_AP_PERF_POWERPC_TRACE_IMC_ONLINE,
CPUHP_AP_PERF_POWERPC_HV_24x7_ONLINE,
CPUHP_AP_PERF_POWERPC_HV_GPCI_ONLINE,
CPUHP_AP_WATCHDOG_ONLINE,
CPUHP_AP_WORKQUEUE_ONLINE,
CPUHP_AP_RCUTREE_ONLINE,