From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 95BAE10E9BC for ; Fri, 27 Jan 2023 18:09:39 +0000 (UTC) From: Ashutosh Dixit To: igt-dev@lists.freedesktop.org Date: Fri, 27 Jan 2023 10:09:33 -0800 Message-Id: <20230127180934.158123-2-ashutosh.dixit@intel.com> In-Reply-To: <20230127180934.158123-1-ashutosh.dixit@intel.com> References: <20230127180934.158123-1-ashutosh.dixit@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: [igt-dev] [PATCH i-g-t 1/2] i915/i915_power: Sanity check power measurement List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: Add a test to sanity check power measurement on integrated/discrete by requiring power under load to be > 0 and >= idle power. v2: Code reorganization (Kamil K) v3: More code reorganization (Kamil K) v4: Make sleep duration uint32_t and use #define (Kamil K) Signed-off-by: Ashutosh Dixit Reviewed-by: Riana Tauro Reviewed-by: Kamil Konieczny --- tests/i915/i915_power.c | 72 +++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 2 files changed, 73 insertions(+) create mode 100644 tests/i915/i915_power.c diff --git a/tests/i915/i915_power.c b/tests/i915/i915_power.c new file mode 100644 index 00000000000..f2fd228698a --- /dev/null +++ b/tests/i915/i915_power.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2023 Intel Corporation + */ + +#include "igt.h" +#include "i915/gem.h" +#include "igt_power.h" + +IGT_TEST_DESCRIPTION("i915 power measurement tests"); + +static double measure_power(struct igt_power *pwr, uint32_t duration_sec) +{ + struct power_sample sample[2]; + + igt_power_get_energy(pwr, &sample[0]); + usleep(duration_sec * USEC_PER_SEC); + igt_power_get_energy(pwr, &sample[1]); + + return igt_power_get_mW(pwr, &sample[0], &sample[1]); +} + +static void sanity(int i915) +{ + const intel_ctx_t *ctx; + struct igt_power pwr; + double idle, busy; + igt_spin_t *spin; + uint64_t ahnd; + +#define DURATION_SEC 2 + + /* Idle power */ + igt_require(!igt_power_open(i915, &pwr, "gpu")); + gem_quiescent_gpu(i915); + idle = measure_power(&pwr, DURATION_SEC); + + /* Busy power */ + ctx = intel_ctx_create_all_physical(i915); + ahnd = get_reloc_ahnd(i915, ctx->id); + spin = igt_spin_new(i915, .ahnd = ahnd, .ctx = ctx, + .engine = ALL_ENGINES, + .flags = IGT_SPIN_POLL_RUN); + /* Wait till at least one spinner starts */ + igt_spin_busywait_until_started(spin); + busy = measure_power(&pwr, DURATION_SEC); + igt_free_spins(i915); + put_ahnd(ahnd); + intel_ctx_destroy(i915, ctx); + igt_power_close(&pwr); + + igt_info("Measured power: idle: %g mW, busy: %g mW\n", idle, busy); + igt_assert(idle >= 0 && busy > 0 && busy > idle); +} + +igt_main +{ + int i915; + + igt_fixture { + i915 = drm_open_driver_master(DRIVER_INTEL); + } + + igt_describe("Sanity check gpu power measurement"); + igt_subtest("sanity") { + sanity(i915); + } + + igt_fixture { + close(i915); + } +} diff --git a/tests/meson.build b/tests/meson.build index cce9d89e1c8..d93a07c9ed6 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -213,6 +213,7 @@ i915_progs = [ 'i915_pm_dc', 'i915_pm_rps', 'i915_pm_sseu', + 'i915_power', 'i915_query', 'i915_selftest', 'i915_suspend', -- 2.38.0