Skip to contentSkip to conversation

drm/i915/vlv: use lower precision RC6 counter

PATCH In review Jesse Barnes 3 participants 7 messages Sep 26, 2013 – Sep 27, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/i915/vlv: use lower precision RC6 counter

And add some reg defines while we're at it. Since the units of the RC6 residency counter are actually in CZ clocks, we want to just use the high bits or we'll overflow too frequently.

---
 drivers/gpu/drm/i915/i915_reg.h | 4 ++++
 drivers/gpu/drm/i915/intel_pm.c | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_reg.h +4 -0
index 00fda45..cf995bb 100644
@@ -4721,6 +4721,10 @@
 						 GEN6_PM_RP_DOWN_TIMEOUT)
 
 #define GEN6_GT_GFX_RC6_LOCKED			0x138104
+#define VLV_COUNTER_CONTROL			0x138104
+#define   VLV_COUNT_RANGE_HIGH			(1<<15)
+#define   VLV_MEDIA_RC6_COUNT_EN		(1<<1)
+#define   VLV_RENDER_RC6_COUNT_EN		(1<<0)
 #define GEN6_GT_GFX_RC6				0x138108
 #define GEN6_GT_GFX_RC6p			0x13810C
 #define GEN6_GT_GFX_RC6pp			0x138110
drivers/gpu/drm/i915/intel_pm.c +4 -1
index d27eda6..d8bdc98 100644
@@ -3827,7 +3827,10 @@ static void valleyview_enable_rps(struct drm_device *dev)
 	I915_WRITE(GEN6_RC6_THRESHOLD, 0xc350);
 
 	/* allows RC6 residency counter to work */
-	I915_WRITE(0x138104, _MASKED_BIT_ENABLE(0x3));
+	I915_WRITE(VLV_COUNTER_CONTROL,
+		   _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH |
+				      VLV_MEDIA_RC6_COUNT_EN |
+				      VLV_RENDER_RC6_COUNT_EN));
 	if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE)
 		rc6_mode = GEN7_RC_CTL_TO_MODE;
 	I915_WRITE(GEN6_RC_CONTROL, rc6_mode);
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 drm/i915/vlv: use correct units for rc6 residency

We need to use the clock control reg to figure out how many CZ clks are in 30ns and use that as the basis for our RC6 residency calculations.

References: https://bugs.freedesktop.org/show_bug.cgi?id=69692

---
 drivers/gpu/drm/i915/i915_reg.h   |  3 +++
 drivers/gpu/drm/i915/i915_sysfs.c | 22 ++++++++++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +3 -0
index cf995bb..6f8d0cf 100644
@@ -1797,6 +1797,9 @@
  */
 #define HSW_CXT_TOTAL_SIZE		(17 * PAGE_SIZE)
 
+#define VLV_CLK_CTL2			0x101104
+#define   CLK_CTL2_CZCOUNT_30NS_SHIFT	28
+
 /*
  * Overlay regs
  */
drivers/gpu/drm/i915/i915_sysfs.c +20 -2
index 44f4c1a..9c60515 100644
@@ -37,12 +37,30 @@ static u32 calc_residency(struct drm_device *dev, const u32 reg)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u64 raw_time; /* 32b value may overflow during fixed point math */
+	u64 units = 128ULL, div = 100000ULL;
 
 	if (!intel_enable_rc6(dev))
 		return 0;
 
-	raw_time = I915_READ(reg) * 128ULL;
-	return DIV_ROUND_UP_ULL(raw_time, 100000);
+	/* On VLV, residency time is in CZ units rather than 1.28us */
+	if (IS_VALLEYVIEW(dev)) {
+		u32 clkctl2;
+
+		clkctl2 = I915_READ(VLV_CLK_CTL2) >>
+			CLK_CTL2_CZCOUNT_30NS_SHIFT;
+		if (!clkctl2) {
+			WARN(!clkctl2, "bogus CZ count value");
+			return 0;
+		}
+		units = DIV_ROUND_UP_ULL(3000ULL, (u64)clkctl2);
+		if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
+			units <<= 8;
+
+		div = 100000000;
+	}
+
+	raw_time = I915_READ(reg) * units;
+	return DIV_ROUND_UP_ULL(raw_time, div);
 }
 
 static ssize_t
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 2/2] drm/i915/vlv: use correct units for rc6 residency

Quoted 2 lines · Jesse Barnes

We need to use the clock control reg to figure out how many CZ clks are in 30ns and use that as the basis for our RC6 residency calculations.

Hmm, that was confusing. Took a couple of reads to be sure that the specs said that the units were always CZ clock cycles.

Quoted 26 lines

References: https://bugs.freedesktop.org/show_bug.cgi?id=69692

---
 drivers/gpu/drm/i915/i915_reg.h   |  3 +++
 drivers/gpu/drm/i915/i915_sysfs.c | 22 ++++++++++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +3 -0
index cf995bb..6f8d0cf 100644
@@ -1797,6 +1797,9 @@
  */
 #define HSW_CXT_TOTAL_SIZE		(17 * PAGE_SIZE)
 
+#define VLV_CLK_CTL2			0x101104
+#define   CLK_CTL2_CZCOUNT_30NS_SHIFT	28
+
 /*
  * Overlay regs
  */
drivers/gpu/drm/i915/i915_sysfs.c +0 -0
index 44f4c1a..9c60515 100644

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg) · line 40

Quoted 4 lines
drivers/gpu/drm/i915/i915_sysfs.c +1 -0
@@ -37,12 +37,30 @@ static u32 calc_residency(struct drm_device *dev, const u32 reg)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u64 raw_time; /* 32b value may overflow during fixed point math */
+	u64 units = 128ULL, div = 100 000ULL;

The ULL suffix here are superfluous and I notice that you didn't use the suffix for the later constants. Be consistent.

Normal units = 128 / (100 * 1000), i.e. each unit is 1.28/1000ms

Quoted 7 lines
drivers/gpu/drm/i915/i915_sysfs.c +1 -2
 	if (!intel_enable_rc6(dev))
 		return 0;
 
-	raw_time = I915_READ(reg) * 128ULL;
-	return DIV_ROUND_UP_ULL(raw_time, 100000);
+	/* On VLV, residency time is in CZ units rather than 1.28us */

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg) · line 55

Quoted 10 lines
drivers/gpu/drm/i915/i915_sysfs.c +10 -0
+	if (IS_VALLEYVIEW(dev)) {
+		u32 clkctl2;
+
+		clkctl2 = I915_READ(VLV_CLK_CTL2) >>
+			CLK_CTL2_CZCOUNT_30NS_SHIFT;
+		if (!clkctl2) {
+			WARN(!clkctl2, "bogus CZ count value");
+			return 0;
+		}
+		units = DIV_ROUND_UP_ULL(3000ULL, (u64)clkctl2);

For your divisor, this should 30*1000 not 3*1000.

Quoted 8 lines
drivers/gpu/drm/i915/i915_sysfs.c +8 -0
+		if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
+			units <<= 8;
+
+		div = 100 000 000;
+	}
+
+	raw_time = I915_READ(reg) * units;
+	return DIV_ROUND_UP_ULL(raw_time, div);
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#3 lore raw

Re: [PATCH 2/2] drm/i915/vlv: use correct units for rc6 residency

Quoted 41 lines · On Thu, 26 Sep 2013 23:25:46 +0100 Chris Wilson <[email protected]>…
Quoted 2 lines · Jesse Barnes

We need to use the clock control reg to figure out how many CZ clks are in 30ns and use that as the basis for our RC6 residency calculations.

Hmm, that was confusing. Took a couple of reads to be sure that the specs said that the units were always CZ clock cycles.

Quoted 26 lines

References: https://bugs.freedesktop.org/show_bug.cgi?id=69692

---
 drivers/gpu/drm/i915/i915_reg.h   |  3 +++
 drivers/gpu/drm/i915/i915_sysfs.c | 22 ++++++++++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +3 -0
index cf995bb..6f8d0cf 100644
@@ -1797,6 +1797,9 @@
  */
 #define HSW_CXT_TOTAL_SIZE		(17 * PAGE_SIZE)
 
+#define VLV_CLK_CTL2			0x101104
+#define   CLK_CTL2_CZCOUNT_30NS_SHIFT	28
+
 /*
  * Overlay regs
  */
drivers/gpu/drm/i915/i915_sysfs.c +0 -0
index 44f4c1a..9c60515 100644

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg) · line 40

Quoted 4 lines
drivers/gpu/drm/i915/i915_sysfs.c +1 -0
@@ -37,12 +37,30 @@ static u32 calc_residency(struct drm_device *dev, const u32 reg)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u64 raw_time; /* 32b value may overflow during fixed point math */
+	u64 units = 128ULL, div = 100 000ULL;

The ULL suffix here are superfluous and I notice that you didn't use the suffix for the later constants. Be consistent.

Quoted 1 line

Normal units = 128 / (100 * 1000), i.e. each unit is 1.28/1000ms

I can drop the ULL, sure.

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/i915/i915_sysfs.c +0 -0
 	if (!intel_enable_rc6(dev))
 		return 0;
 
Quoted 15 lines

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg) · line 55

Quoted 13 lines
drivers/gpu/drm/i915/i915_sysfs.c +11 -2
-	raw_time = I915_READ(reg) * 128ULL;
-	return DIV_ROUND_UP_ULL(raw_time, 100000);
+	/* On VLV, residency time is in CZ units rather than 1.28us */
+	if (IS_VALLEYVIEW(dev)) {
+		u32 clkctl2;
+
+		clkctl2 = I915_READ(VLV_CLK_CTL2) >>
+			CLK_CTL2_CZCOUNT_30NS_SHIFT;
+		if (!clkctl2) {
+			WARN(!clkctl2, "bogus CZ count value");
+			return 0;
+		}
+		units = DIV_ROUND_UP_ULL(3000ULL, (u64)clkctl2);

For your divisor, this should 30*1000 not 3*1000.

30ns * 100 for fixed point precision, just as above.

Quoted 5 lines

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg)

Quoted 5 lines
drivers/gpu/drm/i915/i915_sysfs.c +4 -0
+		if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
+			units <<= 8;
+
+		div = 100 000 000;

Then here we divide out the ns to ms (1000000) and also the 100 for fixed point.

Or do I still have it wrong?

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
#4 lore raw

Re: [PATCH 2/2] drm/i915/vlv: use correct units for rc6 residency

Quoted 34 lines · Jesse Barnes
Quoted 5 lines · On Thu, 26 Sep 2013 23:25:46 +0100 Chris Wilson <[email protected]>…
Quoted 5 lines
drivers/gpu/drm/i915/i915_sysfs.c +0 -0
 	if (!intel_enable_rc6(dev))
 		return 0;
Quoted 15 lines

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg) · line 55

Quoted 13 lines
drivers/gpu/drm/i915/i915_sysfs.c +11 -2
-	raw_time = I915_READ(reg) * 128ULL;
-	return DIV_ROUND_UP_ULL(raw_time, 100000);
+	/* On VLV, residency time is in CZ units rather than 1.28us */
+	if (IS_VALLEYVIEW(dev)) {
+		u32 clkctl2;
+
+		clkctl2 = I915_READ(VLV_CLK_CTL2) >>
+			CLK_CTL2_CZCOUNT_30NS_SHIFT;
+		if (!clkctl2) {
+			WARN(!clkctl2, "bogus CZ count value");
+			return 0;
+		}
+		units = DIV_ROUND_UP_ULL(3000ULL, (u64)clkctl2);

For your divisor, this should 30*1000 not 3*1000.

30ns * 100 for fixed point precision, just as above.

Quoted 5 lines

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg)

Quoted 5 lines
drivers/gpu/drm/i915/i915_sysfs.c +4 -0
+		if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
+			units <<= 8;
+
+		div = 100 000 000;

Then here we divide out the ns to ms (1000000) and also the 100 for fixed point.

Quoted 1 line

Or do I still have it wrong?

Just counting fail on my part, even after splitting it up to make it easier for myself.

How about

#define BIAS 100
units = 30*BIAS / cltctk2;
if (hi) units <<= 8;
div = NSEC_PER_MSEC * BIAS;

All because I have difficultly counting.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#5 lore raw

Re: [PATCH 2/2] drm/i915/vlv: use correct units for rc6 residency

Quoted 40 lines · On Fri, 27 Sep 2013 01:49:37 +0100 Chris Wilson <[email protected]>…
Quoted 34 lines · Jesse Barnes
Quoted 5 lines · On Thu, 26 Sep 2013 23:25:46 +0100 Chris Wilson <[email protected]>…
Quoted 5 lines
drivers/gpu/drm/i915/i915_sysfs.c +0 -0
 	if (!intel_enable_rc6(dev))
 		return 0;
Quoted 15 lines

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg) · line 55

Quoted 13 lines
drivers/gpu/drm/i915/i915_sysfs.c +11 -2
-	raw_time = I915_READ(reg) * 128ULL;
-	return DIV_ROUND_UP_ULL(raw_time, 100000);
+	/* On VLV, residency time is in CZ units rather than 1.28us */
+	if (IS_VALLEYVIEW(dev)) {
+		u32 clkctl2;
+
+		clkctl2 = I915_READ(VLV_CLK_CTL2) >>
+			CLK_CTL2_CZCOUNT_30NS_SHIFT;
+		if (!clkctl2) {
+			WARN(!clkctl2, "bogus CZ count value");
+			return 0;
+		}
+		units = DIV_ROUND_UP_ULL(3000ULL, (u64)clkctl2);

For your divisor, this should 30*1000 not 3*1000.

30ns * 100 for fixed point precision, just as above.

Quoted 5 lines

drivers/gpu/drm/i915/i915_sysfs.c static u32 calc_residency(struct drm_device *dev, const u32 reg)

Quoted 5 lines
drivers/gpu/drm/i915/i915_sysfs.c +4 -0
+		if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
+			units <<= 8;
+
+		div = 100 000 000;

Then here we divide out the ns to ms (1000000) and also the 100 for fixed point.

Quoted 1 line

Or do I still have it wrong?

Just counting fail on my part, even after splitting it up to make it easier for myself.

Quoted 8 lines

How about

#define BIAS 100
units = 30*BIAS / cltctk2;
if (hi) units <<= 8;
div = NSEC_PER_MSEC * BIAS;

All because I have difficultly counting.

Sure, will re-post.

Thanks,

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Reviewed-by on v1 1/2
#6 lore raw
In reply to Jesse Barnes
Quoted 31 lines · Jesse Barnes

And add some reg defines while we're at it. Since the units of the RC6 residency counter are actually in CZ clocks, we want to just use the high bits or we'll overflow too frequently.

---
 drivers/gpu/drm/i915/i915_reg.h | 4 ++++
 drivers/gpu/drm/i915/intel_pm.c | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_reg.h +4 -0
index 00fda45..cf995bb 100644
@@ -4721,6 +4721,10 @@
 						 GEN6_PM_RP_DOWN_TIMEOUT)
 
 #define GEN6_GT_GFX_RC6_LOCKED			0x138104
+#define VLV_COUNTER_CONTROL			0x138104
+#define   VLV_COUNT_RANGE_HIGH			(1<<15)
+#define   VLV_MEDIA_RC6_COUNT_EN		(1<<1)
+#define   VLV_RENDER_RC6_COUNT_EN		(1<<0)
 #define GEN6_GT_GFX_RC6				0x138108
 #define GEN6_GT_GFX_RC6p			0x13810C
 #define GEN6_GT_GFX_RC6pp			0x138110
drivers/gpu/drm/i915/intel_pm.c +0 -0
index d27eda6..d8bdc98 100644
@@ -3827,7 +3827,10 @@ static void valleyview_enable_rps(struct drm_device *dev)
 	I915_WRITE(GEN6_RC6_THRESHOLD, 0xc350);

drivers/gpu/drm/i915/intel_pm.c static void valleyview_enable_rps(struct drm_device *dev) · line 3836

Quoted 10 lines
drivers/gpu/drm/i915/intel_pm.c +4 -1
 
 	/* allows RC6 residency counter to work */
-	I915_WRITE(0x138104, _MASKED_BIT_ENABLE(0x3));
+	I915_WRITE(VLV_COUNTER_CONTROL,
+		   _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH |
+				      VLV_MEDIA_RC6_COUNT_EN |
+				      VLV_RENDER_RC6_COUNT_EN));
 	if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE)
 		rc6_mode = GEN7_RC_CTL_TO_MODE;
 	I915_WRITE(GEN6_RC_CONTROL, rc6_mode);

I wonder if the counters use power ie. only enable them when we are using rc6.

Otherwise, it's:

Signature · 1 line
Ben Widawsky, Intel Open Source Technology Center