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
6845static 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-
8050static 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-
540474int 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- }
632555out :
633556 return rc ;
634557free :
@@ -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