Skip to contentSkip to conversation

drm/msm: Avoid rounding down to zero jiffies

PATCH Applied Rob Clark 2 participants 4 messages Mar 24, 2023 – Mar 28, 2023

Subsystems (3)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

PATCH 1/1 drm/msm: Avoid rounding down to zero jiffies

From: Rob Clark <[email protected]>

If userspace asked for a timeout greater than zero, but less than a jiffy, they clearly weren't planning on spinning. So it is better to round up to one.

This fixes an issue with supertuxkart that was (for some reason) spinning on a gl sync with 1ms timeout. CPU time for a demo lap drops from:

15.83user 20.98system 0:47.46elapsed 77%CPU

to:

8.84user 2.30system 0:46.67elapsed 23%CPU

---
 drivers/gpu/drm/msm/msm_drv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_drv.h +1 -1
index 9f0c184b02a0..7936aa6cad03 100644
@@ -548,7 +548,7 @@ static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
 		remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
 	}
 
-	return clamp(remaining_jiffies, 0LL, (s64)INT_MAX);
+	return clamp(remaining_jiffies, 1LL, (s64)INT_MAX);
 }
 
 /* Driver helpers */
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Rob Clark

From: Rob Clark <[email protected]>

If userspace asked for a timeout greater than zero, but less than a jiffy, they clearly weren't planning on spinning. So it is better to round up to one.

This fixes an issue with supertuxkart that was (for some reason) spinning on a gl sync with 1ms timeout. CPU time for a demo lap drops from:

Quoted 5 lines
   15.83user 20.98system 0:47.46elapsed 77%CPU

to:

   8.84user 2.30system 0:46.67elapsed 23%CPU

Interesting. We potentially increased the timeout, but the overall (elapsed) time has decreased. Nevertheless:

Quoted 19 lines
---
  drivers/gpu/drm/msm/msm_drv.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_drv.h +1 -1
index 9f0c184b02a0..7936aa6cad03 100644
@@ -548,7 +548,7 @@ static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
  		remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
  	}
 
-	return clamp(remaining_jiffies, 0LL, (s64)INT_MAX);
+	return clamp(remaining_jiffies, 1LL, (s64)INT_MAX);
  }
 
  /* Driver helpers */
Signature · 2 lines
With best wishes
Dmitry
author
#2 lore raw
Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Rob Clark

From: Rob Clark <[email protected]>

If userspace asked for a timeout greater than zero, but less than a jiffy, they clearly weren't planning on spinning. So it is better to round up to one.

This fixes an issue with supertuxkart that was (for some reason) spinning on a gl sync with 1ms timeout. CPU time for a demo lap drops from:

Quoted 8 lines
Quoted 5 lines
   15.83user 20.98system 0:47.46elapsed 77%CPU

to:

   8.84user 2.30system 0:46.67elapsed 23%CPU

Interesting. We potentially increased the timeout, but the overall (elapsed) time has decreased. Nevertheless:

There is some randomness from run to run so small variations in total --profile-laps=N time are normal. So I wouldn't read too much into that, compared to %CPU. This shouldn't really change how long it takes for the fence to signal, as much as just prevent the CPU from busy looping until the fence does signal ;-)

(In theory the CPU busy looping could cause GPU thermal throttling, but I don't think that was happening in this case.)

Quoted 1 line

thx

Quoted 24 lines
Quoted 11 lines
---
  drivers/gpu/drm/msm/msm_drv.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_drv.h +0 -0
index 9f0c184b02a0..7936aa6cad03 100644

drivers/gpu/drm/msm/msm_drv.h static inline unsigned long timeout_to_jiffies(const ktime_t *timeout) · line 554

Quoted 8 lines
drivers/gpu/drm/msm/msm_drv.h +1 -1
@@ -548,7 +548,7 @@ static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
              remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
      }
 
-     return clamp(remaining_jiffies, 0LL, (s64)INT_MAX);
+     return clamp(remaining_jiffies, 1LL, (s64)INT_MAX);
  }
 
  /* Driver helpers */

--
With best wishes
Dmitry

#3 lore raw
In reply to Rob Clark
Quoted 9 lines · Rob Clark

If userspace asked for a timeout greater than zero, but less than a jiffy, they clearly weren't planning on spinning. So it is better to round up to one.

This fixes an issue with supertuxkart that was (for some reason) spinning on a gl sync with 1ms timeout. CPU time for a demo lap drops from:

[...]

Applied, thanks!

[1/1] drm/msm: Avoid rounding down to zero jiffies

      https://gitlab.freedesktop.org/lumag/msm/-/commit/a5c5593477b0

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>