All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] tests/perf: add a test for OA data polling reads using "small" buffers
@ 2020-03-27 22:29 Ashutosh Dixit
  2020-03-27 23:09 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/perf: add a test for OA data polling reads using "small" buffers (rev3) Patchwork
  2020-03-28 17:52 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
  0 siblings, 2 replies; 18+ messages in thread
From: Ashutosh Dixit @ 2020-03-27 22:29 UTC (permalink / raw)
  To: igt-dev

Add a test for OA data non-blocking reads using buffers smaller than
the available data. This test would fail for perf revisions < 5
because poll would block even when data was available. Therefore the
amount of data read was limited by the buffer size and the timer
interval and it was impossible to read all available data. This issue
is fixed in perf revision 5.

v2: Complete rewrite, make test fail on existing kernels (Lionel)

v3: Use infinite ppoll timeout (Umesh)
    Increase mismatch tolerance to 20% (Ashutosh)

Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 tests/perf.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/tests/perf.c b/tests/perf.c
index 442d89fbe..6c0b2ee7f 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -2284,6 +2284,65 @@ test_polling(uint64_t requested_oa_period, bool set_kernel_hrtimer, uint64_t ker
 	__perf_close(stream_fd);
 }
 
+static void test_polling_small_buf(void)
+{
+	int oa_exponent = max_oa_exponent_for_period_lte(40 * 1000); /* 40us */
+	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_set->perf_oa_metrics_set,
+		DRM_I915_PERF_PROP_OA_FORMAT, test_set->perf_oa_format,
+		DRM_I915_PERF_PROP_OA_EXPONENT, oa_exponent,
+	};
+	struct drm_i915_perf_open_param param = {
+		.flags = I915_PERF_FLAG_FD_CLOEXEC |
+			I915_PERF_FLAG_DISABLED |
+			I915_PERF_FLAG_FD_NONBLOCK,
+		.num_properties = NUM_PROPERTIES(properties),
+		.properties_ptr = to_user_pointer(properties),
+	};
+	uint32_t test_duration = 80 * 1000 * 1000;
+	int sample_size = (sizeof(struct drm_i915_perf_record_header) +
+				get_oa_format(test_set->perf_oa_format).size);
+	int n_expected_reports = test_duration / oa_exponent_to_ns(oa_exponent);
+	int n_expect_read_bytes = n_expected_reports * sample_size;
+	uint8_t buf[1024];
+	int n_bytes_read = 0;
+	uint32_t n_polls = 0;
+	struct timespec ts = {};
+
+	stream_fd = __perf_open(drm_fd, &param, true /* prevent_pm */);
+	do_ioctl(stream_fd, I915_PERF_IOCTL_ENABLE, 0);
+
+	igt_nsec_elapsed(&ts);
+
+	while (igt_nsec_elapsed(&ts) < test_duration) {
+		struct pollfd pollfd = { .fd = stream_fd, .events = POLLIN };
+		int ret;
+
+		ret = ppoll(&pollfd, 1, NULL, NULL);
+
+		if (pollfd.revents & POLLIN) {
+			ret = read(stream_fd, buf, sizeof(buf));
+			if (ret >= 0)
+				n_bytes_read += ret;
+		}
+
+		n_polls++;
+	}
+
+	igt_info("Read %d expected %d (%.2f%% of the expected number), polls=%u\n",
+		  n_bytes_read, n_expect_read_bytes,
+		  n_bytes_read * 100.0f / n_expect_read_bytes,
+		  n_polls);
+
+	__perf_close(stream_fd);
+
+	igt_assert(abs(n_expect_read_bytes - n_bytes_read) < (0.20 * n_expect_read_bytes));
+}
+
 static int
 num_valid_reports_captured(struct drm_i915_perf_open_param *param,
 			   int64_t *duration_ns)
@@ -4919,6 +4978,10 @@ igt_main
 			     2 * 1000 * 1000 /* default 2ms hrtimer */);
 	}
 
+	igt_describe("Test polled read with buffer size smaller than available data");
+	igt_subtest("polling-small-buf")
+		test_polling_small_buf();
+
 	igt_subtest("short-reads")
 		test_short_reads();
 
-- 
2.25.2

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

^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [igt-dev] [PATCH i-g-t] tests/perf: add a test for OA data polling reads using "small" buffers
@ 2020-03-27  4:42 Ashutosh Dixit
  2020-03-27  4:50 ` Dixit, Ashutosh
  2020-03-27 20:56 ` Umesh Nerlige Ramappa
  0 siblings, 2 replies; 18+ messages in thread
From: Ashutosh Dixit @ 2020-03-27  4:42 UTC (permalink / raw)
  To: igt-dev

Add a test for OA data non-blocking reads using buffers smaller than
the available data. This test would fail for perf revisions < 5
because poll would block even when data was available. Therefore the
amount of data read was limited by the buffer size and the timer
interval and it was impossible to read all available data. This issue
is fixed in perf revision 5.

v2: Complete rewrite, make test fail on existing kernels (Lionel)

Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 tests/perf.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/tests/perf.c b/tests/perf.c
index 724f6f809..3dc757c3b 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -2265,6 +2265,71 @@ test_polling(void)
 	__perf_close(stream_fd);
 }
 
+static void test_polling_small_buf(void)
+{
+	int oa_exponent = max_oa_exponent_for_period_lte(40 * 1000); /* 40us */
+	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_set->perf_oa_metrics_set,
+		DRM_I915_PERF_PROP_OA_FORMAT, test_set->perf_oa_format,
+		DRM_I915_PERF_PROP_OA_EXPONENT, oa_exponent,
+	};
+	struct drm_i915_perf_open_param param = {
+		.flags = I915_PERF_FLAG_FD_CLOEXEC |
+			I915_PERF_FLAG_DISABLED |
+			I915_PERF_FLAG_FD_NONBLOCK,
+		.num_properties = NUM_PROPERTIES(properties),
+		.properties_ptr = to_user_pointer(properties),
+	};
+	uint32_t test_duration = 80 * 1000 * 1000;
+	int sample_size = (sizeof(struct drm_i915_perf_record_header) +
+				get_oa_format(test_set->perf_oa_format).size);
+	int n_expected_reports = test_duration / oa_exponent_to_ns(oa_exponent);
+	int n_expect_read_bytes = n_expected_reports * sample_size;
+	uint8_t buf[1024];
+	int n_bytes_read = 0;
+	uint32_t n_polls = 0;
+	struct timespec ts = {};
+
+	stream_fd = __perf_open(drm_fd, &param, true /* prevent_pm */);
+	do_ioctl(stream_fd, I915_PERF_IOCTL_ENABLE, 0);
+
+	igt_nsec_elapsed(&ts);
+
+	while (igt_nsec_elapsed(&ts) < test_duration) {
+		struct timespec poll_wait = {
+			.tv_sec = 0,
+			.tv_nsec = (test_duration - igt_nsec_elapsed(&ts)),
+		};
+		struct pollfd pollfd = { .fd = stream_fd, .events = POLLIN };
+		int ret;
+
+		ret = ppoll(&pollfd, 1, &poll_wait, NULL);
+
+		if (pollfd.revents & POLLIN) {
+			ret = read(stream_fd, buf, sizeof(buf));
+			if (ret >= 0)
+				n_bytes_read += ret;
+		}
+
+		n_polls++;
+
+		igt_debug("Elapsed=%lu wait=%lu\n", igt_nsec_elapsed(&ts), poll_wait.tv_nsec);
+	}
+
+	igt_info("Read %d expected %d (%.2f%% of the expected number), polls=%u\n",
+		  n_bytes_read, n_expect_read_bytes,
+		  n_bytes_read * 100.0f / n_expect_read_bytes,
+		  n_polls);
+
+	__perf_close(stream_fd);
+
+	igt_assert(abs(n_expect_read_bytes - n_bytes_read) < (0.10 * n_expect_read_bytes));
+}
+
 static int
 num_valid_reports_captured(struct drm_i915_perf_open_param *param,
 			   int64_t *duration_ns)
@@ -4676,6 +4741,10 @@ igt_main
 	igt_subtest("polling")
 		test_polling();
 
+	igt_describe("Test polled read with buffer size smaller than available data");
+	igt_subtest("polling-small-buf")
+		test_polling_small_buf();
+
 	igt_subtest("short-reads")
 		test_short_reads();
 
-- 
2.25.2

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

^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [igt-dev] [PATCH i-g-t] tests/perf: add a test for OA data polling reads using "small" buffers
@ 2020-03-26  5:42 Ashutosh Dixit
  2020-03-26  9:02 ` Lionel Landwerlin
  0 siblings, 1 reply; 18+ messages in thread
From: Ashutosh Dixit @ 2020-03-26  5:42 UTC (permalink / raw)
  To: igt-dev

Add a test for OA data non-blocking reads using buffers smaller than
the available data. This test would fail for perf revisions < 5
because poll would block even when data was available. Therefore the
amount of data read was limited by the buffer size and the timer
interval and it was impossible to read all available data. This issue
is fixed in perf revision 5.

Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Signed-off--by: Ashutosh Dixit <ashutosh.dixit@intel.com>
---
 tests/perf.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/tests/perf.c b/tests/perf.c
index 724f6f809..41e3b4478 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -2265,6 +2265,81 @@ test_polling(void)
 	__perf_close(stream_fd);
 }
 
+static void test_polling_small_buf(void)
+{
+	int oa_exponent = max_oa_exponent_for_period_lte(10 * 1000 * 1000); /* 10ms */
+	/* Use a large value for the timer for a large amout of data to accumulate */
+	uint64_t kernel_hrtimer = 400 * 1000 * 1000; /* 400 ms */
+	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_set->perf_oa_metrics_set,
+		DRM_I915_PERF_PROP_OA_FORMAT, test_set->perf_oa_format,
+		DRM_I915_PERF_PROP_OA_EXPONENT, oa_exponent,
+
+		/* Kernel configuration (optional) */
+		DRM_I915_PERF_PROP_POLL_OA_PERIOD, kernel_hrtimer,
+	};
+	struct drm_i915_perf_open_param param = {
+		.flags = I915_PERF_FLAG_FD_CLOEXEC |
+			I915_PERF_FLAG_DISABLED |
+			I915_PERF_FLAG_FD_NONBLOCK,
+		.num_properties = NUM_PROPERTIES(properties),
+		.properties_ptr = to_user_pointer(properties),
+	};
+	uint8_t buf[1024 * 1024];
+	int ret, iterl = 0, iters = 0, large = 0, small = 0;
+	struct timespec tsl = {}, tss = {};
+
+	stream_fd = __perf_open(drm_fd, &param, true /* prevent_pm */);
+	do_ioctl(stream_fd, I915_PERF_IOCTL_ENABLE, 0);
+
+	/* First do non blocking reads for 4 seconds using 1 MB buffer */
+	igt_nsec_elapsed(&tsl);
+	igt_until_timeout(4) {
+		struct pollfd pollfd = { .fd = stream_fd, .events = POLLIN };
+
+		ret = poll(&pollfd, 1, -1);
+		igt_assert_eq(ret, 1);
+		igt_assert(pollfd.revents & POLLIN);
+
+		ret = read(stream_fd, buf, sizeof(buf));
+		igt_assert(ret > 0);
+		large += ret;
+		iterl++;
+	}
+	igt_debug("Read %d B in %d iterations in %ld ns using 1 MB buffer\n",
+		  large, iterl, igt_nsec_elapsed(&tsl));
+
+	/* Now repeat the read with a 4 KB buffer */
+	igt_nsec_elapsed(&tss);
+	igt_until_timeout(4) {
+		struct pollfd pollfd = { .fd = stream_fd, .events = POLLIN };
+
+		ret = poll(&pollfd, 1, -1);
+		igt_assert_eq(ret, 1);
+		igt_assert(pollfd.revents & POLLIN);
+
+		ret = read(stream_fd, buf, 4096);
+		igt_assert(ret > 0);
+		small += ret;
+		iters++;
+	}
+	igt_debug("Read %d B in %d iterations in %ld ns using 4 KB buffer\n",
+		  small, iters, igt_nsec_elapsed(&tss));
+
+	__perf_close(stream_fd);
+
+	/* Check that data read using the two methods is within 20% of each
+	 * other. Differences between the two cases is due to timing coupled
+	 * with granularity of the data reads, but they are still expected to be
+	 * "close".
+	 */
+	igt_assert(abs(large - small) * 100 / ((large + small) / 2) < 20);
+}
+
 static int
 num_valid_reports_captured(struct drm_i915_perf_open_param *param,
 			   int64_t *duration_ns)
@@ -4676,6 +4751,12 @@ igt_main
 	igt_subtest("polling")
 		test_polling();
 
+	igt_describe("Test polled read with buffer size smaller than available data");
+	igt_subtest("polling-small-buf") {
+		igt_require(i915_perf_revision(drm_fd) >= 5);
+		test_polling_small_buf();
+	}
+
 	igt_subtest("short-reads")
 		test_short_reads();
 
-- 
2.25.2

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

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-04-03  1:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27 22:29 [igt-dev] [PATCH i-g-t] tests/perf: add a test for OA data polling reads using "small" buffers Ashutosh Dixit
2020-03-27 23:09 ` [igt-dev] ✓ Fi.CI.BAT: success for tests/perf: add a test for OA data polling reads using "small" buffers (rev3) Patchwork
2020-03-28 17:52 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2020-03-27  4:42 [igt-dev] [PATCH i-g-t] tests/perf: add a test for OA data polling reads using "small" buffers Ashutosh Dixit
2020-03-27  4:50 ` Dixit, Ashutosh
2020-03-27 16:09   ` Lionel Landwerlin
2020-03-27 19:03     ` Dixit, Ashutosh
2020-03-27 19:06       ` Lionel Landwerlin
2020-03-27 19:49         ` Dixit, Ashutosh
2020-03-31  6:06           ` Dixit, Ashutosh
2020-03-31  7:36             ` Lionel Landwerlin
2020-03-31  7:48               ` Dixit, Ashutosh
2020-04-03  1:19                 ` Dixit, Ashutosh
2020-03-27 20:56 ` Umesh Nerlige Ramappa
2020-03-27 22:02   ` Dixit, Ashutosh
2020-03-26  5:42 Ashutosh Dixit
2020-03-26  9:02 ` Lionel Landwerlin
2020-03-27  4:08   ` Dixit, Ashutosh

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.