Skip to content

Commit bbdd4df

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
dmaengine: idxd: Clean up cpumask and hotplug for perfmon
The idxd PMU is system-wide scope, which is supported by the generic perf_event subsystem now. Set the scope for the idxd PMU and remove all the cpumask and hotplug codes. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Fenghua Yu <fenghua.yu@intel.com> Link: https://lore.kernel.org/r/20240802151643.1691631-6-kan.liang@linux.intel.com
1 parent a8c73b8 commit bbdd4df

File tree

3 files changed

+1
-107
lines changed

3 files changed

+1
-107
lines changed

drivers/dma/idxd/idxd.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ struct idxd_pmu {
124124

125125
struct pmu pmu;
126126
char name[IDXD_NAME_SIZE];
127-
int cpu;
128127

129128
int n_counters;
130129
int counter_width;
@@ -135,8 +134,6 @@ struct idxd_pmu {
135134

136135
unsigned long supported_filters;
137136
int n_filters;
138-
139-
struct hlist_node cpuhp_node;
140137
};
141138

142139
#define IDXD_MAX_PRIORITY 0xf
@@ -803,14 +800,10 @@ void idxd_user_counter_increment(struct idxd_wq *wq, u32 pasid, int index);
803800
int perfmon_pmu_init(struct idxd_device *idxd);
804801
void perfmon_pmu_remove(struct idxd_device *idxd);
805802
void perfmon_counter_overflow(struct idxd_device *idxd);
806-
void perfmon_init(void);
807-
void perfmon_exit(void);
808803
#else
809804
static inline int perfmon_pmu_init(struct idxd_device *idxd) { return 0; }
810805
static inline void perfmon_pmu_remove(struct idxd_device *idxd) {}
811806
static inline void perfmon_counter_overflow(struct idxd_device *idxd) {}
812-
static inline void perfmon_init(void) {}
813-
static inline void perfmon_exit(void) {}
814807
#endif
815808

816809
/* debugfs */

drivers/dma/idxd/init.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,6 @@ static int __init idxd_init_module(void)
878878
else
879879
support_enqcmd = true;
880880

881-
perfmon_init();
882-
883881
err = idxd_driver_register(&idxd_drv);
884882
if (err < 0)
885883
goto err_idxd_driver_register;
@@ -928,7 +926,6 @@ static void __exit idxd_exit_module(void)
928926
idxd_driver_unregister(&idxd_drv);
929927
pci_unregister_driver(&idxd_pci_driver);
930928
idxd_cdev_remove();
931-
perfmon_exit();
932929
idxd_remove_debugfs();
933930
}
934931
module_exit(idxd_exit_module);

drivers/dma/idxd/perfmon.c

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,6 @@
66
#include "idxd.h"
77
#include "perfmon.h"
88

9-
static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr,
10-
char *buf);
11-
12-
static cpumask_t perfmon_dsa_cpu_mask;
13-
static bool cpuhp_set_up;
14-
static enum cpuhp_state cpuhp_slot;
15-
16-
/*
17-
* perf userspace reads this attribute to determine which cpus to open
18-
* counters on. It's connected to perfmon_dsa_cpu_mask, which is
19-
* maintained by the cpu hotplug handlers.
20-
*/
21-
static DEVICE_ATTR_RO(cpumask);
22-
23-
static struct attribute *perfmon_cpumask_attrs[] = {
24-
&dev_attr_cpumask.attr,
25-
NULL,
26-
};
27-
28-
static struct attribute_group cpumask_attr_group = {
29-
.attrs = perfmon_cpumask_attrs,
30-
};
31-
329
/*
3310
* These attributes specify the bits in the config word that the perf
3411
* syscall uses to pass the event ids and categories to perfmon.
@@ -67,16 +44,9 @@ static struct attribute_group perfmon_format_attr_group = {
6744

6845
static const struct attribute_group *perfmon_attr_groups[] = {
6946
&perfmon_format_attr_group,
70-
&cpumask_attr_group,
7147
NULL,
7248
};
7349

74-
static ssize_t cpumask_show(struct device *dev, struct device_attribute *attr,
75-
char *buf)
76-
{
77-
return cpumap_print_to_pagebuf(true, buf, &perfmon_dsa_cpu_mask);
78-
}
79-
8050
static bool is_idxd_event(struct idxd_pmu *idxd_pmu, struct perf_event *event)
8151
{
8252
return &idxd_pmu->pmu == event->pmu;
@@ -217,7 +187,6 @@ static int perfmon_pmu_event_init(struct perf_event *event)
217187
return -EINVAL;
218188

219189
event->hw.event_base = ioread64(PERFMON_TABLE_OFFSET(idxd));
220-
event->cpu = idxd->idxd_pmu->cpu;
221190
event->hw.config = event->attr.config;
222191

223192
if (event->group_leader != event)
@@ -488,6 +457,7 @@ static void idxd_pmu_init(struct idxd_pmu *idxd_pmu)
488457
idxd_pmu->pmu.stop = perfmon_pmu_event_stop;
489458
idxd_pmu->pmu.read = perfmon_pmu_event_update;
490459
idxd_pmu->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE;
460+
idxd_pmu->pmu.scope = PERF_PMU_SCOPE_SYS_WIDE;
491461
idxd_pmu->pmu.module = THIS_MODULE;
492462
}
493463

@@ -496,59 +466,17 @@ void perfmon_pmu_remove(struct idxd_device *idxd)
496466
if (!idxd->idxd_pmu)
497467
return;
498468

499-
cpuhp_state_remove_instance(cpuhp_slot, &idxd->idxd_pmu->cpuhp_node);
500469
perf_pmu_unregister(&idxd->idxd_pmu->pmu);
501470
kfree(idxd->idxd_pmu);
502471
idxd->idxd_pmu = NULL;
503472
}
504473

505-
static int perf_event_cpu_online(unsigned int cpu, struct hlist_node *node)
506-
{
507-
struct idxd_pmu *idxd_pmu;
508-
509-
idxd_pmu = hlist_entry_safe(node, typeof(*idxd_pmu), cpuhp_node);
510-
511-
/* select the first online CPU as the designated reader */
512-
if (cpumask_empty(&perfmon_dsa_cpu_mask)) {
513-
cpumask_set_cpu(cpu, &perfmon_dsa_cpu_mask);
514-
idxd_pmu->cpu = cpu;
515-
}
516-
517-
return 0;
518-
}
519-
520-
static int perf_event_cpu_offline(unsigned int cpu, struct hlist_node *node)
521-
{
522-
struct idxd_pmu *idxd_pmu;
523-
unsigned int target;
524-
525-
idxd_pmu = hlist_entry_safe(node, typeof(*idxd_pmu), cpuhp_node);
526-
527-
if (!cpumask_test_and_clear_cpu(cpu, &perfmon_dsa_cpu_mask))
528-
return 0;
529-
530-
target = cpumask_any_but(cpu_online_mask, cpu);
531-
/* migrate events if there is a valid target */
532-
if (target < nr_cpu_ids) {
533-
cpumask_set_cpu(target, &perfmon_dsa_cpu_mask);
534-
perf_pmu_migrate_context(&idxd_pmu->pmu, cpu, target);
535-
}
536-
537-
return 0;
538-
}
539-
540474
int perfmon_pmu_init(struct idxd_device *idxd)
541475
{
542476
union idxd_perfcap perfcap;
543477
struct idxd_pmu *idxd_pmu;
544478
int rc = -ENODEV;
545479

546-
/*
547-
* perfmon module initialization failed, nothing to do
548-
*/
549-
if (!cpuhp_set_up)
550-
return -ENODEV;
551-
552480
/*
553481
* If perfmon_offset or num_counters is 0, it means perfmon is
554482
* not supported on this hardware.
@@ -624,11 +552,6 @@ int perfmon_pmu_init(struct idxd_device *idxd)
624552
if (rc)
625553
goto free;
626554

627-
rc = cpuhp_state_add_instance(cpuhp_slot, &idxd_pmu->cpuhp_node);
628-
if (rc) {
629-
perf_pmu_unregister(&idxd->idxd_pmu->pmu);
630-
goto free;
631-
}
632555
out:
633556
return rc;
634557
free:
@@ -637,22 +560,3 @@ int perfmon_pmu_init(struct idxd_device *idxd)
637560

638561
goto out;
639562
}
640-
641-
void __init perfmon_init(void)
642-
{
643-
int rc = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
644-
"driver/dma/idxd/perf:online",
645-
perf_event_cpu_online,
646-
perf_event_cpu_offline);
647-
if (WARN_ON(rc < 0))
648-
return;
649-
650-
cpuhp_slot = rc;
651-
cpuhp_set_up = true;
652-
}
653-
654-
void __exit perfmon_exit(void)
655-
{
656-
if (cpuhp_set_up)
657-
cpuhp_remove_multi_state(cpuhp_slot);
658-
}

0 commit comments

Comments
 (0)