etnaviv: drm: Normalize nano seconds
authorGuido Günther <agx@sigxcpu.org>
Thu, 23 Jan 2020 08:20:00 +0000 (09:20 +0100)
committerMarge Bot <eric+marge@anholt.net>
Sun, 10 May 2020 07:32:12 +0000 (07:32 +0000)
Make sure the nano second part is less than one second. This matches
what clock_settime expects and allows for more concise kernel
interfaces.

Signed-off-by: Guido Günther <guido.gunther@puri.sm>
Reviewed-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3534>

src/etnaviv/drm/etnaviv_priv.h

index 93bd2d90985e1746eb5f744c4cb400f414b78477..054e6cc730e72fcece57da77abf72cbd41164fea 100644 (file)
@@ -208,6 +208,10 @@ static inline void get_abs_timeout(struct drm_etnaviv_timespec *tv, uint64_t ns)
        clock_gettime(CLOCK_MONOTONIC, &t);
        tv->tv_sec = t.tv_sec + ns / NSEC_PER_SEC;
        tv->tv_nsec = t.tv_nsec + ns % NSEC_PER_SEC;
        clock_gettime(CLOCK_MONOTONIC, &t);
        tv->tv_sec = t.tv_sec + ns / NSEC_PER_SEC;
        tv->tv_nsec = t.tv_nsec + ns % NSEC_PER_SEC;
+       if (tv->tv_nsec >= NSEC_PER_SEC) {
+               tv->tv_nsec -= NSEC_PER_SEC;
+               tv->tv_sec++;
+       }
 }
 
 #if HAVE_VALGRIND
 }
 
 #if HAVE_VALGRIND