Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/include/linux New ktime utilities. Fi...



details:   https://anonhg.NetBSD.org/src/rev/a4355252709d
branches:  trunk
changeset: 992567:a4355252709d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 07:03:11 2018 +0000

description:
New ktime utilities.  Fix monotonic offset business.

diffstat:

 sys/external/bsd/drm2/include/linux/ktime.h |  36 ++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 3 deletions(-)

diffs (64 lines):

diff -r 1342ca455132 -r a4355252709d sys/external/bsd/drm2/include/linux/ktime.h
--- a/sys/external/bsd/drm2/include/linux/ktime.h       Mon Aug 27 07:03:02 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/ktime.h       Mon Aug 27 07:03:11 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ktime.h,v 1.3 2014/07/16 20:56:25 riastradh Exp $      */
+/*     $NetBSD: ktime.h,v 1.4 2018/08/27 07:03:11 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -100,12 +100,17 @@
 }
 
 static inline ktime_t
+timespec_to_ktime(struct timespec ts)
+{
+       return ns_to_ktime(1000000000*ts.tv_sec + ts.tv_nsec);
+}
+
+static inline ktime_t
 ktime_get(void)
 {
        struct timespec ts;
        ktime_t kt;
 
-       /* XXX nanotime or nanouptime?  */
        nanouptime(&ts);
 
        /* XXX Silently truncate?  */
@@ -116,9 +121,34 @@
 }
 
 static inline ktime_t
+ktime_get_real(void)
+{
+       struct timespec ts;
+       ktime_t kt;
+
+       nanotime(&ts);
+
+       /* XXX Silently truncate?  */
+       kt.kt_sec_nsec.ktsn_sec = ts.tv_sec & 0xffffffffUL;
+       kt.kt_sec_nsec.ktsn_nsec = ts.tv_nsec;
+
+       return kt;
+}
+
+static inline ktime_t
 ktime_get_monotonic_offset(void)
 {
-       return ns_to_ktime(0);  /* XXX Obviously wrong!  Revisit.  */
+       return timespec_to_ktime(boottime);
+}
+
+static inline ktime_t
+ktime_mono_to_real(ktime_t kt)
+{
+       struct timespec ts = ktime_to_timespec(kt);
+
+       timespecadd(&ts, &boottime, &ts);
+
+       return timespec_to_ktime(ts);
 }
 
 static inline bool



Home | Main Index | Thread Index | Old Index