[PATCH i-g-t] i915/perf: Test OA buffer wrap around
Umesh Nerlige Ramappa
umesh.nerlige.ramappa at intel.com
Fri Nov 20 17:27:36 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 | 103 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/tests/i915/perf.c b/tests/i915/perf.c
index caeabd62..6b097e35 100644
--- a/tests/i915/perf.c
+++ b/tests/i915/perf.c
@@ -1154,6 +1154,79 @@ test_missing_sample_flags(void)
do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m, 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);
+ if (header->type == DRM_I915_PERF_RECORD_OA_BUFFER_LOST ||
+ header->type == DRM_I915_PERF_RECORD_OA_REPORT_LOST) {
+ igt_debug("%s\n", header_msg[header->type]);
+ *offset += sizeof(*header);
+ len -= sizeof(header);
+ header++;
+ }
+
+ igt_assert_eq(header->type, DRM_I915_PERF_RECORD_SAMPLE);
+ igt_assert_eq(header->size, sample_size);
+ igt_assert(len > 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;
+ uint32_t *report0 = malloc(format_size);
+ uint8_t *buf = malloc(MAX_OA_BUF_SIZE);
+ size_t offset = 0;
+ int count = 0;
+
+ while (count < num_reports) {
+ ssize_t len = read_reports(stream_fd, buf, MAX_OA_BUF_SIZE);
+
+ igt_assert(len > 0);
+ igt_kmsg("read %d bytes\n", (int)len);
+
+ while(offset < len && count++ < num_reports) {
+ uint32_t *report1 = get_report(buf, &offset, len,
+ format);
+
+ if (count >= 2)
+ sanity_check_reports(report0, report1, format);
+
+ memcpy(report0, report1, format_size);
+ }
+ }
+ free(buf);
+ free(report0);
+ igt_assert_eq(count, num_reports);
+}
+
static void
read_2_oa_reports(int format_id,
int exponent,
@@ -1457,6 +1530,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(100 * 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, ¶m, false);
+ read_oa_reports(test_set->perf_oa_format, num_reports);
+ __perf_close(stream_fd);
+}
+
static void
test_oa_formats(void)
{
@@ -4867,6 +4966,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