@@ -822,11 +822,6 @@ static ssize_t i915_pmu_event_show(struct device *dev,
822
822
return sprintf (buf , "config=0x%lx\n" , eattr -> val );
823
823
}
824
824
825
- static struct attribute_group i915_pmu_events_attr_group = {
826
- .name = "events" ,
827
- /* Patch in attrs at runtime. */
828
- };
829
-
830
825
static ssize_t
831
826
i915_pmu_get_attr_cpumask (struct device * dev ,
832
827
struct device_attribute * attr ,
@@ -846,13 +841,6 @@ static const struct attribute_group i915_pmu_cpumask_attr_group = {
846
841
.attrs = i915_cpumask_attrs ,
847
842
};
848
843
849
- static const struct attribute_group * i915_pmu_attr_groups [] = {
850
- & i915_pmu_format_attr_group ,
851
- & i915_pmu_events_attr_group ,
852
- & i915_pmu_cpumask_attr_group ,
853
- NULL
854
- };
855
-
856
844
#define __event (__config , __name , __unit ) \
857
845
{ \
858
846
.config = (__config), \
@@ -1026,23 +1014,23 @@ err:;
1026
1014
1027
1015
static void free_event_attributes (struct i915_pmu * pmu )
1028
1016
{
1029
- struct attribute * * attr_iter = i915_pmu_events_attr_group .attrs ;
1017
+ struct attribute * * attr_iter = pmu -> events_attr_group .attrs ;
1030
1018
1031
1019
for (; * attr_iter ; attr_iter ++ )
1032
1020
kfree ((* attr_iter )-> name );
1033
1021
1034
- kfree (i915_pmu_events_attr_group .attrs );
1022
+ kfree (pmu -> events_attr_group .attrs );
1035
1023
kfree (pmu -> i915_attr );
1036
1024
kfree (pmu -> pmu_attr );
1037
1025
1038
- i915_pmu_events_attr_group .attrs = NULL ;
1026
+ pmu -> events_attr_group .attrs = NULL ;
1039
1027
pmu -> i915_attr = NULL ;
1040
1028
pmu -> pmu_attr = NULL ;
1041
1029
}
1042
1030
1043
1031
static int i915_pmu_cpu_online (unsigned int cpu , struct hlist_node * node )
1044
1032
{
1045
- struct i915_pmu * pmu = hlist_entry_safe (node , typeof (* pmu ), node );
1033
+ struct i915_pmu * pmu = hlist_entry_safe (node , typeof (* pmu ), cpuhp . node );
1046
1034
1047
1035
GEM_BUG_ON (!pmu -> base .event_init );
1048
1036
@@ -1055,7 +1043,7 @@ static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node)
1055
1043
1056
1044
static int i915_pmu_cpu_offline (unsigned int cpu , struct hlist_node * node )
1057
1045
{
1058
- struct i915_pmu * pmu = hlist_entry_safe (node , typeof (* pmu ), node );
1046
+ struct i915_pmu * pmu = hlist_entry_safe (node , typeof (* pmu ), cpuhp . node );
1059
1047
unsigned int target ;
1060
1048
1061
1049
GEM_BUG_ON (!pmu -> base .event_init );
@@ -1072,8 +1060,6 @@ static int i915_pmu_cpu_offline(unsigned int cpu, struct hlist_node *node)
1072
1060
return 0 ;
1073
1061
}
1074
1062
1075
- static enum cpuhp_state cpuhp_slot = CPUHP_INVALID ;
1076
-
1077
1063
static int i915_pmu_register_cpuhp_state (struct i915_pmu * pmu )
1078
1064
{
1079
1065
enum cpuhp_state slot ;
@@ -1087,21 +1073,22 @@ static int i915_pmu_register_cpuhp_state(struct i915_pmu *pmu)
1087
1073
return ret ;
1088
1074
1089
1075
slot = ret ;
1090
- ret = cpuhp_state_add_instance (slot , & pmu -> node );
1076
+ ret = cpuhp_state_add_instance (slot , & pmu -> cpuhp . node );
1091
1077
if (ret ) {
1092
1078
cpuhp_remove_multi_state (slot );
1093
1079
return ret ;
1094
1080
}
1095
1081
1096
- cpuhp_slot = slot ;
1082
+ pmu -> cpuhp . slot = slot ;
1097
1083
return 0 ;
1098
1084
}
1099
1085
1100
1086
static void i915_pmu_unregister_cpuhp_state (struct i915_pmu * pmu )
1101
1087
{
1102
- WARN_ON (cpuhp_slot == CPUHP_INVALID );
1103
- WARN_ON (cpuhp_state_remove_instance (cpuhp_slot , & pmu -> node ));
1104
- cpuhp_remove_multi_state (cpuhp_slot );
1088
+ WARN_ON (pmu -> cpuhp .slot == CPUHP_INVALID );
1089
+ WARN_ON (cpuhp_state_remove_instance (pmu -> cpuhp .slot , & pmu -> cpuhp .node ));
1090
+ cpuhp_remove_multi_state (pmu -> cpuhp .slot );
1091
+ pmu -> cpuhp .slot = CPUHP_INVALID ;
1105
1092
}
1106
1093
1107
1094
static bool is_igp (struct drm_i915_private * i915 )
@@ -1118,6 +1105,13 @@ static bool is_igp(struct drm_i915_private *i915)
1118
1105
void i915_pmu_register (struct drm_i915_private * i915 )
1119
1106
{
1120
1107
struct i915_pmu * pmu = & i915 -> pmu ;
1108
+ const struct attribute_group * attr_groups [] = {
1109
+ & i915_pmu_format_attr_group ,
1110
+ & pmu -> events_attr_group ,
1111
+ & i915_pmu_cpumask_attr_group ,
1112
+ NULL
1113
+ };
1114
+
1121
1115
int ret = - ENOMEM ;
1122
1116
1123
1117
if (INTEL_GEN (i915 ) <= 2 ) {
@@ -1128,6 +1122,7 @@ void i915_pmu_register(struct drm_i915_private *i915)
1128
1122
spin_lock_init (& pmu -> lock );
1129
1123
hrtimer_init (& pmu -> timer , CLOCK_MONOTONIC , HRTIMER_MODE_REL );
1130
1124
pmu -> timer .function = i915_sample ;
1125
+ pmu -> cpuhp .slot = CPUHP_INVALID ;
1131
1126
1132
1127
if (!is_igp (i915 )) {
1133
1128
pmu -> name = kasprintf (GFP_KERNEL ,
@@ -1143,11 +1138,16 @@ void i915_pmu_register(struct drm_i915_private *i915)
1143
1138
if (!pmu -> name )
1144
1139
goto err ;
1145
1140
1146
- i915_pmu_events_attr_group .attrs = create_event_attributes (pmu );
1147
- if (!i915_pmu_events_attr_group .attrs )
1141
+ pmu -> events_attr_group .name = "events" ;
1142
+ pmu -> events_attr_group .attrs = create_event_attributes (pmu );
1143
+ if (!pmu -> events_attr_group .attrs )
1148
1144
goto err_name ;
1149
1145
1150
- pmu -> base .attr_groups = i915_pmu_attr_groups ;
1146
+ pmu -> base .attr_groups = kmemdup (attr_groups , sizeof (attr_groups ),
1147
+ GFP_KERNEL );
1148
+ if (!pmu -> base .attr_groups )
1149
+ goto err_attr ;
1150
+
1151
1151
pmu -> base .task_ctx_nr = perf_invalid_context ;
1152
1152
pmu -> base .event_init = i915_pmu_event_init ;
1153
1153
pmu -> base .add = i915_pmu_event_add ;
@@ -1159,7 +1159,7 @@ void i915_pmu_register(struct drm_i915_private *i915)
1159
1159
1160
1160
ret = perf_pmu_register (& pmu -> base , pmu -> name , -1 );
1161
1161
if (ret )
1162
- goto err_attr ;
1162
+ goto err_groups ;
1163
1163
1164
1164
ret = i915_pmu_register_cpuhp_state (pmu );
1165
1165
if (ret )
@@ -1169,6 +1169,8 @@ void i915_pmu_register(struct drm_i915_private *i915)
1169
1169
1170
1170
err_unreg :
1171
1171
perf_pmu_unregister (& pmu -> base );
1172
+ err_groups :
1173
+ kfree (pmu -> base .attr_groups );
1172
1174
err_attr :
1173
1175
pmu -> base .event_init = NULL ;
1174
1176
free_event_attributes (pmu );
@@ -1194,6 +1196,7 @@ void i915_pmu_unregister(struct drm_i915_private *i915)
1194
1196
1195
1197
perf_pmu_unregister (& pmu -> base );
1196
1198
pmu -> base .event_init = NULL ;
1199
+ kfree (pmu -> base .attr_groups );
1197
1200
if (!is_igp (i915 ))
1198
1201
kfree (pmu -> name );
1199
1202
free_event_attributes (pmu );
0 commit comments