From patchwork Thu Jan 30 21:30:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinay Belgaumkar X-Patchwork-Id: 13954995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 831BEC02193 for ; Thu, 30 Jan 2025 21:34:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A50410E9F3; Thu, 30 Jan 2025 21:34:12 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="nGA6NEdT"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1A2D110E9D8; Thu, 30 Jan 2025 21:34:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738272852; x=1769808852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yfm7lhWkn/4CXBMLNBXX8ByFLXl4ccXO/DIHJIk61zQ=; b=nGA6NEdTeTEcpL7QLVSluSaMvWrOgAiD0J8YfcfhQRuVUfLwqfBVZIin oDXZYQGDi3w69SRUFu7L+nuXo/AqJmUgyR6FBXNqqMjSs6a108eYPTBrz /6k2fKnjhG51jUHdfPUIGg0nBVojFrJuyL0fY9Ghohyrx22Cp11YorLBI n94M+rIt52kj3RqJAIpVCxcOqm6PldbDk5BUpVGgULAG9NsX3n1emN1iZ D2Iwb1mcNrig8pZNYmp+gTi5vKTPJZU802BqjbEUJp5Qow/2iVbCv+cj3 hRMnt18pJMRYYsikGreZ4/ma7YSHyb/SRxHt12M35Ui/Zyzkl51CKG0jo w==; X-CSE-ConnectionGUID: 4keWZJDxRGuUlnh6g4vYVQ== X-CSE-MsgGUID: 5Njk67FvRPm9fRdF7lW1zA== X-IronPort-AV: E=McAfee;i="6700,10204,11331"; a="38083290" X-IronPort-AV: E=Sophos;i="6.13,246,1732608000"; d="scan'208";a="38083290" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2025 13:34:11 -0800 X-CSE-ConnectionGUID: 1wSRkvoiT3a37B+A26CmDg== X-CSE-MsgGUID: /a91y3XPQ3CgffmH87AJJw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,246,1732608000"; d="scan'208";a="109352116" Received: from vbelgaum-ubuntu.fm.intel.com ([10.1.39.141]) by fmviesa007.fm.intel.com with ESMTP; 30 Jan 2025 13:34:10 -0800 From: Vinay Belgaumkar To: intel-gfx@lists.freedesktop.org, igt-dev@lists.freedesktop.org Cc: Vinay Belgaumkar Subject: [PATCH i-g-t v7 1/3] lib/igt_core: Add tolerance and measured_usleep utils Date: Thu, 30 Jan 2025 13:30:26 -0800 Message-Id: <20250130213028.3852086-2-vinay.belgaumkar@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250130213028.3852086-1-vinay.belgaumkar@intel.com> References: <20250130213028.3852086-1-vinay.belgaumkar@intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add these redundant utils to core lib. Also fix the bug in measured_usleep, it was returning nsec slept not usec. The only test which now uses the local version of measured_usleep is perf_pmu. Patch for that will be sent separately since it also needs some test changes. Signed-off-by: Vinay Belgaumkar --- lib/igt_core.c | 20 ++++++++++ lib/igt_core.h | 20 ++++++++++ tests/intel/drm_fdinfo.c | 55 +++++--------------------- tests/intel/gem_exec_nop.c | 6 --- tests/intel/gem_spin_batch.c | 6 --- tests/intel/i915_pm_rc6_residency.c | 42 ++++---------------- tests/intel/perf_pmu.c | 15 +------ tests/intel/sysfs_heartbeat_interval.c | 17 +------- tests/intel/xe_pm_residency.c | 29 ++------------ 9 files changed, 62 insertions(+), 148 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index 407f7b551..b95db1b25 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -3553,3 +3553,23 @@ void igt_emit_ignore_dmesg_regex(const char *ignore_dmesg_regex) g_regex_unref(re); igt_kmsg(KMSG_INFO "%s%s\n", mark_ignore_dmesg, ignore_dmesg_regex); } + +/** + * @igt_measured_usleep: Helper to model accurate sleep time for tests + * @usec: usec to sleep + * Return: usec slept + */ +unsigned int igt_measured_usleep(unsigned int usec) +{ + struct timespec ts = { }; + unsigned int slept_usec; + + slept_usec = igt_nsec_elapsed(&ts) / NSEC_PER_USEC; + igt_assert(slept_usec == 0); + do { + usleep(usec - slept_usec); + slept_usec = igt_nsec_elapsed(&ts) / NSEC_PER_USEC; + } while (slept_usec < usec); + + return igt_nsec_elapsed(&ts) / NSEC_PER_USEC; +} diff --git a/lib/igt_core.h b/lib/igt_core.h index f0ba1a381..0f2af950b 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -1524,9 +1524,11 @@ void igt_kmsg(const char *format, ...); #if __WORDSIZE == 64 #define MSEC_PER_SEC (1000ul) #define USEC_PER_MSEC (1000ul) +#define NSEC_PER_USEC (1000ul) #else #define MSEC_PER_SEC (1000ull) #define USEC_PER_MSEC (1000ull) +#define NSEC_PER_USEC (1000ull) #endif #define USEC_PER_SEC (1000u * MSEC_PER_SEC) @@ -1536,6 +1538,23 @@ void igt_kmsg(const char *format, ...); #define for_if(expr__) if (!(expr__)) {} else +#define __assert_within_epsilon(x, ref, tol_up, tol_down, debug_data) \ + igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \ + (double)(x) >= (1.0 - (tol_down)) * (double)(ref), \ + "'%s' != '%s' (%f not within +%.1f%%/-%.1f%% tolerance of %f)\n%s\n",\ + #x, #ref, (double)(x), \ + (tol_up) * 100.0, (tol_down) * 100.0, \ + (double)(ref), debug_data) + +#define assert_within_epsilon(x, ref, tolerance) \ + __assert_within_epsilon(x, ref, tolerance, tolerance, "\0") + +#define assert_within_epsilon_up_down(x, ref, tol_up, tol_down) \ + __assert_within_epsilon(x, ref, tol_up, tol_down, "\0") + +#define assert_within_epsilon_debug(x, ref, tolerance, debug_data) \ + __assert_within_epsilon(x, ref, tolerance, tolerance, debug_data) + /** * igt_pci_system_init: * IGT wrapper around pci_system_init() @@ -1578,4 +1597,5 @@ void igt_pci_system_cleanup(void); void igt_emit_ignore_dmesg_regex(const char *ignore_dmesg_regex); +unsigned int igt_measured_usleep(unsigned int usec); #endif /* IGT_CORE_H */ diff --git a/tests/intel/drm_fdinfo.c b/tests/intel/drm_fdinfo.c index b66ac9e1b..6a3d92008 100644 --- a/tests/intel/drm_fdinfo.c +++ b/tests/intel/drm_fdinfo.c @@ -106,23 +106,6 @@ static const char *engine_map[] = { "compute", }; -#define __assert_within_epsilon(x, ref, tol_up, tol_down) \ - do { \ - igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \ - (double)(x) >= (1.0 - (tol_down)) * (double)(ref), \ - "'%s' != '%s' (%f not within +%.1f%%/-%.1f%% tolerance of %f)\n",\ - #x, #ref, (double)(x), \ - (tol_up) * 100.0, (tol_down) * 100.0, \ - (double)(ref)); \ - igt_debug("%f within +%.1f%%/-%.1f%% tolerance of %f\n",\ - (double)(x), \ - (tol_up) * 100.0, (tol_down) * 100.0, \ - (double)(ref)); \ - } while (0) - -#define assert_within_epsilon(x, ref, tolerance) \ - __assert_within_epsilon(x, ref, tolerance, tolerance) - static void basics(int i915, unsigned int num_classes) { struct drm_client_fdinfo info = { }; @@ -137,26 +120,6 @@ static void basics(int i915, unsigned int num_classes) igt_assert_eq(info.num_engines, num_classes); } -/* - * Helper for cases where we assert on time spent sleeping (directly or - * indirectly), so make it more robust by ensuring the system sleep time - * is within test tolerance to start with. - */ -static unsigned int measured_usleep(unsigned int usec) -{ - struct timespec ts = { }; - unsigned int slept; - - slept = igt_nsec_elapsed(&ts); - igt_assert(slept == 0); - do { - usleep(usec - slept); - slept = igt_nsec_elapsed(&ts) / 1000; - } while (slept < usec); - - return igt_nsec_elapsed(&ts); -} - #define TEST_BUSY (1) #define FLAG_SYNC (2) #define TEST_TRAILING_IDLE (4) @@ -239,7 +202,7 @@ single(int gem_fd, const intel_ctx_t *ctx, spin = NULL; val = read_engine_time(gem_fd, e->class); - slept = measured_usleep(batch_duration_ns / 1000); + slept = igt_measured_usleep(batch_duration_ns / 1000); if (flags & TEST_TRAILING_IDLE) end_spin(spin_fd, spin, flags); val = read_engine_time(gem_fd, e->class) - val; @@ -258,7 +221,7 @@ single(int gem_fd, const intel_ctx_t *ctx, igt_assert(!gem_bo_busy(spin_fd, spin->handle)); val = read_engine_time(gem_fd, e->class); - slept = measured_usleep(batch_duration_ns / 1000); + slept = igt_measured_usleep(batch_duration_ns / 1000); val = read_engine_time(gem_fd, e->class) - val; assert_within_epsilon(slept - val, slept, tolerance); @@ -320,7 +283,7 @@ busy_check_all(int gem_fd, const intel_ctx_t *ctx, spin = igt_sync_spin(gem_fd, ahnd, ctx, e); read_engine_time_all(gem_fd, tval[0]); - slept = measured_usleep(batch_duration_ns / 1000); + slept = igt_measured_usleep(batch_duration_ns / 1000); if (flags & TEST_TRAILING_IDLE) end_spin(gem_fd, spin, flags); read_engine_time_all(gem_fd, tval[1]); @@ -395,7 +358,7 @@ most_busy_check_all(int gem_fd, const intel_ctx_t *ctx, usleep(__igt_sync_spin_wait(gem_fd, spin) * num_engines / 1e3); read_engine_time_all(gem_fd, tval[0]); - slept = measured_usleep(batch_duration_ns / 1000); + slept = igt_measured_usleep(batch_duration_ns / 1000); if (flags & TEST_TRAILING_IDLE) end_spin(gem_fd, spin, flags); read_engine_time_all(gem_fd, tval[1]); @@ -450,7 +413,7 @@ all_busy_check_all(int gem_fd, const intel_ctx_t *ctx, usleep(__igt_sync_spin_wait(gem_fd, spin) * num_engines / 1e3); read_engine_time_all(gem_fd, tval[0]); - slept = measured_usleep(batch_duration_ns / 1000); + slept = igt_measured_usleep(batch_duration_ns / 1000); if (flags & TEST_TRAILING_IDLE) end_spin(gem_fd, spin, flags); read_engine_time_all(gem_fd, tval[1]); @@ -596,7 +559,7 @@ virtual(int i915, const intel_ctx_cfg_t *base_cfg, unsigned int flags) spin = NULL; val = read_engine_time(i915, class); - slept = measured_usleep(batch_duration_ns / 1000); + slept = igt_measured_usleep(batch_duration_ns / 1000); if (flags & TEST_TRAILING_IDLE) end_spin(i915, spin, flags); val = read_engine_time(i915, class) - val; @@ -615,7 +578,7 @@ virtual(int i915, const intel_ctx_cfg_t *base_cfg, unsigned int flags) igt_assert(!gem_bo_busy(i915, spin->handle)); val = read_engine_time(i915, class); - slept = measured_usleep(batch_duration_ns / + slept = igt_measured_usleep(batch_duration_ns / 1000); val = read_engine_time(i915, class) - val; @@ -705,7 +668,7 @@ virtual_all(int i915, const intel_ctx_cfg_t *base_cfg, unsigned int flags) usleep(__igt_sync_spin_wait(i915, spin) * count / 1e3); val = read_engine_time(i915, class); - slept = measured_usleep(batch_duration_ns / 1000); + slept = igt_measured_usleep(batch_duration_ns / 1000); if (flags & TEST_TRAILING_IDLE) end_spin(i915, spin, flags); val = read_engine_time(i915, class) - val; @@ -723,7 +686,7 @@ virtual_all(int i915, const intel_ctx_cfg_t *base_cfg, unsigned int flags) igt_assert(!gem_bo_busy(i915, spin->handle)); val = read_engine_time(i915, class); - slept = measured_usleep(batch_duration_ns / + slept = igt_measured_usleep(batch_duration_ns / 1000); val = read_engine_time(i915, class) - val; diff --git a/tests/intel/gem_exec_nop.c b/tests/intel/gem_exec_nop.c index 652f8deff..74593c085 100644 --- a/tests/intel/gem_exec_nop.c +++ b/tests/intel/gem_exec_nop.c @@ -434,12 +434,6 @@ stable_nop_on_ring(int fd, uint32_t handle, const intel_ctx_t *ctx, return n; } -#define assert_within_epsilon(x, ref, tolerance) \ - igt_assert_f((x) <= (1.0 + tolerance) * ref && \ - (x) >= (1.0 - tolerance) * ref, \ - "'%s' != '%s' (%f not within %f%% tolerance of %f)\n",\ - #x, #ref, x, tolerance * 100.0, ref) - static void headless(int fd, uint32_t handle, const intel_ctx_t *ctx, const struct intel_execution_engine2 *e) { diff --git a/tests/intel/gem_spin_batch.c b/tests/intel/gem_spin_batch.c index 85408a4c0..dee892411 100644 --- a/tests/intel/gem_spin_batch.c +++ b/tests/intel/gem_spin_batch.c @@ -51,12 +51,6 @@ #define MAX_ERROR 5 /* % */ -#define assert_within_epsilon(x, ref, tolerance) \ - igt_assert_f(100 * x <= (100 + tolerance) * ref && \ - 100 * x >= (100 - tolerance) * ref, \ - "'%s' != '%s' (%lld not within %d%% tolerance of %lld)\n",\ - #x, #ref, (long long)x, tolerance, (long long)ref) - static void spin(int fd, const intel_ctx_t *ctx_id, unsigned int engine, unsigned int flags, diff --git a/tests/intel/i915_pm_rc6_residency.c b/tests/intel/i915_pm_rc6_residency.c index 7942d46d3..d4489d0f7 100644 --- a/tests/intel/i915_pm_rc6_residency.c +++ b/tests/intel/i915_pm_rc6_residency.c @@ -234,17 +234,6 @@ static uint64_t pmu_read_single(int fd) return __pmu_read_single(fd, NULL); } -#define __assert_within_epsilon(x, ref, tol_up, tol_down, debug_data) \ - igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \ - (double)(x) >= (1.0 - (tol_down)) * (double)(ref), \ - "'%s' != '%s' (%f not within +%.1f%%/-%.1f%% tolerance of %f)\n %s\n",\ - #x, #ref, (double)(x), \ - (tol_up) * 100.0, (tol_down) * 100.0, \ - (double)(ref), debug_data) - -#define assert_within_epsilon(x, ref, tolerance, debug_data) \ - __assert_within_epsilon(x, ref, tolerance, tolerance, debug_data) - static char *get_drpc(int i915, int gt_id) { int gt_dir; @@ -275,21 +264,6 @@ static bool __pmu_wait_for_rc6(int fd) return false; } -static unsigned int measured_usleep(unsigned int usec) -{ - struct timespec ts = { }; - unsigned int slept; - - slept = igt_nsec_elapsed(&ts); - igt_assert(slept == 0); - do { - usleep(usec - slept); - slept = igt_nsec_elapsed(&ts) / 1000; - } while (slept < usec); - - return igt_nsec_elapsed(&ts); -} - static uint32_t batch_create(int fd) { const uint32_t bbe = MI_BATCH_BUFFER_END; @@ -416,7 +390,7 @@ static void rc6_idle(int i915, uint32_t ctx_id, uint64_t flags, unsigned int gt) /* While idle check full RC6. */ igt_power_get_energy(&gpu, &sample[0]); rc6 = -__pmu_read_single(fd, &ts[0]); - slept = measured_usleep(duration_ns / 1000); + slept = igt_measured_usleep(duration_ns / 1000); rc6 += __pmu_read_single(fd, &ts[1]); igt_debug("slept=%lu perf=%"PRIu64", rc6=%"PRIu64"\n", slept, ts[1] - ts[0], rc6); @@ -431,7 +405,7 @@ static void rc6_idle(int i915, uint32_t ctx_id, uint64_t flags, unsigned int gt) } drpc = get_drpc(i915, gt); - assert_within_epsilon(rc6, ts[1] - ts[0], 5, drpc); + assert_within_epsilon_debug(rc6, ts[1] - ts[0], 5, drpc); done = mmap(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); @@ -443,7 +417,7 @@ static void rc6_idle(int i915, uint32_t ctx_id, uint64_t flags, unsigned int gt) igt_power_get_energy(&gpu, &sample[0]); cycles = -READ_ONCE(done[1]); rc6 = -__pmu_read_single(fd, &ts[0]); - slept = measured_usleep(duration_ns / 1000); + slept = igt_measured_usleep(duration_ns / 1000); rc6 += __pmu_read_single(fd, &ts[1]); cycles += READ_ONCE(done[1]); igt_debug("%s: slept=%lu perf=%"PRIu64", cycles=%lu, rc6=%"PRIu64"\n", @@ -469,7 +443,7 @@ static void rc6_idle(int i915, uint32_t ctx_id, uint64_t flags, unsigned int gt) /* While very nearly idle, expect full RC6 */ drpc = get_drpc(i915, gt); - assert_within_epsilon(rc6, ts[1] - ts[0], tolerance, drpc); + assert_within_epsilon_debug(rc6, ts[1] - ts[0], tolerance, drpc); free(drpc); drpc = NULL; @@ -512,7 +486,7 @@ static void rc6_fence(int i915, unsigned int gt) /* While idle check full RC6. */ igt_power_get_energy(&gpu, &sample[0]); rc6 = -__pmu_read_single(fd, &ts[0]); - slept = measured_usleep(duration_ns / 1000); + slept = igt_measured_usleep(duration_ns / 1000); rc6 += __pmu_read_single(fd, &ts[1]); igt_debug("slept=%lu perf=%"PRIu64", rc6=%"PRIu64"\n", slept, ts[1] - ts[0], rc6); @@ -527,7 +501,7 @@ static void rc6_fence(int i915, unsigned int gt) } drpc = get_drpc(i915, gt); - assert_within_epsilon(rc6, ts[1] - ts[0], 5, drpc); + assert_within_epsilon_debug(rc6, ts[1] - ts[0], 5, drpc); /* Submit but delay execution, we should be idle and conserving power */ ctx = intel_ctx_create_for_gt(i915, gt); @@ -549,7 +523,7 @@ static void rc6_fence(int i915, unsigned int gt) igt_power_get_energy(&gpu, &sample[0]); rc6 = -__pmu_read_single(fd, &ts[0]); - slept = measured_usleep(duration_ns / 1000); + slept = igt_measured_usleep(duration_ns / 1000); rc6 += __pmu_read_single(fd, &ts[1]); igt_debug("%s: slept=%lu perf=%"PRIu64", rc6=%"PRIu64"\n", e->name, slept, ts[1] - ts[0], rc6); @@ -570,7 +544,7 @@ static void rc6_fence(int i915, unsigned int gt) drpc = get_drpc(i915, gt); - assert_within_epsilon(rc6, ts[1] - ts[0], tolerance, drpc); + assert_within_epsilon_debug(rc6, ts[1] - ts[0], tolerance, drpc); gem_quiescent_gpu(i915); free(drpc); diff --git a/tests/intel/perf_pmu.c b/tests/intel/perf_pmu.c index 5d0467c02..87de062cb 100644 --- a/tests/intel/perf_pmu.c +++ b/tests/intel/perf_pmu.c @@ -284,19 +284,6 @@ static uint64_t pmu_read_multi(int fd, unsigned int num, uint64_t *val) return buf[1]; } -#define __assert_within_epsilon(x, ref, tol_up, tol_down, debug_data) \ - igt_assert_f((double)(x) <= (1.0 + (tol_up)) * (double)(ref) && \ - (double)(x) >= (1.0 - (tol_down)) * (double)(ref), \ - "'%s' != '%s' (%f not within +%.1f%%/-%.1f%% tolerance of %f)\n%s\n",\ - #x, #ref, (double)(x), \ - (tol_up) * 100.0, (tol_down) * 100.0, \ - (double)(ref), debug_data) - -#define assert_within_epsilon(x, ref, tolerance) \ - __assert_within_epsilon(x, ref, tolerance, tolerance, no_debug_data) - -#define assert_within_epsilon_debug(x, ref, tolerance, debug_data) \ - __assert_within_epsilon(x, ref, tolerance, tolerance, debug_data) /* * Helper for cases where we assert on time spent sleeping (directly or * indirectly), so make it more robust by ensuring the system sleep time @@ -1772,7 +1759,7 @@ test_frequency(int gem_fd, unsigned int gt) * On thermally throttled devices we cannot be sure maximum frequency * can be reached so use larger tolerance downards. */ - __assert_within_epsilon(max[0], max_freq, tolerance, 0.15f, no_debug_data); + assert_within_epsilon_up_down(max[0], max_freq, tolerance, 0.15f); } static void diff --git a/tests/intel/sysfs_heartbeat_interval.c b/tests/intel/sysfs_heartbeat_interval.c index 486a1514d..56fb1b499 100644 --- a/tests/intel/sysfs_heartbeat_interval.c +++ b/tests/intel/sysfs_heartbeat_interval.c @@ -307,21 +307,6 @@ static void test_nopreempt(int i915, int engine) set_heartbeat(engine, saved); } -static unsigned int measured_usleep(unsigned int usec) -{ - struct timespec ts = { }; - unsigned int slept; - - slept = igt_nsec_elapsed(&ts); - igt_assert(slept == 0); - do { - usleep(usec - slept); - slept = igt_nsec_elapsed(&ts) / 1000; - } while (slept < usec); - - return igt_nsec_elapsed(&ts); -} - static void client(int i915, int engine, int *ctl, int duration, int expect) { unsigned int class, inst; @@ -352,7 +337,7 @@ static void client(int i915, int engine, int *ctl, int duration, int expect) continue; } - elapsed = measured_usleep(duration * 1000); + elapsed = igt_measured_usleep(duration * 1000); igt_spin_end(spin); sync_fence_wait(spin->out_fence, -1); diff --git a/tests/intel/xe_pm_residency.c b/tests/intel/xe_pm_residency.c index f9e96d608..3432077cc 100644 --- a/tests/intel/xe_pm_residency.c +++ b/tests/intel/xe_pm_residency.c @@ -32,14 +32,6 @@ const double tolerance = 0.1; int fw_handle = -1; -#define assert_within_epsilon(x, ref, tol) \ - igt_assert_f((double)(x) <= (1.0 + (tol)) * (double)(ref) && \ - (double)(x) >= (1.0 - (tol)) * (double)(ref), \ - "'%s' != '%s' (%f not within +%.1f%%/-%.1f%% tolerance of %f)\n",\ - #x, #ref, (double)(x), \ - (tol) * 100.0, (tol) * 100.0, \ - (double)(ref)) - enum test_type { TEST_S2IDLE, TEST_IDLE, @@ -177,21 +169,6 @@ static void exec_load(int fd, struct drm_xe_engine_class_instance *hwe, unsigned xe_vm_destroy(fd, vm); } -static unsigned int measured_usleep(unsigned int usec) -{ - struct timespec ts = { }; - unsigned int slept; - - slept = igt_nsec_elapsed(&ts); - igt_assert(slept == 0); - do { - usleep(usec - slept); - slept = igt_nsec_elapsed(&ts) / 1000; - } while (slept < usec); - - return igt_nsec_elapsed(&ts) / 1000; -} - static unsigned long read_idle_residency(int fd, int gt) { unsigned long residency = 0; @@ -224,7 +201,7 @@ static void test_idle_residency(int fd, int gt, enum test_type flag) if (flag == TEST_IDLE) { residency_start = read_idle_residency(fd, gt); - elapsed_ms = measured_usleep(SLEEP_DURATION * USEC_PER_SEC) / 1000; + elapsed_ms = igt_measured_usleep(SLEEP_DURATION * USEC_PER_SEC) / 1000; residency_end = read_idle_residency(fd, gt); } @@ -260,7 +237,7 @@ static void idle_residency_on_exec(int fd, struct drm_xe_engine_class_instance * start = READ_ONCE(done[1]); residency_start = read_idle_residency(fd, hwe->gt_id); - elapsed_ms = measured_usleep(SLEEP_DURATION * USEC_PER_SEC) / 1000; + elapsed_ms = igt_measured_usleep(SLEEP_DURATION * USEC_PER_SEC) / 1000; residency_end = read_idle_residency(fd, hwe->gt_id); end = READ_ONCE(done[1]); *done = 1; @@ -281,7 +258,7 @@ static void measure_power(struct igt_power *gpu, double *power) struct power_sample power_sample[2]; igt_power_get_energy(gpu, &power_sample[0]); - measured_usleep(SLEEP_DURATION * USEC_PER_SEC); + igt_measured_usleep(SLEEP_DURATION * USEC_PER_SEC); igt_power_get_energy(gpu, &power_sample[1]); *power = igt_power_get_mW(gpu, &power_sample[0], &power_sample[1]); } From patchwork Thu Jan 30 21:30:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinay Belgaumkar X-Patchwork-Id: 13955015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F5CAC02194 for ; Thu, 30 Jan 2025 21:34:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C8A610E9DE; Thu, 30 Jan 2025 21:34:22 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Vx9JJiyV"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B98D10E9DE; Thu, 30 Jan 2025 21:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738272862; x=1769808862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZFoTvs5QOB6VbF3u54gQUe7NpOMX9p524oIM+UDwkJ4=; b=Vx9JJiyVnVvBg4+QHYOMvPiSusNV8liS5eCE43ee7ijRrpaDymtqjA1p 2vsWN6pdt3f0HRFlV0ge1mcJl0isabdSJ4/LccbqFe6J6A2+qhnCNCDgT Ag0hYzRJrUn2HhQD1JxNf03Zq5QcOVDzr6yE7OcFzTv9We8nmZmhb5wSr 1nXAc2t8tneNkyUdGigzfHgPY5MwyIyrfONZzpPakTjSF2uS0sHp7G6Uu nBiG/LXvXEGpH77iuBPe6n++xV4w2jKo8jVap6dtii42LQPDz/NDeo4Nn 8/fBUvZ/zvYo/E3yU1xTj1Inefq2VdykmUZ0FH83RH5sv/SMFQ9WQA9NW g==; X-CSE-ConnectionGUID: vAYe2tHRRwa+/j/xQIb4Yg== X-CSE-MsgGUID: yy4lo/knR4esZAWSDs5ryw== X-IronPort-AV: E=McAfee;i="6700,10204,11331"; a="38083307" X-IronPort-AV: E=Sophos;i="6.13,246,1732608000"; d="scan'208";a="38083307" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2025 13:34:22 -0800 X-CSE-ConnectionGUID: GRVbC7sMSOW1b+4swEnUSw== X-CSE-MsgGUID: ZVmbgvF3Qb+JKKWm3K78VQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,246,1732608000"; d="scan'208";a="109352191" Received: from vbelgaum-ubuntu.fm.intel.com ([10.1.39.141]) by fmviesa007.fm.intel.com with ESMTP; 30 Jan 2025 13:34:18 -0800 From: Vinay Belgaumkar To: intel-gfx@lists.freedesktop.org, igt-dev@lists.freedesktop.org Cc: Vinay Belgaumkar , Riana Tauro , Lucas De Marchi , Kamil Konieczny , Rodrigo Vivi Subject: [PATCH i-g-t v7 2/3] lib/igt_perf: Add utils to extract PMU event info Date: Thu, 30 Jan 2025 13:30:27 -0800 Message-Id: <20250130213028.3852086-3-vinay.belgaumkar@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250130213028.3852086-1-vinay.belgaumkar@intel.com> References: <20250130213028.3852086-1-vinay.belgaumkar@intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Functions to parse event ID and GT bit shift for PMU events. v2: Review comments (Riana) v3: Review comments (Lucas) Cc: Riana Tauro Cc: Lucas De Marchi Cc: Kamil Konieczny Cc: Rodrigo Vivi Signed-off-by: Vinay Belgaumkar Reviewed-by: Riana Tauro --- lib/igt_perf.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_perf.h | 2 ++ 2 files changed, 72 insertions(+) diff --git a/lib/igt_perf.c b/lib/igt_perf.c index 3866c6d77..f021fc3ec 100644 --- a/lib/igt_perf.c +++ b/lib/igt_perf.c @@ -92,6 +92,76 @@ const char *xe_perf_device(int xe, char *buf, int buflen) return buf; } +/** + * perf_event_format: Returns the start/end positions of an event format param + * @device: PMU device + * @param: Parameter for which you need the format start/end bits + * Returns: 0 on success or negative error code + */ +int perf_event_format(const char *device, const char *param, uint32_t *start, uint32_t *end) +{ + char buf[NAME_MAX]; + ssize_t bytes; + int ret; + int fd; + + snprintf(buf, sizeof(buf), + "/sys/bus/event_source/devices/%s/format/%s", + device, param); + + fd = open(buf, O_RDONLY | O_CLOEXEC); + if (fd < 0) + return -EINVAL; + + bytes = read(fd, buf, sizeof(buf) - 1); + close(fd); + if (bytes < 1) + return -EINVAL; + + buf[bytes] = '\0'; + ret = sscanf(buf, "config:%u-%u", start, end); + if (ret != 2) + return -EINVAL; + + return ret; +} + +/** + * perf_event_config: + * @device: Device string in driver:pci format + * @event: The event name + * @config: Pointer to the config + * Returns: 0 for success, negative value on error + */ +int perf_event_config(const char *device, const char *event, uint64_t *config) +{ + char buf[NAME_MAX]; + ssize_t bytes; + int ret; + int fd; + + snprintf(buf, sizeof(buf), + "/sys/bus/event_source/devices/%s/events/%s", + device, + event); + + fd = open(buf, O_RDONLY); + if (fd < 0) + return -EINVAL; + + bytes = read(fd, buf, sizeof(buf) - 1); + close(fd); + if (bytes < 1) + return ret; + + buf[bytes] = '\0'; + ret = sscanf(buf, "event=0x%lx", config); + if (ret != 1) + return -EINVAL; + + return 0; +} + uint64_t xe_perf_type_id(int xe) { char buf[80]; diff --git a/lib/igt_perf.h b/lib/igt_perf.h index 3d9ba2917..69f7a3d74 100644 --- a/lib/igt_perf.h +++ b/lib/igt_perf.h @@ -71,5 +71,7 @@ int perf_i915_open(int i915, uint64_t config); int perf_i915_open_group(int i915, uint64_t config, int group); int perf_xe_open(int xe, uint64_t config); +int perf_event_config(const char *device, const char *event, uint64_t *config); +int perf_event_format(const char *device, const char *param, uint32_t *start, uint32_t *end); #endif /* I915_PERF_H */ From patchwork Thu Jan 30 21:30:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vinay Belgaumkar X-Patchwork-Id: 13954996 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BF94C0218D for ; Thu, 30 Jan 2025 21:34:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 19F1710E9D7; Thu, 30 Jan 2025 21:34:22 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="i2S8tn39"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 39A2610E9D9; Thu, 30 Jan 2025 21:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738272863; x=1769808863; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nYMnbQTII8+qSuOA2xssSMUyQ3kXkf2qzRW8BNQvp+k=; b=i2S8tn395YCELUmE4P3VxvpE0wkFQ5qBIsVCHWv2IQY5LrAccT9uJW7f oozLay6QMPgjP77dDy9ZRr7XkBEsZ9at84JX2XBbGyQChtC+zpM5L4T1d jpmRpz38S+6ujuFd0Cif49JpPpryzLHhgcc8WcUlKgbR1ioOZvLy0h+co rmzk4f3ovG4JEHZN5WnrzrTfSA5BRid4exJBZpVHvVhJXh7k4yLuGrHjp tcpgeCn/KE9j3dFeq8AqcUcS0gKN0H38OVqUADJdnp5Wmj/iSgk9PwWSt 9Qka9zYw0XdnyKghmAgQF8T7FImNueV4H3WmyCyYYk4MUqVMK5ckQ+ovF w==; X-CSE-ConnectionGUID: LORxqvrCQm6g2Exmq2KBzA== X-CSE-MsgGUID: YBOF/8eeSoSLjCGs1bWwuQ== X-IronPort-AV: E=McAfee;i="6700,10204,11331"; a="38083308" X-IronPort-AV: E=Sophos;i="6.13,246,1732608000"; d="scan'208";a="38083308" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2025 13:34:22 -0800 X-CSE-ConnectionGUID: p6hEH8wURPeGkTK20i0LCA== X-CSE-MsgGUID: Ehfm929HQjCnxNCvmsS4Mg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,246,1732608000"; d="scan'208";a="109352194" Received: from vbelgaum-ubuntu.fm.intel.com ([10.1.39.141]) by fmviesa007.fm.intel.com with ESMTP; 30 Jan 2025 13:34:19 -0800 From: Vinay Belgaumkar To: intel-gfx@lists.freedesktop.org, igt-dev@lists.freedesktop.org Cc: Vinay Belgaumkar , Lucas De Marchi , Riana Tauro , Rodrigo Vivi Subject: [PATCH i-g-t v7 3/3] tests/xe/pmu: Add pmu tests for gt-c6 Date: Thu, 30 Jan 2025 13:30:28 -0800 Message-Id: <20250130213028.3852086-4-vinay.belgaumkar@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250130213028.3852086-1-vinay.belgaumkar@intel.com> References: <20250130213028.3852086-1-vinay.belgaumkar@intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Simple tests for validating the PMU implementation for GT C6 residencies. v2: Rename rc6-residency-* to gt-c6-residency and remove freq tests. v3: Keep just gt-c6 tests, add frequency tests later. v4: Review comments (Riana) v5: Review comments (Lucas) Cc: Lucas De Marchi Cc: Riana Tauro Cc: Rodrigo Vivi Signed-off-by: Vinay Belgaumkar Reviewed-by: Riana Tauro --- tests/intel/xe_pmu.c | 149 +++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 2 files changed, 150 insertions(+) create mode 100644 tests/intel/xe_pmu.c diff --git a/tests/intel/xe_pmu.c b/tests/intel/xe_pmu.c new file mode 100644 index 000000000..44589cb86 --- /dev/null +++ b/tests/intel/xe_pmu.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2025 Intel Corporation + */ + +/** + * TEST: Test Xe PMU functionality + * Category: Perf Monitoring Unit + * Mega feature: Perf Monitoring Unit + * Sub-category: Telemetry + * Functionality: Power/Perf + * Test category: Functional tests + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "igt.h" +#include "igt_device.h" +#include "igt_power.h" +#include "igt_sysfs.h" +#include "igt_perf.h" + +#include "lib/igt_syncobj.h" +#include "xe/xe_ioctl.h" +#include "xe/xe_gt.h" +#include "xe/xe_query.h" +#include "xe/xe_spin.h" +#include "xe/xe_util.h" + +#define SLEEP_DURATION 2 /* in seconds */ +const double tolerance = 0.1; +const char *no_debug_data = "\0"; + +static int open_pmu(int xe, uint64_t config) +{ + int fd; + + fd = perf_xe_open(xe, config); + igt_skip_on(fd < 0 && errno == ENODEV); + igt_assert(fd >= 0); + + return fd; +} + +static uint64_t __pmu_read_single(int fd, uint64_t *ts) +{ + uint64_t data[2]; + + igt_assert_eq(read(fd, data, sizeof(data)), sizeof(data)); + if (ts) + *ts = data[1]; + + return data[0]; +} + +static unsigned long read_idle_residency(int fd, int gt) +{ + unsigned long residency = 0; + int gt_fd; + + gt_fd = xe_sysfs_gt_open(fd, gt); + igt_assert(gt_fd >= 0); + igt_assert(igt_sysfs_scanf(gt_fd, "gtidle/idle_residency_ms", "%lu", &residency) == 1); + close(gt_fd); + + return residency; +} + +static u64 get_event_config(int xe, unsigned int gt, char *event) +{ + int ret; + char xe_device[100]; + u64 pmu_config; + u32 start, end; + + xe_perf_device(xe, xe_device, sizeof(xe_device)); + ret = perf_event_config(xe_device, event, &pmu_config); + igt_assert(ret >= 0); + ret = perf_event_format(xe_device, "gt", &start, &end); + igt_assert(ret >= 0); + pmu_config |= (u64) gt << start; + + return pmu_config; +} + +/** + * SUBTEST: gt-c6-idle + * Description: Basic residency test to validate idle residency + * measured over a time interval is within the tolerance + */ +static void test_gt_c6_idle(int xe, unsigned int gt) +{ + int pmu_fd; + u64 pmu_config; + char event[100]; + uint64_t ts[2]; + unsigned long slept, start, end; + uint64_t val; + + /* Get the PMU config for the gt-c6 event */ + sprintf(event, "gt-c6-residency"); + pmu_config = get_event_config(xe, gt, event); + + pmu_fd = open_pmu(xe, pmu_config); + + igt_require_f(igt_wait(xe_gt_is_in_c6(xe, gt), 1000, 10), "GT %d should be in C6\n", gt); + + /* While idle check full RC6. */ + start = read_idle_residency(xe, gt); + val = __pmu_read_single(pmu_fd, &ts[0]); + slept = igt_measured_usleep(SLEEP_DURATION * USEC_PER_SEC) / 1000; + end = read_idle_residency(xe, gt); + val = __pmu_read_single(pmu_fd, &ts[1]) - val; + + igt_debug("gt%u: slept=%lu, perf=%"PRIu64"\n", + gt, slept, val); + + igt_debug("Start res: %lu, end_res: %lu", start, end); + + assert_within_epsilon(val, + (ts[1] - ts[0])/USEC_PER_SEC, + tolerance); + close(pmu_fd); +} + +igt_main +{ + int fd, gt; + + igt_fixture { + fd = drm_open_driver(DRIVER_XE); + igt_require(!IS_PONTEVECCHIO(xe_dev_id(fd))); + } + + igt_describe("Validate PMU gt-c6 residency counters when idle"); + igt_subtest("gt-c6-idle") + xe_for_each_gt(fd, gt) + test_gt_c6_idle(fd, gt); + + igt_fixture { + close(fd); + } +} diff --git a/tests/meson.build b/tests/meson.build index 33dffad31..d20f50766 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -309,6 +309,7 @@ intel_xe_progs = [ 'xe_pat', 'xe_peer2peer', 'xe_pm', + 'xe_pmu', 'xe_pm_residency', 'xe_prime_self_import', 'xe_query',