Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe/gt_throttle: Tidy up attribute definition

Move the attribute definitions to be grouped together rather than near
the show() function: checkpatch keeps complaining about the missing
newline when defining new attributes and it reads better to group
everything, which should match e.g. the xe_pmu.c style.

While grouping them, also define a THROTTLE_ATTR_RO(), similar to
DEVICE_ATTR_RO(), and use it to define all attributes. This makes it
shorter and with a familiar syntax.

Finally, during the cri_throttle_attrs[] array definition, also
highlight what's coming from common attributes and what is CRI-specific.

These 3 things could be done as separate commits, but they are all about
the same thing: reduce the attribute definition verbosity and are very
simple and mechanical.

Reviewed-by: Raag Jadav <raag.jadav@intel.com>
Link: https://patch.msgid.link/20251029-gt-throttle-cri-v3-5-d1f5abbb8114@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

+35 -28
+35 -28
drivers/gpu/drm/xe/xe_gt_throttle.c
··· 93 93 94 94 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, U32_MAX)); 95 95 } 96 - static struct kobj_attribute attr_status = __ATTR_RO(status); 97 96 98 97 static ssize_t reason_pl1_show(struct kobject *kobj, 99 98 struct kobj_attribute *attr, char *buff) ··· 101 102 102 103 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, POWER_LIMIT_1_MASK)); 103 104 } 104 - static struct kobj_attribute attr_reason_pl1 = __ATTR_RO(reason_pl1); 105 105 106 106 static ssize_t reason_pl2_show(struct kobject *kobj, 107 107 struct kobj_attribute *attr, char *buff) ··· 109 111 110 112 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, POWER_LIMIT_2_MASK)); 111 113 } 112 - static struct kobj_attribute attr_reason_pl2 = __ATTR_RO(reason_pl2); 113 114 114 115 static ssize_t reason_pl4_show(struct kobject *kobj, 115 116 struct kobj_attribute *attr, char *buff) ··· 117 120 118 121 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, POWER_LIMIT_4_MASK)); 119 122 } 120 - static struct kobj_attribute attr_reason_pl4 = __ATTR_RO(reason_pl4); 121 123 122 124 static ssize_t reason_thermal_show(struct kobject *kobj, 123 125 struct kobj_attribute *attr, char *buff) ··· 125 129 126 130 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, THERMAL_LIMIT_MASK)); 127 131 } 128 - static struct kobj_attribute attr_reason_thermal = __ATTR_RO(reason_thermal); 129 132 130 133 static ssize_t reason_soc_thermal_show(struct kobject *kobj, 131 134 struct kobj_attribute *attr, char *buff) ··· 133 138 134 139 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, SOC_THERMAL_LIMIT_MASK)); 135 140 } 136 - static struct kobj_attribute attr_reason_soc_thermal = __ATTR_RO(reason_soc_thermal); 137 141 138 142 static ssize_t reason_prochot_show(struct kobject *kobj, 139 143 struct kobj_attribute *attr, char *buff) ··· 141 147 142 148 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PROCHOT_MASK)); 143 149 } 144 - static struct kobj_attribute attr_reason_prochot = __ATTR_RO(reason_prochot); 145 150 146 151 static ssize_t reason_ratl_show(struct kobject *kobj, 147 152 struct kobj_attribute *attr, char *buff) ··· 149 156 150 157 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, RATL_MASK)); 151 158 } 152 - static struct kobj_attribute attr_reason_ratl = __ATTR_RO(reason_ratl); 153 159 154 160 static ssize_t reason_vr_thermalert_show(struct kobject *kobj, 155 161 struct kobj_attribute *attr, char *buff) ··· 157 165 158 166 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, VR_THERMALERT_MASK)); 159 167 } 160 - static struct kobj_attribute attr_reason_vr_thermalert = __ATTR_RO(reason_vr_thermalert); 161 168 162 169 static ssize_t reason_soc_avg_thermal_show(struct kobject *kobj, 163 170 struct kobj_attribute *attr, char *buff) ··· 165 174 166 175 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, SOC_AVG_THERMAL_MASK)); 167 176 } 168 - static struct kobj_attribute attr_reason_soc_avg_thermal = __ATTR_RO(reason_soc_avg_thermal); 169 177 170 178 static ssize_t reason_vr_tdc_show(struct kobject *kobj, 171 179 struct kobj_attribute *attr, char *buff) ··· 173 183 174 184 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, VR_TDC_MASK)); 175 185 } 176 - static struct kobj_attribute attr_reason_vr_tdc = __ATTR_RO(reason_vr_tdc); 177 186 178 187 static ssize_t reason_fastvmode_show(struct kobject *kobj, 179 188 struct kobj_attribute *attr, char *buff) ··· 181 192 182 193 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, FASTVMODE_MASK)); 183 194 } 184 - static struct kobj_attribute attr_reason_fastvmode = __ATTR_RO(reason_fastvmode); 185 195 186 196 static ssize_t reason_mem_thermal_show(struct kobject *kobj, 187 197 struct kobj_attribute *attr, char *buff) ··· 189 201 190 202 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, MEM_THERMAL_MASK)); 191 203 } 192 - static struct kobj_attribute attr_reason_mem_thermal = __ATTR_RO(reason_mem_thermal); 193 204 194 205 static ssize_t reason_vr_thermal_show(struct kobject *kobj, 195 206 struct kobj_attribute *attr, char *buff) ··· 197 210 198 211 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, VR_THERMAL_MASK)); 199 212 } 200 - static struct kobj_attribute attr_reason_vr_thermal = __ATTR_RO(reason_vr_thermal); 201 213 202 214 static ssize_t reason_iccmax_show(struct kobject *kobj, 203 215 struct kobj_attribute *attr, char *buff) ··· 205 219 206 220 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, ICCMAX_MASK)); 207 221 } 208 - static struct kobj_attribute attr_reason_iccmax = __ATTR_RO(reason_iccmax); 209 222 210 223 static ssize_t reason_psys_pl1_show(struct kobject *kobj, 211 224 struct kobj_attribute *attr, char *buff) ··· 213 228 214 229 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PSYS_PL1_MASK)); 215 230 } 216 - static struct kobj_attribute attr_reason_psys_pl1 = __ATTR_RO(reason_psys_pl1); 217 231 218 232 static ssize_t reason_psys_pl2_show(struct kobject *kobj, 219 233 struct kobj_attribute *attr, char *buff) ··· 221 237 222 238 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PSYS_PL2_MASK)); 223 239 } 224 - static struct kobj_attribute attr_reason_psys_pl2 = __ATTR_RO(reason_psys_pl2); 225 240 226 241 static ssize_t reason_p0_freq_show(struct kobject *kobj, 227 242 struct kobj_attribute *attr, char *buff) ··· 229 246 230 247 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, P0_FREQ_MASK)); 231 248 } 232 - static struct kobj_attribute attr_reason_p0_freq = __ATTR_RO(reason_p0_freq); 233 249 234 250 static ssize_t reason_psys_crit_show(struct kobject *kobj, 235 251 struct kobj_attribute *attr, char *buff) ··· 237 255 238 256 return sysfs_emit(buff, "%u\n", is_throttled_by(gt, PSYS_CRIT_MASK)); 239 257 } 240 - static struct kobj_attribute attr_reason_psys_crit = __ATTR_RO(reason_psys_crit); 258 + 259 + #define THROTTLE_ATTR_RO(name) \ 260 + struct kobj_attribute attr_##name = __ATTR_RO(name) 261 + 262 + static THROTTLE_ATTR_RO(status); 263 + static THROTTLE_ATTR_RO(reason_pl1); 264 + static THROTTLE_ATTR_RO(reason_pl2); 265 + static THROTTLE_ATTR_RO(reason_pl4); 266 + static THROTTLE_ATTR_RO(reason_thermal); 267 + static THROTTLE_ATTR_RO(reason_prochot); 268 + static THROTTLE_ATTR_RO(reason_ratl); 269 + static THROTTLE_ATTR_RO(reason_vr_thermalert); 270 + static THROTTLE_ATTR_RO(reason_vr_tdc); 241 271 242 272 static struct attribute *throttle_attrs[] = { 243 273 &attr_status.attr, ··· 264 270 NULL 265 271 }; 266 272 273 + static THROTTLE_ATTR_RO(reason_vr_thermal); 274 + static THROTTLE_ATTR_RO(reason_soc_thermal); 275 + static THROTTLE_ATTR_RO(reason_mem_thermal); 276 + static THROTTLE_ATTR_RO(reason_iccmax); 277 + static THROTTLE_ATTR_RO(reason_soc_avg_thermal); 278 + static THROTTLE_ATTR_RO(reason_fastvmode); 279 + static THROTTLE_ATTR_RO(reason_psys_pl1); 280 + static THROTTLE_ATTR_RO(reason_psys_pl2); 281 + static THROTTLE_ATTR_RO(reason_p0_freq); 282 + static THROTTLE_ATTR_RO(reason_psys_crit); 283 + 267 284 static struct attribute *cri_throttle_attrs[] = { 285 + /* Common */ 268 286 &attr_status.attr, 269 - &attr_reason_prochot.attr, 270 - &attr_reason_soc_thermal.attr, 271 - &attr_reason_mem_thermal.attr, 272 - &attr_reason_vr_thermal.attr, 273 - &attr_reason_iccmax.attr, 274 - &attr_reason_ratl.attr, 275 - &attr_reason_soc_avg_thermal.attr, 276 - &attr_reason_fastvmode.attr, 277 - &attr_reason_pl4.attr, 278 287 &attr_reason_pl1.attr, 279 288 &attr_reason_pl2.attr, 289 + &attr_reason_pl4.attr, 290 + &attr_reason_prochot.attr, 291 + &attr_reason_ratl.attr, 292 + /* CRI */ 293 + &attr_reason_vr_thermal.attr, 294 + &attr_reason_soc_thermal.attr, 295 + &attr_reason_mem_thermal.attr, 296 + &attr_reason_iccmax.attr, 297 + &attr_reason_soc_avg_thermal.attr, 298 + &attr_reason_fastvmode.attr, 280 299 &attr_reason_psys_pl1.attr, 281 300 &attr_reason_psys_pl2.attr, 282 301 &attr_reason_p0_freq.attr,