All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Peres <martin.peres@mupuf.org>
To: Development mailing list for IGT GPU Tools
	<igt-dev@lists.freedesktop.org>
Cc: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Subject: [igt-dev] [PATCH i-g-t v3 2/2] amdgpu/info: add timestamp-related tests
Date: Tue, 16 Feb 2021 22:25:57 +0200	[thread overview]
Message-ID: <20210216202557.878778-2-martin.peres@mupuf.org> (raw)
In-Reply-To: <20210216202557.878778-1-martin.peres@mupuf.org>

This test makes sure:

 * the clock is running at the expected rate
 * (potential) power gating has no effect on the clock

v2:
 - use signed integer for the gpu timestamp diff (Bas)

v3:
 - add test and subtest descriptions (Arek)
 - split the fast and long tests in different subtests (Martin)
 - use igt_stats to compute actual statistics (Chris)

v4:
 - call igt_stats_fini() after finishing with the stats (Petri)

Cc: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Signed-off-by: Martin Peres <martin.peres@mupuf.org>
---
 tests/amdgpu/amd_info.c | 79 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/tests/amdgpu/amd_info.c b/tests/amdgpu/amd_info.c
index 6764e640..e3b1eac1 100644
--- a/tests/amdgpu/amd_info.c
+++ b/tests/amdgpu/amd_info.c
@@ -44,6 +44,75 @@ static void query_firmware_version_test(void)
 	igt_assert_eq(r, 0);
 }
 
+static void query_timestamp_test(uint32_t sleep_time, int sample_count)
+{
+	struct amdgpu_gpu_info gpu_info = {};
+	double median, std_err, err_95_conf;
+	igt_stats_t stats;
+	float ns_per_tick;
+	int i;
+
+	igt_stats_init_with_size(&stats, sample_count);
+
+	/* figure out how many nanoseconds each gpu timestamp tick represents */
+	igt_assert_eq(amdgpu_query_gpu_info(dev, &gpu_info), 0);
+	igt_assert_lt(0, gpu_info.gpu_counter_freq);
+	ns_per_tick = 1e9 / (gpu_info.gpu_counter_freq * 1000.0);
+
+	/* acquire the data needed for the analysis */
+	for (i = 0; i < sample_count; i++) {
+		uint64_t ts_start, ts_end, cpu_delta;
+		int64_t gpu_delta;
+		float corrected_gpu_delta;
+		struct timespec ts_cpu;
+		int r;
+
+		igt_assert_eq(igt_gettime(&ts_cpu), 0);
+
+		r = amdgpu_query_info(dev, AMDGPU_INFO_TIMESTAMP, 8, &ts_start);
+		igt_assert_eq(r, 0);
+
+		usleep(sleep_time);
+
+		r = amdgpu_query_info(dev, AMDGPU_INFO_TIMESTAMP, 8, &ts_end);
+		igt_assert_eq(r, 0);
+
+		/* get the GPU and CPU deltas */
+		cpu_delta = igt_nsec_elapsed(&ts_cpu);
+		gpu_delta = ts_end - ts_start;
+		corrected_gpu_delta = gpu_delta * ns_per_tick;
+
+		/* make sure the GPU timestamps are ordered */
+		igt_assert_lt_s64(0, gpu_delta);
+
+		igt_stats_push_float(&stats, corrected_gpu_delta / cpu_delta);
+	}
+
+	/* generate the statistics */
+	median = igt_stats_get_median(&stats);
+	std_err = igt_stats_get_std_error(&stats);
+	err_95_conf = std_err * 1.96;
+
+	/* check that the median ticking rate is ~1.0, meaning that the
+	 * the GPU and CPU timestamps grow at the same rate
+	 */
+	igt_assert_f(median > 0.99 && median < 1.01,
+		     "The GPU time elapses at %.2f%% (+/- %.2f%% at 95%% "
+		     "confidence) of the CPU's speed\ngpu_counter_freq=%u kHz, "
+		     "should be %.0f kHz (+/- %.1f kHz at 95%% confidence)\n",
+		     median * 100.0, err_95_conf * 100.0,
+		     gpu_info.gpu_counter_freq,
+		     gpu_info.gpu_counter_freq * median,
+		     gpu_info.gpu_counter_freq * err_95_conf);
+
+	/* check the jitter in the ticking rate */
+	igt_assert_f(err_95_conf < 0.01,
+		     "The GPU time ticks with a jitter greater than 1%%, at "
+		     "95%% confidence (+/- %.3f%%)\n", err_95_conf * 100.0);
+
+	igt_stats_fini(&stats);
+}
+
 IGT_TEST_DESCRIPTION("Test the consistency of the data provided through the "
 		     "DRM_AMDGPU_INFO IOCTL");
 igt_main
@@ -67,6 +136,16 @@ igt_main
 	igt_subtest("query-firmware-version")
 		query_firmware_version_test();
 
+	igt_describe("Check that the GPU time ticks constantly, and at the "
+		     "same rate as the CPU");
+	igt_subtest("query-timestamp")
+		query_timestamp_test(10000, 100);
+
+	igt_describe("Check that the GPU time keeps on ticking, even during "
+		     "long idle times which could lead to clock/power gating");
+	igt_subtest("query-timestamp-while-idle")
+		query_timestamp_test(7000000, 1);
+
 	igt_fixture {
 		amdgpu_device_deinitialize(dev);
 		close(fd);
-- 
2.30.1

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

  reply	other threads:[~2021-02-16 20:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-16 20:25 [igt-dev] [PATCH i-g-t v3 1/2] amdgpu/basic: move amdgpu_query_info_test to its own file Martin Peres
2021-02-16 20:25 ` Martin Peres [this message]
2021-02-17  7:24   ` [igt-dev] [PATCH i-g-t v3 2/2] amdgpu/info: add timestamp-related tests Petri Latvala
2021-02-17 11:41     ` Martin Peres
2021-02-16 21:17 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,v3,1/2] amdgpu/basic: move amdgpu_query_info_test to its own file Patchwork
2021-02-16 22:21 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2021-02-17  7:37 ` [igt-dev] [PATCH i-g-t v3 1/2] " Petri Latvala
2021-02-17 11:43   ` Martin Peres

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=20210216202557.878778-2-martin.peres@mupuf.org \
    --to=martin.peres@mupuf.org \
    --cc=bas@basnieuwenhuizen.nl \
    --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.