All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v2 4/4] tests/perf: add new tests for configurable OA buffer size
Date: Mon, 15 Oct 2018 17:20:41 +0100	[thread overview]
Message-ID: <20181015162041.29140-5-lionel.g.landwerlin@intel.com> (raw)
In-Reply-To: <20181015162041.29140-1-lionel.g.landwerlin@intel.com>

Verify that the buffer fills up within the expected time based of a
given size and also that invalid sizes are rejected.

v2: Update tests to reflect that we have to match the exact HW buffer
    size (Lionel)
    Bump the minimum buffer fill duration requirement to 40ms
    (unreliable otherwise on small cores & ICL) (Lionel)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 tests/perf.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 111 insertions(+), 9 deletions(-)

diff --git a/tests/perf.c b/tests/perf.c
index 6c448036..4b7bb689 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -2348,11 +2348,31 @@ test_polling(void)
 	__perf_close(stream_fd);
 }
 
+static int
+find_oa_exponent_for_buffer_fill_time(size_t oa_buf_size, size_t report_size, uint64_t fill_time_ns)
+{
+	size_t n_reports = oa_buf_size / report_size;
+
+	for (int e = 1; e < 32; e++) {
+		if (fill_time_ns < oa_exponent_to_ns(e) * n_reports)
+			return e;
+	}
+
+	igt_assert(!"reached");
+	return -1;
+}
+
 static void
-test_buffer_fill(void)
+test_buffer_fill(bool program_size, size_t oa_buf_size)
 {
-	/* ~5 micro second period */
-	int oa_exponent = max_oa_exponent_for_period_lte(5000);
+	size_t report_size = get_oa_format(test_oa_format).size;
+	/*
+	 * Select an exponent that guarantees that the buffer fills up
+	 * in about 40ms. Otherwise the nanosleep might be too short
+	 * which makes the test unreliable.
+	 */
+	int oa_exponent = find_oa_exponent_for_buffer_fill_time(oa_buf_size, report_size,
+								40 * 1000 * 1000UL);
 	uint64_t oa_period = oa_exponent_to_ns(oa_exponent);
 	uint64_t properties[] = {
 		/* Include OA reports in samples */
@@ -2362,18 +2382,18 @@ test_buffer_fill(void)
 		DRM_I915_PERF_PROP_OA_METRICS_SET, test_metric_set_id,
 		DRM_I915_PERF_PROP_OA_FORMAT, test_oa_format,
 		DRM_I915_PERF_PROP_OA_EXPONENT, oa_exponent,
+		DRM_I915_PERF_PROP_OA_BUFFER_SIZE, oa_buf_size,
 	};
 	struct drm_i915_perf_open_param param = {
 		.flags = I915_PERF_FLAG_FD_CLOEXEC,
-		.num_properties = sizeof(properties) / 16,
+		.num_properties = program_size ?
+		(ARRAY_SIZE(properties) / 2) : ((ARRAY_SIZE(properties) / 2) - 1),
 		.properties_ptr = to_user_pointer(properties),
 	};
 	struct drm_i915_perf_record_header *header;
 	int buf_size = 65536 * (256 + sizeof(struct drm_i915_perf_record_header));
 	uint8_t *buf = malloc(buf_size);
 	int len;
-	size_t oa_buf_size = DEFAULT_OA_BUF_SIZE;
-	size_t report_size = get_oa_format(test_oa_format).size;
 	int n_full_oa_reports = oa_buf_size / report_size;
 	uint64_t fill_duration = n_full_oa_reports * oa_period;
 
@@ -2410,8 +2430,9 @@ test_buffer_fill(void)
 
 		do_ioctl(stream_fd, I915_PERF_IOCTL_DISABLE, 0);
 
-		igt_debug("fill_duration = %"PRIu64"ns, oa_exponent = %u\n",
-			  fill_duration, oa_exponent);
+		igt_debug("fill_duration = %"PRIu64"ns/%"PRIu64"us/%"PRIu64"ms, oa_exponent = %u, buf_size = %lu\n",
+			  fill_duration, fill_duration / 1000, fill_duration / 1000000,
+			  oa_exponent, oa_buf_size);
 
 		do_ioctl(stream_fd, I915_PERF_IOCTL_ENABLE, 0);
 
@@ -2491,6 +2512,43 @@ test_buffer_fill(void)
 	__perf_close(stream_fd);
 }
 
+static void
+test_invalid_buffer_size()
+{
+	uint64_t properties[] = {
+		/* Include OA reports in samples */
+		DRM_I915_PERF_PROP_SAMPLE_OA, true,
+
+		/* OA unit configuration */
+		DRM_I915_PERF_PROP_OA_METRICS_SET, test_metric_set_id,
+		DRM_I915_PERF_PROP_OA_FORMAT, test_oa_format,
+		DRM_I915_PERF_PROP_OA_EXPONENT, max_oa_exponent_for_period_lte(5000),
+		DRM_I915_PERF_PROP_OA_BUFFER_SIZE, 0 /* updated below */,
+	};
+	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),
+	};
+	size_t size = 128 * 1024;
+
+	while (size <= DEFAULT_OA_BUF_SIZE) {
+		properties[ARRAY_SIZE(properties) - 1] = size + 2;
+		do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, &param, EINVAL);
+
+		size *= 2;
+	}
+
+	properties[ARRAY_SIZE(properties) - 1] = DEFAULT_OA_BUF_SIZE * 2;
+	do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, &param, EINVAL);
+
+	properties[ARRAY_SIZE(properties) - 1] = 0xffffffff;
+	do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, &param, EINVAL);
+
+	properties[ARRAY_SIZE(properties) - 1] = 0xffffffffffffffff;
+	do_ioctl_err(drm_fd, DRM_IOCTL_I915_PERF_OPEN, &param, EINVAL);
+}
+
 static void
 test_enable_disable(void)
 {
@@ -4093,6 +4151,32 @@ test_sysctl_defaults(void)
 	igt_assert_eq(max_freq, 100000);
 }
 
+static bool
+kernel_supports_open_option(int fd, uint64_t option, uint64_t value)
+{
+	uint64_t properties[] = {
+		/* Intentionally wrong handle */
+		DRM_I915_PERF_PROP_CTX_HANDLE, UINT64_MAX,
+
+		DRM_I915_PERF_PROP_SAMPLE_OA, true,
+		DRM_I915_PERF_PROP_OA_METRICS_SET, test_metric_set_id,
+		DRM_I915_PERF_PROP_OA_FORMAT, test_oa_format,
+		DRM_I915_PERF_PROP_OA_EXPONENT, max_oa_exponent_for_period_lte(5000),
+		option, value,
+	};
+	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),
+	};
+	int ret;
+
+	ret = igt_ioctl(fd, DRM_IOCTL_I915_PERF_OPEN, &param);
+	assert(ret == -1);
+
+	return errno == ENOENT;
+}
+
 igt_main
 {
 	igt_skip_on_simulation();
@@ -4166,7 +4250,25 @@ igt_main
 	}
 
 	igt_subtest("buffer-fill")
-		test_buffer_fill();
+		test_buffer_fill(false, DEFAULT_OA_BUF_SIZE);
+
+	igt_subtest("buffer-fill-sized") {
+		size_t size = 128 * 1024; /* Smallest HW supported size. */
+		const size_t max_size = DEFAULT_OA_BUF_SIZE;
+
+		igt_require(kernel_supports_open_option(drm_fd, DRM_I915_PERF_PROP_OA_BUFFER_SIZE, 0));
+
+		while (size <= max_size) {
+			test_buffer_fill(true, size);
+			size *= 2;
+		}
+	}
+
+	igt_subtest("invalid-buffer-size") {
+		igt_require(kernel_supports_open_option(drm_fd, DRM_I915_PERF_PROP_OA_BUFFER_SIZE, 0));
+
+		test_invalid_buffer_size();
+	}
 
 	igt_subtest("disabled-read-error")
 		test_disabled_read_error();
-- 
2.19.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-10-15 16:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-15 16:20 [igt-dev] [PATCH i-g-t v2 0/4] tests/perf: add support for new oa buffer size parameter Lionel Landwerlin
2018-10-15 16:20 ` [igt-dev] [PATCH i-g-t v2 1/4] include: bump drm uAPI headers Lionel Landwerlin
2018-10-22 18:36   ` Matthew Auld
2018-10-15 16:20 ` [igt-dev] [PATCH i-g-t v2 2/4] tests/perf: buffer-fill: drop load helper usage Lionel Landwerlin
2018-10-22 17:34   ` Matthew Auld
2018-10-15 16:20 ` [igt-dev] [PATCH i-g-t v2 3/4] tests/perf: rename MAX_OA_BUFFER_SIZE Lionel Landwerlin
2018-10-22 17:44   ` Matthew Auld
2018-10-15 16:20 ` Lionel Landwerlin [this message]
2018-10-22 18:33   ` [igt-dev] [PATCH i-g-t v2 4/4] tests/perf: add new tests for configurable OA buffer size Matthew Auld
2018-10-15 17:53 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/perf: add support for new oa buffer size parameter (rev2) Patchwork
2018-10-15 23:12 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181015162041.29140-5-lionel.g.landwerlin@intel.com \
    --to=lionel.g.landwerlin@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.