Commit d4e3d455 authored by Chris Wilson's avatar Chris Wilson

drm/i915/selftests: Move gpu energy measurement into its own little lib

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: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarAndi Shyti <andi.shyti@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200417152018.13079-1-chris@chris-wilson.co.uk
parent 680e1af7
......@@ -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
......
......@@ -11,22 +11,7 @@
#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]) {
......
// 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 */
}
/* 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 */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment