On Mon, Aug 03, 2020 at 07:16:46PM +1000, Jonathan Gray wrote:
> Scott mentioned that ktime should be using a runtime clock which stops
> during suspend.  The exception to this is ktime_get_bootime() which does
> not stop when suspended.
> 
> This is described in
> https://www.kernel.org/doc/html/latest/core-api/timekeeping.html
> 
> There was perhaps some confusion as CLOCK_MONOTONIC does not count
> time suspended on linux but does for us.

I'm concerned that this will create a clock mismatch in some of the
drivers.

My incomplete understanding of the situation is that parts of recent
graphics drivers are now implemented in userspace.  For instance, in
xenocara/lib I see that mesa and libdrm both use clock_gettime(2).
The code in question does not look like test code.

So, if userspace is using CLOCK_MONOTONIC and the kernel is using
nanoruntime(9), the clocks are no longer the same and their timestamps
are no longer comparable.  Then, if userspace is looking at kernel
timestamps, or vice versa, I would expect strange side effects.  You
probably wouldn't see them until after the first suspend/resume on a
given machine.

Is that possible?

If so, a full switch to the runtime clock would require corresponding
changes in userspace.  Probably switching to CLOCK_UPTIME in the right
spots.

> Index: include/linux/ktime.h
> ===================================================================
> RCS file: /cvs/src/sys/dev/pci/drm/include/linux/ktime.h,v
> retrieving revision 1.5
> diff -u -p -r1.5 ktime.h
> --- include/linux/ktime.h     29 Jul 2020 09:52:21 -0000      1.5
> +++ include/linux/ktime.h     3 Aug 2020 08:26:55 -0000
> @@ -28,7 +28,7 @@ static inline ktime_t
>  ktime_get(void)
>  {
>       struct timespec ts;
> -     nanouptime(&ts);
> +     nanoruntime(&ts);
>       return TIMESPEC_TO_NSEC(&ts);
>  }
>  
> @@ -36,7 +36,7 @@ static inline ktime_t
>  ktime_get_raw(void)
>  {
>       struct timespec ts;
> -     nanouptime(&ts);
> +     nanoruntime(&ts);
>       return TIMESPEC_TO_NSEC(&ts);
>  }
>  
> Index: include/linux/timekeeping.h
> ===================================================================
> RCS file: /cvs/src/sys/dev/pci/drm/include/linux/timekeeping.h,v
> retrieving revision 1.8
> diff -u -p -r1.8 timekeeping.h
> --- include/linux/timekeeping.h       29 Jul 2020 09:52:21 -0000      1.8
> +++ include/linux/timekeeping.h       3 Aug 2020 08:28:30 -0000
> @@ -3,7 +3,6 @@
>  #ifndef _LINUX_TIMEKEEPING_H
>  #define _LINUX_TIMEKEEPING_H
>  
> -#define ktime_get_boottime() ktime_get()
>  #define get_seconds()                gettime()
>  
>  static inline time_t
> @@ -24,6 +23,14 @@ static inline uint64_t
>  ktime_get_ns(void)
>  {
>       return ktime_get();
> +}
> +
> +static inline ktime_t
> +ktime_get_boottime(void)
> +{
> +     struct timespec ts;
> +     nanouptime(&ts);
> +     return TIMESPEC_TO_NSEC(&ts);
>  }
>  
>  #endif
> 

Reply via email to