[PATCH i-g-t] i915/perf: Test OA buffer wrap around

Umesh Nerlige Ramappa umesh.nerlige.ramappa at intel.com
Tue Nov 24 01:56:52 UTC 2020


Ensure that reports generated after OA buffer wraps around pass the
sanity check.

Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa at intel.com>
---
 tests/i915/perf.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git a/tests/i915/perf.c b/tests/i915/perf.c
index caeabd62..fb2f7232 100644
--- a/tests/i915/perf.c
+++ b/tests/i915/perf.c
@@ -1154,6 +1154,90 @@ test_missing_sample_flags(void)
 	do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, &param, EINVAL);
 }
 
+static const char *header_msg[DRM_I915_PERF_RECORD_MAX] = {
+	[DRM_I915_PERF_RECORD_SAMPLE] = "OA sample",
+	[DRM_I915_PERF_RECORD_OA_REPORT_LOST] = "OA report lost",
+	[DRM_I915_PERF_RECORD_OA_BUFFER_LOST] = "OA buffer lost",
+};
+
+static size_t
+read_reports(int fd, void *buf, size_t count)
+{
+	ssize_t len;
+
+	while ((len = read(fd, buf, count)) < 0 && errno == EINTR)
+		;
+
+	return len;
+}
+
+static void *get_report(uint8_t *buf, size_t *offset, size_t len, int format_id)
+{
+	struct drm_i915_perf_record_header *header;
+	size_t format_size = get_oa_format(format_id).size;
+	size_t sample_size = sizeof(*header) + format_size;
+
+	igt_assert(len > sizeof(*header));
+
+	header = (void *)(buf + *offset);
+	igt_assert_eq(header->pad, 0);
+	igt_assert(header->type < DRM_I915_PERF_RECORD_MAX);
+	igt_assert_neq(header->type, DRM_I915_PERF_RECORD_OA_BUFFER_LOST);
+	if (header->type == DRM_I915_PERF_RECORD_OA_REPORT_LOST) {
+		/*
+		 * If a report follows these errors, then the report will have a
+		 * sample record. Adjust len and offset accordingly
+		 */
+		igt_debug("%s\n", header_msg[header->type]);
+		*offset += sizeof(*header);
+		len -= sizeof(header);
+		header++;
+	}
+
+	igt_assert(len >= sample_size);
+	igt_assert_eq(header->type, DRM_I915_PERF_RECORD_SAMPLE);
+	igt_assert_eq(header->size, sample_size);
+
+	*offset += sample_size;
+
+	return (void *)(header + 1);
+}
+
+static void read_oa_reports(int format, int num_reports)
+{
+	size_t format_size = get_oa_format(format).size;
+	size_t sample_size = sizeof(struct drm_i915_perf_record_header) +
+			     format_size;
+	size_t buf_size = num_reports * sample_size;
+	uint8_t *buf = malloc(buf_size);
+	uint32_t *report1, *report0;
+	size_t len = 0, offset = 0;
+	uint32_t count;
+
+	igt_require(buf);
+	/*
+	 * If we are using a fast exponent and a limited read buffer, we will
+	 * reach an OA BUFFER LOST condition soon. Use a buffer that fits all
+	 * reports and read all reports. Sanity check later.
+	 */
+	while (len < buf_size) {
+		len += read_reports(stream_fd, buf + len, buf_size - len);
+		igt_assert(len > 0);
+	}
+	igt_debug("read %lu bytes\n", len);
+
+	for (count = 0; offset < buf_size; count++) {
+		report1 = get_report(buf, &offset, buf_size - offset, format);
+		if (count > 0)
+			sanity_check_reports(report0, report1, format);
+
+		report0 = report1;
+	}
+	free(buf);
+
+	igt_assert_eq(count, num_reports);
+}
+
 static void
 read_2_oa_reports(int format_id,
 		  int exponent,
@@ -1457,6 +1541,32 @@ print_report(uint32_t *report, int fmt)
 }
 #endif
 
+static void
+test_oa_buffer_wrap_around(void)
+{
+	int exponent = max_oa_exponent_for_period_lte(40 * 1000);
+	uint64_t properties[] = {
+		DRM_I915_PERF_PROP_SAMPLE_OA, true,
+		DRM_I915_PERF_PROP_OA_METRICS_SET, test_set->perf_oa_metrics_set,
+		DRM_I915_PERF_PROP_OA_FORMAT, test_set->perf_oa_format,
+		DRM_I915_PERF_PROP_OA_EXPONENT, exponent,
+	};
+	struct drm_i915_perf_open_param param = {
+		.flags = I915_PERF_FLAG_FD_CLOEXEC,
+		.num_properties = ARRAY_SIZE(properties) / 2,
+		.properties_ptr = to_user_pointer(properties),
+	};
+	struct oa_format format = get_oa_format(test_set->perf_oa_format);
+	int num_reports = (16 * 1024 * 1024 / format.size) * 2 + 1000;
+
+	igt_assert(format.name);
+	igt_debug("Reading %d reports for OA format %s\n", num_reports, format.name);
+
+	stream_fd = __perf_open(drm_fd, &param, false);
+	read_oa_reports(test_set->perf_oa_format, num_reports);
+	__perf_close(stream_fd);
+}
+
 static void
 test_oa_formats(void)
 {
@@ -4867,6 +4977,10 @@ igt_main
 	igt_subtest("oa-formats")
 		test_oa_formats();
 
+	igt_describe("Test report sanity on OA buffer wrap around");
+	igt_subtest("oa-buffer-wrap-around")
+		test_oa_buffer_wrap_around();
+
 	igt_subtest("invalid-oa-exponent")
 		test_invalid_oa_exponent();
 	igt_subtest("low-oa-exponent-permissions")
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list