[PATCH 1/1] drm/xe/oa: Combined diff of changes between v8 and v9

Ashutosh Dixit ashutosh.dixit at intel.com
Thu Feb 8 05:35:18 UTC 2024


Because Xe OA changes between successive revisions are distributed across
multiple patches, provide a combined diff of all changes in a single patch
to help with the code review.

These changes pertain to: https://patchwork.freedesktop.org/series/121084/

This patch will not compile, it's purpose is to just provide the diff.

Changes between v8 and v9 include:

* Disable overrun mode only when time based sampling is enabled
* Use graphics versions rather than absolute platform names
* Skip reporting reserved engines attached to OA units
* Remove gt_id, open_stream and oa_buf_size from 'struct drm_xe_oa_unit'
  used in drm_xe_query_oa_units
* Expose oa_buf_size via DRM_XE_PERF_IOCTL_INFO perf fd ioctl
* Introduce 'struct drm_xe_oa_stream_status' for returning OA stream
  status (rather than returning just via DRM_XE_PERF_IOCTL_STATUS return
  code
* Clarify some uapi comments

Signed-off-by: Ashutosh Dixit <ashutosh.dixit at intel.com>
---
 drivers/gpu/drm/xe/xe_oa.c    | 87 +++++++++++++++++++----------------
 drivers/gpu/drm/xe/xe_query.c |  8 ++--
 include/uapi/drm/xe_drm.h     | 73 ++++++++++++++++++++++-------
 3 files changed, 106 insertions(+), 62 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index 560b6a3189e42..c26bbed1940ec 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -381,7 +381,7 @@ static void xe_oa_init_oa_buffer(struct xe_oa_stream *stream)
 	 * mode to avoid this issue.
 	 */
 	if (GRAPHICS_VER(stream->oa->xe) >= 20 &&
-	    stream->hwe->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG)
+	    stream->hwe->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG && stream->sample)
 		oa_buf |= OAG_OABUFFER_DISABLE_OVERRUN_MODE;
 	/*
 	 * PRM says: "This MMIO must be set before the OATAILPTR register and after the
@@ -1029,12 +1029,29 @@ static long xe_oa_config_locked(struct xe_oa_stream *stream,
 	return ret;
 }
 
-static long xe_oa_status_locked(struct xe_oa_stream *stream)
+static long xe_oa_status_locked(struct xe_oa_stream *stream, unsigned long arg)
 {
-	u32 ret = xe_mmio_read32(stream->gt, __oa_regs(stream)->oa_status);
+	struct drm_xe_oa_stream_status status = {};
+	void __user *uaddr = (void __user *)arg;
+
+	status.oa_status = xe_mmio_read32(stream->gt, __oa_regs(stream)->oa_status);
+
+	if (copy_to_user(uaddr, &status, sizeof(status)))
+		return -EFAULT;
 
 	xe_mmio_write32(stream->gt, __oa_regs(stream)->oa_status, 0);
-	return ret;
+	return 0;
+}
+
+static long xe_oa_info_locked(struct xe_oa_stream *stream, unsigned long arg)
+{
+	struct drm_xe_oa_stream_info info = { .oa_buf_size = XE_OA_BUFFER_SIZE, };
+	void __user *uaddr = (void __user *)arg;
+
+	if (copy_to_user(uaddr, &info, sizeof(info)))
+		return -EFAULT;
+
+	return 0;
 }
 
 static long xe_oa_ioctl_locked(struct xe_oa_stream *stream,
@@ -1051,7 +1068,9 @@ static long xe_oa_ioctl_locked(struct xe_oa_stream *stream,
 	case DRM_XE_PERF_IOCTL_CONFIG:
 		return xe_oa_config_locked(stream, arg);
 	case DRM_XE_PERF_IOCTL_STATUS:
-		return xe_oa_status_locked(stream);
+		return xe_oa_status_locked(stream, arg);
+	case DRM_XE_PERF_IOCTL_INFO:
+		return xe_oa_info_locked(stream, arg);
 	}
 
 	return -EINVAL;
@@ -2206,37 +2225,8 @@ static void oa_format_add(struct xe_oa *oa, enum xe_oa_format_name format)
 
 static void xe_oa_init_supported_formats(struct xe_oa *oa)
 {
-	switch (oa->xe->info.platform) {
-	case XE_TIGERLAKE:
-	case XE_ROCKETLAKE:
-	case XE_ALDERLAKE_S:
-	case XE_ALDERLAKE_P:
-	case XE_ALDERLAKE_N:
-	case XE_DG1:
-		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:
-	case XE_PVC:
-		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_OAC_FORMAT_A24u64_B8_C8);
-		oa_format_add(oa, XE_OAC_FORMAT_A22u32_R2u32_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_OAC_FORMAT_A24u64_B8_C8);
-		oa_format_add(oa, XE_OAC_FORMAT_A22u32_R2u32_B8_C8);
-		oa_format_add(oa, XE_OAM_FORMAT_MPEC8u64_B8_C8);
-		oa_format_add(oa, XE_OAM_FORMAT_MPEC8u32_B8_C8);
-		break;
-
-	case XE_LUNARLAKE:
+	if (GRAPHICS_VER(oa->xe) >= 20) {
+		/* Xe2+ */
 		oa_format_add(oa, XE_OAM_FORMAT_MPEC8u64_B8_C8);
 		oa_format_add(oa, XE_OAM_FORMAT_MPEC8u32_B8_C8);
 		oa_format_add(oa, XE_OA_FORMAT_PEC64u64);
@@ -2248,10 +2238,27 @@ static void xe_oa_init_supported_formats(struct xe_oa *oa)
 		oa_format_add(oa, XE_OA_FORMAT_PEC32u32_G2);
 		oa_format_add(oa, XE_OA_FORMAT_PEC36u64_G1_32_G2_4);
 		oa_format_add(oa, XE_OA_FORMAT_PEC36u64_G1_4_G2_32);
-		break;
-
-	default:
-		drm_err(&oa->xe->drm, "Unknown platform\n");
+	} else if (GRAPHICS_VERx100(oa->xe) >= 1270) {
+		/* 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_OAC_FORMAT_A24u64_B8_C8);
+		oa_format_add(oa, XE_OAC_FORMAT_A22u32_R2u32_B8_C8);
+		oa_format_add(oa, XE_OAM_FORMAT_MPEC8u64_B8_C8);
+		oa_format_add(oa, XE_OAM_FORMAT_MPEC8u32_B8_C8);
+	} else if (GRAPHICS_VERx100(oa->xe) >= 1255) {
+		/* XE_DG2, XE_PVC */
+		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_OAC_FORMAT_A24u64_B8_C8);
+		oa_format_add(oa, XE_OAC_FORMAT_A22u32_R2u32_B8_C8);
+	} else {
+		/* Gen12+ */
+		xe_assert(oa->xe, GRAPHICS_VER(oa->xe) >= 12);
+		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);
 	}
 }
 
diff --git a/drivers/gpu/drm/xe/xe_query.c b/drivers/gpu/drm/xe/xe_query.c
index 6f8fc9d2127ed..828be65a076d6 100644
--- a/drivers/gpu/drm/xe/xe_query.c
+++ b/drivers/gpu/drm/xe/xe_query.c
@@ -566,18 +566,15 @@ static int query_oa_units(struct xe_device *xe,
 
 			du->oa_unit_id = u->oa_unit_id;
 			du->oa_unit_type = u->type;
-			du->gt_id = gt->info.id;
-			du->open_stream = !!u->exclusive_stream;
 			du->oa_timestamp_freq = xe_oa_timestamp_frequency(gt);
-			du->oa_buf_size = XE_OA_BUFFER_SIZE;
-			du->num_engines = u->num_engines;
 
 			for (j = 1; j < DRM_XE_OA_PROPERTY_MAX; j++)
 				du->capabilities |= BIT(j);
 
 			j = 0;
 			for_each_hw_engine(hwe, gt, hwe_id) {
-				if (xe_oa_unit_id(hwe) == u->oa_unit_id) {
+				if (!xe_hw_engine_is_reserved(hwe) &&
+				    xe_oa_unit_id(hwe) == u->oa_unit_id) {
 					du->eci[j].engine_class =
 						xe_to_user_engine_class[hwe->class];
 					du->eci[j].engine_instance = hwe->logical_instance;
@@ -585,6 +582,7 @@ static int query_oa_units(struct xe_device *xe,
 					j++;
 				}
 			}
+			du->num_engines = j;
 			pdu += sizeof(*du) + j * sizeof(du->eci[0]);
 			qoa->num_oa_units++;
 		}
diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
index 2c0949b248d9a..bd535343a406c 100644
--- a/include/uapi/drm/xe_drm.h
+++ b/include/uapi/drm/xe_drm.h
@@ -1385,6 +1385,9 @@ struct drm_xe_perf_param {
 
 /**
  * enum drm_xe_perf_ioctls - Perf fd ioctl's
+ *
+ * Information exchanged between userspace and kernel for perf fd ioctl's
+ * is stream type specific
  */
 enum drm_xe_perf_ioctls {
 	/** @DRM_XE_PERF_IOCTL_ENABLE: Enable data capture for a stream */
@@ -1396,8 +1399,11 @@ enum drm_xe_perf_ioctls {
 	/** @DRM_XE_PERF_IOCTL_CONFIG: Change stream configuration */
 	DRM_XE_PERF_IOCTL_CONFIG = _IO('i', 0x2),
 
-	/** @DRM_XE_PERF_IOCTL_STATUS: Stream status */
+	/** @DRM_XE_PERF_IOCTL_STATUS: Return stream status */
 	DRM_XE_PERF_IOCTL_STATUS = _IO('i', 0x3),
+
+	/** @DRM_XE_PERF_IOCTL_INFO: Return stream info */
+	DRM_XE_PERF_IOCTL_INFO = _IO('i', 0x4),
 };
 
 /** enum drm_xe_oa_unit_type - OA unit types */
@@ -1411,26 +1417,20 @@ enum drm_xe_oa_unit_type {
  */
 struct drm_xe_oa_unit {
 	/** @oa_unit_id: OA unit ID */
-	__u16 oa_unit_id;
+	__u32 oa_unit_id;
 
 	/** @oa_unit_type: OA unit type of @drm_xe_oa_unit_type */
-	__u16 oa_unit_type;
-
-	/** @gt_id: GT ID for this OA unit */
-	__u16 gt_id;
+	__u32 oa_unit_type;
 
-	/** @open_stream: True if a stream is open on the OA unit */
-	__u16 open_stream;
-
-	/** @capabilities: OA capabilities bit-mask */
+	/**
+	 * @capabilities: OA capabilities bit-mask: this is a bit-mask of
+	 * property id's in enum @drm_xe_oa_property_id
+	 */
 	__u64 capabilities;
 
 	/** @oa_timestamp_freq: OA timestamp freq */
 	__u64 oa_timestamp_freq;
 
-	/** @oa_buf_size: OA buffer size */
-	__u64 oa_buf_size;
-
 	/** @reserved: MBZ */
 	__u64 reserved[4];
 
@@ -1448,8 +1448,22 @@ struct drm_xe_oa_unit {
  * is equal to DRM_XE_DEVICE_QUERY_OA_UNITS, then the reply uses struct
  * drm_xe_query_oa_units in .data.
  *
- * When there is an @open_stream, the query returns properties specific to
- * that @open_stream. Else default properties are returned.
+ * OA unit properties for all OA units can be accessed using a code block
+ * such as the one below:
+ *
+ * .. code-block:: C
+ *
+ *	struct drm_xe_query_oa_units *qoa;
+ *	struct drm_xe_oa_unit *oau;
+ *	u8 *poau;
+ *
+ *	// malloc qoa and issue DRM_XE_DEVICE_QUERY_OA_UNITS. Then:
+ *	poau = (u8 *)&qoa->oa_units[0];
+ *	for (int i = 0; i < qoa->num_oa_units; i++) {
+ *		oau = (struct drm_xe_oa_unit *)poau;
+ *		// Access 'struct drm_xe_oa_unit' fields here
+ *		poau += sizeof(*oau) + oau->num_engines * sizeof(oau->eci[0]);
+ *	}
  */
 struct drm_xe_query_oa_units {
 	/** @num_oa_units: number of OA units returned in oau[] */
@@ -1489,8 +1503,9 @@ enum drm_xe_oa_property_id {
 	DRM_XE_OA_PROPERTY_OA_UNIT_ID = 1,
 
 	/**
-	 * @DRM_XE_OA_PROPERTY_SAMPLE_OA: A value of 1 requests the inclusion of
-	 * raw OA unit reports as part of stream samples.
+	 * @DRM_XE_OA_PROPERTY_SAMPLE_OA: A value of 1 requests inclusion of raw
+	 * OA unit reports or stream samples in a global buffer attached to an
+	 * OA unit.
 	 */
 	DRM_XE_OA_PROPERTY_SAMPLE_OA,
 
@@ -1563,6 +1578,30 @@ struct drm_xe_oa_config {
 	__u64 regs_ptr;
 };
 
+/**
+ * struct drm_xe_oa_stream_status - OA stream status returned from
+ * @DRM_XE_PERF_IOCTL_STATUS perf fd ioctl
+ */
+struct drm_xe_oa_stream_status {
+	/** @oa_status: OA status register as specified in Bspec */
+	__u64 oa_status;
+
+	/** @reserved */
+	__u64 reserved[3];
+};
+
+/**
+ * struct drm_xe_oa_stream_info - OA stream info returned from
+ * @DRM_XE_PERF_IOCTL_INFO perf fd ioctl
+ */
+struct drm_xe_oa_stream_info {
+	/** @oa_buf_size: OA buffer size */
+	__u64 oa_buf_size;
+
+	/** @reserved */
+	__u64 reserved[3];
+};
+
 #if defined(__cplusplus)
 }
 #endif
-- 
2.41.0



More information about the Intel-xe mailing list