[PATCH i-g-t 1/1] tests/intel/xe_oa: Add test for different OA buffer sizes
Sai Teja Pottumuttu
sai.teja.pottumuttu at intel.com
Wed Dec 4 16:16:06 UTC 2024
Add a new test oa-buffer-size to test different OA buffer sizes, its
allocation and overflow scenarios. The test uses the new property
DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE to be able to vary the OA buffer
sizes.
Signed-off-by: Sai Teja Pottumuttu <sai.teja.pottumuttu at intel.com>
---
include/drm-uapi/xe_drm.h | 8 +++++
tests/intel/xe_oa.c | 71 +++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/include/drm-uapi/xe_drm.h b/include/drm-uapi/xe_drm.h
index 56163eb91..6d3ea045f 100644
--- a/include/drm-uapi/xe_drm.h
+++ b/include/drm-uapi/xe_drm.h
@@ -1486,6 +1486,7 @@ struct drm_xe_oa_unit {
__u64 capabilities;
#define DRM_XE_OA_CAPS_BASE (1 << 0)
#define DRM_XE_OA_CAPS_SYNCS (1 << 1)
+#define DRM_XE_OA_CAPS_OA_BUFFER_SIZE (1 << 2)
/** @oa_timestamp_freq: OA timestamp freq */
__u64 oa_timestamp_freq;
@@ -1651,6 +1652,13 @@ enum drm_xe_oa_property_id {
* to the VM bind case.
*/
DRM_XE_OA_PROPERTY_SYNCS,
+
+ /**
+ * @DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE: Specifies the size of OA buffer
+ * allocated by the driver in bytes. The default size would be 16MB and the
+ * supported sizes are powers of 2 from 128KB to 128MB.
+ */
+ DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE,
};
/**
diff --git a/tests/intel/xe_oa.c b/tests/intel/xe_oa.c
index 40f5d3607..abe0d2cc3 100644
--- a/tests/intel/xe_oa.c
+++ b/tests/intel/xe_oa.c
@@ -2504,6 +2504,60 @@ again_1:
__perf_close(stream_fd);
}
+/**
+ * SUBTEST: oa-buffer-size
+ * Description: Test OA buffer allocation and overflow with different OA buffer sizes.
+ */
+static void test_oa_buffer_size(size_t oa_buffer_size)
+{
+ int oa_exponent = max_oa_exponent_for_period_lte(20000);
+ uint64_t properties[] = {
+ DRM_XE_OA_PROPERTY_OA_UNIT_ID, 0,
+
+ /* Include OA reports in samples */
+ DRM_XE_OA_PROPERTY_SAMPLE_OA, true,
+
+ /* OA unit configuration */
+ DRM_XE_OA_PROPERTY_OA_METRIC_SET, default_test_set->perf_oa_metrics_set,
+ DRM_XE_OA_PROPERTY_OA_FORMAT, __ff(default_test_set->perf_oa_format),
+ DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT, oa_exponent,
+
+ DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE, oa_buffer_size
+ };
+ struct intel_xe_oa_open_prop param = {
+ .num_properties = ARRAY_SIZE(properties) / 2,
+ .properties_ptr = to_user_pointer(properties),
+ };
+ uint32_t buf_size = 2 * oa_buffer_size;
+ uint8_t *buf = malloc(buf_size);
+ struct drm_xe_oa_stream_info info;
+ uint32_t total_len = 0;
+ int len;
+ u32 oa_status;
+
+ igt_assert(buf);
+
+ stream_fd = __perf_open(drm_fd, ¶m, true);
+
+ do_ioctl(stream_fd, DRM_XE_OBSERVATION_IOCTL_INFO, &info);
+ igt_assert_eq(oa_buffer_size, info.oa_buf_size);
+
+ while (total_len < buf_size &&
+ ((len = read(stream_fd, &buf[total_len], buf_size - total_len)) > 0 ||
+ (len == -1 && (errno == EINTR || errno == EIO)))) {
+ if (errno == EIO) {
+ oa_status = get_stream_status(stream_fd);
+ igt_debug("oa_status %#x\n", oa_status);
+ igt_assert(!(oa_status & DRM_XE_OASTATUS_BUFFER_OVERFLOW));
+ }
+ if (len > 0)
+ total_len += len;
+ }
+
+ __perf_close(stream_fd);
+ free(buf);
+}
+
/**
* SUBTEST: non-zero-reason
* Description: Test reason field is non-zero. Can also check OA buffer wraparound issues
@@ -4870,6 +4924,23 @@ igt_main
igt_subtest_with_dynamic("buffer-fill")
__for_one_hwe_in_oag(hwe)
test_buffer_fill(hwe);
+ igt_subtest_group {
+ igt_fixture {
+ struct drm_xe_query_oa_units *qoa = xe_oa_units(drm_fd);
+ struct drm_xe_oa_unit *oau = (struct drm_xe_oa_unit *)&qoa->oa_units[0];
+
+ igt_require(oau->capabilities & DRM_XE_OA_CAPS_OA_BUFFER_SIZE);
+ }
+
+ igt_subtest_with_dynamic("oa-buffer-size") {
+ igt_dynamic_f("8MB")
+ test_oa_buffer_size(SZ_8M);
+ igt_dynamic_f("32MB")
+ test_oa_buffer_size(SZ_32M);
+ igt_dynamic("128MB")
+ test_oa_buffer_size(SZ_128M);
+ }
+ }
igt_subtest_with_dynamic("non-zero-reason") {
__for_one_hwe_in_oag(hwe)
--
2.34.1
More information about the igt-dev
mailing list