Skip to contentSkip to conversation

drm/msm: avoid using 'timespec'

PATCH In review Arnd Bergmann 2 participants 4 messages Jun 18, 2018 – Jul 11, 2018

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

PATCH 1/1 drm/msm: avoid using 'timespec'

The timespec structure and associated interfaces are deprecated and will be removed in the future because of the y2038 overflow.

The use of ktime_to_timespec() in timeout_to_jiffies() does not suffer from that overflow, but is easy to avoid by just converting the ktime_t into jiffies directly.

---
 drivers/gpu/drm/msm/msm_drv.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +1 -2
index b2da1fbf81e0..cc8977476a41 100644
@@ -353,8 +353,7 @@ static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
 		remaining_jiffies = 0;
 	} else {
 		ktime_t rem = ktime_sub(*timeout, now);
-		struct timespec ts = ktime_to_timespec(rem);
-		remaining_jiffies = timespec_to_jiffies(&ts);
+		remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);
 	}
 
 	return remaining_jiffies;
Signature · 6 lines
2.9.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 17 lines · Arnd Bergmann

The timespec structure and associated interfaces are deprecated and will be removed in the future because of the y2038 overflow.

The use of ktime_to_timespec() in timeout_to_jiffies() does not suffer from that overflow, but is easy to avoid by just converting the ktime_t into jiffies directly.

---
 drivers/gpu/drm/msm/msm_drv.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_drv.h +0 -0
index b2da1fbf81e0..cc8977476a41 100644

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

Quoted 6 lines
drivers/gpu/drm/msm/msm_drv.h +1 -2
@@ -353,8 +353,7 @@ static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
 		remaining_jiffies = 0;
 	} else {
 		ktime_t rem = ktime_sub(*timeout, now);
-		struct timespec ts = ktime_to_timespec(rem);
-		remaining_jiffies = timespec_to_jiffies(&ts);
+		remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);

Do you need to wrap rem in ktime_to_ns() just to be safe?

Sean

Quoted 6 lines
drivers/gpu/drm/msm/msm_drv.h +0 -0
 	}
 
 	return remaining_jiffies;
Signature · 1 line
2.9.0
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
#2 lore raw
Quoted 13 lines · Sean Paul
Quoted 12 lines · Arnd Bergmann

The timespec structure and associated interfaces are deprecated and will be removed in the future because of the y2038 overflow.

The use of ktime_to_timespec() in timeout_to_jiffies() does not suffer from that overflow, but is easy to avoid by just converting the ktime_t into jiffies directly.

---
 drivers/gpu/drm/msm/msm_drv.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 13 lines

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

Quoted 11 lines
drivers/gpu/drm/msm/msm_drv.h +1 -2
index b2da1fbf81e0..cc8977476a41 100644
@@ -353,8 +353,7 @@ static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
              remaining_jiffies = 0;
      } else {
              ktime_t rem = ktime_sub(*timeout, now);
-             struct timespec ts = ktime_to_timespec(rem);
-             remaining_jiffies = timespec_to_jiffies(&ts);
+             remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);

Do you need to wrap rem in ktime_to_ns() just to be safe?

The ktime_t interfaces are still defined to use an opaque type, as previously it was a union that could be a seconds/nanoseconds pair depending on the architecture. These days, ktime_t is just a 64-bit integer, so div_u64() would work just as well as ktime_divns(), but this is the documented way to do it.

Arnd

Reviewed-by
#3 lore raw
Quoted 28 lines · Arnd Bergmann
Quoted 13 lines · Sean Paul
Quoted 12 lines · Arnd Bergmann

The timespec structure and associated interfaces are deprecated and will be removed in the future because of the y2038 overflow.

The use of ktime_to_timespec() in timeout_to_jiffies() does not suffer from that overflow, but is easy to avoid by just converting the ktime_t into jiffies directly.

---
 drivers/gpu/drm/msm/msm_drv.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 13 lines

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

Quoted 11 lines
drivers/gpu/drm/msm/msm_drv.h +1 -2
index b2da1fbf81e0..cc8977476a41 100644
@@ -353,8 +353,7 @@ static inline unsigned long timeout_to_jiffies(const ktime_t *timeout)
              remaining_jiffies = 0;
      } else {
              ktime_t rem = ktime_sub(*timeout, now);
-             struct timespec ts = ktime_to_timespec(rem);
-             remaining_jiffies = timespec_to_jiffies(&ts);
+             remaining_jiffies = ktime_divns(rem, NSEC_PER_SEC / HZ);

Do you need to wrap rem in ktime_to_ns() just to be safe?

Quoted 5 lines

The ktime_t interfaces are still defined to use an opaque type, as previously it was a union that could be a seconds/nanoseconds pair depending on the architecture. These days, ktime_t is just a 64-bit integer, so div_u64() would work just as well as ktime_divns(), but this is the documented way to do it.

Hey Arnd,
Ahh, ok, I think I realize my confusion now. If ktime_t was not ns, ktime_divns() would do the conversion for us. Since it is ns, the conversion is a no-op (which is why I didn't see ktime_to_ns() in ktime_divns()).

Thanks for breaking that down for me,

Quoted 2 lines

Arnd

Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS