drm/i915/selftests: Move gpu energy measurement into its own little lib
authorChris Wilson <chris@chris-wilson.co.uk>
Fri, 17 Apr 2020 15:20:17 +0000 (16:20 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 17 Apr 2020 17:48:51 +0000 (18:48 +0100)
Move the handy utility to measure the GPU energy consumption using RAPL
msr into a common lib so that it can be reused easily.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Andi Shyti <andi.shyti@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200417152018.13079-1-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/Makefile
drivers/gpu/drm/i915/gt/selftest_rc6.c
drivers/gpu/drm/i915/selftests/librapl.c [new file with mode: 0644]
drivers/gpu/drm/i915/selftests/librapl.h [new file with mode: 0644]

index 44c506b..6f112d8 100644 (file)
@@ -257,7 +257,8 @@ i915-$(CONFIG_DRM_I915_SELFTEST) += \
        selftests/igt_live_test.o \
        selftests/igt_mmap.o \
        selftests/igt_reset.o \
-       selftests/igt_spinner.o
+       selftests/igt_spinner.o \
+       selftests/librapl.o
 
 # virtual gpu code
 i915-y += i915_vgpu.o
index 08c3dbd..2dc4606 100644 (file)
 #include "selftest_rc6.h"
 
 #include "selftests/i915_random.h"
-
-static u64 energy_uJ(struct intel_rc6 *rc6)
-{
-       unsigned long long power;
-       u32 units;
-
-       if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power))
-               return 0;
-
-       units = (power & 0x1f00) >> 8;
-
-       if (rdmsrl_safe(MSR_PP1_ENERGY_STATUS, &power))
-               return 0;
-
-       return (1000000 * power) >> units; /* convert to uJ */
-}
+#include "selftests/librapl.h"
 
 static u64 rc6_residency(struct intel_rc6 *rc6)
 {
@@ -74,9 +59,9 @@ int live_rc6_manual(void *arg)
        res[0] = rc6_residency(rc6);
 
        dt = ktime_get();
-       rc0_power = energy_uJ(rc6);
+       rc0_power = librapl_energy_uJ();
        msleep(250);
-       rc0_power = energy_uJ(rc6) - rc0_power;
+       rc0_power = librapl_energy_uJ() - rc0_power;
        dt = ktime_sub(ktime_get(), dt);
        res[1] = rc6_residency(rc6);
        if ((res[1] - res[0]) >> 10) {
@@ -99,9 +84,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 = energy_uJ(rc6);
+       rc6_power = librapl_energy_uJ();
        msleep(100);
-       rc6_power = energy_uJ(rc6) - rc6_power;
+       rc6_power = librapl_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/selftests/librapl.c b/drivers/gpu/drm/i915/selftests/librapl.c
new file mode 100644 (file)
index 0000000..58710ac
--- /dev/null
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2020 Intel Corporation
+ */
+
+#include <asm/msr.h>
+
+#include "librapl.h"
+
+u64 librapl_energy_uJ(void)
+{
+       unsigned long long power;
+       u32 units;
+
+       if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power))
+               return 0;
+
+       units = (power & 0x1f00) >> 8;
+
+       if (rdmsrl_safe(MSR_PP1_ENERGY_STATUS, &power))
+               return 0;
+
+       return (1000000 * power) >> units; /* convert to uJ */
+}
diff --git a/drivers/gpu/drm/i915/selftests/librapl.h b/drivers/gpu/drm/i915/selftests/librapl.h
new file mode 100644 (file)
index 0000000..887f3e9
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2020 Intel Corporation
+ */
+
+#ifndef SELFTEST_LIBRAPL_H
+#define SELFTEST_LIBRAPL_H
+
+#include <linux/types.h>
+
+u64 librapl_energy_uJ(void);
+
+#endif /* SELFTEST_LIBRAPL_H */