180 lines
5.0 KiB
Diff
180 lines
5.0 KiB
Diff
|
From 7b4f6ba1b1dc5f3120652bcb5921a697d5167bff Mon Sep 17 00:00:00 2001
|
||
|
From: Kan Liang <kan.liang@linux.intel.com>
|
||
|
Date: Fri, 2 Aug 2024 08:16:43 -0700
|
||
|
Subject: perf/x86/rapl: Clean up cpumask and hotplug
|
||
|
|
||
|
The rapl pmu is die scope, which is supported by the generic perf_event
|
||
|
subsystem now.
|
||
|
|
||
|
Set the scope for the rapl PMU and remove all the cpumask and hotplug
|
||
|
codes.
|
||
|
|
||
|
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
|
||
|
Cc: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
|
||
|
---
|
||
|
arch/x86/events/rapl.c | 80 +-------------------------------------
|
||
|
include/linux/cpuhotplug.h | 1 -
|
||
|
2 files changed, 2 insertions(+), 79 deletions(-)
|
||
|
|
||
|
--- a/arch/x86/events/rapl.c
|
||
|
+++ b/arch/x86/events/rapl.c
|
||
|
@@ -135,7 +135,6 @@ struct rapl_model {
|
||
|
/* 1/2^hw_unit Joule */
|
||
|
static int rapl_hw_unit[NR_RAPL_DOMAINS] __read_mostly;
|
||
|
static struct rapl_pmus *rapl_pmus;
|
||
|
-static cpumask_t rapl_cpu_mask;
|
||
|
static unsigned int rapl_cntr_mask;
|
||
|
static u64 rapl_timer_ms;
|
||
|
static struct perf_msr *rapl_msrs;
|
||
|
@@ -340,8 +339,6 @@ static int rapl_pmu_event_init(struct pe
|
||
|
if (event->cpu < 0)
|
||
|
return -EINVAL;
|
||
|
|
||
|
- event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG;
|
||
|
-
|
||
|
if (!cfg || cfg >= NR_RAPL_DOMAINS + 1)
|
||
|
return -EINVAL;
|
||
|
|
||
|
@@ -360,7 +357,6 @@ static int rapl_pmu_event_init(struct pe
|
||
|
pmu = cpu_to_rapl_pmu(event->cpu);
|
||
|
if (!pmu)
|
||
|
return -EINVAL;
|
||
|
- event->cpu = pmu->cpu;
|
||
|
event->pmu_private = pmu;
|
||
|
event->hw.event_base = rapl_msrs[bit].msr;
|
||
|
event->hw.config = cfg;
|
||
|
@@ -374,23 +370,6 @@ static void rapl_pmu_event_read(struct p
|
||
|
rapl_event_update(event);
|
||
|
}
|
||
|
|
||
|
-static ssize_t rapl_get_attr_cpumask(struct device *dev,
|
||
|
- struct device_attribute *attr, char *buf)
|
||
|
-{
|
||
|
- return cpumap_print_to_pagebuf(true, buf, &rapl_cpu_mask);
|
||
|
-}
|
||
|
-
|
||
|
-static DEVICE_ATTR(cpumask, S_IRUGO, rapl_get_attr_cpumask, NULL);
|
||
|
-
|
||
|
-static struct attribute *rapl_pmu_attrs[] = {
|
||
|
- &dev_attr_cpumask.attr,
|
||
|
- NULL,
|
||
|
-};
|
||
|
-
|
||
|
-static struct attribute_group rapl_pmu_attr_group = {
|
||
|
- .attrs = rapl_pmu_attrs,
|
||
|
-};
|
||
|
-
|
||
|
RAPL_EVENT_ATTR_STR(energy-cores, rapl_cores, "event=0x01");
|
||
|
RAPL_EVENT_ATTR_STR(energy-pkg , rapl_pkg, "event=0x02");
|
||
|
RAPL_EVENT_ATTR_STR(energy-ram , rapl_ram, "event=0x03");
|
||
|
@@ -438,7 +417,6 @@ static struct attribute_group rapl_pmu_f
|
||
|
};
|
||
|
|
||
|
static const struct attribute_group *rapl_attr_groups[] = {
|
||
|
- &rapl_pmu_attr_group,
|
||
|
&rapl_pmu_format_group,
|
||
|
&rapl_pmu_events_group,
|
||
|
NULL,
|
||
|
@@ -541,49 +519,6 @@ static struct perf_msr amd_rapl_msrs[] =
|
||
|
[PERF_RAPL_PSYS] = { 0, &rapl_events_psys_group, NULL, false, 0 },
|
||
|
};
|
||
|
|
||
|
-static int rapl_cpu_offline(unsigned int cpu)
|
||
|
-{
|
||
|
- struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
|
||
|
- int target;
|
||
|
-
|
||
|
- /* Check if exiting cpu is used for collecting rapl events */
|
||
|
- if (!cpumask_test_and_clear_cpu(cpu, &rapl_cpu_mask))
|
||
|
- return 0;
|
||
|
-
|
||
|
- pmu->cpu = -1;
|
||
|
- /* Find a new cpu to collect rapl events */
|
||
|
- target = cpumask_any_but(topology_die_cpumask(cpu), cpu);
|
||
|
-
|
||
|
- /* Migrate rapl events to the new target */
|
||
|
- if (target < nr_cpu_ids) {
|
||
|
- cpumask_set_cpu(target, &rapl_cpu_mask);
|
||
|
- pmu->cpu = target;
|
||
|
- perf_pmu_migrate_context(pmu->pmu, cpu, target);
|
||
|
- }
|
||
|
- return 0;
|
||
|
-}
|
||
|
-
|
||
|
-static int rapl_cpu_online(unsigned int cpu)
|
||
|
-{
|
||
|
- struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
|
||
|
- int target;
|
||
|
-
|
||
|
- if (!pmu)
|
||
|
- return -ENOMEM;
|
||
|
-
|
||
|
- /*
|
||
|
- * Check if there is an online cpu in the package which collects rapl
|
||
|
- * events already.
|
||
|
- */
|
||
|
- target = cpumask_any_and(&rapl_cpu_mask, topology_die_cpumask(cpu));
|
||
|
- if (target < nr_cpu_ids)
|
||
|
- return 0;
|
||
|
-
|
||
|
- cpumask_set_cpu(cpu, &rapl_cpu_mask);
|
||
|
- pmu->cpu = cpu;
|
||
|
- return 0;
|
||
|
-}
|
||
|
-
|
||
|
static int rapl_check_hw_unit(struct rapl_model *rm)
|
||
|
{
|
||
|
u64 msr_rapl_power_unit_bits;
|
||
|
@@ -707,6 +642,7 @@ static int __init init_rapl_pmus(void)
|
||
|
rapl_pmus->pmu.stop = rapl_pmu_event_stop;
|
||
|
rapl_pmus->pmu.read = rapl_pmu_event_read;
|
||
|
rapl_pmus->pmu.module = THIS_MODULE;
|
||
|
+ rapl_pmus->pmu.scope = PERF_PMU_SCOPE_DIE;
|
||
|
rapl_pmus->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE;
|
||
|
|
||
|
init_rapl_pmu();
|
||
|
@@ -857,24 +793,13 @@ static int __init rapl_pmu_init(void)
|
||
|
if (ret)
|
||
|
return ret;
|
||
|
|
||
|
- /*
|
||
|
- * Install callbacks. Core will call them for each online cpu.
|
||
|
- */
|
||
|
- ret = cpuhp_setup_state(CPUHP_AP_PERF_X86_RAPL_ONLINE,
|
||
|
- "perf/x86/rapl:online",
|
||
|
- rapl_cpu_online, rapl_cpu_offline);
|
||
|
- if (ret)
|
||
|
- goto out;
|
||
|
-
|
||
|
ret = perf_pmu_register(&rapl_pmus->pmu, "power", -1);
|
||
|
if (ret)
|
||
|
- goto out1;
|
||
|
+ goto out;
|
||
|
|
||
|
rapl_advertise();
|
||
|
return 0;
|
||
|
|
||
|
-out1:
|
||
|
- cpuhp_remove_state(CPUHP_AP_PERF_X86_RAPL_ONLINE);
|
||
|
out:
|
||
|
pr_warn("Initialization failed (%d), disabled\n", ret);
|
||
|
cleanup_rapl_pmus();
|
||
|
@@ -884,7 +809,6 @@ module_init(rapl_pmu_init);
|
||
|
|
||
|
static void __exit intel_rapl_exit(void)
|
||
|
{
|
||
|
- cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_RAPL_ONLINE);
|
||
|
perf_pmu_unregister(&rapl_pmus->pmu);
|
||
|
cleanup_rapl_pmus();
|
||
|
}
|
||
|
--- a/include/linux/cpuhotplug.h
|
||
|
+++ b/include/linux/cpuhotplug.h
|
||
|
@@ -207,7 +207,6 @@ enum cpuhp_state {
|
||
|
CPUHP_AP_PERF_X86_UNCORE_ONLINE,
|
||
|
CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
|
||
|
CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
|
||
|
- CPUHP_AP_PERF_X86_RAPL_ONLINE,
|
||
|
CPUHP_AP_PERF_S390_CF_ONLINE,
|
||
|
CPUHP_AP_PERF_S390_SF_ONLINE,
|
||
|
CPUHP_AP_PERF_ARM_CCI_ONLINE,
|