Adds base i915 perf infrastructure for Gen performance metrics. This adds a DRM_IOCTL_I915_PERF_OPEN ioctl that takes an array of uint64 properties to configure a stream of metrics and returns a new fd usable with standard VFS system calls including read() to read typed and sized records; ioctl() to enable or disable capture and poll() to wait for data. A stream is opened something like: uint64_t properties[] = { /* Single context sampling */ DRM_I915_PERF_PROP_CTX_HANDLE, ctx_handle, /* Include OA reports in samples */ DRM_I915_PERF_PROP_SAMPLE_OA, true, /* OA unit configuration */ DRM_I915_PERF_PROP_OA_METRICS_SET, metrics_set_id, DRM_I915_PERF_PROP_OA_FORMAT, report_format, DRM_I915_PERF_PROP_OA_EXPONENT, period_exponent, }; struct drm_i915_perf_open_param parm = { .flags = I915_PERF_FLAG_FD_CLOEXEC | I915_PERF_FLAG_FD_NONBLOCK | I915_PERF_FLAG_DISABLED, .properties_ptr = (uint64_t)properties, .num_properties = sizeof(properties) / 16, }; int fd = drmIoctl(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m); Records read all start with a common { type, size } header with DRM_I915_PERF_RECORD_SAMPLE being of most interest. Sample records contain an extensible number of fields and it's the DRM_I915_PERF_PROP_SAMPLE_xyz properties given when opening that determine what's included in every sample. No specific streams are supported yet so any attempt to open a stream will return an error. v2: use i915_gem_context_get() - Chris Wilson v3: update read() interface to avoid passing state struct - Chris Wilson fix some rebase fallout, with i915-perf init/deinit v4: s/DRM_IORW/DRM_IOW/ - Emil Velikov
Showing the changes to include/uapi (1 of 5 files). Show all
Unified · Split
| @@ -258,6 +258,7 @@ typedef struct _drm_i915_sarea { · 257 unmodified lines | ||
| 258 | 258 | #define DRM_I915_GEM_USERPTR 0x33 |
| 259 | 259 | #define DRM_I915_GEM_CONTEXT_GETPARAM 0x34 |
| 260 | 260 | #define DRM_I915_GEM_CONTEXT_SETPARAM 0x35 |
| 261 | +#define DRM_I915_PERF_OPEN 0x36 | |
| 261 | 262 | |
| 262 | 263 | #define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) |
| 263 | 264 | #define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH) |
| @@ -311,6 +312,7 @@ typedef struct _drm_i915_sarea { · 47 unmodified lines | ||
| 311 | 312 | #define DRM_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_USERPTR, struct drm_i915_gem_userptr) |
| 312 | 313 | #define DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_GETPARAM, struct drm_i915_gem_context_param) |
| 313 | 314 | #define DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_SETPARAM, struct drm_i915_gem_context_param) |
| 315 | +#define DRM_IOCTL_I915_PERF_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_OPEN, struct drm_i915_perf_open_param) | |
| 314 | 316 | |
| 315 | 317 | /* Allow drivers to submit batchbuffers directly to hardware, relying |
| 316 | 318 | * on the security mechanisms provided by hardware. |
| @@ -1228,6 +1230,71 @@ struct drm_i915_gem_context_param { · 911 unmodified lines | ||
| 1228 | 1230 | __u64 value; |
| 1229 | 1231 | }; |
| 1230 | 1232 | |
| 1233 | +enum drm_i915_perf_property_id { | |
| 1234 | + /** | |
| 1235 | + * Open the stream for a specific context handle (as used with | |
| 1236 | + * execbuffer2). A stream opened for a specific context this way | |
| 1237 | + * won't typically require root privileges. | |
| 1238 | + */ | |
| 1239 | + DRM_I915_PERF_PROP_CTX_HANDLE = 1, | |
| 1240 | + | |
| 1241 | + DRM_I915_PERF_PROP_MAX /* non-ABI */ | |
| 1242 | +}; | |
| 1243 | + | |
| 1244 | +struct drm_i915_perf_open_param { | |
| 1245 | + __u32 flags; | |
| 1246 | +#define I915_PERF_FLAG_FD_CLOEXEC (1<<0) | |
| 1247 | +#define I915_PERF_FLAG_FD_NONBLOCK (1<<1) | |
| 1248 | +#define I915_PERF_FLAG_DISABLED (1<<2) | |
| 1249 | + | |
| 1250 | + /** The number of u64 (id, value) pairs */ | |
| 1251 | + __u32 num_properties; | |
| 1252 | + | |
| 1253 | + /** | |
| 1254 | + * Pointer to array of u64 (id, value) pairs configuring the stream | |
| 1255 | + * to open. | |
| 1256 | + */ | |
| 1257 | + __u64 __user properties_ptr; | |
| 1258 | +}; | |
| 1259 | + | |
| 1260 | +#define I915_PERF_IOCTL_ENABLE _IO('i', 0x0) | |
| 1261 | +#define I915_PERF_IOCTL_DISABLE _IO('i', 0x1) | |
| 1262 | + | |
| 1263 | +/** | |
| 1264 | + * Common to all i915 perf records | |
| 1265 | + */ | |
| 1266 | +struct drm_i915_perf_record_header { | |
| 1267 | + __u32 type; | |
| 1268 | + __u16 pad; | |
| 1269 | + __u16 size; | |
| 1270 | +}; | |
| 1271 | + | |
| 1272 | +enum drm_i915_perf_record_type { | |
| 1273 | + | |
| 1274 | + /** | |
| 1275 | + * Samples are the work horse record type whose contents are extensible | |
| 1276 | + * and defined when opening an i915 perf stream based on the given | |
| 1277 | + * properties. | |
| 1278 | + * | |
| 1279 | + * Boolean properties following the naming convention | |
| 1280 | + * DRM_I915_PERF_SAMPLE_xyz_PROP request the inclusion of 'xyz' data in | |
| 1281 | + * every sample. | |
| 1282 | + * | |
| 1283 | + * The order of these sample properties given by userspace has no | |
| 1284 | + * affect on the ordering of data within a sample. The order will be | |
| 1285 | + * documented here. | |
| 1286 | + * | |
| 1287 | + * struct { | |
| 1288 | + * struct drm_i915_perf_record_header header; | |
| 1289 | + * | |
| 1290 | + * TODO: itemize extensible sample data here | |
| 1291 | + * }; | |
| 1292 | + */ | |
| 1293 | + DRM_I915_PERF_RECORD_SAMPLE = 1, | |
| 1294 | + | |
| 1295 | + DRM_I915_PERF_RECORD_MAX /* non-ABI */ | |
| 1296 | +}; | |
| 1297 | + | |
| 1231 | 1298 | #if defined(__cplusplus) |
| 1232 | 1299 | } |
| 1233 | 1300 | #endif |