> Date: Tue, 21 Jul 2020 19:33:21 +1000
> From: Jonathan Gray <[email protected]>
> 
> Change from using timevals for ktime to 64 bit count of nanoseconds
> to closer match linux.  From a discussion with cheloha@

ok kettenis@

> Index: sys/dev/pci/drm/drm_vblank.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/pci/drm/drm_vblank.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 drm_vblank.c
> --- sys/dev/pci/drm/drm_vblank.c      8 Jun 2020 04:47:58 -0000       1.5
> +++ sys/dev/pci/drm/drm_vblank.c      21 Jul 2020 07:00:48 -0000
> @@ -184,7 +184,7 @@ static void drm_reset_vblank_timestamp(s
>        * interrupt and assign 0 for now, to mark the vblanktimestamp as 
> invalid.
>        */
>       if (!rc)
> -             t_vblank = (struct timeval) {0, 0};
> +             t_vblank = 0;
>  
>       /*
>        * +1 to make sure user will never see the same
> @@ -293,7 +293,7 @@ static void drm_update_vblank_count(stru
>        * for now, to mark the vblanktimestamp as invalid.
>        */
>       if (!rc && !in_vblank_irq)
> -             t_vblank = (struct timeval) {0, 0};
> +             t_vblank = 0;
>  
>       store_vblank(dev, pipe, diff, t_vblank, cur_vblank);
>  }
> @@ -871,7 +871,7 @@ static u64 drm_vblank_count_and_time(str
>       unsigned int seq;
>  
>       if (WARN_ON(pipe >= dev->num_crtcs)) {
> -             *vblanktime = (struct timeval) {0, 0};
> +             *vblanktime = 0;
>               return 0;
>       }
>  
> Index: sys/dev/pci/drm/include/linux/ktime.h
> ===================================================================
> RCS file: /cvs/src/sys/dev/pci/drm/include/linux/ktime.h,v
> retrieving revision 1.4
> diff -u -p -r1.4 ktime.h
> --- sys/dev/pci/drm/include/linux/ktime.h     7 Jul 2020 04:05:25 -0000       
> 1.4
> +++ sys/dev/pci/drm/include/linux/ktime.h     21 Jul 2020 07:00:48 -0000
> @@ -22,42 +22,40 @@
>  #include <linux/time.h>
>  #include <linux/jiffies.h>
>  
> -typedef struct timeval ktime_t;
> +typedef int64_t ktime_t;
>  
> -static inline struct timeval
> +static inline ktime_t
>  ktime_get(void)
>  {
> -     struct timeval tv;
> -     
> -     microuptime(&tv);
> -     return tv;
> +     struct timespec ts;
> +     nanouptime(&ts);
> +     return TIMESPEC_TO_NSEC(&ts);
>  }
>  
> -static inline struct timeval
> +static inline ktime_t
>  ktime_get_raw(void)
>  {
> -     struct timeval tv;
> -     
> -     microuptime(&tv);
> -     return tv;
> +     struct timespec ts;
> +     nanouptime(&ts);
> +     return TIMESPEC_TO_NSEC(&ts);
>  }
>  
>  static inline int64_t
> -ktime_to_ms(struct timeval tv)
> +ktime_to_ms(ktime_t k)
>  {
> -     return timeval_to_ms(&tv);
> +     return k / NSEC_PER_MSEC;
>  }
>  
>  static inline int64_t
> -ktime_to_us(struct timeval tv)
> +ktime_to_us(ktime_t k)
>  {
> -     return timeval_to_us(&tv);
> +     return k / NSEC_PER_USEC;
>  }
>  
>  static inline int64_t
> -ktime_to_ns(struct timeval tv)
> +ktime_to_ns(ktime_t k)
>  {
> -     return timeval_to_ns(&tv);
> +     return k;
>  }
>  
>  static inline int64_t
> @@ -67,70 +65,66 @@ ktime_get_raw_ns(void)
>  }
>  
>  static inline struct timespec64
> -ktime_to_timespec64(struct timeval tv)
> +ktime_to_timespec64(ktime_t k)
>  {
>       struct timespec64 ts;
> -     ts.tv_sec = tv.tv_sec;
> -     ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC;
> +     ts.tv_sec = k / NSEC_PER_SEC;
> +     ts.tv_nsec = k % NSEC_PER_SEC;
>       return ts;
>  }
>  
> -static inline struct timeval
> -ktime_sub(struct timeval a, struct timeval b)
> +static inline ktime_t
> +ktime_sub(ktime_t a, ktime_t b)
>  {
> -     struct timeval res;
> -     timersub(&a, &b, &res);
> -     return res;
> +     return a - b;
>  }
>  
> -static inline struct timeval
> -ktime_add(struct timeval a, struct timeval b)
> +static inline ktime_t
> +ktime_add(ktime_t a, ktime_t b)
>  {
> -     struct timeval res;
> -     timeradd(&a, &b, &res);
> -     return res;
> +     return a + b;
>  }
>  
> -static inline struct timeval
> -ktime_add_us(struct timeval tv, int64_t us)
> +static inline ktime_t
> +ktime_add_us(ktime_t k, uint64_t us)
>  {
> -     return ns_to_timeval(timeval_to_ns(&tv) + (us * NSEC_PER_USEC));
> +     return k + (us * NSEC_PER_USEC);
>  }
>  
> -static inline struct timeval
> -ktime_add_ns(struct timeval tv, int64_t ns)
> +static inline ktime_t
> +ktime_add_ns(ktime_t k, int64_t ns)
>  {
> -     return ns_to_timeval(timeval_to_ns(&tv) + ns);
> +     return k + ns;
>  }
>  
> -static inline struct timeval
> -ktime_sub_ns(struct timeval tv, int64_t ns)
> +static inline ktime_t
> +ktime_sub_ns(ktime_t k, int64_t ns)
>  {
> -     return ns_to_timeval(timeval_to_ns(&tv) - ns);
> +     return k - ns;
>  }
>  
>  static inline int64_t
> -ktime_us_delta(struct timeval a, struct timeval b)
> +ktime_us_delta(ktime_t a, ktime_t b)
>  {
>       return ktime_to_us(ktime_sub(a, b));
>  }
>  
>  static inline int64_t
> -ktime_ms_delta(struct timeval a, struct timeval b)
> +ktime_ms_delta(ktime_t a, ktime_t b)
>  {
>       return ktime_to_ms(ktime_sub(a, b));
>  }
>  
>  static inline bool
> -ktime_after(const struct timeval a, const struct timeval b)
> +ktime_after(ktime_t a, ktime_t b)
>  {
> -     return timercmp(&a, &b, >);
> +     return a > b;
>  }
>  
> -static inline struct timeval
> +static inline ktime_t
>  ns_to_ktime(uint64_t ns)
>  {
> -     return ns_to_timeval(ns);
> +     return ns;
>  }
>  
>  #include <linux/timekeeping.h>
> Index: sys/dev/pci/drm/include/linux/timekeeping.h
> ===================================================================
> RCS file: /cvs/src/sys/dev/pci/drm/include/linux/timekeeping.h,v
> retrieving revision 1.7
> diff -u -p -r1.7 timekeeping.h
> --- sys/dev/pci/drm/include/linux/timekeeping.h       7 Jul 2020 04:05:25 
> -0000       1.7
> +++ sys/dev/pci/drm/include/linux/timekeeping.h       21 Jul 2020 07:00:48 
> -0000
> @@ -12,19 +12,18 @@ ktime_get_real_seconds(void)
>       return gettime();
>  }
>  
> -static inline struct timeval
> +static inline ktime_t
>  ktime_get_real(void)
>  {
> -     struct timeval tv;
> -     microtime(&tv);
> -     return tv;
> +     struct timespec ts;
> +     nanotime(&ts);
> +     return TIMESPEC_TO_NSEC(&ts);
>  }
>  
>  static inline uint64_t
>  ktime_get_ns(void)
>  {
> -     struct timeval tv = ktime_get();
> -     return timeval_to_ns(&tv);
> +     return ktime_get();
>  }
>  
>  #endif
> 
> 

Reply via email to