Skip to contentSkip to conversation

drm/msm: Avoid rounding up to one jiffy

PATCH In review Rob Clark 2 participants 2 messages Jan 13, 2025 – Jan 15, 2025

Subsystems (3)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH v2 1/1 drm/msm: Avoid rounding up to one jiffy

From: Rob Clark <[email protected]>

If userspace is trying to achieve a timeout of zero, let 'em have it. Only round up if the timeout is greater than zero.

Fixes 4969bccd5f4e ("drm/msm: Avoid rounding down to zero jiffies")
---
 drivers/gpu/drm/msm/msm_drv.h | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +4 -7
index fee31680a6d5..a65077855201 100644
@@ -537,15 +537,12 @@ static inline int align_pitch(int width, int bpp)
 static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
 {
 	ktime_t now = ktime_get();
-	s64 remaining_jiffies;
 
-	if (ktime_compare(*timeout, now) < 0) {
-		remaining_jiffies = 0;
-	} else {
-		ktime_t rem = ktime_sub(*timeout, now);
-		remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
-	}
+	if (ktime_compare(*timeout, now) <= 0)
+		return 0;
 
+	ktime_t rem = ktime_sub(*timeout, now);
+	s64 remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
 	return clamp(remaining_jiffies, 1LL, (s64)INT_MAX);
 }
 
Signature · 1 line
2.47.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Rob Clark

From: Rob Clark <[email protected]>

If userspace is trying to achieve a timeout of zero, let 'em have it. Only round up if the timeout is greater than zero.

Fixes 4969bccd5f4e ("drm/msm: Avoid rounding down to zero jiffies")

-Akhil

Quoted 28 lines
---
 drivers/gpu/drm/msm/msm_drv.h | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +4 -7
index fee31680a6d5..a65077855201 100644
@@ -537,15 +537,12 @@ static inline int align_pitch(int width, int bpp)
 static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
 {
 	ktime_t now = ktime_get();
-	s64 remaining_jiffies;
 
-	if (ktime_compare(*timeout, now) < 0) {
-		remaining_jiffies = 0;
-	} else {
-		ktime_t rem = ktime_sub(*timeout, now);
-		remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
-	}
+	if (ktime_compare(*timeout, now) <= 0)
+		return 0;
 
+	ktime_t rem = ktime_sub(*timeout, now);
+	s64 remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
 	return clamp(remaining_jiffies, 1LL, (s64)INT_MAX);
 }