From patchwork Wed Oct 19 06:04:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Riana Tauro X-Patchwork-Id: 13011368 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 E8FFBC4332F for ; Wed, 19 Oct 2022 06:04:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B63710E415; Wed, 19 Oct 2022 06:04:50 +0000 (UTC) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id BDFC010E415 for ; Wed, 19 Oct 2022 06:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666159473; x=1697695473; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VpATPIqxdRLUvqba809Oykl/C1bF60m34L3KSDZaPPE=; b=lddXEYpfmjNka7Tzc3sJxRyaDbN+8OGxg9jBrz4Vwxdmzu1hnM6qpb1O 9dlpQAc4QU/3u49Q/p2Ye81HKa7vWTmcFig6fGG57rlaLnMe9GBDJo6b+ 91Sh44LDvN8xn5yeZLGsuo1TrPa4ekoWCVjkT7pvM3n6uos0FEaeYSfV8 Rvzr3r+NAfxpGXc/vl688XtTc8XiJmBiiuJK1Iws4QiaHyr4PDleFcn1v gRSF9O3WVXbAK5mjZdPGmxMqdw6zRhrPYqynVvLftj0VZE0GlmadAtnM1 Y63BvL1zmtA5c68YrOsS0B8+JFqTW4bsS6HMEj943z/eaPSQWgy4aVfzf A==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="368367032" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="368367032" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 23:04:33 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="580170666" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="580170666" Received: from rtauro-desk.iind.intel.com ([10.190.239.41]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 23:04:31 -0700 From: Riana Tauro To: intel-gfx@lists.freedesktop.org Date: Wed, 19 Oct 2022 11:34:00 +0530 Message-Id: <20221019060402.2807360-2-riana.tauro@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019060402.2807360-1-riana.tauro@intel.com> References: <20221019060402.2807360-1-riana.tauro@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 1/3] 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 functions in librapl library to libpower. No functional changes. Signed-off-by: Riana Tauro --- 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 2535593ab379..6bb291312c84 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -339,7 +339,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 8c70b7e12074..aacff50dfa89 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 99a372486fb7..3287698c655b 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 */ @@ -1099,9 +1099,9 @@ static u64 __measure_power(int duration_ms) u64 dE, dt; dt = ktime_get(); - dE = librapl_energy_uJ(); + dE = libpower_get_energy_uJ(); 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); @@ -1147,7 +1147,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 4c6e9257e593..494e7a486b07 100644 --- a/drivers/gpu/drm/i915/gt/selftest_slpc.c +++ b/drivers/gpu/drm/i915/gt/selftest_slpc.c @@ -161,7 +161,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..c66e993c5f85 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 © 2022 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..5352981eb946 --- /dev/null +++ b/drivers/gpu/drm/i915/selftests/libpower.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2022 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 Oct 19 06:04:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riana Tauro X-Patchwork-Id: 13011369 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 34082C43217 for ; Wed, 19 Oct 2022 06:04:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8675B10EA6A; Wed, 19 Oct 2022 06:04:51 +0000 (UTC) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 444EE10E415 for ; Wed, 19 Oct 2022 06:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666159476; x=1697695476; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6ybq6eX+tWw4v7EYi7jSm0s4SbAHfoeR1qBZ7Im7zIo=; b=ICgy1WWy1zTz2RE3H1cA+46wcOahx/2GhXllmwdA/QOBxubGXx8xZnec CMUUux0RqD+iqxtwH4rWT7T3UZhRvK/q3IKRog+VnIjDW1wqrgUyODdSB AzwZDirN6TbV26BEcokGhW6Ok/227pKVZh47MwyygZUt9W6IoWz3AaMPU TCrH6orAw9xn3DNwcrAdYU+m9DTQCNUnWm+LHe4w38OnvSohcGzrh2c0j 3frkTXGrWHOB4No40EpD7smnDdiCgxiW6+U53RferpnjqIpNrU64/IJtk AJ7ddy1iV4ssE/DUpyNJXDVENhgCPE+c8aLOAwGvkKy9dcumpPAp23yxc Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="368367038" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="368367038" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 23:04:36 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="580170673" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="580170673" Received: from rtauro-desk.iind.intel.com ([10.190.239.41]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 23:04:33 -0700 From: Riana Tauro To: intel-gfx@lists.freedesktop.org Date: Wed, 19 Oct 2022 11:34:01 +0530 Message-Id: <20221019060402.2807360-3-riana.tauro@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019060402.2807360-1-riana.tauro@intel.com> References: <20221019060402.2807360-1-riana.tauro@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/3] 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. This is used by selftest to verify power consumption Signed-off-by: Riana Tauro --- drivers/gpu/drm/i915/i915_hwmon.c | 23 ++++++++++++++++++++--- drivers/gpu/drm/i915/i915_hwmon.h | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c index 9e9781493025..1eb85cd96171 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.c +++ b/drivers/gpu/drm/i915/i915_hwmon.c @@ -138,7 +138,7 @@ hwm_field_scale_and_write(struct hwm_drvdata *ddat, i915_reg_t rgadr, * hwmon->scl_shift_energy of 14 bits we have 57 (63 - 20 + 14) bits before * energy1_input overflows. This at 1000 W is an overflow duration of 278 years. */ -static void +static int hwm_energy(struct hwm_drvdata *ddat, long *energy) { struct intel_uncore *uncore = ddat->uncore; @@ -153,6 +153,9 @@ hwm_energy(struct hwm_drvdata *ddat, long *energy) else rgaddr = hwmon->rg.energy_status_all; + if (!i915_mmio_reg_valid(rgaddr)) + return -EOPNOTSUPP; + mutex_lock(&hwmon->hwmon_lock); with_intel_runtime_pm(uncore->rpm, wakeref) @@ -167,6 +170,21 @@ hwm_energy(struct hwm_drvdata *ddat, long *energy) *energy = mul_u64_u32_shr(ei->accum_energy, SF_ENERGY, hwmon->scl_shift_energy); mutex_unlock(&hwmon->hwmon_lock); + + return 0; +} + +/* + * i915_hwm_get_energy - obtains energy value + * Returns: 0 on success or a negative error code + */ +int +i915_hwm_get_energy(struct drm_i915_private *i915, long *energy) +{ + struct i915_hwmon *hwmon = i915->hwmon; + struct hwm_drvdata *ddat = &hwmon->ddat; + + return hwm_energy(ddat, energy); } static ssize_t @@ -441,8 +459,7 @@ hwm_energy_read(struct hwm_drvdata *ddat, u32 attr, long *val) { switch (attr) { case hwmon_energy_input: - hwm_energy(ddat, val); - return 0; + return hwm_energy(ddat, val); default: return -EOPNOTSUPP; } diff --git a/drivers/gpu/drm/i915/i915_hwmon.h b/drivers/gpu/drm/i915/i915_hwmon.h index 7ca9cf2c34c9..fa3b13568b37 100644 --- a/drivers/gpu/drm/i915/i915_hwmon.h +++ b/drivers/gpu/drm/i915/i915_hwmon.h @@ -12,6 +12,7 @@ struct drm_i915_private; #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_hwm_get_energy(struct drm_i915_private *i915, 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) { }; From patchwork Wed Oct 19 06:04:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riana Tauro X-Patchwork-Id: 13011370 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 1B15CC4332F for ; Wed, 19 Oct 2022 06:05:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D9D810EA7A; Wed, 19 Oct 2022 06:05:09 +0000 (UTC) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC72D10E415 for ; Wed, 19 Oct 2022 06:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666159478; x=1697695478; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SnL0po/JOXVHg1aU+fGXha4LHuu2Dfgb44yuIKVLCII=; b=LmIR/G33i+otZZ8i0QSnLhkITarSJsCNUJs+vz2Mn8WmqE7GkuhX6U5A lR0zLU2yeBCy3EzSZvzcW4VECwZYc/HULhCjcdgEmpnq+apY/4MMPd0/8 BXKl6VGqcHHPvJEL8yJLjIARLF5ktGAX7WGcbcXJ80lcSQsr9nNx/vr8b d72IAnaD3SlDDP72xRo/Ko5Y3k0cQpotAWQNI/fwT1oMhgD40tCmVWHbc 7l+M1Uk1T4C0IP+0FnBKhCpA8aCbax/oSCcjkv+9cw/BW86MEgulefpIe wTbhumkiDi2aGYhoIn4yRFWJjtjjc7ce60ZqNM9ONmhsPHfAmUBcB9uVE w==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="368367055" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="368367055" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 23:04:38 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="580170684" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="580170684" Received: from rtauro-desk.iind.intel.com ([10.190.239.41]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 23:04:36 -0700 From: Riana Tauro To: intel-gfx@lists.freedesktop.org Date: Wed, 19 Oct 2022 11:34:02 +0530 Message-Id: <20221019060402.2807360-4-riana.tauro@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019060402.2807360-1-riana.tauro@intel.com> References: <20221019060402.2807360-1-riana.tauro@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 3/3] 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 Signed-off-by: Tilak Tangudu Signed-off-by: Riana Tauro --- drivers/gpu/drm/i915/gt/selftest_rc6.c | 8 +++--- drivers/gpu/drm/i915/gt/selftest_rps.c | 22 +++++++-------- drivers/gpu/drm/i915/gt/selftest_slpc.c | 2 +- drivers/gpu/drm/i915/selftests/libpower.c | 33 ++++++++++++----------- drivers/gpu/drm/i915/selftests/libpower.h | 8 +++--- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/selftest_rc6.c b/drivers/gpu/drm/i915/gt/selftest_rc6.c index aacff50dfa89..585915f7c988 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rc6.c +++ b/drivers/gpu/drm/i915/gt/selftest_rc6.c @@ -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->i915); msleep(250); - rc0_power = libpower_get_energy_uJ() - rc0_power; + rc0_power = libpower_get_energy_uJ(gt->i915) - 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->i915); msleep(100); - rc6_power = libpower_get_energy_uJ() - rc6_power; + rc6_power = libpower_get_energy_uJ(gt->i915) - 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 3287698c655b..e88bd774a862 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rps.c +++ b/drivers/gpu/drm/i915/gt/selftest_rps.c @@ -1094,38 +1094,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; dt = ktime_get(); - dE = libpower_get_energy_uJ(); + dE = libpower_get_energy_uJ(gt->i915); usleep_range(1000 * duration_ms, 2000 * duration_ms); - dE = libpower_get_energy_uJ() - dE; + dE = libpower_get_energy_uJ(gt->i915) - 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) @@ -1191,10 +1191,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 494e7a486b07..bca15cfad8a1 100644 --- a/drivers/gpu/drm/i915/gt/selftest_slpc.c +++ b/drivers/gpu/drm/i915/gt/selftest_slpc.c @@ -70,7 +70,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; } diff --git a/drivers/gpu/drm/i915/selftests/libpower.c b/drivers/gpu/drm/i915/selftests/libpower.c index c66e993c5f85..b0dfcdf0f20b 100644 --- a/drivers/gpu/drm/i915/selftests/libpower.c +++ b/drivers/gpu/drm/i915/selftests/libpower.c @@ -6,29 +6,30 @@ #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 drm_i915_private *i915) { unsigned long long power; u32 units; + long energy_uJ = 0; - if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) - return 0; + if (IS_DGFX(i915)) { +#if IS_REACHABLE(CONFIG_HWMON) + if (i915_hwm_get_energy(i915, &energy_uJ)) +#endif + 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 5352981eb946..03a44611f9e9 100644 --- a/drivers/gpu/drm/i915/selftests/libpower.h +++ b/drivers/gpu/drm/i915/selftests/libpower.h @@ -10,8 +10,10 @@ struct drm_i915_private; -bool libpower_supported(const struct drm_i915_private *i915); - -u64 libpower_get_energy_uJ(void); +u64 libpower_get_energy_uJ(struct drm_i915_private *i915); +static inline bool libpower_supported(struct drm_i915_private *i915) +{ + return libpower_get_energy_uJ(i915); +} #endif /* SELFTEST_LIBPOWER_H */