Message ID | 20190620141159.15965-3-Jason@zx2c4.com |
---|---|
State | Superseded |
Headers | show |
Series | [1/3] timekeeping: add missing non-_ns functions for fast accessors | expand |
On Thu, Jun 20, 2019 at 4:12 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > > > diff --git a/Documentation/core-api/timekeeping.rst b/Documentation/core-api/timekeeping.rst > index ad32085174f8..d5e88f0e06a4 100644 > --- a/Documentation/core-api/timekeeping.rst > +++ b/Documentation/core-api/timekeeping.rst > @@ -99,16 +99,20 @@ Coarse and fast access > > Some additional variants exist for more specialized cases: > > -.. c:function:: ktime_t ktime_get_coarse_boottime( void ) > +.. c:function:: ktime_t ktime_get_coarse( void ) > + ktime_t ktime_get_coarse_boottime( void ) > ktime_t ktime_get_coarse_real( void ) > ktime_t ktime_get_coarse_clocktai( void ) > - ktime_t ktime_get_coarse_raw( void ) > + > +.. c:function:: u64 ktime_get_coarse_ns( void ) > + u64 ktime_get_boot_coarse_ns( void ) > + u64 ktime_get_real_coarse_ns( void ) > + u64 ktime_get_tai_coarse_ns( void ) I would prefer the 'coarse' on the other side, i.e. ktime_get_coarse_real_ns instead of ktime_get_real_coarse_ns, as this is what we already have with ktime_get_coarse_real_ts64. I originally went with that order to avoid the function sounding "real coarse", although I have to admit that it was before Thomas fixed it in e3ff9c3678b4 ("timekeeping: Repair ktime_get_coarse*() granularity"). ;-) I would also prefer _boottime over _boot. Unfortunately we are already inconsistent and have roughly the same number of callers for ktime_get_boot_ns() and ktime_get_boottime(). Arnd
On Fri, Jun 21, 2019 at 4:45 PM Arnd Bergmann <arnd@arndb.de> wrote: > I would prefer the 'coarse' on the other side, i.e. > ktime_get_coarse_real_ns instead of ktime_get_real_coarse_ns, > as this is what we already have with ktime_get_coarse_real_ts64. > > I originally went with that order to avoid the function sounding > "real coarse", although I have to admit that it was before Thomas > fixed it in e3ff9c3678b4 ("timekeeping: Repair ktime_get_coarse*() > granularity"). ;-) I can do this, but that means also I'll change get_real_fast to get_fast_real, too, in order to be consistent. Is that okay?
On Fri, Jun 21, 2019 at 4:46 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > On Fri, Jun 21, 2019 at 4:45 PM Arnd Bergmann <arnd@arndb.de> wrote: > > I would prefer the 'coarse' on the other side, i.e. > > ktime_get_coarse_real_ns instead of ktime_get_real_coarse_ns, > > as this is what we already have with ktime_get_coarse_real_ts64. > > > > I originally went with that order to avoid the function sounding > > "real coarse", although I have to admit that it was before Thomas > > fixed it in e3ff9c3678b4 ("timekeeping: Repair ktime_get_coarse*() > > granularity"). ;-) > > I can do this, but that means also I'll change get_real_fast to > get_fast_real, too, in order to be consistent. Is that okay? I care less about these since ktime_get_real_fast_ns() already exists. My preference would be leaving alons the _fast_ns() functions for now, but making everything else consistent instead. Thomas created the _fast_ns() accessors with a specific application in mind, and I suppose we don't really want them to be used much beyond that. I wonder if we should try to come up with a better name instead of "fast" that makes the purpose clearer and does not suggest that it's faster to read than the "coarse" version. Arnd
On Fri, Jun 21, 2019 at 4:58 PM Arnd Bergmann <arnd@arndb.de> wrote: > I care less about these since ktime_get_real_fast_ns() already > exists. My preference would be leaving alons the _fast_ns() > functions for now, but making everything else consistent instead. > > Thomas created the _fast_ns() accessors with a specific application > in mind, and I suppose we don't really want them to be used much > beyond that. I wonder if we should try to come up with a better > name instead of "fast" that makes the purpose clearer and does > not suggest that it's faster to read than the "coarse" version. Oh shoot, I just submitted v3 having not seen this. Does v3's 4/4 look fine, or shall I undo the _fast switcheroo and resubmit? Jason
On Fri, Jun 21, 2019 at 5:07 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > > On Fri, Jun 21, 2019 at 4:58 PM Arnd Bergmann <arnd@arndb.de> wrote: > > I care less about these since ktime_get_real_fast_ns() already > > exists. My preference would be leaving alons the _fast_ns() > > functions for now, but making everything else consistent instead. > > > > Thomas created the _fast_ns() accessors with a specific application > > in mind, and I suppose we don't really want them to be used much > > beyond that. I wonder if we should try to come up with a better > > name instead of "fast" that makes the purpose clearer and does > > not suggest that it's faster to read than the "coarse" version. > > Oh shoot, I just submitted v3 having not seen this. Does v3's 4/4 look > fine, or shall I undo the _fast switcheroo and resubmit? I'd still prefer to leave out anything touching the _fast functions from patches 1 and 4. AFAICT, that would leave ktime_get_tai_ns() and ktime_get_boot_ns() to be renamed to clocktai() and bootime() respectively. Arnd
diff --git a/Documentation/core-api/timekeeping.rst b/Documentation/core-api/timekeeping.rst index ad32085174f8..d5e88f0e06a4 100644 --- a/Documentation/core-api/timekeeping.rst +++ b/Documentation/core-api/timekeeping.rst @@ -99,16 +99,20 @@ Coarse and fast access Some additional variants exist for more specialized cases: -.. c:function:: ktime_t ktime_get_coarse_boottime( void ) +.. c:function:: ktime_t ktime_get_coarse( void ) + ktime_t ktime_get_coarse_boottime( void ) ktime_t ktime_get_coarse_real( void ) ktime_t ktime_get_coarse_clocktai( void ) - ktime_t ktime_get_coarse_raw( void ) + +.. c:function:: u64 ktime_get_coarse_ns( void ) + u64 ktime_get_boot_coarse_ns( void ) + u64 ktime_get_real_coarse_ns( void ) + u64 ktime_get_tai_coarse_ns( void ) .. c:function:: void ktime_get_coarse_ts64( struct timespec64 * ) void ktime_get_coarse_boottime_ts64( struct timespec64 * ) void ktime_get_coarse_real_ts64( struct timespec64 * ) void ktime_get_coarse_clocktai_ts64( struct timespec64 * ) - void ktime_get_coarse_raw_ts64( struct timespec64 * ) These are quicker than the non-coarse versions, but less accurate, corresponding to CLOCK_MONONOTNIC_COARSE and CLOCK_REALTIME_COARSE diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index c5d360779fab..3df8e63c704b 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -113,6 +113,33 @@ static inline ktime_t ktime_get_coarse_clocktai(void) return ktime_get_coarse_with_offset(TK_OFFS_TAI); } +static inline ktime_t ktime_get_coarse(void) +{ + struct timespec64 ts; + ktime_get_coarse_ts64(&ts); + return timespec64_to_ktime(ts); +} + +static inline u64 ktime_get_coarse_ns(void) +{ + return ktime_to_ns(ktime_get_coarse()); +} + +static inline u64 ktime_get_real_coarse_ns(void) +{ + return ktime_to_ns(ktime_get_coarse_real()); +} + +static inline u64 ktime_get_boot_coarse_ns(void) +{ + return ktime_to_ns(ktime_get_coarse_boottime()); +} + +static inline u64 ktime_get_tai_coarse_ns(void) +{ + return ktime_to_ns(ktime_get_coarse_clocktai()); +} + /** * ktime_mono_to_real - Convert monotonic time to clock realtime */
This further unifies the accessors for the fast and coarse functions, so that the same types of functions are available for each. There was also a bit of confusion with the documentation, which prior advertised a function that has never existed. Finally, the vanilla ktime_get_coarse() was omitted from the API originally, so this fills this oversight. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Thomas Gleixner <tglx@linutronix.de> --- Documentation/core-api/timekeeping.rst | 10 +++++++--- include/linux/timekeeping.h | 27 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) -- 2.21.0