[PATCH v12 41/69] drm_vblank: avoid bit-test when DRM_USE_DYNAMIC_DEBUG=y

Jim Cromie posted 69 patches 1 week ago
[PATCH v12 41/69] drm_vblank: avoid bit-test when DRM_USE_DYNAMIC_DEBUG=y
Posted by Jim Cromie 1 week ago
drm_crtc_vblank_helper_get_vblank_timestamp_internal() is called about
~100 times per sec, on a single display. It currently calls
drm_debug_enabled(DRM_UT_VBL) to avoid doing ktime_to_timespec64()
conversions when drm_dbg_vbl() is disabled.

When CONFIG_DRM_USE_DYNAMIC_DEBUG=Y, that bit-test is redundant,
because its also done by the static-key inside drm_dbg_vbl().

In this case, we can move the ktime conversions into the drm_dbg_vbl()
argument list (using a comma operator to evaluate the assignment, then
pass the address of its LHS).  Then the __dynamic_func_call() wrapping
the func guards the arg-list too, avoiding its evaluation when its not
being printed.

When CONFIG_DRM_USE_DYNAMIC_DEBUG=N, the bit-test is needed, because
the conversion in the arg-list is not guarded, and we'd do the
conversions even when the callsite is disabled.

We can optimize for both Y/N cases by changing
drm_debug_enabled(DRM_UT_VBL) to __drm_debug_enabled(DRM_UT_VBL).
This gives us the short-circuit when the static-key guard is there,
and the bit-test by drm_debug_enabled_raw() otherwise.

TLDR: we could change __drm_debug_enabled() to call _instrumented()
instead of _raw() for the =N case, but that should be accompanied by
some experiments and results.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
-v12-
restore (previously dropped) drm_debug_enabled, with __ alterations.
---
 drivers/gpu/drm/drm_vblank.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index f78bf37f1e0a..8ec025e12c67 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -803,15 +803,14 @@ drm_crtc_vblank_helper_get_vblank_timestamp_internal(
 	 */
 	*vblank_time = ktime_sub_ns(etime, delta_ns);
 
-	if (!drm_debug_enabled(DRM_UT_VBL))
+	if (!__drm_debug_enabled(DRM_UT_VBL))
 		return true;
 
-	ts_etime = ktime_to_timespec64(etime);
-	ts_vblank_time = ktime_to_timespec64(*vblank_time);
-
 	drm_dbg_vbl(dev,
 		    "crtc %u : v p(%d,%d)@ %ptSp -> %ptSp [e %d us, %d rep]\n",
-		    pipe, hpos, vpos, &ts_etime, &ts_vblank_time,
+		    pipe, hpos, vpos,
+		    (ts_etime = ktime_to_timespec64(etime), &ts_etime),
+		    (ts_vblank_time = ktime_to_timespec64(*vblank_time), &ts_vblank_time),
 		    duration_ns / 1000, i);
 
 	return true;
-- 
2.53.0