From patchwork Wed Apr 5 06:00:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Riana Tauro X-Patchwork-Id: 13201157 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 CAB80C7619A for ; Wed, 5 Apr 2023 06:00:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5EC4F10E0D0; Wed, 5 Apr 2023 06:00:43 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA5E510E06C for ; Wed, 5 Apr 2023 06:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680674441; x=1712210441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=asQ1O0pMc/00cH16XeGLAywxWOxlMQ1hHpBQ84mbixE=; b=Da/RWxwSN4Y5wQsnQKc6iDzijv04MLUwRZyFaM9LhieIMtVuE1zPGwEA 9O8XK2L6F48v9Aqcoej/8CE+4TjAYOPaxrO4HkGgSxy8TD4A1AJTCsIcC E5eznfZPa8y2dQAqsCtJqVtaGIKt2OUgEoje5/ZIXop5KJeZ5C/xPZcEC yTpKQAuOAmJ1dKisD7+9ziwkWkXUhW/rSKyTP6pMb2VXzHzU83e2zDNTg zIK97NGWGWnrv3I7L0z8ChGPvmwGZkAFCM5S350PVAyUwGm5ec/xr7Qwc vaqa3zfKaHONY7jdlQyhu7ZMAyWaLUsqzLtdIg3w7Psa1JGVJrh4oOxWO A==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="326412455" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="326412455" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="860849551" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="860849551" Received: from rtauro-desk.iind.intel.com ([10.190.239.41]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:39 -0700 From: Riana Tauro To: intel-gfx@lists.freedesktop.org Date: Wed, 5 Apr 2023 11:30:26 +0530 Message-Id: <20230405060029.3574262-2-riana.tauro@intel.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405060029.3574262-1-riana.tauro@intel.com> References: <20230405060029.3574262-1-riana.tauro@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v8 1/4] drm/i915/selftests: Rename librapl library to libpower 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" Rename librapl files to libpower and replace librapl with libpower prefix. No functional changes v2: update commit message (Anshuman) v3: fix license year Signed-off-by: Riana Tauro Reviewed-by: Anshuman Gupta Reviewed-by: Ashutosh Dixit --- drivers/gpu/drm/i915/Makefile | 2 +- drivers/gpu/drm/i915/gt/selftest_rc6.c | 12 ++++++------ drivers/gpu/drm/i915/gt/selftest_rps.c | 8 ++++---- drivers/gpu/drm/i915/gt/selftest_slpc.c | 2 +- .../i915/selftests/{librapl.c => libpower.c} | 10 +++++----- drivers/gpu/drm/i915/selftests/libpower.h | 17 +++++++++++++++++ drivers/gpu/drm/i915/selftests/librapl.h | 17 ----------------- 7 files changed, 34 insertions(+), 34 deletions(-) rename drivers/gpu/drm/i915/selftests/{librapl.c => libpower.c} (69%) create mode 100644 drivers/gpu/drm/i915/selftests/libpower.h delete mode 100644 drivers/gpu/drm/i915/selftests/librapl.h diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index 057ef22fa9c6..33f2e8038d2f 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -356,7 +356,7 @@ i915-$(CONFIG_DRM_I915_SELFTEST) += \ selftests/igt_mmap.o \ selftests/igt_reset.o \ selftests/igt_spinner.o \ - selftests/librapl.o + selftests/libpower.o # virtual gpu code i915-y += i915_vgpu.o diff --git a/drivers/gpu/drm/i915/gt/selftest_rc6.c b/drivers/gpu/drm/i915/gt/selftest_rc6.c index 2ceeadecc639..15b84c428f66 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rc6.c +++ b/drivers/gpu/drm/i915/gt/selftest_rc6.c @@ -11,7 +11,7 @@ #include "selftest_rc6.h" #include "selftests/i915_random.h" -#include "selftests/librapl.h" +#include "selftests/libpower.h" static u64 rc6_residency(struct intel_rc6 *rc6) { @@ -51,7 +51,7 @@ int live_rc6_manual(void *arg) if (IS_VALLEYVIEW(gt->i915) || IS_CHERRYVIEW(gt->i915)) return 0; - has_power = librapl_supported(gt->i915); + has_power = libpower_supported(gt->i915); wakeref = intel_runtime_pm_get(gt->uncore->rpm); /* Force RC6 off for starters */ @@ -61,9 +61,9 @@ int live_rc6_manual(void *arg) res[0] = rc6_residency(rc6); dt = ktime_get(); - rc0_power = librapl_energy_uJ(); + rc0_power = libpower_get_energy_uJ(); msleep(250); - rc0_power = librapl_energy_uJ() - rc0_power; + rc0_power = libpower_get_energy_uJ() - rc0_power; dt = ktime_sub(ktime_get(), dt); res[1] = rc6_residency(rc6); if ((res[1] - res[0]) >> 10) { @@ -89,9 +89,9 @@ int live_rc6_manual(void *arg) res[0] = rc6_residency(rc6); intel_uncore_forcewake_flush(rc6_to_uncore(rc6), FORCEWAKE_ALL); dt = ktime_get(); - rc6_power = librapl_energy_uJ(); + rc6_power = libpower_get_energy_uJ(); msleep(100); - rc6_power = librapl_energy_uJ() - rc6_power; + rc6_power = libpower_get_energy_uJ() - rc6_power; dt = ktime_sub(ktime_get(), dt); res[1] = rc6_residency(rc6); if (res[1] == res[0]) { diff --git a/drivers/gpu/drm/i915/gt/selftest_rps.c b/drivers/gpu/drm/i915/gt/selftest_rps.c index 84e77e8dbba1..ab534964da4d 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rps.c +++ b/drivers/gpu/drm/i915/gt/selftest_rps.c @@ -19,7 +19,7 @@ #include "selftest_rps.h" #include "selftests/igt_flush_test.h" #include "selftests/igt_spinner.h" -#include "selftests/librapl.h" +#include "selftests/libpower.h" /* Try to isolate the impact of cstates from determing frequency response */ #define CPU_LATENCY 0 /* -1 to disable pm_qos, 0 to disable cstates */ @@ -1094,10 +1094,10 @@ static u64 __measure_power(int duration_ms) { u64 dE, dt; - dE = librapl_energy_uJ(); + dE = libpower_get_energy_uJ(); dt = ktime_get(); usleep_range(1000 * duration_ms, 2000 * duration_ms); - dE = librapl_energy_uJ() - dE; + dE = libpower_get_energy_uJ() - dE; dt = ktime_get() - dt; return div64_u64(1000 * 1000 * dE, dt); @@ -1143,7 +1143,7 @@ int live_rps_power(void *arg) if (!intel_rps_is_enabled(rps) || GRAPHICS_VER(gt->i915) < 6) return 0; - if (!librapl_supported(gt->i915)) + if (!libpower_supported(gt->i915)) return 0; if (igt_spinner_init(&spin, gt)) diff --git a/drivers/gpu/drm/i915/gt/selftest_slpc.c b/drivers/gpu/drm/i915/gt/selftest_slpc.c index bd44ce73a504..fc1cdda82ec6 100644 --- a/drivers/gpu/drm/i915/gt/selftest_slpc.c +++ b/drivers/gpu/drm/i915/gt/selftest_slpc.c @@ -169,7 +169,7 @@ static int slpc_power(struct intel_gt *gt, struct intel_engine_cs *engine) * actually saves power. Let's see if our RAPL measurement supports * that theory. */ - if (!librapl_supported(gt->i915)) + if (!libpower_supported(gt->i915)) return 0; min.freq = slpc->min_freq; diff --git a/drivers/gpu/drm/i915/selftests/librapl.c b/drivers/gpu/drm/i915/selftests/libpower.c similarity index 69% rename from drivers/gpu/drm/i915/selftests/librapl.c rename to drivers/gpu/drm/i915/selftests/libpower.c index eb03b5b28bad..5d96cccd2e55 100644 --- a/drivers/gpu/drm/i915/selftests/librapl.c +++ b/drivers/gpu/drm/i915/selftests/libpower.c @@ -1,23 +1,23 @@ // SPDX-License-Identifier: MIT /* - * Copyright © 2020 Intel Corporation + * Copyright © 2023 Intel Corporation */ #include #include "i915_drv.h" -#include "librapl.h" +#include "libpower.h" -bool librapl_supported(const struct drm_i915_private *i915) +bool libpower_supported(const struct drm_i915_private *i915) { /* Discrete cards require hwmon integration */ if (IS_DGFX(i915)) return false; - return librapl_energy_uJ(); + return libpower_get_energy_uJ(); } -u64 librapl_energy_uJ(void) +u64 libpower_get_energy_uJ(void) { unsigned long long power; u32 units; diff --git a/drivers/gpu/drm/i915/selftests/libpower.h b/drivers/gpu/drm/i915/selftests/libpower.h new file mode 100644 index 000000000000..dd4b93ccf6b0 --- /dev/null +++ b/drivers/gpu/drm/i915/selftests/libpower.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2023 Intel Corporation + */ + +#ifndef SELFTEST_LIBPOWER_H +#define SELFTEST_LIBPOWER_H + +#include + +struct drm_i915_private; + +bool libpower_supported(const struct drm_i915_private *i915); + +u64 libpower_get_energy_uJ(void); + +#endif /* SELFTEST_LIBPOWER_H */ diff --git a/drivers/gpu/drm/i915/selftests/librapl.h b/drivers/gpu/drm/i915/selftests/librapl.h deleted file mode 100644 index e3b24fad0a7a..000000000000 --- a/drivers/gpu/drm/i915/selftests/librapl.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * Copyright © 2020 Intel Corporation - */ - -#ifndef SELFTEST_LIBRAPL_H -#define SELFTEST_LIBRAPL_H - -#include - -struct drm_i915_private; - -bool librapl_supported(const struct drm_i915_private *i915); - -u64 librapl_energy_uJ(void); - -#endif /* SELFTEST_LIBRAPL_H */ From patchwork Wed Apr 5 06:00:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riana Tauro X-Patchwork-Id: 13201158 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 9A42AC7619A for ; Wed, 5 Apr 2023 06:00:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 38EB610E0EC; Wed, 5 Apr 2023 06:00:49 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id B404B10E0EC for ; Wed, 5 Apr 2023 06:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680674447; x=1712210447; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EOmt1uGdJMj34XxyT7egA4tBwOXEce1MgvbHLdNdYdc=; b=DtsXlCoxrN00fy3krgezbKmCMJA6m9shFoXgRIzk6D7GtLo3SShBiSJn 6OndkwP4RcAPRzifn0VsiolbvkrkkIsRWkhuVHFFEKR9QjofiNfw5edpM u/nCD83hPSTd92ZoI7Gk4/ZbUf5altgkT4cADe9RGu3/ksgBiygXZA6GL P02BIxpcanwebbyNC17/L6vPPVYk5duDuHcQoKM5Lcx2vJJ8WgH/oQx5x BnwtwSeCryLhhOVQs7z+B4vAxIp/bUE02R8hYt9YhKyLXb/Sgb+2ETw/Z txHXYEq0znjJ390kNgxjQe7KMWuc0egNw7NT+jlZz/wjDeDAdFd99Y/y5 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="326412494" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="326412494" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="860849575" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="860849575" Received: from rtauro-desk.iind.intel.com ([10.190.239.41]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:41 -0700 From: Riana Tauro To: intel-gfx@lists.freedesktop.org Date: Wed, 5 Apr 2023 11:30:27 +0530 Message-Id: <20230405060029.3574262-3-riana.tauro@intel.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405060029.3574262-1-riana.tauro@intel.com> References: <20230405060029.3574262-1-riana.tauro@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v8 2/4] drm/i915/hwmon: Add helper function to obtain energy values 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 an interface to obtain hwmon energy values. The function returns per-gt energy if gt level energy is available else returns the package level energy if there is a single gt. This is used by selftests to verify power consumption v2 : use i915_hwmon prefix (Anshuman) v3 : re-use is_visible function of energy to remove redundant code (Anshuman) v4 : fix kernel-doc (Anshuman) add per-gt hwmon support (Ashutosh) v5 : add check to return package level energy only when there is a single gt and gt level energy is not available. (Ashutosh) Signed-off-by: Riana Tauro Reviewed-by: Anshuman Gupta Reviewed-by: Ashutosh Dixit --- drivers/gpu/drm/i915/i915_hwmon.c | 28 ++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_hwmon.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c index 8e7dccc8d3a0..efc2ccaf64d1 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.c +++ b/drivers/gpu/drm/i915/i915_hwmon.c @@ -500,6 +500,34 @@ hwm_energy_read(struct hwm_drvdata *ddat, u32 attr, long *val) } } +/** + * i915_hwmon_get_energy - obtains energy value + * @gt: intel_gt structure + * @energy: pointer to store energy in uJ + * + * This function checks for the validity of the underlying energy + * hardware register and obtains per-gt level energy + * values. + * + * Return: 0 on success, -EOPNOTSUPP if register is invalid + */ +int +i915_hwmon_get_energy(struct intel_gt *gt, long *energy) +{ + struct i915_hwmon *hwmon = gt->i915->hwmon; + struct hwm_drvdata *ddat = &hwmon->ddat; + struct hwm_drvdata *ddat_gt = hwmon->ddat_gt + gt->info.id; + + if (hwm_energy_is_visible(ddat_gt, hwmon_energy_input)) + hwm_energy(ddat_gt, energy); + else if (!HAS_EXTRA_GT_LIST(gt->i915) && hwm_energy_is_visible(ddat, hwmon_energy_input)) + hwm_energy(ddat, energy); + else + return -EOPNOTSUPP; + + return 0; +} + static umode_t hwm_curr_is_visible(const struct hwm_drvdata *ddat, u32 attr) { diff --git a/drivers/gpu/drm/i915/i915_hwmon.h b/drivers/gpu/drm/i915/i915_hwmon.h index 7ca9cf2c34c9..1c38cfdbb7e9 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.h +++ b/drivers/gpu/drm/i915/i915_hwmon.h @@ -8,13 +8,16 @@ #define __I915_HWMON_H__ struct drm_i915_private; +struct intel_gt; #if IS_REACHABLE(CONFIG_HWMON) void i915_hwmon_register(struct drm_i915_private *i915); void i915_hwmon_unregister(struct drm_i915_private *i915); +int i915_hwmon_get_energy(struct intel_gt *gt, long *energy); #else static inline void i915_hwmon_register(struct drm_i915_private *i915) { }; static inline void i915_hwmon_unregister(struct drm_i915_private *i915) { }; +static inline int i915_hwmon_get_energy(struct intel_gt *gt, long *energy) { return -EOPNOTSUPP; } #endif #endif /* __I915_HWMON_H__ */ From patchwork Wed Apr 5 06:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riana Tauro X-Patchwork-Id: 13201159 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 B4FC9C76188 for ; Wed, 5 Apr 2023 06:00:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1F36710E2FF; Wed, 5 Apr 2023 06:00:59 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C50610E2FF for ; Wed, 5 Apr 2023 06:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680674458; x=1712210458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hYP9AK0lC9blnheEYIo6o+gTLMTcuC6HwpSA+TQSdH0=; b=MkoOpAo5oeV3CFkF36F/RzXk/8CHSJLhtpSmBqwW3ZdUzV3XRcp5BGgv 7m0uj0q7yRwEaweTrr/cL/OY4tXhAEsRHp51Q6jBkmtcw9LiCHv4efhUJ 9rg54TZxrfx9URBPnQy3pAcMtpbpm667g6Ii8ddMxL8MUA6AiKxXTzYxN 2PjGKdBfV8DfQfhBzB76eXt4zn2L543xohfHLMvwcp2rs5hzhQXa1fbad ObPigx4Dsu/19KDcJBjIiAqkzfgXlltdsJemTD2sQgzd78Q4KyeDuEsbL TzdE6WQxOJrOT5JGCEuyA/AGllmvrax+9/F6go4lMIRyriVO2BJRovgX0 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="326412523" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="326412523" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="860849610" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="860849610" Received: from rtauro-desk.iind.intel.com ([10.190.239.41]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:43 -0700 From: Riana Tauro To: intel-gfx@lists.freedesktop.org Date: Wed, 5 Apr 2023 11:30:28 +0530 Message-Id: <20230405060029.3574262-4-riana.tauro@intel.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405060029.3574262-1-riana.tauro@intel.com> References: <20230405060029.3574262-1-riana.tauro@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v8 3/4] drm/i915/selftests: Add hwmon support in libpower for dgfx 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" From: Tilak Tangudu hwmon provides an interface to read energy values for discrete graphics. add hwmon support to the existing libpower library so that it can verify power consumption values in different selftests. Changed prototype of libpower_get_energy_uJ v2: add per-gt hwmon support (Ashutosh) Signed-off-by: Tilak Tangudu Co-developed-by: Riana Tauro Signed-off-by: Riana Tauro Reviewed-by: Anshuman Gupta Reviewed-by: Ashutosh Dixit --- drivers/gpu/drm/i915/gt/selftest_rc6.c | 10 ++++---- drivers/gpu/drm/i915/gt/selftest_rps.c | 24 +++++++++--------- drivers/gpu/drm/i915/gt/selftest_slpc.c | 4 +-- drivers/gpu/drm/i915/selftests/libpower.c | 31 +++++++++++------------ drivers/gpu/drm/i915/selftests/libpower.h | 10 +++++--- 5 files changed, 40 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/selftest_rc6.c b/drivers/gpu/drm/i915/gt/selftest_rc6.c index 15b84c428f66..682f2fe67b3a 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rc6.c +++ b/drivers/gpu/drm/i915/gt/selftest_rc6.c @@ -51,7 +51,7 @@ int live_rc6_manual(void *arg) if (IS_VALLEYVIEW(gt->i915) || IS_CHERRYVIEW(gt->i915)) return 0; - has_power = libpower_supported(gt->i915); + has_power = libpower_supported(gt); wakeref = intel_runtime_pm_get(gt->uncore->rpm); /* Force RC6 off for starters */ @@ -61,9 +61,9 @@ int live_rc6_manual(void *arg) res[0] = rc6_residency(rc6); dt = ktime_get(); - rc0_power = libpower_get_energy_uJ(); + rc0_power = libpower_get_energy_uJ(gt); msleep(250); - rc0_power = libpower_get_energy_uJ() - rc0_power; + rc0_power = libpower_get_energy_uJ(gt) - rc0_power; dt = ktime_sub(ktime_get(), dt); res[1] = rc6_residency(rc6); if ((res[1] - res[0]) >> 10) { @@ -89,9 +89,9 @@ int live_rc6_manual(void *arg) res[0] = rc6_residency(rc6); intel_uncore_forcewake_flush(rc6_to_uncore(rc6), FORCEWAKE_ALL); dt = ktime_get(); - rc6_power = libpower_get_energy_uJ(); + rc6_power = libpower_get_energy_uJ(gt); msleep(100); - rc6_power = libpower_get_energy_uJ() - rc6_power; + rc6_power = libpower_get_energy_uJ(gt) - rc6_power; dt = ktime_sub(ktime_get(), dt); res[1] = rc6_residency(rc6); if (res[1] == res[0]) { diff --git a/drivers/gpu/drm/i915/gt/selftest_rps.c b/drivers/gpu/drm/i915/gt/selftest_rps.c index ab534964da4d..55ac2fdf2264 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rps.c +++ b/drivers/gpu/drm/i915/gt/selftest_rps.c @@ -1090,38 +1090,38 @@ int live_rps_interrupt(void *arg) return err; } -static u64 __measure_power(int duration_ms) +static u64 __measure_power(struct intel_gt *gt, int duration_ms) { u64 dE, dt; - dE = libpower_get_energy_uJ(); + dE = libpower_get_energy_uJ(gt); dt = ktime_get(); usleep_range(1000 * duration_ms, 2000 * duration_ms); - dE = libpower_get_energy_uJ() - dE; + dE = libpower_get_energy_uJ(gt) - dE; dt = ktime_get() - dt; return div64_u64(1000 * 1000 * dE, dt); } -static u64 measure_power(struct intel_rps *rps, int *freq) +static u64 measure_power(struct intel_gt *gt, int *freq) { u64 x[5]; int i; for (i = 0; i < 5; i++) - x[i] = __measure_power(5); + x[i] = __measure_power(gt, 5); - *freq = (*freq + intel_rps_read_actual_frequency(rps)) / 2; + *freq = (*freq + intel_rps_read_actual_frequency(>->rps)) / 2; /* A simple triangle filter for better result stability */ sort(x, 5, sizeof(*x), cmp_u64, NULL); return div_u64(x[1] + 2 * x[2] + x[3], 4); } -static u64 measure_power_at(struct intel_rps *rps, int *freq) +static u64 measure_power_at(struct intel_gt *gt, int *freq) { - *freq = rps_set_check(rps, *freq); - return measure_power(rps, freq); + *freq = rps_set_check(>->rps, *freq); + return measure_power(gt, freq); } int live_rps_power(void *arg) @@ -1143,7 +1143,7 @@ int live_rps_power(void *arg) if (!intel_rps_is_enabled(rps) || GRAPHICS_VER(gt->i915) < 6) return 0; - if (!libpower_supported(gt->i915)) + if (!libpower_supported(gt)) return 0; if (igt_spinner_init(&spin, gt)) @@ -1187,10 +1187,10 @@ int live_rps_power(void *arg) } max.freq = rps->max_freq; - max.power = measure_power_at(rps, &max.freq); + max.power = measure_power_at(gt, &max.freq); min.freq = rps->min_freq; - min.power = measure_power_at(rps, &min.freq); + min.power = measure_power_at(gt, &min.freq); igt_spinner_end(&spin); st_engine_heartbeat_enable(engine); diff --git a/drivers/gpu/drm/i915/gt/selftest_slpc.c b/drivers/gpu/drm/i915/gt/selftest_slpc.c index fc1cdda82ec6..20b9e05d3d16 100644 --- a/drivers/gpu/drm/i915/gt/selftest_slpc.c +++ b/drivers/gpu/drm/i915/gt/selftest_slpc.c @@ -78,7 +78,7 @@ static u64 measure_power_at_freq(struct intel_gt *gt, int *freq, u64 *power) if (err) return err; *freq = intel_rps_read_actual_frequency(>->rps); - *power = measure_power(>->rps, freq); + *power = measure_power(gt, freq); return err; } @@ -169,7 +169,7 @@ static int slpc_power(struct intel_gt *gt, struct intel_engine_cs *engine) * actually saves power. Let's see if our RAPL measurement supports * that theory. */ - if (!libpower_supported(gt->i915)) + if (!libpower_supported(gt)) return 0; min.freq = slpc->min_freq; diff --git a/drivers/gpu/drm/i915/selftests/libpower.c b/drivers/gpu/drm/i915/selftests/libpower.c index 5d96cccd2e55..c25771d200e2 100644 --- a/drivers/gpu/drm/i915/selftests/libpower.c +++ b/drivers/gpu/drm/i915/selftests/libpower.c @@ -6,29 +6,28 @@ #include #include "i915_drv.h" +#include "i915_hwmon.h" #include "libpower.h" -bool libpower_supported(const struct drm_i915_private *i915) -{ - /* Discrete cards require hwmon integration */ - if (IS_DGFX(i915)) - return false; - - return libpower_get_energy_uJ(); -} - -u64 libpower_get_energy_uJ(void) +u64 libpower_get_energy_uJ(struct intel_gt *gt) { unsigned long long power; u32 units; + long energy_uJ = 0; - if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) - return 0; + if (IS_DGFX(gt->i915)) { + if (i915_hwmon_get_energy(gt, &energy_uJ)) + return 0; + } else { + if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) + return 0; - units = (power & 0x1f00) >> 8; + units = (power & 0x1f00) >> 8; - if (rdmsrl_safe(MSR_PP1_ENERGY_STATUS, &power)) - return 0; + if (rdmsrl_safe(MSR_PP1_ENERGY_STATUS, &power)) + return 0; - return (1000000 * power) >> units; /* convert to uJ */ + energy_uJ = (1000000 * power) >> units; /* convert to uJ */ + } + return energy_uJ; } diff --git a/drivers/gpu/drm/i915/selftests/libpower.h b/drivers/gpu/drm/i915/selftests/libpower.h index dd4b93ccf6b0..52d9eee6852a 100644 --- a/drivers/gpu/drm/i915/selftests/libpower.h +++ b/drivers/gpu/drm/i915/selftests/libpower.h @@ -8,10 +8,12 @@ #include -struct drm_i915_private; +struct intel_gt; -bool libpower_supported(const struct drm_i915_private *i915); - -u64 libpower_get_energy_uJ(void); +u64 libpower_get_energy_uJ(struct intel_gt *gt); +static inline bool libpower_supported(struct intel_gt *gt) +{ + return libpower_get_energy_uJ(gt); +} #endif /* SELFTEST_LIBPOWER_H */ From patchwork Wed Apr 5 06:00:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riana Tauro X-Patchwork-Id: 13201160 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 CD058C7619A for ; Wed, 5 Apr 2023 06:01:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E45410E30F; Wed, 5 Apr 2023 06:01:04 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 19D5610E30F for ; Wed, 5 Apr 2023 06:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680674463; x=1712210463; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OvIug0fLmsMl7GqvjJ05ATlbzz1hDwokT4lX0z7Rqck=; b=CBJMJvE98QcwTC5SqBNZaHcKJtzyWo+wAILG44VKkwI/+a9EWpkclF19 CtS2e/qbM6biDR27iFxpwrjOvtkkgR9QRzA0/6U3mghPBfWYakKPWs7Ov uWV2v8A50QJxrZGifz9lQi9USwan/fmBbH35kw6IBc34hWQJi/YHXUxjR 3aqIVqKv0CpJEL1WFhys1twcQTJGwKR7NBGmGq64Kp2YBy5qUq1YlrfRf b6hS2Qh5GHcswy8ubunoKr+gB/PQV3NY8Qs+NRC+gF4jhfgRd6fJC/L5D cx7QbztUG296XCQ3Pr9QqAYL09kj6msSuWPQUAoE5lJxh2l7Hm82QuIcJ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="326412559" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="326412559" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="860849633" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="860849633" Received: from rtauro-desk.iind.intel.com ([10.190.239.41]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 23:00:46 -0700 From: Riana Tauro To: intel-gfx@lists.freedesktop.org Date: Wed, 5 Apr 2023 11:30:29 +0530 Message-Id: <20230405060029.3574262-5-riana.tauro@intel.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405060029.3574262-1-riana.tauro@intel.com> References: <20230405060029.3574262-1-riana.tauro@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v8 4/4] drm/i915/selftests: skip comparison of power for discrete graphics 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" skip comparison of power for discrete graphics TODO : measure power of GT in discrete graphics and modify the condition. Signed-off-by: Riana Tauro Reviewed-by: Anshuman Gupta --- drivers/gpu/drm/i915/gt/selftest_rc6.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gt/selftest_rc6.c b/drivers/gpu/drm/i915/gt/selftest_rc6.c index 682f2fe67b3a..57c0cb4ecc88 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rc6.c +++ b/drivers/gpu/drm/i915/gt/selftest_rc6.c @@ -107,7 +107,13 @@ int live_rc6_manual(void *arg) ktime_to_ns(dt)); pr_info("GPU consumed %llduW in RC0 and %llduW in RC6\n", rc0_power, rc6_power); - if (2 * rc6_power > rc0_power) { + + /* + * Condition valid for integrated graphics + * TODO : Measure power of GT for discrete graphics and + * modify the condition + */ + if (!IS_DGFX(gt->i915) && (2 * rc6_power > rc0_power)) { pr_err("GPU leaked energy while in RC6!\n"); err = -EINVAL; goto out_unlock;