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

drm/xe/pmu: Add attribute skeleton

Add the generic support for defining new attributes. This only adds
the macros and common infra for the event counters, but no counters
yet. This is going to be added as follow up changes.

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250124050411.2189060-5-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

+69 -4
+65 -4
drivers/gpu/drm/xe/xe_pmu.c
··· 61 61 if (gt >= XE_MAX_GT_PER_TILE) 62 62 return false; 63 63 64 - return false; 64 + return id < sizeof(pmu->supported_events) * BITS_PER_BYTE && 65 + pmu->supported_events & BIT_ULL(id); 65 66 } 66 67 67 68 static void xe_pmu_event_destroy(struct perf_event *event) ··· 214 213 .attrs = pmu_format_attrs, 215 214 }; 216 215 217 - static struct attribute *pmu_event_attrs[] = { 218 - /* No events yet */ 216 + __maybe_unused static ssize_t event_attr_show(struct device *dev, 217 + struct device_attribute *attr, char *buf) 218 + { 219 + struct perf_pmu_events_attr *pmu_attr = 220 + container_of(attr, struct perf_pmu_events_attr, attr); 221 + 222 + return sprintf(buf, "event=%#04llx\n", pmu_attr->id); 223 + } 224 + 225 + #define XE_EVENT_ATTR(name_, v_, id_) \ 226 + PMU_EVENT_ATTR(name_, pmu_event_ ## v_, id_, event_attr_show) 227 + 228 + #define XE_EVENT_ATTR_UNIT(name_, v_, unit_) \ 229 + PMU_EVENT_ATTR_STRING(name_.unit, pmu_event_unit_ ## v_, unit_) 230 + 231 + #define XE_EVENT_ATTR_GROUP(v_, id_, ...) \ 232 + static struct attribute *pmu_attr_ ##v_[] = { \ 233 + __VA_ARGS__, \ 234 + NULL \ 235 + }; \ 236 + static umode_t is_visible_##v_(struct kobject *kobj, \ 237 + struct attribute *attr, int idx) \ 238 + { \ 239 + struct perf_pmu_events_attr *pmu_attr; \ 240 + struct xe_pmu *pmu; \ 241 + \ 242 + pmu_attr = container_of(attr, typeof(*pmu_attr), attr.attr); \ 243 + pmu = container_of(dev_get_drvdata(kobj_to_dev(kobj)), \ 244 + typeof(*pmu), base); \ 245 + \ 246 + return event_supported(pmu, 0, id_) ? attr->mode : 0; \ 247 + } \ 248 + static const struct attribute_group pmu_group_ ##v_ = { \ 249 + .name = "events", \ 250 + .attrs = pmu_attr_ ## v_, \ 251 + .is_visible = is_visible_ ## v_, \ 252 + } 253 + 254 + #define XE_EVENT_ATTR_SIMPLE(name_, v_, id_, unit_) \ 255 + XE_EVENT_ATTR(name_, v_, id_) \ 256 + XE_EVENT_ATTR_UNIT(name_, v_, unit_) \ 257 + XE_EVENT_ATTR_GROUP(v_, id_, &pmu_event_ ##v_.attr.attr, \ 258 + &pmu_event_unit_ ##v_.attr.attr) 259 + 260 + #define XE_EVENT_ATTR_NOUNIT(name_, v_, id_) \ 261 + XE_EVENT_ATTR(name_, v_, id_) \ 262 + XE_EVENT_ATTR_GROUP(v_, id_, &pmu_event_ ##v_.attr.attr) 263 + 264 + static struct attribute *pmu_empty_event_attrs[] = { 265 + /* Empty - all events are added as groups with .attr_update() */ 219 266 NULL, 220 267 }; 221 268 222 269 static const struct attribute_group pmu_events_attr_group = { 223 270 .name = "events", 224 - .attrs = pmu_event_attrs, 271 + .attrs = pmu_empty_event_attrs, 225 272 }; 273 + 274 + static const struct attribute_group *pmu_events_attr_update[] = { 275 + /* No events yet */ 276 + NULL, 277 + }; 278 + 279 + static void set_supported_events(struct xe_pmu *pmu) 280 + { 281 + } 226 282 227 283 /** 228 284 * xe_pmu_unregister() - Remove/cleanup PMU registration ··· 331 273 332 274 pmu->name = name; 333 275 pmu->base.attr_groups = attr_groups; 276 + pmu->base.attr_update = pmu_events_attr_update; 334 277 pmu->base.scope = PERF_PMU_SCOPE_SYS_WIDE; 335 278 pmu->base.module = THIS_MODULE; 336 279 pmu->base.task_ctx_nr = perf_invalid_context; ··· 341 282 pmu->base.start = xe_pmu_event_start; 342 283 pmu->base.stop = xe_pmu_event_stop; 343 284 pmu->base.read = xe_pmu_event_read; 285 + 286 + set_supported_events(pmu); 344 287 345 288 ret = perf_pmu_register(&pmu->base, pmu->name, -1); 346 289 if (ret)
+4
drivers/gpu/drm/xe/xe_pmu_types.h
··· 30 30 * @name: Name as registered with perf core. 31 31 */ 32 32 const char *name; 33 + /** 34 + * @supported_events: Bitmap of supported events, indexed by event id 35 + */ 36 + u64 supported_events; 33 37 }; 34 38 35 39 #endif