Skip to contentSkip to conversation

drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK

PATCH In review Uma Shankar 3 participants 3 messages Nov 26

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

PATCH 1/1 drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK

The horizontal scaler filter works at 2 PPC, but still needs a full clock for a fractional shift of just one pixel. It doesn't shift by two pixels and re-align the taps, so the extra clock doesn't average out.

Bspec now documents the downscale amount used for the min CDCLK calculation as:

hscale_ppc = int(hscale) + min(1, ppc * frac(hscale)) downscale = max(hscale_ppc, hscale * vscale)

Compared to the empirical formula we have now, the fractional penalty is capped at one extra clock, and since the scaler filters vertically first the penalty does not multiply with the vertical downscale factor. Update the code to match.

Platforms without 2 PPC (ppc == 1) are unaffected as the formula then reduces to hscale * vscale.

Bspec: 68858

Fixes f69946f6d891 ("drm/i915/cdclk: Deal with 2 PPC hscale issues when calculating min CDCLK")
---
 drivers/gpu/drm/i915/display/intel_plane.c | 42 ++++++++++++++--------
 1 file changed, 27 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/display/intel_plane.c +27 -15
index d23de0f34e4b..4a430d6a0ba9 100644
@@ -266,25 +266,28 @@ unsigned int intel_adjusted_rate(const struct drm_rect *src,
 }
 
 static unsigned int hscale_cdclk(const struct drm_rect *src,
-				 const struct drm_rect *dst,
-				 unsigned int ppc)
+				 const struct drm_rect *dst)
 {
 	unsigned int hscale;
 
 	hscale = drm_rect_calc_hscale(src, dst, 0, INT_MAX);
 	hscale = max(hscale, 0x10000);
 
-	/*
-	 * Double the fractional part due to some 2 PPC granularity issue
-	 *
-	 * FIXME: BSpec calls for doubling only the <0.5 fractional part,
-	 * and rounding it down to a unit fraction. In practice that is
-	 * not sufficient, and we need a more aggressive CDCLK bump in
-	 * many cases. The updated formula was derived empirically.
-	 * This may need to be updated once we have better undestading
-	 * of what's happening in the hardware...
-	 */
-	return (hscale & ~0xffff) + ppc * (hscale & 0xffff);
+	return hscale;
+}
+
+/*
+ * Bspec: 68858
+ *
+ * The horizontal filter works at 2 PPC but still needs a full clock
+ * for a fractional shift of just 1 pixel, so the fractional part of
+ * the horizontal downscale factor costs PPC times more, but at most
+ * one full extra clock.
+ */
+static unsigned int hscale_ppc_cdclk(unsigned int hscale,
+				     unsigned int ppc)
+{
+	return (hscale & ~0xffff) + min(ppc * (hscale & 0xffff), 0x10000);
 }
 
 static unsigned int vscale_cdclk(const struct drm_rect *src,
@@ -303,10 +306,19 @@ unsigned int intel_adjusted_rate_cdclk(const struct drm_rect *src,
 				       unsigned int rate,
 				       unsigned int ppc)
 {
-	unsigned int hscale = hscale_cdclk(src, dst, ppc);
+	unsigned int hscale = hscale_cdclk(src, dst);
 	unsigned int vscale = vscale_cdclk(src, dst);
+	u64 scale;
+
+	/*
+	 * The scaler filters vertically first, so the horizontal
+	 * PPC inefficiency doesn't multiply with the vertical
+	 * downscale factor. .32 fixed point.
+	 */
+	scale = max((u64)hscale_ppc_cdclk(hscale, ppc) << 16,
+		    mul_u32_u32(hscale, vscale));
 
-	return DIV64_U64_ROUND_UP((u64)rate * hscale * vscale, 1ull << 32);
+	return DIV64_U64_ROUND_UP(rate * scale, 1ull << 32);
 }
 
 unsigned int intel_plane_pixel_rate(const struct intel_crtc_state *crtc_state,
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Uma Shankar

The horizontal scaler filter works at 2 PPC, but still needs a full clock for a fractional shift of just one pixel. It doesn't shift by two pixels and re-align the taps, so the extra clock doesn't average out.

Bspec now documents the downscale amount used for the min CDCLK calculation as:

hscale_ppc = int(hscale) + min(1, ppc * frac(hscale)) downscale = max(hscale_ppc, hscale * vscale)

Compared to the empirical formula we have now, the fractional penalty is capped at one extra clock, and since the scaler filters vertically first the penalty does not multiply with the vertical downscale factor. Update the code to match.

Quoted 7 lines

Platforms without 2 PPC (ppc == 1) are unaffected as the formula then reduces to hscale * vscale.

Bspec: 68858

Fixes f69946f6d891 ("drm/i915/cdclk: Deal with 2 PPC hscale issues when calculating min CDCLK")

Looks good.

Quoted 74 lines
---
 drivers/gpu/drm/i915/display/intel_plane.c | 42 ++++++++++++++--------
 1 file changed, 27 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/display/intel_plane.c +27 -15
index d23de0f34e4b..4a430d6a0ba9 100644
@@ -266,25 +266,28 @@ unsigned int intel_adjusted_rate(const struct drm_rect *src,
 }
 
 static unsigned int hscale_cdclk(const struct drm_rect *src,
-				 const struct drm_rect *dst,
-				 unsigned int ppc)
+				 const struct drm_rect *dst)
 {
 	unsigned int hscale;
 
 	hscale = drm_rect_calc_hscale(src, dst, 0, INT_MAX);
 	hscale = max(hscale, 0x10000);
 
-	/*
-	 * Double the fractional part due to some 2 PPC granularity issue
-	 *
-	 * FIXME: BSpec calls for doubling only the <0.5 fractional part,
-	 * and rounding it down to a unit fraction. In practice that is
-	 * not sufficient, and we need a more aggressive CDCLK bump in
-	 * many cases. The updated formula was derived empirically.
-	 * This may need to be updated once we have better undestading
-	 * of what's happening in the hardware...
-	 */
-	return (hscale & ~0xffff) + ppc * (hscale & 0xffff);
+	return hscale;
+}
+
+/*
+ * Bspec: 68858
+ *
+ * The horizontal filter works at 2 PPC but still needs a full clock
+ * for a fractional shift of just 1 pixel, so the fractional part of
+ * the horizontal downscale factor costs PPC times more, but at most
+ * one full extra clock.
+ */
+static unsigned int hscale_ppc_cdclk(unsigned int hscale,
+				     unsigned int ppc)
+{
+	return (hscale & ~0xffff) + min(ppc * (hscale & 0xffff), 0x10000);
 }
 
 static unsigned int vscale_cdclk(const struct drm_rect *src,
@@ -303,10 +306,19 @@ unsigned int intel_adjusted_rate_cdclk(const struct drm_rect *src,
 				       unsigned int rate,
 				       unsigned int ppc)
 {
-	unsigned int hscale = hscale_cdclk(src, dst, ppc);
+	unsigned int hscale = hscale_cdclk(src, dst);
 	unsigned int vscale = vscale_cdclk(src, dst);
+	u64 scale;
+
+	/*
+	 * The scaler filters vertically first, so the horizontal
+	 * PPC inefficiency doesn't multiply with the vertical
+	 * downscale factor. .32 fixed point.
+	 */
+	scale = max((u64)hscale_ppc_cdclk(hscale, ppc) << 16,
+		    mul_u32_u32(hscale, vscale));
 
-	return DIV64_U64_ROUND_UP((u64)rate * hscale * vscale, 1ull << 32);
+	return DIV64_U64_ROUND_UP(rate * scale, 1ull << 32);
 }
 
 unsigned int intel_plane_pixel_rate(const struct intel_crtc_state *crtc_state,
Signature · 1 line
2.50.1
Signature · 2 lines
Ville Syrjälä
Intel
#2 lore raw

✓ i915.CI.BAT: success for drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK

In reply to Uma Shankar
== Series Details ==

== Series Details ==

Series: drm/i915/cdclk: Fix 2 PPC hscale adjustment for min CDCLK
URL : https://patchwork.freedesktop.org/series/179792/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_19618 -> Patchwork_179792v1
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179792v1/index.html

Participating hosts (40 -> 39)
------------------------------

Missing (1): bat-dg2-13

Known issues
------------

Here are the changes found in Patchwork_179792v1 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live:
- fi-bsw-n3050: [PASS][1] -> [ABORT][2] ([i915#17765] / [i915#17881]) +1 other test abort
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_19618/fi-bsw-n3050/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179792v1/fi-bsw-n3050/igt@[email protected]

[i915#17765]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17765
[i915#17881]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17881

Build changes
-------------

* Linux: CI_DRM_19618 -> Patchwork_179792v1

CI-20190529: 20190529
CI_DRM_19618: 436eec0ef1b65f139fa2f3c42aea97c29da57c8c @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_9204: 52e9317c945f97f29fbec75be29280fc7b00cf32 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_179792v1: 436eec0ef1b65f139fa2f3c42aea97c29da57c8c @ git://anongit.freedesktop.org/gfx-ci/linux

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179792v1/index.html