Add OA functionality to Xe
Subsystems (3)
cover Add OA functionality to Xe
This patchset is the initial port of i915 perf/OA functionality to the XE driver. The following features in i915 have not been ported and will be added (as new patches) if/as they are needed:
* Inline batch submission on stream exec_queue/hw_engine
* NOA wait
* GuC ctx id (guc_sw_ctx_id)
* CTX_R_PWR_CLK_STATE/GEN8_R_PWR_CLK_STATE
* hold_preemption (DRM_XE_OA_PROP_HOLD_PREEMPTION)
* sseu_config (DRM_XE_OA_PROP_GLOBAL_SSEU)
* MTL bios_c6_setup
* ratelimits
* compat ioctl
I am providing the following additional HAX patch (not part of this series) to help review these patches:
https://patchwork.freedesktop.org/patch/551683/?series=120100&rev=4
The commit message in the above patch explains how it can be useful for reviewing this series.
This series is also available at:
https://gitlab.freedesktop.org/adixit/kernel/-/tree/xe-oa
The series has been tested against this IGT series:
https://gitlab.freedesktop.org/adixit/igt-gpu-tools/-/tree/xe-oa
v2: Fix build
v3: Rebase, due to s/xe_engine/xe_exec_queue/
v4: Re-run for testing
v5: Address review comments, new patches 11 through 17
v6: New patches 18 through 21
Ashutosh Dixit (21):
drm/xe/uapi: Introduce OA (observability architecture) uapi drm/xe/oa: Add OA types
drm/xe/oa: Add registers and GPU commands used by OA drm/xe/oa: Module init/exit and probe/remove drm/xe/oa: Add/remove config ioctl's
drm/xe/oa: Start implementing OA stream open ioctl drm/xe/oa: OA stream initialization
drm/xe/oa: Expose OA stream fd
drm/xe/oa: Read file_operation
drm/xe/oa: Implement queries
drm/xe/oa: Override GuC RC with OA on PVC
drm/xe/uapi: "Perf" layer to support multiple perf counter stream
types
drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl drm/xe/uapi: Simplify OA configs in uapi
drm/xe/uapi: Remove OA format names from OA uapi drm/xe/oa: Make xe_oa_timestamp_frequency per gt drm/xe/oa: Remove filtering reports on context id drm/xe/uapi: More OA uapi fixes/additions
drm/xe/uapi: Drop OA_IOCTL_VERSION
drm/xe/uapi: Use OA unit id to identify OA unit drm/xe/uapi: Convert OA property key/value pairs to a struct
drivers/gpu/drm/xe/Makefile | 2 + drivers/gpu/drm/xe/regs/xe_engine_regs.h | 2 + drivers/gpu/drm/xe/regs/xe_gpu_commands.h | 13 + drivers/gpu/drm/xe/regs/xe_oa_regs.h | 173 ++ drivers/gpu/drm/xe/xe_device.c | 13 + drivers/gpu/drm/xe/xe_device_types.h | 4 + drivers/gpu/drm/xe/xe_gt_types.h | 4 + drivers/gpu/drm/xe/xe_guc_pc.c | 60 + drivers/gpu/drm/xe/xe_guc_pc.h | 3 + drivers/gpu/drm/xe/xe_hw_engine_types.h | 2 + drivers/gpu/drm/xe/xe_module.c | 5 + drivers/gpu/drm/xe/xe_oa.c | 2314 +++++++++++++++++++++ drivers/gpu/drm/xe/xe_oa.h | 27 + drivers/gpu/drm/xe/xe_oa_types.h | 307 +++ drivers/gpu/drm/xe/xe_perf.c | 36 + drivers/gpu/drm/xe/xe_perf.h | 16 + drivers/gpu/drm/xe/xe_query.c | 5 +- include/uapi/drm/xe_drm.h | 288 ++- 18 files changed, 3272 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/xe/regs/xe_oa_regs.h create mode 100644 drivers/gpu/drm/xe/xe_oa.c create mode 100644 drivers/gpu/drm/xe/xe_oa.h create mode 100644 drivers/gpu/drm/xe/xe_oa_types.h create mode 100644 drivers/gpu/drm/xe/xe_perf.c create mode 100644 drivers/gpu/drm/xe/xe_perf.h
Signature · 1 line
2.41.0
PATCH 1/21 drm/xe/uapi: Introduce OA (observability architecture) uapi
OA uapi allows userspace to:
* Read streams of performance counters written by hardware
* Configure (and reconfigure) which sets of perf counters are captured as part of OA streams
* Configure other properties (such as format and periodicity) of such captures.
* Query associated parameters such as OA unit timestamp freq, oa_unit_id's for hw engines and OA ioctl version
v2: Explain OA is observability architecture (Francois)
Change to reserved[7] in struct drm_xe_query_gts (Lionel)
--- include/uapi/drm/xe_drm.h | 255 +++++++++++++++++++++++++++++++++++++- 1 file changed, 253 insertions(+), 2 deletions(-)
include/uapi/drm/xe_drm.h +253 -2
@@ -111,6 +111,9 @@ struct xe_user_extension {#define DRM_XE_WAIT_USER_FENCE 0x0b#define DRM_XE_VM_MADVISE 0x0c#define DRM_XE_EXEC_QUEUE_GET_PROPERTY 0x0d +#define DRM_XE_OA_OPEN 0x16 +#define DRM_XE_OA_ADD_CONFIG 0x17 +#define DRM_XE_OA_REMOVE_CONFIG 0x18/* Must be kept compact -- no holes */ #define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query)
@@ -127,6 +130,9 @@ struct xe_user_extension {#define DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property)#define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)#define DRM_IOCTL_XE_VM_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_MADVISE, struct drm_xe_vm_madvise) +#define DRM_IOCTL_XE_OA_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_OPEN, struct drm_xe_oa_open_param) +#define DRM_IOCTL_XE_OA_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_ADD_CONFIG, struct drm_xe_oa_config) +#define DRM_IOCTL_XE_OA_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_REMOVE_CONFIG, __u64)/** * enum drm_xe_memory_class - Supported memory classes.
@@ -257,7 +263,8 @@ struct drm_xe_query_config {#define XE_QUERY_CONFIG_GT_COUNT 4#define XE_QUERY_CONFIG_MEM_REGION_COUNT 5#define XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY 6 -#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY + 1) +#define XE_QUERY_OA_IOCTL_VERSION 7 +#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_OA_IOCTL_VERSION + 1)/** @info: array of elements containing the config info */ __u64 info[]; };
@@ -294,7 +301,8 @@ struct drm_xe_query_gts {__u64 native_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ __u64 slow_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ __u64 inaccessible_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ -__u64 reserved[8 ]; +__u64 oa_timestamp_freq; +__u64 reserved[7 ]; } gts[]; };
@@ -748,6 +756,7 @@ struct drm_xe_engine_class_instance {__u16 engine_instance;__u16 gt_id; +__u16 oa_unit_id; };struct drm_xe_exec_queue_create {
@@ -1091,6 +1100,248 @@ struct drm_xe_vm_madvise {#define XE_PMU_MEDIA_GROUP_BUSY (gt) ___XE_PMU_OTHER(gt, 3)#define XE_PMU_ANY_ENGINE_GROUP_BUSY (gt) ___XE_PMU_OTHER(gt, 4) +enum drm_xe_oa_format { +XE_OA_FORMAT_C4_B8 =7 , + +/* Gen8+ */ +XE_OA_FORMAT_A12 , +XE_OA_FORMAT_A12_B8_C8 , + XE_OA_FORMAT_A32u40_A4u32_B8_C8, + +/* DG2 */ + XE_OAR_FORMAT_A32u40_A4u32_B8_C8, + XE_OA_FORMAT_A24u40_A14u32_B8_C8, + +/* MTL OAM */ + XE_OAM_FORMAT_MPEC8u64_B8_C8, + XE_OAM_FORMAT_MPEC8u32_B8_C8, + +XE_OA_FORMAT_MAX /* non-ABI */ +}; + +enum drm_xe_oa_property_id { +/** +* Open the stream for a specific exec queue id (as used with +* drm_xe_exec). A stream opened for a specific exec queue id this +* way won't typically require root privileges. +*/ +DRM_XE_OA_PROP_EXEC_QUEUE_ID =1 , + +/** +* A value of 1 requests the inclusion of raw OA unit reports as +* part of stream samples. +*/ +DRM_XE_OA_PROP_SAMPLE_OA , + +/** +* The value specifies which set of OA unit metrics should be +* configured, defining the contents of any OA unit reports. +*/ +DRM_XE_OA_PROP_OA_METRICS_SET , + +/** +* The value specifies the size and layout of OA unit reports. +*/ +DRM_XE_OA_PROP_OA_FORMAT , + +/** +* Specifying this property implicitly requests periodic OA unit +* sampling and (at least on Haswell) the sampling frequency is derived +* from this exponent as follows: +* +* 80ns * 2^(period_exponent + 1) +*/ +DRM_XE_OA_PROP_OA_EXPONENT , + +/** +* Specifying this property is only valid when specify a context to +* filter with DRM_XE_OA_PROP_ENGINE_ID. Specifying this property +* will hold preemption of the particular engine we want to gather +* performance data about. +*/ +DRM_XE_OA_PROP_HOLD_PREEMPTION , + +/** +* Specifying this pins all contexts to the specified SSEU power +* configuration for the duration of the recording. +* +* This parameter's value is a pointer to a struct +* drm_xe_gem_context_param_sseu (TBD). +*/ +DRM_XE_OA_PROP_GLOBAL_SSEU , + +/** +* This optional parameter specifies the timer interval in nanoseconds +* at which the xe driver will check the OA buffer for available data. +* Minimum allowed value is 100 microseconds. A default value is used by +* the driver if this parameter is not specified. Note that larger timer +* values will reduce cpu consumption during OA perf captures. However, +* excessively large values would potentially result in OA buffer +* overwrites as captures reach end of the OA buffer. +*/ +DRM_XE_OA_PROP_POLL_OA_PERIOD , + +/** +* Multiple engines may be mapped to the same OA unit. The OA unit is +* identified by class:instance of any engine mapped to it. +* +* This parameter specifies the engine class and must be passed along +* with DRM_XE_OA_PROP_OA_ENGINE_INSTANCE. +*/ +DRM_XE_OA_PROP_OA_ENGINE_CLASS , + +/** +* This parameter specifies the engine instance and must be passed along +* with DRM_XE_OA_PROP_OA_ENGINE_CLASS. +*/ +DRM_XE_OA_PROP_OA_ENGINE_INSTANCE , + +DRM_XE_OA_PROP_MAX /* non-ABI */ +}; + +struct drm_xe_oa_open_param { +__u32 flags; +#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) +#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) +#define XE_OA_FLAG_DISABLED (1 << 2) + +/** The number of u64 (id, value) pairs */ +__u32 num_properties; + +/** +* Pointer to array of u64 (id, value) pairs configuring the stream +* to open. +*/ +__u64 properties_ptr; +}; + +struct drm_xe_oa_record_header { +__u32 type; +__u16 pad; +__u16 size; +}; + +enum drm_xe_oa_record_type { +/** +* Samples are the work horse record type whose contents are +* extensible and defined when opening an xe oa stream based on the +* given properties. +* +* Boolean properties following the naming convention +* DRM_XE_OA_SAMPLE_xyz_PROP request the inclusion of 'xyz' data in +* every sample. +* +* The order of these sample properties given by userspace has no +* affect on the ordering of data within a sample. The order is +* documented here. +* +* struct { +* struct drm_xe_oa_record_header header; +* +* { u32 oa_report[]; } && DRM_XE_OA_PROP_SAMPLE_OA +* }; +*/ +DRM_XE_OA_RECORD_SAMPLE =1 , + +/** +* Indicates that one or more OA reports were not written by the +* hardware. This can happen for example if an MI_REPORT_PERF_COUNT +* command collides with periodic sampling - which would be more likely +* at higher sampling frequencies. +*/ +DRM_XE_OA_RECORD_OA_REPORT_LOST =2 , + +/** +* An error occurred that resulted in all pending OA reports being lost. +*/ +DRM_XE_OA_RECORD_OA_BUFFER_LOST =3 , + +DRM_XE_OA_RECORD_MAX /* non-ABI */ +}; + +struct drm_xe_oa_config { +/** +* @uuid: +* +* String formatted like "%\08x-%\04x-%\04x-%\04x-%\012x" +*/ +char uuid[36 ]; + +/** +* @n_mux_regs: +* +* Number of mux regs in &mux_regs_ptr. +*/ +__u32 n_mux_regs; + +/** +* @n_boolean_regs: +* +* Number of boolean regs in &boolean_regs_ptr. +*/ +__u32 n_boolean_regs; + +/** +* @n_flex_regs: +* +* Number of flex regs in &flex_regs_ptr. +*/ +__u32 n_flex_regs; + +/** +* @mux_regs_ptr: +* +* Pointer to tuples of u32 values (register address, value) for mux +* registers. Expected length of buffer is (2 * sizeof(u32) * +* &n_mux_regs). +*/ +__u64 mux_regs_ptr; + +/** +* @boolean_regs_ptr: +* +* Pointer to tuples of u32 values (register address, value) for mux +* registers. Expected length of buffer is (2 * sizeof(u32) * +* &n_boolean_regs). +*/ +__u64 boolean_regs_ptr; + +/** +* @flex_regs_ptr: +* +* Pointer to tuples of u32 values (register address, value) for mux +* registers. Expected length of buffer is (2 * sizeof(u32) * +* &n_flex_regs). +*/ +__u64 flex_regs_ptr; +}; + +/* +* Enable data capture for a stream that was either opened in a disabled state +* via I915_PERF_FLAG_DISABLED or was later disabled via +* I915_PERF_IOCTL_DISABLE. +* +* It is intended to be cheaper to disable and enable a stream than it may be +* to close and re-open a stream with the same configuration. +* +* It's undefined whether any pending data for the stream will be lost. +*/ +#define XE_OA_IOCTL_ENABLE _IO('i', 0x0) + +/* +* Disable data capture for a stream. +* +* It is an error to try and read a stream that is disabled. +*/ +#define XE_OA_IOCTL_DISABLE _IO('i', 0x1) + +/* +* Change metrics_set captured by a stream. +* +* Returns the previously bound metrics set id, or a negative error code. +*/ +#define XE_OA_IOCTL_CONFIG _IO('i', 0x2) +#if defined(__cplusplus) }#endif
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 01/21] drm/xe/uapi: Introduce OA (observability architecture) uapi
Quoted 22 lines · Ashutosh Dixit
OA uapi allows userspace to:
* Read streams of performance counters written by hardware
* Configure (and reconfigure) which sets of perf counters are captured as part of OA streams
* Configure other properties (such as format and periodicity) of such captures.
* Query associated parameters such as OA unit timestamp freq, oa_unit_id's for hw engines and OA ioctl versionv2: Explain OA is observability architecture (Francois)
Change to reserved[7] in structdrm_xe_query_gts(Lionel)Signed-off-by Ashutosh Dixit <[email protected]>---
include/uapi/drm/xe_drm.h| 255 +++++++++++++++++++++++++++++++++++++-1 file changed, 253 insertions(+), 2 deletions(-)include/uapi/drm/xe_drm.h +0
-0
include/uapi/drm/xe_drm.h struct xe_user_extension { · line 113
Quoted 3 lines
include/uapi/drm/xe_drm.h +0
-0@@ -111,6 +111,9 @@ struct xe_user_extension {#define DRM_XE_WAIT_USER_FENCE 0x0b#define DRM_XE_VM_MADVISE 0x0c#define DRM_XE_EXEC_QUEUE_GET_PROPERTY 0x0d
Assuming 0xe, 0xf are in the pipeline by someone else, As long as it's resolved before merge, we should be good.
Quoted 17 lines
include/uapi/drm/xe_drm.h +6
-0+#define DRM_XE_OA_OPEN 0x16 +#define DRM_XE_OA_ADD_CONFIG 0x17 +#define DRM_XE_OA_REMOVE_CONFIG 0x18/* Must be kept compact -- no holes */ #define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query)@@ -127,6 +130,9 @@ struct xe_user_extension {#define DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property)#define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)#define DRM_IOCTL_XE_VM_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_MADVISE, struct drm_xe_vm_madvise) +#define DRM_IOCTL_XE_OA_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_OPEN, struct drm_xe_oa_open_param) +#define DRM_IOCTL_XE_OA_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_ADD_CONFIG, struct drm_xe_oa_config) +#define DRM_IOCTL_XE_OA_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_REMOVE_CONFIG, __u64)/** * enum drm_xe_memory_class - Supported memory classes.
include/uapi/drm/xe_drm.h struct drm_xe_query_config { · line 266
Quoted 5 lines
include/uapi/drm/xe_drm.h +1
-1@@ -257,7 +263,8 @@ struct drm_xe_query_config {#define XE_QUERY_CONFIG_GT_COUNT 4#define XE_QUERY_CONFIG_MEM_REGION_COUNT 5#define XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY 6 -#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY + 1) +#define XE_QUERY_OA_IOCTL_VERSION 7
looks like removed in a later patch. why not just remove it here and avoid adding the backend implementation altogether? Although it would be ideal if the uApi and implementations are part of the same patch. I see that you are doing that in future patches, so ignore if the comment is redundant.
Quoted 35 lines
include/uapi/drm/xe_drm.h +13
-1+#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_OA_IOCTL_VERSION + 1)/** @info: array of elements containing the config info */ __u64 info[]; };@@ -294,7 +301,8 @@ struct drm_xe_query_gts {__u64 native_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ __u64 slow_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ __u64 inaccessible_mem_regions;/* bit mask of instances from drm_xe_query_mem_usage */ -__u64 reserved[8 ]; +__u64 oa_timestamp_freq; +__u64 reserved[7 ]; } gts[]; };@@ -748,6 +756,7 @@ struct drm_xe_engine_class_instance {__u16 engine_instance;__u16 gt_id; +__u16 oa_unit_id; };struct drm_xe_exec_queue_create {@@ -1091,6 +1100,248 @@ struct drm_xe_vm_madvise {#define XE_PMU_MEDIA_GROUP_BUSY (gt) ___XE_PMU_OTHER(gt, 3)#define XE_PMU_ANY_ENGINE_GROUP_BUSY (gt) ___XE_PMU_OTHER(gt, 4) +enum drm_xe_oa_format { +XE_OA_FORMAT_C4_B8 =7 , + +/* Gen8+ */ +XE_OA_FORMAT_A12 , +XE_OA_FORMAT_A12_B8_C8 , + XE_OA_FORMAT_A32u40_A4u32_B8_C8, + +/* DG2 */
include/uapi/drm/xe_drm.h struct drm_xe_vm_madvise { · line 1121
Quoted 10 lines
include/uapi/drm/xe_drm.h +10
-0+ XE_OAR_FORMAT_A32u40_A4u32_B8_C8, + XE_OA_FORMAT_A24u40_A14u32_B8_C8, + +/* MTL OAM */ + XE_OAM_FORMAT_MPEC8u64_B8_C8, + XE_OAM_FORMAT_MPEC8u32_B8_C8, + + XE_OA_FORMAT_MAX /* non-ABI */ +}; +
okay, I see what you meant when you said that things change in future patches, so I will stop reviewing this patch here and continue to review the future uapi patches.
Umesh
Quoted 229 lines
include/uapi/drm/xe_drm.h +223
-0+enum drm_xe_oa_property_id { +/** +* Open the stream for a specific exec queue id (as used with +* drm_xe_exec). A stream opened for a specific exec queue id this +* way won't typically require root privileges. +*/ +DRM_XE_OA_PROP_EXEC_QUEUE_ID =1 , + +/** +* A value of 1 requests the inclusion of raw OA unit reports as +* part of stream samples. +*/ +DRM_XE_OA_PROP_SAMPLE_OA , + +/** +* The value specifies which set of OA unit metrics should be +* configured, defining the contents of any OA unit reports. +*/ +DRM_XE_OA_PROP_OA_METRICS_SET , + +/** +* The value specifies the size and layout of OA unit reports. +*/ +DRM_XE_OA_PROP_OA_FORMAT , + +/** +* Specifying this property implicitly requests periodic OA unit +* sampling and (at least on Haswell) the sampling frequency is derived +* from this exponent as follows: +* +* 80ns * 2^(period_exponent + 1) +*/ +DRM_XE_OA_PROP_OA_EXPONENT , + +/** +* Specifying this property is only valid when specify a context to +* filter with DRM_XE_OA_PROP_ENGINE_ID. Specifying this property +* will hold preemption of the particular engine we want to gather +* performance data about. +*/ +DRM_XE_OA_PROP_HOLD_PREEMPTION , + +/** +* Specifying this pins all contexts to the specified SSEU power +* configuration for the duration of the recording. +* +* This parameter's value is a pointer to a struct +* drm_xe_gem_context_param_sseu (TBD). +*/ +DRM_XE_OA_PROP_GLOBAL_SSEU , + +/** +* This optional parameter specifies the timer interval in nanoseconds +* at which the xe driver will check the OA buffer for available data. +* Minimum allowed value is 100 microseconds. A default value is used by +* the driver if this parameter is not specified. Note that larger timer +* values will reduce cpu consumption during OA perf captures. However, +* excessively large values would potentially result in OA buffer +* overwrites as captures reach end of the OA buffer. +*/ +DRM_XE_OA_PROP_POLL_OA_PERIOD , + +/** +* Multiple engines may be mapped to the same OA unit. The OA unit is +* identified by class:instance of any engine mapped to it. +* +* This parameter specifies the engine class and must be passed along +* with DRM_XE_OA_PROP_OA_ENGINE_INSTANCE. +*/ +DRM_XE_OA_PROP_OA_ENGINE_CLASS , + +/** +* This parameter specifies the engine instance and must be passed along +* with DRM_XE_OA_PROP_OA_ENGINE_CLASS. +*/ +DRM_XE_OA_PROP_OA_ENGINE_INSTANCE , + +DRM_XE_OA_PROP_MAX /* non-ABI */ +}; + +struct drm_xe_oa_open_param { +__u32 flags; +#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) +#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) +#define XE_OA_FLAG_DISABLED (1 << 2) + +/** The number of u64 (id, value) pairs */ +__u32 num_properties; + +/** +* Pointer to array of u64 (id, value) pairs configuring the stream +* to open. +*/ +__u64 properties_ptr; +}; + +struct drm_xe_oa_record_header { +__u32 type; +__u16 pad; +__u16 size; +}; + +enum drm_xe_oa_record_type { +/** +* Samples are the work horse record type whose contents are +* extensible and defined when opening an xe oa stream based on the +* given properties. +* +* Boolean properties following the naming convention +* DRM_XE_OA_SAMPLE_xyz_PROP request the inclusion of 'xyz' data in +* every sample. +* +* The order of these sample properties given by userspace has no +* affect on the ordering of data within a sample. The order is +* documented here. +* +* struct { +* struct drm_xe_oa_record_header header; +* +* { u32 oa_report[]; } && DRM_XE_OA_PROP_SAMPLE_OA +* }; +*/ +DRM_XE_OA_RECORD_SAMPLE =1 , + +/** +* Indicates that one or more OA reports were not written by the +* hardware. This can happen for example if an MI_REPORT_PERF_COUNT +* command collides with periodic sampling - which would be more likely +* at higher sampling frequencies. +*/ +DRM_XE_OA_RECORD_OA_REPORT_LOST =2 , + +/** +* An error occurred that resulted in all pending OA reports being lost. +*/ +DRM_XE_OA_RECORD_OA_BUFFER_LOST =3 , + +DRM_XE_OA_RECORD_MAX /* non-ABI */ +}; + +struct drm_xe_oa_config { +/** +* @uuid: +* +* String formatted like "%\08x-%\04x-%\04x-%\04x-%\012x" +*/ +char uuid[36 ]; + +/** +* @n_mux_regs: +* +* Number of mux regs in &mux_regs_ptr. +*/ +__u32 n_mux_regs; + +/** +* @n_boolean_regs: +* +* Number of boolean regs in &boolean_regs_ptr. +*/ +__u32 n_boolean_regs; + +/** +* @n_flex_regs: +* +* Number of flex regs in &flex_regs_ptr. +*/ +__u32 n_flex_regs; + +/** +* @mux_regs_ptr: +* +* Pointer to tuples of u32 values (register address, value) for mux +* registers. Expected length of buffer is (2 * sizeof(u32) * +* &n_mux_regs). +*/ +__u64 mux_regs_ptr; + +/** +* @boolean_regs_ptr: +* +* Pointer to tuples of u32 values (register address, value) for mux +* registers. Expected length of buffer is (2 * sizeof(u32) * +* &n_boolean_regs). +*/ +__u64 boolean_regs_ptr; + +/** +* @flex_regs_ptr: +* +* Pointer to tuples of u32 values (register address, value) for mux +* registers. Expected length of buffer is (2 * sizeof(u32) * +* &n_flex_regs). +*/ +__u64 flex_regs_ptr; +}; + +/* +* Enable data capture for a stream that was either opened in a disabled state +* via I915_PERF_FLAG_DISABLED or was later disabled via +* I915_PERF_IOCTL_DISABLE. +* +* It is intended to be cheaper to disable and enable a stream than it may be +* to close and re-open a stream with the same configuration. +* +* It's undefined whether any pending data for the stream will be lost. +*/ +#define XE_OA_IOCTL_ENABLE _IO('i', 0x0) + +/* +* Disable data capture for a stream. +* +* It is an error to try and read a stream that is disabled. +*/ +#define XE_OA_IOCTL_DISABLE _IO('i', 0x1) + +/* +* Change metrics_set captured by a stream. +* +* Returns the previously bound metrics set id, or a negative error code. +*/ +#define XE_OA_IOCTL_CONFIG _IO('i', 0x2) +#if defined(__cplusplus) }#endif Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 01/21] drm/xe/uapi: Introduce OA (observability architecture) uapi
Quoted 4 lines · Umesh Nerlige Ramappa
okay, I see what you meant when you said that things change in future patches, so I will stop reviewing this patch here and continue to review the future uapi patches.
Yes I retained the patches since IMO it's easier to review patches (see what changed) rather than look at a giant blob of code. If you want to look the code the latest code is always availbable here (even before I post the patches):
https://gitlab.freedesktop.org/adixit/kernel/-/tree/xe-oa
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 01/21] drm/xe/uapi: Introduce OA (observability architecture) uapi
In reply to Ashutosh DixitQuoted 1 line · Ashutosh Dixit
Hi Umesh,
Quoted 32 lines
include/uapi/drm/xe_drm.h +32
-0+struct drm_xe_oa_record_header { +__u32 type; +__u16 pad; +__u16 size; +}; + +enum drm_xe_oa_record_type { +/** +* Samples are the work horse record type whose contents are +* extensible and defined when opening an xe oa stream based on the +* given properties. +* +* Boolean properties following the naming convention +* DRM_XE_OA_SAMPLE_xyz_PROP request the inclusion of 'xyz' data in +* every sample. +* +* The order of these sample properties given by userspace has no +* affect on the ordering of data within a sample. The order is +* documented here. +* +* struct { +* struct drm_xe_oa_record_header header; +* +* { u32 oa_report[]; } && DRM_XE_OA_PROP_SAMPLE_OA +* }; +*/ +DRM_XE_OA_RECORD_SAMPLE =1 , + +/** +* Indicates that one or more OA reports were not written by the +* hardware. This can happen for example if an MI_REPORT_PERF_COUNT +* command collides with periodic sampling - which would be more likely
include/uapi/drm/xe_drm.h struct drm_xe_vm_madvise { · line 1259
Quoted 10 lines
include/uapi/drm/xe_drm.h +10
-0+* at higher sampling frequencies. +*/ +DRM_XE_OA_RECORD_OA_REPORT_LOST =2 , + +/** +* An error occurred that resulted in all pending OA reports being lost. +*/ +DRM_XE_OA_RECORD_OA_BUFFER_LOST =3 , + +DRM_XE_OA_RECORD_MAX /* non-ABI */
Rather than maintain these statuses in the uapi, how about just returning oa_status register (from which these statuses come) directly to userland. Basically the 32 bit type can directly be the oa_status register directly. We can steal bit 31 (or something like that) to indicate a real SAMPLE vs a status header. This way only bit 31 gets into xe_drm.h. Thoughts?
Thanks.
--
Ashutosh
PATCH 2/21 drm/xe/oa: Add OA types
In reply to Ashutosh DixitAdd types and data structs used by OA. The data structs maintain device and gt level information, information about the open OA stream and OA buffer used internally to capture OA counters written by HW as well as capture configurations which can be selected for an OA stream.
v2: Add linux includes to fix build
v3: Change oa_unit_id to u16 (Umesh)
--- drivers/gpu/drm/xe/xe_oa_types.h | 295 +++++++++++++++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_oa_types.h
drivers/gpu/drm/xe/xe_oa_types.h new file +295 -0
@@ -0,0 +1,295 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef _XE_OA_TYPES_H_ +#define _XE_OA_TYPES_H__ + +#include <linux/idr.h> +#include <linux/kobject.h> +#include <linux/poll.h> +#include <linux/sysfs.h> +#include <drm/xe_drm.h> +#include "regs/xe_reg_defs.h" + +struct drm_device ; +struct drm_file ; + +enum { +OA_GROUP_OAG =0 , +OA_GROUP_OAM_SAMEDIA_0 =0 , + +OA_GROUP_MAX , +OA_GROUP_INVALID =U32_MAX , +}; + +enum oa_type { +TYPE_OAG , +TYPE_OAM , +}; + +enum report_header { +HDR_32_BIT =0 , +HDR_64_BIT , +}; + +struct xe_oa_format { +u32 format; +int size; +int type; +enum report_header header; +}; + +struct xe_oa_reg { +struct xe_reg addr; +u32 value; +}; + +struct xe_oa_config { +struct xe_oa *oa; + +char uuid[UUID_STRING_LEN +1 ]; +int id; + +const struct xe_oa_reg *mux_regs; +u32 mux_regs_len; +const struct xe_oa_reg *b_counter_regs; +u32 b_counter_regs_len; +const struct xe_oa_reg *flex_regs; +u32 flex_regs_len; + +struct attribute_group sysfs_metric; +struct attribute *attrs[2 ]; +struct kobj_attribute sysfs_metric_id; + +struct kref ref; +struct rcu_head rcu; +}; + +struct xe_oa_regs { +u32 base; +struct xe_reg oa_head_ptr; +struct xe_reg oa_tail_ptr; +struct xe_reg oa_buffer; +struct xe_reg oa_ctx_ctrl; +struct xe_reg oa_ctrl; +struct xe_reg oa_debug; +struct xe_reg oa_status; +u32 oa_ctrl_counter_format_shift; +}; + +/** +* struct xe_oa_group - OA group representing one hardware OA unit +*/ +struct xe_oa_group { +/** @oa_unit_id: identifier for the OA unit */ +u16 oa_unit_id; + +/** +* @exclusive_stream: The stream currently using the OA unit. This is +* sometimes accessed outside a syscall associated to its file +* descriptor. +*/ +struct xe_oa_stream *exclusive_stream; + +/** @num_engines: number of engines using this OA unit */ +u32 num_engines; + +/** @regs: OA buffer register group for programming the OA unit */ +struct xe_oa_regs regs; + +/** @type: Type of OA unit - OAM, OAG etc. */ +enum oa_type type; +}; + +/** +* struct xe_oa_gt - OA per-gt information +*/ +struct xe_oa_gt { +/** @lock: lock associated with anything below within this structure */ +struct mutex lock; + +/** @num_oa_groups: number of oa groups per gt */ +u32 num_oa_groups; + +/** @group: list of OA groups - one for each OA buffer */ +struct xe_oa_group *group; +}; + +/** +* struct xe_oa - OA device level information +*/ +struct xe_oa { +/** @xe: back pointer to xe device */ +struct xe_device *xe; + +/** @metrics_kobj: kobj for metrics sysfs */ +struct kobject *metrics_kobj; + +/** +* @metrics_lock: lock associated with adding/modifying/removing OA +* configs in oa->metrics_idr. +*/ +struct mutex metrics_lock; + +/** +* @metrics_idr: List of dynamic configurations (struct xe_oa_config) +*/ +struct idr metrics_idr; + +/** @ctx_oactxctrl_offset: offset of OACTXCONTROL register in context image */ +u32 ctx_oactxctrl_offset; + +/** @oa_formats: tracks all OA formats across platforms */ +const struct xe_oa_format *oa_formats; + +#define FORMAT_MASK_SIZE DIV_ROUND_UP(XE_OA_FORMAT_MAX - 1, BITS_PER_LONG) + +/** @format_mask: tracks valid OA formats for a platform */ +unsigned long format_mask[FORMAT_MASK_SIZE ]; + +/** @oa_unit_ids: tracks oa unit ids assigned across gt's */ +u16 oa_unit_ids; +}; + +/** +* struct xe_oa_stream - state for a single open stream FD +*/ +struct xe_oa_stream { +/** @oa: xe_oa backpointer */ +struct xe_oa *oa; + +/** @gt: gt associated with the oa stream */ +struct xe_gt *gt; + +/** +* @hwe: hardware engine associated with this performance stream. +*/ +struct xe_hw_engine *hwe; + +/** @lock: Lock associated with operations on stream */ +struct mutex lock; + +/** +* @sample: true when DRM_XE_OA_PROP_SAMPLE_OA is given when +* opening a stream, representing the contents of a single sample +* as read() by userspace. +*/ +bool sample; + +/** +* @sample_size: Considering the configured contents of a sample +* combined with the required header size, this is the total size +* of a single sample record. +*/ +int sample_size; + +/** +* @exec_q: %NULL if measuring system-wide across all exec_q's or a +* specific exec_q that is being monitored. +*/ +struct xe_exec_queue *exec_q; + +/** +* @enabled: Whether the stream is currently enabled, considering +* whether the stream was opened in a disabled state and based +* on `XE_OA_IOCTL_ENABLE` and `XE_OA_IOCTL_DISABLE` calls. +*/ +bool enabled; + +/** @oa_config: The OA configuration used by the stream */ +struct xe_oa_config *oa_config; + +/** +* @oa_config_bos: A list of struct i915_oa_config_bo allocated lazily +* each time @oa_config changes. +*/ +struct llist_head oa_config_bos; + +/** @specific_ctx_id: id of the context used for filtering reports */ +u32 specific_ctx_id; + +/** @specific_ctx_id_mask: The mask used to masking specific_ctx_id bits */ +u32 specific_ctx_id_mask; + +/** +* @poll_check_timer: High resolution timer that will periodically +* check for data in the circular OA buffer for notifying userspace +* (e.g. during a read() or poll()). +*/ +struct hrtimer poll_check_timer; + +/** +* @poll_wq: The wait queue that hrtimer callback wakes when it +* sees data ready to read in the circular OA buffer. +*/ +wait_queue_head_t poll_wq; + +/** @pollin: Whether there is data available to read */ +bool pollin; + +/** @periodic: Whether periodic sampling is currently enabled */ +bool periodic; + +/** @period_exponent: The OA unit sampling frequency is derived from this */ +int period_exponent; + +/** @oa_buffer: State of the OA buffer */ +struct { +/** @format: data format */ +const struct xe_oa_format *format; + +/** @format: xe_bo backing the OA buffer */ +struct xe_bo *bo; + +/** @vaddr: mapped vaddr of the OA buffer */ +u8 *vaddr; + +/** @last_ctx_id: last context id for OA data added */ +u32 last_ctx_id; + +/** +* @ptr_lock: Locks reads and writes to all head/tail state +* +* Consider: the head and tail pointer state needs to be read +* consistently from a hrtimer callback (atomic context) and +* read() fop (user context) with tail pointer updates happening +* in atomic context and head updates in user context and the +* (unlikely) possibility of read() errors needing to reset all +* head/tail state. +* +* Note: Contention/performance aren't currently a significant +* concern here considering the relatively low frequency of +* hrtimer callbacks (5ms period) and that reads typically only +* happen in response to a hrtimer event and likely complete +* before the next callback. +* +* Note: This lock is not held *while* reading and copying data +* to userspace so the value of head observed in htrimer +* callbacks won't represent any partial consumption of data. +*/ +spinlock_t ptr_lock; + +/** +* @head: Although we can always read back the head pointer register, +* we prefer to avoid trusting the HW state, just to avoid any +* risk that some hardware condition could somehow bump the +* head pointer unpredictably and cause us to forward the wrong +* OA buffer data to userspace. +*/ +u32 head; + +/** +* @tail: The last verified tail that can be read by userspace. +*/ +u32 tail; + } oa_buffer; + +/** +* @poll_oa_period: The period in nanoseconds at which the OA +* buffer should be checked for available data. +*/ +u64 poll_oa_period; +}; +#endif
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 02/21] drm/xe/oa: Add OA types
Quoted 9 lines · Ashutosh Dixit
Add types and data structs used by OA. The data structs maintain device and gt level information, information about the open OA stream and OA buffer used internally to capture OA counters written by HW as well as capture configurations which can be selected for an OA stream.
v2: Add linux includes to fix build
v3: Changeoa_unit_idto u16 (Umesh)Signed-off-by Ashutosh Dixit <[email protected]>
lgtm,
Umesh
Quoted 309 lines
---
drivers/gpu/drm/xe/xe_oa_types.h| 295 +++++++++++++++++++++++++++++++1 file changed, 295 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_oa_types.hdrivers/gpu/drm/xe/xe_oa_types.h new file +295
-0@@ -0,0 +1,295 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef _XE_OA_TYPES_H_ +#define _XE_OA_TYPES_H__ + +#include <linux/idr.h> +#include <linux/kobject.h> +#include <linux/poll.h> +#include <linux/sysfs.h> +#include <drm/xe_drm.h> +#include "regs/xe_reg_defs.h" + +struct drm_device ; +struct drm_file ; + +enum { +OA_GROUP_OAG =0 , +OA_GROUP_OAM_SAMEDIA_0 =0 , + +OA_GROUP_MAX , +OA_GROUP_INVALID =U32_MAX , +}; + +enum oa_type { +TYPE_OAG , +TYPE_OAM , +}; + +enum report_header { +HDR_32_BIT =0 , +HDR_64_BIT , +}; + +struct xe_oa_format { +u32 format; +int size; +int type; +enum report_header header; +}; + +struct xe_oa_reg { +struct xe_reg addr; +u32 value; +}; + +struct xe_oa_config { +struct xe_oa *oa; + +char uuid[UUID_STRING_LEN +1 ]; +int id; + +const struct xe_oa_reg *mux_regs; +u32 mux_regs_len; +const struct xe_oa_reg *b_counter_regs; +u32 b_counter_regs_len; +const struct xe_oa_reg *flex_regs; +u32 flex_regs_len; + +struct attribute_group sysfs_metric; +struct attribute *attrs[2 ]; +struct kobj_attribute sysfs_metric_id; + +struct kref ref; +struct rcu_head rcu; +}; + +struct xe_oa_regs { +u32 base; +struct xe_reg oa_head_ptr; +struct xe_reg oa_tail_ptr; +struct xe_reg oa_buffer; +struct xe_reg oa_ctx_ctrl; +struct xe_reg oa_ctrl; +struct xe_reg oa_debug; +struct xe_reg oa_status; +u32 oa_ctrl_counter_format_shift; +}; + +/** +* struct xe_oa_group - OA group representing one hardware OA unit +*/ +struct xe_oa_group { +/** @oa_unit_id: identifier for the OA unit */ +u16 oa_unit_id; + +/** +* @exclusive_stream: The stream currently using the OA unit. This is +* sometimes accessed outside a syscall associated to its file +* descriptor. +*/ +struct xe_oa_stream *exclusive_stream; + +/** @num_engines: number of engines using this OA unit */ +u32 num_engines; + +/** @regs: OA buffer register group for programming the OA unit */ +struct xe_oa_regs regs; + +/** @type: Type of OA unit - OAM, OAG etc. */ +enum oa_type type; +}; + +/** +* struct xe_oa_gt - OA per-gt information +*/ +struct xe_oa_gt { +/** @lock: lock associated with anything below within this structure */ +struct mutex lock; + +/** @num_oa_groups: number of oa groups per gt */ +u32 num_oa_groups; + +/** @group: list of OA groups - one for each OA buffer */ +struct xe_oa_group *group; +}; + +/** +* struct xe_oa - OA device level information +*/ +struct xe_oa { +/** @xe: back pointer to xe device */ +struct xe_device *xe; + +/** @metrics_kobj: kobj for metrics sysfs */ +struct kobject *metrics_kobj; + +/** +* @metrics_lock: lock associated with adding/modifying/removing OA +* configs in oa->metrics_idr. +*/ +struct mutex metrics_lock; + +/** +* @metrics_idr: List of dynamic configurations (struct xe_oa_config) +*/ +struct idr metrics_idr; + +/** @ctx_oactxctrl_offset: offset of OACTXCONTROL register in context image */ +u32 ctx_oactxctrl_offset; + +/** @oa_formats: tracks all OA formats across platforms */ +const struct xe_oa_format *oa_formats; + +#define FORMAT_MASK_SIZE DIV_ROUND_UP(XE_OA_FORMAT_MAX - 1, BITS_PER_LONG) + +/** @format_mask: tracks valid OA formats for a platform */ +unsigned long format_mask[FORMAT_MASK_SIZE ]; + +/** @oa_unit_ids: tracks oa unit ids assigned across gt's */ +u16 oa_unit_ids; +}; + +/** +* struct xe_oa_stream - state for a single open stream FD +*/ +struct xe_oa_stream { +/** @oa: xe_oa backpointer */ +struct xe_oa *oa; + +/** @gt: gt associated with the oa stream */ +struct xe_gt *gt; + +/** +* @hwe: hardware engine associated with this performance stream. +*/ +struct xe_hw_engine *hwe; + +/** @lock: Lock associated with operations on stream */ +struct mutex lock; + +/** +* @sample: true when DRM_XE_OA_PROP_SAMPLE_OA is given when +* opening a stream, representing the contents of a single sample +* as read() by userspace. +*/ +bool sample; + +/** +* @sample_size: Considering the configured contents of a sample +* combined with the required header size, this is the total size +* of a single sample record. +*/ +int sample_size; + +/** +* @exec_q: %NULL if measuring system-wide across all exec_q's or a +* specific exec_q that is being monitored. +*/ +struct xe_exec_queue *exec_q; + +/** +* @enabled: Whether the stream is currently enabled, considering +* whether the stream was opened in a disabled state and based +* on `XE_OA_IOCTL_ENABLE` and `XE_OA_IOCTL_DISABLE` calls. +*/ +bool enabled; + +/** @oa_config: The OA configuration used by the stream */ +struct xe_oa_config *oa_config; + +/** +* @oa_config_bos: A list of struct i915_oa_config_bo allocated lazily +* each time @oa_config changes. +*/ +struct llist_head oa_config_bos; + +/** @specific_ctx_id: id of the context used for filtering reports */ +u32 specific_ctx_id; + +/** @specific_ctx_id_mask: The mask used to masking specific_ctx_id bits */ +u32 specific_ctx_id_mask; + +/** +* @poll_check_timer: High resolution timer that will periodically +* check for data in the circular OA buffer for notifying userspace +* (e.g. during a read() or poll()). +*/ +struct hrtimer poll_check_timer; + +/** +* @poll_wq: The wait queue that hrtimer callback wakes when it +* sees data ready to read in the circular OA buffer. +*/ +wait_queue_head_t poll_wq; + +/** @pollin: Whether there is data available to read */ +bool pollin; + +/** @periodic: Whether periodic sampling is currently enabled */ +bool periodic; + +/** @period_exponent: The OA unit sampling frequency is derived from this */ +int period_exponent; + +/** @oa_buffer: State of the OA buffer */ +struct { +/** @format: data format */ +const struct xe_oa_format *format; + +/** @format: xe_bo backing the OA buffer */ +struct xe_bo *bo; + +/** @vaddr: mapped vaddr of the OA buffer */ +u8 *vaddr; + +/** @last_ctx_id: last context id for OA data added */ +u32 last_ctx_id; + +/** +* @ptr_lock: Locks reads and writes to all head/tail state +* +* Consider: the head and tail pointer state needs to be read +* consistently from a hrtimer callback (atomic context) and +* read() fop (user context) with tail pointer updates happening +* in atomic context and head updates in user context and the +* (unlikely) possibility of read() errors needing to reset all +* head/tail state. +* +* Note: Contention/performance aren't currently a significant +* concern here considering the relatively low frequency of +* hrtimer callbacks (5ms period) and that reads typically only +* happen in response to a hrtimer event and likely complete +* before the next callback. +* +* Note: This lock is not held *while* reading and copying data +* to userspace so the value of head observed in htrimer +* callbacks won't represent any partial consumption of data. +*/ +spinlock_t ptr_lock; + +/** +* @head: Although we can always read back the head pointer register, +* we prefer to avoid trusting the HW state, just to avoid any +* risk that some hardware condition could somehow bump the +* head pointer unpredictably and cause us to forward the wrong +* OA buffer data to userspace. +*/ +u32 head; + +/** +* @tail: The last verified tail that can be read by userspace. +*/ +u32 tail; + } oa_buffer; + +/** +* @poll_oa_period: The period in nanoseconds at which the OA +* buffer should be checked for available data. +*/ +u64 poll_oa_period; +}; +#endif Signature · 1 line
2.41.0
PATCH 3/21 drm/xe/oa: Add registers and GPU commands used by OA
In reply to Ashutosh DixitAdd registers and GPU commands used by OA in subsequent patches. The xe oa code programs OA units which generate performance data. The code also submits command buffers to change hardware engine context images and implement waits.
v2: Remove unused registers (used by noa wait) (Umesh)
--- drivers/gpu/drm/xe/regs/xe_engine_regs.h | 2 + drivers/gpu/drm/xe/regs/xe_gpu_commands.h | 13 ++ drivers/gpu/drm/xe/regs/xe_oa_regs.h | 173 ++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 drivers/gpu/drm/xe/regs/xe_oa_regs.h
drivers/gpu/drm/xe/regs/xe_engine_regs.h +2 -0
@@ -115,6 +115,8 @@#define RING_EXECLIST_CONTROL (base) XE_REG((base) + 0x550)#define EL_CTRL_LOAD REG_BIT(0) +#define GEN8_RING_CS_GPR (base, n) XE_REG((base) + 0x600 + (n) * 8) +#define VDBOX_CGCTL3F10 (base) XE_REG((base) + 0x3f10)#define IECPUNIT_CLKGATE_DIS REG_BIT(22)
drivers/gpu/drm/xe/regs/xe_gpu_commands.h +13 -0
@@ -14,6 +14,7 @@#define MI_INSTR (opcode, flags) \ (__INSTR(INSTR_MI_CLIENT) | (opcode) << 23 | (flags)) +#define MI_OPCODE (x) (((x) >> 23) & 0x3f)#define MI_NOOP MI_INSTR(0, 0)#define MI_USER_INTERRUPT MI_INSTR(0x02, 0)
@@ -23,12 +24,19 @@#define MI_ARB_DISABLE (0<<0)#define MI_BATCH_BUFFER_END MI_INSTR(0x0a, 0) +#define MI_STORE_DATA_IMM MI_INSTR(0x20, 0) +#define MI_STORE_DWORD_IMM_GEN4 MI_INSTR(0x20, 2)#define MI_LOAD_REGISTER_IMM (x) MI_INSTR(0x22, 2*(x)-1)#define MI_LRI_LRM_CS_MMIO REG_BIT(19)#define MI_LRI_MMIO_REMAP_EN REG_BIT(17)#define MI_LRI_FORCE_POSTED (1<<12) +#define IS_MI_LRI_CMD (x) (MI_OPCODE(x) == MI_OPCODE(MI_INSTR(0x22, 0))) +#define MI_LRI_LEN (x) (((x) & 0xff) + 1) + +#define MI_STORE_REGISTER_MEM MI_INSTR(0x24, 1) +#define MI_SRM_LRM_GLOBAL_GTT REG_BIT(22)#define MI_FLUSH_DW MI_INSTR(0x26, 1)#define MI_FLUSH_DW_STORE_INDEX (1<<21)
@@ -37,7 +45,12 @@#define MI_FLUSH_DW_OP_STOREDW (1<<14)#define MI_FLUSH_DW_USE_GTT (1<<2) +#define MI_LOAD_REGISTER_MEM MI_INSTR(0x29, 1) + +#define MI_LOAD_REGISTER_REG MI_INSTR(0x2A, 1) +#define MI_BATCH_BUFFER_START MI_INSTR(0x31, 1) +#define MI_BATCH_PREDICATE REG_BIT(15)/* HSW+ on RCS only*/ #define XY_CTRL_SURF_COPY_BLT ((2 << 29) | (0x48 << 22) | 3)#define SRC_ACCESS_TYPE_SHIFT 21
drivers/gpu/drm/xe/regs/xe_oa_regs.h new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 03/21] drm/xe/oa: Add registers and GPU commands used by OA
Quoted 8 lines · Ashutosh Dixit
Add registers and GPU commands used by OA in subsequent patches. The xe oa code programs OA units which generate performance data. The code also submits command buffers to change hardware engine context images and implement waits.
v2: Remove unused registers (used by noa wait) (Umesh)
Signed-off-by Ashutosh Dixit <[email protected]>
Quoted 247 lines
---
drivers/gpu/drm/xe/regs/xe_engine_regs.h | 2 + drivers/gpu/drm/xe/regs/xe_gpu_commands.h | 13 ++ drivers/gpu/drm/xe/regs/xe_oa_regs.h | 173 ++++++++++++++++++++++ 3 files changed, 188 insertions(+)create mode 100644
drivers/gpu/drm/xe/regs/xe_oa_regs.hdrivers/gpu/drm/xe/regs/xe_engine_regs.h +2
-0@@ -115,6 +115,8 @@#define RING_EXECLIST_CONTROL (base) XE_REG((base) + 0x550)#define EL_CTRL_LOAD REG_BIT(0) +#define GEN8_RING_CS_GPR (base, n) XE_REG((base) + 0x600 + (n) * 8) +#define VDBOX_CGCTL3F10 (base) XE_REG((base) + 0x3f10)#define IECPUNIT_CLKGATE_DIS REG_BIT(22)drivers/gpu/drm/xe/regs/xe_gpu_commands.h +13
-0@@ -14,6 +14,7 @@#define MI_INSTR (opcode, flags) \ (__INSTR(INSTR_MI_CLIENT) | (opcode) << 23 | (flags)) +#define MI_OPCODE (x) (((x) >> 23) & 0x3f)#define MI_NOOP MI_INSTR(0, 0)#define MI_USER_INTERRUPT MI_INSTR(0x02, 0)@@ -23,12 +24,19 @@#define MI_ARB_DISABLE (0<<0)#define MI_BATCH_BUFFER_END MI_INSTR(0x0a, 0) +#define MI_STORE_DATA_IMM MI_INSTR(0x20, 0) +#define MI_STORE_DWORD_IMM_GEN4 MI_INSTR(0x20, 2)#define MI_LOAD_REGISTER_IMM (x) MI_INSTR(0x22, 2*(x)-1)#define MI_LRI_LRM_CS_MMIO REG_BIT(19)#define MI_LRI_MMIO_REMAP_EN REG_BIT(17)#define MI_LRI_FORCE_POSTED (1<<12) +#define IS_MI_LRI_CMD (x) (MI_OPCODE(x) == MI_OPCODE(MI_INSTR(0x22, 0))) +#define MI_LRI_LEN (x) (((x) & 0xff) + 1) + +#define MI_STORE_REGISTER_MEM MI_INSTR(0x24, 1) +#define MI_SRM_LRM_GLOBAL_GTT REG_BIT(22)#define MI_FLUSH_DW MI_INSTR(0x26, 1)#define MI_FLUSH_DW_STORE_INDEX (1<<21)@@ -37,7 +45,12 @@#define MI_FLUSH_DW_OP_STOREDW (1<<14)#define MI_FLUSH_DW_USE_GTT (1<<2) +#define MI_LOAD_REGISTER_MEM MI_INSTR(0x29, 1) + +#define MI_LOAD_REGISTER_REG MI_INSTR(0x2A, 1) +#define MI_BATCH_BUFFER_START MI_INSTR(0x31, 1) +#define MI_BATCH_PREDICATE REG_BIT(15)/* HSW+ on RCS only*/ #define XY_CTRL_SURF_COPY_BLT ((2 << 29) | (0x48 << 22) | 3)#define SRC_ACCESS_TYPE_SHIFT 21drivers/gpu/drm/xe/regs/xe_oa_regs.h new file +173
-0@@ -0,0 +1,173 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef __XE_OA_REGS__ +#define __XE_OA_REGS__ + +#define REG_EQUAL (reg, xe_reg) ((reg) == (xe_reg.addr)) +#define REG_EQUAL_MCR (reg, xe_reg) ((reg) == (xe_reg.__reg.addr)) + +#define HALF_SLICE_CHICKEN2 XE_REG_MCR(0xe180) +#define GEN8_ST_PO_DISABLE REG_BIT(13) + +#define GEN7_ROW_CHICKEN2 XE_REG(0xe4f4) +#define GEN8_ROW_CHICKEN XE_REG_MCR(0xe4f0) +#define STALL_DOP_GATING_DISABLE REG_BIT(5) +#define GEN12_DISABLE_DOP_GATING REG_BIT(0) + +#define RPM_CONFIG1 XE_REG(0xd04) +#define GEN10_GT_NOA_ENABLE REG_BIT(9) + +#define WAIT_FOR_RC6_EXIT XE_REG(0x20cc) +#define HSW_WAIT_FOR_RC6_EXIT_ENABLE REG_BIT(0) + +#define EU_PERF_CNTL0 XE_REG(0xe458) +#define EU_PERF_CNTL4 XE_REG(0xe45c) +#define EU_PERF_CNTL1 XE_REG(0xe558) +#define EU_PERF_CNTL5 XE_REG(0xe55c) +#define EU_PERF_CNTL2 XE_REG(0xe658) +#define EU_PERF_CNTL6 XE_REG(0xe65c) +#define EU_PERF_CNTL3 XE_REG(0xe758) + +#define OABUFFER_SIZE_MASK REG_GENMASK(5, 3) +#define OABUFFER_SIZE_128K REG_FIELD_PREP(OABUFFER_SIZE_MASK, 0) +#define OABUFFER_SIZE_256K REG_FIELD_PREP(OABUFFER_SIZE_MASK, 1) +#define OABUFFER_SIZE_512K REG_FIELD_PREP(OABUFFER_SIZE_MASK, 2) +#define OABUFFER_SIZE_1M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 3) +#define OABUFFER_SIZE_2M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 4) +#define OABUFFER_SIZE_4M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 5) +#define OABUFFER_SIZE_8M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 6) +#define OABUFFER_SIZE_16M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 7) + +#define GEN12_OA_TLB_INV_CR XE_REG(0xceec) + +/* Gen12 OAR unit */ +#define GEN12_OAR_OACONTROL XE_REG(0x2960) +#define GEN12_OAR_OACONTROL_COUNTER_FORMAT_SHIFT 1 +#define GEN12_OAR_OACONTROL_COUNTER_ENABLE REG_BIT(0) + +#define GEN8_OACTXCONTROL XE_REG(0x2360) +#define GEN8_OA_COUNTER_RESUME REG_BIT(0) + +#define GEN12_OACTXCONTROL (base) XE_REG((base) + 0x360) +#define GEN12_OAR_OASTATUS XE_REG(0x2968) + +/* Gen12 OAG unit */ +#define GEN12_OAG_OAHEADPTR XE_REG(0xdb00) +#define GEN12_OAG_OAHEADPTR_MASK 0xffffffc0 +#define GEN12_OAG_OATAILPTR XE_REG(0xdb04) +#define GEN12_OAG_OATAILPTR_MASK 0xffffffc0 + +#define GEN12_OAG_OABUFFER XE_REG(0xdb08) +#define GEN12_OAG_OABUFFER_BUFFER_SIZE_MASK (0x7) +#define GEN12_OAG_OABUFFER_BUFFER_SIZE_SHIFT (3) +#define GEN12_OAG_OABUFFER_MEMORY_SELECT REG_BIT(0)/* 0: PPGTT, 1: GGTT */ + +#define GEN12_OAG_OAGLBCTXCTRL XE_REG(0x2b28) +#define GEN12_OAG_OAGLBCTXCTRL_TIMER_PERIOD_SHIFT 2 +#define GEN12_OAG_OAGLBCTXCTRL_TIMER_ENABLE REG_BIT(1) +#define GEN12_OAG_OAGLBCTXCTRL_COUNTER_RESUME REG_BIT(0) + +#define GEN12_OAG_OACONTROL XE_REG(0xdaf4) +#define GEN12_OAG_OACONTROL_OA_COUNTER_FORMAT_SHIFT 2 +#define GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE REG_BIT(0) + +#define GEN12_OAG_OA_DEBUG XE_REG(0xdaf8) +#define GEN12_OAG_OA_DEBUG_INCLUDE_CLK_RATIO REG_BIT(6) +#define GEN12_OAG_OA_DEBUG_DISABLE_CLK_RATIO_REPORTS REG_BIT(5) +#define GEN12_OAG_OA_DEBUG_DISABLE_GO_1_0_REPORTS REG_BIT(2) +#define GEN12_OAG_OA_DEBUG_DISABLE_CTX_SWITCH_REPORTS REG_BIT(1) + +#define GEN12_OAG_OASTATUS XE_REG(0xdafc) +#define GEN12_OAG_OASTATUS_COUNTER_OVERFLOW REG_BIT(2) +#define GEN12_OAG_OASTATUS_BUFFER_OVERFLOW REG_BIT(1) +#define GEN12_OAG_OASTATUS_REPORT_LOST REG_BIT(0) + +#define GDT_CHICKEN_BITS XE_REG(0x9840) +#define GT_NOA_ENABLE 0x00000080 + +#define GEN12_SQCNT1 XE_REG(0x8718) +#define GEN12_SQCNT1_PMON_ENABLE REG_BIT(30) +#define GEN12_SQCNT1_OABPC REG_BIT(29) + +/* Gen12 OAM unit */ +#define GEN12_OAM_HEAD_POINTER_OFFSET (0x1a0) +#define GEN12_OAM_HEAD_POINTER_MASK 0xffffffc0 + +#define GEN12_OAM_TAIL_POINTER_OFFSET (0x1a4) +#define GEN12_OAM_TAIL_POINTER_MASK 0xffffffc0 + +#define GEN12_OAM_BUFFER_OFFSET (0x1a8) +#define GEN12_OAM_BUFFER_SIZE_MASK (0x7) +#define GEN12_OAM_BUFFER_SIZE_SHIFT (3) +#define GEN12_OAM_BUFFER_MEMORY_SELECT REG_BIT(0)/* 0: PPGTT, 1: GGTT */ + +#define GEN12_OAM_CONTEXT_CONTROL_OFFSET (0x1bc) +#define GEN12_OAM_CONTEXT_CONTROL_TIMER_PERIOD_SHIFT 2 +#define GEN12_OAM_CONTEXT_CONTROL_TIMER_ENABLE REG_BIT(1) +#define GEN12_OAM_CONTEXT_CONTROL_COUNTER_RESUME REG_BIT(0) + +#define GEN12_OAM_CONTROL_OFFSET (0x194) +#define GEN12_OAM_CONTROL_COUNTER_FORMAT_SHIFT 1 +#define GEN12_OAM_CONTROL_COUNTER_ENABLE REG_BIT(0) + +#define GEN12_OAM_DEBUG_OFFSET (0x198) +#define GEN12_OAM_DEBUG_BUFFER_SIZE_SELECT REG_BIT(12) +#define GEN12_OAM_DEBUG_INCLUDE_CLK_RATIO REG_BIT(6) +#define GEN12_OAM_DEBUG_DISABLE_CLK_RATIO_REPORTS REG_BIT(5) +#define GEN12_OAM_DEBUG_DISABLE_GO_1_0_REPORTS REG_BIT(2) +#define GEN12_OAM_DEBUG_DISABLE_CTX_SWITCH_REPORTS REG_BIT(1) + +#define GEN12_OAM_STATUS_OFFSET (0x19c) +#define GEN12_OAM_STATUS_COUNTER_OVERFLOW REG_BIT(2) +#define GEN12_OAM_STATUS_BUFFER_OVERFLOW REG_BIT(1) +#define GEN12_OAM_STATUS_REPORT_LOST REG_BIT(0) + +#define GEN12_OAM_MMIO_TRG_OFFSET (0x1d0) + +#define GEN12_OAM_MMIO_TRG (base) \ + XE_REG((base) + GEN12_OAM_MMIO_TRG_OFFSET) + +#define GEN12_OAM_HEAD_POINTER (base) \ + XE_REG((base) + GEN12_OAM_HEAD_POINTER_OFFSET) +#define GEN12_OAM_TAIL_POINTER (base) \ + XE_REG((base) + GEN12_OAM_TAIL_POINTER_OFFSET) +#define GEN12_OAM_BUFFER (base) \ + XE_REG((base) + GEN12_OAM_BUFFER_OFFSET) +#define GEN12_OAM_CONTEXT_CONTROL (base) \ + XE_REG((base) + GEN12_OAM_CONTEXT_CONTROL_OFFSET) +#define GEN12_OAM_CONTROL (base) \ + XE_REG((base) + GEN12_OAM_CONTROL_OFFSET) +#define GEN12_OAM_DEBUG (base) \ + XE_REG((base) + GEN12_OAM_DEBUG_OFFSET) +#define GEN12_OAM_STATUS (base) \ + XE_REG((base) + GEN12_OAM_STATUS_OFFSET) + +#define GEN12_OAM_CEC0_0_OFFSET (0x40) +#define GEN12_OAM_CEC7_1_OFFSET (0x7c) +#define GEN12_OAM_CEC0_0 (base) \ + XE_REG((base) + GEN12_OAM_CEC0_0_OFFSET) +#define GEN12_OAM_CEC7_1 (base) \ + XE_REG((base) + GEN12_OAM_CEC7_1_OFFSET) + +#define GEN12_OAM_STARTTRIG1_OFFSET (0x00) +#define GEN12_OAM_STARTTRIG8_OFFSET (0x1c) +#define GEN12_OAM_STARTTRIG1 (base) \ + XE_REG((base) + GEN12_OAM_STARTTRIG1_OFFSET) +#define GEN12_OAM_STARTTRIG8 (base) \ + XE_REG((base) + GEN12_OAM_STARTTRIG8_OFFSET) + +#define GEN12_OAM_REPORTTRIG1_OFFSET (0x20) +#define GEN12_OAM_REPORTTRIG8_OFFSET (0x3c) +#define GEN12_OAM_REPORTTRIG1 (base) \ + XE_REG((base) + GEN12_OAM_REPORTTRIG1_OFFSET) +#define GEN12_OAM_REPORTTRIG8 (base) \ + XE_REG((base) + GEN12_OAM_REPORTTRIG8_OFFSET) + +#define GEN12_OAM_PERF_COUNTER_B0_OFFSET (0x84) +#define GEN12_OAM_PERF_COUNTER_B (base, idx) \ + XE_REG((base) + GEN12_OAM_PERF_COUNTER_B0_OFFSET + 4 * (idx)) + +#endif /* __XE_OA_REGS__ */ Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 03/21] drm/xe/oa: Add registers and GPU commands used by OA
Quoted 7 lines · Umesh Nerlige Ramappa
Quoted 5 lines · Ashutosh Dixit
Add registers and GPU commands used by OA in subsequent patches. The xe oa code programs OA units which generate performance data. The code also submits command buffers to change hardware engine context images and implement waits.
Quoted 5 lines
Quoted 3 lines
v2: Remove unused registers (used by noa wait) (Umesh)
Signed-off-by Ashutosh Dixit <[email protected]>Reviewed-by Umesh Nerlige Ramappa <[email protected]>
Thanks, though I am also thinking of doing s/GEN12_/XE_/ in all the register name #define's, to better align with the new XE/XE2 nomenclature.
Quoted 247 lines
Quoted 247 lines
---
drivers/gpu/drm/xe/regs/xe_engine_regs.h | 2 + drivers/gpu/drm/xe/regs/xe_gpu_commands.h | 13 ++ drivers/gpu/drm/xe/regs/xe_oa_regs.h | 173 ++++++++++++++++++++++ 3 files changed, 188 insertions(+)create mode 100644
drivers/gpu/drm/xe/regs/xe_oa_regs.hdrivers/gpu/drm/xe/regs/xe_engine_regs.h +2
-0@@ -115,6 +115,8 @@#define RING_EXECLIST_CONTROL (base) XE_REG((base) + 0x550)#define EL_CTRL_LOAD REG_BIT(0) +#define GEN8_RING_CS_GPR (base, n) XE_REG((base) + 0x600 + (n) * 8) +#define VDBOX_CGCTL3F10 (base) XE_REG((base) + 0x3f10)#define IECPUNIT_CLKGATE_DIS REG_BIT(22)drivers/gpu/drm/xe/regs/xe_gpu_commands.h +13
-0@@ -14,6 +14,7 @@#define MI_INSTR (opcode, flags) \ (__INSTR(INSTR_MI_CLIENT) | (opcode) << 23 | (flags)) +#define MI_OPCODE (x) (((x) >> 23) & 0x3f)#define MI_NOOP MI_INSTR(0, 0)#define MI_USER_INTERRUPT MI_INSTR(0x02, 0)@@ -23,12 +24,19 @@#define MI_ARB_DISABLE (0<<0)#define MI_BATCH_BUFFER_END MI_INSTR(0x0a, 0) +#define MI_STORE_DATA_IMM MI_INSTR(0x20, 0) +#define MI_STORE_DWORD_IMM_GEN4 MI_INSTR(0x20, 2)#define MI_LOAD_REGISTER_IMM (x) MI_INSTR(0x22, 2*(x)-1)#define MI_LRI_LRM_CS_MMIO REG_BIT(19)#define MI_LRI_MMIO_REMAP_EN REG_BIT(17)#define MI_LRI_FORCE_POSTED (1<<12) +#define IS_MI_LRI_CMD (x) (MI_OPCODE(x) == MI_OPCODE(MI_INSTR(0x22, 0))) +#define MI_LRI_LEN (x) (((x) & 0xff) + 1) + +#define MI_STORE_REGISTER_MEM MI_INSTR(0x24, 1) +#define MI_SRM_LRM_GLOBAL_GTT REG_BIT(22)#define MI_FLUSH_DW MI_INSTR(0x26, 1)#define MI_FLUSH_DW_STORE_INDEX (1<<21)@@ -37,7 +45,12 @@#define MI_FLUSH_DW_OP_STOREDW (1<<14)#define MI_FLUSH_DW_USE_GTT (1<<2) +#define MI_LOAD_REGISTER_MEM MI_INSTR(0x29, 1) + +#define MI_LOAD_REGISTER_REG MI_INSTR(0x2A, 1) +#define MI_BATCH_BUFFER_START MI_INSTR(0x31, 1) +#define MI_BATCH_PREDICATE REG_BIT(15)/* HSW+ on RCS only*/ #define XY_CTRL_SURF_COPY_BLT ((2 << 29) | (0x48 << 22) | 3)#define SRC_ACCESS_TYPE_SHIFT 21drivers/gpu/drm/xe/regs/xe_oa_regs.h new file +173
-1@@ -0,0 +1,173 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef __XE_OA_REGS__ +#define __XE_OA_REGS__ + +#define REG_EQUAL (reg, xe_reg) ((reg) == (xe_reg.addr)) +#define REG_EQUAL_MCR (reg, xe_reg) ((reg) == (xe_reg.__reg.addr)) + +#define HALF_SLICE_CHICKEN2 XE_REG_MCR(0xe180) +#define GEN8_ST_PO_DISABLE REG_BIT(13) + +#define GEN7_ROW_CHICKEN2 XE_REG(0xe4f4) +#define GEN8_ROW_CHICKEN XE_REG_MCR(0xe4f0) +#define STALL_DOP_GATING_DISABLE REG_BIT(5) +#define GEN12_DISABLE_DOP_GATING REG_BIT(0) + +#define RPM_CONFIG1 XE_REG(0xd04) +#define GEN10_GT_NOA_ENABLE REG_BIT(9) + +#define WAIT_FOR_RC6_EXIT XE_REG(0x20cc) +#define HSW_WAIT_FOR_RC6_EXIT_ENABLE REG_BIT(0) + +#define EU_PERF_CNTL0 XE_REG(0xe458) +#define EU_PERF_CNTL4 XE_REG(0xe45c) +#define EU_PERF_CNTL1 XE_REG(0xe558) +#define EU_PERF_CNTL5 XE_REG(0xe55c) +#define EU_PERF_CNTL2 XE_REG(0xe658) +#define EU_PERF_CNTL6 XE_REG(0xe65c) +#define EU_PERF_CNTL3 XE_REG(0xe758) + +#define OABUFFER_SIZE_MASK REG_GENMASK(5, 3) +#define OABUFFER_SIZE_128K REG_FIELD_PREP(OABUFFER_SIZE_MASK, 0) +#define OABUFFER_SIZE_256K REG_FIELD_PREP(OABUFFER_SIZE_MASK, 1) +#define OABUFFER_SIZE_512K REG_FIELD_PREP(OABUFFER_SIZE_MASK, 2) +#define OABUFFER_SIZE_1M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 3) +#define OABUFFER_SIZE_2M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 4) +#define OABUFFER_SIZE_4M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 5) +#define OABUFFER_SIZE_8M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 6) +#define OABUFFER_SIZE_16M REG_FIELD_PREP(OABUFFER_SIZE_MASK, 7) + +#define GEN12_OA_TLB_INV_CR XE_REG(0xceec) + +/* Gen12 OAR unit */ +#define GEN12_OAR_OACONTROL XE_REG(0x2960) +#define GEN12_OAR_OACONTROL_COUNTER_FORMAT_SHIFT 1 +#define GEN12_OAR_OACONTROL_COUNTER_ENABLE REG_BIT(0) + +#define GEN8_OACTXCONTROL XE_REG(0x2360) +#define GEN8_OA_COUNTER_RESUME REG_BIT(0) + +#define GEN12_OACTXCONTROL (base) XE_REG((base) + 0x360) +#define GEN12_OAR_OASTATUS XE_REG(0x2968) + +/* Gen12 OAG unit */ +#define GEN12_OAG_OAHEADPTR XE_REG(0xdb00) +#define GEN12_OAG_OAHEADPTR_MASK 0xffffffc0 +#define GEN12_OAG_OATAILPTR XE_REG(0xdb04) +#define GEN12_OAG_OATAILPTR_MASK 0xffffffc0 + +#define GEN12_OAG_OABUFFER XE_REG(0xdb08) +#define GEN12_OAG_OABUFFER_BUFFER_SIZE_MASK (0x7) +#define GEN12_OAG_OABUFFER_BUFFER_SIZE_SHIFT (3) +#define GEN12_OAG_OABUFFER_MEMORY_SELECT REG_BIT(0)/* 0: PPGTT, 1: GGTT */ + +#define GEN12_OAG_OAGLBCTXCTRL XE_REG(0x2b28) +#define GEN12_OAG_OAGLBCTXCTRL_TIMER_PERIOD_SHIFT 2 +#define GEN12_OAG_OAGLBCTXCTRL_TIMER_ENABLE REG_BIT(1) +#define GEN12_OAG_OAGLBCTXCTRL_COUNTER_RESUME REG_BIT(0) + +#define GEN12_OAG_OACONTROL XE_REG(0xdaf4) +#define GEN12_OAG_OACONTROL_OA_COUNTER_FORMAT_SHIFT 2 +#define GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE REG_BIT(0) + +#define GEN12_OAG_OA_DEBUG XE_REG(0xdaf8) +#define GEN12_OAG_OA_DEBUG_INCLUDE_CLK_RATIO REG_BIT(6) +#define GEN12_OAG_OA_DEBUG_DISABLE_CLK_RATIO_REPORTS REG_BIT(5) +#define GEN12_OAG_OA_DEBUG_DISABLE_GO_1_0_REPORTS REG_BIT(2) +#define GEN12_OAG_OA_DEBUG_DISABLE_CTX_SWITCH_REPORTS REG_BIT(1) + +#define GEN12_OAG_OASTATUS XE_REG(0xdafc) +#define GEN12_OAG_OASTATUS_COUNTER_OVERFLOW REG_BIT(2) +#define GEN12_OAG_OASTATUS_BUFFER_OVERFLOW REG_BIT(1) +#define GEN12_OAG_OASTATUS_REPORT_LOST REG_BIT(0) + +#define GDT_CHICKEN_BITS XE_REG(0x9840) +#define GT_NOA_ENABLE 0x00000080 + +#define GEN12_SQCNT1 XE_REG(0x8718) +#define GEN12_SQCNT1_PMON_ENABLE REG_BIT(30) +#define GEN12_SQCNT1_OABPC REG_BIT(29) + +/* Gen12 OAM unit */ +#define GEN12_OAM_HEAD_POINTER_OFFSET (0x1a0) +#define GEN12_OAM_HEAD_POINTER_MASK 0xffffffc0 + +#define GEN12_OAM_TAIL_POINTER_OFFSET (0x1a4) +#define GEN12_OAM_TAIL_POINTER_MASK 0xffffffc0 + +#define GEN12_OAM_BUFFER_OFFSET (0x1a8) +#define GEN12_OAM_BUFFER_SIZE_MASK (0x7) +#define GEN12_OAM_BUFFER_SIZE_SHIFT (3) +#define GEN12_OAM_BUFFER_MEMORY_SELECT REG_BIT(0)/* 0: PPGTT, 1: GGTT */ + +#define GEN12_OAM_CONTEXT_CONTROL_OFFSET (0x1bc) +#define GEN12_OAM_CONTEXT_CONTROL_TIMER_PERIOD_SHIFT 2 +#define GEN12_OAM_CONTEXT_CONTROL_TIMER_ENABLE REG_BIT(1) +#define GEN12_OAM_CONTEXT_CONTROL_COUNTER_RESUME REG_BIT(0) + +#define GEN12_OAM_CONTROL_OFFSET (0x194) +#define GEN12_OAM_CONTROL_COUNTER_FORMAT_SHIFT 1 +#define GEN12_OAM_CONTROL_COUNTER_ENABLE REG_BIT(0) + +#define GEN12_OAM_DEBUG_OFFSET (0x198) +#define GEN12_OAM_DEBUG_BUFFER_SIZE_SELECT REG_BIT(12) +#define GEN12_OAM_DEBUG_INCLUDE_CLK_RATIO REG_BIT(6) +#define GEN12_OAM_DEBUG_DISABLE_CLK_RATIO_REPORTS REG_BIT(5) +#define GEN12_OAM_DEBUG_DISABLE_GO_1_0_REPORTS REG_BIT(2) +#define GEN12_OAM_DEBUG_DISABLE_CTX_SWITCH_REPORTS REG_BIT(1) + +#define GEN12_OAM_STATUS_OFFSET (0x19c) +#define GEN12_OAM_STATUS_COUNTER_OVERFLOW REG_BIT(2) +#define GEN12_OAM_STATUS_BUFFER_OVERFLOW REG_BIT(1) +#define GEN12_OAM_STATUS_REPORT_LOST REG_BIT(0) + +#define GEN12_OAM_MMIO_TRG_OFFSET (0x1d0) + +#define GEN12_OAM_MMIO_TRG (base) \ + XE_REG((base) + GEN12_OAM_MMIO_TRG_OFFSET) + +#define GEN12_OAM_HEAD_POINTER (base) \ + XE_REG((base) + GEN12_OAM_HEAD_POINTER_OFFSET) +#define GEN12_OAM_TAIL_POINTER (base) \ + XE_REG((base) + GEN12_OAM_TAIL_POINTER_OFFSET) +#define GEN12_OAM_BUFFER (base) \ + XE_REG((base) + GEN12_OAM_BUFFER_OFFSET) +#define GEN12_OAM_CONTEXT_CONTROL (base) \ + XE_REG((base) + GEN12_OAM_CONTEXT_CONTROL_OFFSET) +#define GEN12_OAM_CONTROL (base) \ + XE_REG((base) + GEN12_OAM_CONTROL_OFFSET) +#define GEN12_OAM_DEBUG (base) \ + XE_REG((base) + GEN12_OAM_DEBUG_OFFSET) +#define GEN12_OAM_STATUS (base) \ + XE_REG((base) + GEN12_OAM_STATUS_OFFSET) + +#define GEN12_OAM_CEC0_0_OFFSET (0x40) +#define GEN12_OAM_CEC7_1_OFFSET (0x7c) +#define GEN12_OAM_CEC0_0 (base) \ + XE_REG((base) + GEN12_OAM_CEC0_0_OFFSET) +#define GEN12_OAM_CEC7_1 (base) \ + XE_REG((base) + GEN12_OAM_CEC7_1_OFFSET) + +#define GEN12_OAM_STARTTRIG1_OFFSET (0x00) +#define GEN12_OAM_STARTTRIG8_OFFSET (0x1c) +#define GEN12_OAM_STARTTRIG1 (base) \ + XE_REG((base) + GEN12_OAM_STARTTRIG1_OFFSET) +#define GEN12_OAM_STARTTRIG8 (base) \ + XE_REG((base) + GEN12_OAM_STARTTRIG8_OFFSET) + +#define GEN12_OAM_REPORTTRIG1_OFFSET (0x20) +#define GEN12_OAM_REPORTTRIG8_OFFSET (0x3c) +#define GEN12_OAM_REPORTTRIG1 (base) \ + XE_REG((base) + GEN12_OAM_REPORTTRIG1_OFFSET) +#define GEN12_OAM_REPORTTRIG8 (base) \ + XE_REG((base) + GEN12_OAM_REPORTTRIG8_OFFSET) + +#define GEN12_OAM_PERF_COUNTER_B0_OFFSET (0x84) +#define GEN12_OAM_PERF_COUNTER_B (base, idx) \ + XE_REG((base) + GEN12_OAM_PERF_COUNTER_B0_OFFSET + 4 * (idx)) + +#endif /* __XE_OA_REGS__ */ --2.41.0
PATCH 4/21 drm/xe/oa: Module init/exit and probe/remove
In reply to Ashutosh DixitPerform OA initialization at module init and probe time:
* Setup perf_stream_paranoid and oa_max_sample_rate files in /proc
* Setup metrics sysfs directories to expose which metrics configurations are available
* Setup OA groups which associate hw engines with OA units
* Initialize OA units
--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 11 + drivers/gpu/drm/xe/xe_device_types.h | 4 + drivers/gpu/drm/xe/xe_gt_types.h | 4 + drivers/gpu/drm/xe/xe_hw_engine_types.h | 2 + drivers/gpu/drm/xe/xe_module.c | 5 + drivers/gpu/drm/xe/xe_oa.c | 309 ++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_oa.h | 18 ++ 8 files changed, 354 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_oa.c create mode 100644 drivers/gpu/drm/xe/xe_oa.h
drivers/gpu/drm/xe/Makefile +1 -0
@@ -84,6 +84,7 @@ xe-y += xe_bb.o \ xe_mmio.o \ xe_mocs.o \ xe_module.o \ + xe_oa.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \
drivers/gpu/drm/xe/xe_device.c +11 -0
@@ -25,6 +25,7 @@#include "xe_irq.h" #include "xe_mmio.h" #include "xe_module.h" +#include "xe_oa.h" #include "xe_pcode.h" #include "xe_pm.h" #include "xe_query.h"
@@ -323,6 +324,10 @@ int xe_device_probe(struct xe_device *xe) goto err_irq_shutdown; } + err =xe_oa_init (xe); +if (err) + goto err_irq_shutdown; + err =xe_display_init (xe);if (err) goto err_irq_shutdown;
@@ -333,6 +338,8 @@ int xe_device_probe(struct xe_device *xe)xe_display_register (xe); +xe_oa_register (xe); +xe_debugfs_register (xe);xe_pmu_register (&xe->pmu);
@@ -363,10 +370,14 @@ static void xe_device_remove_display(struct xe_device *xe)void xe_device_remove (struct xe_device *xe) { +xe_oa_unregister (xe); +xe_device_remove_display (xe);xe_display_fini (xe); +xe_oa_fini (xe); +xe_irq_shutdown (xe); }
drivers/gpu/drm/xe/xe_device_types.h +4 -0
@@ -17,6 +17,7 @@#include "xe_platform_types.h" #include "xe_pmu.h" #include "xe_step_types.h" +#include "xe_oa.h" #if IS_ENABLED (CONFIG_DRM_XE_DISPLAY )#include "soc/intel_pch.h"
@@ -365,6 +366,9 @@ struct xe_device {/** @pmu: performance monitoring unit */ struct xe_pmu pmu; +/** @oa: oa perf counter subsystem */ +struct xe_oa oa; +/* private: */ #if IS_ENABLED (CONFIG_DRM_XE_DISPLAY )
drivers/gpu/drm/xe/xe_gt_types.h +4 -0
@@ -13,6 +13,7 @@#include "xe_reg_sr_types.h" #include "xe_sa_types.h" #include "xe_uc_types.h" +#include "xe_oa.h" struct xe_exec_queue_ops ;struct xe_migrate ;
@@ -347,6 +348,9 @@ struct xe_gt {/** @oob: bitmap with active OOB workaroudns */ unsigned long *oob; } wa_active; + +/** @oa: oa perf counter subsystem per gt info */ +struct xe_oa_gt oa; };#endif
drivers/gpu/drm/xe/xe_hw_engine_types.h +2 -0
@@ -146,6 +146,8 @@ struct xe_hw_engine {enum xe_hw_engine_id engine_id;/** @eclass: pointer to per hw engine class interface */ struct xe_hw_engine_class_intf *eclass; +/** @oa_group: oa unit for this hw engine */ +struct xe_oa_group *oa_group; };/**
drivers/gpu/drm/xe/xe_module.c +5 -0
@@ -11,6 +11,7 @@#include "xe_drv.h" #include "xe_hw_fence.h" #include "xe_module.h" +#include "xe_oa.h" #include "xe_pci.h" #include "xe_pmu.h" #include "xe_sched_job.h"
@@ -68,6 +69,10 @@ static const struct init_funcs init_funcs[] = { .init = xe_register_pci_driver, .exit = xe_unregister_pci_driver, }, + { + .init = xe_oa_sysctl_register, + .exit = xe_oa_sysctl_unregister, + }, };static int __init xe_init (void )
drivers/gpu/drm/xe/xe_oa.c new file +309 -0
309 lines not on this page · raw message
drivers/gpu/drm/xe/xe_oa.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef _XE_OA_H_ +#define _XE_OA_H_ + +#include "xe_oa_types.h" + +int xe_oa_init (struct xe_device *xe); +void xe_oa_fini (struct xe_device *xe); +void xe_oa_register (struct xe_device *xe); +void xe_oa_unregister (struct xe_device *xe); +int xe_oa_sysctl_register (void ); +void xe_oa_sysctl_unregister (void ); + +#endif
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 04/21] drm/xe/oa: Module init/exit and probe/remove
Quoted 9 lines · Ashutosh Dixit
Perform OA initialization at module init and probe time:
* Setup
perf_stream_paranoidandoa_max_sample_ratefiles in /proc
* Setup metrics sysfs directories to expose which metrics configurations are available
* Setup OA groups which associate hw engines with OA units
* Initialize OA unitsSigned-off-by Ashutosh Dixit <[email protected]>
similar to what was present on i915,
Umesh
Quoted 494 lines
---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 11 + drivers/gpu/drm/xe/xe_device_types.h | 4 + drivers/gpu/drm/xe/xe_gt_types.h | 4 + drivers/gpu/drm/xe/xe_hw_engine_types.h | 2 + drivers/gpu/drm/xe/xe_module.c | 5 + drivers/gpu/drm/xe/xe_oa.c | 309 ++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_oa.h | 18 ++ 8 files changed, 354 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_oa.c
create mode 100644drivers/gpu/drm/xe/xe_oa.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -84,6 +84,7 @@ xe-y += xe_bb.o \ xe_mmio.o \ xe_mocs.o \ xe_module.o \ + xe_oa.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_device.c +11
-0@@ -25,6 +25,7 @@#include "xe_irq.h" #include "xe_mmio.h" #include "xe_module.h" +#include "xe_oa.h" #include "xe_pcode.h" #include "xe_pm.h" #include "xe_query.h" @@ -323,6 +324,10 @@ int xe_device_probe(struct xe_device *xe) goto err_irq_shutdown; } + err =xe_oa_init (xe); +if (err) + goto err_irq_shutdown; + err =xe_display_init (xe);if (err) goto err_irq_shutdown;@@ -333,6 +338,8 @@ int xe_device_probe(struct xe_device *xe)xe_display_register (xe); +xe_oa_register (xe); +xe_debugfs_register (xe);xe_pmu_register (&xe->pmu);@@ -363,10 +370,14 @@ static void xe_device_remove_display(struct xe_device *xe)void xe_device_remove (struct xe_device *xe) { +xe_oa_unregister (xe); +xe_device_remove_display (xe);xe_display_fini (xe); +xe_oa_fini (xe); +xe_irq_shutdown (xe); }drivers/gpu/drm/xe/xe_device_types.h +4
-0@@ -17,6 +17,7 @@#include "xe_platform_types.h" #include "xe_pmu.h" #include "xe_step_types.h" +#include "xe_oa.h" #if IS_ENABLED (CONFIG_DRM_XE_DISPLAY )#include "soc/intel_pch.h" @@ -365,6 +366,9 @@ struct xe_device {/** @pmu: performance monitoring unit */ struct xe_pmu pmu; +/** @oa: oa perf counter subsystem */ +struct xe_oa oa; +/* private: */ #if IS_ENABLED (CONFIG_DRM_XE_DISPLAY )drivers/gpu/drm/xe/xe_gt_types.h +4
-0@@ -13,6 +13,7 @@#include "xe_reg_sr_types.h" #include "xe_sa_types.h" #include "xe_uc_types.h" +#include "xe_oa.h" struct xe_exec_queue_ops ;struct xe_migrate ;@@ -347,6 +348,9 @@ struct xe_gt {/** @oob: bitmap with active OOB workaroudns */ unsigned long *oob; } wa_active; + +/** @oa: oa perf counter subsystem per gt info */ +struct xe_oa_gt oa; };#endif drivers/gpu/drm/xe/xe_hw_engine_types.h +2
-0@@ -146,6 +146,8 @@ struct xe_hw_engine {enum xe_hw_engine_id engine_id;/** @eclass: pointer to per hw engine class interface */ struct xe_hw_engine_class_intf *eclass; +/** @oa_group: oa unit for this hw engine */ +struct xe_oa_group *oa_group; };/** drivers/gpu/drm/xe/xe_module.c +5
-0@@ -11,6 +11,7 @@#include "xe_drv.h" #include "xe_hw_fence.h" #include "xe_module.h" +#include "xe_oa.h" #include "xe_pci.h" #include "xe_pmu.h" #include "xe_sched_job.h" @@ -68,6 +69,10 @@ static const struct init_funcs init_funcs[] = { .init = xe_register_pci_driver, .exit = xe_unregister_pci_driver, }, + { + .init = xe_oa_sysctl_register, + .exit = xe_oa_sysctl_unregister, + }, };static int __init xe_init (void )drivers/gpu/drm/xe/xe_oa.c new file +309
-0@@ -0,0 +1,309 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2023 Intel Corporation +*/ + +#include <linux/anon_inodes.h> +#include <linux/nospec.h> +#include <linux/sizes.h> +#include <linux/uuid.h> + +#include <drm/xe_drm.h> +#include <drm/drm_drv.h> + +#include "regs/xe_oa_regs.h" +#include "xe_gt.h" +#include "xe_device.h" +#include "xe_oa.h" + +static u32 xe_oa_stream_paranoid = true; +static int xe_oa_sample_rate_hard_limit; +static u32 xe_oa_max_sample_rate =100000 ; + +static const struct xe_oa_format oa_formats[] = { + [XE_OA_FORMAT_C4_B8 ] = {7 ,64 }, + [XE_OA_FORMAT_A12 ] = {0 ,64 }, + [XE_OA_FORMAT_A12_B8_C8 ] = {2 ,128 }, + [XE_OA_FORMAT_A32u40_A4u32_B8_C8] = {5 ,256 }, + [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = {5 ,256 }, + [XE_OA_FORMAT_A24u40_A14u32_B8_C8] = {5 ,256 }, + [XE_OAM_FORMAT_MPEC8u64_B8_C8] = {1 ,192 ,TYPE_OAM ,HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u32_B8_C8] = {2 ,128 ,TYPE_OAM ,HDR_64_BIT }, +}; + +static struct ctl_table_header *sysctl_header; + +void xe_oa_register (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; + +if (!oa->xe) +return ; + + oa->metrics_kobj =kobject_create_and_add ("metrics" , + &xe->drm.primary->kdev->kobj); +} + +void xe_oa_unregister (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; + +if (!oa->metrics_kobj) +return ; + +kobject_put (oa->metrics_kobj); + oa->metrics_kobj =NULL ; +} + +static u32 num_oa_groups_per_gt (struct xe_gt *gt) +{ +return 1 ; +} + +static u32 __oam_engine_group (struct xe_hw_engine *hwe) +{ +if (GRAPHICS_VERx100 (gt_to_xe (hwe->gt)) >=1270 ) { +/* +* There's 1 SAMEDIA gt and 1 OAM per SAMEDIA gt. All media slices +* within the gt use the same OAM. All MTL SKUs list 1 SA MEDIA. +*/ +drm_WARN_ON (&hwe->gt->tile->xe->drm, + hwe->gt->info.type !=XE_GT_TYPE_MEDIA ); + +return OA_GROUP_OAM_SAMEDIA_0 ; + } + +return OA_GROUP_INVALID ; +} + +static u32 __oa_engine_group (struct xe_hw_engine *hwe) +{ +switch (hwe->class) { +case XE_ENGINE_CLASS_RENDER : +return OA_GROUP_OAG ; + +case XE_ENGINE_CLASS_VIDEO_DECODE : +case XE_ENGINE_CLASS_VIDEO_ENHANCE : +return __oam_engine_group (hwe); + +default : +return OA_GROUP_INVALID ; + } +} + +static struct xe_oa_regs __oam_regs (u32 base) +{ +return (struct xe_oa_regs ) { + base, +GEN12_OAM_HEAD_POINTER (base), +GEN12_OAM_TAIL_POINTER (base), +GEN12_OAM_BUFFER (base), +GEN12_OAM_CONTEXT_CONTROL (base), +GEN12_OAM_CONTROL (base), +GEN12_OAM_DEBUG (base), +GEN12_OAM_STATUS (base), +GEN12_OAM_CONTROL_COUNTER_FORMAT_SHIFT , + }; +} + +static struct xe_oa_regs __oag_regs (void ) +{ +return (struct xe_oa_regs ) { +0 , +GEN12_OAG_OAHEADPTR , +GEN12_OAG_OATAILPTR , +GEN12_OAG_OABUFFER , +GEN12_OAG_OAGLBCTXCTRL , +GEN12_OAG_OACONTROL , +GEN12_OAG_OA_DEBUG , +GEN12_OAG_OASTATUS , +GEN12_OAG_OACONTROL_OA_COUNTER_FORMAT_SHIFT , + }; +} + +static void xe_oa_init_groups (struct xe_gt *gt) +{ +const u32 mtl_oa_base[] = { + [OA_GROUP_OAM_SAMEDIA_0 ] =0x393000 , + }; +int i, num_groups = gt->oa.num_oa_groups; + +for (i =0 ; i < num_groups; i++) { +struct xe_oa_group *g = >->oa.group[i]; + +/* Fused off engines can result in a group with num_engines == 0 */ +if (g->num_engines ==0 ) +continue ; + +if (i ==OA_GROUP_OAG && gt->info.type !=XE_GT_TYPE_MEDIA ) { + g->regs =__oag_regs (); + g->type =TYPE_OAG ; + }else if (GRAPHICS_VERx100 (gt_to_xe (gt)) >=1270 ) { + g->regs =__oam_regs (mtl_oa_base[i]); + g->type =TYPE_OAM ; + } + +/* Set oa_unit_ids now to ensure ids remain contiguous. */ + g->oa_unit_id = gt->tile->xe->oa.oa_unit_ids++; + } +} + +static int xe_oa_init_gt (struct xe_gt *gt) +{ +u32 num_groups =num_oa_groups_per_gt (gt); +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; +struct xe_oa_group *g; + + g =kcalloc (num_groups,sizeof (*g),GFP_KERNEL ); +if (!g) +return -ENOMEM ; + +for_each_hw_engine (hwe, gt, id) { +u32 index =__oa_engine_group (hwe); + + hwe->oa_group =NULL ; +if (index < num_groups) { + g[index].num_engines++; + hwe->oa_group = &g[index]; + } + } + + gt->oa.num_oa_groups = num_groups; + gt->oa.group = g; + +xe_oa_init_groups (gt); + +return 0 ; +} + +static int xe_oa_init_engine_groups (struct xe_oa *oa) +{ +struct xe_gt *gt; +int i, ret; + +for_each_gt (gt, oa->xe, i) { + ret =xe_oa_init_gt (gt); +if (ret) +return ret; + } + +return 0 ; +} + +static void oa_format_add (struct xe_oa *oa,enum drm_xe_oa_format format) +{ +__set_bit (format, oa->format_mask); +} + +static void xe_oa_init_supported_formats (struct xe_oa *oa) +{ +switch (oa->xe->info.platform) { +case XE_ALDERLAKE_S : +case XE_ALDERLAKE_P : +oa_format_add (oa,XE_OA_FORMAT_A12 ); +oa_format_add (oa,XE_OA_FORMAT_A12_B8_C8 ); +oa_format_add (oa, XE_OA_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa,XE_OA_FORMAT_C4_B8 ); +break ; + +case XE_DG2 : +oa_format_add (oa, XE_OAR_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa, XE_OA_FORMAT_A24u40_A14u32_B8_C8); +break ; + +case XE_METEORLAKE : +oa_format_add (oa, XE_OAR_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa, XE_OA_FORMAT_A24u40_A14u32_B8_C8); +oa_format_add (oa, XE_OAM_FORMAT_MPEC8u64_B8_C8); +oa_format_add (oa, XE_OAM_FORMAT_MPEC8u32_B8_C8); +break ; + +default : +drm_err (&oa->xe->drm,"Unknown platform\n" ); + } +} + +int xe_oa_init (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; +struct xe_gt *gt; +int i, ret; + +/* Support OA only with GuC submission and Gen12+ */ +if (XE_WARN_ON (!xe_device_uc_enabled (xe)) ||XE_WARN_ON (GRAPHICS_VER (xe) <12 )) +return 0 ; + + oa->xe = xe; + oa->oa_formats = oa_formats; + +for_each_gt (gt, xe, i) +mutex_init (>->oa.lock); + +/* Choose a representative limit */ + xe_oa_sample_rate_hard_limit =xe_root_mmio_gt (xe)->info.clock_freq /2 ; + +mutex_init (&oa->metrics_lock); +idr_init_base (&oa->metrics_idr,1 ); + + ret =xe_oa_init_engine_groups (oa); +if (ret) { +drm_err (&xe->drm,"OA initialization failed %d\n" , ret); +return ret; + } + +xe_oa_init_supported_formats (oa); + + oa->xe = xe; +return 0 ; +} + +void xe_oa_fini (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; +struct xe_gt *gt; +int i; + +if (!oa->xe) +return ; + +for_each_gt (gt, xe, i) +kfree (gt->oa.group); + +idr_destroy (&oa->metrics_idr); + + oa->xe =NULL ; +} + +static struct ctl_table oa_ctl_table[] = { + { + .procname ="perf_stream_paranoid" , + .data = &xe_oa_stream_paranoid, + .maxlen =sizeof (xe_oa_stream_paranoid), + .mode =0644 , + .proc_handler = proc_dointvec_minmax, + .extra1 =SYSCTL_ZERO , + .extra2 =SYSCTL_ONE , + }, + { + .procname ="oa_max_sample_rate" , + .data = &xe_oa_max_sample_rate, + .maxlen =sizeof (xe_oa_max_sample_rate), + .mode =0644 , + .proc_handler = proc_dointvec_minmax, + .extra1 =SYSCTL_ZERO , + .extra2 = &xe_oa_sample_rate_hard_limit, + }, + {} +}; + +int xe_oa_sysctl_register (void ) +{ + sysctl_header =register_sysctl ("dev/xe" , oa_ctl_table); +return 0 ; +} + +void xe_oa_sysctl_unregister (void ) +{ +unregister_sysctl_table (sysctl_header); +}drivers/gpu/drm/xe/xe_oa.h new file +18
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef _XE_OA_H_ +#define _XE_OA_H_ + +#include "xe_oa_types.h" + +int xe_oa_init (struct xe_device *xe); +void xe_oa_fini (struct xe_device *xe); +void xe_oa_register (struct xe_device *xe); +void xe_oa_unregister (struct xe_device *xe); +int xe_oa_sysctl_register (void ); +void xe_oa_sysctl_unregister (void ); + +#endif Signature · 1 line
2.41.0
Re: [Intel-xe] [04/21] drm/xe/oa: Module init/exit and probe/remove
In reply to Ashutosh DixitQuoted 361 lines · Ashutosh Dixit
Perform OA initialization at module init and probe time:
* Setup
perf_stream_paranoidandoa_max_sample_ratefiles in /proc
* Setup metrics sysfs directories to expose which metrics configurations are available
* Setup OA groups which associate hw engines with OA units
* Initialize OA unitsSigned-off-by Ashutosh Dixit <[email protected]>Reviewed-by Umesh Nerlige Ramappa <[email protected]>--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 11 + drivers/gpu/drm/xe/xe_device_types.h | 4 + drivers/gpu/drm/xe/xe_gt_types.h | 4 + drivers/gpu/drm/xe/xe_hw_engine_types.h | 2 + drivers/gpu/drm/xe/xe_module.c | 5 + drivers/gpu/drm/xe/xe_oa.c | 309 ++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_oa.h | 18 ++ 8 files changed, 354 insertions(+)create mode 100644
drivers/gpu/drm/xe/xe_oa.c
create mode 100644drivers/gpu/drm/xe/xe_oa.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -84,6 +84,7 @@ xe-y += xe_bb.o \ xe_mmio.o \ xe_mocs.o \ xe_module.o \ + xe_oa.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \drivers/gpu/drm/xe/xe_device.c +11
-0@@ -25,6 +25,7 @@#include "xe_irq.h" #include "xe_mmio.h" #include "xe_module.h" +#include "xe_oa.h" #include "xe_pcode.h" #include "xe_pm.h" #include "xe_query.h" @@ -323,6 +324,10 @@ int xe_device_probe(struct xe_device *xe) goto err_irq_shutdown; } + err =xe_oa_init (xe); +if (err) + goto err_irq_shutdown; + err =xe_display_init (xe);if (err) goto err_irq_shutdown;@@ -333,6 +338,8 @@ int xe_device_probe(struct xe_device *xe)xe_display_register (xe); +xe_oa_register (xe); +xe_debugfs_register (xe);xe_pmu_register (&xe->pmu);@@ -363,10 +370,14 @@ static void xe_device_remove_display(struct xe_device *xe)void xe_device_remove (struct xe_device *xe) { +xe_oa_unregister (xe); +xe_device_remove_display (xe);xe_display_fini (xe); +xe_oa_fini (xe); +xe_irq_shutdown (xe); }drivers/gpu/drm/xe/xe_device_types.h +4
-0@@ -17,6 +17,7 @@#include "xe_platform_types.h" #include "xe_pmu.h" #include "xe_step_types.h" +#include "xe_oa.h" #if IS_ENABLED (CONFIG_DRM_XE_DISPLAY )#include "soc/intel_pch.h" @@ -365,6 +366,9 @@ struct xe_device {/** @pmu: performance monitoring unit */ struct xe_pmu pmu; +/** @oa: oa perf counter subsystem */ +struct xe_oa oa; +/* private: */ #if IS_ENABLED (CONFIG_DRM_XE_DISPLAY )drivers/gpu/drm/xe/xe_gt_types.h +4
-0@@ -13,6 +13,7 @@#include "xe_reg_sr_types.h" #include "xe_sa_types.h" #include "xe_uc_types.h" +#include "xe_oa.h" struct xe_exec_queue_ops ;struct xe_migrate ;@@ -347,6 +348,9 @@ struct xe_gt {/** @oob: bitmap with active OOB workaroudns */ unsigned long *oob; } wa_active; + +/** @oa: oa perf counter subsystem per gt info */ +struct xe_oa_gt oa; };#endif drivers/gpu/drm/xe/xe_hw_engine_types.h +2
-0@@ -146,6 +146,8 @@ struct xe_hw_engine {enum xe_hw_engine_id engine_id;/** @eclass: pointer to per hw engine class interface */ struct xe_hw_engine_class_intf *eclass; +/** @oa_group: oa unit for this hw engine */ +struct xe_oa_group *oa_group; };/** drivers/gpu/drm/xe/xe_module.c +5
-0@@ -11,6 +11,7 @@#include "xe_drv.h" #include "xe_hw_fence.h" #include "xe_module.h" +#include "xe_oa.h" #include "xe_pci.h" #include "xe_pmu.h" #include "xe_sched_job.h" @@ -68,6 +69,10 @@ static const struct init_funcs init_funcs[] = { .init = xe_register_pci_driver, .exit = xe_unregister_pci_driver, }, + { + .init = xe_oa_sysctl_register, + .exit = xe_oa_sysctl_unregister, + }, };static int __init xe_init (void )drivers/gpu/drm/xe/xe_oa.c new file +193
-0@@ -0,0 +1,309 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2023 Intel Corporation +*/ + +#include <linux/anon_inodes.h> +#include <linux/nospec.h> +#include <linux/sizes.h> +#include <linux/uuid.h> + +#include <drm/xe_drm.h> +#include <drm/drm_drv.h> + +#include "regs/xe_oa_regs.h" +#include "xe_gt.h" +#include "xe_device.h" +#include "xe_oa.h" + +static u32 xe_oa_stream_paranoid = true; +static int xe_oa_sample_rate_hard_limit; +static u32 xe_oa_max_sample_rate =100000 ; + +static const struct xe_oa_format oa_formats[] = { + [XE_OA_FORMAT_C4_B8 ] = {7 ,64 }, + [XE_OA_FORMAT_A12 ] = {0 ,64 }, + [XE_OA_FORMAT_A12_B8_C8 ] = {2 ,128 }, + [XE_OA_FORMAT_A32u40_A4u32_B8_C8] = {5 ,256 }, + [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = {5 ,256 }, + [XE_OA_FORMAT_A24u40_A14u32_B8_C8] = {5 ,256 }, + [XE_OAM_FORMAT_MPEC8u64_B8_C8] = {1 ,192 ,TYPE_OAM ,HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u32_B8_C8] = {2 ,128 ,TYPE_OAM ,HDR_64_BIT }, +}; + +static struct ctl_table_header *sysctl_header; + +void xe_oa_register (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; + +if (!oa->xe) +return ; + + oa->metrics_kobj =kobject_create_and_add ("metrics" , + &xe->drm.primary->kdev->kobj); +} + +void xe_oa_unregister (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; + +if (!oa->metrics_kobj) +return ; + +kobject_put (oa->metrics_kobj); + oa->metrics_kobj =NULL ; +} + +static u32 num_oa_groups_per_gt (struct xe_gt *gt) +{ +return 1 ; +} + +static u32 __oam_engine_group (struct xe_hw_engine *hwe) +{ +if (GRAPHICS_VERx100 (gt_to_xe (hwe->gt)) >=1270 ) { +/* +* There's 1 SAMEDIA gt and 1 OAM per SAMEDIA gt. All media slices +* within the gt use the same OAM. All MTL SKUs list 1 SA MEDIA. +*/ +drm_WARN_ON (&hwe->gt->tile->xe->drm, + hwe->gt->info.type !=XE_GT_TYPE_MEDIA ); + +return OA_GROUP_OAM_SAMEDIA_0 ; + } + +return OA_GROUP_INVALID ; +} + +static u32 __oa_engine_group (struct xe_hw_engine *hwe) +{ +switch (hwe->class) { +case XE_ENGINE_CLASS_RENDER : +return OA_GROUP_OAG ; + +case XE_ENGINE_CLASS_VIDEO_DECODE : +case XE_ENGINE_CLASS_VIDEO_ENHANCE : +return __oam_engine_group (hwe); + +default : +return OA_GROUP_INVALID ; + } +} + +static struct xe_oa_regs __oam_regs (u32 base) +{ +return (struct xe_oa_regs ) { + base, +GEN12_OAM_HEAD_POINTER (base), +GEN12_OAM_TAIL_POINTER (base), +GEN12_OAM_BUFFER (base), +GEN12_OAM_CONTEXT_CONTROL (base), +GEN12_OAM_CONTROL (base), +GEN12_OAM_DEBUG (base), +GEN12_OAM_STATUS (base), +GEN12_OAM_CONTROL_COUNTER_FORMAT_SHIFT , + }; +} + +static struct xe_oa_regs __oag_regs (void ) +{ +return (struct xe_oa_regs ) { +0 , +GEN12_OAG_OAHEADPTR , +GEN12_OAG_OATAILPTR , +GEN12_OAG_OABUFFER , +GEN12_OAG_OAGLBCTXCTRL , +GEN12_OAG_OACONTROL , +GEN12_OAG_OA_DEBUG , +GEN12_OAG_OASTATUS , +GEN12_OAG_OACONTROL_OA_COUNTER_FORMAT_SHIFT , + }; +} + +static void xe_oa_init_groups (struct xe_gt *gt) +{ +const u32 mtl_oa_base[] = { + [OA_GROUP_OAM_SAMEDIA_0 ] =0x393000 , + }; +int i, num_groups = gt->oa.num_oa_groups; + +for (i =0 ; i < num_groups; i++) { +struct xe_oa_group *g = >->oa.group[i]; + +/* Fused off engines can result in a group with num_engines == 0 */ +if (g->num_engines ==0 ) +continue ; + +if (i ==OA_GROUP_OAG && gt->info.type !=XE_GT_TYPE_MEDIA ) { + g->regs =__oag_regs (); + g->type =TYPE_OAG ; + }else if (GRAPHICS_VERx100 (gt_to_xe (gt)) >=1270 ) { + g->regs =__oam_regs (mtl_oa_base[i]); + g->type =TYPE_OAM ; + } + +/* Set oa_unit_ids now to ensure ids remain contiguous. */ + g->oa_unit_id = gt->tile->xe->oa.oa_unit_ids++; + } +} + +static int xe_oa_init_gt (struct xe_gt *gt) +{ +u32 num_groups =num_oa_groups_per_gt (gt); +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; +struct xe_oa_group *g; + + g =kcalloc (num_groups,sizeof (*g),GFP_KERNEL ); +if (!g) +return -ENOMEM ; + +for_each_hw_engine (hwe, gt, id) { +u32 index =__oa_engine_group (hwe); + + hwe->oa_group =NULL ; +if (index < num_groups) { + g[index].num_engines++; + hwe->oa_group = &g[index]; + } + } + + gt->oa.num_oa_groups = num_groups; + gt->oa.group = g; + +xe_oa_init_groups (gt); + +return 0 ; +} + +static int xe_oa_init_engine_groups (struct xe_oa *oa) +{ +struct xe_gt *gt; +int i, ret; + +for_each_gt (gt, oa->xe, i) { + ret =xe_oa_init_gt (gt); +if (ret) +return ret; + } + +return 0 ; +} +
drivers/gpu/drm/xe/xe_oa.c line 203
Quoted 10 lines
drivers/gpu/drm/xe/xe_oa.c new file +10
-0+static void oa_format_add (struct xe_oa *oa,enum drm_xe_oa_format format) +{ +__set_bit (format, oa->format_mask); +} + +static void xe_oa_init_supported_formats (struct xe_oa *oa) +{ +switch (oa->xe->info.platform) { +case XE_ALDERLAKE_S : +case XE_ALDERLAKE_P :
case XE_ALDERLAKE_N:
case XE_DG1:
case XE_TIGERLAKE:
case XE_ROCKETLAKE:
Those are essentially the same from the OA register/format point of view.
Quoted 130 lines
drivers/gpu/drm/xe/xe_oa.c new file +106
-0+oa_format_add (oa,XE_OA_FORMAT_A12 ); +oa_format_add (oa,XE_OA_FORMAT_A12_B8_C8 ); +oa_format_add (oa, XE_OA_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa,XE_OA_FORMAT_C4_B8 ); +break ; + +case XE_DG2 : +oa_format_add (oa, XE_OAR_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa, XE_OA_FORMAT_A24u40_A14u32_B8_C8); +break ; + +case XE_METEORLAKE : +oa_format_add (oa, XE_OAR_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa, XE_OA_FORMAT_A24u40_A14u32_B8_C8); +oa_format_add (oa, XE_OAM_FORMAT_MPEC8u64_B8_C8); +oa_format_add (oa, XE_OAM_FORMAT_MPEC8u32_B8_C8); +break ; + +default : +drm_err (&oa->xe->drm,"Unknown platform\n" ); + } +} + +int xe_oa_init (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; +struct xe_gt *gt; +int i, ret; + +/* Support OA only with GuC submission and Gen12+ */ +if (XE_WARN_ON (!xe_device_uc_enabled (xe)) ||XE_WARN_ON (GRAPHICS_VER (xe) <12 )) +return 0 ; + + oa->xe = xe; + oa->oa_formats = oa_formats; + +for_each_gt (gt, xe, i) +mutex_init (>->oa.lock); + +/* Choose a representative limit */ + xe_oa_sample_rate_hard_limit =xe_root_mmio_gt (xe)->info.clock_freq /2 ; + +mutex_init (&oa->metrics_lock); +idr_init_base (&oa->metrics_idr,1 ); + + ret =xe_oa_init_engine_groups (oa); +if (ret) { +drm_err (&xe->drm,"OA initialization failed %d\n" , ret); +return ret; + } + +xe_oa_init_supported_formats (oa); + + oa->xe = xe; +return 0 ; +} + +void xe_oa_fini (struct xe_device *xe) +{ +struct xe_oa *oa = &xe->oa; +struct xe_gt *gt; +int i; + +if (!oa->xe) +return ; + +for_each_gt (gt, xe, i) +kfree (gt->oa.group); + +idr_destroy (&oa->metrics_idr); + + oa->xe =NULL ; +} + +static struct ctl_table oa_ctl_table[] = { + { + .procname ="perf_stream_paranoid" , + .data = &xe_oa_stream_paranoid, + .maxlen =sizeof (xe_oa_stream_paranoid), + .mode =0644 , + .proc_handler = proc_dointvec_minmax, + .extra1 =SYSCTL_ZERO , + .extra2 =SYSCTL_ONE , + }, + { + .procname ="oa_max_sample_rate" , + .data = &xe_oa_max_sample_rate, + .maxlen =sizeof (xe_oa_max_sample_rate), + .mode =0644 , + .proc_handler = proc_dointvec_minmax, + .extra1 =SYSCTL_ZERO , + .extra2 = &xe_oa_sample_rate_hard_limit, + }, + {} +}; + +int xe_oa_sysctl_register (void ) +{ + sysctl_header =register_sysctl ("dev/xe" , oa_ctl_table); +return 0 ; +} + +void xe_oa_sysctl_unregister (void ) +{ +unregister_sysctl_table (sysctl_header); +}drivers/gpu/drm/xe/xe_oa.h new file +18
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef _XE_OA_H_ +#define _XE_OA_H_ + +#include "xe_oa_types.h" + +int xe_oa_init (struct xe_device *xe); +void xe_oa_fini (struct xe_device *xe); +void xe_oa_register (struct xe_device *xe); +void xe_oa_unregister (struct xe_device *xe); +int xe_oa_sysctl_register (void ); +void xe_oa_sysctl_unregister (void ); + +#endif
Re: [Intel-xe] [04/21] drm/xe/oa: Module init/exit and probe/remove
Quoted 9 lines · Lionel Landwerlin
drivers/gpu/drm/xe/xe_oa.c line 203
Quoted 6 lines
drivers/gpu/drm/xe/xe_oa.c new file +5
-0+static void xe_oa_init_supported_formats (struct xe_oa *oa) +{ +switch (oa->xe->info.platform) { +case XE_ALDERLAKE_S : +case XE_ALDERLAKE_P :case
XE_ALDERLAKE_N:
Quoted 7 lines
case
XE_DG1:case
XE_TIGERLAKE:case
XE_ROCKETLAKE:Those are essentially the same from the OA register/format point of view.
OK, will add them. Thx.
Quoted 23 lines
Quoted 23 lines
drivers/gpu/drm/xe/xe_oa.c new file +22
-0+oa_format_add (oa,XE_OA_FORMAT_A12 ); +oa_format_add (oa,XE_OA_FORMAT_A12_B8_C8 ); +oa_format_add (oa, XE_OA_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa,XE_OA_FORMAT_C4_B8 ); +break ; + +case XE_DG2 : +oa_format_add (oa, XE_OAR_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa, XE_OA_FORMAT_A24u40_A14u32_B8_C8); +break ; + +case XE_METEORLAKE : +oa_format_add (oa, XE_OAR_FORMAT_A32u40_A4u32_B8_C8); +oa_format_add (oa, XE_OA_FORMAT_A24u40_A14u32_B8_C8); +oa_format_add (oa, XE_OAM_FORMAT_MPEC8u64_B8_C8); +oa_format_add (oa, XE_OAM_FORMAT_MPEC8u32_B8_C8); +break ; + +default : +drm_err (&oa->xe->drm,"Unknown platform\n" ); + } +}
PATCH 5/21 drm/xe/oa: Add/remove config ioctl's
In reply to Ashutosh DixitOA configurations consist of a set of event and counter select registers. The add_config ioctl validates and stores such configurations and also exposes them in the metrics sysfs. These configurations will be programmed to OA unit HW when an OA stream using a configuration is opened. The OA stream can also switch to other stored configurations.
--- drivers/gpu/drm/xe/xe_device.c | 4 + drivers/gpu/drm/xe/xe_oa.c | 379 ++++++++++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_oa.h | 5 + 3 files changed, 387 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_device.c +4 -0
@@ -114,6 +114,10 @@ static const struct drm_ioctl_desc xe_ioctls[] = {DRM_IOCTL_DEF_DRV (XE_WAIT_USER_FENCE , xe_wait_user_fence_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE , xe_vm_madvise_ioctl,DRM_RENDER_ALLOW ), + +DRM_IOCTL_DEF_DRV (XE_OA_ADD_CONFIG , xe_oa_add_config_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(XE_OA_REMOVE_CONFIG, xe_oa_remove_config_ioctl, DRM_RENDER_ALLOW), + }; static const struct file_operations xe_driver_fops = {
drivers/gpu/drm/xe/xe_oa.c +378 -1
404 lines not on this page · raw message
drivers/gpu/drm/xe/xe_oa.h +5 -0
@@ -12,7 +12,12 @@ int xe_oa_init(struct xe_device *xe);void xe_oa_fini (struct xe_device *xe);void xe_oa_register (struct xe_device *xe);void xe_oa_unregister (struct xe_device *xe); +int xe_oa_ioctl_version (struct xe_device *xe);int xe_oa_sysctl_register (void );void xe_oa_sysctl_unregister (void ); +int xe_oa_add_config_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int xe_oa_remove_config_ioctl (struct drm_device *dev,void *data, +struct drm_file *file);#endif
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 05/21] drm/xe/oa: Add/remove config ioctl's
Quoted 7 lines · Ashutosh Dixit
OA configurations consist of a set of event and counter select registers. The
add_configioctl validates and stores such configurations and also exposes them in the metrics sysfs. These configurations will be programmed to OA unit HW when an OA stream using a configuration is opened. The OA stream can also switch to other stored configurations.Signed-off-by Ashutosh Dixit <[email protected]>
I think the plan was to do away with the differentiation of flex/mux/b even from the implementation, otherwise this lgtm,
Umesh
Quoted 453 lines
---
drivers/gpu/drm/xe/xe_device.c | 4 + drivers/gpu/drm/xe/xe_oa.c | 379 ++++++++++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_oa.h | 5 + 3 files changed, 387 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_device.c +4
-0@@ -114,6 +114,10 @@ static const struct drm_ioctl_desc xe_ioctls[] = {DRM_IOCTL_DEF_DRV (XE_WAIT_USER_FENCE , xe_wait_user_fence_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE , xe_vm_madvise_ioctl,DRM_RENDER_ALLOW ), + +DRM_IOCTL_DEF_DRV (XE_OA_ADD_CONFIG , xe_oa_add_config_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(XE_OA_REMOVE_CONFIG, xe_oa_remove_config_ioctl, DRM_RENDER_ALLOW), + }; static const struct file_operations xe_driver_fops = {drivers/gpu/drm/xe/xe_oa.c +378
-1@@ -12,8 +12,8 @@#include <drm/drm_drv.h> #include "regs/xe_oa_regs.h" -#include "xe_gt.h" #include "xe_device.h" +#include "xe_gt.h" #include "xe_oa.h" static u32 xe_oa_stream_paranoid = true;@@ -33,6 +33,376 @@ static const struct xe_oa_format oa_formats[] = {static struct ctl_table_header *sysctl_header; +static void xe_oa_config_release (struct kref *ref) +{ +struct xe_oa_config *oa_config = +container_of (ref,typeof (*oa_config), ref); + +kfree (oa_config->flex_regs); +kfree (oa_config->b_counter_regs); +kfree (oa_config->mux_regs); + +kfree_rcu (oa_config, rcu); +} + +static void xe_oa_config_put (struct xe_oa_config *oa_config) +{ +if (!oa_config) +return ; + +kref_put (&oa_config->ref, xe_oa_config_release); +} + +static bool xe_oa_is_valid_flex_addr (struct xe_oa *oa,u32 addr) +{ +static const struct xe_reg flex_eu_regs[] = { +EU_PERF_CNTL0 , +EU_PERF_CNTL1 , +EU_PERF_CNTL2 , +EU_PERF_CNTL3 , +EU_PERF_CNTL4 , +EU_PERF_CNTL5 , +EU_PERF_CNTL6 , + }; +int i; + +for (i =0 ; i <ARRAY_SIZE (flex_eu_regs); i++) { +if (flex_eu_regs[i].addr == addr) +return true; + } +return false; +} + +static bool xe_oa_reg_in_range_table (u32 addr,const struct xe_mmio_range *table) +{ +while (table->start || table->end) { +if (addr >= table->start && addr <= table->end) +return true; + + table++; + } + +return false; +} + +static const struct xe_mmio_range xehp_oa_b_counters[] = { + { .start =0xdc48 , .end =0xdc48 },/* OAA_ENABLE_REG */ + { .start =0xdd00 , .end =0xdd48 },/* OAG_LCE0_0 - OAA_LENABLE_REG */ + {} +}; + +static const struct xe_mmio_range gen12_oa_b_counters[] = { + { .start =0x2b2c , .end =0x2b2c },/* GEN12_OAG_OA_PESS */ + { .start =0xd900 , .end =0xd91c },/* GEN12_OAG_OASTARTTRIG[1-8] */ + { .start =0xd920 , .end =0xd93c },/* GEN12_OAG_OAREPORTTRIG1[1-8] */ + { .start =0xd940 , .end =0xd97c },/* GEN12_OAG_CEC[0-7][0-1] */ + { .start =0xdc00 , .end =0xdc3c },/* GEN12_OAG_SCEC[0-7][0-1] */ + { .start =0xdc40 , .end =0xdc40 },/* GEN12_OAG_SPCTR_CNF */ + { .start =0xdc44 , .end =0xdc44 },/* GEN12_OAA_DBG_REG */ + {} +}; + +static const struct xe_mmio_range mtl_oam_b_counters[] = { + { .start =0x393000 , .end =0x39301c },/* GEN12_OAM_STARTTRIG1[1-8] */ + { .start =0x393020 , .end =0x39303c },/* GEN12_OAM_REPORTTRIG1[1-8] */ + { .start =0x393040 , .end =0x39307c },/* GEN12_OAM_CEC[0-7][0-1] */ + { .start =0x393200 , .end =0x39323C },/* MPES[0-7] */ + {} +}; + +static bool xe_oa_is_valid_b_counter_addr (struct xe_oa *oa,u32 addr) +{ +return xe_oa_reg_in_range_table (addr, xehp_oa_b_counters) || +xe_oa_reg_in_range_table (addr, gen12_oa_b_counters) || +xe_oa_reg_in_range_table (addr, mtl_oam_b_counters); +} + +/* +* Ref: 14010536224: +* 0x20cc is repurposed on MTL, so use a separate array for MTL. +*/ +static const struct xe_mmio_range mtl_oa_mux_regs[] = { + { .start =0x0d00 , .end =0x0d04 },/* RPM_CONFIG[0-1] */ + { .start =0x0d0c , .end =0x0d2c },/* NOA_CONFIG[0-8] */ + { .start =0x9840 , .end =0x9840 },/* GDT_CHICKEN_BITS */ + { .start =0x9884 , .end =0x9888 },/* NOA_WRITE */ + { .start =0x38d100 , .end =0x38d114 },/* VISACTL */ + {} +}; + +static const struct xe_mmio_range gen12_oa_mux_regs[] = { + { .start =0x0d00 , .end =0x0d04 },/* RPM_CONFIG[0-1] */ + { .start =0x0d0c , .end =0x0d2c },/* NOA_CONFIG[0-8] */ + { .start =0x9840 , .end =0x9840 },/* GDT_CHICKEN_BITS */ + { .start =0x9884 , .end =0x9888 },/* NOA_WRITE */ + { .start =0x20cc , .end =0x20cc },/* WAIT_FOR_RC6_EXIT */ + {} +}; + +static bool xe_oa_is_valid_mux_addr (struct xe_oa *oa,u32 addr) +{ +if (oa->xe->info.platform ==XE_METEORLAKE ) +return xe_oa_reg_in_range_table (addr, mtl_oa_mux_regs); +else +return xe_oa_reg_in_range_table (addr, gen12_oa_mux_regs); +} + +static u32 mask_reg_value (u32 reg,u32 val) +{ +/* +* HALF_SLICE_CHICKEN2 is programmed with a the WaDisableSTUnitPowerOptimization +* workaround. Make sure the value programmed by userspace doesn't change this. +*/ +if (REG_EQUAL_MCR (reg,HALF_SLICE_CHICKEN2 )) + val = val & ~_MASKED_BIT_ENABLE (GEN8_ST_PO_DISABLE ); + +/* +* WAIT_FOR_RC6_EXIT has only one bit fullfilling the function indicated by its +* name and a bunch of selection fields used by OA configs. +*/ +if (REG_EQUAL (reg,WAIT_FOR_RC6_EXIT )) + val = val & ~_MASKED_BIT_ENABLE (HSW_WAIT_FOR_RC6_EXIT_ENABLE ); + +return val; +} + +static struct xe_oa_reg * +xe_oa_alloc_regs (struct xe_oa *oa,bool (*is_valid)(struct xe_oa *oa,u32 addr), +u32 __user *regs,u32 n_regs) +{ +struct xe_oa_reg *oa_regs; +int err; +u32 i; + +if (!n_regs ||WARN_ON (!is_valid)) +return NULL ; + + oa_regs =kmalloc_array (n_regs,sizeof (*oa_regs),GFP_KERNEL ); +if (!oa_regs) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < n_regs; i++) { +u32 addr, value; + + err =get_user (addr, regs); +if (err) + goto addr_err; + +if (!is_valid (oa, addr)) { +drm_dbg (&oa->xe->drm,"Invalid oa_reg address: %X\n" , addr); + err = -EINVAL ; + goto addr_err; + } + + err =get_user (value, regs +1 ); +if (err) + goto addr_err; + + oa_regs[i].addr =XE_REG (addr); + oa_regs[i].value =mask_reg_value (addr, value); + + regs +=2 ; + } + +return oa_regs; + +addr_err: +kfree (oa_regs); +return ERR_PTR (err); +} + +static ssize_t show_dynamic_id (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf) +{ +struct xe_oa_config *oa_config = +container_of (attr,typeof (*oa_config), sysfs_metric_id); + +return sprintf (buf,"%d\n" , oa_config->id); +} + +static int create_dynamic_oa_sysfs_entry (struct xe_oa *oa, +struct xe_oa_config *oa_config) +{ +sysfs_attr_init (&oa_config->sysfs_metric_id.attr); + oa_config->sysfs_metric_id.attr.name ="id" ; + oa_config->sysfs_metric_id.attr.mode =0444 ; + oa_config->sysfs_metric_id.show = show_dynamic_id; + oa_config->sysfs_metric_id.store =NULL ; + + oa_config->attrs[0 ] = &oa_config->sysfs_metric_id.attr; + oa_config->attrs[1 ] =NULL ; + + oa_config->sysfs_metric.name = oa_config->uuid; + oa_config->sysfs_metric.attrs = oa_config->attrs; + +return sysfs_create_group (oa->metrics_kobj, &oa_config->sysfs_metric); +} + +int xe_oa_add_config_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +struct xe_oa *oa = &to_xe_device (dev)->oa; +struct drm_xe_oa_config *arg = data; +struct xe_oa_config *oa_config, *tmp; +struct xe_oa_reg *regs; +int err, id; + +if (!oa->xe) { +drm_dbg (&oa->xe->drm,"xe oa interface not available for this system\n" ); +return -ENODEV ; + } + +if (xe_oa_stream_paranoid && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm,"Insufficient privileges to add xe OA config\n" ); +return -EACCES ; + } + +if ((!arg->mux_regs_ptr || !arg->n_mux_regs) && + (!arg->boolean_regs_ptr || !arg->n_boolean_regs) && + (!arg->flex_regs_ptr || !arg->n_flex_regs)) { +drm_dbg (&oa->xe->drm,"No OA registers given\n" ); +return -EINVAL ; + } + + oa_config =kzalloc (sizeof (*oa_config),GFP_KERNEL ); +if (!oa_config) +return -ENOMEM ; + + oa_config->oa = oa; +kref_init (&oa_config->ref); + +if (!uuid_is_valid (arg->uuid)) { +drm_dbg (&oa->xe->drm,"Invalid uuid format for OA config\n" ); + err = -EINVAL ; + goto reg_err; + } + +/* Last character in oa_config->uuid will be 0 because oa_config is kzalloc */ +memcpy (oa_config->uuid, arg->uuid,sizeof (arg->uuid)); + + oa_config->mux_regs_len = arg->n_mux_regs; + regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_mux_addr, +u64_to_user_ptr (arg->mux_regs_ptr), + arg->n_mux_regs); +if (IS_ERR (regs)) { +drm_dbg (&oa->xe->drm,"Failed to create OA config for mux_regs\n" ); + err =PTR_ERR (regs); + goto reg_err; + } + oa_config->mux_regs = regs; + + oa_config->b_counter_regs_len = arg->n_boolean_regs; + regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_b_counter_addr, +u64_to_user_ptr (arg->boolean_regs_ptr), + arg->n_boolean_regs); +if (IS_ERR (regs)) { +drm_dbg (&oa->xe->drm,"Failed to create OA config for b_counter_regs\n" ); + err =PTR_ERR (regs); + goto reg_err; + } + oa_config->b_counter_regs = regs; + + oa_config->flex_regs_len = arg->n_flex_regs; + regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_flex_addr, +u64_to_user_ptr (arg->flex_regs_ptr), + arg->n_flex_regs); +if (IS_ERR (regs)) { +drm_dbg (&oa->xe->drm,"Failed to create OA config for flex_regs\n" ); + err =PTR_ERR (regs); + goto reg_err; + } + oa_config->flex_regs = regs; + + err =mutex_lock_interruptible (&oa->metrics_lock); +if (err) + goto reg_err; + +/* We shouldn't have too many configs, so this iteration shouldn't be too costly */ +idr_for_each_entry (&oa->metrics_idr, tmp, id) { +if (!strcmp (tmp->uuid, oa_config->uuid)) { +drm_dbg (&oa->xe->drm,"OA config already exists with this uuid\n" ); + err = -EADDRINUSE ; + goto sysfs_err; + } + } + + err =create_dynamic_oa_sysfs_entry (oa, oa_config); +if (err) { +drm_dbg (&oa->xe->drm,"Failed to create sysfs entry for OA config\n" ); + goto sysfs_err; + } + +/* Config id 0 is invalid, id 1 for kernel stored test config. */ + oa_config->id =idr_alloc (&oa->metrics_idr, oa_config,2 ,0 ,GFP_KERNEL ); +if (oa_config->id <0 ) { +drm_dbg (&oa->xe->drm,"Failed to create sysfs entry for OA config\n" ); + err = oa_config->id; + goto sysfs_err; + } + +mutex_unlock (&oa->metrics_lock); + +drm_dbg (&oa->xe->drm,"Added config %s id=%i\n" , oa_config->uuid, oa_config->id); + +return oa_config->id; + +sysfs_err: +mutex_unlock (&oa->metrics_lock); +reg_err: +xe_oa_config_put (oa_config); +drm_dbg (&oa->xe->drm,"Failed to add new OA config\n" ); +return err; +} + +int xe_oa_remove_config_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +struct xe_oa *oa = &to_xe_device (dev)->oa; +struct xe_oa_config *oa_config; +u64 *arg = data; +int ret; + +if (!oa->xe) { +drm_dbg (&oa->xe->drm,"xe oa interface not available for this system\n" ); +return -ENODEV ; + } + +if (xe_oa_stream_paranoid && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm,"Insufficient privileges to remove xe OA config\n" ); +return -EACCES ; + } + + ret =mutex_lock_interruptible (&oa->metrics_lock); +if (ret) +return ret; + + oa_config =idr_find (&oa->metrics_idr, *arg); +if (!oa_config) { +drm_dbg (&oa->xe->drm,"Failed to remove unknown OA config\n" ); + ret = -ENOENT ; + goto err_unlock; + } + +WARN_ON (*arg != oa_config->id); + +sysfs_remove_group (oa->metrics_kobj, &oa_config->sysfs_metric); + +idr_remove (&oa->metrics_idr, *arg); + +mutex_unlock (&oa->metrics_lock); + +drm_dbg (&oa->xe->drm,"Removed config %s id=%i\n" , oa_config->uuid, oa_config->id); + +xe_oa_config_put (oa_config); + +return 0 ; + +err_unlock: +mutex_unlock (&oa->metrics_lock); +return ret; +} +void xe_oa_register (struct xe_device *xe) {struct xe_oa *oa = &xe->oa;@@ -258,6 +628,12 @@ int xe_oa_init(struct xe_device *xe)return 0 ; } +static int destroy_config (int id,void *p,void *data) +{ +xe_oa_config_put (p); +return 0 ; +} +void xe_oa_fini (struct xe_device *xe) {struct xe_oa *oa = &xe->oa;@@ -270,6 +646,7 @@ void xe_oa_fini(struct xe_device *xe)for_each_gt (gt, xe, i)kfree (gt->oa.group); +idr_for_each (&oa->metrics_idr, destroy_config, oa);idr_destroy (&oa->metrics_idr); oa->xe =NULL ;drivers/gpu/drm/xe/xe_oa.h +5
-0@@ -12,7 +12,12 @@ int xe_oa_init(struct xe_device *xe);void xe_oa_fini (struct xe_device *xe);void xe_oa_register (struct xe_device *xe);void xe_oa_unregister (struct xe_device *xe); +int xe_oa_ioctl_version (struct xe_device *xe);int xe_oa_sysctl_register (void );void xe_oa_sysctl_unregister (void ); +int xe_oa_add_config_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +int xe_oa_remove_config_ioctl (struct drm_device *dev,void *data, +struct drm_file *file);#endif Signature · 1 line
2.41.0
PATCH 6/21 drm/xe/oa: Start implementing OA stream open ioctl
In reply to Ashutosh DixitStart implementing OA stream open ioctl and parse properties passed in as part of OA stream open. The remaining operations associated with OA stream open continue in subsequent patches.
v2: Include PVC in xe_oa_timestamp_frequency
Remove forcewake_get from reading RPM_CONFIG0
--- drivers/gpu/drm/xe/xe_device.c | 1 + drivers/gpu/drm/xe/xe_oa.c | 239 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_oa.h | 2 + 3 files changed, 242 insertions(+)
drivers/gpu/drm/xe/xe_device.c +1 -0
@@ -115,6 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE , xe_vm_madvise_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (XE_OA_OPEN , xe_oa_stream_open_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (XE_OA_ADD_CONFIG , xe_oa_add_config_ioctl,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(XE_OA_REMOVE_CONFIG, xe_oa_remove_config_ioctl, DRM_RENDER_ALLOW),
drivers/gpu/drm/xe/xe_oa.c +239 -0
262 lines not on this page · raw message
drivers/gpu/drm/xe/xe_oa.h +2 -0
@@ -16,6 +16,8 @@ int xe_oa_ioctl_version(struct xe_device *xe);int xe_oa_sysctl_register (void );void xe_oa_sysctl_unregister (void ); +int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data, +struct drm_file *file);int xe_oa_add_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); int xe_oa_remove_config_ioctl(struct drm_device *dev, void *data,
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 06/21] drm/xe/oa: Start implementing OA stream open ioctl
Quoted 8 lines · Ashutosh Dixit
Start implementing OA stream open ioctl and parse properties passed in as part of OA stream open. The remaining operations associated with OA stream open continue in subsequent patches.
v2: Include PVC in
xe_oa_timestamp_frequency
Removeforcewake_getfrom readingRPM_CONFIG0Signed-off-by Ashutosh Dixit <[email protected]>
lgtm, largely similar to i915,
Quoted 303 lines
---
drivers/gpu/drm/xe/xe_device.c | 1 + drivers/gpu/drm/xe/xe_oa.c | 239 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_oa.h | 2 + 3 files changed, 242 insertions(+)drivers/gpu/drm/xe/xe_device.c +1
-0@@ -115,6 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE , xe_vm_madvise_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (XE_OA_OPEN , xe_oa_stream_open_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (XE_OA_ADD_CONFIG , xe_oa_add_config_ioctl,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(XE_OA_REMOVE_CONFIG, xe_oa_remove_config_ioctl, DRM_RENDER_ALLOW),drivers/gpu/drm/xe/xe_oa.c +239
-0@@ -11,11 +11,16 @@#include <drm/xe_drm.h> #include <drm/drm_drv.h> +#include "regs/xe_gt_regs.h" #include "regs/xe_oa_regs.h" #include "xe_device.h" #include "xe_gt.h" +#include "xe_mmio.h" #include "xe_oa.h" +#define DEFAULT_POLL_FREQUENCY_HZ 200 +#define DEFAULT_POLL_PERIOD_NS (NSEC_PER_SEC / DEFAULT_POLL_FREQUENCY_HZ) +static u32 xe_oa_stream_paranoid = true;static int xe_oa_sample_rate_hard_limit;static u32 xe_oa_max_sample_rate =100000 ;@@ -31,6 +36,21 @@ static const struct xe_oa_format oa_formats[] = { [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, TYPE_OAM, HDR_64_BIT }, }; +struct xe_oa_open_properties { +bool sample; +bool single_exec_q; +u64 exec_q_id; + +int metrics_set; +int oa_format; +bool oa_periodic; +int oa_period_exponent; + +struct xe_hw_engine *hwe; + +u64 poll_oa_period; +}; +static struct ctl_table_header *sysctl_header;static void xe_oa_config_release (struct kref *ref)@@ -53,6 +73,225 @@ static void xe_oa_config_put(struct xe_oa_config *oa_config)kref_put (&oa_config->ref, xe_oa_config_release); } +/* +* OA timestamp frequency = CS timestamp frequency in most platforms. On some +* platforms OA unit ignores the CTC_SHIFT and the 2 timestamps differ. In such +* cases, return the adjusted CS timestamp frequency to the user. +*/ +u32 xe_oa_timestamp_frequency (struct xe_device *xe) +{ +u32 reg, shift; + +/* +* Wa_18013179988:dg2 +* Wa_14015568240:pvc +* Wa_14015846243:mtl +*/ +switch (xe->info.platform) { +case XE_DG2 : +case XE_PVC : +case XE_METEORLAKE : +xe_device_mem_access_get (xe); + reg =xe_mmio_read32 (xe_root_mmio_gt (xe),RPM_CONFIG0 ); +xe_device_mem_access_put (xe); + + shift =REG_FIELD_GET (RPM_CONFIG0_CTC_SHIFT_PARAMETER_MASK , reg); +return xe_root_mmio_gt (xe)->info.clock_freq << (3 - shift); + +default : +return xe_root_mmio_gt (xe)->info.clock_freq; + } +} + +static u64 oa_exponent_to_ns (struct xe_oa *oa,int exponent) +{ +u64 nom = (2ULL << exponent) *NSEC_PER_SEC ; +u32 den =xe_oa_timestamp_frequency (oa->xe); + +return div_u64 (nom + den -1 , den); +} + +static bool oa_format_valid (struct xe_oa *oa,u64 format) +{ +if (format >=XE_OA_FORMAT_MAX ) +return false; +return test_bit (format, oa->format_mask); +} + +static bool engine_supports_oa (const struct xe_hw_engine *hwe) +{ +return hwe->oa_group; +} + +static bool engine_supports_oa_format (const struct xe_hw_engine *hwe,int type) +{ +return hwe->oa_group && hwe->oa_group->type == type; +} + +#define OA_EXPONENT_MAX 31 + +static int xe_oa_read_properties_unlocked (struct xe_oa *oa,u64 __user *uprops, +u32 n_props, +struct xe_oa_open_properties *props) +{ +const struct xe_oa_format *f; +u64 __user *uprop = uprops; +bool config_instance = false; +bool config_class = false; +u8 class, instance; +struct xe_gt *gt; +u32 i; +int ret; + +if (!n_props || n_props >=DRM_XE_OA_PROP_MAX ) { +drm_dbg (&oa->xe->drm,"Invalid number of xe perf properties given\n" ); +return -EINVAL ; + } + + props->poll_oa_period =DEFAULT_POLL_PERIOD_NS ; + +/* Defaults when class:instance is not passed */ + class =XE_ENGINE_CLASS_RENDER ; + instance =0 ; + +for (i =0 ; i < n_props; i++) { +u64 oa_period, oa_freq_hz; +u64 id, value; + + ret =get_user (id, uprop); +if (ret) +return ret; + + ret =get_user (value, uprop +1 ); +if (ret) +return ret; + +switch ((enum drm_xe_oa_property_id )id) { +case DRM_XE_OA_PROP_EXEC_QUEUE_ID : + props->single_exec_q = true; + props->exec_q_id = value; +break ; +case DRM_XE_OA_PROP_SAMPLE_OA : + props->sample = value; +break ; +case DRM_XE_OA_PROP_OA_METRICS_SET : +if (!value) { +drm_dbg (&oa->xe->drm,"Unknown OA metric set ID\n" ); +return -EINVAL ; + } + props->metrics_set = value; +break ; +case DRM_XE_OA_PROP_OA_FORMAT : +if (!oa_format_valid (oa, value)) { +drm_dbg (&oa->xe->drm,"Unsupported OA report format %llu\n" , + value); +return -EINVAL ; + } + props->oa_format = value; +break ; +case DRM_XE_OA_PROP_OA_EXPONENT : +if (value >OA_EXPONENT_MAX ) { +drm_dbg (&oa->xe->drm,"OA timer exponent too high (> %u)\n" , +OA_EXPONENT_MAX ); +return -EINVAL ; + } + +BUILD_BUG_ON (sizeof (oa_period) !=8 ); + oa_period =oa_exponent_to_ns (oa, value); + + oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period); +if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm, +"OA exponent would exceed the max sampling frequency (sysctl dev.xe.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n" , + xe_oa_max_sample_rate); +return -EACCES ; + } + + props->oa_periodic = true; + props->oa_period_exponent = value; +break ; +case DRM_XE_OA_PROP_POLL_OA_PERIOD : +if (value <100000 /* 100us */ ) { +drm_dbg (&oa->xe->drm,"OA timer too small (%lluns < 100us)\n" , + value); +return -EINVAL ; + } + props->poll_oa_period = value; +break ; +case DRM_XE_OA_PROP_OA_ENGINE_CLASS : + class = (u8 )value; + config_class = true; +break ; +case DRM_XE_OA_PROP_OA_ENGINE_INSTANCE : + instance = (u8 )value; + config_instance = true; +break ; +default : +drm_dbg (&oa->xe->drm,"Unknown xe oa property ID %lld\n" , id); +return -EINVAL ; + } + + uprop +=2 ; + } + +if ((config_class && !config_instance) || + (config_instance && !config_class)) { +drm_dbg (&oa->xe->drm,"OA engine class/instance parameters must be passed together\n" ); +return -EINVAL ; + } + +for_each_gt (gt, oa->xe, i) { + props->hwe =xe_gt_hw_engine (gt, class, instance, false); +if (props->hwe) +break ; + } +if (!props->hwe) { +drm_dbg (&oa->xe->drm,"OA engine class and instance invalid %d:%d\n" , + class, instance); +return -EINVAL ; + } + +if (!engine_supports_oa (props->hwe)) { +drm_dbg (&oa->xe->drm,"Engine not supported by OA %d:%d\n" , + class, instance); +return -EINVAL ; + } + + f = &oa->oa_formats[props->oa_format]; +if (!props->oa_format || !f->size || + !engine_supports_oa_format (props->hwe, f->type)) { +drm_dbg (&oa->xe->drm,"Invalid OA format %d type %d size %d for class %d\n" , + props->oa_format, f->type, f->size, props->hwe->class); +return -EINVAL ; + } + +return 0 ; +} + +int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +struct xe_oa *oa = &to_xe_device (dev)->oa; +struct drm_xe_oa_open_param *param = data; +struct xe_oa_open_properties props = {}; +u32 known_open_flags; + +if (!oa->xe) { +drm_dbg (&oa->xe->drm,"xe oa interface not available for this system\n" ); +return -ENODEV ; + } + + known_open_flags =XE_OA_FLAG_FD_CLOEXEC |XE_OA_FLAG_FD_NONBLOCK |XE_OA_FLAG_DISABLED ; +if (param->flags & ~known_open_flags) { +drm_dbg (&oa->xe->drm,"Unknown drm_xe_oa_open_param flag\n" ); +return -EINVAL ; + } + +return xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param->properties_ptr), + param->num_properties, + &props); +} +static bool xe_oa_is_valid_flex_addr (struct xe_oa *oa,u32 addr) {static const struct xe_reg flex_eu_regs[] = {drivers/gpu/drm/xe/xe_oa.h +2
-0@@ -16,6 +16,8 @@ int xe_oa_ioctl_version(struct xe_device *xe);int xe_oa_sysctl_register (void );void xe_oa_sysctl_unregister (void ); +int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data, +struct drm_file *file);int xe_oa_add_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); int xe_oa_remove_config_ioctl(struct drm_device *dev, void *data,Signature · 1 line
2.41.0
PATCH 7/21 drm/xe/oa: OA stream initialization
In reply to Ashutosh DixitImplement majority of OA stream initialization (as part of OA stream open ioctl). The OA buffer is allocated for receiving perf counter samples from HW. The selected counter configuration is programmed into OA unit HW using a command/batch buffer. For OAR, the render context image is modified so as to have correct register values when the context switches in.
v2: Rebase, with change to xe_oa_submit_bb
--- drivers/gpu/drm/xe/xe_oa.c | 672 ++++++++++++++++++++++++++++++++++++- 1 file changed, 669 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +669 -3
@@ -11,13 +11,26 @@#include <drm/xe_drm.h> #include <drm/drm_drv.h> +#include "regs/xe_engine_regs.h" #include "regs/xe_gt_regs.h" +#include "regs/xe_lrc_layout.h" #include "regs/xe_oa_regs.h" +#include "regs/xe_regs.h" +#include "xe_bb.h" +#include "xe_bo.h" #include "xe_device.h" +#include "xe_exec_queue.h" #include "xe_gt.h" +#include "xe_gt_mcr.h" +#include "xe_lrc.h" +#include "xe_migrate.h" #include "xe_mmio.h" #include "xe_oa.h" +#include "xe_sched_job.h" +#include "xe_vm.h" +#define OA_BUFFER_SIZE SZ_16M +#define OA_TAKEN (tail, head) (((tail) - (head)) & (OA_BUFFER_SIZE - 1))#define DEFAULT_POLL_FREQUENCY_HZ 200#define DEFAULT_POLL_PERIOD_NS (NSEC_PER_SEC / DEFAULT_POLL_FREQUENCY_HZ)
@@ -25,6 +38,12 @@ static u32 xe_oa_stream_paranoid = true;static int xe_oa_sample_rate_hard_limit;static u32 xe_oa_max_sample_rate =100000 ; +struct flex { +struct xe_reg reg; +u32 offset; +u32 value; +}; +static const struct xe_oa_format oa_formats[] = { [XE_OA_FORMAT_C4_B8 ] = {7 ,64 }, [XE_OA_FORMAT_A12 ] = {0 ,64 },
@@ -51,6 +70,13 @@ struct xe_oa_open_properties {u64 poll_oa_period; }; +struct xe_oa_config_bo { +struct llist_node node; + +struct xe_oa_config *oa_config; +struct xe_bb *bb; +}; +static struct ctl_table_header *sysctl_header;static void xe_oa_config_release (struct kref *ref)
@@ -73,6 +99,634 @@ static void xe_oa_config_put(struct xe_oa_config *oa_config)kref_put (&oa_config->ref, xe_oa_config_release); } +static struct xe_oa_config *xe_oa_config_get (struct xe_oa_config *oa_config) +{ +return kref_get_unless_zero (&oa_config->ref) ? oa_config :NULL ; +} + +static struct xe_oa_config *xe_oa_get_oa_config (struct xe_oa *oa,int metrics_set) +{ +struct xe_oa_config *oa_config; + +rcu_read_lock (); + oa_config =idr_find (&oa->metrics_idr, metrics_set); +if (oa_config) + oa_config =xe_oa_config_get (oa_config); +rcu_read_unlock (); + +return oa_config; +} + +static void free_oa_config_bo (struct xe_oa_config_bo *oa_bo) +{ +xe_oa_config_put (oa_bo->oa_config); +xe_bb_free (oa_bo->bb,NULL ); +kfree (oa_bo); +} + +static const struct xe_oa_regs *__oa_regs (struct xe_oa_stream *stream) +{ +return &stream->hwe->oa_group->regs; +} + +static int xe_oa_submit_bb (struct xe_oa_stream *stream,struct xe_bb *bb) +{ +struct xe_hw_engine *hwe = stream->hwe; +struct xe_sched_job *job; +struct xe_exec_queue *q; +struct dma_fence *fence; +long timeout; +int err =0 ; + + q =xe_exec_queue_create (hwe->gt->tile->xe,NULL ,BIT (hwe->logical_instance),1 , + hwe,EXEC_QUEUE_FLAG_KERNEL ); +if (IS_ERR (q)) { + err =PTR_ERR (q); +drm_err (&stream->oa->xe->drm,"gt%d, hwe %s, xe_exec_queue_create failed=%d" , + stream->gt->info.id, hwe->name, err); + goto exit; + } + +/* Will add MI_BATCH_BUFFER_END */ + job =xe_bb_create_job (q, bb); +if (IS_ERR (job)) { + err =PTR_ERR (job); + goto put_exec_q; + } + +xe_sched_job_arm (job); + fence =dma_fence_get (&job->drm.s_fence->finished); +xe_sched_job_push (job); + + timeout =dma_fence_wait_timeout (fence, false,HZ ); +dma_fence_put (fence); +if (timeout <0 ) + err = timeout; +else if (!timeout) + err = -ETIME ; +put_exec_q: +xe_exec_queue_put (q); +exit: +return err; +} + +static void xe_oa_free_oa_buffer (struct xe_oa_stream *stream) +{ +xe_bo_unpin_map_no_vm (stream->oa_buffer.bo); +} + +static void xe_oa_free_configs (struct xe_oa_stream *stream) +{ +struct xe_oa_config_bo *oa_bo, *tmp; + +xe_oa_config_put (stream->oa_config); +llist_for_each_entry_safe (oa_bo, tmp, stream->oa_config_bos.first, node) +free_oa_config_bo (oa_bo); +} + +static void xe_oa_store_flex (struct xe_oa_stream *stream,struct xe_lrc *lrc, +struct xe_bb *bb,const struct flex *flex,u32 count) +{ +u32 offset =xe_bo_ggtt_addr (lrc->bo); + +do { + bb->cs[bb->len++] =MI_STORE_DWORD_IMM_GEN4 |MI_SRM_LRM_GLOBAL_GTT ; + bb->cs[bb->len++] = offset + flex->offset *sizeof (u32); + bb->cs[bb->len++] =0 ; + bb->cs[bb->len++] = flex->value; + + }while (flex++, --count); +} + +static int xe_oa_modify_context (struct xe_oa_stream *stream,struct xe_lrc *lrc, +const struct flex *flex,u32 count) +{ +struct xe_bb *bb; +int err =0 ; + + bb =xe_bb_new (stream->gt,4 * count +1 , false); +if (IS_ERR (bb)) { + err =PTR_ERR (bb); + goto exit; + } + +xe_oa_store_flex (stream, lrc, bb, flex, count); + + err =xe_oa_submit_bb (stream, bb); +xe_bb_free (bb,NULL ); +exit: +return err; +} + +static void xe_oa_load_flex (struct xe_oa_stream *stream,struct xe_bb *bb, +const struct flex *flex,u32 count) +{ +XE_WARN_ON (!count || count >63 ); + + bb->cs[bb->len++] =MI_LOAD_REGISTER_IMM (count); + +do { + bb->cs[bb->len++] = flex->reg.addr; + bb->cs[bb->len++] = flex->value; + + }while (flex++, --count); + + bb->cs[bb->len++] =MI_NOOP ; +} + +static int xe_oa_modify_self (struct xe_oa_stream *stream, +const struct flex *flex,u32 count) +{ +struct xe_bb *bb; +int err =0 ; + + bb =xe_bb_new (stream->gt,2 * count +3 , false); +if (IS_ERR (bb)) { + err =PTR_ERR (bb); + goto exit; + } + +xe_oa_load_flex (stream, bb, flex, count); + + err =xe_oa_submit_bb (stream, bb); +xe_bb_free (bb,NULL ); +exit: +return err; +} + +static int xe_oa_configure_oar_context (struct xe_oa_stream *stream,bool enable) +{ +int err; +u32 format = stream->oa_buffer.format->format; +u32 offset = stream->oa->ctx_oactxctrl_offset; +struct flex regs_context[] = { + { +GEN8_OACTXCONTROL , + offset +1 , + enable ?GEN8_OA_COUNTER_RESUME :0 , + }, + }; +#define GEN12_CTX_CTRL_OAR_CONTEXT_ENABLE BIT(8) +#define GEN12_OAR_OACONTROL_OFFSET 0x5B0 +/* Offsets in regs_lri are not used since this configuration is applied using LRI */ +struct flex regs_lri[] = { + { +GEN12_OAR_OACONTROL , +GEN12_OAR_OACONTROL_OFFSET +1 , + (format <<GEN12_OAR_OACONTROL_COUNTER_FORMAT_SHIFT ) | + (enable ?GEN12_OAR_OACONTROL_COUNTER_ENABLE :0 ) + }, + { +RING_CONTEXT_CONTROL (stream->hwe->mmio_base), +CTX_CONTEXT_CONTROL , +_MASKED_FIELD (GEN12_CTX_CTRL_OAR_CONTEXT_ENABLE , + enable ? +GEN12_CTX_CTRL_OAR_CONTEXT_ENABLE : +0 ) + }, + }; + +/* Modify stream hwe context image with regs_context */ + err =xe_oa_modify_context (stream, &stream->exec_q->lrc[0 ], + regs_context,ARRAY_SIZE (regs_context)); +if (err) +return err; + +/* Apply regs_lri using LRI */ +return xe_oa_modify_self (stream, regs_lri,ARRAY_SIZE (regs_lri)); +} + +#define HAS_OA_BPC_REPORTING (xe) (GRAPHICS_VERx100(xe) >= 1255) + +static void xe_oa_disable_metric_set (struct xe_oa_stream *stream) +{ +u32 sqcnt1; + +/* +* Wa_1508761755:xehpsdv, dg2 +* Enable thread stall DOP gating and EU DOP gating. +*/ +if (stream->gt->tile->xe->info.platform ==XE_DG2 ) { +xe_gt_mcr_multicast_write (stream->gt,GEN8_ROW_CHICKEN , +_MASKED_BIT_ENABLE (STALL_DOP_GATING_DISABLE )); +xe_mmio_write32 (stream->gt,GEN7_ROW_CHICKEN2 , +_MASKED_BIT_ENABLE (GEN12_DISABLE_DOP_GATING )); + } + +/* disable the context save/restore or OAR counters */ +if (stream->exec_q) +xe_oa_configure_oar_context (stream, false); + +/* Make sure we disable noa to save power. */ +xe_mmio_rmw32 (stream->gt,RPM_CONFIG1 ,GEN10_GT_NOA_ENABLE ,0 ); + + sqcnt1 =GEN12_SQCNT1_PMON_ENABLE | + (HAS_OA_BPC_REPORTING (stream->gt->tile->xe) ?GEN12_SQCNT1_OABPC :0 ); + +/* Reset PMON Enable to save power. */ +xe_mmio_rmw32 (stream->gt,GEN12_SQCNT1 , sqcnt1,0 ); +} + +static int xe_oa_alloc_oa_buffer (struct xe_oa_stream *stream) +{ +struct xe_bo *bo; + +BUILD_BUG_ON_NOT_POWER_OF_2 (OA_BUFFER_SIZE ); +BUILD_BUG_ON (OA_BUFFER_SIZE <SZ_128K ||OA_BUFFER_SIZE >SZ_16M ); + + bo =xe_bo_create_pin_map (stream->gt->tile->xe, stream->gt->tile,NULL , +OA_BUFFER_SIZE , ttm_bo_type_kernel, +XE_BO_CREATE_SYSTEM_BIT |XE_BO_CREATE_GGTT_BIT ); +if (IS_ERR (bo)) +return PTR_ERR (bo); + + stream->oa_buffer.bo = bo; + stream->oa_buffer.vaddr = bo->vmap.is_iomem ? + bo->vmap.vaddr_iomem : bo->vmap.vaddr; +return 0 ; +} + +static void write_cs_mi_lri (struct xe_bb *bb,const struct xe_oa_reg *reg_data,u32 n_regs) +{ +u32 i; + +#define MI_LOAD_REGISTER_IMM_MAX_REGS (126) + +for (i =0 ; i < n_regs; i++) { +if ((i %MI_LOAD_REGISTER_IMM_MAX_REGS ) ==0 ) { +u32 n_lri =min_t (u32, n_regs - i, +MI_LOAD_REGISTER_IMM_MAX_REGS ); + + bb->cs[bb->len++] =MI_LOAD_REGISTER_IMM (n_lri); + } + bb->cs[bb->len++] = reg_data[i].addr.addr; + bb->cs[bb->len++] = reg_data[i].value; + } +} + +static int num_lri_dwords (int num_regs) +{ +int count =0 ; + +if (num_regs >0 ) { + count +=DIV_ROUND_UP (num_regs,MI_LOAD_REGISTER_IMM_MAX_REGS ); + count += num_regs *2 ; + } + +return count; +} + +static struct xe_oa_config_bo * +__xe_oa_alloc_config_buffer (struct xe_oa_stream *stream,struct xe_oa_config *oa_config) +{ +struct xe_oa_config_bo *oa_bo; +size_t config_length =0 ; +struct xe_bb *bb; + + oa_bo =kzalloc (sizeof (*oa_bo),GFP_KERNEL ); +if (!oa_bo) +return ERR_PTR (-ENOMEM ); + + config_length +=num_lri_dwords (oa_config->mux_regs_len); + config_length +=num_lri_dwords (oa_config->b_counter_regs_len); + config_length +=num_lri_dwords (oa_config->flex_regs_len); + config_length++;/* MI_BATCH_BUFFER_END */ + config_length =ALIGN (sizeof (u32) * config_length,XE_PAGE_SIZE ) /sizeof (u32); + + bb =xe_bb_new (stream->gt, config_length, false); +if (IS_ERR (bb)) + goto err_free; + +write_cs_mi_lri (bb, oa_config->mux_regs, oa_config->mux_regs_len); +write_cs_mi_lri (bb, oa_config->b_counter_regs, oa_config->b_counter_regs_len); +write_cs_mi_lri (bb, oa_config->flex_regs, oa_config->flex_regs_len); + + oa_bo->bb = bb; + oa_bo->oa_config =xe_oa_config_get (oa_config); +llist_add (&oa_bo->node, &stream->oa_config_bos); + +return oa_bo; +err_free: +kfree (oa_bo); +return ERR_CAST (bb); +} + +static struct xe_oa_config_bo *xe_oa_alloc_config_buffer (struct xe_oa_stream *stream) +{ +struct xe_oa_config *oa_config = stream->oa_config; +struct xe_oa_config_bo *oa_bo; + +/* Look for the buffer in the already allocated BOs attached to the stream */ +llist_for_each_entry (oa_bo, stream->oa_config_bos.first, node) { +if (oa_bo->oa_config == oa_config && +memcmp (oa_bo->oa_config->uuid, oa_config->uuid, +sizeof (oa_config->uuid)) ==0 ) + goto out; + } + + oa_bo =__xe_oa_alloc_config_buffer (stream, oa_config); +out: +return oa_bo; +} + +static int xe_oa_emit_oa_config (struct xe_oa_stream *stream) +{ +struct xe_oa_config_bo *oa_bo; +int err =0 ; + + oa_bo =xe_oa_alloc_config_buffer (stream); +if (IS_ERR (oa_bo)) { + err =PTR_ERR (oa_bo); + goto exit; + } + + err =xe_oa_submit_bb (stream, oa_bo->bb); +exit: +return err; +} + +static u32 oag_report_ctx_switches (const struct xe_oa_stream *stream) +{ +return _MASKED_FIELD (GEN12_OAG_OA_DEBUG_DISABLE_CTX_SWITCH_REPORTS , + stream->sample ? +0 :GEN12_OAG_OA_DEBUG_DISABLE_CTX_SWITCH_REPORTS ); +} + +static int xe_oa_enable_metric_set (struct xe_oa_stream *stream) +{ +u32 sqcnt1; +int ret; + +/* +* Wa_1508761755:xehpsdv, dg2 +* EU NOA signals behave incorrectly if EU clock gating is enabled. +* Disable thread stall DOP gating and EU DOP gating. +*/ +if (stream->gt->tile->xe->info.platform ==XE_DG2 ) { +xe_gt_mcr_multicast_write (stream->gt,GEN8_ROW_CHICKEN , +_MASKED_BIT_ENABLE (STALL_DOP_GATING_DISABLE )); +xe_mmio_write32 (stream->gt,GEN7_ROW_CHICKEN2 , +_MASKED_BIT_ENABLE (GEN12_DISABLE_DOP_GATING )); + } + +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_debug, +/* Disable clk ratio reports, like previous Gens. */ +_MASKED_BIT_ENABLE (GEN12_OAG_OA_DEBUG_DISABLE_CLK_RATIO_REPORTS | +GEN12_OAG_OA_DEBUG_INCLUDE_CLK_RATIO ) | +/* +* If the user didn't require OA reports, instruct the hardware +* not to emit ctx switch reports. +*/ +oag_report_ctx_switches (stream)); + +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_ctx_ctrl, stream->periodic ? + (GEN12_OAG_OAGLBCTXCTRL_COUNTER_RESUME | +GEN12_OAG_OAGLBCTXCTRL_TIMER_ENABLE | + (stream->period_exponent << +GEN12_OAG_OAGLBCTXCTRL_TIMER_PERIOD_SHIFT )) :0 ); + +/* +* Initialize Super Queue Internal Cnt Register +* Set PMON Enable in order to collect valid metrics. +* Enable bytes per clock reporting in OA for XEHPSDV onward. +*/ + sqcnt1 =GEN12_SQCNT1_PMON_ENABLE | + (HAS_OA_BPC_REPORTING (stream->gt->tile->xe) ?GEN12_SQCNT1_OABPC :0 ); + +xe_mmio_rmw32 (stream->gt,GEN12_SQCNT1 ,0 , sqcnt1); + +/* +* For Gen12, performance counters are context saved/restored. Only enable it +* for the context that requested this. +*/ +if (stream->exec_q) { + ret =xe_oa_configure_oar_context (stream, true); +if (ret) +return ret; + } + +return xe_oa_emit_oa_config (stream); +} + +static bool engine_supports_mi_query (struct xe_hw_engine *hwe) +{ +return hwe->class ==XE_ENGINE_CLASS_RENDER ; +} + +#define MI_LRI_LEN (x) (((x) & 0xff) + 1) + +static bool xe_oa_find_reg_in_lri (u32 *state,u32 reg,u32 *offset,u32 end) +{ +u32 idx = *offset; +u32 len =min (MI_LRI_LEN (state[idx]) + idx, end); +bool found = false; + + idx++; +for (; idx < len; idx +=2 ) { +if (state[idx] == reg) { + found = true; +break ; + } + } + + *offset = idx; +return found; +} + +static u32 xe_oa_context_image_offset (struct xe_oa_stream *stream,u32 reg) +{ +u32 len = (xe_lrc_size (stream->gt->tile->xe, stream->hwe->class) -PAGE_SIZE ) /4 ; +u32 *state = stream->gt->default_lrc[stream->hwe->class]; +u32 offset; + +if (drm_WARN_ON (&stream->oa->xe->drm, !state)) +return U32_MAX ; + +for (offset =0 ; offset < len; ) { +if (IS_MI_LRI_CMD (state[offset])) { +/* +* We expect reg-value pairs in MI_LRI command, so +* MI_LRI_LEN() should be even +*/ +drm_WARN_ON (&stream->oa->xe->drm, +MI_LRI_LEN (state[offset]) &0x1 ); + +if (xe_oa_find_reg_in_lri (state, reg, &offset, len)) +break ; + }else { + offset++; + } + } + +return offset < len ? offset :U32_MAX ; +} + +static int xe_oa_set_ctx_ctrl_offset (struct xe_oa_stream *stream) +{ +struct xe_reg reg =GEN12_OACTXCONTROL (stream->hwe->mmio_base); +u32 offset = stream->oa->ctx_oactxctrl_offset; + +/* Do this only once. Failure is stored as offset of U32_MAX */ +if (offset) + goto exit; + + offset =xe_oa_context_image_offset (stream, reg.addr); + stream->oa->ctx_oactxctrl_offset = offset; + +drm_dbg (&stream->oa->xe->drm,"%s oa ctx control at 0x%08x dword offset\n" , + stream->hwe->name, offset); +exit: +return offset && offset !=U32_MAX ?0 : -ENODEV ; +} + +static int xe_oa_stream_init (struct xe_oa_stream *stream, +struct xe_oa_open_properties *props) +{ +struct xe_oa_group *g = props->hwe->oa_group; +struct xe_gt *gt = props->hwe->gt; +struct xe_oa *oa = stream->oa; +int ret; + + stream->poll_oa_period = props->poll_oa_period; + stream->hwe = props->hwe; + stream->gt = stream->hwe->gt; + stream->sample_size =sizeof (struct drm_xe_oa_record_header ); + stream->oa_buffer.format = &oa->oa_formats[props->oa_format]; + + stream->sample = props->sample; + stream->sample_size += stream->oa_buffer.format->size; + stream->periodic = props->oa_periodic; + stream->period_exponent = props->oa_period_exponent; + +if (stream->exec_q &&engine_supports_mi_query (stream->hwe)) { +/* If we don't find the context offset, just return error */ + ret =xe_oa_set_ctx_ctrl_offset (stream); +if (ret) { +drm_err (&stream->gt->tile->xe->drm, +"xe_oa_set_ctx_ctrl_offset failed for %s\n" , + stream->hwe->name); + goto exit; + } + } + + stream->oa_config =xe_oa_get_oa_config (oa, props->metrics_set); +if (!stream->oa_config) { +drm_dbg (&oa->xe->drm,"Invalid OA config id=%i\n" , props->metrics_set); + ret = -EINVAL ; + goto exit; + } + + ret =xe_oa_alloc_oa_buffer (stream); +if (ret) + goto err_free_configs; + +/* Take runtime pm ref and forcewake to disable RC6 */ +xe_device_mem_access_get (stream->oa->xe); +XE_WARN_ON (xe_force_wake_get (gt_to_fw (gt),XE_FORCEWAKE_ALL )); + + ret =xe_oa_enable_metric_set (stream); +if (ret) { +drm_dbg (&oa->xe->drm,"Unable to enable metric set\n" ); + goto err_fw_put; + } + +drm_dbg (&oa->xe->drm,"opening stream oa config uuid=%s\n" , + stream->oa_config->uuid); + +WRITE_ONCE (g->exclusive_stream, stream); + +hrtimer_init (&stream->poll_check_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); +init_waitqueue_head (&stream->poll_wq); + +spin_lock_init (&stream->oa_buffer.ptr_lock); +mutex_init (&stream->lock); + +return 0 ; + +err_fw_put: +xe_oa_disable_metric_set (stream); +XE_WARN_ON (xe_force_wake_put (gt_to_fw (gt),XE_FORCEWAKE_ALL )); +xe_device_mem_access_put (stream->oa->xe); +xe_oa_free_oa_buffer (stream); +err_free_configs: +xe_oa_free_configs (stream); +exit: +return ret; +} + +static int +xe_oa_stream_open_ioctl_locked (struct xe_oa *oa, +struct drm_xe_oa_open_param *param, +struct xe_oa_open_properties *props, +struct drm_file *file) +{ +struct xe_file *xef =to_xe_file (file); +struct xe_oa_stream *stream =NULL ; +struct xe_exec_queue *q =NULL ; +bool privileged_op = true; +int stream_fd; +int ret; + +if (props->single_exec_q) { + q =xe_exec_queue_lookup (xef, props->exec_q_id); +if (XE_IOCTL_DBG (oa->xe, !q)) { + ret = -ENOENT ; + goto err_exec_q; + } + } + +/* +* The OAR unit only monitors the RCS on a per context basis. Relax +* requirements if the user doesn't request global stream access, +* i.e. query based sampling using MI_REPORT_PERF_COUNT +*/ +if (q && !props->sample) + privileged_op = false; + +if (privileged_op && xe_oa_stream_paranoid && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm,"Insufficient privileges to open xe perf stream\n" ); + ret = -EACCES ; + goto err_exec_q; + } + +if (!props->sample && !q) { +drm_dbg (&oa->xe->drm,"Only OA report sampling supported\n" ); + ret = -EINVAL ; + goto err_exec_q; + } + +/* We currently only allow exclusive access */ +if (props->hwe->oa_group->exclusive_stream) { +drm_dbg (&oa->xe->drm,"OA unit already in use\n" ); + ret = -EBUSY ; + goto err_exec_q; + } + + stream =kzalloc (sizeof (*stream),GFP_KERNEL ); +if (!stream) { + ret = -ENOMEM ; + goto err_exec_q; + } + + stream->oa = oa; + stream->exec_q = q; + + ret =xe_oa_stream_init (stream, props); +if (ret) + goto err_free; + +/* Hold a reference on the drm device till stream_fd is released */ +drm_dev_get (&oa->xe->drm); + +return stream_fd; +err_free: +kfree (stream); +err_exec_q: +if (q) +xe_exec_queue_put (q); +return ret; +} +/* * OA timestamp frequency = CS timestamp frequency in most platforms. On some * platforms OA unit ignores the CTC_SHIFT and the 2 timestamps differ. In such
@@ -275,6 +929,8 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data,struct drm_xe_oa_open_param *param = data;struct xe_oa_open_properties props = {};u32 known_open_flags; +struct xe_gt *gt; +int ret;if (!oa->xe) {drm_dbg (&oa->xe->drm,"xe oa interface not available for this system\n" );
@@ -287,9 +943,19 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data,return -EINVAL ; } -return xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param->properties_ptr), - param->num_properties, - &props); + ret =xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param->properties_ptr), + param->num_properties, + &props); +if (ret) +return ret; + + gt = props.hwe->gt; + +mutex_lock (>->oa.lock); + ret =xe_oa_stream_open_ioctl_locked (oa, param, &props, file); +mutex_unlock (>->oa.lock); + +return ret; }static bool xe_oa_is_valid_flex_addr (struct xe_oa *oa,u32 addr)
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 07/21] drm/xe/oa: OA stream initialization
Quoted 31 lines · Ashutosh Dixit
drivers/gpu/drm/xe/xe_oa.c +30
-0+static int xe_oa_configure_oar_context (struct xe_oa_stream *stream,bool enable) +{ +int err; +u32 format = stream->oa_buffer.format->format; +u32 offset = stream->oa->ctx_oactxctrl_offset; +struct flex regs_context[] = { + { +GEN8_OACTXCONTROL , + offset +1 , + enable ?GEN8_OA_COUNTER_RESUME :0 , + }, + }; +#define GEN12_CTX_CTRL_OAR_CONTEXT_ENABLE BIT(8) +#define GEN12_OAR_OACONTROL_OFFSET 0x5B0 +/* Offsets in regs_lri are not used since this configuration is applied using LRI */ +struct flex regs_lri[] = { + { +GEN12_OAR_OACONTROL , +GEN12_OAR_OACONTROL_OFFSET +1 , + (format <<GEN12_OAR_OACONTROL_COUNTER_FORMAT_SHIFT ) | + (enable ?GEN12_OAR_OACONTROL_COUNTER_ENABLE :0 ) + }, + { +RING_CONTEXT_CONTROL (stream->hwe->mmio_base), +CTX_CONTEXT_CONTROL , +_MASKED_FIELD (GEN12_CTX_CTRL_OAR_CONTEXT_ENABLE , + enable ? +GEN12_CTX_CTRL_OAR_CONTEXT_ENABLE : +0 ) + },
drivers/gpu/drm/xe/xe_oa.c static void xe_oa_config_put(struct xe_oa_config *oa_config) · line 296
Quoted 10 lines
drivers/gpu/drm/xe/xe_oa.c +10
-0+ }; + +/* Modify stream hwe context image with regs_context */ + err =xe_oa_modify_context (stream, &stream->exec_q->lrc[0 ], + regs_context,ARRAY_SIZE (regs_context)); +if (err) +return err; + +/* Apply regs_lri using LRI */ +return xe_oa_modify_self (stream, regs_lri,ARRAY_SIZE (regs_lri));
This function is incorrect. Please don't review this. Hopefully I have fixed it here (at least "gen12-unprivileged-single-ctx-counters" IGT passes with this patch):
https://gitlab.freedesktop.org/adixit/kernel/-/commit/eb47df203caf259d2b0a3fc7cb9b557a78f76b8b
The above patch will be included in the next rev of the series.
Thanks.
--
Ashutosh
PATCH 8/21 drm/xe/oa: Expose OA stream fd
In reply to Ashutosh DixitThe OA stream open ioctl returns an fd with its own file_operations for the newly initialized OA stream. These file_operations allow userspace to enable or disable the stream, as well as apply a different counter configuration for the OA stream. Userspace can also poll for data availability. OA stream initialization is completed in this commit by enabling the OA stream. When sampling is enabled this starts a hrtimer which periodically checks for data availablility.
--- drivers/gpu/drm/xe/xe_oa.c | 386 +++++++++++++++++++++++++++++++++++++ 1 file changed, 386 insertions(+)
drivers/gpu/drm/xe/xe_oa.c +386 -0
@@ -12,6 +12,7 @@#include <drm/drm_drv.h> #include "regs/xe_engine_regs.h" +#include "regs/xe_gpu_commands.h" #include "regs/xe_gt_regs.h" #include "regs/xe_lrc_layout.h" #include "regs/xe_oa_regs.h"
@@ -26,6 +27,7 @@#include "xe_migrate.h" #include "xe_mmio.h" #include "xe_oa.h" +#include "xe_pm.h" #include "xe_sched_job.h" #include "xe_vm.h"
@@ -33,6 +35,7 @@#define OA_TAKEN (tail, head) (((tail) - (head)) & (OA_BUFFER_SIZE - 1))#define DEFAULT_POLL_FREQUENCY_HZ 200#define DEFAULT_POLL_PERIOD_NS (NSEC_PER_SEC / DEFAULT_POLL_FREQUENCY_HZ) +#define INVALID_CTX_ID U32_MAXstatic u32 xe_oa_stream_paranoid = true;static int xe_oa_sample_rate_hard_limit;
@@ -129,6 +132,210 @@ static const struct xe_oa_regs *__oa_regs(struct xe_oa_stream *stream)return &stream->hwe->oa_group->regs; } +static u32 gen12_oa_hw_tail_read (struct xe_oa_stream *stream) +{ +return xe_mmio_read32 (stream->gt,__oa_regs (stream)->oa_tail_ptr) & +GEN12_OAG_OATAILPTR_MASK ; +} + +#define oa_report_header_64bit (__s) \ + ((__s)->oa_buffer.format->header == HDR_64_BIT) + +static u64 oa_report_id (struct xe_oa_stream *stream,void *report) +{ +return oa_report_header_64bit (stream) ? *(u64 *)report : *(u32 *)report; +} + +static u64 oa_timestamp (struct xe_oa_stream *stream,void *report) +{ +return oa_report_header_64bit (stream) ? + *((u64 *)report +1 ) : + *((u32 *)report +1 ); +} + +static bool xe_oa_buffer_check_unlocked (struct xe_oa_stream *stream) +{ +u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); +int report_size = stream->oa_buffer.format->size; +u32 tail, hw_tail; +unsigned long flags; +bool pollin; +u32 partial_report_size; + +/* +* We have to consider the (unlikely) possibility that read() errors could result +* in an OA buffer reset which might reset the head and tail state. +*/ +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + + hw_tail =gen12_oa_hw_tail_read (stream); + hw_tail -= gtt_offset; + +/* +* The tail pointer increases in 64 byte increments, not in report_size +* steps. Also the report size may not be a power of 2. Compute potentially +* partially landed report in the OA buffer +*/ + partial_report_size =OA_TAKEN (hw_tail, stream->oa_buffer.tail); + partial_report_size %= report_size; + +/* Subtract partial amount off the tail */ + hw_tail =OA_TAKEN (hw_tail, partial_report_size); + + tail = hw_tail; + +/* +* Walk the stream backward until we find a report with report id and timestmap +* not at 0. Since the circular buffer pointers progress by increments of 64 bytes +* and that reports can be up to 256 bytes long, we can't tell whether a report +* has fully landed in memory before the report id and timestamp of the following +* report have effectively landed. +* +* This is assuming that the writes of the OA unit land in memory in the order +* they were written to. If not : (╯°□°)╯︵ ┻━┻ +*/ +while (OA_TAKEN (tail, stream->oa_buffer.tail) >= report_size) { +void *report = stream->oa_buffer.vaddr + tail; + +if (oa_report_id (stream, report) || +oa_timestamp (stream, report)) +break ; + + tail =OA_TAKEN (tail, report_size); + } + +if (OA_TAKEN (hw_tail, tail) > report_size) +drm_dbg (&stream->oa->xe->drm, +"unlanded report(s) head=0x%x tail=0x%x hw_tail=0x%x\n" , + stream->oa_buffer.head, tail, hw_tail); + + stream->oa_buffer.tail = tail; + + pollin =OA_TAKEN (stream->oa_buffer.tail, + stream->oa_buffer.head) >= report_size; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + +return pollin; +} + +static enum hrtimer_restart xe_oa_poll_check_timer_cb (struct hrtimer *hrtimer) +{ +struct xe_oa_stream *stream = +container_of (hrtimer,typeof (*stream), poll_check_timer); + +if (xe_oa_buffer_check_unlocked (stream)) { + stream->pollin = true; +wake_up (&stream->poll_wq); + } + +hrtimer_forward_now (hrtimer,ns_to_ktime (stream->poll_oa_period)); + +return HRTIMER_RESTART ; +} + +static void xe_oa_init_oa_buffer (struct xe_oa_stream *stream) +{ +u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); +unsigned long flags; + +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_status,0 ); +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_head_ptr, + gtt_offset &GEN12_OAG_OAHEADPTR_MASK ); + stream->oa_buffer.head =0 ; + +/* +* PRM says: "This MMIO must be set before the OATAILPTR register and after the +* OAHEADPTR register. This is to enable proper functionality of the overflow bit". +*/ +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_buffer, gtt_offset | +OABUFFER_SIZE_16M |GEN12_OAG_OABUFFER_MEMORY_SELECT ); +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_tail_ptr, + gtt_offset &GEN12_OAG_OATAILPTR_MASK ); + +/* Mark that we need updated tail pointers to read from... */ + stream->oa_buffer.tail =0 ; + +/* +* Reset state used to recognise context switches, affecting which reports we will +* forward to userspace while filtering for a single context. +*/ + stream->oa_buffer.last_ctx_id =INVALID_CTX_ID ; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + +/* Zero out the OA buffer since we rely on zero report id and timestamp fields */ +memset (stream->oa_buffer.vaddr,0 , stream->oa_buffer.bo->size); +} + +static void xe_oa_enable (struct xe_oa_stream *stream) +{ +const struct xe_oa_regs *regs; +u32 val; + +/* +* BSpec: 46822 +* Correct values for OAR counters are still dependent on enabling the +* GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE in OAG_OACONTROL. Enabling this +* bit means OAG unit will write reports to the OAG buffer, so +* initialize the OAG buffer correctly. +*/ +xe_oa_init_oa_buffer (stream); + + regs =__oa_regs (stream); + val = (stream->oa_buffer.format->format << regs->oa_ctrl_counter_format_shift) | +GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE ; + +xe_mmio_write32 (stream->gt, regs->oa_ctrl, val); +} + +static void xe_oa_disable (struct xe_oa_stream *stream) +{ +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_ctrl,0 ); +if (xe_mmio_wait32 (stream->gt,__oa_regs (stream)->oa_ctrl, +GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE ,0 ,50000 ,NULL , false)) +drm_err (&stream->oa->xe->drm, +"wait for OA to be disabled timed out\n" ); + +xe_mmio_write32 (stream->gt,GEN12_OA_TLB_INV_CR ,1 ); +if (xe_mmio_wait32 (stream->gt,GEN12_OA_TLB_INV_CR ,1 ,0 ,50000 ,NULL , false)) +drm_err (&stream->oa->xe->drm, +"wait for OA tlb invalidate timed out\n" ); +} + +static __poll_t xe_oa_poll_locked (struct xe_oa_stream *stream, +struct file *file,poll_table *wait) +{ +__poll_t events =0 ; + +poll_wait (file, &stream->poll_wq, wait); + +/* +* We don't explicitly check whether there's something to read here since this +* path may be hot depending on what else userspace is polling, or on the timeout +* in use. We rely on hrtimer/xe_oa_poll_check_timer_cb to notify us when there +* are samples to read. +*/ +if (stream->pollin) + events |=EPOLLIN ; + +return events; +} + +static __poll_t xe_oa_poll (struct file *file,poll_table *wait) +{ +struct xe_oa_stream *stream = file->private_data; +__poll_t ret; + +mutex_lock (&stream->lock); + ret =xe_oa_poll_locked (stream, file, wait); +mutex_unlock (&stream->lock); + +return ret; +} +static int xe_oa_submit_bb (struct xe_oa_stream *stream,struct xe_bb *bb) {struct xe_hw_engine *hwe = stream->hwe;
@@ -327,6 +534,25 @@ static void xe_oa_disable_metric_set(struct xe_oa_stream *stream)xe_mmio_rmw32 (stream->gt,GEN12_SQCNT1 , sqcnt1,0 ); } +static void xe_oa_stream_destroy (struct xe_oa_stream *stream) +{ +struct xe_oa_group *g = stream->hwe->oa_group; +struct xe_gt *gt = stream->hwe->gt; + +if (WARN_ON (stream != g->exclusive_stream)) +return ; + +/* Unset exclusive_stream first */ +WRITE_ONCE (g->exclusive_stream,NULL ); +xe_oa_disable_metric_set (stream); + +XE_WARN_ON (xe_force_wake_put (gt_to_fw (gt),XE_FORCEWAKE_ALL )); +xe_device_mem_access_put (stream->oa->xe); + +xe_oa_free_oa_buffer (stream); +xe_oa_free_configs (stream); +} +static int xe_oa_alloc_oa_buffer (struct xe_oa_stream *stream) {struct xe_bo *bo;
@@ -508,6 +734,148 @@ static int xe_oa_enable_metric_set(struct xe_oa_stream *stream)return xe_oa_emit_oa_config (stream); } +static void xe_oa_stream_enable (struct xe_oa_stream *stream) +{ + stream->pollin = false; + +xe_oa_enable (stream); + +if (stream->sample) +hrtimer_start (&stream->poll_check_timer, +ns_to_ktime (stream->poll_oa_period), +HRTIMER_MODE_REL_PINNED ); +} + +static void xe_oa_stream_disable (struct xe_oa_stream *stream) +{ +xe_oa_disable (stream); + +if (stream->sample) +hrtimer_cancel (&stream->poll_check_timer); +} + +static void xe_oa_enable_locked (struct xe_oa_stream *stream) +{ +if (stream->enabled) +return ; + + stream->enabled = true; + +xe_oa_stream_enable (stream); +} + +static void xe_oa_disable_locked (struct xe_oa_stream *stream) +{ +if (!stream->enabled) +return ; + + stream->enabled = false; + +xe_oa_stream_disable (stream); +} + +static long xe_oa_config_locked (struct xe_oa_stream *stream, +unsigned long metrics_set) +{ +struct xe_oa_config *config; +long ret = stream->oa_config->id; + + config =xe_oa_get_oa_config (stream->oa, metrics_set); +if (!config) +return -ENODEV ; + +if (config != stream->oa_config) { +int err; + +/* +* If OA is bound to a specific engine, emit the reconfiguration +* inline from that engine. The update will then be ordered with +* respect to submission on that engine. +*/ + err =xe_oa_emit_oa_config (stream); +if (!err) + config =xchg (&stream->oa_config, config); +else + ret = err; + } + +xe_oa_config_put (config); + +return ret; +} + +static long xe_oa_ioctl_locked (struct xe_oa_stream *stream, +unsigned int cmd, +unsigned long arg) +{ +switch (cmd) { +case XE_OA_IOCTL_ENABLE : +xe_oa_enable_locked (stream); +return 0 ; +case XE_OA_IOCTL_DISABLE : +xe_oa_disable_locked (stream); +return 0 ; +case XE_OA_IOCTL_CONFIG : +return xe_oa_config_locked (stream, arg); + } + +return -EINVAL ; +} + +static long xe_oa_ioctl (struct file *file, +unsigned int cmd, +unsigned long arg) +{ +struct xe_oa_stream *stream = file->private_data; +long ret; + +mutex_lock (&stream->lock); + ret =xe_oa_ioctl_locked (stream, cmd, arg); +mutex_unlock (&stream->lock); + +return ret; +} + +static void xe_oa_destroy_locked (struct xe_oa_stream *stream) +{ +if (stream->enabled) +xe_oa_disable_locked (stream); + +xe_oa_stream_destroy (stream); + +if (stream->exec_q) +xe_exec_queue_put (stream->exec_q); + +kfree (stream); +} + +static int xe_oa_release (struct inode *inode,struct file *file) +{ +struct xe_oa_stream *stream = file->private_data; +struct xe_gt *gt = stream->gt; + +/* +* Within this call, we know that the fd is being closed and we have no other +* user of stream->lock. Use the perf lock to destroy the stream here. +*/ +mutex_lock (>->oa.lock); +xe_oa_destroy_locked (stream); +mutex_unlock (>->oa.lock); + +/* Release the reference the perf stream kept on the driver. */ +drm_dev_put (>->tile->xe->drm); + +return 0 ; +} + +static const struct file_operations xe_oa_fops = { + .owner =THIS_MODULE , + .llseek = no_llseek, + .release = xe_oa_release, + .poll = xe_oa_poll, + .unlocked_ioctl = xe_oa_ioctl, +}; +static bool engine_supports_mi_query (struct xe_hw_engine *hwe) {return hwe->class ==XE_ENGINE_CLASS_RENDER ;
@@ -636,6 +1004,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,WRITE_ONCE (g->exclusive_stream, stream);hrtimer_init (&stream->poll_check_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + stream->poll_check_timer.function = xe_oa_poll_check_timer_cb;init_waitqueue_head (&stream->poll_wq);spin_lock_init (&stream->oa_buffer.ptr_lock);
@@ -663,6 +1032,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,struct xe_file *xef =to_xe_file (file);struct xe_oa_stream *stream =NULL ;struct xe_exec_queue *q =NULL ; +unsigned long f_flags =0 ;bool privileged_op = true;int stream_fd;int ret;
@@ -715,10 +1085,26 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,if (ret) goto err_free; +if (param->flags &XE_OA_FLAG_FD_CLOEXEC ) + f_flags |=O_CLOEXEC ; +if (param->flags &XE_OA_FLAG_FD_NONBLOCK ) + f_flags |=O_NONBLOCK ; + + stream_fd =anon_inode_getfd ("[xe_oa]" , &xe_oa_fops, stream, f_flags); +if (stream_fd <0 ) { + ret = stream_fd; + goto err_destroy; + } + +if (!(param->flags &XE_OA_FLAG_DISABLED )) +xe_oa_enable_locked (stream); +/* Hold a reference on the drm device till stream_fd is released */ drm_dev_get (&oa->xe->drm);return stream_fd; +err_destroy: +xe_oa_stream_destroy (stream); err_free:kfree (stream); err_exec_q:
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 08/21] drm/xe/oa: Expose OA stream fd
Quoted 186 lines · Ashutosh Dixit
The OA stream open ioctl returns an fd with its own
file_operationsfor the newly initialized OA stream. Thesefile_operationsallow userspace to enable or disable the stream, as well as apply a different counter configuration for the OA stream. Userspace can also poll for data availability. OA stream initialization is completed in this commit by enabling the OA stream. When sampling is enabled this starts a hrtimer which periodically checks for data availablility.Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_oa.c| 386 +++++++++++++++++++++++++++++++++++++1 file changed, 386 insertions(+)drivers/gpu/drm/xe/xe_oa.c +144
-0@@ -12,6 +12,7 @@#include <drm/drm_drv.h> #include "regs/xe_engine_regs.h" +#include "regs/xe_gpu_commands.h" #include "regs/xe_gt_regs.h" #include "regs/xe_lrc_layout.h" #include "regs/xe_oa_regs.h" @@ -26,6 +27,7 @@#include "xe_migrate.h" #include "xe_mmio.h" #include "xe_oa.h" +#include "xe_pm.h" #include "xe_sched_job.h" #include "xe_vm.h" @@ -33,6 +35,7 @@#define OA_TAKEN (tail, head) (((tail) - (head)) & (OA_BUFFER_SIZE - 1))#define DEFAULT_POLL_FREQUENCY_HZ 200#define DEFAULT_POLL_PERIOD_NS (NSEC_PER_SEC / DEFAULT_POLL_FREQUENCY_HZ) +#define INVALID_CTX_ID U32_MAXstatic u32 xe_oa_stream_paranoid = true;static int xe_oa_sample_rate_hard_limit;@@ -129,6 +132,210 @@ static const struct xe_oa_regs *__oa_regs(struct xe_oa_stream *stream)return &stream->hwe->oa_group->regs; } +static u32 gen12_oa_hw_tail_read (struct xe_oa_stream *stream) +{ +return xe_mmio_read32 (stream->gt,__oa_regs (stream)->oa_tail_ptr) & +GEN12_OAG_OATAILPTR_MASK ; +} + +#define oa_report_header_64bit (__s) \ + ((__s)->oa_buffer.format->header == HDR_64_BIT) + +static u64 oa_report_id (struct xe_oa_stream *stream,void *report) +{ +return oa_report_header_64bit (stream) ? *(u64 *)report : *(u32 *)report; +} + +static u64 oa_timestamp (struct xe_oa_stream *stream,void *report) +{ +return oa_report_header_64bit (stream) ? + *((u64 *)report +1 ) : + *((u32 *)report +1 ); +} + +static bool xe_oa_buffer_check_unlocked (struct xe_oa_stream *stream) +{ +u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); +int report_size = stream->oa_buffer.format->size; +u32 tail, hw_tail; +unsigned long flags; +bool pollin; +u32 partial_report_size; + +/* +* We have to consider the (unlikely) possibility that read() errors could result +* in an OA buffer reset which might reset the head and tail state. +*/ +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + + hw_tail =gen12_oa_hw_tail_read (stream); + hw_tail -= gtt_offset; + +/* +* The tail pointer increases in 64 byte increments, not in report_size +* steps. Also the report size may not be a power of 2. Compute potentially +* partially landed report in the OA buffer +*/ + partial_report_size =OA_TAKEN (hw_tail, stream->oa_buffer.tail); + partial_report_size %= report_size; + +/* Subtract partial amount off the tail */ + hw_tail =OA_TAKEN (hw_tail, partial_report_size); + + tail = hw_tail; + +/* +* Walk the stream backward until we find a report with report id and timestmap +* not at 0. Since the circular buffer pointers progress by increments of 64 bytes +* and that reports can be up to 256 bytes long, we can't tell whether a report +* has fully landed in memory before the report id and timestamp of the following +* report have effectively landed. +* +* This is assuming that the writes of the OA unit land in memory in the order +* they were written to. If not : (╯°□°)╯︵ ┻━┻ +*/ +while (OA_TAKEN (tail, stream->oa_buffer.tail) >= report_size) { +void *report = stream->oa_buffer.vaddr + tail; + +if (oa_report_id (stream, report) || +oa_timestamp (stream, report)) +break ; + + tail =OA_TAKEN (tail, report_size); + } + +if (OA_TAKEN (hw_tail, tail) > report_size) +drm_dbg (&stream->oa->xe->drm, +"unlanded report(s) head=0x%x tail=0x%x hw_tail=0x%x\n" , + stream->oa_buffer.head, tail, hw_tail); + + stream->oa_buffer.tail = tail; + + pollin =OA_TAKEN (stream->oa_buffer.tail, + stream->oa_buffer.head) >= report_size; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + +return pollin; +} + +static enum hrtimer_restart xe_oa_poll_check_timer_cb (struct hrtimer *hrtimer) +{ +struct xe_oa_stream *stream = +container_of (hrtimer,typeof (*stream), poll_check_timer); + +if (xe_oa_buffer_check_unlocked (stream)) { + stream->pollin = true; +wake_up (&stream->poll_wq); + } + +hrtimer_forward_now (hrtimer,ns_to_ktime (stream->poll_oa_period)); + +return HRTIMER_RESTART ; +} + +static void xe_oa_init_oa_buffer (struct xe_oa_stream *stream) +{ +u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); +unsigned long flags; + +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_status,0 ); +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_head_ptr, + gtt_offset &GEN12_OAG_OAHEADPTR_MASK ); + stream->oa_buffer.head =0 ; + +/* +* PRM says: "This MMIO must be set before the OATAILPTR register and after the +* OAHEADPTR register. This is to enable proper functionality of the overflow bit". +*/ +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_buffer, gtt_offset | +OABUFFER_SIZE_16M |GEN12_OAG_OABUFFER_MEMORY_SELECT ); +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_tail_ptr, + gtt_offset &GEN12_OAG_OATAILPTR_MASK ); + +/* Mark that we need updated tail pointers to read from... */ + stream->oa_buffer.tail =0 ; + +/* +* Reset state used to recognise context switches, affecting which reports we will +* forward to userspace while filtering for a single context. +*/ + stream->oa_buffer.last_ctx_id =INVALID_CTX_ID ; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + +/* Zero out the OA buffer since we rely on zero report id and timestamp fields */ +memset (stream->oa_buffer.vaddr,0 , stream->oa_buffer.bo->size); +} + +static void xe_oa_enable (struct xe_oa_stream *stream) +{ +const struct xe_oa_regs *regs;
drivers/gpu/drm/xe/xe_oa.c static const struct xe_oa_regs *__oa_regs(struct xe_oa_stream *stream) · line 285
Quoted 10 lines
drivers/gpu/drm/xe/xe_oa.c +10
-0+u32 val; + +/* +* BSpec: 46822 +* Correct values for OAR counters are still dependent on enabling the +* GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE in OAG_OACONTROL. Enabling this +* bit means OAG unit will write reports to the OAG buffer, so +* initialize the OAG buffer correctly. +*/ +xe_oa_init_oa_buffer (stream);
In the case where we just want OAR/OAC, we could go with a small OAG buffer and set "Disable Overrun Mode" bit in the OAG_OABUFFER register. Then OAG would just stop once the buffer is full. I would think that would consume less HW resources. We can do this later too, everything here lgtm,
Quoted 277 lines
drivers/gpu/drm/xe/xe_oa.c +232
-0+ + regs =__oa_regs (stream); + val = (stream->oa_buffer.format->format << regs->oa_ctrl_counter_format_shift) | +GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE ; + +xe_mmio_write32 (stream->gt, regs->oa_ctrl, val); +} + +static void xe_oa_disable (struct xe_oa_stream *stream) +{ +xe_mmio_write32 (stream->gt,__oa_regs (stream)->oa_ctrl,0 ); +if (xe_mmio_wait32 (stream->gt,__oa_regs (stream)->oa_ctrl, +GEN12_OAG_OACONTROL_OA_COUNTER_ENABLE ,0 ,50000 ,NULL , false)) +drm_err (&stream->oa->xe->drm, +"wait for OA to be disabled timed out\n" ); + +xe_mmio_write32 (stream->gt,GEN12_OA_TLB_INV_CR ,1 ); +if (xe_mmio_wait32 (stream->gt,GEN12_OA_TLB_INV_CR ,1 ,0 ,50000 ,NULL , false)) +drm_err (&stream->oa->xe->drm, +"wait for OA tlb invalidate timed out\n" ); +} + +static __poll_t xe_oa_poll_locked (struct xe_oa_stream *stream, +struct file *file,poll_table *wait) +{ +__poll_t events =0 ; + +poll_wait (file, &stream->poll_wq, wait); + +/* +* We don't explicitly check whether there's something to read here since this +* path may be hot depending on what else userspace is polling, or on the timeout +* in use. We rely on hrtimer/xe_oa_poll_check_timer_cb to notify us when there +* are samples to read. +*/ +if (stream->pollin) + events |=EPOLLIN ; + +return events; +} + +static __poll_t xe_oa_poll (struct file *file,poll_table *wait) +{ +struct xe_oa_stream *stream = file->private_data; +__poll_t ret; + +mutex_lock (&stream->lock); + ret =xe_oa_poll_locked (stream, file, wait); +mutex_unlock (&stream->lock); + +return ret; +} +static int xe_oa_submit_bb (struct xe_oa_stream *stream,struct xe_bb *bb) {struct xe_hw_engine *hwe = stream->hwe;@@ -327,6 +534,25 @@ static void xe_oa_disable_metric_set(struct xe_oa_stream *stream)xe_mmio_rmw32 (stream->gt,GEN12_SQCNT1 , sqcnt1,0 ); } +static void xe_oa_stream_destroy (struct xe_oa_stream *stream) +{ +struct xe_oa_group *g = stream->hwe->oa_group; +struct xe_gt *gt = stream->hwe->gt; + +if (WARN_ON (stream != g->exclusive_stream)) +return ; + +/* Unset exclusive_stream first */ +WRITE_ONCE (g->exclusive_stream,NULL ); +xe_oa_disable_metric_set (stream); + +XE_WARN_ON (xe_force_wake_put (gt_to_fw (gt),XE_FORCEWAKE_ALL )); +xe_device_mem_access_put (stream->oa->xe); + +xe_oa_free_oa_buffer (stream); +xe_oa_free_configs (stream); +} +static int xe_oa_alloc_oa_buffer (struct xe_oa_stream *stream) {struct xe_bo *bo;@@ -508,6 +734,148 @@ static int xe_oa_enable_metric_set(struct xe_oa_stream *stream)return xe_oa_emit_oa_config (stream); } +static void xe_oa_stream_enable (struct xe_oa_stream *stream) +{ + stream->pollin = false; + +xe_oa_enable (stream); + +if (stream->sample) +hrtimer_start (&stream->poll_check_timer, +ns_to_ktime (stream->poll_oa_period), +HRTIMER_MODE_REL_PINNED ); +} + +static void xe_oa_stream_disable (struct xe_oa_stream *stream) +{ +xe_oa_disable (stream); + +if (stream->sample) +hrtimer_cancel (&stream->poll_check_timer); +} + +static void xe_oa_enable_locked (struct xe_oa_stream *stream) +{ +if (stream->enabled) +return ; + + stream->enabled = true; + +xe_oa_stream_enable (stream); +} + +static void xe_oa_disable_locked (struct xe_oa_stream *stream) +{ +if (!stream->enabled) +return ; + + stream->enabled = false; + +xe_oa_stream_disable (stream); +} + +static long xe_oa_config_locked (struct xe_oa_stream *stream, +unsigned long metrics_set) +{ +struct xe_oa_config *config; +long ret = stream->oa_config->id; + + config =xe_oa_get_oa_config (stream->oa, metrics_set); +if (!config) +return -ENODEV ; + +if (config != stream->oa_config) { +int err; + +/* +* If OA is bound to a specific engine, emit the reconfiguration +* inline from that engine. The update will then be ordered with +* respect to submission on that engine. +*/ + err =xe_oa_emit_oa_config (stream); +if (!err) + config =xchg (&stream->oa_config, config); +else + ret = err; + } + +xe_oa_config_put (config); + +return ret; +} + +static long xe_oa_ioctl_locked (struct xe_oa_stream *stream, +unsigned int cmd, +unsigned long arg) +{ +switch (cmd) { +case XE_OA_IOCTL_ENABLE : +xe_oa_enable_locked (stream); +return 0 ; +case XE_OA_IOCTL_DISABLE : +xe_oa_disable_locked (stream); +return 0 ; +case XE_OA_IOCTL_CONFIG : +return xe_oa_config_locked (stream, arg); + } + +return -EINVAL ; +} + +static long xe_oa_ioctl (struct file *file, +unsigned int cmd, +unsigned long arg) +{ +struct xe_oa_stream *stream = file->private_data; +long ret; + +mutex_lock (&stream->lock); + ret =xe_oa_ioctl_locked (stream, cmd, arg); +mutex_unlock (&stream->lock); + +return ret; +} + +static void xe_oa_destroy_locked (struct xe_oa_stream *stream) +{ +if (stream->enabled) +xe_oa_disable_locked (stream); + +xe_oa_stream_destroy (stream); + +if (stream->exec_q) +xe_exec_queue_put (stream->exec_q); + +kfree (stream); +} + +static int xe_oa_release (struct inode *inode,struct file *file) +{ +struct xe_oa_stream *stream = file->private_data; +struct xe_gt *gt = stream->gt; + +/* +* Within this call, we know that the fd is being closed and we have no other +* user of stream->lock. Use the perf lock to destroy the stream here. +*/ +mutex_lock (>->oa.lock); +xe_oa_destroy_locked (stream); +mutex_unlock (>->oa.lock); + +/* Release the reference the perf stream kept on the driver. */ +drm_dev_put (>->tile->xe->drm); + +return 0 ; +} + +static const struct file_operations xe_oa_fops = { + .owner =THIS_MODULE , + .llseek = no_llseek, + .release = xe_oa_release, + .poll = xe_oa_poll, + .unlocked_ioctl = xe_oa_ioctl, +}; +static bool engine_supports_mi_query (struct xe_hw_engine *hwe) {return hwe->class ==XE_ENGINE_CLASS_RENDER ;@@ -636,6 +1004,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,WRITE_ONCE (g->exclusive_stream, stream);hrtimer_init (&stream->poll_check_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + stream->poll_check_timer.function = xe_oa_poll_check_timer_cb;init_waitqueue_head (&stream->poll_wq);spin_lock_init (&stream->oa_buffer.ptr_lock);@@ -663,6 +1032,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,struct xe_file *xef =to_xe_file (file);struct xe_oa_stream *stream =NULL ;struct xe_exec_queue *q =NULL ; +unsigned long f_flags =0 ;bool privileged_op = true;int stream_fd;int ret;@@ -715,10 +1085,26 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,if (ret) goto err_free; +if (param->flags &XE_OA_FLAG_FD_CLOEXEC ) + f_flags |=O_CLOEXEC ; +if (param->flags &XE_OA_FLAG_FD_NONBLOCK ) + f_flags |=O_NONBLOCK ; + + stream_fd =anon_inode_getfd ("[xe_oa]" , &xe_oa_fops, stream, f_flags); +if (stream_fd <0 ) { + ret = stream_fd; + goto err_destroy; + } + +if (!(param->flags &XE_OA_FLAG_DISABLED )) +xe_oa_enable_locked (stream); +/* Hold a reference on the drm device till stream_fd is released */ drm_dev_get (&oa->xe->drm);return stream_fd; +err_destroy: +xe_oa_stream_destroy (stream);
err_free:kfree(stream);
err_exec_q:Signature · 1 line
2.41.0
PATCH 9/21 drm/xe/oa: Read file_operation
In reply to Ashutosh DixitFinally implement the OA stream read file_operation which was the only fop missing in the previous commit. Both blocking and non-blocking reads are supported. The read copies OA perf data from the OA buffer to the user buffer provided as part of read system call.
v2: Implement oa_report_ctx_invalid (Umesh)
--- drivers/gpu/drm/xe/xe_oa.c | 360 +++++++++++++++++++++++++++++++++++++ 1 file changed, 360 insertions(+)
drivers/gpu/drm/xe/xe_oa.c +360 -0
@@ -146,6 +146,30 @@ static u64 oa_report_id(struct xe_oa_stream *stream, void *report)return oa_report_header_64bit (stream) ? *(u64 *)report : *(u32 *)report; } +#define OAREPORT_REASON_MASK_EXTENDED GENMASK(25, 19) +#define OAREPORT_REASON_TIMER BIT(0) +#define OAREPORT_REASON_CTX_SWITCH BIT(3) +#define OAREPORT_REASON_CLK_RATIO BIT(5) +#define OAREPORT_CONTEXT_VALID BIT(16) + +static u64 oa_report_reason (struct xe_oa_stream *stream,void *report) +{ +return FIELD_GET (OAREPORT_REASON_MASK_EXTENDED ,oa_report_id (stream, report)); +} + +static void oa_report_id_clear (struct xe_oa_stream *stream,u32 *report) +{ +if (oa_report_header_64bit (stream)) + *(u64 *)report =0 ; +else + *report =0 ; +} + +static bool oa_report_ctx_invalid (struct xe_oa_stream *stream,void *report) +{ +return !(oa_report_id (stream, report) &OAREPORT_CONTEXT_VALID ); +} +static u64 oa_timestamp (struct xe_oa_stream *stream,void *report) { return oa_report_header_64bit(stream) ?
@@ -153,6 +177,29 @@ static u64 oa_timestamp(struct xe_oa_stream *stream, void *report) *((u32 *)report +1 ); } +static void oa_timestamp_clear (struct xe_oa_stream *stream,u32 *report) +{ +if (oa_report_header_64bit (stream)) + *(u64 *)&report[2 ] =0 ; +else + report[1 ] =0 ; +} + +static u32 oa_context_id (struct xe_oa_stream *stream,u32 *report) +{ +u32 ctx_id =oa_report_header_64bit (stream) ? report[4 ] : report[2 ]; + +return ctx_id & stream->specific_ctx_id_mask; +} + +static void oa_context_id_squash (struct xe_oa_stream *stream,u32 *report) +{ +if (oa_report_header_64bit (stream)) + report[4 ] =INVALID_CTX_ID ; +else + report[2 ] =INVALID_CTX_ID ; +} +static bool xe_oa_buffer_check_unlocked (struct xe_oa_stream *stream) {u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo);
@@ -234,6 +281,199 @@ static enum hrtimer_restart xe_oa_poll_check_timer_cb(struct hrtimer *hrtimer)return HRTIMER_RESTART ; } +static int xe_oa_append_status (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset, +enum drm_xe_oa_record_type type) +{ +struct drm_xe_oa_record_header header = { type,0 ,sizeof (header) }; + +if ((count - *offset) < header.size) +return -ENOSPC ; + +if (copy_to_user (buf + *offset, &header,sizeof (header))) +return -EFAULT ; + + *offset += header.size; + +return 0 ; +} + +static int xe_oa_append_sample (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset,const u8 *report) +{ +int report_size = stream->oa_buffer.format->size; +struct drm_xe_oa_record_header header; +int report_size_partial; +u8 *oa_buf_end; + + header.type =DRM_XE_OA_RECORD_SAMPLE ; + header.pad =0 ; + header.size = stream->sample_size; + +if ((count - *offset) < header.size) +return -ENOSPC ; + + buf += *offset; +if (copy_to_user (buf, &header,sizeof (header))) +return -EFAULT ; + buf +=sizeof (header); + + oa_buf_end = stream->oa_buffer.vaddr +OA_BUFFER_SIZE ; + report_size_partial = oa_buf_end - report; + +if (report_size_partial < report_size) { +if (copy_to_user (buf, report, report_size_partial)) +return -EFAULT ; + buf += report_size_partial; + +if (copy_to_user (buf, stream->oa_buffer.vaddr, + report_size - report_size_partial)) +return -EFAULT ; + }else if (copy_to_user (buf, report, report_size)) { +return -EFAULT ; + } + + *offset += header.size; + +return 0 ; +} + +static int xe_oa_append_reports (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset) +{ +int report_size = stream->oa_buffer.format->size; +u8 *oa_buf_base = stream->oa_buffer.vaddr; +u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); +u32 mask = (OA_BUFFER_SIZE -1 ); +size_t start_offset = *offset; +unsigned long flags; +u32 head, tail; +int ret =0 ; + +if (drm_WARN_ON (&stream->oa->xe->drm, !stream->enabled)) +return -EIO ; + +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + + head = stream->oa_buffer.head; + tail = stream->oa_buffer.tail; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + +/* An out of bounds or misaligned head or tail pointer implies a driver bug */ +if (drm_WARN_ONCE (&stream->oa->xe->drm, + head >OA_BUFFER_SIZE || tail >OA_BUFFER_SIZE , +"Inconsistent OA buffer pointers: head = %u, tail = %u\n" , + head, tail)) +return -EIO ; + +for (;OA_TAKEN (tail, head); head = (head + report_size) & mask) { +u8 *report = oa_buf_base + head; +u32 ctx_id, *report32 = (void *)report; +u64 reason; + +/* +* The reason field indicates what triggered this report (e.g. timer +* triggered or a context switch). +* +* In MMIO triggered reports, some platforms do not set the reason bit in +* this field and it is valid to have a reason field of zero. +*/ + reason =oa_report_reason (stream, report); + ctx_id =oa_context_id (stream, report32); + +/* +* Squash whatever is in the CTX_ID field if it's marked as invalid to be +* sure we avoid false-positive, single-context filtering below... +* +* Note: we don't clear the valid_ctx_bit so userspace can understand that +* the ID has been squashed by the kernel. +*/ +if (oa_report_ctx_invalid (stream, report)) { + ctx_id =INVALID_CTX_ID ; +oa_context_id_squash (stream, report32); + } + +/* +* NB: The OA unit does not support clock gating off for a specific +* context and the kernel can't securely stop counters from updating as +* system-wide/global values. +* +* Automatic reports include a context ID so reports can be filtered on +* the cpu but it's not worth trying to automatically subtract/hide +* counter progress for other contexts while filtering since userspace can +* issue MI_REPORT_PERF_COUNT commands which would still provide a +* side-band view of the real values. +* +* To allow userspace to normalize counters for a single filtered context +* then it needs be forwarded bookend context-switch reports so that it +* can track switches in between MI_REPORT_PERF_COUNT commands and can +* itself subtract/ignore the progress of counters associated with other +* contexts. Note that the hardware automatically triggers reports when +* switching to a new context which are tagged with the ID of the newly +* active context. To avoid the complexity of reading ahead while parsing +* reports to try and minimize forwarding redundant context switch reports +* (i.e. between other, unrelated contexts) we simply elect to forward +* them all. +* +* We don't rely solely on the reason field to identify context switches +* since it's not-uncommon for periodic samples to identify a switch +* before any 'context switch' report. +*/ +if (!stream->exec_q || stream->specific_ctx_id == ctx_id || + stream->oa_buffer.last_ctx_id == stream->specific_ctx_id || + reason &OAREPORT_REASON_CTX_SWITCH ) { +/* +* While filtering for a single context we avoid +* leaking the IDs of other contexts. +*/ +if (stream->exec_q && stream->specific_ctx_id != ctx_id) +oa_context_id_squash (stream, report32); + + ret =xe_oa_append_sample (stream, buf, count, offset, report); +if (ret) +break ; + + stream->oa_buffer.last_ctx_id = ctx_id; + } + +if (is_power_of_2 (report_size)) { +/* +* Clear out report id and timestamp as a means to +* detect unlanded reports. +*/ +oa_report_id_clear (stream, report32); +oa_timestamp_clear (stream, report32); + }else { +u8 *oa_buf_end = stream->oa_buffer.vaddr + +OA_BUFFER_SIZE ; +u32 part = oa_buf_end - (u8 *)report32; + +/* Zero out the entire report */ +if (report_size <= part) { +memset (report32,0 , report_size); + }else { +memset (report32,0 , part); +memset (oa_buf_base,0 , report_size - part); + } + } + } + +if (start_offset != *offset) { +struct xe_reg oaheadptr =__oa_regs (stream)->oa_head_ptr; + +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + +xe_mmio_write32 (stream->gt, oaheadptr, + (head + gtt_offset) &GEN12_OAG_OAHEADPTR_MASK ); + stream->oa_buffer.head = head; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + } + +return ret; +} +static void xe_oa_init_oa_buffer (struct xe_oa_stream *stream) {u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo);
@@ -305,6 +545,125 @@ static void xe_oa_disable(struct xe_oa_stream *stream) "wait for OA tlb invalidate timed out\n"); } +static int __xe_oa_read (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset) +{ +struct xe_reg oastatus_reg =__oa_regs (stream)->oa_status; +u32 oastatus; +int ret; + +if (drm_WARN_ON (&stream->oa->xe->drm, !stream->oa_buffer.vaddr)) +return -EIO ; + + oastatus =xe_mmio_read32 (stream->gt, oastatus_reg); + +/* +* We treat OABUFFER_OVERFLOW as a significant error: +* +* We could handle this more gracefully, but some Gens don't correctly suppress +* certain automatically triggered reports in this condition and so we have to +* assume that old reports are now being trampled over. +* +* Considering how we don't currently give userspace control over the OA buffer +* size and always configure a large 16MB buffer, then a buffer overflow does +* anyway likely indicate that something has gone quite badly wrong. +*/ +if (oastatus &GEN12_OAG_OASTATUS_BUFFER_OVERFLOW ) { + ret =xe_oa_append_status (stream, buf, count, offset, +DRM_XE_OA_RECORD_OA_BUFFER_LOST ); +if (ret) +return ret; + +drm_dbg (&stream->oa->xe->drm, +"OA buffer overflow (exponent = %d): force restart\n" , + stream->period_exponent); + +xe_oa_disable (stream); +xe_oa_enable (stream); + +/* +* Note: oa_enable is expected to re-init the oabuffer and reset +* oastatus_reg for us +*/ + oastatus =xe_mmio_read32 (stream->gt, oastatus_reg); + } + +if (oastatus &GEN12_OAG_OASTATUS_REPORT_LOST ) { + ret =xe_oa_append_status (stream, buf, count, offset, +DRM_XE_OA_RECORD_OA_REPORT_LOST ); +if (ret) +return ret; + +xe_mmio_rmw32 (stream->gt, oastatus_reg, +GEN12_OAG_OASTATUS_COUNTER_OVERFLOW | +GEN12_OAG_OASTATUS_REPORT_LOST ,0 ); + } + +return xe_oa_append_reports (stream, buf, count, offset); +} + +static int xe_oa_wait_unlocked (struct xe_oa_stream *stream) +{ +/* We might wait indefinitely if periodic sampling is not enabled */ +if (!stream->periodic) +return -EIO ; + +return wait_event_interruptible (stream->poll_wq, +xe_oa_buffer_check_unlocked (stream)); +} + +static ssize_t xe_oa_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct xe_oa_stream *stream = file->private_data; +size_t offset =0 ; +int ret; + +/* Can't read from disabled streams */ +if (!stream->enabled || !stream->sample) +return -EIO ; + +if (!(file->f_flags &O_NONBLOCK )) { +/* +* There's the small chance of false positives from wait_unlocked, +* e.g. with single engine filtering since we only wait until oabuffer +* has >= 1 report we don't immediately know whether any reports really +* belong to the current engine. +*/ +do { + ret =xe_oa_wait_unlocked (stream); +if (ret) +return ret; + +mutex_lock (&stream->lock); + ret =__xe_oa_read (stream, buf, count, &offset); +mutex_unlock (&stream->lock); + }while (!offset && !ret); + }else { +mutex_lock (&stream->lock); + ret =__xe_oa_read (stream, buf, count, &offset); +mutex_unlock (&stream->lock); + } + +/* +* We allow the poll checking to sometimes report false positive EPOLLIN +* events where we might actually report EAGAIN on read() if there's +* not really any data available. In this situation though we don't +* want to enter a busy loop between poll() reporting a EPOLLIN event +* and read() returning -EAGAIN. Clearing the oa.pollin state here +* effectively ensures we back off until the next hrtimer callback +* before reporting another EPOLLIN event. +* The exception to this is if __xe_oa_read returned -ENOSPC which means +* that more OA data is available than could fit in the user provided +* buffer. In this case we want the next poll() call to not block. +*/ +if (ret != -ENOSPC ) + stream->pollin = false; + +/* Possible values for ret are 0, -EFAULT, -ENOSPC, -EIO, ... */ +return offset ?: (ret ?: -EAGAIN ); +} +static __poll_t xe_oa_poll_locked (struct xe_oa_stream *stream,struct file *file,poll_table *wait) {
@@ -873,6 +1232,7 @@ static const struct file_operations xe_oa_fops = { .llseek = no_llseek, .release = xe_oa_release, .poll = xe_oa_poll, + .read = xe_oa_read, .unlocked_ioctl = xe_oa_ioctl, };
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 09/21] drm/xe/oa: Read file_operation
Quoted 8 lines · Ashutosh Dixit
Finally implement the OA stream read
file_operationwhich was the only fop missing in the previous commit. Both blocking and non-blocking reads are supported. The read copies OA perf data from the OA buffer to the user buffer provided as part of read system call.v2: Implement
oa_report_ctx_invalid(Umesh)Signed-off-by Ashutosh Dixit <[email protected]>
lgtm,
Quoted 406 lines
---
drivers/gpu/drm/xe/xe_oa.c| 360 +++++++++++++++++++++++++++++++++++++1 file changed, 360 insertions(+)drivers/gpu/drm/xe/xe_oa.c +360
-0@@ -146,6 +146,30 @@ static u64 oa_report_id(struct xe_oa_stream *stream, void *report)return oa_report_header_64bit (stream) ? *(u64 *)report : *(u32 *)report; } +#define OAREPORT_REASON_MASK_EXTENDED GENMASK(25, 19) +#define OAREPORT_REASON_TIMER BIT(0) +#define OAREPORT_REASON_CTX_SWITCH BIT(3) +#define OAREPORT_REASON_CLK_RATIO BIT(5) +#define OAREPORT_CONTEXT_VALID BIT(16) + +static u64 oa_report_reason (struct xe_oa_stream *stream,void *report) +{ +return FIELD_GET (OAREPORT_REASON_MASK_EXTENDED ,oa_report_id (stream, report)); +} + +static void oa_report_id_clear (struct xe_oa_stream *stream,u32 *report) +{ +if (oa_report_header_64bit (stream)) + *(u64 *)report =0 ; +else + *report =0 ; +} + +static bool oa_report_ctx_invalid (struct xe_oa_stream *stream,void *report) +{ +return !(oa_report_id (stream, report) &OAREPORT_CONTEXT_VALID ); +} +static u64 oa_timestamp (struct xe_oa_stream *stream,void *report) { return oa_report_header_64bit(stream) ?@@ -153,6 +177,29 @@ static u64 oa_timestamp(struct xe_oa_stream *stream, void *report) *((u32 *)report +1 ); } +static void oa_timestamp_clear (struct xe_oa_stream *stream,u32 *report) +{ +if (oa_report_header_64bit (stream)) + *(u64 *)&report[2 ] =0 ; +else + report[1 ] =0 ; +} + +static u32 oa_context_id (struct xe_oa_stream *stream,u32 *report) +{ +u32 ctx_id =oa_report_header_64bit (stream) ? report[4 ] : report[2 ]; + +return ctx_id & stream->specific_ctx_id_mask; +} + +static void oa_context_id_squash (struct xe_oa_stream *stream,u32 *report) +{ +if (oa_report_header_64bit (stream)) + report[4 ] =INVALID_CTX_ID ; +else + report[2 ] =INVALID_CTX_ID ; +} +static bool xe_oa_buffer_check_unlocked (struct xe_oa_stream *stream) {u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo);@@ -234,6 +281,199 @@ static enum hrtimer_restart xe_oa_poll_check_timer_cb(struct hrtimer *hrtimer)return HRTIMER_RESTART ; } +static int xe_oa_append_status (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset, +enum drm_xe_oa_record_type type) +{ +struct drm_xe_oa_record_header header = { type,0 ,sizeof (header) }; + +if ((count - *offset) < header.size) +return -ENOSPC ; + +if (copy_to_user (buf + *offset, &header,sizeof (header))) +return -EFAULT ; + + *offset += header.size; + +return 0 ; +} + +static int xe_oa_append_sample (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset,const u8 *report) +{ +int report_size = stream->oa_buffer.format->size; +struct drm_xe_oa_record_header header; +int report_size_partial; +u8 *oa_buf_end; + + header.type =DRM_XE_OA_RECORD_SAMPLE ; + header.pad =0 ; + header.size = stream->sample_size; + +if ((count - *offset) < header.size) +return -ENOSPC ; + + buf += *offset; +if (copy_to_user (buf, &header,sizeof (header))) +return -EFAULT ; + buf +=sizeof (header); + + oa_buf_end = stream->oa_buffer.vaddr +OA_BUFFER_SIZE ; + report_size_partial = oa_buf_end - report; + +if (report_size_partial < report_size) { +if (copy_to_user (buf, report, report_size_partial)) +return -EFAULT ; + buf += report_size_partial; + +if (copy_to_user (buf, stream->oa_buffer.vaddr, + report_size - report_size_partial)) +return -EFAULT ; + }else if (copy_to_user (buf, report, report_size)) { +return -EFAULT ; + } + + *offset += header.size; + +return 0 ; +} + +static int xe_oa_append_reports (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset) +{ +int report_size = stream->oa_buffer.format->size; +u8 *oa_buf_base = stream->oa_buffer.vaddr; +u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo); +u32 mask = (OA_BUFFER_SIZE -1 ); +size_t start_offset = *offset; +unsigned long flags; +u32 head, tail; +int ret =0 ; + +if (drm_WARN_ON (&stream->oa->xe->drm, !stream->enabled)) +return -EIO ; + +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + + head = stream->oa_buffer.head; + tail = stream->oa_buffer.tail; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + +/* An out of bounds or misaligned head or tail pointer implies a driver bug */ +if (drm_WARN_ONCE (&stream->oa->xe->drm, + head >OA_BUFFER_SIZE || tail >OA_BUFFER_SIZE , +"Inconsistent OA buffer pointers: head = %u, tail = %u\n" , + head, tail)) +return -EIO ; + +for (;OA_TAKEN (tail, head); head = (head + report_size) & mask) { +u8 *report = oa_buf_base + head; +u32 ctx_id, *report32 = (void *)report; +u64 reason; + +/* +* The reason field indicates what triggered this report (e.g. timer +* triggered or a context switch). +* +* In MMIO triggered reports, some platforms do not set the reason bit in +* this field and it is valid to have a reason field of zero. +*/ + reason =oa_report_reason (stream, report); + ctx_id =oa_context_id (stream, report32); + +/* +* Squash whatever is in the CTX_ID field if it's marked as invalid to be +* sure we avoid false-positive, single-context filtering below... +* +* Note: we don't clear the valid_ctx_bit so userspace can understand that +* the ID has been squashed by the kernel. +*/ +if (oa_report_ctx_invalid (stream, report)) { + ctx_id =INVALID_CTX_ID ; +oa_context_id_squash (stream, report32); + } + +/* +* NB: The OA unit does not support clock gating off for a specific +* context and the kernel can't securely stop counters from updating as +* system-wide/global values. +* +* Automatic reports include a context ID so reports can be filtered on +* the cpu but it's not worth trying to automatically subtract/hide +* counter progress for other contexts while filtering since userspace can +* issue MI_REPORT_PERF_COUNT commands which would still provide a +* side-band view of the real values. +* +* To allow userspace to normalize counters for a single filtered context +* then it needs be forwarded bookend context-switch reports so that it +* can track switches in between MI_REPORT_PERF_COUNT commands and can +* itself subtract/ignore the progress of counters associated with other +* contexts. Note that the hardware automatically triggers reports when +* switching to a new context which are tagged with the ID of the newly +* active context. To avoid the complexity of reading ahead while parsing +* reports to try and minimize forwarding redundant context switch reports +* (i.e. between other, unrelated contexts) we simply elect to forward +* them all. +* +* We don't rely solely on the reason field to identify context switches +* since it's not-uncommon for periodic samples to identify a switch +* before any 'context switch' report. +*/ +if (!stream->exec_q || stream->specific_ctx_id == ctx_id || + stream->oa_buffer.last_ctx_id == stream->specific_ctx_id || + reason &OAREPORT_REASON_CTX_SWITCH ) { +/* +* While filtering for a single context we avoid +* leaking the IDs of other contexts. +*/ +if (stream->exec_q && stream->specific_ctx_id != ctx_id) +oa_context_id_squash (stream, report32); + + ret =xe_oa_append_sample (stream, buf, count, offset, report); +if (ret) +break ; + + stream->oa_buffer.last_ctx_id = ctx_id; + } + +if (is_power_of_2 (report_size)) { +/* +* Clear out report id and timestamp as a means to +* detect unlanded reports. +*/ +oa_report_id_clear (stream, report32); +oa_timestamp_clear (stream, report32); + }else { +u8 *oa_buf_end = stream->oa_buffer.vaddr + +OA_BUFFER_SIZE ; +u32 part = oa_buf_end - (u8 *)report32; + +/* Zero out the entire report */ +if (report_size <= part) { +memset (report32,0 , report_size); + }else { +memset (report32,0 , part); +memset (oa_buf_base,0 , report_size - part); + } + } + } + +if (start_offset != *offset) { +struct xe_reg oaheadptr =__oa_regs (stream)->oa_head_ptr; + +spin_lock_irqsave (&stream->oa_buffer.ptr_lock, flags); + +xe_mmio_write32 (stream->gt, oaheadptr, + (head + gtt_offset) &GEN12_OAG_OAHEADPTR_MASK ); + stream->oa_buffer.head = head; + +spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags); + } + +return ret; +} +static void xe_oa_init_oa_buffer (struct xe_oa_stream *stream) {u32 gtt_offset =xe_bo_ggtt_addr (stream->oa_buffer.bo);@@ -305,6 +545,125 @@ static void xe_oa_disable(struct xe_oa_stream *stream) "wait for OA tlb invalidate timed out\n"); } +static int __xe_oa_read (struct xe_oa_stream *stream,char __user *buf, +size_t count,size_t *offset) +{ +struct xe_reg oastatus_reg =__oa_regs (stream)->oa_status; +u32 oastatus; +int ret; + +if (drm_WARN_ON (&stream->oa->xe->drm, !stream->oa_buffer.vaddr)) +return -EIO ; + + oastatus =xe_mmio_read32 (stream->gt, oastatus_reg); + +/* +* We treat OABUFFER_OVERFLOW as a significant error: +* +* We could handle this more gracefully, but some Gens don't correctly suppress +* certain automatically triggered reports in this condition and so we have to +* assume that old reports are now being trampled over. +* +* Considering how we don't currently give userspace control over the OA buffer +* size and always configure a large 16MB buffer, then a buffer overflow does +* anyway likely indicate that something has gone quite badly wrong. +*/ +if (oastatus &GEN12_OAG_OASTATUS_BUFFER_OVERFLOW ) { + ret =xe_oa_append_status (stream, buf, count, offset, +DRM_XE_OA_RECORD_OA_BUFFER_LOST ); +if (ret) +return ret; + +drm_dbg (&stream->oa->xe->drm, +"OA buffer overflow (exponent = %d): force restart\n" , + stream->period_exponent); + +xe_oa_disable (stream); +xe_oa_enable (stream); + +/* +* Note: oa_enable is expected to re-init the oabuffer and reset +* oastatus_reg for us +*/ + oastatus =xe_mmio_read32 (stream->gt, oastatus_reg); + } + +if (oastatus &GEN12_OAG_OASTATUS_REPORT_LOST ) { + ret =xe_oa_append_status (stream, buf, count, offset, +DRM_XE_OA_RECORD_OA_REPORT_LOST ); +if (ret) +return ret; + +xe_mmio_rmw32 (stream->gt, oastatus_reg, +GEN12_OAG_OASTATUS_COUNTER_OVERFLOW | +GEN12_OAG_OASTATUS_REPORT_LOST ,0 ); + } + +return xe_oa_append_reports (stream, buf, count, offset); +} + +static int xe_oa_wait_unlocked (struct xe_oa_stream *stream) +{ +/* We might wait indefinitely if periodic sampling is not enabled */ +if (!stream->periodic) +return -EIO ; + +return wait_event_interruptible (stream->poll_wq, +xe_oa_buffer_check_unlocked (stream)); +} + +static ssize_t xe_oa_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct xe_oa_stream *stream = file->private_data; +size_t offset =0 ; +int ret; + +/* Can't read from disabled streams */ +if (!stream->enabled || !stream->sample) +return -EIO ; + +if (!(file->f_flags &O_NONBLOCK )) { +/* +* There's the small chance of false positives from wait_unlocked, +* e.g. with single engine filtering since we only wait until oabuffer +* has >= 1 report we don't immediately know whether any reports really +* belong to the current engine. +*/ +do { + ret =xe_oa_wait_unlocked (stream); +if (ret) +return ret; + +mutex_lock (&stream->lock); + ret =__xe_oa_read (stream, buf, count, &offset); +mutex_unlock (&stream->lock); + }while (!offset && !ret); + }else { +mutex_lock (&stream->lock); + ret =__xe_oa_read (stream, buf, count, &offset); +mutex_unlock (&stream->lock); + } + +/* +* We allow the poll checking to sometimes report false positive EPOLLIN +* events where we might actually report EAGAIN on read() if there's +* not really any data available. In this situation though we don't +* want to enter a busy loop between poll() reporting a EPOLLIN event +* and read() returning -EAGAIN. Clearing the oa.pollin state here +* effectively ensures we back off until the next hrtimer callback +* before reporting another EPOLLIN event. +* The exception to this is if __xe_oa_read returned -ENOSPC which means +* that more OA data is available than could fit in the user provided +* buffer. In this case we want the next poll() call to not block. +*/ +if (ret != -ENOSPC ) + stream->pollin = false; + +/* Possible values for ret are 0, -EFAULT, -ENOSPC, -EIO, ... */ +return offset ?: (ret ?: -EAGAIN ); +} +static __poll_t xe_oa_poll_locked (struct xe_oa_stream *stream,struct file *file,poll_table *wait) {@@ -873,6 +1232,7 @@ static const struct file_operations xe_oa_fops = { .llseek = no_llseek, .release = xe_oa_release, .poll = xe_oa_poll, + .read = xe_oa_read, .unlocked_ioctl = xe_oa_ioctl, };Signature · 1 line
2.41.0
PATCH 10/21 drm/xe/oa: Implement queries
In reply to Ashutosh DixitImplement queries to query OA unit ID's for HW engines, OA timestamp freq and OA ioctl version.
v2: Convert oa_unit_id to u16 (Umesh)
--- drivers/gpu/drm/xe/xe_oa.c | 11 +++++++++++ drivers/gpu/drm/xe/xe_oa.h | 3 +++ drivers/gpu/drm/xe/xe_query.c | 6 +++++- 3 files changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_oa.c +11 -0
@@ -2212,6 +2212,12 @@ static int xe_oa_init_engine_groups(struct xe_oa *oa)return 0 ; } +u16 xe_oa_unit_id (struct xe_hw_engine *hwe) +{ +return hwe->oa_group && hwe->oa_group->num_engines ? + hwe->oa_group->oa_unit_id :U16_MAX ; +} +static void oa_format_add (struct xe_oa *oa,enum drm_xe_oa_format format) {__set_bit (format, oa->format_mask);
@@ -2325,6 +2331,11 @@ static struct ctl_table oa_ctl_table[] = { {} }; +int xe_oa_ioctl_version (struct xe_device *xe) +{ +return 1 ; +} +int xe_oa_sysctl_register (void ) { sysctl_header =register_sysctl ("dev/xe" , oa_ctl_table);
drivers/gpu/drm/xe/xe_oa.h +3 -0
@@ -22,4 +22,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data, struct drm_file *file);int xe_oa_remove_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +u32 xe_oa_timestamp_frequency (struct xe_device *xe); +u16 xe_oa_unit_id (struct xe_hw_engine *hwe); +#endif
drivers/gpu/drm/xe/xe_query.c +5 -1
@@ -78,7 +78,9 @@ static int query_engines(struct xe_device *xe, xe_to_user_engine_class[hwe->class]; hw_engine_info[i].engine_instance = hwe->logical_instance; - hw_engine_info[i++].gt_id = gt->info.id; + hw_engine_info[i].gt_id = gt->info.id; + hw_engine_info[i].oa_unit_id =xe_oa_unit_id (hwe); + i++; }if (copy_to_user (query_ptr, hw_engine_info, size)) {
@@ -200,6 +202,7 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)hweight_long (xe->info.mem_region_mask); config->info[XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY ] =xe_exec_queue_device_get_max_priority (xe); + config->info[XE_QUERY_OA_IOCTL_VERSION ] =xe_oa_ioctl_version (xe);if (copy_to_user (query_ptr, config, size)) {kfree (config);
@@ -241,6 +244,7 @@ static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) gts->gts[id].type =XE_QUERY_GT_TYPE_MAIN ; gts->gts[id].instance = id; gts->gts[id].clock_freq = gt->info.clock_freq; + gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (xe);if (!IS_DGFX (xe)) gts->gts[id].native_mem_regions =0x1 ;else
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 10/21] drm/xe/oa: Implement queries
Quoted 6 lines · Ashutosh Dixit
Implement queries to query OA unit ID's for HW engines, OA timestamp freq and OA ioctl version.
v2: Convert
oa_unit_idto u16 (Umesh)Signed-off-by Ashutosh Dixit <[email protected]>
I guess this will change in the next revision, so will review that.
Umesh
Quoted 81 lines
---
drivers/gpu/drm/xe/xe_oa.c | 11 +++++++++++ drivers/gpu/drm/xe/xe_oa.h | 3 +++ drivers/gpu/drm/xe/xe_query.c | 6 +++++- 3 files changed, 19 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_oa.c +11
-0@@ -2212,6 +2212,12 @@ static int xe_oa_init_engine_groups(struct xe_oa *oa)return 0 ; } +u16 xe_oa_unit_id (struct xe_hw_engine *hwe) +{ +return hwe->oa_group && hwe->oa_group->num_engines ? + hwe->oa_group->oa_unit_id :U16_MAX ; +} +static void oa_format_add (struct xe_oa *oa,enum drm_xe_oa_format format) {__set_bit (format, oa->format_mask);@@ -2325,6 +2331,11 @@ static struct ctl_table oa_ctl_table[] = { {} }; +int xe_oa_ioctl_version (struct xe_device *xe) +{ +return 1 ; +} +int xe_oa_sysctl_register (void ) { sysctl_header =register_sysctl ("dev/xe" , oa_ctl_table);drivers/gpu/drm/xe/xe_oa.h +3
-0@@ -22,4 +22,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data, struct drm_file *file);int xe_oa_remove_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +u32 xe_oa_timestamp_frequency (struct xe_device *xe); +u16 xe_oa_unit_id (struct xe_hw_engine *hwe); +#endif drivers/gpu/drm/xe/xe_query.c +5
-1@@ -78,7 +78,9 @@ static int query_engines(struct xe_device *xe, xe_to_user_engine_class[hwe->class]; hw_engine_info[i].engine_instance = hwe->logical_instance; - hw_engine_info[i++].gt_id = gt->info.id; + hw_engine_info[i].gt_id = gt->info.id; + hw_engine_info[i].oa_unit_id =xe_oa_unit_id (hwe); + i++; }if (copy_to_user (query_ptr, hw_engine_info, size)) {@@ -200,6 +202,7 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)hweight_long (xe->info.mem_region_mask); config->info[XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY ] =xe_exec_queue_device_get_max_priority (xe); + config->info[XE_QUERY_OA_IOCTL_VERSION ] =xe_oa_ioctl_version (xe);if (copy_to_user (query_ptr, config, size)) {kfree (config);@@ -241,6 +244,7 @@ static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) gts->gts[id].type =XE_QUERY_GT_TYPE_MAIN ; gts->gts[id].instance = id; gts->gts[id].clock_freq = gt->info.clock_freq; + gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (xe);if (!IS_DGFX (xe)) gts->gts[id].native_mem_regions =0x1 ;else Signature · 1 line
2.41.0
PATCH 11/21 drm/xe/oa: Override GuC RC with OA on PVC
In reply to Ashutosh DixitOn PVC, a w/a resets RCS/CCS before it goes into RC6. This breaks OA since OA does not expect engine resets during its use. Fix it by disabling RC6.
--- drivers/gpu/drm/xe/xe_guc_pc.c | 60 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_guc_pc.h | 3 ++ drivers/gpu/drm/xe/xe_oa.c | 26 +++++++++++++- drivers/gpu/drm/xe/xe_oa_types.h | 6 ++++ 4 files changed, 94 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_guc_pc.c +60 -0
@@ -225,6 +225,27 @@ static int pc_action_set_param(struct xe_guc_pc *pc, u8 id, u32 value)return ret; } +static int pc_action_unset_param (struct xe_guc_pc *pc,u8 id) +{ +struct xe_guc_ct *ct = &pc_to_guc (pc)->ct; +int ret; +u32 action[] = { +GUC_ACTION_HOST2GUC_PC_SLPC_REQUEST , +SLPC_EVENT (SLPC_EVENT_PARAMETER_UNSET ,1 ), + id, + }; + +if (wait_for_pc_state (pc,SLPC_GLOBAL_STATE_RUNNING )) +return -EAGAIN ; + + ret =xe_guc_ct_send (ct, action,ARRAY_SIZE (action),0 ,0 ); +if (ret) +drm_err (&pc_to_xe (pc)->drm,"GuC PC unset param failed: %pe" , +ERR_PTR (ret)); + +return ret; +} +static int pc_action_setup_gucrc (struct xe_guc_pc *pc,u32 mode) {struct xe_guc_ct *ct = &pc_to_guc (pc)->ct;
@@ -768,6 +789,45 @@ int xe_guc_pc_gucrc_disable(struct xe_guc_pc *pc)return ret; } +/** +* xe_guc_pc_override_gucrc_mode() - override GUCRC mode +* @pc: Xe_GuC_PC instance +* @mode: new value of the mode. +* +* Override the GUCRC mode. +* +* Return: 0 on success, negative error code on error. +*/ +int xe_guc_pc_override_gucrc_mode (struct xe_guc_pc *pc,enum slpc_gucrc_mode mode) +{ +int ret; + +xe_device_mem_access_get (pc_to_xe (pc)); + ret =pc_action_set_param (pc,SLPC_PARAM_PWRGATE_RC_MODE , mode); +xe_device_mem_access_put (pc_to_xe (pc)); + +return ret; +} + +/** +* xe_guc_pc_override_gucrc_mode() - override GUCRC mode +* @pc: Xe_GuC_PC instance +* +* Unset the GUCRC mode override +* +* Return: 0 on success, negative error code on error. +*/ +int xe_guc_pc_unset_gucrc_mode (struct xe_guc_pc *pc) +{ +int ret; + +xe_device_mem_access_get (pc_to_xe (pc)); + ret =pc_action_unset_param (pc,SLPC_PARAM_PWRGATE_RC_MODE ); +xe_device_mem_access_put (pc_to_xe (pc)); + +return ret; +} +static void pc_init_pcode_freq (struct xe_guc_pc *pc) {u32 min =DIV_ROUND_CLOSEST (pc->rpn_freq,GT_FREQUENCY_MULTIPLIER );
drivers/gpu/drm/xe/xe_guc_pc.h +3 -0
@@ -7,12 +7,15 @@#define _XE_GUC_PC_H_#include "xe_guc_pc_types.h" +#include "abi/guc_actions_slpc_abi.h" int xe_guc_pc_init (struct xe_guc_pc *pc);void xe_guc_pc_fini (struct xe_guc_pc *pc);int xe_guc_pc_start (struct xe_guc_pc *pc);int xe_guc_pc_stop (struct xe_guc_pc *pc);int xe_guc_pc_gucrc_disable (struct xe_guc_pc *pc); +int xe_guc_pc_override_gucrc_mode (struct xe_guc_pc *pc,enum slpc_gucrc_mode mode); +int xe_guc_pc_unset_gucrc_mode (struct xe_guc_pc *pc);enum xe_gt_idle_state xe_guc_pc_c_status (struct xe_guc_pc *pc);u64 xe_guc_pc_rc6_residency (struct xe_guc_pc *pc);
drivers/gpu/drm/xe/xe_oa.c +25 -1
@@ -23,6 +23,7 @@#include "xe_exec_queue.h" #include "xe_gt.h" #include "xe_gt_mcr.h" +#include "xe_guc_pc.h" #include "xe_lrc.h" #include "xe_migrate.h" #include "xe_mmio.h"
@@ -909,6 +910,10 @@ static void xe_oa_stream_destroy(struct xe_oa_stream *stream)xe_device_mem_access_put (stream->oa->xe);xe_oa_free_oa_buffer (stream); +/* Wa_1509372804:pvc: * Unset the override of GUCRC mode to enable rc6 */ +if (stream->override_gucrc) +XE_WARN_ON (xe_guc_pc_unset_gucrc_mode (>->uc.guc.pc)); +xe_oa_free_configs (stream); }
@@ -1344,9 +1349,25 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream, goto exit; } +/* +* Wa_1509372804:pvc +* +* GuC reset of engines causes OA to lose configuration +* state. Prevent this by overriding GUCRC mode. +* +*/ +if (gt->tile->xe->info.platform ==XE_PVC ) { + ret =xe_guc_pc_override_gucrc_mode (>->uc.guc.pc, +SLPC_GUCRC_MODE_GUCRC_NO_RC6 ); +if (ret) + goto err_free_configs; + + stream->override_gucrc = true; + } + ret =xe_oa_alloc_oa_buffer (stream);if (ret) - goto err_free_configs; + goto err_unset_gucrc;/* Take runtime pm ref and forcewake to disable RC6 */ xe_device_mem_access_get (stream->oa->xe);
@@ -1377,6 +1398,9 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,XE_WARN_ON (xe_force_wake_put (gt_to_fw (gt),XE_FORCEWAKE_ALL ));xe_device_mem_access_put (stream->oa->xe);xe_oa_free_oa_buffer (stream); +err_unset_gucrc: +if (stream->override_gucrc) +XE_WARN_ON (xe_guc_pc_unset_gucrc_mode (>->uc.guc.pc)); err_free_configs:xe_oa_free_configs (stream); exit:
drivers/gpu/drm/xe/xe_oa_types.h +6 -0
@@ -291,5 +291,11 @@ struct xe_oa_stream {* buffer should be checked for available data. */ u64 poll_oa_period; + +/** +* @override_gucrc: GuC RC has been overridden for the perf stream, +* and we need to restore the default configuration on release. +*/ + bool override_gucrc; };#endif
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 11/21] drm/xe/oa: Override GuC RC with OA on PVC
Quoted 4 lines · Ashutosh Dixit
On PVC, a w/a resets RCS/CCS before it goes into RC6. This breaks OA since OA does not expect engine resets during its use. Fix it by disabling RC6.
Signed-off-by Ashutosh Dixit <[email protected]>
lgtm
Quoted 184 lines
---
drivers/gpu/drm/xe/xe_guc_pc.c | 60 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_guc_pc.h | 3 ++ drivers/gpu/drm/xe/xe_oa.c | 26 +++++++++++++- drivers/gpu/drm/xe/xe_oa_types.h | 6 ++++ 4 files changed, 94 insertions(+), 1 deletion(-)drivers/gpu/drm/xe/xe_guc_pc.c +60
-0@@ -225,6 +225,27 @@ static int pc_action_set_param(struct xe_guc_pc *pc, u8 id, u32 value)return ret; } +static int pc_action_unset_param (struct xe_guc_pc *pc,u8 id) +{ +struct xe_guc_ct *ct = &pc_to_guc (pc)->ct; +int ret; +u32 action[] = { +GUC_ACTION_HOST2GUC_PC_SLPC_REQUEST , +SLPC_EVENT (SLPC_EVENT_PARAMETER_UNSET ,1 ), + id, + }; + +if (wait_for_pc_state (pc,SLPC_GLOBAL_STATE_RUNNING )) +return -EAGAIN ; + + ret =xe_guc_ct_send (ct, action,ARRAY_SIZE (action),0 ,0 ); +if (ret) +drm_err (&pc_to_xe (pc)->drm,"GuC PC unset param failed: %pe" , +ERR_PTR (ret)); + +return ret; +} +static int pc_action_setup_gucrc (struct xe_guc_pc *pc,u32 mode) {struct xe_guc_ct *ct = &pc_to_guc (pc)->ct;@@ -768,6 +789,45 @@ int xe_guc_pc_gucrc_disable(struct xe_guc_pc *pc)return ret; } +/** +* xe_guc_pc_override_gucrc_mode() - override GUCRC mode +* @pc: Xe_GuC_PC instance +* @mode: new value of the mode. +* +* Override the GUCRC mode. +* +* Return: 0 on success, negative error code on error. +*/ +int xe_guc_pc_override_gucrc_mode (struct xe_guc_pc *pc,enum slpc_gucrc_mode mode) +{ +int ret; + +xe_device_mem_access_get (pc_to_xe (pc)); + ret =pc_action_set_param (pc,SLPC_PARAM_PWRGATE_RC_MODE , mode); +xe_device_mem_access_put (pc_to_xe (pc)); + +return ret; +} + +/** +* xe_guc_pc_override_gucrc_mode() - override GUCRC mode +* @pc: Xe_GuC_PC instance +* +* Unset the GUCRC mode override +* +* Return: 0 on success, negative error code on error. +*/ +int xe_guc_pc_unset_gucrc_mode (struct xe_guc_pc *pc) +{ +int ret; + +xe_device_mem_access_get (pc_to_xe (pc)); + ret =pc_action_unset_param (pc,SLPC_PARAM_PWRGATE_RC_MODE ); +xe_device_mem_access_put (pc_to_xe (pc)); + +return ret; +} +static void pc_init_pcode_freq (struct xe_guc_pc *pc) {u32 min =DIV_ROUND_CLOSEST (pc->rpn_freq,GT_FREQUENCY_MULTIPLIER );drivers/gpu/drm/xe/xe_guc_pc.h +3
-0@@ -7,12 +7,15 @@#define _XE_GUC_PC_H_#include "xe_guc_pc_types.h" +#include "abi/guc_actions_slpc_abi.h" int xe_guc_pc_init (struct xe_guc_pc *pc);void xe_guc_pc_fini (struct xe_guc_pc *pc);int xe_guc_pc_start (struct xe_guc_pc *pc);int xe_guc_pc_stop (struct xe_guc_pc *pc);int xe_guc_pc_gucrc_disable (struct xe_guc_pc *pc); +int xe_guc_pc_override_gucrc_mode (struct xe_guc_pc *pc,enum slpc_gucrc_mode mode); +int xe_guc_pc_unset_gucrc_mode (struct xe_guc_pc *pc);enum xe_gt_idle_state xe_guc_pc_c_status (struct xe_guc_pc *pc);u64 xe_guc_pc_rc6_residency (struct xe_guc_pc *pc);drivers/gpu/drm/xe/xe_oa.c +25
-1@@ -23,6 +23,7 @@#include "xe_exec_queue.h" #include "xe_gt.h" #include "xe_gt_mcr.h" +#include "xe_guc_pc.h" #include "xe_lrc.h" #include "xe_migrate.h" #include "xe_mmio.h" @@ -909,6 +910,10 @@ static void xe_oa_stream_destroy(struct xe_oa_stream *stream)xe_device_mem_access_put (stream->oa->xe);xe_oa_free_oa_buffer (stream); +/* Wa_1509372804:pvc: * Unset the override of GUCRC mode to enable rc6 */ +if (stream->override_gucrc) +XE_WARN_ON (xe_guc_pc_unset_gucrc_mode (>->uc.guc.pc)); +xe_oa_free_configs (stream); }@@ -1344,9 +1349,25 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream, goto exit; } +/* +* Wa_1509372804:pvc +* +* GuC reset of engines causes OA to lose configuration +* state. Prevent this by overriding GUCRC mode. +* +*/ +if (gt->tile->xe->info.platform ==XE_PVC ) { + ret =xe_guc_pc_override_gucrc_mode (>->uc.guc.pc, +SLPC_GUCRC_MODE_GUCRC_NO_RC6 ); +if (ret) + goto err_free_configs; + + stream->override_gucrc = true; + } + ret =xe_oa_alloc_oa_buffer (stream);if (ret) - goto err_free_configs; + goto err_unset_gucrc;/* Take runtime pm ref and forcewake to disable RC6 */ xe_device_mem_access_get (stream->oa->xe);@@ -1377,6 +1398,9 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,XE_WARN_ON (xe_force_wake_put (gt_to_fw (gt),XE_FORCEWAKE_ALL ));xe_device_mem_access_put (stream->oa->xe);xe_oa_free_oa_buffer (stream); +err_unset_gucrc: +if (stream->override_gucrc) +XE_WARN_ON (xe_guc_pc_unset_gucrc_mode (>->uc.guc.pc));
err_free_configs:xe_oa_free_configs(stream);exit:
drivers/gpu/drm/xe/xe_oa_types.h +6
-0@@ -291,5 +291,11 @@ struct xe_oa_stream {* buffer should be checked for available data. */ u64 poll_oa_period; + +/** +* @override_gucrc: GuC RC has been overridden for the perf stream, +* and we need to restore the default configuration on release. +*/ + bool override_gucrc; };#endif Signature · 1 line
2.41.0
PATCH 12/21 drm/xe/uapi: "Perf" layer to support multiple perf counter stream types
In reply to Ashutosh DixitIn XE, the plan is to support multiple types of perf counter streams (OA is only one type of these streams). This requires addition of a PERF layer to multiplex these different stream types through a single set of PERF ioctl's.
--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 8 +++--- drivers/gpu/drm/xe/xe_oa.c | 43 +++++++++++++++++----------- drivers/gpu/drm/xe/xe_perf.c | 52 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_perf.h | 18 ++++++++++++ include/uapi/drm/xe_drm.h | 44 +++++++++++++++++++--------- 6 files changed, 133 insertions(+), 33 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_perf.c create mode 100644 drivers/gpu/drm/xe/xe_perf.h
drivers/gpu/drm/xe/Makefile +1 -0
@@ -88,6 +88,7 @@ xe-y += xe_bb.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \ + xe_perf.o \ xe_pm.o \ xe_preempt_fence.o \ xe_pt.o \
drivers/gpu/drm/xe/xe_device.c +4 -4
@@ -25,8 +25,8 @@#include "xe_irq.h" #include "xe_mmio.h" #include "xe_module.h" -#include "xe_oa.h" #include "xe_pcode.h" +#include "xe_perf.h" #include "xe_pm.h" #include "xe_query.h" #include "xe_tile.h"
@@ -115,9 +115,9 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE , xe_vm_madvise_ioctl,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_OA_OPEN , xe_oa_stream_open_ioctl,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_OA_ADD_CONFIG , xe_oa_add_config_ioctl,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_OA_REMOVE_CONFIG, xe_oa_remove_config_ioctl, DRM_RENDER_ALLOW), +DRM_IOCTL_DEF_DRV (XE_PERF_OPEN , xe_perf_open_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG , xe_perf_add_config_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), };
drivers/gpu/drm/xe/xe_oa.c +27 -16
115 lines not on this page · raw message
drivers/gpu/drm/xe/xe_perf.c new file +52 -0
52 lines not on this page · raw message
drivers/gpu/drm/xe/xe_perf.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2023 Intel Corporation +*/ + +#ifndef _XE_PERF_H_ +#define _XE_PERF_H_ + +#include <drm/xe_drm.h> + +struct drm_device ; +struct drm_file ; + +int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int xe_perf_add_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int xe_perf_remove_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); + +#endif
include/uapi/drm/xe_drm.h +31 -13
76 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 12/21] drm/xe/uapi: "Perf" layer to support multiple perf counter stream types
Quoted 199 lines · Ashutosh Dixit
In XE, the plan is to support multiple types of perf counter streams (OA is only one type of these streams). This requires addition of a PERF layer to multiplex these different stream types through a single set of PERF ioctl's.
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 8 +++--- drivers/gpu/drm/xe/xe_oa.c | 43 +++++++++++++++++----------- drivers/gpu/drm/xe/xe_perf.c | 52 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_perf.h | 18 ++++++++++++ include/uapi/drm/xe_drm.h | 44 +++++++++++++++++++--------- 6 files changed, 133 insertions(+), 33 deletions(-)create mode 100644
drivers/gpu/drm/xe/xe_perf.c
create mode 100644drivers/gpu/drm/xe/xe_perf.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -88,6 +88,7 @@ xe-y += xe_bb.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \ + xe_perf.o \ xe_pm.o \ xe_preempt_fence.o \ xe_pt.o \drivers/gpu/drm/xe/xe_device.c +4
-4@@ -25,8 +25,8 @@#include "xe_irq.h" #include "xe_mmio.h" #include "xe_module.h" -#include "xe_oa.h" #include "xe_pcode.h" +#include "xe_perf.h" #include "xe_pm.h" #include "xe_query.h" #include "xe_tile.h" @@ -115,9 +115,9 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE , xe_vm_madvise_ioctl,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_OA_OPEN , xe_oa_stream_open_ioctl,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_OA_ADD_CONFIG , xe_oa_add_config_ioctl,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_OA_REMOVE_CONFIG, xe_oa_remove_config_ioctl, DRM_RENDER_ALLOW), +DRM_IOCTL_DEF_DRV (XE_PERF_OPEN , xe_perf_open_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG , xe_perf_add_config_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), };drivers/gpu/drm/xe/xe_oa.c +27
-16@@ -1173,13 +1173,13 @@ static long xe_oa_ioctl_locked(struct xe_oa_stream *stream, unsigned long arg) {switch (cmd) { -case XE_OA_IOCTL_ENABLE : +case XE_PERF_IOCTL_ENABLE :xe_oa_enable_locked (stream);return 0 ; -case XE_OA_IOCTL_DISABLE : +case XE_PERF_IOCTL_DISABLE :xe_oa_disable_locked (stream);return 0 ; -case XE_OA_IOCTL_CONFIG : +case XE_PERF_IOCTL_CONFIG :return xe_oa_config_locked (stream, arg); }@@ -1692,12 +1692,11 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops,return 0 ; } -int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data, -struct drm_file *file) +int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct xe_oa *oa = &to_xe_device (dev)->oa; -struct drm_xe_oa_open_param *param = data;struct xe_oa_open_properties props = {}; +struct drm_xe_oa_open_param param;u32 known_open_flags;struct xe_gt *gt;int ret;@@ -1707,14 +1706,18 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data,return -ENODEV ; } + ret =__copy_from_user (¶m, data,sizeof (param)); +if (XE_IOCTL_DBG (oa->xe, ret)) +return -EFAULT ; + known_open_flags =XE_OA_FLAG_FD_CLOEXEC |XE_OA_FLAG_FD_NONBLOCK |XE_OA_FLAG_DISABLED ; -if (param->flags & ~known_open_flags) { +if (param.flags & ~known_open_flags) {drm_dbg (&oa->xe->drm,"Unknown drm_xe_oa_open_param flag\n" );return -EINVAL ; } - ret =xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param->properties_ptr), - param->num_properties, + ret =xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param.properties_ptr), + param.num_properties, &props);if (ret)return ret;@@ -1722,7 +1725,7 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data, gt = props.hwe->gt;mutex_lock (>->oa.lock); - ret =xe_oa_stream_open_ioctl_locked (oa, param, &props, file); + ret =xe_oa_stream_open_ioctl_locked (oa, ¶m, &props, file);mutex_unlock (>->oa.lock);return ret;@@ -1918,7 +1921,8 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data, struct drm_file *file) {struct xe_oa *oa = &to_xe_device (dev)->oa; -struct drm_xe_oa_config *arg = data; +struct drm_xe_oa_config param; +struct drm_xe_oa_config *arg = ¶m;struct xe_oa_config *oa_config, *tmp;struct xe_oa_reg *regs;int err, id;@@ -1933,6 +1937,10 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,return -EACCES ; } + err =__copy_from_user (¶m, data,sizeof (param)); +if (XE_IOCTL_DBG (oa->xe, err)) +return -EFAULT ; +if ((!arg->mux_regs_ptr || !arg->n_mux_regs) && (!arg->boolean_regs_ptr || !arg->n_boolean_regs) && (!arg->flex_regs_ptr || !arg->n_flex_regs)) {@@ -2035,7 +2043,7 @@ int xe_oa_remove_config_ioctl(struct drm_device *dev, void *data, {struct xe_oa *oa = &to_xe_device (dev)->oa;struct xe_oa_config *oa_config; -u64 *arg = data; +u64 arg, *ptr = data;int ret;if (!oa->xe) {@@ -2048,22 +2056,25 @@ int xe_oa_remove_config_ioctl(struct drm_device *dev, void *data,return -EACCES ; } + ret =get_user (arg, ptr); +if (XE_IOCTL_DBG (oa->xe, ret)) +return ret; + ret =mutex_lock_interruptible (&oa->metrics_lock);if (ret)return ret; - oa_config =idr_find (&oa->metrics_idr, *arg); + oa_config =idr_find (&oa->metrics_idr, arg);if (!oa_config) {drm_dbg (&oa->xe->drm,"Failed to remove unknown OA config\n" ); ret = -ENOENT ; goto err_unlock; } -WARN_ON (*arg != oa_config->id); +WARN_ON (arg != oa_config->id);sysfs_remove_group (oa->metrics_kobj, &oa_config->sysfs_metric); - -idr_remove (&oa->metrics_idr, *arg); +idr_remove (&oa->metrics_idr, arg);mutex_unlock (&oa->metrics_lock);drivers/gpu/drm/xe/xe_perf.c new file +10
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2023 Intel Corporation +*/ + +#include "xe_oa.h" +#include "xe_perf.h" + +int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +{
drivers/gpu/drm/xe/xe_perf.c line 20
Quoted 10 lines
drivers/gpu/drm/xe/xe_perf.c new file +10
-0+struct drm_xe_perf_param *arg = data; + +if (arg->extensions) +return -EINVAL ; + +switch (arg->perf_type) { +case XE_PERF_TYPE_OA : +return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file); +default : +return -EINVAL ;
Wondering if a different unique error must be returned to indicate that a particular perf module is not supported. Other than that, this lgtm,
Umesh
Re: [Intel-xe] [PATCH 12/21] drm/xe/uapi: "Perf" layer to support multiple perf counter stream types
Quoted 206 lines · Umesh Nerlige Ramappa
Quoted 204 lines · Ashutosh Dixit
In XE, the plan is to support multiple types of perf counter streams (OA is only one type of these streams). This requires addition of a PERF layer to multiplex these different stream types through a single set of PERF ioctl's.
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.c | 8 +++--- drivers/gpu/drm/xe/xe_oa.c | 43 +++++++++++++++++----------- drivers/gpu/drm/xe/xe_perf.c | 52 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_perf.h | 18 ++++++++++++ include/uapi/drm/xe_drm.h | 44 +++++++++++++++++++--------- 6 files changed, 133 insertions(+), 33 deletions(-)create mode 100644
drivers/gpu/drm/xe/xe_perf.c
create mode 100644drivers/gpu/drm/xe/xe_perf.hdrivers/gpu/drm/xe/Makefile +1
-0@@ -88,6 +88,7 @@ xe-y += xe_bb.o \ xe_pat.o \ xe_pci.o \ xe_pcode.o \ + xe_perf.o \ xe_pm.o \ xe_preempt_fence.o \ xe_pt.o \drivers/gpu/drm/xe/xe_device.c +4
-4@@ -25,8 +25,8 @@#include "xe_irq.h" #include "xe_mmio.h" #include "xe_module.h" -#include "xe_oa.h" #include "xe_pcode.h" +#include "xe_perf.h" #include "xe_pm.h" #include "xe_query.h" #include "xe_tile.h" @@ -115,9 +115,9 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE , xe_vm_madvise_ioctl,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_OA_OPEN , xe_oa_stream_open_ioctl,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_OA_ADD_CONFIG , xe_oa_add_config_ioctl,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_OA_REMOVE_CONFIG, xe_oa_remove_config_ioctl, DRM_RENDER_ALLOW), +DRM_IOCTL_DEF_DRV (XE_PERF_OPEN , xe_perf_open_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG , xe_perf_add_config_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), };drivers/gpu/drm/xe/xe_oa.c +27
-16@@ -1173,13 +1173,13 @@ static long xe_oa_ioctl_locked(struct xe_oa_stream *stream, unsigned long arg) {switch (cmd) { -case XE_OA_IOCTL_ENABLE : +case XE_PERF_IOCTL_ENABLE :xe_oa_enable_locked (stream);return 0 ; -case XE_OA_IOCTL_DISABLE : +case XE_PERF_IOCTL_DISABLE :xe_oa_disable_locked (stream);return 0 ; -case XE_OA_IOCTL_CONFIG : +case XE_PERF_IOCTL_CONFIG :return xe_oa_config_locked (stream, arg); }@@ -1692,12 +1692,11 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops,return 0 ; } -int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data, -struct drm_file *file) +int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct xe_oa *oa = &to_xe_device (dev)->oa; -struct drm_xe_oa_open_param *param = data;struct xe_oa_open_properties props = {}; +struct drm_xe_oa_open_param param;u32 known_open_flags;struct xe_gt *gt;int ret;@@ -1707,14 +1706,18 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data,return -ENODEV ; } + ret =__copy_from_user (¶m, data,sizeof (param)); +if (XE_IOCTL_DBG (oa->xe, ret)) +return -EFAULT ; + known_open_flags =XE_OA_FLAG_FD_CLOEXEC |XE_OA_FLAG_FD_NONBLOCK |XE_OA_FLAG_DISABLED ; -if (param->flags & ~known_open_flags) { +if (param.flags & ~known_open_flags) {drm_dbg (&oa->xe->drm,"Unknown drm_xe_oa_open_param flag\n" );return -EINVAL ; } - ret =xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param->properties_ptr), - param->num_properties, + ret =xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param.properties_ptr), + param.num_properties, &props);if (ret)return ret;@@ -1722,7 +1725,7 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data, gt = props.hwe->gt;mutex_lock (>->oa.lock); - ret =xe_oa_stream_open_ioctl_locked (oa, param, &props, file); + ret =xe_oa_stream_open_ioctl_locked (oa, ¶m, &props, file);mutex_unlock (>->oa.lock);return ret;@@ -1918,7 +1921,8 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data, struct drm_file *file) {struct xe_oa *oa = &to_xe_device (dev)->oa; -struct drm_xe_oa_config *arg = data; +struct drm_xe_oa_config param; +struct drm_xe_oa_config *arg = ¶m;struct xe_oa_config *oa_config, *tmp;struct xe_oa_reg *regs;int err, id;@@ -1933,6 +1937,10 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,return -EACCES ; } + err =__copy_from_user (¶m, data,sizeof (param)); +if (XE_IOCTL_DBG (oa->xe, err)) +return -EFAULT ; +if ((!arg->mux_regs_ptr || !arg->n_mux_regs) && (!arg->boolean_regs_ptr || !arg->n_boolean_regs) && (!arg->flex_regs_ptr || !arg->n_flex_regs)) {@@ -2035,7 +2043,7 @@ int xe_oa_remove_config_ioctl(struct drm_device *dev, void *data, {struct xe_oa *oa = &to_xe_device (dev)->oa;struct xe_oa_config *oa_config; -u64 *arg = data; +u64 arg, *ptr = data;int ret;if (!oa->xe) {@@ -2048,22 +2056,25 @@ int xe_oa_remove_config_ioctl(struct drm_device *dev, void *data,return -EACCES ; } + ret =get_user (arg, ptr); +if (XE_IOCTL_DBG (oa->xe, ret)) +return ret; + ret =mutex_lock_interruptible (&oa->metrics_lock);if (ret)return ret; - oa_config =idr_find (&oa->metrics_idr, *arg); + oa_config =idr_find (&oa->metrics_idr, arg);if (!oa_config) {drm_dbg (&oa->xe->drm,"Failed to remove unknown OA config\n" ); ret = -ENOENT ; goto err_unlock; } -WARN_ON (*arg != oa_config->id); +WARN_ON (arg != oa_config->id);sysfs_remove_group (oa->metrics_kobj, &oa_config->sysfs_metric); - -idr_remove (&oa->metrics_idr, *arg); +idr_remove (&oa->metrics_idr, arg);mutex_unlock (&oa->metrics_lock);drivers/gpu/drm/xe/xe_perf.c new file +15
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright © 2023 Intel Corporation +*/ + +#include "xe_oa.h" +#include "xe_perf.h" + +int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +{ +struct drm_xe_perf_param *arg = data; + +if (arg->extensions) +return -EINVAL ; +
Quoted 8 lines
drivers/gpu/drm/xe/xe_perf.c line 20
Quoted 5 lines
drivers/gpu/drm/xe/xe_perf.c new file +5
-0+switch (arg->perf_type) { +case XE_PERF_TYPE_OA : +return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file); +default : +return -EINVAL ;Wondering if a different unique error must be returned to indicate that a particular perf module is not supported. Other than that, this lgtm,
Somthing weird like ECONNABORTED? If ops are included here probably EOPNOSUPP would also work. Probably doesn't matter much. Maybe I will change to EOPNOSUPP for now.
Quoted 1 line
Reviewed-by Umesh Nerlige Ramappa <[email protected]>
Thanks.
--
Ashutosh
PATCH 13/21 drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl
In reply to Ashutosh DixitSince we are already mulitplexing multiple perf counter stream types through the PERF layer, it seems odd to retain separate ioctls for perf op's (add/remove config). In fact it seems logical to also multiplex these ops through a single PERF ioctl. This also affords greater flexibility to add stream specific ops if needed for different perf stream types.
--- drivers/gpu/drm/xe/xe_device.c | 5 +---- drivers/gpu/drm/xe/xe_perf.c | 32 ++++++++------------------------ drivers/gpu/drm/xe/xe_perf.h | 4 +--- include/uapi/drm/xe_drm.h | 16 ++++++++++------ 4 files changed, 20 insertions(+), 37 deletions(-)
drivers/gpu/drm/xe/xe_device.c +1 -4
@@ -115,10 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE ,xe_vm_madvise_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_OPEN ,xe_perf_open_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG ,xe_perf_add_config_ioctl ,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), - + DRM_IOCTL_DEF_DRV(XE_PERF, xe_perf_ioctl, DRM_RENDER_ALLOW), };static const struct file_operations xe_driver_fops = {
drivers/gpu/drm/xe/xe_perf.c +8 -24
@@ -6,37 +6,21 @@#include "xe_oa.h" #include "xe_perf.h" -int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +int xe_oa_ioctl (struct drm_device *dev,struct drm_xe_perf_param *arg,struct drm_file *file) { -struct drm_xe_perf_param *arg = data; - -if (arg->extensions) -return -EINVAL ; - -switch (arg->perf_type) { -case XE_PERF_TYPE_OA : +switch (arg->perf_op) { +case XE_PERF_STREAM_OPEN :return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file); -default : -return -EINVAL ; - } -} - -int xe_perf_add_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file) -{ -struct drm_xe_perf_param *arg = data; - -if (arg->extensions) -return -EINVAL ; - -switch (arg->perf_type) { -case XE_PERF_TYPE_OA : +case XE_PERF_ADD_CONFIG :return xe_oa_add_config_ioctl (dev, (void *)arg->param, file); +case XE_PERF_REMOVE_CONFIG : +return xe_oa_remove_config_ioctl (dev, (void *)arg->param, file);default :return -EINVAL ; } } -int xe_perf_remove_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +int xe_perf_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct drm_xe_perf_param *arg = data;
@@ -45,7 +29,7 @@ int xe_perf_remove_config_ioctl(struct drm_device *dev, void *data, struct drm_fswitch (arg->perf_type) {case XE_PERF_TYPE_OA : -return xe_oa_remove_config_ioctl (dev, (void *)arg->param, file); +return xe_oa_ioctl (dev, arg, file);default :return -EINVAL ; }
drivers/gpu/drm/xe/xe_perf.h +1 -3
@@ -11,8 +11,6 @@struct drm_device ;struct drm_file ; -int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file); -int xe_perf_add_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); -int xe_perf_remove_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int xe_perf_ioctl (struct drm_device *dev,void *data,struct drm_file *file);#endif
include/uapi/drm/xe_drm.h +10 -6
@@ -111,9 +111,7 @@ struct xe_user_extension {#define DRM_XE_WAIT_USER_FENCE 0x0b#define DRM_XE_VM_MADVISE 0x0c#define DRM_XE_EXEC_QUEUE_GET_PROPERTY 0x0d -#define DRM_XE_PERF_OPEN 0x16 -#define DRM_XE_PERF_ADD_CONFIG 0x17 -#define DRM_XE_PERF_REMOVE_CONFIG 0x18 +#define DRM_XE_PERF 0x16/* Must be kept compact -- no holes */ #define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query)
@@ -130,9 +128,7 @@ struct xe_user_extension {#define DRM_IOCTL_XE_EXEC_QUEUE_SET_PROPERTY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_SET_PROPERTY, struct drm_xe_exec_queue_set_property)#define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)#define DRM_IOCTL_XE_VM_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_MADVISE, struct drm_xe_vm_madvise) -#define DRM_IOCTL_XE_PERF_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF_OPEN, struct drm_xe_perf_param) -#define DRM_IOCTL_XE_PERF_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF_ADD_CONFIG, struct drm_xe_perf_param) -#define DRM_IOCTL_XE_PERF_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF_REMOVE_CONFIG, struct drm_xe_perf_param) +#define DRM_IOCTL_XE_PERF DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF, struct drm_xe_perf_param)/** * enum drm_xe_memory_class - Supported memory classes.
@@ -1104,6 +1100,12 @@ enum drm_xe_perf_type { XE_PERF_TYPE_OA, }; +enum drm_xe_perf_op { +XE_PERF_STREAM_OPEN , +XE_PERF_ADD_CONFIG , +XE_PERF_REMOVE_CONFIG , +}; +/** * struct drm_xe_perf_param - XE perf layer param *
@@ -1116,6 +1118,8 @@ struct drm_xe_perf_param {__u64 extensions;/** @perf_type: Type, of enum drm_xe_perf_type, of perf stream */ __u64 perf_type; +/** @perf_op: Perf op, of enum drm_xe_perf_op */ +__u64 perf_op;/** @param: Pointer to actual stream params */ __u64 param; };
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 13/21] drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl
Quoted 41 lines · Ashutosh Dixit
Since we are already mulitplexing multiple perf counter stream types through the PERF layer, it seems odd to retain separate ioctls for perf op's (add/remove config). In fact it seems logical to also multiplex these ops through a single PERF ioctl. This also affords greater flexibility to add stream specific ops if needed for different perf stream types.
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 +---- drivers/gpu/drm/xe/xe_perf.c | 32 ++++++++------------------------ drivers/gpu/drm/xe/xe_perf.h | 4 +--- include/uapi/drm/xe_drm.h | 16 ++++++++++------ 4 files changed, 20 insertions(+), 37 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-4@@ -115,10 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE ,xe_vm_madvise_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_OPEN ,xe_perf_open_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG ,xe_perf_add_config_ioctl ,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), - + DRM_IOCTL_DEF_DRV(XE_PERF, xe_perf_ioctl, DRM_RENDER_ALLOW), };static const struct file_operations xe_driver_fops = {drivers/gpu/drm/xe/xe_perf.c +1
-1@@ -6,37 +6,21 @@#include "xe_oa.h" #include "xe_perf.h" -int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +int xe_oa_ioctl (struct drm_device *dev,struct drm_xe_perf_param *arg,struct drm_file *file) {
drivers/gpu/drm/xe/xe_perf.c line 13
Quoted 10 lines
drivers/gpu/drm/xe/xe_perf.c +2
-7-struct drm_xe_perf_param *arg = data; - -if (arg->extensions) -return -EINVAL ; - -switch (arg->perf_type) { -case XE_PERF_TYPE_OA : +switch (arg->perf_op) { +case XE_PERF_STREAM_OPEN :return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file);
It's a nice idea to reduce the ioctls, but if your struct drm_xe_perf_param *arg is overloaded based on the PERF_OP passed, then I would recommend validating that the right arg is passed for the corresponding OP. Ideally I wouldn't go that route since that would require some sort of signature in the arg which would identify it as the correct param. Instead I would be okay with retaining separate ioctls for the 3 operations.
Umesh
Re: [Intel-xe] [PATCH 13/21] drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 48 lines · Ashutosh Dixit
Quoted 47 lines
Since we are already mulitplexing multiple perf counter stream types through the PERF layer, it seems odd to retain separate ioctls for perf op's (add/remove config). In fact it seems logical to also multiplex these ops through a single PERF ioctl. This also affords greater flexibility to add stream specific ops if needed for different perf stream types.
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 +---- drivers/gpu/drm/xe/xe_perf.c | 32 ++++++++------------------------ drivers/gpu/drm/xe/xe_perf.h | 4 +--- include/uapi/drm/xe_drm.h | 16 ++++++++++------ 4 files changed, 20 insertions(+), 37 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-4@@ -115,10 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE ,xe_vm_madvise_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_OPEN ,xe_perf_open_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG ,xe_perf_add_config_ioctl ,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), - + DRM_IOCTL_DEF_DRV(XE_PERF, xe_perf_ioctl, DRM_RENDER_ALLOW), };static const struct file_operations xe_driver_fops = {drivers/gpu/drm/xe/xe_perf.c +1
-7@@ -6,37 +6,21 @@#include "xe_oa.h" #include "xe_perf.h" -int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +int xe_oa_ioctl (struct drm_device *dev,struct drm_xe_perf_param *arg,struct drm_file *file) { -struct drm_xe_perf_param *arg = data; - -if (arg->extensions) -return -EINVAL ; - -switch (arg->perf_type) {
Quoted 8 lines
drivers/gpu/drm/xe/xe_perf.c line 13
Quoted 4 lines
drivers/gpu/drm/xe/xe_perf.c +2
-1-case XE_PERF_TYPE_OA : +switch (arg->perf_op) { +case XE_PERF_STREAM_OPEN :return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file);It's a nice idea to reduce the ioctls, but if your struct
drm_xe_perf_param*arg is overloaded based on thePERF_OPpassed, then I would recommend validating that the right arg is passed for the corresponding OP.
I am not following what you mean here: which right arg for which OP?
The PERF layer only demultiplexes based on perf_type (say OA/XYZ etc.). The perf_op belongs to the perf_type layer (say OA), not the PERF layer. It is the job of the perf_type layer (OA) to validate the perf_op, not the job of the PERF layer. It is just convenient to include the perf_op as part of 'struct drm_xe_perf_param' (rather than inventing yet another layer there). See the function xe_perf_ioctl() in the patch.
The xe_oa_ioctl function above could possibly be moved into xe_oa.c. I just left it in xe_perf.c since it didn't seem to matter much. But I am open to doing that.
Quoted 4 lines
Ideally I wouldn't go that route since that would require some sort of signature in the arg which would identify it as the correct param. Instead I would be okay with retaining separate ioctls for the 3 operations.
If we were not doing this multiplexing based on perf_type (as in i915) we could have separate ioctl's for each operation. But since here we have anyway introduced a multiplxing layer, to me it makes no sense to have separate operation ioctl's (only disadvantags and no advantages). (Note that the multiplexing layer implies a (non-obvious) additional copy_from_user per operation visible in the previous "drm/xe/uapi: "Perf" layer to support multiple perf counter stream types" patch).
Also we cannot assume that a future stream type will only have 3 operations as i915 OA did. The OPEN/ADD_CONFIG/CLOSE are really OA specific operations. But it appears other potential perf_type's will also be able to use them, at least initially that is why they are left defined as PERF_OP's (rather than OA_OP's) in xe_drm.h. New stream types are free to introduce new ops in this design.
So retaining the ops inside a single PERF ioctl eliminates the need for introducing a new ioctl each time a stream type introduces a new OP.
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 13/21] drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl
Quoted 72 lines · Ashutosh
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 48 lines · Ashutosh Dixit
Quoted 47 lines
Since we are already mulitplexing multiple perf counter stream types through the PERF layer, it seems odd to retain separate ioctls for perf op's (add/remove config). In fact it seems logical to also multiplex these ops through a single PERF ioctl. This also affords greater flexibility to add stream specific ops if needed for different perf stream types.
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 +---- drivers/gpu/drm/xe/xe_perf.c | 32 ++++++++------------------------ drivers/gpu/drm/xe/xe_perf.h | 4 +--- include/uapi/drm/xe_drm.h | 16 ++++++++++------ 4 files changed, 20 insertions(+), 37 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-4@@ -115,10 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE ,xe_vm_madvise_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_OPEN ,xe_perf_open_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG ,xe_perf_add_config_ioctl ,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), - + DRM_IOCTL_DEF_DRV(XE_PERF, xe_perf_ioctl, DRM_RENDER_ALLOW), };static const struct file_operations xe_driver_fops = {drivers/gpu/drm/xe/xe_perf.c +1
-7@@ -6,37 +6,21 @@#include "xe_oa.h" #include "xe_perf.h" -int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +int xe_oa_ioctl (struct drm_device *dev,struct drm_xe_perf_param *arg,struct drm_file *file) { -struct drm_xe_perf_param *arg = data; - -if (arg->extensions) -return -EINVAL ; - -switch (arg->perf_type) {Quoted 8 lines
drivers/gpu/drm/xe/xe_perf.c line 13
Quoted 4 lines
drivers/gpu/drm/xe/xe_perf.c +2
-1-case XE_PERF_TYPE_OA : +switch (arg->perf_op) { +case XE_PERF_STREAM_OPEN :return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file);It's a nice idea to reduce the ioctls, but if your struct
drm_xe_perf_param*arg is overloaded based on thePERF_OPpassed, then I would recommend validating that the right arg is passed for the corresponding OP.I am not following what you mean here: which right arg for which OP?
The PERF layer only demultiplexes based on
perf_type(say OA/XYZ etc.). Theperf_opbelongs to theperf_typelayer (say OA), not the PERF layer. It is the job of theperf_typelayer (OA) to validate theperf_op, not the job of the PERF layer. It is just convenient to include theperf_opas part of 'structdrm_xe_perf_param' (rather than inventing yet another layer there). See the functionxe_perf_ioctl()in the patch.
Quoted 3 lines
The
xe_oa_ioctlfunction above could possibly be moved intoxe_oa.c. I just left it inxe_perf.csince it didn't seem to matter much. But I am open to doing that.
OK, I think I figured out the right way to visualize this. It's as follows. Let's say we have a an OA stream inside the PERF layer. So what we have is:
struct drm_xe_perf_param {
perf_type;
struct oa {
oa_op;
struct oa_op_params {
...
}
}
}So basically I have eliminated 'struct oa' and merged into 'struct drm_xe_perf_param'. But oa_op still belongs to the OA layer, not the PERF layer. So the oa layer handles the oa_op not the PERF layer.
Quoted 5 lines
Quoted 4 lines
Ideally I wouldn't go that route since that would require some sort of signature in the arg which would identify it as the correct param. Instead I would be okay with retaining separate ioctls for the 3 operations.
Quoted 7 lines
If we were not doing this multiplexing based on
perf_type(as in i915) we could have separate ioctl's for each operation. But since here we have anyway introduced a multiplxing layer, to me it makes no sense to have separate operation ioctl's (only disadvantags and no advantages). (Note that the multiplexing layer implies a (non-obvious) additionalcopy_from_userper operation visible in the previous "drm/xe/uapi: "Perf" layer to support multiple perf counter stream types" patch).
The drm layer does a copy_from_user for the first layer but any second layer structs need to be copy_from_user'd by the driver.
Quoted 10 lines
Also we cannot assume that a future stream type will only have 3 operations as i915 OA did. The OPEN/ADD_CONFIG/CLOSE are really OA specific operations. But it appears other potential perf_type's will also be able to use them, at least initially that is why they are left defined as PERF_OP's (rather than OA_OP's) in
xe_drm.h. New stream types are free to introduce new ops in this design.So retaining the ops inside a single PERF ioctl eliminates the need for introducing a new ioctl each time a stream type introduces a new OP.
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 13/21] drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl
Quoted 110 lines · Ashutosh
Quoted 72 lines · Ashutosh
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 48 lines · Ashutosh Dixit
Quoted 47 lines
Since we are already mulitplexing multiple perf counter stream types through the PERF layer, it seems odd to retain separate ioctls for perf op's (add/remove config). In fact it seems logical to also multiplex these ops through a single PERF ioctl. This also affords greater flexibility to add stream specific ops if needed for different perf stream types.
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 +---- drivers/gpu/drm/xe/xe_perf.c | 32 ++++++++------------------------ drivers/gpu/drm/xe/xe_perf.h | 4 +--- include/uapi/drm/xe_drm.h | 16 ++++++++++------ 4 files changed, 20 insertions(+), 37 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-4@@ -115,10 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE ,xe_vm_madvise_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_OPEN ,xe_perf_open_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG ,xe_perf_add_config_ioctl ,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), - + DRM_IOCTL_DEF_DRV(XE_PERF, xe_perf_ioctl, DRM_RENDER_ALLOW), };static const struct file_operations xe_driver_fops = {drivers/gpu/drm/xe/xe_perf.c +1
-7@@ -6,37 +6,21 @@#include "xe_oa.h" #include "xe_perf.h" -int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +int xe_oa_ioctl (struct drm_device *dev,struct drm_xe_perf_param *arg,struct drm_file *file) { -struct drm_xe_perf_param *arg = data; - -if (arg->extensions) -return -EINVAL ; - -switch (arg->perf_type) {Quoted 8 lines
drivers/gpu/drm/xe/xe_perf.c line 13
Quoted 4 lines
drivers/gpu/drm/xe/xe_perf.c +2
-1-case XE_PERF_TYPE_OA : +switch (arg->perf_op) { +case XE_PERF_STREAM_OPEN :return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file);It's a nice idea to reduce the ioctls, but if your struct
drm_xe_perf_param*arg is overloaded based on thePERF_OPpassed, then I would recommend validating that the right arg is passed for the corresponding OP.I am not following what you mean here: which right arg for which OP?
The PERF layer only demultiplexes based on
perf_type(say OA/XYZ etc.). Theperf_opbelongs to theperf_typelayer (say OA), not the PERF layer. It is the job of theperf_typelayer (OA) to validate theperf_op, not the job of the PERF layer. It is just convenient to include theperf_opas part of 'structdrm_xe_perf_param' (rather than inventing yet another layer there). See the functionxe_perf_ioctl()in the patch.Quoted 3 lines
The
xe_oa_ioctlfunction above could possibly be moved intoxe_oa.c. I just left it inxe_perf.csince it didn't seem to matter much. But I am open to doing that.OK, I think I figured out the right way to visualize this. It's as follows. Let's say we have a an OA stream inside the PERF layer. So what we have is:
struct drm_xe_perf_param { perf_type; struct oa { oa_op; struct oa_op_params { ... } } }So basically I have eliminated 'struct oa' and merged into 'struct
drm_xe_perf_param'. Butoa_opstill belongs to the OA layer, not the PERF layer. So the oa layer handles theoa_opnot the PERF layer.Quoted 5 lines
Quoted 4 lines
Ideally I wouldn't go that route since that would require some sort of signature in the arg which would identify it as the correct param. Instead I would be okay with retaining separate ioctls for the 3 operations.
Quoted 7 lines
If we were not doing this multiplexing based on
perf_type(as in i915) we could have separate ioctl's for each operation. But since here we have anyway introduced a multiplxing layer, to me it makes no sense to have separate operation ioctl's (only disadvantags and no advantages). (Note that the multiplexing layer implies a (non-obvious) additionalcopy_from_userper operation visible in the previous "drm/xe/uapi: "Perf" layer to support multiple perf counter stream types" patch).
Quoted 13 lines
The drm layer does a
copy_from_userfor the first layer but any second layer structs need to be copy_from_user'd by the driver.Quoted 10 lines
Also we cannot assume that a future stream type will only have 3 operations as i915 OA did. The OPEN/ADD_CONFIG/CLOSE are really OA specific operations. But it appears other potential perf_type's will also be able to use them, at least initially that is why they are left defined as PERF_OP's (rather than OA_OP's) in
xe_drm.h. New stream types are free to introduce new ops in this design.So retaining the ops inside a single PERF ioctl eliminates the need for introducing a new ioctl each time a stream type introduces a new OP.
I think I misunderstood. This is fine as long as the underlying layer is able to validate the arguments.
Thanks,
Umesh
Quoted 4 lines
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 13/21] drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl
Quoted 92 lines · Umesh Nerlige Ramappa
Quoted 90 lines · Ashutosh
Quoted 69 lines · Ashutosh
Quoted 49 lines · Umesh Nerlige Ramappa
Quoted 47 lines · Ashutosh Dixit
Since we are already mulitplexing multiple perf counter stream types through the PERF layer, it seems odd to retain separate ioctls for perf op's (add/remove config). In fact it seems logical to also multiplex these ops through a single PERF ioctl. This also affords greater flexibility to add stream specific ops if needed for different perf stream types.
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_device.c | 5 +---- drivers/gpu/drm/xe/xe_perf.c | 32 ++++++++------------------------ drivers/gpu/drm/xe/xe_perf.h | 4 +--- include/uapi/drm/xe_drm.h | 16 ++++++++++------ 4 files changed, 20 insertions(+), 37 deletions(-)drivers/gpu/drm/xe/xe_device.c +1
-4@@ -115,10 +115,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF_DRV (XE_VM_MADVISE ,xe_vm_madvise_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_OPEN ,xe_perf_open_ioctl ,DRM_RENDER_ALLOW ), -DRM_IOCTL_DEF_DRV (XE_PERF_ADD_CONFIG ,xe_perf_add_config_ioctl ,DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(XE_PERF_REMOVE_CONFIG, xe_perf_remove_config_ioctl, DRM_RENDER_ALLOW), - + DRM_IOCTL_DEF_DRV(XE_PERF, xe_perf_ioctl, DRM_RENDER_ALLOW), };static const struct file_operations xe_driver_fops = {drivers/gpu/drm/xe/xe_perf.c +1
-7@@ -6,37 +6,21 @@#include "xe_oa.h" #include "xe_perf.h" -int xe_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +int xe_oa_ioctl (struct drm_device *dev,struct drm_xe_perf_param *arg,struct drm_file *file) { -struct drm_xe_perf_param *arg = data; - -if (arg->extensions) -return -EINVAL ; - -switch (arg->perf_type) {Quoted 8 lines
drivers/gpu/drm/xe/xe_perf.c line 13
Quoted 4 lines
drivers/gpu/drm/xe/xe_perf.c +2
-1-case XE_PERF_TYPE_OA : +switch (arg->perf_op) { +case XE_PERF_STREAM_OPEN :return xe_oa_stream_open_ioctl (dev, (void *)arg->param, file);It's a nice idea to reduce the ioctls, but if your struct
drm_xe_perf_param*arg is overloaded based on thePERF_OPpassed, then I would recommend validating that the right arg is passed for the corresponding OP.I am not following what you mean here: which right arg for which OP?
The PERF layer only demultiplexes based on
perf_type(say OA/XYZ etc.). Theperf_opbelongs to theperf_typelayer (say OA), not the PERF layer. It is the job of theperf_typelayer (OA) to validate theperf_op, not the job of the PERF layer. It is just convenient to include theperf_opas part of 'structdrm_xe_perf_param' (rather than inventing yet another layer there). See the functionxe_perf_ioctl()in the patch.Quoted 3 lines
The
xe_oa_ioctlfunction above could possibly be moved intoxe_oa.c. I just left it inxe_perf.csince it didn't seem to matter much. But I am open to doing that.OK, I think I figured out the right way to visualize this. It's as follows. Let's say we have a an OA stream inside the PERF layer. So what we have is:
struct drm_xe_perf_param { perf_type; struct oa { oa_op; struct oa_op_params { ... } } }
Quoted 3 lines
Quoted 3 lines
So basically I have eliminated 'struct oa' and merged into 'struct
drm_xe_perf_param'. Butoa_opstill belongs to the OA layer, not the PERF layer. So the oa layer handles theoa_opnot the PERF layer.
Umesh brought up an excellent point. When UMD and KMD versions are not the same and struct sizes change, UMD and KMD have different values for 'struct oa_op_params' above. To handle this situation, we will add a 'size' field to 'struct oa' above (in reality to 'struct drm_xe_perf_param'). UMD can fill in this field to indicate its notion of the 'struct oa_op_params' size.
This should enable the kernel to take handle the discrepancy in the param size between userspace and kernel (if needed, possibly in the future). It may also be possible to move the additional copy_from_user into the perf layer, similar to what drm_ioctl() does. But we will start by adding 'size' to the header.
Quoted 29 lines
Quoted 13 lines
Quoted 5 lines
Quoted 4 lines
Ideally I wouldn't go that route since that would require some sort of signature in the arg which would identify it as the correct param. Instead I would be okay with retaining separate ioctls for the 3 operations.
Quoted 7 lines
If we were not doing this multiplexing based on
perf_type(as in i915) we could have separate ioctl's for each operation. But since here we have anyway introduced a multiplxing layer, to me it makes no sense to have separate operation ioctl's (only disadvantags and no advantages). (Note that the multiplexing layer implies a (non-obvious) additionalcopy_from_userper operation visible in the previous "drm/xe/uapi: "Perf" layer to support multiple perf counter stream types" patch).Quoted 13 lines
The drm layer does a
copy_from_userfor the first layer but any second layer structs need to be copy_from_user'd by the driver.Quoted 10 lines
Also we cannot assume that a future stream type will only have 3 operations as i915 OA did. The OPEN/ADD_CONFIG/CLOSE are really OA specific operations. But it appears other potential perf_type's will also be able to use them, at least initially that is why they are left defined as PERF_OP's (rather than OA_OP's) in
xe_drm.h. New stream types are free to introduce new ops in this design.So retaining the ops inside a single PERF ioctl eliminates the need for introducing a new ioctl each time a stream type introduces a new OP.
I think I misunderstood. This is fine as long as the underlying layer is able to validate the arguments.
PATCH 14/21 drm/xe/uapi: Simplify OA configs in uapi
In reply to Ashutosh DixitIn OA uapi, there is no reason to have separate mux/boolean/flex registers in 'struct drm_xe_oa_config'. The kernel knows ranges of these registers and can determine which are which when needed without these being provided through the uapi. Therefore combine the three register arrays into a single one in the uapi.
--- drivers/gpu/drm/xe/xe_oa.c | 60 +++++++++----------------------- drivers/gpu/drm/xe/xe_oa_types.h | 8 ++--- include/uapi/drm/xe_drm.h | 48 +++++-------------------- 3 files changed, 27 insertions(+), 89 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +17 -43
@@ -88,9 +88,7 @@ static void xe_oa_config_release(struct kref *ref)struct xe_oa_config *oa_config =container_of (ref,typeof (*oa_config), ref); -kfree (oa_config->flex_regs); -kfree (oa_config->b_counter_regs); -kfree (oa_config->mux_regs); +kfree (oa_config->regs);kfree_rcu (oa_config, rcu); }
@@ -970,16 +968,14 @@ static struct xe_oa_config_bo * __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oa_config) { struct xe_oa_config_bo *oa_bo; -size_t config_length =0 ; +size_t config_length;struct xe_bb *bb; oa_bo =kzalloc (sizeof (*oa_bo),GFP_KERNEL );if (!oa_bo)return ERR_PTR (-ENOMEM ); - config_length +=num_lri_dwords (oa_config->mux_regs_len); - config_length +=num_lri_dwords (oa_config->b_counter_regs_len); - config_length +=num_lri_dwords (oa_config->flex_regs_len); + config_length =num_lri_dwords (oa_config->regs_len); config_length++;/* MI_BATCH_BUFFER_END */ config_length =ALIGN (sizeof (u32) * config_length,XE_PAGE_SIZE ) /sizeof (u32);
@@ -987,9 +983,7 @@ __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oaif (IS_ERR (bb)) goto err_free; -write_cs_mi_lri (bb, oa_config->mux_regs, oa_config->mux_regs_len); -write_cs_mi_lri (bb, oa_config->b_counter_regs, oa_config->b_counter_regs_len); -write_cs_mi_lri (bb, oa_config->flex_regs, oa_config->flex_regs_len); +write_cs_mi_lri (bb, oa_config->regs, oa_config->regs_len); oa_bo->bb = bb; oa_bo->oa_config =xe_oa_config_get (oa_config);
@@ -1825,6 +1819,13 @@ static bool xe_oa_is_valid_mux_addr(struct xe_oa *oa, u32 addr)return xe_oa_reg_in_range_table (addr, gen12_oa_mux_regs); } +static bool xe_oa_is_valid_config_reg_addr (struct xe_oa *oa,u32 addr) +{ +return xe_oa_is_valid_flex_addr (oa, addr) || +xe_oa_is_valid_b_counter_addr (oa, addr) || +xe_oa_is_valid_mux_addr (oa, addr); +} +static u32 mask_reg_value (u32 reg,u32 val) {/*
@@ -1852,9 +1853,6 @@ xe_oa_alloc_regs(struct xe_oa *oa, bool (*is_valid)(struct xe_oa *oa, u32 addr),int err;u32 i; -if (!n_regs ||WARN_ON (!is_valid)) -return NULL ; - oa_regs =kmalloc_array (n_regs,sizeof (*oa_regs),GFP_KERNEL );if (!oa_regs)return ERR_PTR (-ENOMEM );
@@ -1941,9 +1939,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_DBG (oa->xe, err))return -EFAULT ; -if ((!arg->mux_regs_ptr || !arg->n_mux_regs) && - (!arg->boolean_regs_ptr || !arg->n_boolean_regs) && - (!arg->flex_regs_ptr || !arg->n_flex_regs)) { +if (!arg->regs_ptr || !arg->n_regs) {drm_dbg (&oa->xe->drm,"No OA registers given\n" );return -EINVAL ; }
@@ -1964,38 +1960,16 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,/* Last character in oa_config->uuid will be 0 because oa_config is kzalloc */ memcpy (oa_config->uuid, arg->uuid,sizeof (arg->uuid)); - oa_config->mux_regs_len = arg->n_mux_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_mux_addr, -u64_to_user_ptr (arg->mux_regs_ptr), - arg->n_mux_regs); + oa_config->regs_len = arg->n_regs; + regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_config_reg_addr, +u64_to_user_ptr (arg->regs_ptr), + arg->n_regs);if (IS_ERR (regs)) {drm_dbg (&oa->xe->drm,"Failed to create OA config for mux_regs\n" ); err =PTR_ERR (regs); goto reg_err; } - oa_config->mux_regs = regs; - - oa_config->b_counter_regs_len = arg->n_boolean_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_b_counter_addr, -u64_to_user_ptr (arg->boolean_regs_ptr), - arg->n_boolean_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for b_counter_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->b_counter_regs = regs; - - oa_config->flex_regs_len = arg->n_flex_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_flex_addr, -u64_to_user_ptr (arg->flex_regs_ptr), - arg->n_flex_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for flex_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->flex_regs = regs; + oa_config->regs = regs; err =mutex_lock_interruptible (&oa->metrics_lock);if (err)
drivers/gpu/drm/xe/xe_oa_types.h +2 -6
@@ -52,12 +52,8 @@ struct xe_oa_config {char uuid[UUID_STRING_LEN +1 ];int id; -const struct xe_oa_reg *mux_regs; -u32 mux_regs_len; -const struct xe_oa_reg *b_counter_regs; -u32 b_counter_regs_len; -const struct xe_oa_reg *flex_regs; -u32 flex_regs_len; +const struct xe_oa_reg *regs; +u32 regs_len;struct attribute_group sysfs_metric;struct attribute *attrs[2 ];
include/uapi/drm/xe_drm.h +8 -40
60 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 14/21] drm/xe/uapi: Simplify OA configs in uapi
Quoted 8 lines · Ashutosh Dixit
In OA uapi, there is no reason to have separate mux/boolean/flex registers in 'struct
drm_xe_oa_config'. The kernel knows ranges of these registers and can determine which are which when needed without these being provided through the uapi. Therefore combine the three register arrays into a single one in the uapi.Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>
lgtm
Umesh
Quoted 217 lines
---
drivers/gpu/drm/xe/xe_oa.c | 60 +++++++++----------------------- drivers/gpu/drm/xe/xe_oa_types.h | 8 ++--- include/uapi/drm/xe_drm.h | 48 +++++-------------------- 3 files changed, 27 insertions(+), 89 deletions(-)drivers/gpu/drm/xe/xe_oa.c +17
-43@@ -88,9 +88,7 @@ static void xe_oa_config_release(struct kref *ref)struct xe_oa_config *oa_config =container_of (ref,typeof (*oa_config), ref); -kfree (oa_config->flex_regs); -kfree (oa_config->b_counter_regs); -kfree (oa_config->mux_regs); +kfree (oa_config->regs);kfree_rcu (oa_config, rcu); }@@ -970,16 +968,14 @@ static struct xe_oa_config_bo * __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oa_config) { struct xe_oa_config_bo *oa_bo; -size_t config_length =0 ; +size_t config_length;struct xe_bb *bb; oa_bo =kzalloc (sizeof (*oa_bo),GFP_KERNEL );if (!oa_bo)return ERR_PTR (-ENOMEM ); - config_length +=num_lri_dwords (oa_config->mux_regs_len); - config_length +=num_lri_dwords (oa_config->b_counter_regs_len); - config_length +=num_lri_dwords (oa_config->flex_regs_len); + config_length =num_lri_dwords (oa_config->regs_len); config_length++;/* MI_BATCH_BUFFER_END */ config_length =ALIGN (sizeof (u32) * config_length,XE_PAGE_SIZE ) /sizeof (u32);@@ -987,9 +983,7 @@ __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oaif (IS_ERR (bb)) goto err_free; -write_cs_mi_lri (bb, oa_config->mux_regs, oa_config->mux_regs_len); -write_cs_mi_lri (bb, oa_config->b_counter_regs, oa_config->b_counter_regs_len); -write_cs_mi_lri (bb, oa_config->flex_regs, oa_config->flex_regs_len); +write_cs_mi_lri (bb, oa_config->regs, oa_config->regs_len); oa_bo->bb = bb; oa_bo->oa_config =xe_oa_config_get (oa_config);@@ -1825,6 +1819,13 @@ static bool xe_oa_is_valid_mux_addr(struct xe_oa *oa, u32 addr)return xe_oa_reg_in_range_table (addr, gen12_oa_mux_regs); } +static bool xe_oa_is_valid_config_reg_addr (struct xe_oa *oa,u32 addr) +{ +return xe_oa_is_valid_flex_addr (oa, addr) || +xe_oa_is_valid_b_counter_addr (oa, addr) || +xe_oa_is_valid_mux_addr (oa, addr); +} +static u32 mask_reg_value (u32 reg,u32 val) {/* @@ -1852,9 +1853,6 @@ xe_oa_alloc_regs(struct xe_oa *oa, bool (*is_valid)(struct xe_oa *oa, u32 addr),int err;u32 i; -if (!n_regs ||WARN_ON (!is_valid)) -return NULL ; - oa_regs =kmalloc_array (n_regs,sizeof (*oa_regs),GFP_KERNEL );if (!oa_regs)return ERR_PTR (-ENOMEM );@@ -1941,9 +1939,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_DBG (oa->xe, err))return -EFAULT ; -if ((!arg->mux_regs_ptr || !arg->n_mux_regs) && - (!arg->boolean_regs_ptr || !arg->n_boolean_regs) && - (!arg->flex_regs_ptr || !arg->n_flex_regs)) { +if (!arg->regs_ptr || !arg->n_regs) {drm_dbg (&oa->xe->drm,"No OA registers given\n" );return -EINVAL ; }@@ -1964,38 +1960,16 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,/* Last character in oa_config->uuid will be 0 because oa_config is kzalloc */ memcpy (oa_config->uuid, arg->uuid,sizeof (arg->uuid)); - oa_config->mux_regs_len = arg->n_mux_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_mux_addr, -u64_to_user_ptr (arg->mux_regs_ptr), - arg->n_mux_regs); + oa_config->regs_len = arg->n_regs; + regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_config_reg_addr, +u64_to_user_ptr (arg->regs_ptr), + arg->n_regs);if (IS_ERR (regs)) {drm_dbg (&oa->xe->drm,"Failed to create OA config for mux_regs\n" ); err =PTR_ERR (regs); goto reg_err; } - oa_config->mux_regs = regs; - - oa_config->b_counter_regs_len = arg->n_boolean_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_b_counter_addr, -u64_to_user_ptr (arg->boolean_regs_ptr), - arg->n_boolean_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for b_counter_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->b_counter_regs = regs; - - oa_config->flex_regs_len = arg->n_flex_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_flex_addr, -u64_to_user_ptr (arg->flex_regs_ptr), - arg->n_flex_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for flex_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->flex_regs = regs; + oa_config->regs = regs; err =mutex_lock_interruptible (&oa->metrics_lock);if (err)drivers/gpu/drm/xe/xe_oa_types.h +2
-6@@ -52,12 +52,8 @@ struct xe_oa_config {char uuid[UUID_STRING_LEN +1 ];int id; -const struct xe_oa_reg *mux_regs; -u32 mux_regs_len; -const struct xe_oa_reg *b_counter_regs; -u32 b_counter_regs_len; -const struct xe_oa_reg *flex_regs; -u32 flex_regs_len; +const struct xe_oa_reg *regs; +u32 regs_len;struct attribute_group sysfs_metric;struct attribute *attrs[2 ];include/uapi/drm/xe_drm.h +8
-40@@ -1292,52 +1292,20 @@ struct drm_xe_oa_config {char uuid[36 ];/** -* @n_mux_regs: +* @n_regs: * -* Number of mux regs in &mux_regs_ptr. +* Number of regs in @regs_ptr. */ -__u32 n_mux_regs; +__u32 n_regs;/** -* @n_boolean_regs: +* @regs_ptr: * -* Number of boolean regs in &boolean_regs_ptr. +* Pointer to tuples of u32 values (register address, value) for OA +* config registers. Expected length of buffer is (2 * sizeof(u32) * +* @n_regs). */ -__u32 n_boolean_regs; - -/** -* @n_flex_regs: -* -* Number of flex regs in &flex_regs_ptr. -*/ -__u32 n_flex_regs; - -/** -* @mux_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_mux_regs). -*/ -__u64 mux_regs_ptr; - -/** -* @boolean_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_boolean_regs). -*/ -__u64 boolean_regs_ptr; - -/** -* @flex_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_flex_regs). -*/ -__u64 flex_regs_ptr; +__u64 regs_ptr; };/* Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 14/21] drm/xe/uapi: Simplify OA configs in uapi
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 7 lines · Ashutosh Dixit
Quoted 6 lines
In OA uapi, there is no reason to have separate mux/boolean/flex registers in 'struct
drm_xe_oa_config'. The kernel knows ranges of these registers and can determine which are which when needed without these being provided through the uapi. Therefore combine the three register arrays into a single one in the uapi.
Quoted 5 lines
Quoted 2 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>lgtm
Reviewed-by Umesh Nerlige Ramappa <[email protected]>
Thanks, though just wondering if internally in the driver we should still maintain the distinction between flex/mux/b_counter registers? Or can we remove this distinction even internally in the driver and just maintain a single valid register range per platform? At least at present there seems to be no reason to maintain 3 different register ranges. So it will simplify the code a little bit if we just have a single range per platform (3 ranges can just be maintained in comments). Thoughts?
Thanks.
--
Ashutosh
Quoted 217 lines
Quoted 217 lines
---
drivers/gpu/drm/xe/xe_oa.c | 60 +++++++++----------------------- drivers/gpu/drm/xe/xe_oa_types.h | 8 ++--- include/uapi/drm/xe_drm.h | 48 +++++-------------------- 3 files changed, 27 insertions(+), 89 deletions(-)drivers/gpu/drm/xe/xe_oa.c +17
-43@@ -88,9 +88,7 @@ static void xe_oa_config_release(struct kref *ref)struct xe_oa_config *oa_config =container_of (ref,typeof (*oa_config), ref); -kfree (oa_config->flex_regs); -kfree (oa_config->b_counter_regs); -kfree (oa_config->mux_regs); +kfree (oa_config->regs);kfree_rcu (oa_config, rcu); }@@ -970,16 +968,14 @@ static struct xe_oa_config_bo * __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oa_config) { struct xe_oa_config_bo *oa_bo; -size_t config_length =0 ; +size_t config_length;struct xe_bb *bb; oa_bo =kzalloc (sizeof (*oa_bo),GFP_KERNEL );if (!oa_bo)return ERR_PTR (-ENOMEM ); - config_length +=num_lri_dwords (oa_config->mux_regs_len); - config_length +=num_lri_dwords (oa_config->b_counter_regs_len); - config_length +=num_lri_dwords (oa_config->flex_regs_len); + config_length =num_lri_dwords (oa_config->regs_len); config_length++;/* MI_BATCH_BUFFER_END */ config_length =ALIGN (sizeof (u32) * config_length,XE_PAGE_SIZE ) /sizeof (u32);@@ -987,9 +983,7 @@ __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oaif (IS_ERR (bb)) goto err_free; -write_cs_mi_lri (bb, oa_config->mux_regs, oa_config->mux_regs_len); -write_cs_mi_lri (bb, oa_config->b_counter_regs, oa_config->b_counter_regs_len); -write_cs_mi_lri (bb, oa_config->flex_regs, oa_config->flex_regs_len); +write_cs_mi_lri (bb, oa_config->regs, oa_config->regs_len); oa_bo->bb = bb; oa_bo->oa_config =xe_oa_config_get (oa_config);@@ -1825,6 +1819,13 @@ static bool xe_oa_is_valid_mux_addr(struct xe_oa *oa, u32 addr)return xe_oa_reg_in_range_table (addr, gen12_oa_mux_regs); } +static bool xe_oa_is_valid_config_reg_addr (struct xe_oa *oa,u32 addr) +{ +return xe_oa_is_valid_flex_addr (oa, addr) || +xe_oa_is_valid_b_counter_addr (oa, addr) || +xe_oa_is_valid_mux_addr (oa, addr); +} +static u32 mask_reg_value (u32 reg,u32 val) {/* @@ -1852,9 +1853,6 @@ xe_oa_alloc_regs(struct xe_oa *oa, bool (*is_valid)(struct xe_oa *oa, u32 addr),int err;u32 i; -if (!n_regs ||WARN_ON (!is_valid)) -return NULL ; - oa_regs =kmalloc_array (n_regs,sizeof (*oa_regs),GFP_KERNEL );if (!oa_regs)return ERR_PTR (-ENOMEM );@@ -1941,9 +1939,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_DBG (oa->xe, err))return -EFAULT ; -if ((!arg->mux_regs_ptr || !arg->n_mux_regs) && - (!arg->boolean_regs_ptr || !arg->n_boolean_regs) && - (!arg->flex_regs_ptr || !arg->n_flex_regs)) { +if (!arg->regs_ptr || !arg->n_regs) {drm_dbg (&oa->xe->drm,"No OA registers given\n" );return -EINVAL ; }@@ -1964,38 +1960,16 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,/* Last character in oa_config->uuid will be 0 because oa_config is kzalloc */ memcpy (oa_config->uuid, arg->uuid,sizeof (arg->uuid)); - oa_config->mux_regs_len = arg->n_mux_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_mux_addr, -u64_to_user_ptr (arg->mux_regs_ptr), - arg->n_mux_regs); + oa_config->regs_len = arg->n_regs; + regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_config_reg_addr, +u64_to_user_ptr (arg->regs_ptr), + arg->n_regs);if (IS_ERR (regs)) {drm_dbg (&oa->xe->drm,"Failed to create OA config for mux_regs\n" ); err =PTR_ERR (regs); goto reg_err; } - oa_config->mux_regs = regs; - - oa_config->b_counter_regs_len = arg->n_boolean_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_b_counter_addr, -u64_to_user_ptr (arg->boolean_regs_ptr), - arg->n_boolean_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for b_counter_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->b_counter_regs = regs; - - oa_config->flex_regs_len = arg->n_flex_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_flex_addr, -u64_to_user_ptr (arg->flex_regs_ptr), - arg->n_flex_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for flex_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->flex_regs = regs; + oa_config->regs = regs; err =mutex_lock_interruptible (&oa->metrics_lock);if (err)drivers/gpu/drm/xe/xe_oa_types.h +2
-6@@ -52,12 +52,8 @@ struct xe_oa_config {char uuid[UUID_STRING_LEN +1 ];int id; -const struct xe_oa_reg *mux_regs; -u32 mux_regs_len; -const struct xe_oa_reg *b_counter_regs; -u32 b_counter_regs_len; -const struct xe_oa_reg *flex_regs; -u32 flex_regs_len; +const struct xe_oa_reg *regs; +u32 regs_len;struct attribute_group sysfs_metric;struct attribute *attrs[2 ];include/uapi/drm/xe_drm.h +8
-41@@ -1292,52 +1292,20 @@ struct drm_xe_oa_config {char uuid[36 ];/** -* @n_mux_regs: +* @n_regs: * -* Number of mux regs in &mux_regs_ptr. +* Number of regs in @regs_ptr. */ -__u32 n_mux_regs; +__u32 n_regs;/** -* @n_boolean_regs: +* @regs_ptr: * -* Number of boolean regs in &boolean_regs_ptr. +* Pointer to tuples of u32 values (register address, value) for OA +* config registers. Expected length of buffer is (2 * sizeof(u32) * +* @n_regs). */ -__u32 n_boolean_regs; - -/** -* @n_flex_regs: -* -* Number of flex regs in &flex_regs_ptr. -*/ -__u32 n_flex_regs; - -/** -* @mux_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_mux_regs). -*/ -__u64 mux_regs_ptr; - -/** -* @boolean_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_boolean_regs). -*/ -__u64 boolean_regs_ptr; - -/** -* @flex_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_flex_regs). -*/ -__u64 flex_regs_ptr; +__u64 regs_ptr; };/* -- 2.41.0
Rodrigo Vivi
maintainerRe: [Intel-xe] [PATCH 14/21] drm/xe/uapi: Simplify OA configs in uapi
Quoted 17 lines · Ashutosh
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 12 lines · Ashutosh Dixit
Quoted 8 lines
In OA uapi, there is no reason to have separate mux/boolean/flex registers in 'struct
drm_xe_oa_config'. The kernel knows ranges of these registers and can determine which are which when needed without these being provided through the uapi. Therefore combine the three register arrays into a single one in the uapi.Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>lgtm
Reviewed-by Umesh Nerlige Ramappa <[email protected]>
Please do not merge this before syncing with Francois as this might conflict hard with the big series that is getting ready in sync with UMDs as well.
Quoted 230 lines
Thanks, though just wondering if internally in the driver we should still maintain the distinction between flex/mux/b_counter registers? Or can we remove this distinction even internally in the driver and just maintain a single valid register range per platform? At least at present there seems to be no reason to maintain 3 different register ranges. So it will simplify the code a little bit if we just have a single range per platform (3 ranges can just be maintained in comments). Thoughts?
Thanks.
--
AshutoshQuoted 217 lines
Quoted 217 lines
---
drivers/gpu/drm/xe/xe_oa.c | 60 +++++++++----------------------- drivers/gpu/drm/xe/xe_oa_types.h | 8 ++--- include/uapi/drm/xe_drm.h | 48 +++++-------------------- 3 files changed, 27 insertions(+), 89 deletions(-)drivers/gpu/drm/xe/xe_oa.c +17
-43@@ -88,9 +88,7 @@ static void xe_oa_config_release(struct kref *ref)struct xe_oa_config *oa_config =container_of (ref,typeof (*oa_config), ref); -kfree (oa_config->flex_regs); -kfree (oa_config->b_counter_regs); -kfree (oa_config->mux_regs); +kfree (oa_config->regs);kfree_rcu (oa_config, rcu); }@@ -970,16 +968,14 @@ static struct xe_oa_config_bo * __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oa_config) { struct xe_oa_config_bo *oa_bo; -size_t config_length =0 ; +size_t config_length;struct xe_bb *bb; oa_bo =kzalloc (sizeof (*oa_bo),GFP_KERNEL );if (!oa_bo)return ERR_PTR (-ENOMEM ); - config_length +=num_lri_dwords (oa_config->mux_regs_len); - config_length +=num_lri_dwords (oa_config->b_counter_regs_len); - config_length +=num_lri_dwords (oa_config->flex_regs_len); + config_length =num_lri_dwords (oa_config->regs_len); config_length++;/* MI_BATCH_BUFFER_END */ config_length =ALIGN (sizeof (u32) * config_length,XE_PAGE_SIZE ) /sizeof (u32);@@ -987,9 +983,7 @@ __xe_oa_alloc_config_buffer(struct xe_oa_stream *stream, struct xe_oa_config *oaif (IS_ERR (bb)) goto err_free; -write_cs_mi_lri (bb, oa_config->mux_regs, oa_config->mux_regs_len); -write_cs_mi_lri (bb, oa_config->b_counter_regs, oa_config->b_counter_regs_len); -write_cs_mi_lri (bb, oa_config->flex_regs, oa_config->flex_regs_len); +write_cs_mi_lri (bb, oa_config->regs, oa_config->regs_len); oa_bo->bb = bb; oa_bo->oa_config =xe_oa_config_get (oa_config);@@ -1825,6 +1819,13 @@ static bool xe_oa_is_valid_mux_addr(struct xe_oa *oa, u32 addr)return xe_oa_reg_in_range_table (addr, gen12_oa_mux_regs); } +static bool xe_oa_is_valid_config_reg_addr (struct xe_oa *oa,u32 addr) +{ +return xe_oa_is_valid_flex_addr (oa, addr) || +xe_oa_is_valid_b_counter_addr (oa, addr) || +xe_oa_is_valid_mux_addr (oa, addr); +} +static u32 mask_reg_value (u32 reg,u32 val) {/* @@ -1852,9 +1853,6 @@ xe_oa_alloc_regs(struct xe_oa *oa, bool (*is_valid)(struct xe_oa *oa, u32 addr),int err;u32 i; -if (!n_regs ||WARN_ON (!is_valid)) -return NULL ; - oa_regs =kmalloc_array (n_regs,sizeof (*oa_regs),GFP_KERNEL );if (!oa_regs)return ERR_PTR (-ENOMEM );@@ -1941,9 +1939,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_DBG (oa->xe, err))return -EFAULT ; -if ((!arg->mux_regs_ptr || !arg->n_mux_regs) && - (!arg->boolean_regs_ptr || !arg->n_boolean_regs) && - (!arg->flex_regs_ptr || !arg->n_flex_regs)) { +if (!arg->regs_ptr || !arg->n_regs) {drm_dbg (&oa->xe->drm,"No OA registers given\n" );return -EINVAL ; }@@ -1964,38 +1960,16 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data,/* Last character in oa_config->uuid will be 0 because oa_config is kzalloc */ memcpy (oa_config->uuid, arg->uuid,sizeof (arg->uuid)); - oa_config->mux_regs_len = arg->n_mux_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_mux_addr, -u64_to_user_ptr (arg->mux_regs_ptr), - arg->n_mux_regs); + oa_config->regs_len = arg->n_regs; + regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_config_reg_addr, +u64_to_user_ptr (arg->regs_ptr), + arg->n_regs);if (IS_ERR (regs)) {drm_dbg (&oa->xe->drm,"Failed to create OA config for mux_regs\n" ); err =PTR_ERR (regs); goto reg_err; } - oa_config->mux_regs = regs; - - oa_config->b_counter_regs_len = arg->n_boolean_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_b_counter_addr, -u64_to_user_ptr (arg->boolean_regs_ptr), - arg->n_boolean_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for b_counter_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->b_counter_regs = regs; - - oa_config->flex_regs_len = arg->n_flex_regs; - regs =xe_oa_alloc_regs (oa, xe_oa_is_valid_flex_addr, -u64_to_user_ptr (arg->flex_regs_ptr), - arg->n_flex_regs); -if (IS_ERR (regs)) { -drm_dbg (&oa->xe->drm,"Failed to create OA config for flex_regs\n" ); - err =PTR_ERR (regs); - goto reg_err; - } - oa_config->flex_regs = regs; + oa_config->regs = regs; err =mutex_lock_interruptible (&oa->metrics_lock);if (err)drivers/gpu/drm/xe/xe_oa_types.h +2
-6@@ -52,12 +52,8 @@ struct xe_oa_config {char uuid[UUID_STRING_LEN +1 ];int id; -const struct xe_oa_reg *mux_regs; -u32 mux_regs_len; -const struct xe_oa_reg *b_counter_regs; -u32 b_counter_regs_len; -const struct xe_oa_reg *flex_regs; -u32 flex_regs_len; +const struct xe_oa_reg *regs; +u32 regs_len;struct attribute_group sysfs_metric;struct attribute *attrs[2 ];include/uapi/drm/xe_drm.h +8
-41@@ -1292,52 +1292,20 @@ struct drm_xe_oa_config {char uuid[36 ];/** -* @n_mux_regs: +* @n_regs: * -* Number of mux regs in &mux_regs_ptr. +* Number of regs in @regs_ptr. */ -__u32 n_mux_regs; +__u32 n_regs;/** -* @n_boolean_regs: +* @regs_ptr: * -* Number of boolean regs in &boolean_regs_ptr. +* Pointer to tuples of u32 values (register address, value) for OA +* config registers. Expected length of buffer is (2 * sizeof(u32) * +* @n_regs). */ -__u32 n_boolean_regs; - -/** -* @n_flex_regs: -* -* Number of flex regs in &flex_regs_ptr. -*/ -__u32 n_flex_regs; - -/** -* @mux_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_mux_regs). -*/ -__u64 mux_regs_ptr; - -/** -* @boolean_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_boolean_regs). -*/ -__u64 boolean_regs_ptr; - -/** -* @flex_regs_ptr: -* -* Pointer to tuples of u32 values (register address, value) for mux -* registers. Expected length of buffer is (2 * sizeof(u32) * -* &n_flex_regs). -*/ -__u64 flex_regs_ptr; +__u64 regs_ptr; };/* -- 2.41.0
PATCH 15/21 drm/xe/uapi: Remove OA format names from OA uapi
In reply to Ashutosh DixitOA format names (in enum drm_xe_oa_format) have an overhead in that the uapi header has to be updated each time a HW introduces a new format. Instead of directly using OA format names, switch to using the same fields Bspec uses to specify formats. The fields change much less often than the format names. The format names are still internally maintained, just not exchanged through the uapi.
Bspec: 52198, 60942
--- drivers/gpu/drm/xe/xe_oa.c | 52 +++++++++++++++++++++----------- drivers/gpu/drm/xe/xe_oa_types.h | 23 ++++++++++++-- include/uapi/drm/xe_drm.h | 33 ++++++++++---------- 3 files changed, 72 insertions(+), 36 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +35 -17
@@ -53,10 +53,10 @@ static const struct xe_oa_format oa_formats[] = { [XE_OA_FORMAT_A12] = { 0, 64 }, [XE_OA_FORMAT_A12_B8_C8] = { 2, 128 }, [XE_OA_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256 }, - [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256 }, + [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256, XE_OA_FMT_TYPE_OAR }, [XE_OA_FORMAT_A24u40_A14u32_B8_C8] = { 5, 256 }, - [XE_OAM_FORMAT_MPEC8u64_B8_C8] = { 1, 192, TYPE_OAM, HDR_64_BIT }, - [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, TYPE_OAM, HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u64_B8_C8] = { 1, 192, XE_OA_FMT_TYPE_OAM_MPEC, HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, XE_OA_FMT_TYPE_OAM_MPEC, HDR_64_BIT }, };struct xe_oa_open_properties {
@@ -65,7 +65,7 @@ struct xe_oa_open_properties {u64 exec_q_id;int metrics_set; -int oa_format; +enum xe_oa_format_name oa_format;bool oa_periodic;int oa_period_exponent;
@@ -1529,13 +1529,6 @@ static u64 oa_exponent_to_ns(struct xe_oa *oa, int exponent)return div_u64 (nom + den -1 , den); } -static bool oa_format_valid (struct xe_oa *oa,u64 format) -{ -if (format >=XE_OA_FORMAT_MAX ) -return false; -return test_bit (format, oa->format_mask); -} -static bool engine_supports_oa (const struct xe_hw_engine *hwe) {return hwe->oa_group;
@@ -1543,7 +1536,32 @@ static bool engine_supports_oa(const struct xe_hw_engine *hwe)static bool engine_supports_oa_format (const struct xe_hw_engine *hwe,int type) { -return hwe->oa_group && hwe->oa_group->type == type; +switch (hwe->oa_group->type) { +case TYPE_OAG : +return type ==XE_OA_FMT_TYPE_OAG || type ==XE_OA_FMT_TYPE_OAR ; +case TYPE_OAM : +return type ==XE_OA_FMT_TYPE_OAM || type ==XE_OA_FMT_TYPE_OAM_MPEC ; +default : +return false; + } +} + +static int decode_oa_format (struct xe_oa *oa,u64 prop,enum xe_oa_format_name *name) +{ +u32 counter_sel =FIELD_GET (XE_OA_MASK_COUNTER_SEL , prop); +u32 type =FIELD_GET (XE_OA_MASK_FMT_TYPE , prop); +int idx; + +for_each_set_bit (idx, oa->format_mask,XE_OA_FORMAT_MAX ) { +const struct xe_oa_format *f = &oa->oa_formats[idx]; + +if (type == f->type && counter_sel == f->format) { + *name = idx; +return 0 ; + } + } + +return -EINVAL ; }#define OA_EXPONENT_MAX 31
@@ -1600,12 +1618,12 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, props->metrics_set = value;break ;case DRM_XE_OA_PROP_OA_FORMAT : -if (!oa_format_valid (oa, value)) { -drm_dbg (&oa->xe->drm,"Unsupported OA report format %llu\n" , + ret =decode_oa_format (oa, value, &props->oa_format); +if (ret) { +drm_dbg (&oa->xe->drm,"Unsupported OA report format %#llx\n" , value); -return -EINVAL ; +return ret; } - props->oa_format = value;break ;case DRM_XE_OA_PROP_OA_EXPONENT :if (value >OA_EXPONENT_MAX ) {
@@ -2227,7 +2245,7 @@ u16 xe_oa_unit_id(struct xe_hw_engine *hwe) hwe->oa_group->oa_unit_id : U16_MAX; } -static void oa_format_add (struct xe_oa *oa,enum drm_xe_oa_format format) +static void oa_format_add (struct xe_oa *oa,enum xe_oa_format_name format) {__set_bit (format, oa->format_mask); }
drivers/gpu/drm/xe/xe_oa_types.h +21 -2
@@ -24,7 +24,7 @@ enum { OA_GROUP_INVALID = U32_MAX, }; -enum oa_type { +enum oa_unit_type {TYPE_OAG ,TYPE_OAM , };
@@ -34,6 +34,25 @@ enum report_header { HDR_64_BIT, }; +enum xe_oa_format_name { +XE_OA_FORMAT_C4_B8 =7 , + +/* Gen8+ */ +XE_OA_FORMAT_A12 , +XE_OA_FORMAT_A12_B8_C8 , + XE_OA_FORMAT_A32u40_A4u32_B8_C8, + +/* DG2 */ + XE_OAR_FORMAT_A32u40_A4u32_B8_C8, + XE_OA_FORMAT_A24u40_A14u32_B8_C8, + +/* MTL OAM */ + XE_OAM_FORMAT_MPEC8u64_B8_C8, + XE_OAM_FORMAT_MPEC8u32_B8_C8, + +XE_OA_FORMAT_MAX , +}; +struct xe_oa_format {u32 format;int size;
@@ -96,7 +115,7 @@ struct xe_oa_group {struct xe_oa_regs regs;/** @type: Type of OA unit - OAM, OAG etc. */ -enum oa_type type; +enum oa_unit_type type; };/**
include/uapi/drm/xe_drm.h +16 -17
@@ -1124,23 +1124,13 @@ struct drm_xe_perf_param {__u64 param; }; -enum drm_xe_oa_format { -XE_OA_FORMAT_C4_B8 =7 , - -/* Gen8+ */ -XE_OA_FORMAT_A12 , -XE_OA_FORMAT_A12_B8_C8 , - XE_OA_FORMAT_A32u40_A4u32_B8_C8, - -/* DG2 */ - XE_OAR_FORMAT_A32u40_A4u32_B8_C8, - XE_OA_FORMAT_A24u40_A14u32_B8_C8, - -/* MTL OAM */ - XE_OAM_FORMAT_MPEC8u64_B8_C8, - XE_OAM_FORMAT_MPEC8u32_B8_C8, - -XE_OA_FORMAT_MAX /* non-ABI */ +enum drm_xe_oa_format_type { +XE_OA_FMT_TYPE_OAG , +XE_OA_FMT_TYPE_OAR , +XE_OA_FMT_TYPE_OAM , +XE_OA_FMT_TYPE_OAC , +XE_OA_FMT_TYPE_OAM_MPEC , +XE_OA_FMT_TYPE_PEC , };enum drm_xe_oa_property_id {
@@ -1167,6 +1157,15 @@ enum drm_xe_oa_property_id {* The value specifies the size and layout of OA unit reports. */ DRM_XE_OA_PROP_OA_FORMAT, +/** +* OA_FORMAT's are specified the same way as in Bspec, in terms of +* the following quantities: a. enum @drm_xe_oa_format_type +* b. Counter select c. Counter size and d. BC report +*/ +#define XE_OA_MASK_FMT_TYPE (0xff << 0) +#define XE_OA_MASK_COUNTER_SEL (0xff << 8) +#define XE_OA_MASK_COUNTER_SIZE (0xff << 16) +#define XE_OA_MASK_BC_REPORT (0xff << 24)/** * Specifying this property implicitly requests periodic OA unit
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 15/21] drm/xe/uapi: Remove OA format names from OA uapi
Quoted 6 lines · Ashutosh Dixit
OA format names (in enum
drm_xe_oa_format) have an overhead in that the uapi header has to be updated each time a HW introduces a new format. Instead of directly using OA format names, switch to using the same fields Bspec uses to specify formats. The fields change much less often than the format names. The format names are still internally maintained, just not exchanged through the uapi.
I am rethinking this now. Maybe we should retain the same thing that existed in i915 - the enum of formats. I see some resistance to this change from UMDs like Mesa. If the enum is easier for UMDs, let's just retain that.
As for updating the UApi for each platform, we must make sure hardware retains a backwards compatible OA format for new platforms. That's outside the scope of this activity though.
Sorry about the churn, since I suggested this. Let me know if you think otherwise.
Thanks,
Umesh
Quoted 213 lines
Bspec: 52198, 60942
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_oa.c | 52 +++++++++++++++++++++----------- drivers/gpu/drm/xe/xe_oa_types.h | 23 ++++++++++++-- include/uapi/drm/xe_drm.h | 33 ++++++++++---------- 3 files changed, 72 insertions(+), 36 deletions(-)drivers/gpu/drm/xe/xe_oa.c +35
-17@@ -53,10 +53,10 @@ static const struct xe_oa_format oa_formats[] = { [XE_OA_FORMAT_A12] = { 0, 64 }, [XE_OA_FORMAT_A12_B8_C8] = { 2, 128 }, [XE_OA_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256 }, - [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256 }, + [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256, XE_OA_FMT_TYPE_OAR }, [XE_OA_FORMAT_A24u40_A14u32_B8_C8] = { 5, 256 }, - [XE_OAM_FORMAT_MPEC8u64_B8_C8] = { 1, 192, TYPE_OAM, HDR_64_BIT }, - [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, TYPE_OAM, HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u64_B8_C8] = { 1, 192, XE_OA_FMT_TYPE_OAM_MPEC, HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, XE_OA_FMT_TYPE_OAM_MPEC, HDR_64_BIT }, };struct xe_oa_open_properties {@@ -65,7 +65,7 @@ struct xe_oa_open_properties {u64 exec_q_id;int metrics_set; -int oa_format; +enum xe_oa_format_name oa_format;bool oa_periodic;int oa_period_exponent;@@ -1529,13 +1529,6 @@ static u64 oa_exponent_to_ns(struct xe_oa *oa, int exponent)return div_u64 (nom + den -1 , den); } -static bool oa_format_valid (struct xe_oa *oa,u64 format) -{ -if (format >=XE_OA_FORMAT_MAX ) -return false; -return test_bit (format, oa->format_mask); -} -static bool engine_supports_oa (const struct xe_hw_engine *hwe) {return hwe->oa_group;@@ -1543,7 +1536,32 @@ static bool engine_supports_oa(const struct xe_hw_engine *hwe)static bool engine_supports_oa_format (const struct xe_hw_engine *hwe,int type) { -return hwe->oa_group && hwe->oa_group->type == type; +switch (hwe->oa_group->type) { +case TYPE_OAG : +return type ==XE_OA_FMT_TYPE_OAG || type ==XE_OA_FMT_TYPE_OAR ; +case TYPE_OAM : +return type ==XE_OA_FMT_TYPE_OAM || type ==XE_OA_FMT_TYPE_OAM_MPEC ; +default : +return false; + } +} + +static int decode_oa_format (struct xe_oa *oa,u64 prop,enum xe_oa_format_name *name) +{ +u32 counter_sel =FIELD_GET (XE_OA_MASK_COUNTER_SEL , prop); +u32 type =FIELD_GET (XE_OA_MASK_FMT_TYPE , prop); +int idx; + +for_each_set_bit (idx, oa->format_mask,XE_OA_FORMAT_MAX ) { +const struct xe_oa_format *f = &oa->oa_formats[idx]; + +if (type == f->type && counter_sel == f->format) { + *name = idx; +return 0 ; + } + } + +return -EINVAL ; }#define OA_EXPONENT_MAX 31@@ -1600,12 +1618,12 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, props->metrics_set = value;break ;case DRM_XE_OA_PROP_OA_FORMAT : -if (!oa_format_valid (oa, value)) { -drm_dbg (&oa->xe->drm,"Unsupported OA report format %llu\n" , + ret =decode_oa_format (oa, value, &props->oa_format); +if (ret) { +drm_dbg (&oa->xe->drm,"Unsupported OA report format %#llx\n" , value); -return -EINVAL ; +return ret; } - props->oa_format = value;break ;case DRM_XE_OA_PROP_OA_EXPONENT :if (value >OA_EXPONENT_MAX ) {@@ -2227,7 +2245,7 @@ u16 xe_oa_unit_id(struct xe_hw_engine *hwe) hwe->oa_group->oa_unit_id : U16_MAX; } -static void oa_format_add (struct xe_oa *oa,enum drm_xe_oa_format format) +static void oa_format_add (struct xe_oa *oa,enum xe_oa_format_name format) {__set_bit (format, oa->format_mask); }drivers/gpu/drm/xe/xe_oa_types.h +21
-2@@ -24,7 +24,7 @@ enum { OA_GROUP_INVALID = U32_MAX, }; -enum oa_type { +enum oa_unit_type {TYPE_OAG ,TYPE_OAM , };@@ -34,6 +34,25 @@ enum report_header { HDR_64_BIT, }; +enum xe_oa_format_name { +XE_OA_FORMAT_C4_B8 =7 , + +/* Gen8+ */ +XE_OA_FORMAT_A12 , +XE_OA_FORMAT_A12_B8_C8 , + XE_OA_FORMAT_A32u40_A4u32_B8_C8, + +/* DG2 */ + XE_OAR_FORMAT_A32u40_A4u32_B8_C8, + XE_OA_FORMAT_A24u40_A14u32_B8_C8, + +/* MTL OAM */ + XE_OAM_FORMAT_MPEC8u64_B8_C8, + XE_OAM_FORMAT_MPEC8u32_B8_C8, + +XE_OA_FORMAT_MAX , +}; +struct xe_oa_format {u32 format;int size;@@ -96,7 +115,7 @@ struct xe_oa_group {struct xe_oa_regs regs;/** @type: Type of OA unit - OAM, OAG etc. */ -enum oa_type type; +enum oa_unit_type type; };/** include/uapi/drm/xe_drm.h +16
-17@@ -1124,23 +1124,13 @@ struct drm_xe_perf_param {__u64 param; }; -enum drm_xe_oa_format { -XE_OA_FORMAT_C4_B8 =7 , - -/* Gen8+ */ -XE_OA_FORMAT_A12 , -XE_OA_FORMAT_A12_B8_C8 , - XE_OA_FORMAT_A32u40_A4u32_B8_C8, - -/* DG2 */ - XE_OAR_FORMAT_A32u40_A4u32_B8_C8, - XE_OA_FORMAT_A24u40_A14u32_B8_C8, - -/* MTL OAM */ - XE_OAM_FORMAT_MPEC8u64_B8_C8, - XE_OAM_FORMAT_MPEC8u32_B8_C8, - -XE_OA_FORMAT_MAX /* non-ABI */ +enum drm_xe_oa_format_type { +XE_OA_FMT_TYPE_OAG , +XE_OA_FMT_TYPE_OAR , +XE_OA_FMT_TYPE_OAM , +XE_OA_FMT_TYPE_OAC , +XE_OA_FMT_TYPE_OAM_MPEC , +XE_OA_FMT_TYPE_PEC , };enum drm_xe_oa_property_id {@@ -1167,6 +1157,15 @@ enum drm_xe_oa_property_id {* The value specifies the size and layout of OA unit reports. */ DRM_XE_OA_PROP_OA_FORMAT, +/** +* OA_FORMAT's are specified the same way as in Bspec, in terms of +* the following quantities: a. enum @drm_xe_oa_format_type +* b. Counter select c. Counter size and d. BC report +*/ +#define XE_OA_MASK_FMT_TYPE (0xff << 0) +#define XE_OA_MASK_COUNTER_SEL (0xff << 8) +#define XE_OA_MASK_COUNTER_SIZE (0xff << 16) +#define XE_OA_MASK_BC_REPORT (0xff << 24)/** * Specifying this property implicitly requests periodic OA unit Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 15/21] drm/xe/uapi: Remove OA format names from OA uapi
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 8 lines · Ashutosh Dixit
Quoted 6 lines
OA format names (in enum
drm_xe_oa_format) have an overhead in that the uapi header has to be updated each time a HW introduces a new format. Instead of directly using OA format names, switch to using the same fields Bspec uses to specify formats. The fields change much less often than the format names. The format names are still internally maintained, just not exchanged through the uapi.
Quoted 4 lines
I am rethinking this now. Maybe we should retain the same thing that existed in i915 - the enum of formats. I see some resistance to this change from UMDs like Mesa. If the enum is easier for UMDs, let's just retain that.
I will not resist strongly against going back to the format enum's but I would like to run this patch with the UMD's first before deciding (since they haven't really seen this patch). As said in the commit message above the change here (a) follows Bspec (b) is more relient to changes each time a new format is introduced. Also the format enum's can be maintained internally in both the kernel and in userland, the format enum just don't come through the uapi.
The kernel change can of course be seen below in this patch.
The IGT userspace change is seen the "tests/xe/oa: Use OA format fields, not format names" patch here:
https://gitlab.freedesktop.org/adixit/igt-gpu-tools/-/commits/xe-oa
Let me run this past the UMD's and then decide on this.
Thanks.
--
Ashutosh
Quoted 224 lines
As for updating the UApi for each platform, we must make sure hardware retains a backwards compatible OA format for new platforms. That's outside the scope of this activity though.
Sorry about the churn, since I suggested this. Let me know if you think otherwise.
Thanks,
UmeshQuoted 213 lines
Bspec: 52198, 60942
Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_oa.c | 52 +++++++++++++++++++++----------- drivers/gpu/drm/xe/xe_oa_types.h | 23 ++++++++++++-- include/uapi/drm/xe_drm.h | 33 ++++++++++---------- 3 files changed, 72 insertions(+), 36 deletions(-)drivers/gpu/drm/xe/xe_oa.c +35
-17@@ -53,10 +53,10 @@ static const struct xe_oa_format oa_formats[] = { [XE_OA_FORMAT_A12] = { 0, 64 }, [XE_OA_FORMAT_A12_B8_C8] = { 2, 128 }, [XE_OA_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256 }, - [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256 }, + [XE_OAR_FORMAT_A32u40_A4u32_B8_C8] = { 5, 256, XE_OA_FMT_TYPE_OAR }, [XE_OA_FORMAT_A24u40_A14u32_B8_C8] = { 5, 256 }, - [XE_OAM_FORMAT_MPEC8u64_B8_C8] = { 1, 192, TYPE_OAM, HDR_64_BIT }, - [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, TYPE_OAM, HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u64_B8_C8] = { 1, 192, XE_OA_FMT_TYPE_OAM_MPEC, HDR_64_BIT }, + [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, XE_OA_FMT_TYPE_OAM_MPEC, HDR_64_BIT }, };struct xe_oa_open_properties {@@ -65,7 +65,7 @@ struct xe_oa_open_properties {u64 exec_q_id;int metrics_set; -int oa_format; +enum xe_oa_format_name oa_format;bool oa_periodic;int oa_period_exponent;@@ -1529,13 +1529,6 @@ static u64 oa_exponent_to_ns(struct xe_oa *oa, int exponent)return div_u64 (nom + den -1 , den); } -static bool oa_format_valid (struct xe_oa *oa,u64 format) -{ -if (format >=XE_OA_FORMAT_MAX ) -return false; -return test_bit (format, oa->format_mask); -} -static bool engine_supports_oa (const struct xe_hw_engine *hwe) {return hwe->oa_group;@@ -1543,7 +1536,32 @@ static bool engine_supports_oa(const struct xe_hw_engine *hwe)static bool engine_supports_oa_format (const struct xe_hw_engine *hwe,int type) { -return hwe->oa_group && hwe->oa_group->type == type; +switch (hwe->oa_group->type) { +case TYPE_OAG : +return type ==XE_OA_FMT_TYPE_OAG || type ==XE_OA_FMT_TYPE_OAR ; +case TYPE_OAM : +return type ==XE_OA_FMT_TYPE_OAM || type ==XE_OA_FMT_TYPE_OAM_MPEC ; +default : +return false; + } +} + +static int decode_oa_format (struct xe_oa *oa,u64 prop,enum xe_oa_format_name *name) +{ +u32 counter_sel =FIELD_GET (XE_OA_MASK_COUNTER_SEL , prop); +u32 type =FIELD_GET (XE_OA_MASK_FMT_TYPE , prop); +int idx; + +for_each_set_bit (idx, oa->format_mask,XE_OA_FORMAT_MAX ) { +const struct xe_oa_format *f = &oa->oa_formats[idx]; + +if (type == f->type && counter_sel == f->format) { + *name = idx; +return 0 ; + } + } + +return -EINVAL ; }#define OA_EXPONENT_MAX 31@@ -1600,12 +1618,12 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, props->metrics_set = value;break ;case DRM_XE_OA_PROP_OA_FORMAT : -if (!oa_format_valid (oa, value)) { -drm_dbg (&oa->xe->drm,"Unsupported OA report format %llu\n" , + ret =decode_oa_format (oa, value, &props->oa_format); +if (ret) { +drm_dbg (&oa->xe->drm,"Unsupported OA report format %#llx\n" , value); -return -EINVAL ; +return ret; } - props->oa_format = value;break ;case DRM_XE_OA_PROP_OA_EXPONENT :if (value >OA_EXPONENT_MAX ) {@@ -2227,7 +2245,7 @@ u16 xe_oa_unit_id(struct xe_hw_engine *hwe) hwe->oa_group->oa_unit_id : U16_MAX; } -static void oa_format_add (struct xe_oa *oa,enum drm_xe_oa_format format) +static void oa_format_add (struct xe_oa *oa,enum xe_oa_format_name format) {__set_bit (format, oa->format_mask); }drivers/gpu/drm/xe/xe_oa_types.h +21
-2@@ -24,7 +24,7 @@ enum { OA_GROUP_INVALID = U32_MAX, }; -enum oa_type { +enum oa_unit_type {TYPE_OAG ,TYPE_OAM , };@@ -34,6 +34,25 @@ enum report_header { HDR_64_BIT, }; +enum xe_oa_format_name { +XE_OA_FORMAT_C4_B8 =7 , + +/* Gen8+ */ +XE_OA_FORMAT_A12 , +XE_OA_FORMAT_A12_B8_C8 , + XE_OA_FORMAT_A32u40_A4u32_B8_C8, + +/* DG2 */ + XE_OAR_FORMAT_A32u40_A4u32_B8_C8, + XE_OA_FORMAT_A24u40_A14u32_B8_C8, + +/* MTL OAM */ + XE_OAM_FORMAT_MPEC8u64_B8_C8, + XE_OAM_FORMAT_MPEC8u32_B8_C8, + +XE_OA_FORMAT_MAX , +}; +struct xe_oa_format {u32 format;int size;@@ -96,7 +115,7 @@ struct xe_oa_group {struct xe_oa_regs regs;/** @type: Type of OA unit - OAM, OAG etc. */ -enum oa_type type; +enum oa_unit_type type; };/** include/uapi/drm/xe_drm.h +16
-18@@ -1124,23 +1124,13 @@ struct drm_xe_perf_param {__u64 param; }; -enum drm_xe_oa_format { -XE_OA_FORMAT_C4_B8 =7 , - -/* Gen8+ */ -XE_OA_FORMAT_A12 , -XE_OA_FORMAT_A12_B8_C8 , - XE_OA_FORMAT_A32u40_A4u32_B8_C8, - -/* DG2 */ - XE_OAR_FORMAT_A32u40_A4u32_B8_C8, - XE_OA_FORMAT_A24u40_A14u32_B8_C8, - -/* MTL OAM */ - XE_OAM_FORMAT_MPEC8u64_B8_C8, - XE_OAM_FORMAT_MPEC8u32_B8_C8, - -XE_OA_FORMAT_MAX /* non-ABI */ +enum drm_xe_oa_format_type { +XE_OA_FMT_TYPE_OAG , +XE_OA_FMT_TYPE_OAR , +XE_OA_FMT_TYPE_OAM , +XE_OA_FMT_TYPE_OAC , +XE_OA_FMT_TYPE_OAM_MPEC , +XE_OA_FMT_TYPE_PEC , };enum drm_xe_oa_property_id {@@ -1167,6 +1157,15 @@ enum drm_xe_oa_property_id {* The value specifies the size and layout of OA unit reports. */ DRM_XE_OA_PROP_OA_FORMAT, +/** +* OA_FORMAT's are specified the same way as in Bspec, in terms of +* the following quantities: a. enum @drm_xe_oa_format_type +* b. Counter select c. Counter size and d. BC report +*/ +#define XE_OA_MASK_FMT_TYPE (0xff << 0) +#define XE_OA_MASK_COUNTER_SEL (0xff << 8) +#define XE_OA_MASK_COUNTER_SIZE (0xff << 16) +#define XE_OA_MASK_BC_REPORT (0xff << 24)/** * Specifying this property implicitly requests periodic OA unit -- 2.41.0
PATCH 16/21 drm/xe/oa: Make xe_oa_timestamp_frequency per gt
In reply to Ashutosh DixitClock freq's can be different for different gt's.
--- drivers/gpu/drm/xe/xe_oa.c | 44 +++++++++++++++++------------------ drivers/gpu/drm/xe/xe_oa.h | 2 +- drivers/gpu/drm/xe/xe_query.c | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +22 -22
@@ -1496,7 +1496,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,* platforms OA unit ignores the CTC_SHIFT and the 2 timestamps differ. In such * cases, return the adjusted CS timestamp frequency to the user. */ -u32 xe_oa_timestamp_frequency (struct xe_device *xe) +u32 xe_oa_timestamp_frequency (struct xe_gt *gt) {u32 reg, shift;
@@ -1505,26 +1505,26 @@ u32 xe_oa_timestamp_frequency(struct xe_device *xe)* Wa_14015568240:pvc * Wa_14015846243:mtl */ -switch (xe->info.platform) { +switch (gt->tile->xe->info.platform) {case XE_DG2 :case XE_PVC :case XE_METEORLAKE : -xe_device_mem_access_get (xe); - reg =xe_mmio_read32 (xe_root_mmio_gt (xe),RPM_CONFIG0 ); -xe_device_mem_access_put (xe); +xe_device_mem_access_get (gt->tile->xe); + reg =xe_mmio_read32 (gt,RPM_CONFIG0 ); +xe_device_mem_access_put (gt->tile->xe); shift =REG_FIELD_GET (RPM_CONFIG0_CTC_SHIFT_PARAMETER_MASK , reg); -return xe_root_mmio_gt (xe)->info.clock_freq << (3 - shift); +return gt->info.clock_freq << (3 - shift);default : -return xe_root_mmio_gt (xe)->info.clock_freq; +return gt->info.clock_freq; } } -static u64 oa_exponent_to_ns (struct xe_oa *oa,int exponent) +static u64 oa_exponent_to_ns (struct xe_gt *gt,int exponent) {u64 nom = (2ULL << exponent) *NSEC_PER_SEC ; -u32 den =xe_oa_timestamp_frequency (oa->xe); +u32 den =xe_oa_timestamp_frequency (gt);return div_u64 (nom + den -1 , den); }
@@ -1591,7 +1591,6 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, instance =0 ;for (i =0 ; i < n_props; i++) { -u64 oa_period, oa_freq_hz;u64 id, value; ret =get_user (id, uprop);
@@ -1631,18 +1630,6 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, OA_EXPONENT_MAX);return -EINVAL ; } - -BUILD_BUG_ON (sizeof (oa_period) !=8 ); - oa_period =oa_exponent_to_ns (oa, value); - - oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period); -if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { -drm_dbg (&oa->xe->drm, -"OA exponent would exceed the max sampling frequency (sysctl dev.xe.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n" , - xe_oa_max_sample_rate); -return -EACCES ; - } - props->oa_periodic = true; props->oa_period_exponent = value;break ;
@@ -1701,6 +1688,19 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops,return -EINVAL ; } +if (props->oa_periodic) { +u64 oa_period, oa_freq_hz; + + oa_period =oa_exponent_to_ns (props->hwe->gt, props->oa_period_exponent); + oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period); +if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm, +"OA exponent would exceed the max sampling frequency (sysctl dev.xe.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n" , + xe_oa_max_sample_rate); +return -EACCES ; + } + } +return 0 ; }
drivers/gpu/drm/xe/xe_oa.h +1 -1
@@ -22,7 +22,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data, struct drm_file *file);int xe_oa_remove_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); -u32 xe_oa_timestamp_frequency (struct xe_device *xe); +u32 xe_oa_timestamp_frequency (struct xe_gt *gt);u16 xe_oa_unit_id (struct xe_hw_engine *hwe);#endif
drivers/gpu/drm/xe/xe_query.c +1 -1
@@ -244,7 +244,7 @@ static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) gts->gts[id].type =XE_QUERY_GT_TYPE_MAIN ; gts->gts[id].instance = id; gts->gts[id].clock_freq = gt->info.clock_freq; - gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (xe); + gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (gt);if (!IS_DGFX (xe)) gts->gts[id].native_mem_regions =0x1 ;else
Signature · 1 line
2.41.0
Rodrigo Vivi
maintainerRe: [Intel-xe] [PATCH 16/21] drm/xe/oa: Make xe_oa_timestamp_frequency per gt
Quoted 123 lines · Ashutosh Dixit
Clock freq's can be different for different gt's.
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>--- drivers/gpu/drm/xe/xe_oa.c | 44 +++++++++++++++++------------------ drivers/gpu/drm/xe/xe_oa.h | 2 +- drivers/gpu/drm/xe/xe_query.c | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-)drivers/gpu/drm/xe/xe_oa.c +22
-22@@ -1496,7 +1496,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,* platforms OA unit ignores the CTC_SHIFT and the 2 timestamps differ. In such * cases, return the adjusted CS timestamp frequency to the user. */ -u32 xe_oa_timestamp_frequency (struct xe_device *xe) +u32 xe_oa_timestamp_frequency (struct xe_gt *gt) {u32 reg, shift;@@ -1505,26 +1505,26 @@ u32 xe_oa_timestamp_frequency(struct xe_device *xe)* Wa_14015568240:pvc * Wa_14015846243:mtl */ -switch (xe->info.platform) { +switch (gt->tile->xe->info.platform) {case XE_DG2 :case XE_PVC :case XE_METEORLAKE : -xe_device_mem_access_get (xe); - reg =xe_mmio_read32 (xe_root_mmio_gt (xe),RPM_CONFIG0 ); -xe_device_mem_access_put (xe); +xe_device_mem_access_get (gt->tile->xe); + reg =xe_mmio_read32 (gt,RPM_CONFIG0 ); +xe_device_mem_access_put (gt->tile->xe); shift =REG_FIELD_GET (RPM_CONFIG0_CTC_SHIFT_PARAMETER_MASK , reg); -return xe_root_mmio_gt (xe)->info.clock_freq << (3 - shift); +return gt->info.clock_freq << (3 - shift);default : -return xe_root_mmio_gt (xe)->info.clock_freq; +return gt->info.clock_freq; } } -static u64 oa_exponent_to_ns (struct xe_oa *oa,int exponent) +static u64 oa_exponent_to_ns (struct xe_gt *gt,int exponent) {u64 nom = (2ULL << exponent) *NSEC_PER_SEC ; -u32 den =xe_oa_timestamp_frequency (oa->xe); +u32 den =xe_oa_timestamp_frequency (gt);return div_u64 (nom + den -1 , den); }@@ -1591,7 +1591,6 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, instance =0 ;for (i =0 ; i < n_props; i++) { -u64 oa_period, oa_freq_hz;u64 id, value; ret =get_user (id, uprop);@@ -1631,18 +1630,6 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, OA_EXPONENT_MAX);return -EINVAL ; } - -BUILD_BUG_ON (sizeof (oa_period) !=8 ); - oa_period =oa_exponent_to_ns (oa, value); - - oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period); -if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { -drm_dbg (&oa->xe->drm, -"OA exponent would exceed the max sampling frequency (sysctl dev.xe.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n" , - xe_oa_max_sample_rate); -return -EACCES ; - } - props->oa_periodic = true; props->oa_period_exponent = value;break ;@@ -1701,6 +1688,19 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops,return -EINVAL ; } +if (props->oa_periodic) { +u64 oa_period, oa_freq_hz; + + oa_period =oa_exponent_to_ns (props->hwe->gt, props->oa_period_exponent); + oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period); +if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm, +"OA exponent would exceed the max sampling frequency (sysctl dev.xe.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n" , + xe_oa_max_sample_rate); +return -EACCES ; + } + } +return 0 ; }drivers/gpu/drm/xe/xe_oa.h +1
-1@@ -22,7 +22,7 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, void *data, struct drm_file *file);int xe_oa_remove_config_ioctl (struct drm_device *dev,void *data,struct drm_file *file); -u32 xe_oa_timestamp_frequency (struct xe_device *xe); +u32 xe_oa_timestamp_frequency (struct xe_gt *gt);u16 xe_oa_unit_id (struct xe_hw_engine *hwe);#endif drivers/gpu/drm/xe/xe_query.c +0
-0
drivers/gpu/drm/xe/xe_query.c static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) · line 246
Quoted 3 lines
drivers/gpu/drm/xe/xe_query.c +0
-0@@ -244,7 +244,7 @@ static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) gts->gts[id].type =XE_QUERY_GT_TYPE_MAIN ; gts->gts[id].instance = id; gts->gts[id].clock_freq = gt->info.clock_freq;
first look it here ^
drivers/gpu/drm/xe/xe_query.c static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) · line 247
Quoted 2 lines
drivers/gpu/drm/xe/xe_query.c +1
-1- gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (xe); + gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (gt);
Then please notice that we are trying to kill the duplications on the uapi [1] and now notice that this series is adding yet another duplication:
+u32 xe_oa_timestamp_frequency(struct xe_gt *gt)
+ return gt->info.clock_freq;
(copied from above)
Quoted 6 lines
drivers/gpu/drm/xe/xe_query.c +0
-0if (!IS_DGFX (xe)) gts->gts[id].native_mem_regions =0x1 ;else Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 16/21] drm/xe/oa: Make xe_oa_timestamp_frequency per gt
Quoted 1 line · Rodrigo Vivi
Hi Rodrigo,
Quoted 44 lines · Ashutosh Dixit
Quoted 43 lines
Clock freq's can be different for different gt's.
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>--- drivers/gpu/drm/xe/xe_oa.c | 44 +++++++++++++++++------------------ drivers/gpu/drm/xe/xe_oa.h | 2 +- drivers/gpu/drm/xe/xe_query.c | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-)drivers/gpu/drm/xe/xe_oa.c +6
-6@@ -1496,7 +1496,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,* platforms OA unit ignores the CTC_SHIFT and the 2 timestamps differ. In such * cases, return the adjusted CS timestamp frequency to the user. */ -u32 xe_oa_timestamp_frequency (struct xe_device *xe) +u32 xe_oa_timestamp_frequency (struct xe_gt *gt) {u32 reg, shift;@@ -1505,26 +1505,26 @@ u32 xe_oa_timestamp_frequency(struct xe_device *xe)* Wa_14015568240:pvc * Wa_14015846243:mtl */ -switch (xe->info.platform) { +switch (gt->tile->xe->info.platform) {case XE_DG2 :case XE_PVC :case XE_METEORLAKE : -xe_device_mem_access_get (xe); - reg =xe_mmio_read32 (xe_root_mmio_gt (xe),RPM_CONFIG0 ); -xe_device_mem_access_put (xe); +xe_device_mem_access_get (gt->tile->xe); + reg =xe_mmio_read32 (gt,RPM_CONFIG0 ); +xe_device_mem_access_put (gt->tile->xe); shift =REG_FIELD_GET (RPM_CONFIG0_CTC_SHIFT_PARAMETER_MASK , reg); -return xe_root_mmio_gt (xe)->info.clock_freq << (3 - shift); +return gt->info.clock_freq << (3 - shift);
Quoted 5 lines
drivers/gpu/drm/xe/xe_oa.c u32 xe_oa_timestamp_frequency(struct xe_device *xe) · line 1522
Quoted 5 lines
drivers/gpu/drm/xe/xe_oa.c +1
-1default : -return xe_root_mmio_gt (xe)->info.clock_freq; +return gt->info.clock_freq; } }
/snip/
Quoted 21 lines
drivers/gpu/drm/xe/xe_query.c static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) · line 246
Quoted 8 lines
drivers/gpu/drm/xe/xe_query.c +0
-0@@ -244,7 +244,7 @@ static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) gts->gts[id].type =XE_QUERY_GT_TYPE_MAIN ; gts->gts[id].instance = id; gts->gts[id].clock_freq = gt->info.clock_freq;first look it here ^
drivers/gpu/drm/xe/xe_query.c static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) · line 247
Quoted 2 lines
drivers/gpu/drm/xe/xe_query.c +1
-1- gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (xe); + gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (gt);Then please notice that we are trying to kill the duplications on the uapi [1] and now notice that this series is adding yet another duplication:
(quoted diff) +2
-0+u32 xe_oa_timestamp_frequency(struct xe_gt *gt) + return gt->info.clock_freq;(copied from above)
Quoted 1 line
Well it's duplicated on some platforms but not on others. If it helps, there is another proposal which will move all OA related information (including oa_timestamp_freq) into a separate drm_xe_query_oa_info struct (so out of the current uapi struct's into drm_xe_query_oa_info). See:
https://patchwork.freedesktop.org/patch/558367/?series=121084&rev=6
Thanks.
--
Ashutosh
Rodrigo Vivi
maintainerRe: [Intel-xe] [PATCH 16/21] drm/xe/oa: Make xe_oa_timestamp_frequency per gt
Quoted 74 lines · Ashutosh
Quoted 1 line · Rodrigo Vivi
Hi Rodrigo,
Quoted 44 lines · Ashutosh Dixit
Quoted 43 lines
Clock freq's can be different for different gt's.
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>--- drivers/gpu/drm/xe/xe_oa.c | 44 +++++++++++++++++------------------ drivers/gpu/drm/xe/xe_oa.h | 2 +- drivers/gpu/drm/xe/xe_query.c | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-)drivers/gpu/drm/xe/xe_oa.c +6
-6@@ -1496,7 +1496,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,* platforms OA unit ignores the CTC_SHIFT and the 2 timestamps differ. In such * cases, return the adjusted CS timestamp frequency to the user. */ -u32 xe_oa_timestamp_frequency (struct xe_device *xe) +u32 xe_oa_timestamp_frequency (struct xe_gt *gt) {u32 reg, shift;@@ -1505,26 +1505,26 @@ u32 xe_oa_timestamp_frequency(struct xe_device *xe)* Wa_14015568240:pvc * Wa_14015846243:mtl */ -switch (xe->info.platform) { +switch (gt->tile->xe->info.platform) {case XE_DG2 :case XE_PVC :case XE_METEORLAKE : -xe_device_mem_access_get (xe); - reg =xe_mmio_read32 (xe_root_mmio_gt (xe),RPM_CONFIG0 ); -xe_device_mem_access_put (xe); +xe_device_mem_access_get (gt->tile->xe); + reg =xe_mmio_read32 (gt,RPM_CONFIG0 ); +xe_device_mem_access_put (gt->tile->xe); shift =REG_FIELD_GET (RPM_CONFIG0_CTC_SHIFT_PARAMETER_MASK , reg); -return xe_root_mmio_gt (xe)->info.clock_freq << (3 - shift); +return gt->info.clock_freq << (3 - shift);Quoted 5 lines
drivers/gpu/drm/xe/xe_oa.c u32 xe_oa_timestamp_frequency(struct xe_device *xe) · line 1522
Quoted 5 lines
drivers/gpu/drm/xe/xe_oa.c +1
-1default : -return xe_root_mmio_gt (xe)->info.clock_freq; +return gt->info.clock_freq; } }/snip/
Quoted 17 lines
drivers/gpu/drm/xe/xe_query.c static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) · line 246
Quoted 8 lines
drivers/gpu/drm/xe/xe_query.c +0
-0@@ -244,7 +244,7 @@ static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) gts->gts[id].type =XE_QUERY_GT_TYPE_MAIN ; gts->gts[id].instance = id; gts->gts[id].clock_freq = gt->info.clock_freq;first look it here ^
drivers/gpu/drm/xe/xe_query.c static int query_gts(struct xe_device *xe, struct drm_xe_device_query *query) · line 247
Quoted 2 lines
drivers/gpu/drm/xe/xe_query.c +1
-1- gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (xe); + gts->gts[id].oa_timestamp_freq =xe_oa_timestamp_frequency (gt);Then please notice that we are trying to kill the duplications on the uapi [1] and now notice that this series is adding yet another duplication:
Quoted 7 lines
Quoted 5 lines
(quoted diff) +2
-0+u32 xe_oa_timestamp_frequency(struct xe_gt *gt) + return gt->info.clock_freq;(copied from above)
Well it's duplicated on some platforms but not on others.
Oh, I see now. Thanks for the explanation.
Quoted 6 lines
If it helps,
there is another proposal which will move all OA related information (includingoa_timestamp_freq) into a separatedrm_xe_query_oa_infostruct (so out of the current uapi struct's intodrm_xe_query_oa_info). See:https://patchwork.freedesktop.org/patch/558367/?series=121084&rev=6
yeap, the individual query looks good.
Quoted 4 lines
Thanks.
--
Ashutosh
PATCH 17/21 drm/xe/oa: Remove filtering reports on context id
In reply to Ashutosh DixitAt present XE OA code does not obtain context id's from GuC. Even if these context id's were available it is not clear if included reports for userspace should be filtered on context id's. Till these issues are resolved remove filtering reports based on context id's.
--- drivers/gpu/drm/xe/xe_oa.c | 33 +++----------------------------- drivers/gpu/drm/xe/xe_oa_types.h | 9 --------- 2 files changed, 3 insertions(+), 39 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +3 -30
@@ -184,13 +184,6 @@ static void oa_timestamp_clear(struct xe_oa_stream *stream, u32 *report) report[1 ] =0 ; } -static u32 oa_context_id (struct xe_oa_stream *stream,u32 *report) -{ -u32 ctx_id =oa_report_header_64bit (stream) ? report[4 ] : report[2 ]; - -return ctx_id & stream->specific_ctx_id_mask; -} -static void oa_context_id_squash (struct xe_oa_stream *stream,u32 *report) {if (oa_report_header_64bit (stream))
@@ -368,7 +361,7 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,for (;OA_TAKEN (tail, head); head = (head + report_size) & mask) {u8 *report = oa_buf_base + head; -u32 ctx_id, *report32 = (void *)report; +u32 *report32 = (void *)report;u64 reason;/*
@@ -379,7 +372,6 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* this field and it is valid to have a reason field of zero. */ reason =oa_report_reason (stream, report); - ctx_id =oa_context_id (stream, report32);/* * Squash whatever is in the CTX_ID field if it's marked as invalid to be
@@ -388,10 +380,8 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* Note: we don't clear the valid_ctx_bit so userspace can understand that * the ID has been squashed by the kernel. */ -if (oa_report_ctx_invalid (stream, report)) { - ctx_id =INVALID_CTX_ID ; +if (oa_report_ctx_invalid (stream, report))oa_context_id_squash (stream, report32); - }/* * NB: The OA unit does not support clock gating off for a specific
@@ -419,21 +409,10 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* since it's not-uncommon for periodic samples to identify a switch * before any 'context switch' report. */ -if (!stream->exec_q || stream->specific_ctx_id == ctx_id || - stream->oa_buffer.last_ctx_id == stream->specific_ctx_id || - reason &OAREPORT_REASON_CTX_SWITCH ) { -/* -* While filtering for a single context we avoid -* leaking the IDs of other contexts. -*/ -if (stream->exec_q && stream->specific_ctx_id != ctx_id) -oa_context_id_squash (stream, report32); - +if (!stream->exec_q || reason &OAREPORT_REASON_CTX_SWITCH ) { ret =xe_oa_append_sample (stream, buf, count, offset, report);if (ret)break ; - - stream->oa_buffer.last_ctx_id = ctx_id; }if (is_power_of_2 (report_size)) {
@@ -497,12 +476,6 @@ static void xe_oa_init_oa_buffer(struct xe_oa_stream *stream)/* Mark that we need updated tail pointers to read from... */ stream->oa_buffer.tail =0 ; -/* -* Reset state used to recognise context switches, affecting which reports we will -* forward to userspace while filtering for a single context. -*/ - stream->oa_buffer.last_ctx_id =INVALID_CTX_ID ; -spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags);/* Zero out the OA buffer since we rely on zero report id and timestamp fields */
drivers/gpu/drm/xe/xe_oa_types.h +0 -9
@@ -222,12 +222,6 @@ struct xe_oa_stream {*/ struct llist_head oa_config_bos; -/** @specific_ctx_id: id of the context used for filtering reports */ -u32 specific_ctx_id; - -/** @specific_ctx_id_mask: The mask used to masking specific_ctx_id bits */ -u32 specific_ctx_id_mask; -/** * @poll_check_timer: High resolution timer that will periodically * check for data in the circular OA buffer for notifying userspace
@@ -261,9 +255,6 @@ struct xe_oa_stream {/** @vaddr: mapped vaddr of the OA buffer */ u8 *vaddr; -/** @last_ctx_id: last context id for OA data added */ -u32 last_ctx_id; -/** * @ptr_lock: Locks reads and writes to all head/tail state *
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 17/21] drm/xe/oa: Remove filtering reports on context id
Quoted 7 lines · Ashutosh Dixit
At present XE OA code does not obtain context id's from GuC. Even if these context id's were available it is not clear if included reports for userspace should be filtered on context id's. Till these issues are resolved remove filtering reports based on context id's.
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>
For review, it would be easier to just drop whatever is not used rather than adding it in earlier patches and removing it later. I guess you want to highlight what has changed between i915 and Xe, but I guess we can review everything as new code and refer to i915 offline.
Thanks,
Umesh
Quoted 118 lines
---
drivers/gpu/drm/xe/xe_oa.c| 33 +++-----------------------------drivers/gpu/drm/xe/xe_oa_types.h| 9 ---------2 files changed, 3 insertions(+), 39 deletions(-)drivers/gpu/drm/xe/xe_oa.c +3
-30@@ -184,13 +184,6 @@ static void oa_timestamp_clear(struct xe_oa_stream *stream, u32 *report) report[1 ] =0 ; } -static u32 oa_context_id (struct xe_oa_stream *stream,u32 *report) -{ -u32 ctx_id =oa_report_header_64bit (stream) ? report[4 ] : report[2 ]; - -return ctx_id & stream->specific_ctx_id_mask; -} -static void oa_context_id_squash (struct xe_oa_stream *stream,u32 *report) {if (oa_report_header_64bit (stream))@@ -368,7 +361,7 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,for (;OA_TAKEN (tail, head); head = (head + report_size) & mask) {u8 *report = oa_buf_base + head; -u32 ctx_id, *report32 = (void *)report; +u32 *report32 = (void *)report;u64 reason;/* @@ -379,7 +372,6 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* this field and it is valid to have a reason field of zero. */ reason =oa_report_reason (stream, report); - ctx_id =oa_context_id (stream, report32);/* * Squash whatever is in the CTX_ID field if it's marked as invalid to be @@ -388,10 +380,8 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* Note: we don't clear the valid_ctx_bit so userspace can understand that * the ID has been squashed by the kernel. */ -if (oa_report_ctx_invalid (stream, report)) { - ctx_id =INVALID_CTX_ID ; +if (oa_report_ctx_invalid (stream, report))oa_context_id_squash (stream, report32); - }/* * NB: The OA unit does not support clock gating off for a specific @@ -419,21 +409,10 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* since it's not-uncommon for periodic samples to identify a switch * before any 'context switch' report. */ -if (!stream->exec_q || stream->specific_ctx_id == ctx_id || - stream->oa_buffer.last_ctx_id == stream->specific_ctx_id || - reason &OAREPORT_REASON_CTX_SWITCH ) { -/* -* While filtering for a single context we avoid -* leaking the IDs of other contexts. -*/ -if (stream->exec_q && stream->specific_ctx_id != ctx_id) -oa_context_id_squash (stream, report32); - +if (!stream->exec_q || reason &OAREPORT_REASON_CTX_SWITCH ) { ret =xe_oa_append_sample (stream, buf, count, offset, report);if (ret)break ; - - stream->oa_buffer.last_ctx_id = ctx_id; }if (is_power_of_2 (report_size)) {@@ -497,12 +476,6 @@ static void xe_oa_init_oa_buffer(struct xe_oa_stream *stream)/* Mark that we need updated tail pointers to read from... */ stream->oa_buffer.tail =0 ; -/* -* Reset state used to recognise context switches, affecting which reports we will -* forward to userspace while filtering for a single context. -*/ - stream->oa_buffer.last_ctx_id =INVALID_CTX_ID ; -spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags);/* Zero out the OA buffer since we rely on zero report id and timestamp fields */ drivers/gpu/drm/xe/xe_oa_types.h +0
-9@@ -222,12 +222,6 @@ struct xe_oa_stream {*/ struct llist_head oa_config_bos; -/** @specific_ctx_id: id of the context used for filtering reports */ -u32 specific_ctx_id; - -/** @specific_ctx_id_mask: The mask used to masking specific_ctx_id bits */ -u32 specific_ctx_id_mask; -/** * @poll_check_timer: High resolution timer that will periodically * check for data in the circular OA buffer for notifying userspace @@ -261,9 +255,6 @@ struct xe_oa_stream {/** @vaddr: mapped vaddr of the OA buffer */ u8 *vaddr; -/** @last_ctx_id: last context id for OA data added */ -u32 last_ctx_id; -/** * @ptr_lock: Locks reads and writes to all head/tail state * Signature · 1 line
2.41.0
Re: [Intel-xe] [17/21] drm/xe/oa: Remove filtering reports on context id
In reply to Ashutosh DixitQuoted 4 lines · Ashutosh Dixit
At present XE OA code does not obtain context id's from GuC. Even if these context id's were available it is not clear if included reports for userspace should be filtered on context id's. Till these issues are resolved remove filtering reports based on context id's.
If you're removing this, then the opening of the perf stream should always be a privileged operation.
I guess this also makes DRM_XE_OA_PROP_EXEC_QUEUE_ID useless?
It should probably be removed from the uapi.
-Lionel
Quoted 118 lines
Suggested-by Umesh Nerlige Ramappa<[email protected]>Signed-off-by Ashutosh Dixit<[email protected]>--- drivers/gpu/drm/xe/xe_oa.c | 33 +++----------------------------- drivers/gpu/drm/xe/xe_oa_types.h | 9 --------- 2 files changed, 3 insertions(+), 39 deletions(-)drivers/gpu/drm/xe/xe_oa.c +3
-30@@ -184,13 +184,6 @@ static void oa_timestamp_clear(struct xe_oa_stream *stream, u32 *report) report[1 ] =0 ; } -static u32 oa_context_id (struct xe_oa_stream *stream,u32 *report) -{ -u32 ctx_id =oa_report_header_64bit (stream) ? report[4 ] : report[2 ]; - -return ctx_id & stream->specific_ctx_id_mask; -} -static void oa_context_id_squash (struct xe_oa_stream *stream,u32 *report) {if (oa_report_header_64bit (stream))@@ -368,7 +361,7 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,for (;OA_TAKEN (tail, head); head = (head + report_size) & mask) {u8 *report = oa_buf_base + head; -u32 ctx_id, *report32 = (void *)report; +u32 *report32 = (void *)report;u64 reason;/* @@ -379,7 +372,6 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* this field and it is valid to have a reason field of zero. */ reason =oa_report_reason (stream, report); - ctx_id =oa_context_id (stream, report32);/* * Squash whatever is in the CTX_ID field if it's marked as invalid to be @@ -388,10 +380,8 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* Note: we don't clear the valid_ctx_bit so userspace can understand that * the ID has been squashed by the kernel. */ -if (oa_report_ctx_invalid (stream, report)) { - ctx_id =INVALID_CTX_ID ; +if (oa_report_ctx_invalid (stream, report))oa_context_id_squash (stream, report32); - }/* * NB: The OA unit does not support clock gating off for a specific @@ -419,21 +409,10 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* since it's not-uncommon for periodic samples to identify a switch * before any 'context switch' report. */ -if (!stream->exec_q || stream->specific_ctx_id == ctx_id || - stream->oa_buffer.last_ctx_id == stream->specific_ctx_id || - reason &OAREPORT_REASON_CTX_SWITCH ) { -/* -* While filtering for a single context we avoid -* leaking the IDs of other contexts. -*/ -if (stream->exec_q && stream->specific_ctx_id != ctx_id) -oa_context_id_squash (stream, report32); - +if (!stream->exec_q || reason &OAREPORT_REASON_CTX_SWITCH ) { ret =xe_oa_append_sample (stream, buf, count, offset, report);if (ret)break ; - - stream->oa_buffer.last_ctx_id = ctx_id; }if (is_power_of_2 (report_size)) {@@ -497,12 +476,6 @@ static void xe_oa_init_oa_buffer(struct xe_oa_stream *stream)/* Mark that we need updated tail pointers to read from... */ stream->oa_buffer.tail =0 ; -/* -* Reset state used to recognise context switches, affecting which reports we will -* forward to userspace while filtering for a single context. -*/ - stream->oa_buffer.last_ctx_id =INVALID_CTX_ID ; -spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags);/* Zero out the OA buffer since we rely on zero report id and timestamp fields */ drivers/gpu/drm/xe/xe_oa_types.h +0
-9@@ -222,12 +222,6 @@ struct xe_oa_stream {*/ struct llist_head oa_config_bos; -/** @specific_ctx_id: id of the context used for filtering reports */ -u32 specific_ctx_id; - -/** @specific_ctx_id_mask: The mask used to masking specific_ctx_id bits */ -u32 specific_ctx_id_mask; -/** * @poll_check_timer: High resolution timer that will periodically * check for data in the circular OA buffer for notifying userspace @@ -261,9 +255,6 @@ struct xe_oa_stream {/** @vaddr: mapped vaddr of the OA buffer */ u8 *vaddr; -/** @last_ctx_id: last context id for OA data added */ -u32 last_ctx_id; -/** * @ptr_lock: Locks reads and writes to all head/tail state *
Re: [Intel-xe] [17/21] drm/xe/oa: Remove filtering reports on context id
Quoted 9 lines · Lionel Landwerlin
On 19/09/2023 19:10, Ashutosh Dixit wrote:
At present XE OA code does not obtain context id's from GuC. Even if these context id's were available it is not clear if included reports for userspace should be filtered on context id's. Till these issues are resolved remove filtering reports based on context id's.
If you're removing this, then the opening of the perf stream should always be a privileged operation.
Maybe I didn't understand the filtering use case in i915 correctly.
The OA buffer access is/was always privileged. Filtering was only squashing out the irrelevant contexts in the OA buffer. However those squashed contexts are also copied over to the user buffer. My thought was to just return everything unsquashed since this is a privileged operation.
Quoted 4 lines
I guess this also makes
DRM_XE_OA_PROP_EXEC_QUEUE_IDuseless?It should probably be removed from the uapi.
DRM_XE_OA_PROP_EXEC_QUEUE_ID was still used to enable OAR on a specific context. If we drop this, we could enable it on all RCS instances. The problem comes when OAC is used. If there are multiple CCS instances on a tile, OAC can only be enabled on one instance.
Thanks,
Umesh
Quoted 127 lines
-Lionel
Suggested-by Umesh Nerlige Ramappa [1]<[email protected]>Signed-off-by Ashutosh Dixit [2]<[email protected]>--- drivers/gpu/drm/xe/xe_oa.c | 33 +++----------------------------- drivers/gpu/drm/xe/xe_oa_types.h | 9 --------- 2 files changed, 3 insertions(+), 39 deletions(-)drivers/gpu/drm/xe/xe_oa.c +3
-30@@ -184,13 +184,6 @@ static void oa_timestamp_clear(struct xe_oa_stream *stream, u32 *report) report[1 ] =0 ; } -static u32 oa_context_id (struct xe_oa_stream *stream,u32 *report) -{ -u32 ctx_id =oa_report_header_64bit (stream) ? report[4 ] : report[2 ]; - -return ctx_id & stream->specific_ctx_id_mask; -} -static void oa_context_id_squash (struct xe_oa_stream *stream,u32 *report) {if (oa_report_header_64bit (stream))@@ -368,7 +361,7 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,for (;OA_TAKEN (tail, head); head = (head + report_size) & mask) {u8 *report = oa_buf_base + head; -u32 ctx_id, *report32 = (void *)report; +u32 *report32 = (void *)report;u64 reason;/* @@ -379,7 +372,6 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* this field and it is valid to have a reason field of zero. */ reason =oa_report_reason (stream, report); - ctx_id =oa_context_id (stream, report32);/* * Squash whatever is in the CTX_ID field if it's marked as invalid to be @@ -388,10 +380,8 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* Note: we don't clear the valid_ctx_bit so userspace can understand that * the ID has been squashed by the kernel. */ -if (oa_report_ctx_invalid (stream, report)) { - ctx_id =INVALID_CTX_ID ; +if (oa_report_ctx_invalid (stream, report))oa_context_id_squash (stream, report32); - }/* * NB: The OA unit does not support clock gating off for a specific @@ -419,21 +409,10 @@ static int xe_oa_append_reports(struct xe_oa_stream *stream, char __user *buf,* since it's not-uncommon for periodic samples to identify a switch * before any 'context switch' report. */ -if (!stream->exec_q || stream->specific_ctx_id == ctx_id || - stream->oa_buffer.last_ctx_id == stream->specific_ctx_id || - reason &OAREPORT_REASON_CTX_SWITCH ) { -/* -* While filtering for a single context we avoid -* leaking the IDs of other contexts. -*/ -if (stream->exec_q && stream->specific_ctx_id != ctx_id) -oa_context_id_squash (stream, report32); - +if (!stream->exec_q || reason &OAREPORT_REASON_CTX_SWITCH ) { ret =xe_oa_append_sample (stream, buf, count, offset, report);if (ret)break ; - - stream->oa_buffer.last_ctx_id = ctx_id; }if (is_power_of_2 (report_size)) {@@ -497,12 +476,6 @@ static void xe_oa_init_oa_buffer(struct xe_oa_stream *stream)/* Mark that we need updated tail pointers to read from... */ stream->oa_buffer.tail =0 ; -/* -* Reset state used to recognise context switches, affecting which reports we will -* forward to userspace while filtering for a single context. -*/ - stream->oa_buffer.last_ctx_id =INVALID_CTX_ID ; -spin_unlock_irqrestore (&stream->oa_buffer.ptr_lock, flags);/* Zero out the OA buffer since we rely on zero report id and timestamp fields */ drivers/gpu/drm/xe/xe_oa_types.h +0
-9@@ -222,12 +222,6 @@ struct xe_oa_stream {*/ struct llist_head oa_config_bos; -/** @specific_ctx_id: id of the context used for filtering reports */ -u32 specific_ctx_id; - -/** @specific_ctx_id_mask: The mask used to masking specific_ctx_id bits */ -u32 specific_ctx_id_mask; -/** * @poll_check_timer: High resolution timer that will periodically * check for data in the circular OA buffer for notifying userspace @@ -261,9 +255,6 @@ struct xe_oa_stream {/** @vaddr: mapped vaddr of the OA buffer */ u8 *vaddr; -/** @last_ctx_id: last context id for OA data added */ -u32 last_ctx_id; -/** * @ptr_lock: Locks reads and writes to all head/tail state * References
Visible links
1. mailto:[email protected]
2. mailto:[email protected]
PATCH 18/21 drm/xe/uapi: More OA uapi fixes/additions
In reply to Ashutosh Dixit- Add drm_xe_query_oa_info to query information about OA units
- Discontinue DRM_XE_OA_PROP_GLOBAL_SSEU since it is no longer needed
- Add DRM_XE_OA_PROP_OA_BUFFER_SIZE to configure OA buffer size
- Add output parameter 'config_syncobj' to signal userland when stream configuration is complete.
- Add extensions field to structs to make structs future extensible
The implementation of these uapi features will follow later. At present the emphasis is to finalize the uapi header.
--- include/uapi/drm/xe_drm.h | 72 +++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-)
include/uapi/drm/xe_drm.h +66 -6
@@ -395,6 +395,7 @@ struct drm_xe_device_query {#define DRM_XE_DEVICE_QUERY_GTS 3#define DRM_XE_DEVICE_QUERY_HWCONFIG 4#define DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 5 +#define DRM_XE_DEVICE_QUERY_OA_INFO 6/** @query: The type of data to query */ __u32 query;
@@ -1133,6 +1134,48 @@ enum drm_xe_oa_format_type { XE_OA_FMT_TYPE_PEC, }; +/** +* struct drm_xe_query_oa_info - describe OA units +* +* If a query is made with a struct drm_xe_device_query where .query +* is equal to DRM_XE_DEVICE_QUERY_OA_INFO, then the reply uses struct +* drm_xe_query_oa_info in .data. +*/ +struct drm_xe_query_oa_info { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @oa_unit_count: number of OA units returned in oau[] */ +__u32 oa_unit_count; + +/** @pad: MBZ */ +__u32 pad; + +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @oau: OA units returned for this device */ +struct drm_xe_query_oa_unit { +/** @oa_unit_id: OA unit ID */ +__u16 oa_unit_id; + +/** @gt_id: GT ID for this OA unit */ +__u16 gt_id; + +/** @pad: MBZ */ +__u32 pad; + +/** @oa_timestamp_freq: OA timestamp freq */ +__u64 oa_timestamp_freq; + +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @eci: engines attached to this OA unit */ +struct drm_xe_engine_class_instance eci[]; + } oau[]; +}; +enum drm_xe_oa_property_id {/** * Open the stream for a specific exec queue id (as used with
@@ -1185,13 +1228,11 @@ enum drm_xe_oa_property_id {DRM_XE_OA_PROP_HOLD_PREEMPTION ,/** -* Specifying this pins all contexts to the specified SSEU power -* configuration for the duration of the recording. -* -* This parameter's value is a pointer to a struct -* drm_xe_gem_context_param_sseu (TBD). +* Specify a global OA buffer size to be allocated in bytes. The +* size specified must be supported by HW (powers of 2 ranging from +* 128 KB to 128Mb depending on the platform) */ - DRM_XE_OA_PROP_GLOBAL_SSEU, + DRM_XE_OA_PROP_OA_BUFFER_SIZE,/** * This optional parameter specifies the timer interval in nanoseconds
@@ -1223,6 +1264,22 @@ enum drm_xe_oa_property_id { };struct drm_xe_oa_open_param { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** +* @config_syncobj: (Output) handle to configuration syncobj +* +* Handle to a syncobj which the kernel will signal after stream +* configuration or re-configuration is complete (after return from +* the ioctl). This handle can be provided as a dependency to the +* next XE exec ioctl. +*/ +__u32 config_syncobj; + +__u32 reserved; + +/** @flags: Flags */ __u32 flags;#define XE_OA_FLAG_FD_CLOEXEC (1 << 0)#define XE_OA_FLAG_FD_NONBLOCK (1 << 1)
@@ -1283,6 +1340,9 @@ enum drm_xe_oa_record_type { };struct drm_xe_oa_config { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; +/** * @uuid: *
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 18/21] drm/xe/uapi: More OA uapi fixes/additions
Quoted 5 lines · Ashutosh Dixit
struct
drm_xe_oa_open_param{include/uapi/drm/xe_drm.h +3
-0+/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; +
include/uapi/drm/xe_drm.h enum drm_xe_oa_property_id { · line 1279
Quoted 10 lines
include/uapi/drm/xe_drm.h +10
-0+/** +* @config_syncobj: (Output) handle to configuration syncobj +* +* Handle to a syncobj which the kernel will signal after stream +* configuration or re-configuration is complete (after return from +* the ioctl). This handle can be provided as a dependency to the +* next XE exec ioctl. +*/ +__u32 config_syncobj; +
I am reworking this fence part and will post this in the next rev. Please don't review this yet. Other uapi changes in this series can be reviewed now.
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 18/21] drm/xe/uapi: More OA uapi fixes/additions
In reply to Ashutosh DixitQuoted 7 lines · Ashutosh Dixit
include/uapi/drm/xe_drm.h +6
-0+/** +* struct drm_xe_query_oa_info - describe OA units +* +* If a query is made with a struct drm_xe_device_query where .query +* is equal to DRM_XE_DEVICE_QUERY_OA_INFO, then the reply uses struct +* drm_xe_query_oa_info in .data.
include/uapi/drm/xe_drm.h enum drm_xe_oa_format_type { · line 1152
Quoted 10 lines
include/uapi/drm/xe_drm.h +10
-0+*/ +struct drm_xe_query_oa_info { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @oa_unit_count: number of OA units returned in oau[] */ +__u32 oa_unit_count; + +/** @pad: MBZ */ +__u32 pad;
After discussions with Umesh, we will add a 'capabilities' bitmask here.
Umesh, could you please see if anything else should be added to this struct?
Thanks.
--
Ashutosh
Quoted 25 lines
include/uapi/drm/xe_drm.h +25
-0+ +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @oau: OA units returned for this device */ +struct drm_xe_query_oa_unit { +/** @oa_unit_id: OA unit ID */ +__u16 oa_unit_id; + +/** @gt_id: GT ID for this OA unit */ +__u16 gt_id; + +/** @pad: MBZ */ +__u32 pad; + +/** @oa_timestamp_freq: OA timestamp freq */ +__u64 oa_timestamp_freq; + +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @eci: engines attached to this OA unit */ +struct drm_xe_engine_class_instance eci[]; + } oau[]; +};
Re: [Intel-xe] [PATCH 18/21] drm/xe/uapi: More OA uapi fixes/additions
Quoted 21 lines · Ashutosh
Quoted 7 lines · Ashutosh Dixit
include/uapi/drm/xe_drm.h +6
-0+/** +* struct drm_xe_query_oa_info - describe OA units +* +* If a query is made with a struct drm_xe_device_query where .query +* is equal to DRM_XE_DEVICE_QUERY_OA_INFO, then the reply uses struct +* drm_xe_query_oa_info in .data. include/uapi/drm/xe_drm.h enum drm_xe_oa_format_type { · line 1152
Quoted 10 lines
include/uapi/drm/xe_drm.h +10
-0+*/ +struct drm_xe_query_oa_info { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @oa_unit_count: number of OA units returned in oau[] */ +__u32 oa_unit_count; + +/** @pad: MBZ */ +__u32 pad;After discussions with Umesh, we will add a 'capabilities' bitmask here.
Quoted 2 lines
Umesh, could you please see if anything else should be added to this struct?
Nothing that I can think of now.
Thanks,
Umesh
Quoted 30 lines
Thanks.
--
AshutoshQuoted 25 lines
include/uapi/drm/xe_drm.h +25
-0+ +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @oau: OA units returned for this device */ +struct drm_xe_query_oa_unit { +/** @oa_unit_id: OA unit ID */ +__u16 oa_unit_id; + +/** @gt_id: GT ID for this OA unit */ +__u16 gt_id; + +/** @pad: MBZ */ +__u32 pad; + +/** @oa_timestamp_freq: OA timestamp freq */ +__u64 oa_timestamp_freq; + +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @eci: engines attached to this OA unit */ +struct drm_xe_engine_class_instance eci[]; + } oau[]; +};
Re: [Intel-xe] [18/21] drm/xe/uapi: More OA uapi fixes/additions
In reply to Ashutosh DixitQuoted 100 lines · Ashutosh Dixit
- Add
drm_xe_query_oa_infoto query information about OA units
- DiscontinueDRM_XE_OA_PROP_GLOBAL_SSEUsince it is no longer needed
- AddDRM_XE_OA_PROP_OA_BUFFER_SIZEto configure OA buffer size
- Add output parameter 'config_syncobj' to signal userland when stream configuration is complete.
- Add extensions field to structs to make structs future extensibleThe implementation of these uapi features will follow later. At present the emphasis is to finalize the uapi header.
Signed-off-by Ashutosh Dixit <[email protected]>--- include/uapi/drm/xe_drm.h | 72 +++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-)include/uapi/drm/xe_drm.h +49
-6@@ -395,6 +395,7 @@ struct drm_xe_device_query {#define DRM_XE_DEVICE_QUERY_GTS 3#define DRM_XE_DEVICE_QUERY_HWCONFIG 4#define DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 5 +#define DRM_XE_DEVICE_QUERY_OA_INFO 6/** @query: The type of data to query */ __u32 query;@@ -1133,6 +1134,48 @@ enum drm_xe_oa_format_type { XE_OA_FMT_TYPE_PEC, }; +/** +* struct drm_xe_query_oa_info - describe OA units +* +* If a query is made with a struct drm_xe_device_query where .query +* is equal to DRM_XE_DEVICE_QUERY_OA_INFO, then the reply uses struct +* drm_xe_query_oa_info in .data. +*/ +struct drm_xe_query_oa_info { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** @oa_unit_count: number of OA units returned in oau[] */ +__u32 oa_unit_count; + +/** @pad: MBZ */ +__u32 pad; + +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @oau: OA units returned for this device */ +struct drm_xe_query_oa_unit { +/** @oa_unit_id: OA unit ID */ +__u16 oa_unit_id; + +/** @gt_id: GT ID for this OA unit */ +__u16 gt_id; + +/** @pad: MBZ */ +__u32 pad; + +/** @oa_timestamp_freq: OA timestamp freq */ +__u64 oa_timestamp_freq; + +/** @reserved: MBZ */ +__u64 reserved[4 ]; + +/** @eci: engines attached to this OA unit */ +struct drm_xe_engine_class_instance eci[]; + } oau[]; +}; +enum drm_xe_oa_property_id {/** * Open the stream for a specific exec queue id (as used with @@ -1185,13 +1228,11 @@ enum drm_xe_oa_property_id {DRM_XE_OA_PROP_HOLD_PREEMPTION ,/** -* Specifying this pins all contexts to the specified SSEU power -* configuration for the duration of the recording. -* -* This parameter's value is a pointer to a struct -* drm_xe_gem_context_param_sseu (TBD). +* Specify a global OA buffer size to be allocated in bytes. The +* size specified must be supported by HW (powers of 2 ranging from +* 128 KB to 128Mb depending on the platform) */ - DRM_XE_OA_PROP_GLOBAL_SSEU, + DRM_XE_OA_PROP_OA_BUFFER_SIZE,/** * This optional parameter specifies the timer interval in nanoseconds @@ -1223,6 +1264,22 @@ enum drm_xe_oa_property_id { };struct drm_xe_oa_open_param { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions;
include/uapi/drm/xe_drm.h enum drm_xe_oa_property_id { · line 1278
Quoted 10 lines
include/uapi/drm/xe_drm.h +10
-0+ +/** +* @config_syncobj: (Output) handle to configuration syncobj +* +* Handle to a syncobj which the kernel will signal after stream +* configuration or re-configuration is complete (after return from +* the ioctl). This handle can be provided as a dependency to the +* next XE exec ioctl. +*/ +__u32 config_syncobj;
So you're adding this, but there is no implementation for it?
Quoted 17 lines
include/uapi/drm/xe_drm.h +7
-0+ +__u32 reserved; + +/** @flags: Flags */ __u32 flags;#define XE_OA_FLAG_FD_CLOEXEC (1 << 0)#define XE_OA_FLAG_FD_NONBLOCK (1 << 1)@@ -1283,6 +1340,9 @@ enum drm_xe_oa_record_type { };struct drm_xe_oa_config { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; +/** * @uuid: *
Re: [Intel-xe] [18/21] drm/xe/uapi: More OA uapi fixes/additions
Quoted 16 lines · Lionel Landwerlin
Quoted 4 lines
struct drm_xe_oa_open_param {include/uapi/drm/xe_drm.h +2
-0+/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions;include/uapi/drm/xe_drm.h enum drm_xe_oa_property_id { · line 1278
Quoted 10 lines
include/uapi/drm/xe_drm.h +10
-0+ +/** +* @config_syncobj: (Output) handle to configuration syncobj +* +* Handle to a syncobj which the kernel will signal after stream +* configuration or re-configuration is complete (after return from +* the ioctl). This handle can be provided as a dependency to the +* next XE exec ioctl. +*/ +__u32 config_syncobj;So you're adding this, but there is no implementation for it?
Not yet, but there will be. Actually the plan is to do this:
struct drm_xe_oa_open_param {
/** @extensions: Pointer to the first extension struct, if any */
__u64 extensions;
/** @num_syncs: Amount of struct drm_xe_sync in array. */
__u32 num_syncs;
/** @syncs: Pointer to struct drm_xe_sync array. */
__u64 syncs;Which is exactly the same as what we see in drm_xe_vm_bind or drm_xe_exec. So the plan is to make perf_open behave exactly like an xe_exec which can be pipelined with other operations.
Re: [Intel-xe] [18/21] drm/xe/uapi: More OA uapi fixes/additions
Quoted 27 lines · Ashutosh
Quoted 6 lines · Lionel Landwerlin
Quoted 6 lines
struct drm_xe_oa_open_param {include/uapi/drm/xe_drm.h +5
-0+/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** +* @config_syncobj: (Output) handle to configuration syncobj Quoted 8 lines
include/uapi/drm/xe_drm.h enum drm_xe_oa_property_id { · line 1278
Quoted 7 lines
include/uapi/drm/xe_drm.h +7
-0+* +* Handle to a syncobj which the kernel will signal after stream +* configuration or re-configuration is complete (after return from +* the ioctl). This handle can be provided as a dependency to the +* next XE exec ioctl. +*/ +__u32 config_syncobj;So you're adding this, but there is no implementation for it?
Not yet, but there will be. Actually the plan is to do this:
struct drm_xe_oa_open_param { /** @extensions: Pointer to the first extension struct, if any */ __u64 extensions; /** @num_syncs: Amount of struct drm_xe_sync in array. */ __u32 num_syncs; /** @syncs: Pointer to struct drm_xe_sync array. */ __u64 syncs;
Quoted 3 lines
Which is exactly the same as what we see in
drm_xe_vm_bindordrm_xe_exec. So the plan is to makeperf_openbehave exactly like anxe_execwhich can be pipelined with other operations.
I don't think this is going to work because it means we have to close and reopen the stream every time we want to change the configuration.
It would need to be a separate ioctl on the perf file descriptor to be usable.
Otherwise we can't really pipeline anything since we have to drain the buffer until we can close it and reopen a new file descriptor.
-Lionel
Re: [Intel-xe] [18/21] drm/xe/uapi: More OA uapi fixes/additions
Quoted 1 line · Lionel Landwerlin
Hi Lionel,
Quoted 32 lines · Ashutosh
Quoted 27 lines · Lionel Landwerlin
Quoted 6 lines
Quoted 6 lines
struct drm_xe_oa_open_param {include/uapi/drm/xe_drm.h +5
-0+/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions; + +/** +* @config_syncobj: (Output) handle to configuration syncobj Quoted 8 lines
include/uapi/drm/xe_drm.h enum drm_xe_oa_property_id { · line 1278
Quoted 7 lines
include/uapi/drm/xe_drm.h +7
-0+* +* Handle to a syncobj which the kernel will signal after stream +* configuration or re-configuration is complete (after return from +* the ioctl). This handle can be provided as a dependency to the +* next XE exec ioctl. +*/ +__u32 config_syncobj;So you're adding this, but there is no implementation for it?
Not yet, but there will be. Actually the plan is to do this:
struct drm_xe_oa_open_param { /** @extensions: Pointer to the first extension struct, if any */ __u64 extensions; /** @num_syncs: Amount of struct drm_xe_sync in array. */ __u32 num_syncs; /** @syncs: Pointer to struct drm_xe_sync array. */ __u64 syncs;Quoted 3 lines
Which is exactly the same as what we see in
drm_xe_vm_bindordrm_xe_exec. So the plan is to makeperf_openbehave exactly like anxe_execwhich can be pipelined with other operations.
Quoted 5 lines
I don't think this is going to work because it means we have to close and reopen the stream every time we want to change the configuration.
It would need to be a separate ioctl on the perf file descriptor to be usable.
I didn't mention it, but the plan is the provide the same sync mechanism also on the perf fd stream reconfiguration ioctl.
Quoted 2 lines
Otherwise we can't really pipeline anything since we have to drain the buffer until we can close it and reopen a new file descriptor.
This I don't understand, since the disable-reconfigure-enable sequence on the perf fd also resets OA buffer head/tail pointers (lose contents of the OA buffer). So not sure why we don't need to "drain the buffer" in this case.
Of course, secretly I am hoping if it's possible to eliminate these disable-reconfigure-enable ioctl's on the perf fd and just do stream_close followed by reconfigure + stream_open. I don't quite understand why this is not possible.
Thanks.
--
Ashutosh
PATCH 19/21 drm/xe/uapi: Drop OA_IOCTL_VERSION
In reply to Ashutosh DixitOA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
For XE, we will track addition of new properties by means of xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.
--- drivers/gpu/drm/xe/xe_oa.c | 5 ----- drivers/gpu/drm/xe/xe_oa.h | 1 - drivers/gpu/drm/xe/xe_query.c | 1 - include/uapi/drm/xe_drm.h | 3 +-- 4 files changed, 1 insertion(+), 9 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +0 -5
@@ -2331,11 +2331,6 @@ static struct ctl_table oa_ctl_table[] = { {} }; -int xe_oa_ioctl_version (struct xe_device *xe) -{ -return 1 ; -} -int xe_oa_sysctl_register (void ) { sysctl_header =register_sysctl ("dev/xe" , oa_ctl_table);
drivers/gpu/drm/xe/xe_oa.h +0 -1
@@ -12,7 +12,6 @@ int xe_oa_init(struct xe_device *xe);void xe_oa_fini (struct xe_device *xe);void xe_oa_register (struct xe_device *xe);void xe_oa_unregister (struct xe_device *xe); -int xe_oa_ioctl_version (struct xe_device *xe);int xe_oa_sysctl_register (void );void xe_oa_sysctl_unregister (void );
drivers/gpu/drm/xe/xe_query.c +0 -1
@@ -202,7 +202,6 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)hweight_long (xe->info.mem_region_mask); config->info[XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY ] =xe_exec_queue_device_get_max_priority (xe); - config->info[XE_QUERY_OA_IOCTL_VERSION ] =xe_oa_ioctl_version (xe);if (copy_to_user (query_ptr, config, size)) {kfree (config);
include/uapi/drm/xe_drm.h +1 -2
@@ -259,8 +259,7 @@ struct drm_xe_query_config {#define XE_QUERY_CONFIG_GT_COUNT 4#define XE_QUERY_CONFIG_MEM_REGION_COUNT 5#define XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY 6 -#define XE_QUERY_OA_IOCTL_VERSION 7 -#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_OA_IOCTL_VERSION + 1) +#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY + 1)/** @info: array of elements containing the config info */ __u64 info[]; };
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
Quoted 4 lines · Ashutosh Dixit
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
This is not strictly true. E.g. AMD's include/uapi/linux/kfd_ioctl.h contains KFD_IOCTL_MAJOR_VERSION/KFD_IOCTL_MINOR_VERSION.
Quoted 4 lines
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.
But let's see if we need a version for OA or the kernel version itself is sufficient.
Quoted 3 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
Quoted 9 lines · Ashutosh
Quoted 4 lines · Ashutosh Dixit
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
This is not strictly true. E.g. AMD's
include/uapi/linux/kfd_ioctl.hcontains KFD_IOCTL_MAJOR_VERSION/KFD_IOCTL_MINOR_VERSION.
Quoted 11 lines
Quoted 4 lines
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.But let's see if we need a version for OA or the kernel version itself is sufficient.
Quoted 3 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>
ok, if there is precedence for a version, no harm adding it, but I agree that we should see if there are ways to do this with the generic OA query. For features that are added with extensions, it's taken care of inherently. Sometimes there are features that are internal to the implementation that the user might want to know. Those may need to be exposed via capabilities/flags in the generic oa/perf query.
Umesh
Quoted 4 lines
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
Quoted 20 lines · Umesh Nerlige Ramappa
Quoted 18 lines · Ashutosh
Quoted 4 lines · Ashutosh Dixit
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
This is not strictly true. E.g. AMD's
include/uapi/linux/kfd_ioctl.hcontains KFD_IOCTL_MAJOR_VERSION/KFD_IOCTL_MINOR_VERSION.Quoted 4 lines
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.But let's see if we need a version for OA or the kernel version itself is sufficient.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>ok, if there is precedence for a version, no harm adding it, but I agree that we should see if there are ways to do this with the generic OA query. For features that are added with extensions, it's taken care of inherently.
Afaiu, in this case userland is still relying on return codes from the kernel to discover available features, whereas a version or capability flags allow userland to know available features a priori without "discovery" by means of return codes.
Quoted 3 lines
Sometimes there are features that are internal to the implementation that the user might want to know. Those may need to be exposed via capabilities/flags in the generic oa/perf query.
I agree that capability flags do appear to be a better option than a version. But in i915 we could update the version without modifying the uapi header, which we cannot do if we have capability flags (we'd e.g. at least have to expose a new capability bit). Is modifying the uapi header a concern?
Both the version and capability flags can be easily included in the oa_info struct we are considering now.
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
Quoted 38 lines · Ashutosh
Quoted 20 lines · Umesh Nerlige Ramappa
Quoted 18 lines · Ashutosh
Quoted 4 lines · Ashutosh Dixit
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
This is not strictly true. E.g. AMD's
include/uapi/linux/kfd_ioctl.hcontains KFD_IOCTL_MAJOR_VERSION/KFD_IOCTL_MINOR_VERSION.Quoted 4 lines
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.But let's see if we need a version for OA or the kernel version itself is sufficient.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>ok, if there is precedence for a version, no harm adding it, but I agree that we should see if there are ways to do this with the generic OA query. For features that are added with extensions, it's taken care of inherently.
Afaiu, in this case userland is still relying on return codes from the kernel to discover available features, whereas a version or capability flags allow userland to know available features a priori without "discovery" by means of return codes.
Quoted 3 lines
Sometimes there are features that are internal to the implementation that the user might want to know. Those may need to be exposed via capabilities/flags in the generic oa/perf query.
Quoted 6 lines
I agree that capability flags do appear to be a better option than a version. But in i915 we could update the version without modifying the uapi header, which we cannot do if we have capability flags (we'd e.g. at least have to expose a new capability bit). Is modifying the uapi header a concern?
IMO, capability is still a uApi, so any such flags should be part of the header.
Thanks,
Umesh
Quoted 6 lines
Both the version and capability flags can be easily included in the
oa_infostruct we are considering now.Thanks.
--
Ashutosh
Re: [Intel-xe] [19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
In reply to Ashutosh DixitQuoted 8 lines · Ashutosh Dixit
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.
As a userspace driver this terrible.
You're making us write more code because we have to discover every single piece of implementation tweaks ever made to the kernel driver.
Yes OA version was an outlier in that it was better than the rest of kernel API.
By reading a single value we could make decisions about how to communicate with the kernel driver.
Having xe_user_extension here is not helping, we still have to fuzz our way around the kernel to figure out what feature level is available.
-Lionel
Quoted 64 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>--- drivers/gpu/drm/xe/xe_oa.c | 5 ----- drivers/gpu/drm/xe/xe_oa.h | 1 - drivers/gpu/drm/xe/xe_query.c | 1 - include/uapi/drm/xe_drm.h | 3 +-- 4 files changed, 1 insertion(+), 9 deletions(-)drivers/gpu/drm/xe/xe_oa.c +0
-5@@ -2331,11 +2331,6 @@ static struct ctl_table oa_ctl_table[] = { {} }; -int xe_oa_ioctl_version (struct xe_device *xe) -{ -return 1 ; -} -int xe_oa_sysctl_register (void ) { sysctl_header =register_sysctl ("dev/xe" , oa_ctl_table);drivers/gpu/drm/xe/xe_oa.h +0
-1@@ -12,7 +12,6 @@ int xe_oa_init(struct xe_device *xe);void xe_oa_fini (struct xe_device *xe);void xe_oa_register (struct xe_device *xe);void xe_oa_unregister (struct xe_device *xe); -int xe_oa_ioctl_version (struct xe_device *xe);int xe_oa_sysctl_register (void );void xe_oa_sysctl_unregister (void );drivers/gpu/drm/xe/xe_query.c +0
-1@@ -202,7 +202,6 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)hweight_long (xe->info.mem_region_mask); config->info[XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY ] =xe_exec_queue_device_get_max_priority (xe); - config->info[XE_QUERY_OA_IOCTL_VERSION ] =xe_oa_ioctl_version (xe);if (copy_to_user (query_ptr, config, size)) {kfree (config);include/uapi/drm/xe_drm.h +1
-2@@ -259,8 +259,7 @@ struct drm_xe_query_config {#define XE_QUERY_CONFIG_GT_COUNT 4#define XE_QUERY_CONFIG_MEM_REGION_COUNT 5#define XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY 6 -#define XE_QUERY_OA_IOCTL_VERSION 7 -#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_OA_IOCTL_VERSION + 1) +#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY + 1)/** @info: array of elements containing the config info */ __u64 info[]; };
Re: [Intel-xe] [19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
Quoted 13 lines · Lionel Landwerlin
Quoted 8 lines · Ashutosh Dixit
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.As a userspace driver this terrible.
Quoted 8 lines
You're making us write more code because we have to discover every single piece of implementation tweaks ever made to the kernel driver.
Yes OA version was an outlier in that it was better than the rest of kernel API.
By reading a single value we could make decisions about how to communicate with the kernel driver.
Having
xe_user_extensionhere is not helping, we still have to fuzz our way around the kernel to figure out what feature level is available.
Hi Lionel, Ashutosh,
I don't want to change interfaces to make it more difficult for the UMDs. Do you think capabilities could help achieve what you want? We could have a bitmask of feature availability and the bitmask could be part of the xe oa query.
If that's seen as an unnecessary uApi impact, then I am ok with version being returned in the oa info query.
My primary concerns with the version in i915 were
(1) version bumps would need documentation even when version bump did not have explicit uApi change. I couldn't find a good place in i915_drm.h to put such documentation. I think capabilities would be self documenting and it would be explicitly added to the uApi header.
(2) sometimes before upstreaming a feature, we maintained an internal version for the feature that was using a different range of versions. This would cause some grief when rebasing since the versions need to be increasing in the order of commits. If we had a bitmask, we can manage it better since there is no need to have an increasing value.
Suggestions welcome.
Thanks,
Umesh
Quoted 67 lines
-Lionel
Quoted 61 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>--- drivers/gpu/drm/xe/xe_oa.c | 5 ----- drivers/gpu/drm/xe/xe_oa.h | 1 - drivers/gpu/drm/xe/xe_query.c | 1 - include/uapi/drm/xe_drm.h | 3 +-- 4 files changed, 1 insertion(+), 9 deletions(-)drivers/gpu/drm/xe/xe_oa.c +0
-5@@ -2331,11 +2331,6 @@ static struct ctl_table oa_ctl_table[] = { {} }; -int xe_oa_ioctl_version (struct xe_device *xe) -{ -return 1 ; -} -int xe_oa_sysctl_register (void ) { sysctl_header =register_sysctl ("dev/xe" , oa_ctl_table);drivers/gpu/drm/xe/xe_oa.h +0
-1@@ -12,7 +12,6 @@ int xe_oa_init(struct xe_device *xe);void xe_oa_fini (struct xe_device *xe);void xe_oa_register (struct xe_device *xe);void xe_oa_unregister (struct xe_device *xe); -int xe_oa_ioctl_version (struct xe_device *xe);int xe_oa_sysctl_register (void );void xe_oa_sysctl_unregister (void );drivers/gpu/drm/xe/xe_query.c +0
-1@@ -202,7 +202,6 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)hweight_long (xe->info.mem_region_mask); config->info[XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY ] =xe_exec_queue_device_get_max_priority (xe); - config->info[XE_QUERY_OA_IOCTL_VERSION ] =xe_oa_ioctl_version (xe);if (copy_to_user (query_ptr, config, size)) {kfree (config);include/uapi/drm/xe_drm.h +1
-2@@ -259,8 +259,7 @@ struct drm_xe_query_config {#define XE_QUERY_CONFIG_GT_COUNT 4#define XE_QUERY_CONFIG_MEM_REGION_COUNT 5#define XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY 6 -#define XE_QUERY_OA_IOCTL_VERSION 7 -#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_OA_IOCTL_VERSION + 1) +#define XE_QUERY_CONFIG_NUM_PARAM (XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY + 1)/** @info: array of elements containing the config info */ __u64 info[]; };
Re: [Intel-xe] [19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh/Lionel,
Quoted 49 lines · Lionel Landwerlin
Quoted 19 lines · Ashutosh Dixit
Quoted 8 lines
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.As a userspace driver this terrible.
You're making us write more code because we have to discover every single piece of implementation tweaks ever made to the kernel driver.
Yes OA version was an outlier in that it was better than the rest of kernel API.
Quoted 6 lines
By reading a single value we could make decisions about how to communicate with the kernel driver.
Having
xe_user_extensionhere is not helping, we still have to fuzz our way around the kernel to figure out what feature level is available.Hi Lionel, Ashutosh,
I don't want to change interfaces to make it more difficult for the UMDs. Do you think capabilities could help achieve what you want? We could have a bitmask of feature availability and the bitmask could be part of the xe oa query.
If that's seen as an unnecessary uApi impact, then I am ok with version being returned in the oa info query.
My primary concerns with the version in i915 were
(1) version bumps would need documentation even when version bump did not have explicit uApi change. I couldn't find a good place in
i915_drm.hto put such documentation. I think capabilities would be self documenting and it would be explicitly added to the uApi header.
(2) sometimes before upstreaming a feature, we maintained an internal version for the feature that was using a different range of versions. This would cause some grief when rebasing since the versions need to be increasing in the order of commits. If we had a bitmask, we can manage it better since there is no need to have an increasing value.
Quoted 1 line
Suggestions welcome.
My 2 cents on this is that we should have uniform interfaces across Xe, rather than have special treatment for OA. Or is OA special? Why? Because we haven't absracted HW well? Why do OA interfaces have to change frequently that we are talking about an OA version or OA capabilities when other interfaces/subsystems don't seem to need these?
To me it seems capabilities should not be in the uapi since capabilities can be constructed entirely in userspace by "probing" for available user extensions (so capabilities seem redundant/duplicated). KMD can make it easier for UMD's by returning unique return codes when particular extensions are not present.
I am copying other people who are defining the uapi in Xe for comments, hopefully we'll hear something. As I said the best way would be to do things uniformly across various subsystems so UMD's can also build and use common user xspace API's.
Francois/Matt/Rodrigo: could you please chime in here about how UMD's are supposed to handle extensions when uapi changes happen.
Thanks.
--
Ashutosh
Re: [Intel-xe] [19/21] drm/xe/uapi: Drop OA_IOCTL_VERSION
Quoted 63 lines · Ashutosh
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh/Lionel,
Quoted 49 lines · Lionel Landwerlin
Quoted 19 lines · Ashutosh Dixit
Quoted 8 lines
OA version was previously used to track which OA properties were introduced at which version. However OA version is an outlier in that a similar version is not used anywhere else in the kernel.
For XE, we will track addition of new properties by means of
xe_user_extension. Userland can either maintain a mapping of OA properties against the kernel version, or rely on return codes (e.g. ENOTSUPP) to "discover" OA properties.As a userspace driver this terrible.
You're making us write more code because we have to discover every single piece of implementation tweaks ever made to the kernel driver.
Yes OA version was an outlier in that it was better than the rest of kernel API.
Quoted 6 lines
By reading a single value we could make decisions about how to communicate with the kernel driver.
Having
xe_user_extensionhere is not helping, we still have to fuzz our way around the kernel to figure out what feature level is available.Hi Lionel, Ashutosh,
I don't want to change interfaces to make it more difficult for the UMDs. Do you think capabilities could help achieve what you want? We could have a bitmask of feature availability and the bitmask could be part of the xe oa query.
If that's seen as an unnecessary uApi impact, then I am ok with version being returned in the oa info query.
My primary concerns with the version in i915 were
(1) version bumps would need documentation even when version bump did not have explicit uApi change. I couldn't find a good place in
i915_drm.hto put such documentation. I think capabilities would be self documenting and it would be explicitly added to the uApi header.
(2) sometimes before upstreaming a feature, we maintained an internal version for the feature that was using a different range of versions. This would cause some grief when rebasing since the versions need to be increasing in the order of commits. If we had a bitmask, we can manage it better since there is no need to have an increasing value.Quoted 1 line
Suggestions welcome.
My 2 cents on this is that we should have uniform interfaces across Xe, rather than have special treatment for OA. Or is OA special? Why? Because we haven't absracted HW well? Why do OA interfaces have to change frequently that we are talking about an OA version or OA capabilities when other interfaces/subsystems don't seem to need these?
Quoted 5 lines
To me it seems capabilities should not be in the uapi since capabilities can be constructed entirely in userspace by "probing" for available user extensions (so capabilities seem redundant/duplicated). KMD can make it easier for UMD's by returning unique return codes when particular extensions are not present.
That said, we could probably go with capabilities if needed. An extension N would be represented by a capability BIT(N). What we don't want to do is add the same extension twice in xe_drm.h, once as an extension and a second time as a capability.
Quoted 12 lines
I am copying other people who are defining the uapi in Xe for comments, hopefully we'll hear something. As I said the best way would be to do things uniformly across various subsystems so UMD's can also build and use common user xspace API's.
Francois/Matt/Rodrigo: could you please chime in here about how UMD's are supposed to handle extensions when uapi changes happen.
Thanks.
--
Ashutosh
PATCH 20/21 drm/xe/uapi: Use OA unit id to identify OA unit
In reply to Ashutosh DixitPrevious uapi uses an indirect way (the engine class/instance of an engine connected to an OA unit) to identify an OA unit. Replace this by directly using the OA unit ID to identify the OA unit.
With this change DRM_XE_OA_PROP_OA_ENGINE_CLASS property is not needed any more and removed. DRM_XE_OA_PROP_OA_ENGINE_INSTANCE is still used with DRM_XE_OA_PROP_EXEC_QUEUE_ID.
--- drivers/gpu/drm/xe/xe_oa.c | 267 +++++++++++++++++++++---------------- include/uapi/drm/xe_drm.h | 22 ++- 2 files changed, 160 insertions(+), 129 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +150 -117
@@ -60,9 +60,13 @@ static const struct xe_oa_format oa_formats[] = { };struct xe_oa_open_properties { +u16 oa_unit_id;bool sample; +bool single_exec_q;u64 exec_q_id; +struct xe_exec_queue *exec_q; +u16 instance;int metrics_set;enum xe_oa_format_name oa_format;
@@ -1287,6 +1291,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,struct xe_oa *oa = stream->oa;int ret; + stream->exec_q = props->exec_q; stream->poll_oa_period = props->poll_oa_period; stream->hwe = props->hwe; stream->gt = stream->hwe->gt;
@@ -1377,61 +1382,27 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,static int xe_oa_stream_open_ioctl_locked (struct xe_oa *oa,struct drm_xe_oa_open_param *param, -struct xe_oa_open_properties *props, -struct drm_file *file) +struct xe_oa_open_properties *props) { -struct xe_file *xef =to_xe_file (file); -struct xe_oa_stream *stream =NULL ; -struct xe_exec_queue *q =NULL ; +struct xe_oa_stream *stream;unsigned long f_flags =0 ; -bool privileged_op = true;int stream_fd;int ret; -if (props->single_exec_q) { - q =xe_exec_queue_lookup (xef, props->exec_q_id); -if (XE_IOCTL_DBG (oa->xe, !q)) { - ret = -ENOENT ; - goto err_exec_q; - } - } - -/* -* The OAR unit only monitors the RCS on a per context basis. Relax -* requirements if the user doesn't request global stream access, -* i.e. query based sampling using MI_REPORT_PERF_COUNT -*/ -if (q && !props->sample) - privileged_op = false; - -if (privileged_op && xe_oa_stream_paranoid && !perfmon_capable ()) { -drm_dbg (&oa->xe->drm,"Insufficient privileges to open xe perf stream\n" ); - ret = -EACCES ; - goto err_exec_q; - } - -if (!props->sample && !q) { -drm_dbg (&oa->xe->drm,"Only OA report sampling supported\n" ); - ret = -EINVAL ; - goto err_exec_q; - } -/* We currently only allow exclusive access */ if (props->hwe->oa_group->exclusive_stream) {drm_dbg (&oa->xe->drm,"OA unit already in use\n" ); ret = -EBUSY ; - goto err_exec_q; + goto exit; } stream =kzalloc (sizeof (*stream),GFP_KERNEL );if (!stream) { ret = -ENOMEM ; - goto err_exec_q; + goto exit; } stream->oa = oa; - stream->exec_q = q; - ret =xe_oa_stream_init (stream, props);if (ret) goto err_free;
@@ -1458,9 +1429,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,xe_oa_stream_destroy (stream); err_free:kfree (stream); -err_exec_q: -if (q) -xe_exec_queue_put (q); +exit:return ret; }
@@ -1502,11 +1471,6 @@ static u64 oa_exponent_to_ns(struct xe_gt *gt, int exponent)return div_u64 (nom + den -1 , den); } -static bool engine_supports_oa (const struct xe_hw_engine *hwe) -{ -return hwe->oa_group; -} -static bool engine_supports_oa_format (const struct xe_hw_engine *hwe,int type) {switch (hwe->oa_group->type) {
@@ -1537,20 +1501,134 @@ static int decode_oa_format(struct xe_oa *oa, u64 prop, enum xe_oa_format_name *return -EINVAL ; } +u16 xe_oa_unit_id (struct xe_hw_engine *hwe) +{ +return hwe->oa_group && hwe->oa_group->num_engines ? + hwe->oa_group->oa_unit_id :U16_MAX ; +} + +static int xe_oa_assign_hwe (struct xe_oa *oa,struct xe_oa_open_properties *props) +{ +struct xe_gt *gt; +int i, ret =0 ; + +if (props->exec_q) { +/* When we have an exec_q, get hwe from the exec_q */ +for_each_gt (gt, oa->xe, i) { + props->hwe =xe_gt_hw_engine (gt, props->exec_q->class, + props->instance, false); +if (props->hwe) +break ; + } +if (props->hwe && (xe_oa_unit_id (props->hwe) != props->oa_unit_id)) { +drm_dbg (&oa->xe->drm,"OA unit ID mismatch for exec_q\n" ); + ret = -EINVAL ; + } + }else { +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; + +/* Else just get the first hwe attached to the oa unit */ +for_each_gt (gt, oa->xe, i) { +for_each_hw_engine (hwe, gt, id) { +if (xe_oa_unit_id (hwe) == props->oa_unit_id) { + props->hwe = hwe; + goto out; + } + } + } + } +out: +if (!props->hwe) { +drm_dbg (&oa->xe->drm,"Unable to find hwe for OA unit ID %d\n" , + props->oa_unit_id); + ret = -EINVAL ; + } + +return ret; +} + +static int xe_oa_validate_properties (struct xe_oa *oa, +struct xe_oa_open_properties *props, +struct drm_file *file) +{ +struct xe_file *xef =to_xe_file (file); +const struct xe_oa_format *f; +bool privileged_op = true; +int ret; + +if (props->single_exec_q) { + props->exec_q =xe_exec_queue_lookup (xef, props->exec_q_id); +if (XE_IOCTL_DBG (oa->xe, !props->exec_q)) { + ret = -ENOENT ; + goto err_exec_q; + } + } + +/* +* The OAR unit only monitors the RCS on a per context basis. Relax +* requirements if the user doesn't request global stream access, +* i.e. query based sampling using MI_REPORT_PERF_COUNT +*/ +if (props->exec_q && !props->sample) + privileged_op = false; + +if (privileged_op && xe_oa_stream_paranoid && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm,"Insufficient privileges to open xe perf stream\n" ); + ret = -EACCES ; + goto err_exec_q; + } + +if (!props->exec_q && !props->sample) { +drm_dbg (&oa->xe->drm,"Only OA report sampling supported\n" ); + ret = -EINVAL ; + goto err_exec_q; + } + + ret =xe_oa_assign_hwe (oa, props); +if (ret) + goto err_exec_q; + + f = &oa->oa_formats[props->oa_format]; +if (!props->oa_format || !f->size || + !engine_supports_oa_format (props->hwe, f->type)) { +drm_dbg (&oa->xe->drm,"Invalid OA format %d type %d size %d for class %d\n" , + props->oa_format, f->type, f->size, props->hwe->class); + ret = -EINVAL ; + goto err_exec_q; + } + +if (props->oa_periodic) { +u64 oa_period, oa_freq_hz; + + oa_period =oa_exponent_to_ns (props->hwe->gt, props->oa_period_exponent); + oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period); +if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { +drm_dbg (&oa->xe->drm, +"OA exponent would exceed the max sampling frequency (sysctl dev.xe.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n" , + xe_oa_max_sample_rate); + ret = -EACCES ; + goto err_exec_q; + } + } + +return 0 ; + +err_exec_q: +if (props->exec_q) +xe_exec_queue_put (props->exec_q); +return ret; +} +#define OA_EXPONENT_MAX 31static int xe_oa_read_properties_unlocked (struct xe_oa *oa,u64 __user *uprops, -u32 n_props, +u32 n_props,struct drm_file *file,struct xe_oa_open_properties *props) { -const struct xe_oa_format *f;u64 __user *uprop = uprops; -bool config_instance = false; -bool config_class = false; -u8 class, instance; -struct xe_gt *gt; -u32 i;int ret; +u32 i;if (!n_props || n_props >=DRM_XE_OA_PROP_MAX ) {drm_dbg (&oa->xe->drm,"Invalid number of xe perf properties given\n" );
@@ -1559,10 +1637,6 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, props->poll_oa_period =DEFAULT_POLL_PERIOD_NS ; -/* Defaults when class:instance is not passed */ - class =XE_ENGINE_CLASS_RENDER ; - instance =0 ; -for (i =0 ; i < n_props; i++) {u64 id, value;
@@ -1575,9 +1649,12 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops,return ret;switch ((enum drm_xe_oa_property_id )id) { -case DRM_XE_OA_PROP_EXEC_QUEUE_ID : - props->single_exec_q = true; - props->exec_q_id = value; +case DRM_XE_OA_PROP_OA_UNIT_ID : +if (value >= oa->oa_unit_ids) { +drm_dbg (&oa->xe->drm,"OA unit ID out of range %lld\n" , value); +return -EINVAL ; + } + props->oa_unit_id = value;break ;case DRM_XE_OA_PROP_SAMPLE_OA : props->sample = value;
@@ -1614,13 +1691,12 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, } props->poll_oa_period = value;break ; -case DRM_XE_OA_PROP_OA_ENGINE_CLASS : - class = (u8 )value; - config_class = true; +case DRM_XE_OA_PROP_EXEC_QUEUE_ID : + props->single_exec_q = true; + props->exec_q_id = value;break ;case DRM_XE_OA_PROP_OA_ENGINE_INSTANCE : - instance = (u8 )value; - config_instance = true; + props->instance = value;break ;default :drm_dbg (&oa->xe->drm,"Unknown xe oa property ID %lld\n" , id);
@@ -1630,49 +1706,9 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops, uprop +=2 ; } -if ((config_class && !config_instance) || - (config_instance && !config_class)) { -drm_dbg (&oa->xe->drm,"OA engine class/instance parameters must be passed together\n" ); -return -EINVAL ; - } - -for_each_gt (gt, oa->xe, i) { - props->hwe =xe_gt_hw_engine (gt, class, instance, false); -if (props->hwe) -break ; - } -if (!props->hwe) { -drm_dbg (&oa->xe->drm,"OA engine class and instance invalid %d:%d\n" , - class, instance); -return -EINVAL ; - } - -if (!engine_supports_oa (props->hwe)) { -drm_dbg (&oa->xe->drm,"Engine not supported by OA %d:%d\n" , - class, instance); -return -EINVAL ; - } - - f = &oa->oa_formats[props->oa_format]; -if (!props->oa_format || !f->size || - !engine_supports_oa_format (props->hwe, f->type)) { -drm_dbg (&oa->xe->drm,"Invalid OA format %d type %d size %d for class %d\n" , - props->oa_format, f->type, f->size, props->hwe->class); -return -EINVAL ; - } - -if (props->oa_periodic) { -u64 oa_period, oa_freq_hz; - - oa_period =oa_exponent_to_ns (props->hwe->gt, props->oa_period_exponent); - oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period); -if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { -drm_dbg (&oa->xe->drm, -"OA exponent would exceed the max sampling frequency (sysctl dev.xe.oa_max_sample_rate) %uHz without CAP_PERFMON or CAP_SYS_ADMIN privileges\n" , - xe_oa_max_sample_rate); -return -EACCES ; - } - } + ret =xe_oa_validate_properties (oa, props, file); +if (ret) +return ret;return 0 ; }
@@ -1702,17 +1738,20 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data, struct drm_file } ret =xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param.properties_ptr), - param.num_properties, - &props); + param.num_properties, file, &props);if (ret)return ret; gt = props.hwe->gt;mutex_lock (>->oa.lock); - ret =xe_oa_stream_open_ioctl_locked (oa, ¶m, &props, file); + ret =xe_oa_stream_open_ioctl_locked (oa, ¶m, &props);mutex_unlock (>->oa.lock); +/* Drop exec_q reference taken in read_properties/validate_properties on error */ +if (ret <0 && props.exec_q) +xe_exec_queue_put (props.exec_q); +return ret; }
@@ -2212,12 +2251,6 @@ static int xe_oa_init_engine_groups(struct xe_oa *oa)return 0 ; } -u16 xe_oa_unit_id (struct xe_hw_engine *hwe) -{ -return hwe->oa_group && hwe->oa_group->num_engines ? - hwe->oa_group->oa_unit_id :U16_MAX ; -} -static void oa_format_add (struct xe_oa *oa,enum xe_oa_format_name format) {__set_bit (format, oa->format_mask);
include/uapi/drm/xe_drm.h +10 -12
@@ -1177,11 +1177,11 @@ struct drm_xe_query_oa_info {enum drm_xe_oa_property_id {/** -* Open the stream for a specific exec queue id (as used with -* drm_xe_exec). A stream opened for a specific exec queue id this -* way won't typically require root privileges. +* ID of the OA unit on which to open the OA stream, see +* @oa_unit_id in 'struct drm_xe_engine_class_instance'. Defaults +* to 0 if not provided. */ -DRM_XE_OA_PROP_EXEC_QUEUE_ID =1 , +DRM_XE_OA_PROP_OA_UNIT_ID =1 ,/** * A value of 1 requests the inclusion of raw OA unit reports as
@@ -1245,17 +1245,15 @@ enum drm_xe_oa_property_id {DRM_XE_OA_PROP_POLL_OA_PERIOD ,/** -* Multiple engines may be mapped to the same OA unit. The OA unit is -* identified by class:instance of any engine mapped to it. -* -* This parameter specifies the engine class and must be passed along -* with DRM_XE_OA_PROP_OA_ENGINE_INSTANCE. +* Open the stream for a specific exec queue id (as used with +* drm_xe_exec). A stream opened for a specific exec queue id this +* way won't typically require root privileges. */ -DRM_XE_OA_PROP_OA_ENGINE_CLASS , +DRM_XE_OA_PROP_EXEC_QUEUE_ID ,/** -* This parameter specifies the engine instance and must be passed along -* with DRM_XE_OA_PROP_OA_ENGINE_CLASS. +* This parameter specifies the engine instance and can be passed along +* with DRM_XE_OA_PROP_EXEC_QUEUE_ID or will default to 0. */ DRM_XE_OA_PROP_OA_ENGINE_INSTANCE,
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 20/21] drm/xe/uapi: Use OA unit id to identify OA unit
Quoted 160 lines · Ashutosh Dixit
Previous uapi uses an indirect way (the engine class/instance of an engine connected to an OA unit) to identify an OA unit. Replace this by directly using the OA unit ID to identify the OA unit.
With this change
DRM_XE_OA_PROP_OA_ENGINE_CLASSproperty is not needed any more and removed.DRM_XE_OA_PROP_OA_ENGINE_INSTANCEis still used withDRM_XE_OA_PROP_EXEC_QUEUE_ID.Signed-off-by Ashutosh Dixit <[email protected]>---
drivers/gpu/drm/xe/xe_oa.c| 267 +++++++++++++++++++++----------------include/uapi/drm/xe_drm.h| 22 ++-2 files changed, 160 insertions(+), 129 deletions(-)drivers/gpu/drm/xe/xe_oa.c +5
-0@@ -60,9 +60,13 @@ static const struct xe_oa_format oa_formats[] = { };struct xe_oa_open_properties { +u16 oa_unit_id;bool sample; +bool single_exec_q;u64 exec_q_id; +struct xe_exec_queue *exec_q; +u16 instance;int metrics_set;enum xe_oa_format_name oa_format;@@ -1287,6 +1291,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,struct xe_oa *oa = stream->oa;int ret; + stream->exec_q = props->exec_q; stream->poll_oa_period = props->poll_oa_period; stream->hwe = props->hwe; stream->gt = stream->hwe->gt;@@ -1377,61 +1382,27 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,static int
xe_oa_stream_open_ioctl_locked(structxe_oa*oa,
structdrm_xe_oa_open_param*param,drivers/gpu/drm/xe/xe_oa.c +1
-2-struct xe_oa_open_properties *props, - struct drm_file *file) + struct xe_oa_open_properties *props){
drivers/gpu/drm/xe/xe_oa.c +1
-3-struct xe_file *xef =to_xe_file (file); -struct xe_oa_stream *stream =NULL ; -struct xe_exec_queue *q =NULL ; +struct xe_oa_stream *stream;unsigned long f_flags = 0;drivers/gpu/drm/xe/xe_oa.c +0
-1-bool privileged_op = true;int stream_fd; int ret;drivers/gpu/drm/xe/xe_oa.c +0
-28-if (props->single_exec_q) { - q =xe_exec_queue_lookup (xef, props->exec_q_id); -if (XE_IOCTL_DBG (oa->xe, !q)) { - ret = -ENOENT ; - goto err_exec_q; - } - } - -/* -* The OAR unit only monitors the RCS on a per context basis. Relax -* requirements if the user doesn't request global stream access, -* i.e. query based sampling using MI_REPORT_PERF_COUNT -*/ -if (q && !props->sample) - privileged_op = false; - -if (privileged_op && xe_oa_stream_paranoid && !perfmon_capable ()) { -drm_dbg (&oa->xe->drm,"Insufficient privileges to open xe perf stream\n" ); - ret = -EACCES ; - goto err_exec_q; - } - -if (!props->sample && !q) { -drm_dbg (&oa->xe->drm,"Only OA report sampling supported\n" ); - ret = -EINVAL ; - goto err_exec_q; - } -/* We currently only allow exclusive access */ if (props->hwe->oa_group->exclusive_stream) { drm_dbg(&oa->xe->drm, "OA unit already in use\n"); ret = -EBUSY;drivers/gpu/drm/xe/xe_oa.c +1
-1- goto err_exec_q; + goto exit;} stream = kzalloc(sizeof(*stream), GFP_KERNEL); if (!stream) { ret = -ENOMEM;drivers/gpu/drm/xe/xe_oa.c +1
-1- goto err_exec_q; + goto exit;} stream->oa = oa;drivers/gpu/drm/xe/xe_oa.c +0
-2- stream->exec_q = q; -ret = xe_oa_stream_init(stream, props); if (ret) goto err_free;drivers/gpu/drm/xe/xe_oa.c +0
-0@@ -1458,9 +1429,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,xe_oa_stream_destroy (stream);
err_free:kfree(stream);drivers/gpu/drm/xe/xe_oa.c +1
-3-err_exec_q: -if (q) -xe_exec_queue_put (q); +exit:return ret; }drivers/gpu/drm/xe/xe_oa.c +27
-5@@ -1502,11 +1471,6 @@ static u64 oa_exponent_to_ns(struct xe_gt *gt, int exponent)return div_u64 (nom + den -1 , den); } -static bool engine_supports_oa (const struct xe_hw_engine *hwe) -{ -return hwe->oa_group; -} -static bool engine_supports_oa_format (const struct xe_hw_engine *hwe,int type) {switch (hwe->oa_group->type) {@@ -1537,20 +1501,134 @@ static int decode_oa_format(struct xe_oa *oa, u64 prop, enum xe_oa_format_name *return -EINVAL ; } +u16 xe_oa_unit_id (struct xe_hw_engine *hwe) +{ +return hwe->oa_group && hwe->oa_group->num_engines ? + hwe->oa_group->oa_unit_id :U16_MAX ; +} + +static int xe_oa_assign_hwe (struct xe_oa *oa,struct xe_oa_open_properties *props) +{ +struct xe_gt *gt; +int i, ret =0 ; + +if (props->exec_q) { +/* When we have an exec_q, get hwe from the exec_q */ +for_each_gt (gt, oa->xe, i) { + props->hwe =xe_gt_hw_engine (gt, props->exec_q->class, + props->instance, false); +if (props->hwe) +break ; + } +if (props->hwe && (xe_oa_unit_id (props->hwe) != props->oa_unit_id)) { +drm_dbg (&oa->xe->drm,"OA unit ID mismatch for exec_q\n" ); + ret = -EINVAL ; + } + }else { +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; +
drivers/gpu/drm/xe/xe_oa.c static int decode_oa_format(struct xe_oa *oa, u64 prop, enum xe_oa_format_name * · line 1540
Quoted 10 lines
drivers/gpu/drm/xe/xe_oa.c +10
-0+/* Else just get the first hwe attached to the oa unit */ +for_each_gt (gt, oa->xe, i) { +for_each_hw_engine (hwe, gt, id) { +if (xe_oa_unit_id (hwe) == props->oa_unit_id) { + props->hwe = hwe; + goto out; + } + } + } + }
I think both the if and else blocks above will get you the same hwe object, so you can just pick the else code to assign hwe.
Are we allowing the user to pass either oa_unit_id OR exec_q/instance? I think based on the HW requirement we should enable OAR/OAG together, so maybe enforce that the user passes both params. Thoughts?
Thanks,
Umesh
Re: [Intel-xe] [PATCH 20/21] drm/xe/uapi: Use OA unit id to identify OA unit
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 8 lines · Ashutosh Dixit
Quoted 7 lines
Previous uapi uses an indirect way (the engine class/instance of an engine connected to an OA unit) to identify an OA unit. Replace this by directly using the OA unit ID to identify the OA unit.
With this change
DRM_XE_OA_PROP_OA_ENGINE_CLASSproperty is not needed any more and removed.DRM_XE_OA_PROP_OA_ENGINE_INSTANCEis still used withDRM_XE_OA_PROP_EXEC_QUEUE_ID.
/snip/
Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/xe/xe_oa.c +26
-0+static int xe_oa_assign_hwe (struct xe_oa *oa,struct xe_oa_open_properties *props) +{ +struct xe_gt *gt; +int i, ret =0 ; + +if (props->exec_q) { +/* When we have an exec_q, get hwe from the exec_q */ +for_each_gt (gt, oa->xe, i) { + props->hwe =xe_gt_hw_engine (gt, props->exec_q->class, + props->instance, false); +if (props->hwe) +break ; + } +if (props->hwe && (xe_oa_unit_id (props->hwe) != props->oa_unit_id)) { +drm_dbg (&oa->xe->drm,"OA unit ID mismatch for exec_q\n" ); + ret = -EINVAL ; + } + }else { +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; + +/* Else just get the first hwe attached to the oa unit */ +for_each_gt (gt, oa->xe, i) { +for_each_hw_engine (hwe, gt, id) { +if (xe_oa_unit_id (hwe) == props->oa_unit_id) { + props->hwe = hwe;
Quoted 8 lines
drivers/gpu/drm/xe/xe_oa.c static int decode_oa_format(struct xe_oa *oa, u64 prop, enum xe_oa_format_name * · line 1540
Quoted 5 lines
drivers/gpu/drm/xe/xe_oa.c +5
-0+ goto out; + } + } + } + }I think both the if and else blocks above will get you the same hwe object, so you can just pick the else code to assign hwe.
Not when there are multiple hwe's attached to a single OA unit (I am thinking media/compute), correct?
Quoted 1 line
Are we allowing the user to pass either
oa_unit_idOR exec_q/instance?
No. oa_unit_id is the basic entity used to identify the OA unit. If userland is only using OAG they can skip exec_q. If exec_q is specified, the code above checks if exec_q/instance lands on the same OA unit as the oa_unit_id.
So oa_unit_id is always provided (for both OAG/OAR) and optionally exec_q/instance can be provided (for OAR).
i915 had basically <class, instance, exec_q> and this XE uapi has <oa_unit_id, exec_q, instance> so the semantics here is almost the same as i915.
Quoted 2 lines
I think based on the HW requirement we should enable OAR/OAG together, so maybe enforce that the user passes both params. Thoughts?
I don't think it will fly since in some cases user is only interested in OAG (global data for all contexts) so no point forcing them to also passing in exec_q/instance. The user may not even have a specific exec_q in such case to pass into the uapi.
Thanks.
--
Ashutosh
Re: [Intel-xe] [PATCH 20/21] drm/xe/uapi: Use OA unit id to identify OA unit
Quoted 69 lines · Ashutosh
Quoted 1 line · Umesh Nerlige Ramappa
Hi Umesh,
Quoted 8 lines · Ashutosh Dixit
Quoted 7 lines
Previous uapi uses an indirect way (the engine class/instance of an engine connected to an OA unit) to identify an OA unit. Replace this by directly using the OA unit ID to identify the OA unit.
With this change
DRM_XE_OA_PROP_OA_ENGINE_CLASSproperty is not needed any more and removed.DRM_XE_OA_PROP_OA_ENGINE_INSTANCEis still used withDRM_XE_OA_PROP_EXEC_QUEUE_ID./snip/
Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/xe/xe_oa.c +26
-0+static int xe_oa_assign_hwe (struct xe_oa *oa,struct xe_oa_open_properties *props) +{ +struct xe_gt *gt; +int i, ret =0 ; + +if (props->exec_q) { +/* When we have an exec_q, get hwe from the exec_q */ +for_each_gt (gt, oa->xe, i) { + props->hwe =xe_gt_hw_engine (gt, props->exec_q->class, + props->instance, false); +if (props->hwe) +break ; + } +if (props->hwe && (xe_oa_unit_id (props->hwe) != props->oa_unit_id)) { +drm_dbg (&oa->xe->drm,"OA unit ID mismatch for exec_q\n" ); + ret = -EINVAL ; + } + }else { +struct xe_hw_engine *hwe; +enum xe_hw_engine_id id; + +/* Else just get the first hwe attached to the oa unit */ +for_each_gt (gt, oa->xe, i) { +for_each_hw_engine (hwe, gt, id) { +if (xe_oa_unit_id (hwe) == props->oa_unit_id) { + props->hwe = hwe;Quoted 8 lines
drivers/gpu/drm/xe/xe_oa.c static int decode_oa_format(struct xe_oa *oa, u64 prop, enum xe_oa_format_name * · line 1540
Quoted 5 lines
drivers/gpu/drm/xe/xe_oa.c +5
-0+ goto out; + } + } + } + }I think both the if and else blocks above will get you the same hwe object, so you can just pick the else code to assign hwe.
Not when there are multiple hwe's attached to a single OA unit (I am thinking media/compute), correct?
Quoted 1 line
Are we allowing the user to pass either
oa_unit_idOR exec_q/instance?No.
oa_unit_idis the basic entity used to identify the OA unit. If userland is only using OAG they can skipexec_q. Ifexec_qis specified, the code above checks if exec_q/instance lands on the same OA unit as theoa_unit_id.So
oa_unit_idis always provided (for both OAG/OAR) and optionally exec_q/instance can be provided (for OAR).i915 had basically <class, instance,
exec_q> and this XE uapi has <oa_unit_id,exec_q, instance> so the semantics here is almost the same as i915.
Quoted 7 lines
Quoted 2 lines
I think based on the HW requirement we should enable OAR/OAG together, so maybe enforce that the user passes both params. Thoughts?
I don't think it will fly since in some cases user is only interested in OAG (global data for all contexts) so no point forcing them to also passing in exec_q/instance. The user may not even have a specific
exec_qin such case to pass into the uapi.
There are some additional considerations for the future about this: I think we should really not need exec_q_id in the OA uapi. We should be able to enable OAR functionality on all exec_q/instance combos (both which are present and which may be created while OA is enabled) which can be scheduled on that OAR unit. This would enable an OA MI_RPC query to be issued on any exec queue which exists while the OA stream is open. OAR registers are part of the context image so this looks feasible to me.
The instance field is interesting since I believe compute has a limitation that OAC can only be enabled on a single hwe at a time. So even if we don't have an exec_q, instance can be used to identify which hwe instance we are enabling OAC on. So the semantics of instance will change in this case: at present instance is the context image instance on which OAR/OAC is enabled, later it will reflect the HW limitation of the engine instance.
Though we may not be do this immediately because of other priorities. So currently we do single exec_q but can deprecate that if we can ever get "any exec_q" to work.
Something like that (not completely thought through yet). Let's not worry about this now but just wanted to write out my thoughts about this in case you had any feedback.
Thanks.
--
Ashutosh
PATCH 21/21 drm/xe/uapi: Convert OA property key/value pairs to a struct
In reply to Ashutosh DixitChange OA uapi to take a param struct rather than property key value pairs. A param struct is simpler and param structs can be extenended in the future using xe_user_extension so there seems to be no reason to use property key value pairs.
--- drivers/gpu/drm/xe/xe_oa.c | 244 ++++++++++++------------------- drivers/gpu/drm/xe/xe_oa_types.h | 4 +- include/uapi/drm/xe_drm.h | 127 ++++++++-------- 3 files changed, 151 insertions(+), 224 deletions(-)
drivers/gpu/drm/xe/xe_oa.c +91 -153
@@ -59,23 +59,10 @@ static const struct xe_oa_format oa_formats[] = { [XE_OAM_FORMAT_MPEC8u32_B8_C8] = { 2, 128, XE_OA_FMT_TYPE_OAM_MPEC, HDR_64_BIT }, }; -struct xe_oa_open_properties { -u16 oa_unit_id; -bool sample; - -bool single_exec_q; -u64 exec_q_id; +struct xe_oa_derived_params {struct xe_exec_queue *exec_q; -u16 instance; - -int metrics_set;enum xe_oa_format_name oa_format; -bool oa_periodic; -int oa_period_exponent; -struct xe_hw_engine *hwe; - -u64 poll_oa_period; };struct xe_oa_config_bo {
@@ -272,7 +259,7 @@ static enum hrtimer_restart xe_oa_poll_check_timer_cb(struct hrtimer *hrtimer)wake_up (&stream->poll_wq); } -hrtimer_forward_now (hrtimer,ns_to_ktime (stream->poll_oa_period)); +hrtimer_forward_now (hrtimer,ns_to_ktime (stream->poll_period_ns));return HRTIMER_RESTART ; }
@@ -1077,7 +1064,7 @@ static void xe_oa_stream_enable(struct xe_oa_stream *stream)if (stream->sample)hrtimer_start (&stream->poll_check_timer, -ns_to_ktime (stream->poll_oa_period), +ns_to_ktime (stream->poll_period_ns),HRTIMER_MODE_REL_PINNED ); }
@@ -1284,24 +1271,26 @@ static int xe_oa_set_ctx_ctrl_offset(struct xe_oa_stream *stream) }static int xe_oa_stream_init (struct xe_oa_stream *stream, -struct xe_oa_open_properties *props) +struct drm_xe_oa_open_param *param, +struct xe_oa_derived_params *dp) { -struct xe_oa_group *g = props->hwe->oa_group; -struct xe_gt *gt = props->hwe->gt; +struct xe_oa_group *g = dp->hwe->oa_group; +struct xe_gt *gt = dp->hwe->gt;struct xe_oa *oa = stream->oa;int ret; - stream->exec_q = props->exec_q; - stream->poll_oa_period = props->poll_oa_period; - stream->hwe = props->hwe; + stream->exec_q = dp->exec_q; + stream->poll_period_ns = param->poll_period_us ? + param->poll_period_us *NSEC_PER_USEC :DEFAULT_POLL_PERIOD_NS ; + stream->hwe = dp->hwe; stream->gt = stream->hwe->gt; stream->sample_size =sizeof (struct drm_xe_oa_record_header ); - stream->oa_buffer.format = &oa->oa_formats[props->oa_format]; + stream->oa_buffer.format = &oa->oa_formats[dp->oa_format]; - stream->sample = props->sample; + stream->sample = param->sample_oa; stream->sample_size += stream->oa_buffer.format->size; - stream->periodic = props->oa_periodic; - stream->period_exponent = props->oa_period_exponent; + stream->periodic = param->period_exponent >0 ; + stream->period_exponent = param->period_exponent;if (stream->exec_q &&engine_supports_mi_query (stream->hwe)) {/* If we don't find the context offset, just return error */
@@ -1314,9 +1303,9 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream, } } - stream->oa_config =xe_oa_get_oa_config (oa, props->metrics_set); + stream->oa_config =xe_oa_get_oa_config (oa, param->metric_set);if (!stream->oa_config) { -drm_dbg (&oa->xe->drm,"Invalid OA config id=%i\n" , props->metrics_set); +drm_dbg (&oa->xe->drm,"Invalid OA config id=%i\n" , param->metric_set); ret = -EINVAL ; goto exit; }
@@ -1382,7 +1371,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,static int xe_oa_stream_open_ioctl_locked (struct xe_oa *oa,struct drm_xe_oa_open_param *param, -struct xe_oa_open_properties *props) +struct xe_oa_derived_params *dp) {struct xe_oa_stream *stream;unsigned long f_flags =0 ;
@@ -1390,7 +1379,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,int ret;/* We currently only allow exclusive access */ -if (props->hwe->oa_group->exclusive_stream) { +if (dp->hwe->oa_group->exclusive_stream) {drm_dbg (&oa->xe->drm,"OA unit already in use\n" ); ret = -EBUSY ; goto exit;
@@ -1403,13 +1392,13 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa, } stream->oa = oa; - ret =xe_oa_stream_init (stream, props); + ret =xe_oa_stream_init (stream, param, dp);if (ret) goto err_free; -if (param->flags &XE_OA_FLAG_FD_CLOEXEC ) +if (param->open_flags &XE_OA_FLAG_FD_CLOEXEC ) f_flags |=O_CLOEXEC ; -if (param->flags &XE_OA_FLAG_FD_NONBLOCK ) +if (param->open_flags &XE_OA_FLAG_FD_NONBLOCK ) f_flags |=O_NONBLOCK ; stream_fd =anon_inode_getfd ("[xe_oa]" , &xe_oa_fops, stream, f_flags);
@@ -1418,7 +1407,7 @@ xe_oa_stream_open_ioctl_locked(struct xe_oa *oa, goto err_destroy; } -if (!(param->flags &XE_OA_FLAG_DISABLED )) +if (!(param->open_flags &XE_OA_FLAG_DISABLED ))xe_oa_enable_locked (stream);/* Hold a reference on the drm device till stream_fd is released */
@@ -1483,10 +1472,10 @@ static bool engine_supports_oa_format(const struct xe_hw_engine *hwe, int type) } } -static int decode_oa_format (struct xe_oa *oa,u64 prop,enum xe_oa_format_name *name) +static int decode_oa_format (struct xe_oa *oa,u64 fmt,enum xe_oa_format_name *name) { -u32 counter_sel =FIELD_GET (XE_OA_MASK_COUNTER_SEL , prop); -u32 type =FIELD_GET (XE_OA_MASK_FMT_TYPE , prop); +u32 counter_sel =FIELD_GET (XE_OA_MASK_COUNTER_SEL , fmt); +u32 type =FIELD_GET (XE_OA_MASK_FMT_TYPE , fmt);int idx;for_each_set_bit (idx, oa->format_mask,XE_OA_FORMAT_MAX ) {
@@ -1507,20 +1496,21 @@ u16 xe_oa_unit_id(struct xe_hw_engine *hwe) hwe->oa_group->oa_unit_id : U16_MAX; } -static int xe_oa_assign_hwe (struct xe_oa *oa,struct xe_oa_open_properties *props) +static int xe_oa_assign_hwe (struct xe_oa *oa,struct drm_xe_oa_open_param *param, +struct xe_oa_derived_params *dp) {struct xe_gt *gt;int i, ret =0 ; -if (props->exec_q) { +if (dp->exec_q) {/* When we have an exec_q, get hwe from the exec_q */ for_each_gt (gt, oa->xe, i) { - props->hwe =xe_gt_hw_engine (gt, props->exec_q->class, - props->instance, false); -if (props->hwe) + dp->hwe =xe_gt_hw_engine (gt, dp->exec_q->class, + param->engine_instance, false); +if (dp->hwe)break ; } -if (props->hwe && (xe_oa_unit_id (props->hwe) != props->oa_unit_id)) { +if (dp->hwe && (xe_oa_unit_id (dp->hwe) != param->oa_unit_id)) {drm_dbg (&oa->xe->drm,"OA unit ID mismatch for exec_q\n" ); ret = -EINVAL ; }
@@ -1531,35 +1521,35 @@ static int xe_oa_assign_hwe(struct xe_oa *oa, struct xe_oa_open_properties *prop/* Else just get the first hwe attached to the oa unit */ for_each_gt (gt, oa->xe, i) {for_each_hw_engine (hwe, gt, id) { -if (xe_oa_unit_id (hwe) == props->oa_unit_id) { - props->hwe = hwe; +if (xe_oa_unit_id (hwe) == param->oa_unit_id) { + dp->hwe = hwe; goto out; } } } } out: -if (!props->hwe) { +if (!dp->hwe) {drm_dbg (&oa->xe->drm,"Unable to find hwe for OA unit ID %d\n" , - props->oa_unit_id); + param->oa_unit_id); ret = -EINVAL ; }return ret; } -static int xe_oa_validate_properties (struct xe_oa *oa, -struct xe_oa_open_properties *props, -struct drm_file *file) +static int __xe_oa_open_check_params (struct xe_oa *oa,struct drm_file *file, +struct drm_xe_oa_open_param *param, +struct xe_oa_derived_params *dp) {struct xe_file *xef =to_xe_file (file);const struct xe_oa_format *f;bool privileged_op = true;int ret; -if (props->single_exec_q) { - props->exec_q =xe_exec_queue_lookup (xef, props->exec_q_id); -if (XE_IOCTL_DBG (oa->xe, !props->exec_q)) { +if (param->exec_queue_id >0 ) { + dp->exec_q =xe_exec_queue_lookup (xef, param->exec_queue_id); +if (XE_IOCTL_DBG (oa->xe, !dp->exec_q)) { ret = -ENOENT ; goto err_exec_q; }
@@ -1570,7 +1560,7 @@ static int xe_oa_validate_properties(struct xe_oa *oa,* requirements if the user doesn't request global stream access, * i.e. query based sampling using MI_REPORT_PERF_COUNT */ -if (props->exec_q && !props->sample) +if (dp->exec_q && !param->sample_oa) privileged_op = false;if (privileged_op && xe_oa_stream_paranoid && !perfmon_capable ()) {
@@ -1579,29 +1569,29 @@ static int xe_oa_validate_properties(struct xe_oa *oa, goto err_exec_q; } -if (!props->exec_q && !props->sample) { +if (!dp->exec_q && !param->sample_oa) {drm_dbg (&oa->xe->drm,"Only OA report sampling supported\n" ); ret = -EINVAL ; goto err_exec_q; } - ret =xe_oa_assign_hwe (oa, props); + ret =xe_oa_assign_hwe (oa, param, dp);if (ret) goto err_exec_q; - f = &oa->oa_formats[props->oa_format]; -if (!props->oa_format || !f->size || - !engine_supports_oa_format (props->hwe, f->type)) { + f = &oa->oa_formats[dp->oa_format]; +if (!dp->oa_format || !f->size || + !engine_supports_oa_format (dp->hwe, f->type)) {drm_dbg (&oa->xe->drm,"Invalid OA format %d type %d size %d for class %d\n" , - props->oa_format, f->type, f->size, props->hwe->class); + dp->oa_format, f->type, f->size, dp->hwe->class); ret = -EINVAL ; goto err_exec_q; } -if (props->oa_periodic) { +if (param->period_exponent >0 ) {u64 oa_period, oa_freq_hz; - oa_period =oa_exponent_to_ns (props->hwe->gt, props->oa_period_exponent); + oa_period =oa_exponent_to_ns (dp->hwe->gt, param->period_exponent); oa_freq_hz =div64_u64 (NSEC_PER_SEC , oa_period);if (oa_freq_hz > xe_oa_max_sample_rate && !perfmon_capable ()) { drm_dbg(&oa->xe->drm,
@@ -1615,98 +1605,54 @@ static int xe_oa_validate_properties(struct xe_oa *oa,return 0 ; err_exec_q: -if (props->exec_q) -xe_exec_queue_put (props->exec_q); +if (dp->exec_q) +xe_exec_queue_put (dp->exec_q);return ret; } +static int xe_oa_open_check_params (struct xe_oa *oa,struct drm_file *file, +struct drm_xe_oa_open_param *param, +struct xe_oa_derived_params *dp) +{#define OA_EXPONENT_MAX 31 -static int xe_oa_read_properties_unlocked (struct xe_oa *oa,u64 __user *uprops, -u32 n_props,struct drm_file *file, -struct xe_oa_open_properties *props) -{ -u64 __user *uprop = uprops; +u32 known_open_flags;int ret; -u32 i; -if (!n_props || n_props >=DRM_XE_OA_PROP_MAX ) { -drm_dbg (&oa->xe->drm,"Invalid number of xe perf properties given\n" ); +if (param->oa_unit_id >= oa->oa_unit_ids) { +drm_dbg (&oa->xe->drm,"OA unit ID out of range %d\n" , param->oa_unit_id);return -EINVAL ; } - props->poll_oa_period =DEFAULT_POLL_PERIOD_NS ; - -for (i =0 ; i < n_props; i++) { -u64 id, value; + ret =decode_oa_format (oa, param->oa_format, &dp->oa_format); +if (ret) { +drm_dbg (&oa->xe->drm,"Unsupported OA report format %#llx\n" , param->oa_format); +return ret; + } - ret =get_user (id, uprop); -if (ret) -return ret; +/* FIXME: not needed, check and remove */ +if (!param->metric_set) { +drm_dbg (&oa->xe->drm,"Unknown OA metric set ID %d\n" , param->metric_set); +return -EINVAL ; + } - ret =get_user (value, uprop +1 ); -if (ret) -return ret; +if (param->period_exponent >OA_EXPONENT_MAX ) { +drm_dbg (&oa->xe->drm,"OA timer exponent too high (> %u)\n" ,OA_EXPONENT_MAX ); +return -EINVAL ; + } -switch ((enum drm_xe_oa_property_id )id) { -case DRM_XE_OA_PROP_OA_UNIT_ID : -if (value >= oa->oa_unit_ids) { -drm_dbg (&oa->xe->drm,"OA unit ID out of range %lld\n" , value); -return -EINVAL ; - } - props->oa_unit_id = value; -break ; -case DRM_XE_OA_PROP_SAMPLE_OA : - props->sample = value; -break ; -case DRM_XE_OA_PROP_OA_METRICS_SET : -if (!value) { -drm_dbg (&oa->xe->drm,"Unknown OA metric set ID\n" ); -return -EINVAL ; - } - props->metrics_set = value; -break ; -case DRM_XE_OA_PROP_OA_FORMAT : - ret =decode_oa_format (oa, value, &props->oa_format); -if (ret) { -drm_dbg (&oa->xe->drm,"Unsupported OA report format %#llx\n" , - value); -return ret; - } -break ; -case DRM_XE_OA_PROP_OA_EXPONENT : -if (value >OA_EXPONENT_MAX ) { -drm_dbg (&oa->xe->drm,"OA timer exponent too high (> %u)\n" , -OA_EXPONENT_MAX ); -return -EINVAL ; - } - props->oa_periodic = true; - props->oa_period_exponent = value; -break ; -case DRM_XE_OA_PROP_POLL_OA_PERIOD : -if (value <100000 /* 100us */ ) { -drm_dbg (&oa->xe->drm,"OA timer too small (%lluns < 100us)\n" , - value); -return -EINVAL ; - } - props->poll_oa_period = value; -break ; -case DRM_XE_OA_PROP_EXEC_QUEUE_ID : - props->single_exec_q = true; - props->exec_q_id = value; -break ; -case DRM_XE_OA_PROP_OA_ENGINE_INSTANCE : - props->instance = value; -break ; -default : -drm_dbg (&oa->xe->drm,"Unknown xe oa property ID %lld\n" , id); -return -EINVAL ; - } +if (param->poll_period_us && param->poll_period_us <100 ) { +drm_dbg (&oa->xe->drm,"OA timer too small (%dus < 100us)\n" , param->poll_period_us); +return -EINVAL ; + } - uprop +=2 ; + known_open_flags =XE_OA_FLAG_FD_CLOEXEC |XE_OA_FLAG_FD_NONBLOCK |XE_OA_FLAG_DISABLED ; +if (param->open_flags & ~known_open_flags) { +drm_dbg (&oa->xe->drm,"Unknown open_flag %#x\n" , param->open_flags); +return -EINVAL ; } - ret =xe_oa_validate_properties (oa, props, file); + ret =__xe_oa_open_check_params (oa, file, param, dp);if (ret)return ret;
@@ -1716,9 +1662,8 @@ static int xe_oa_read_properties_unlocked(struct xe_oa *oa, u64 __user *uprops,int xe_oa_stream_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {struct xe_oa *oa = &to_xe_device (dev)->oa; -struct xe_oa_open_properties props = {}; +struct xe_oa_derived_params dp = {};struct drm_xe_oa_open_param param; -u32 known_open_flags;struct xe_gt *gt;int ret;
@@ -1731,26 +1676,19 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, void *data, struct drm_fileif (XE_IOCTL_DBG (oa->xe, ret))return -EFAULT ; - known_open_flags =XE_OA_FLAG_FD_CLOEXEC |XE_OA_FLAG_FD_NONBLOCK |XE_OA_FLAG_DISABLED ; -if (param.flags & ~known_open_flags) { -drm_dbg (&oa->xe->drm,"Unknown drm_xe_oa_open_param flag\n" ); -return -EINVAL ; - } - - ret =xe_oa_read_properties_unlocked (oa,u64_to_user_ptr (param.properties_ptr), - param.num_properties, file, &props); + ret =xe_oa_open_check_params (oa, file, ¶m, &dp);if (ret)return ret; - gt = props.hwe->gt; + gt = dp.hwe->gt;mutex_lock (>->oa.lock); - ret =xe_oa_stream_open_ioctl_locked (oa, ¶m, &props); + ret =xe_oa_stream_open_ioctl_locked (oa, ¶m, &dp);mutex_unlock (>->oa.lock); -/* Drop exec_q reference taken in read_properties/validate_properties on error */ -if (ret <0 && props.exec_q) -xe_exec_queue_put (props.exec_q); +/* On error, drop reference taken in validate_params/xe_exec_queue_lookup */ +if (ret <0 && dp.exec_q) +xe_exec_queue_put (dp.exec_q);return ret; }
drivers/gpu/drm/xe/xe_oa_types.h +2 -2
@@ -293,10 +293,10 @@ struct xe_oa_stream { } oa_buffer;/** -* @poll_oa_period: The period in nanoseconds at which the OA +* @poll_period_ns: The period in nanoseconds at which the OA * buffer should be checked for available data. */ -u64 poll_oa_period; +u64 poll_period_ns;/** * @override_gucrc: GuC RC has been overridden for the perf stream,
include/uapi/drm/xe_drm.h +58 -69
174 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [Intel-xe] [PATCH 21/21] drm/xe/uapi: Convert OA property key/value pairs to a struct
Quoted 5 lines · Ashutosh Dixit
Change OA uapi to take a param struct rather than property key value pairs. A param struct is simpler and param structs can be extenended in the future using
xe_user_extensionso there seems to be no reason to use property key value pairs.
There are two ways of doing this:
1. In this patch we have collected all OA properties into a single struct. The assumption is that any future changes would be handled via 'struct drm_xe_ext_set_property' chained structs (basically using xe_user_extension):
https://patchwork.freedesktop.org/patch/558715/
2. The second way to do it would be to use chained 'struct drm_xe_ext_set_property' from the beginning as is being done for DRM_XE_EXEC_QUEUE_SET_PROPERTY. This is basically the same as the earlier OA property key/value pairs except that the properties are now input via chained structs.
This second way is a uniform way of specifying property values whereas the first way in non-uniform.
Just thought I'll point this out when we decide about this uapi during the code review.
Thanks.
--
Ashutosh
Quoted 2 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>
/snip/
Quoted 183 lines
include/uapi/drm/xe_drm.h +58
-70@@ -1175,30 +1175,26 @@ struct drm_xe_query_oa_info { } oau[]; }; -enum drm_xe_oa_property_id { -/** -* ID of the OA unit on which to open the OA stream, see -* @oa_unit_id in 'struct drm_xe_engine_class_instance'. Defaults -* to 0 if not provided. -*/ -DRM_XE_OA_PROP_OA_UNIT_ID =1 , +struct drm_xe_oa_open_param { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions;/** -* A value of 1 requests the inclusion of raw OA unit reports as -* part of stream samples. +* @oa_unit_id: ID of the OA unit on which to open the OA stream, +* see @oa_unit_id in struct @drm_xe_engine_class_instance */ -DRM_XE_OA_PROP_SAMPLE_OA , +__u32 oa_unit_id;/** -* The value specifies which set of OA unit metrics should be -* configured, defining the contents of any OA unit reports. +* @sample_oa: A value of 1 requests the inclusion of raw OA unit +* reports as part of stream samples */ -DRM_XE_OA_PROP_OA_METRICS_SET , +__u32 sample_oa;/** -* The value specifies the size and layout of OA unit reports. +* @oa_format: The value specifies the size and layout of OA unit reports */ -DRM_XE_OA_PROP_OA_FORMAT , +__u64 oa_format;/** * OA_FORMAT's are specified the same way as in Bspec, in terms of * the following quantities: a. enum @drm_xe_oa_format_type @@ -1210,86 +1206,79 @@ enum drm_xe_oa_property_id {#define XE_OA_MASK_BC_REPORT (0xff << 24)/** -* Specifying this property implicitly requests periodic OA unit -* sampling and (at least on Haswell) the sampling frequency is derived -* from this exponent as follows: -* -* 80ns * 2^(period_exponent + 1) +* @metric_set: specifies which set of OA unit metrics should be +* configured, defining the contents of any OA unit reports. Metric +* set ID is returned by the XE_PERF_ADD_CONFIG op of the PREF ioctl */ -DRM_XE_OA_PROP_OA_EXPONENT , +__u32 metric_set;/** -* Specifying this property is only valid when specify a context to -* filter with DRM_XE_OA_PROP_ENGINE_ID. Specifying this property -* will hold preemption of the particular engine we want to gather -* performance data about. +* @period_exponent: Specifying this property implicitly requests +* periodic OA unit sampling. The sampling period is: +* +* 2^(period_exponent + 1) / @oa_timestamp_freq +* +* Set period_exponent *negative* to disable periodic sampling */ -DRM_XE_OA_PROP_HOLD_PREEMPTION , +__s32 period_exponent;/** -* Specify a global OA buffer size to be allocated in bytes. The -* size specified must be supported by HW (powers of 2 ranging from -* 128 KB to 128Mb depending on the platform) +* @oa_buffer_size: Specify a global OA buffer size to be allocated +* in bytes. The size specified must be supported by HW (powers of +* 2 ranging from 128 KB to 128Mb depending on the platform). A +* value of 0 will choose a default size of 16 MB. */ -DRM_XE_OA_PROP_OA_BUFFER_SIZE , +__u32 oa_buffer_size;/** -* This optional parameter specifies the timer interval in nanoseconds -* at which the xe driver will check the OA buffer for available data. -* Minimum allowed value is 100 microseconds. A default value is used by -* the driver if this parameter is not specified. Note that larger timer -* values will reduce cpu consumption during OA perf captures. However, -* excessively large values would potentially result in OA buffer -* overwrites as captures reach end of the OA buffer. +* @poll_period: Specify timer interval in micro-seconds at which +* the xe driver will check the OA buffer for available +* data. Minimum allowed value is 100 microseconds. A value of 0 +* selects a default value is used by the driver. Note that larger +* timer values will reduce cpu consumption during OA perf +* captures. However, excessively large values would potentially +* result in OA buffer overwrites as captures reach end of the OA +* buffer. */ -DRM_XE_OA_PROP_POLL_OA_PERIOD , +__u32 poll_period_us; + +/** @open_flags: Flags */ +__u32 open_flags; +#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) +#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) +#define XE_OA_FLAG_DISABLED (1 << 2)/** -* Open the stream for a specific exec queue id (as used with -* drm_xe_exec). A stream opened for a specific exec queue id this -* way won't typically require root privileges. +* @exec_queue_id: Open the stream for a specific exec queue id (as +* used with drm_xe_exec). A stream opened for a specific exec +* queue id this way won't typically require root +* privileges. Pass a value <= 0 to not specify an exec queue id. */ -DRM_XE_OA_PROP_EXEC_QUEUE_ID , +__s32 exec_queue_id;/** -* This parameter specifies the engine instance and can be passed along -* with DRM_XE_OA_PROP_EXEC_QUEUE_ID or will default to 0. +* @engine_instance: engine instance to use with @exec_queue_id. */ -DRM_XE_OA_PROP_OA_ENGINE_INSTANCE , +__u32 engine_instance; -DRM_XE_OA_PROP_MAX /* non-ABI */ -}; - -struct drm_xe_oa_open_param { -/** @extensions: Pointer to the first extension struct, if any */ -__u64 extensions; +/** +* @hold_preemption: If true, this will disable preemption for the +* exec queue selected with @exec_queue_id +*/ +__u32 hold_preemption;/** -* @config_syncobj: (Output) handle to configuration syncobj +* @config_syncobj: (output) handle to configuration syncobj * * Handle to a syncobj which the kernel will signal after stream * configuration or re-configuration is complete (after return from * the ioctl). This handle can be provided as a dependency to the -* next XE exec ioctl. +* next xe exec ioctl to synchronize xe exec with oa config changes */ __u32 config_syncobj; -__u32 reserved; - -/** @flags: Flags */ -__u32 flags; -#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) -#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) -#define XE_OA_FLAG_DISABLED (1 << 2) - -/** The number of u64 (id, value) pairs */ -__u32 num_properties; - -/** -* Pointer to array of u64 (id, value) pairs configuring the stream -* to open. -*/ -__u64 properties_ptr; +/** @reserved: reserved (MBZ) */ +__u64 reserved[4 ]; };struct drm_xe_oa_record_header { --2.41.0
Re: [Intel-xe] [PATCH 21/21] drm/xe/uapi: Convert OA property key/value pairs to a struct
Quoted 1 line · Ashutosh
Hi Umesh,
Quoted 22 lines · Ashutosh Dixit
Quoted 5 lines
Change OA uapi to take a param struct rather than property key value pairs. A param struct is simpler and param structs can be extenended in the future using
xe_user_extensionso there seems to be no reason to use property key value pairs.There are two ways of doing this:
1. In this patch we have collected all OA properties into a single struct. The assumption is that any future changes would be handled via 'struct
drm_xe_ext_set_property' chained structs (basically usingxe_user_extension):https://patchwork.freedesktop.org/patch/558715/2. The second way to do it would be to use chained 'struct
drm_xe_ext_set_property' from the beginning as is being done forDRM_XE_EXEC_QUEUE_SET_PROPERTY. This is basically the same as the earlier OA property key/value pairs except that the properties are now input via chained structs.
Quoted 5 lines
This second way is a uniform way of specifying property values whereas the first way in non-uniform.
Just thought I'll point this out when we decide about this uapi during the code review.
Since we are almost certain that the OA uapi will need to be extended in the future, for the sake of uniformity maybe we should go with the approach
2. above (this patch implements approach 1.)? Something to keep in mind for the review of this patch. This is what I was referring to earlier today.
Thanks.
--
Ashutosh
Quoted 189 lines
Quoted 3 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>/snip/
Quoted 183 lines
include/uapi/drm/xe_drm.h +58
-70@@ -1175,30 +1175,26 @@ struct drm_xe_query_oa_info { } oau[]; }; -enum drm_xe_oa_property_id { -/** -* ID of the OA unit on which to open the OA stream, see -* @oa_unit_id in 'struct drm_xe_engine_class_instance'. Defaults -* to 0 if not provided. -*/ -DRM_XE_OA_PROP_OA_UNIT_ID =1 , +struct drm_xe_oa_open_param { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions;/** -* A value of 1 requests the inclusion of raw OA unit reports as -* part of stream samples. +* @oa_unit_id: ID of the OA unit on which to open the OA stream, +* see @oa_unit_id in struct @drm_xe_engine_class_instance */ -DRM_XE_OA_PROP_SAMPLE_OA , +__u32 oa_unit_id;/** -* The value specifies which set of OA unit metrics should be -* configured, defining the contents of any OA unit reports. +* @sample_oa: A value of 1 requests the inclusion of raw OA unit +* reports as part of stream samples */ -DRM_XE_OA_PROP_OA_METRICS_SET , +__u32 sample_oa;/** -* The value specifies the size and layout of OA unit reports. +* @oa_format: The value specifies the size and layout of OA unit reports */ -DRM_XE_OA_PROP_OA_FORMAT , +__u64 oa_format;/** * OA_FORMAT's are specified the same way as in Bspec, in terms of * the following quantities: a. enum @drm_xe_oa_format_type @@ -1210,86 +1206,79 @@ enum drm_xe_oa_property_id {#define XE_OA_MASK_BC_REPORT (0xff << 24)/** -* Specifying this property implicitly requests periodic OA unit -* sampling and (at least on Haswell) the sampling frequency is derived -* from this exponent as follows: -* -* 80ns * 2^(period_exponent + 1) +* @metric_set: specifies which set of OA unit metrics should be +* configured, defining the contents of any OA unit reports. Metric +* set ID is returned by the XE_PERF_ADD_CONFIG op of the PREF ioctl */ -DRM_XE_OA_PROP_OA_EXPONENT , +__u32 metric_set;/** -* Specifying this property is only valid when specify a context to -* filter with DRM_XE_OA_PROP_ENGINE_ID. Specifying this property -* will hold preemption of the particular engine we want to gather -* performance data about. +* @period_exponent: Specifying this property implicitly requests +* periodic OA unit sampling. The sampling period is: +* +* 2^(period_exponent + 1) / @oa_timestamp_freq +* +* Set period_exponent *negative* to disable periodic sampling */ -DRM_XE_OA_PROP_HOLD_PREEMPTION , +__s32 period_exponent;/** -* Specify a global OA buffer size to be allocated in bytes. The -* size specified must be supported by HW (powers of 2 ranging from -* 128 KB to 128Mb depending on the platform) +* @oa_buffer_size: Specify a global OA buffer size to be allocated +* in bytes. The size specified must be supported by HW (powers of +* 2 ranging from 128 KB to 128Mb depending on the platform). A +* value of 0 will choose a default size of 16 MB. */ -DRM_XE_OA_PROP_OA_BUFFER_SIZE , +__u32 oa_buffer_size;/** -* This optional parameter specifies the timer interval in nanoseconds -* at which the xe driver will check the OA buffer for available data. -* Minimum allowed value is 100 microseconds. A default value is used by -* the driver if this parameter is not specified. Note that larger timer -* values will reduce cpu consumption during OA perf captures. However, -* excessively large values would potentially result in OA buffer -* overwrites as captures reach end of the OA buffer. +* @poll_period: Specify timer interval in micro-seconds at which +* the xe driver will check the OA buffer for available +* data. Minimum allowed value is 100 microseconds. A value of 0 +* selects a default value is used by the driver. Note that larger +* timer values will reduce cpu consumption during OA perf +* captures. However, excessively large values would potentially +* result in OA buffer overwrites as captures reach end of the OA +* buffer. */ -DRM_XE_OA_PROP_POLL_OA_PERIOD , +__u32 poll_period_us; + +/** @open_flags: Flags */ +__u32 open_flags; +#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) +#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) +#define XE_OA_FLAG_DISABLED (1 << 2)/** -* Open the stream for a specific exec queue id (as used with -* drm_xe_exec). A stream opened for a specific exec queue id this -* way won't typically require root privileges. +* @exec_queue_id: Open the stream for a specific exec queue id (as +* used with drm_xe_exec). A stream opened for a specific exec +* queue id this way won't typically require root +* privileges. Pass a value <= 0 to not specify an exec queue id. */ -DRM_XE_OA_PROP_EXEC_QUEUE_ID , +__s32 exec_queue_id;/** -* This parameter specifies the engine instance and can be passed along -* with DRM_XE_OA_PROP_EXEC_QUEUE_ID or will default to 0. +* @engine_instance: engine instance to use with @exec_queue_id. */ -DRM_XE_OA_PROP_OA_ENGINE_INSTANCE , +__u32 engine_instance; -DRM_XE_OA_PROP_MAX /* non-ABI */ -}; - -struct drm_xe_oa_open_param { -/** @extensions: Pointer to the first extension struct, if any */ -__u64 extensions; +/** +* @hold_preemption: If true, this will disable preemption for the +* exec queue selected with @exec_queue_id +*/ +__u32 hold_preemption;/** -* @config_syncobj: (Output) handle to configuration syncobj +* @config_syncobj: (output) handle to configuration syncobj * * Handle to a syncobj which the kernel will signal after stream * configuration or re-configuration is complete (after return from * the ioctl). This handle can be provided as a dependency to the -* next XE exec ioctl. +* next xe exec ioctl to synchronize xe exec with oa config changes */ __u32 config_syncobj; -__u32 reserved; - -/** @flags: Flags */ -__u32 flags; -#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) -#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) -#define XE_OA_FLAG_DISABLED (1 << 2) - -/** The number of u64 (id, value) pairs */ -__u32 num_properties; - -/** -* Pointer to array of u64 (id, value) pairs configuring the stream -* to open. -*/ -__u64 properties_ptr; +/** @reserved: reserved (MBZ) */ +__u64 reserved[4 ]; };struct drm_xe_oa_record_header { --2.41.0
Re: [Intel-xe] [PATCH 21/21] drm/xe/uapi: Convert OA property key/value pairs to a struct
Quoted 30 lines · Ashutosh
Quoted 1 line · Ashutosh
Hi Umesh,
Quoted 25 lines · Ashutosh Dixit
Quoted 5 lines
Change OA uapi to take a param struct rather than property key value pairs. A param struct is simpler and param structs can be extenended in the future using
xe_user_extensionso there seems to be no reason to use property key value pairs.There are two ways of doing this:
1. In this patch we have collected all OA properties into a single struct. The assumption is that any future changes would be handled via 'struct
drm_xe_ext_set_property' chained structs (basically usingxe_user_extension):https://patchwork.freedesktop.org/patch/558715/2. The second way to do it would be to use chained 'struct
drm_xe_ext_set_property' from the beginning as is being done forDRM_XE_EXEC_QUEUE_SET_PROPERTY. This is basically the same as the earlier OA property key/value pairs except that the properties are now input via chained structs.This second way is a uniform way of specifying property values whereas the first way in non-uniform.
Quoted 7 lines
Quoted 2 lines
Just thought I'll point this out when we decide about this uapi during the code review.
Since we are almost certain that the OA uapi will need to be extended in the future, for the sake of uniformity maybe we should go with the approach
2. above (this patch implements approach 1.)? Something to keep in mind for the review of this patch. This is what I was referring to earlier today.
Let's go with 2 then. I will skip reviewing this.
Quoted 194 lines
Thanks.
--
AshutoshQuoted 189 lines
Quoted 3 lines
Suggested-by Umesh Nerlige Ramappa <[email protected]>Signed-off-by Ashutosh Dixit <[email protected]>/snip/
Quoted 183 lines
include/uapi/drm/xe_drm.h +58
-70@@ -1175,30 +1175,26 @@ struct drm_xe_query_oa_info { } oau[]; }; -enum drm_xe_oa_property_id { -/** -* ID of the OA unit on which to open the OA stream, see -* @oa_unit_id in 'struct drm_xe_engine_class_instance'. Defaults -* to 0 if not provided. -*/ -DRM_XE_OA_PROP_OA_UNIT_ID =1 , +struct drm_xe_oa_open_param { +/** @extensions: Pointer to the first extension struct, if any */ +__u64 extensions;/** -* A value of 1 requests the inclusion of raw OA unit reports as -* part of stream samples. +* @oa_unit_id: ID of the OA unit on which to open the OA stream, +* see @oa_unit_id in struct @drm_xe_engine_class_instance */ -DRM_XE_OA_PROP_SAMPLE_OA , +__u32 oa_unit_id;/** -* The value specifies which set of OA unit metrics should be -* configured, defining the contents of any OA unit reports. +* @sample_oa: A value of 1 requests the inclusion of raw OA unit +* reports as part of stream samples */ -DRM_XE_OA_PROP_OA_METRICS_SET , +__u32 sample_oa;/** -* The value specifies the size and layout of OA unit reports. +* @oa_format: The value specifies the size and layout of OA unit reports */ -DRM_XE_OA_PROP_OA_FORMAT , +__u64 oa_format;/** * OA_FORMAT's are specified the same way as in Bspec, in terms of * the following quantities: a. enum @drm_xe_oa_format_type @@ -1210,86 +1206,79 @@ enum drm_xe_oa_property_id {#define XE_OA_MASK_BC_REPORT (0xff << 24)/** -* Specifying this property implicitly requests periodic OA unit -* sampling and (at least on Haswell) the sampling frequency is derived -* from this exponent as follows: -* -* 80ns * 2^(period_exponent + 1) +* @metric_set: specifies which set of OA unit metrics should be +* configured, defining the contents of any OA unit reports. Metric +* set ID is returned by the XE_PERF_ADD_CONFIG op of the PREF ioctl */ -DRM_XE_OA_PROP_OA_EXPONENT , +__u32 metric_set;/** -* Specifying this property is only valid when specify a context to -* filter with DRM_XE_OA_PROP_ENGINE_ID. Specifying this property -* will hold preemption of the particular engine we want to gather -* performance data about. +* @period_exponent: Specifying this property implicitly requests +* periodic OA unit sampling. The sampling period is: +* +* 2^(period_exponent + 1) / @oa_timestamp_freq +* +* Set period_exponent *negative* to disable periodic sampling */ -DRM_XE_OA_PROP_HOLD_PREEMPTION , +__s32 period_exponent;/** -* Specify a global OA buffer size to be allocated in bytes. The -* size specified must be supported by HW (powers of 2 ranging from -* 128 KB to 128Mb depending on the platform) +* @oa_buffer_size: Specify a global OA buffer size to be allocated +* in bytes. The size specified must be supported by HW (powers of +* 2 ranging from 128 KB to 128Mb depending on the platform). A +* value of 0 will choose a default size of 16 MB. */ -DRM_XE_OA_PROP_OA_BUFFER_SIZE , +__u32 oa_buffer_size;/** -* This optional parameter specifies the timer interval in nanoseconds -* at which the xe driver will check the OA buffer for available data. -* Minimum allowed value is 100 microseconds. A default value is used by -* the driver if this parameter is not specified. Note that larger timer -* values will reduce cpu consumption during OA perf captures. However, -* excessively large values would potentially result in OA buffer -* overwrites as captures reach end of the OA buffer. +* @poll_period: Specify timer interval in micro-seconds at which +* the xe driver will check the OA buffer for available +* data. Minimum allowed value is 100 microseconds. A value of 0 +* selects a default value is used by the driver. Note that larger +* timer values will reduce cpu consumption during OA perf +* captures. However, excessively large values would potentially +* result in OA buffer overwrites as captures reach end of the OA +* buffer. */ -DRM_XE_OA_PROP_POLL_OA_PERIOD , +__u32 poll_period_us; + +/** @open_flags: Flags */ +__u32 open_flags; +#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) +#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) +#define XE_OA_FLAG_DISABLED (1 << 2)/** -* Open the stream for a specific exec queue id (as used with -* drm_xe_exec). A stream opened for a specific exec queue id this -* way won't typically require root privileges. +* @exec_queue_id: Open the stream for a specific exec queue id (as +* used with drm_xe_exec). A stream opened for a specific exec +* queue id this way won't typically require root +* privileges. Pass a value <= 0 to not specify an exec queue id. */ -DRM_XE_OA_PROP_EXEC_QUEUE_ID , +__s32 exec_queue_id;/** -* This parameter specifies the engine instance and can be passed along -* with DRM_XE_OA_PROP_EXEC_QUEUE_ID or will default to 0. +* @engine_instance: engine instance to use with @exec_queue_id. */ -DRM_XE_OA_PROP_OA_ENGINE_INSTANCE , +__u32 engine_instance; -DRM_XE_OA_PROP_MAX /* non-ABI */ -}; - -struct drm_xe_oa_open_param { -/** @extensions: Pointer to the first extension struct, if any */ -__u64 extensions; +/** +* @hold_preemption: If true, this will disable preemption for the +* exec queue selected with @exec_queue_id +*/ +__u32 hold_preemption;/** -* @config_syncobj: (Output) handle to configuration syncobj +* @config_syncobj: (output) handle to configuration syncobj * * Handle to a syncobj which the kernel will signal after stream * configuration or re-configuration is complete (after return from * the ioctl). This handle can be provided as a dependency to the -* next XE exec ioctl. +* next xe exec ioctl to synchronize xe exec with oa config changes */ __u32 config_syncobj; -__u32 reserved; - -/** @flags: Flags */ -__u32 flags; -#define XE_OA_FLAG_FD_CLOEXEC (1 << 0) -#define XE_OA_FLAG_FD_NONBLOCK (1 << 1) -#define XE_OA_FLAG_DISABLED (1 << 2) - -/** The number of u64 (id, value) pairs */ -__u32 num_properties; - -/** -* Pointer to array of u64 (id, value) pairs configuring the stream -* to open. -*/ -__u64 properties_ptr; +/** @reserved: reserved (MBZ) */ +__u64 reserved[4 ]; };struct drm_xe_oa_record_header { --2.41.0
Patchwork
CI[Intel-xe] ✓ CI.Patch_applied: success for Add OA functionality to Xe (rev6)
In reply to Ashutosh Dixit== Series Details ==
== Series Details ==
Series: Add OA functionality to Xe (rev6)
URL : https://patchwork.freedesktop.org/series/121084/
State : success
== Summary ==
=== Applying kernel patches on branch 'drm-xe-next' with base: ===
Base commit: fac2e20c7 Revert "FIXME: drm/i915/hpd: skip intel_hpd_poll_fini() for non-display paths" === git am output follows ===
Applying: drm/xe/uapi: Introduce OA (observability architecture) uapi
Applying: drm/xe/oa: Add OA types
Applying: drm/xe/oa: Add registers and GPU commands used by OA
Applying: drm/xe/oa: Module init/exit and probe/remove
Applying: drm/xe/oa: Add/remove config ioctl's
Applying: drm/xe/oa: Start implementing OA stream open ioctl
Applying: drm/xe/oa: OA stream initialization
Applying: drm/xe/oa: Expose OA stream fd
Applying: drm/xe/oa: Read file_operation
Applying: drm/xe/oa: Implement queries
Applying: drm/xe/oa: Override GuC RC with OA on PVC
Applying: drm/xe/uapi: "Perf" layer to support multiple perf counter stream types
Applying: drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl
Applying: drm/xe/uapi: Simplify OA configs in uapi
Applying: drm/xe/uapi: Remove OA format names from OA uapi
Applying: drm/xe/oa: Make xe_oa_timestamp_frequency per gt
Applying: drm/xe/oa: Remove filtering reports on context id
Applying: drm/xe/uapi: More OA uapi fixes/additions
Applying: drm/xe/uapi: Drop OA_IOCTL_VERSION
Applying: drm/xe/uapi: Use OA unit id to identify OA unit
Applying: drm/xe/uapi: Convert OA property key/value pairs to a struct
Patchwork
CI[Intel-xe] ✗ CI.checkpatch: warning for Add OA functionality to Xe (rev6)
In reply to Ashutosh Dixit== Series Details ==
== Series Details ==
Series: Add OA functionality to Xe (rev6)
URL : https://patchwork.freedesktop.org/series/121084/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 63c2b6b160bca2df6efc7bc4cea6f442097d7854
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 91586655208548314519f3e7cb8aa67226ed179c
Author: Ashutosh Dixit <[email protected]> Date: Tue Sep 19 09:10:49 2023 -0700
drm/xe/uapi: Convert OA property key/value pairs to a struct
Change OA uapi to take a param struct rather than property key value pairs. A param struct is simpler and param structs can be extenended in the future using xe_user_extension so there seems to be no reason to use property key value pairs.
+ /mt/dim checkpatch fac2e20c785bd790c250e4f4799dfa28e44e7082 drm-intel d26d60548 drm/xe/uapi: Introduce OA (observability architecture) uapi -:38: WARNING:LONG_LINE: line length of 119 exceeds 100 columns #38: FILE: include/uapi/drm/xe_drm.h:133:
+#define DRM_IOCTL_XE_OA_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_OPEN, struct drm_xe_oa_open_param)
-:39: WARNING:LONG_LINE: line length of 121 exceeds 100 columns #39: FILE: include/uapi/drm/xe_drm.h:134:
+#define DRM_IOCTL_XE_OA_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_ADD_CONFIG, struct drm_xe_oa_config)
-:40: WARNING:LONG_LINE: line length of 106 exceeds 100 columns #40: FILE: include/uapi/drm/xe_drm.h:135:
+#define DRM_IOCTL_XE_OA_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OA_REMOVE_CONFIG, __u64)
total: 0 errors, 3 warnings, 0 checks, 291 lines checkeda75037184 drm/xe/oa: Add OA types
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:17: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #17:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 295 lines checkede003a1a12 drm/xe/oa: Add registers and GPU commands used by OA
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:74: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #74:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 219 lines checkedfb603a692 drm/xe/oa: Module init/exit and probe/remove
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:156: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #156:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 430 lines checked07959d2ac drm/xe/oa: Add/remove config ioctl's9d835612f drm/xe/oa: Start implementing OA stream open ioctl16aba32a9 drm/xe/oa: OA stream initialization779cd1d01 drm/xe/oa: Expose OA stream fd724ef3c8a drm/xe/oa: Read file_operation28086b4b9 drm/xe/oa: Implement queriesb725b4c7e drm/xe/oa: Override GuC RC with OA on PVC091754c18 drm/xe/uapi: "Perf" layer to support multiple perf counter stream types Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:181: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #181:
new file mode 100644
-:286: WARNING:LONG_LINE: line length of 118 exceeds 100 columns #286: FILE: include/uapi/drm/xe_drm.h:133:
+#define DRM_IOCTL_XE_PERF_OPEN DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF_OPEN, struct drm_xe_perf_param)
-:287: WARNING:LONG_LINE: line length of 124 exceeds 100 columns #287: FILE: include/uapi/drm/xe_drm.h:134:
+#define DRM_IOCTL_XE_PERF_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF_ADD_CONFIG, struct drm_xe_perf_param)
-:288: WARNING:LONG_LINE: line length of 127 exceeds 100 columns #288: FILE: include/uapi/drm/xe_drm.h:135:
+#define DRM_IOCTL_XE_PERF_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF_REMOVE_CONFIG, struct drm_xe_perf_param)
total: 0 errors, 4 warnings, 0 checks, 289 lines checked 608a27016 drm/xe/uapi: Multiplex PERF ops through a single PERF ioctl -:124: WARNING:LONG_LINE: line length of 113 exceeds 100 columns #124: FILE: include/uapi/drm/xe_drm.h:131:
+#define DRM_IOCTL_XE_PERF DRM_IOW(DRM_COMMAND_BASE + DRM_XE_PERF, struct drm_xe_perf_param)
total: 0 errors, 1 warnings, 0 checks, 112 lines checked ac80af02e drm/xe/uapi: Simplify OA configs in uapi 53b7fa776 drm/xe/uapi: Remove OA format names from OA uapi 0904e0bef drm/xe/oa: Make xe_oa_timestamp_frequency per gt fd2e16bcb drm/xe/oa: Remove filtering reports on context id 8516dd55c drm/xe/uapi: More OA uapi fixes/additions 5a9b1d54b drm/xe/uapi: Drop OA_IOCTL_VERSION28114c1e1 drm/xe/uapi: Use OA unit id to identify OA unit 915866552 drm/xe/uapi: Convert OA property key/value pairs to a struct