[Intel-gfx] [RFC 02/11] drm/i915: Add intel_energy_uJ

Tvrtko Ursulin tursulin at ursulin.net
Mon Sep 11 15:25:50 UTC 2017


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

Extract code from i915_energy_uJ (debugfs) so it can be used by
other callers in future patches.

v2: Rebase.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 17 +----------------
 drivers/gpu/drm/i915/i915_drv.h     |  2 ++
 drivers/gpu/drm/i915/intel_pm.c     | 25 +++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 6338018f655d..b3a4a66bf7c4 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2780,26 +2780,11 @@ static int i915_sink_crc(struct seq_file *m, void *data)
 static int i915_energy_uJ(struct seq_file *m, void *data)
 {
 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
-	unsigned long long power;
-	u32 units;
 
 	if (INTEL_GEN(dev_priv) < 6)
 		return -ENODEV;
 
-	intel_runtime_pm_get(dev_priv);
-
-	if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) {
-		intel_runtime_pm_put(dev_priv);
-		return -ENODEV;
-	}
-
-	units = (power & 0x1f00) >> 8;
-	power = I915_READ(MCH_SECP_NRG_STTS);
-	power = (1000000 * power) >> units; /* convert to uJ */
-
-	intel_runtime_pm_put(dev_priv);
-
-	seq_printf(m, "%llu", power);
+	seq_printf(m, "%llu", intel_energy_uJ(dev_priv));
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index dbd054e88ca2..826c74970ce9 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -4123,6 +4123,8 @@ static inline u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv,
 	return DIV_ROUND_UP_ULL(intel_rc6_residency_ns(dev_priv, reg), 1000);
 }
 
+u64 intel_energy_uJ(struct drm_i915_private *dev_priv);
+
 #define I915_READ8(reg)		dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
 #define I915_WRITE8(reg, val)	dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
 
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index 60461f49936b..ff67df8d99fa 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -9369,3 +9369,28 @@ u64 intel_rc6_residency_ns(struct drm_i915_private *dev_priv,
 
 	return res;
 }
+
+unsigned long long intel_energy_uJ(struct drm_i915_private *dev_priv)
+{
+	unsigned long long power;
+	unsigned long units;
+
+	if (GEM_WARN_ON(INTEL_GEN(dev_priv) < 6))
+		return 0;
+
+	intel_runtime_pm_get(dev_priv);
+
+	if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) {
+		power = 0;
+		goto out;
+	}
+
+	units = (power >> 8) & 0x1f;
+	power = I915_READ(MCH_SECP_NRG_STTS);
+	power = (1000000 * power) >> units; /* convert to uJ */
+
+out:
+	intel_runtime_pm_put(dev_priv);
+
+	return power;
+}
-- 
2.9.5



More information about the Intel-gfx mailing list