Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 3/7] drm/i915: Extend vlv/chv residency resolution
Date: Tue, 14 Mar 2017 15:17:25 +0200	[thread overview]
Message-ID: <1489497449-31640-3-git-send-email-mika.kuoppala@intel.com> (raw)
In-Reply-To: <1489497449-31640-1-git-send-email-mika.kuoppala@intel.com>

The high counter value bit can be used to get 8 bits more
of range out of the same residency counter registers.

Lets toggle this bit on and off on vlv/chv while reading the
counters to push the wrap from 13 seconds to 54 minutes.

Reported-by: Len Brown <len.brown@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>
---
 drivers/gpu/drm/i915/intel_pm.c | 47 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index da742a9..7e7a8d9 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -8350,6 +8350,44 @@ void intel_pm_setup(struct drm_i915_private *dev_priv)
 	atomic_set(&dev_priv->pm.wakeref_count, 0);
 }
 
+static u64 vlv_residency_raw(struct drm_i915_private *dev_priv,
+			     const i915_reg_t reg)
+{
+	u32 lower, upper, tmp, saved_ctl;
+
+	/* The register accessed do not need forcewake. We borrow
+	 * uncore lock to prevent concurrent access to range reg.
+	 */
+	spin_lock_irq(&dev_priv->uncore.lock);
+	saved_ctl = I915_READ_FW(VLV_COUNTER_CONTROL);
+
+	if (!(saved_ctl & VLV_COUNT_RANGE_HIGH))
+		I915_WRITE_FW(VLV_COUNTER_CONTROL,
+			      _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH));
+
+	tmp = I915_READ_FW(reg);
+	do {
+		upper = tmp;
+
+		I915_WRITE_FW(VLV_COUNTER_CONTROL,
+			      _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH));
+		lower = I915_READ_FW(reg);
+
+		I915_WRITE_FW(VLV_COUNTER_CONTROL,
+			      _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH));
+
+		tmp = I915_READ_FW(reg);
+	} while (upper != tmp);
+
+	if (!(saved_ctl & VLV_COUNT_RANGE_HIGH))
+		I915_WRITE_FW(VLV_COUNTER_CONTROL,
+			      _MASKED_BIT_DISABLE(VLV_COUNT_RANGE_HIGH));
+
+	spin_unlock_irq(&dev_priv->uncore.lock);
+
+	return lower | (u64)upper << 8;
+}
+
 u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv,
 			   const i915_reg_t reg)
 {
@@ -8367,15 +8405,16 @@ u64 intel_rc6_residency_us(struct drm_i915_private *dev_priv,
 		units = 1000;
 		div = dev_priv->czclk_freq;
 
-		if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
-			units <<= 8;
+		raw_time = vlv_residency_raw(dev_priv, reg);
+		goto out;
 	} else if (IS_GEN9_LP(dev_priv)) {
 		units = 1000;
 		div = 1200;		/* 833.33ns */
 	}
 
-	raw_time = I915_READ(reg) * units;
-	ret = DIV_ROUND_UP_ULL(raw_time, div);
+	raw_time = I915_READ(reg);
+out:
+	ret = DIV_ROUND_UP_ULL(raw_time * units, div);
 
 	intel_runtime_pm_put(dev_priv);
 	return ret;
-- 
2.7.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2017-03-14 13:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-14 13:17 [PATCH 1/7] drm/i915: Move residency calculation into intel_pm.c Mika Kuoppala
2017-03-14 13:17 ` [PATCH 2/7] drm/i915: Return residency as microseconds Mika Kuoppala
2017-03-14 14:18   ` Chris Wilson
2017-03-14 13:17 ` Mika Kuoppala [this message]
2017-03-14 14:16   ` [PATCH 3/7] drm/i915: Extend vlv/chv residency resolution Chris Wilson
2017-03-14 13:17 ` [PATCH 4/7] drm/i915: Convert debugfs to use generic residency calculator Mika Kuoppala
2017-03-14 14:19   ` Chris Wilson
2017-03-14 13:17 ` [PATCH 5/7] drm/i915: Use cpu clock to calculate rc0 residency Mika Kuoppala
2017-03-14 13:30   ` Chris Wilson
2017-03-14 13:48     ` Ville Syrjälä
2017-03-14 13:17 ` [PATCH 6/7] drm/i915: Use coarse grained residency counter with byt Mika Kuoppala
2017-03-14 13:17 ` [PATCH 7/7] drm/i915: Upclock on the first residency calculation Mika Kuoppala
2017-03-14 13:34   ` Chris Wilson
2017-03-14 13:36     ` Mika Kuoppala
2017-03-14 18:46 ` ✗ Fi.CI.BAT: warning for series starting with [1/7] drm/i915: Move residency calculation into intel_pm.c Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489497449-31640-3-git-send-email-mika.kuoppala@intel.com \
    --to=mika.kuoppala@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox