* [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time
@ 2019-06-19 14:23 Jason A. Donenfeld
2019-06-19 14:41 ` Arnd Bergmann
0 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-19 14:23 UTC (permalink / raw)
To: linux-kernel
Cc: Jason A. Donenfeld, Thomas Gleixner, Peter Zijlstra,
Arnd Bergmann, Andrew Morton
This enables using the usual get_jiffies_64() but taking into account
time spent sleeping, giving the high performance characteristics of
querying jiffies without the drawback.
We accomplish this by precomputing the boottime jiffies offset whenever
it is updated, rather than doing the expensive-ish div_u64 on each
query.
Since the resolution of this is in terms of jiffies, this allows
determining limits for comparison in terms of jiffies too, which makes
the comparisons more exact, despite jiffies being a fairly coarse stamp.
Adding the suspend offset to jiffies as such doesn't actually race in a
way different from the usual races associated with the suspend offset:
either boot offset has been updated before the call to
get_jiffies_boot_64(), in which case we're fine, or it hasn't in which
case, this is no different than any of the existing suspend querying
functions, which may be invoked early in system resumption before the
offset is updated.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc; John Stultz <john.stultz@linaro.org>
---
include/linux/jiffies.h | 1 +
include/linux/timekeeper_internal.h | 2 ++
kernel/time/timekeeping.c | 11 +++++++++++
3 files changed, 14 insertions(+)
diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 1b6d31da7cbc..e4a9776d8b2a 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -80,6 +80,7 @@ extern int register_refined_jiffies(long clock_tick_rate);
extern u64 __cacheline_aligned_in_smp jiffies_64;
extern unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data jiffies;
+u64 get_jiffies_boot_64(void);
#if (BITS_PER_LONG < 64)
u64 get_jiffies_64(void);
#else
diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h
index 7acb953298a7..2e4c52fe0250 100644
--- a/include/linux/timekeeper_internal.h
+++ b/include/linux/timekeeper_internal.h
@@ -51,6 +51,7 @@ struct tk_read_base {
* @wall_to_monotonic: CLOCK_REALTIME to CLOCK_MONOTONIC offset
* @offs_real: Offset clock monotonic -> clock realtime
* @offs_boot: Offset clock monotonic -> clock boottime
+ * @offs_boot_jiffies64 Offset clock monotonic -> clock boottime in jiffies64
* @offs_tai: Offset clock monotonic -> clock tai
* @tai_offset: The current UTC to TAI offset in seconds
* @clock_was_set_seq: The sequence number of clock was set events
@@ -93,6 +94,7 @@ struct timekeeper {
struct timespec64 wall_to_monotonic;
ktime_t offs_real;
ktime_t offs_boot;
+ u64 offs_boot_jiffies64;
ktime_t offs_tai;
s32 tai_offset;
unsigned int clock_was_set_seq;
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 85f5912d8f70..a3707b454446 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -146,6 +146,7 @@ static void tk_set_wall_to_mono(struct timekeeper *tk, struct timespec64 wtm)
static inline void tk_update_sleep_time(struct timekeeper *tk, ktime_t delta)
{
tk->offs_boot = ktime_add(tk->offs_boot, delta);
+ tk->offs_boot_jiffies64 = nsecs_to_jiffies64(ktime_to_ns(tk->offs_boot));
}
/*
@@ -539,6 +540,16 @@ u64 ktime_get_real_fast_ns(void)
}
EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns);
+/**
+ * get_jiffies_boot_64 - The normal get_jiffies_64(), but taking into
+ * account the time spent sleeping.
+ */
+u64 get_jiffies_boot_64(void)
+{
+ return get_jiffies_64() + tk_core.timekeeper.offs_boot_jiffies64;
+}
+EXPORT_SYMBOL(get_jiffies_boot_64);
+
/**
* halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.
* @tk: Timekeeper to snapshot.
--
2.21.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time
2019-06-19 14:23 [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time Jason A. Donenfeld
@ 2019-06-19 14:41 ` Arnd Bergmann
2019-06-19 15:31 ` Jason A. Donenfeld
0 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-19 14:41 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Linux Kernel Mailing List, Thomas Gleixner, Peter Zijlstra,
Andrew Morton
On Wed, Jun 19, 2019 at 4:24 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> This enables using the usual get_jiffies_64() but taking into account
> time spent sleeping, giving the high performance characteristics of
> querying jiffies without the drawback.
Can you quantify how much this gains you over ktime_get_coarse_boottime
in practice? You are effectively adding yet another abstraction for time,
which is something I'd hope to avoid unless you have a strong reason other
than it being faster in theory.
How often do you read the current time?
Arnd
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time
2019-06-19 14:41 ` Arnd Bergmann
@ 2019-06-19 15:31 ` Jason A. Donenfeld
2019-06-19 20:02 ` Arnd Bergmann
0 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-19 15:31 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Linux Kernel Mailing List, Thomas Gleixner, Peter Zijlstra,
Andrew Morton
Hi Arnd,
On Wed, Jun 19, 2019 at 5:08 PM Arnd Bergmann <arnd@arndb.de> wrote:
> Can you quantify how much this gains you over ktime_get_coarse_boottime
> in practice? You are effectively adding yet another abstraction for time,
> which is something I'd hope to avoid unless you have a strong reason other
> than it being faster in theory.
Excellent idea. It turns out to be precisely 0 (see below). A
motivation still remains, though: this allows comparison with units
specified in terms of jiffies, which means that the unit being
compared matches the exact tick of the clock, making those comparisons
as precise as possible, for what they are. I suppose you could argue,
on the other hand, that nanoseconds give so much precision already,
that approximations using them amount practically to the same thing.
I'm not sure which way to reason about that.
For interest, here are a few comparisons taken with kbench9000:
get_jiffies_boot_64 26
ktime_get_coarse_boottime 26
ktime_get_boot_fast_ns with tsc 70
ktime_get_boot_fast_ns with hpet 4922
ktime_get_boot_fast_ns with acpi_pm 1884
As expected, hpet is really quite painful.
Jason
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time
2019-06-19 15:31 ` Jason A. Donenfeld
@ 2019-06-19 20:02 ` Arnd Bergmann
2019-06-19 20:06 ` Jason A. Donenfeld
0 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-19 20:02 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Linux Kernel Mailing List, Thomas Gleixner, Peter Zijlstra,
Andrew Morton
On Wed, Jun 19, 2019 at 5:31 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> Hi Arnd,
>
> On Wed, Jun 19, 2019 at 5:08 PM Arnd Bergmann <arnd@arndb.de> wrote:
> > Can you quantify how much this gains you over ktime_get_coarse_boottime
> > in practice? You are effectively adding yet another abstraction for time,
> > which is something I'd hope to avoid unless you have a strong reason other
> > than it being faster in theory.
>
> Excellent idea. It turns out to be precisely 0 (see below). A
> motivation still remains, though: this allows comparison with units
> specified in terms of jiffies, which means that the unit being
> compared matches the exact tick of the clock, making those comparisons
> as precise as possible, for what they are. I suppose you could argue,
> on the other hand, that nanoseconds give so much precision already,
> that approximations using them amount practically to the same thing.
> I'm not sure which way to reason about that.
>
> For interest, here are a few comparisons taken with kbench9000:
>
> get_jiffies_boot_64 26
> ktime_get_coarse_boottime 26
> ktime_get_boot_fast_ns with tsc 70
> ktime_get_boot_fast_ns with hpet 4922
> ktime_get_boot_fast_ns with acpi_pm 1884
>
> As expected, hpet is really quite painful.
I would prefer not to add the new interface then. We might in
fact move users of get_jiffies_64() to ktime_get_coarse() for
consistency given the small overhead of that function.
Arnd
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time
2019-06-19 20:02 ` Arnd Bergmann
@ 2019-06-19 20:06 ` Jason A. Donenfeld
2019-06-19 20:57 ` Arnd Bergmann
0 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-19 20:06 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Linux Kernel Mailing List, Thomas Gleixner, Peter Zijlstra,
Andrew Morton
On Wed, Jun 19, 2019 at 10:02 PM Arnd Bergmann <arnd@arndb.de> wrote:
> > get_jiffies_boot_64 26
> > ktime_get_coarse_boottime 26
> > ktime_get_boot_fast_ns with tsc 70
> > ktime_get_boot_fast_ns with hpet 4922
> > ktime_get_boot_fast_ns with acpi_pm 1884
> >
> > As expected, hpet is really quite painful.
>
> I would prefer not to add the new interface then. We might in
> fact move users of get_jiffies_64() to ktime_get_coarse() for
> consistency given the small overhead of that function.
In light of the measurements, that seems like a good plan to me.
One thing to consider with moving jiffies users over that way is
ktime_t. Do you want to introduce helpers like
ktime_get_boot_coarse_ns(), just like there is already with the other
various functions like ktime_get_boot_ns(), ktime_get_boot_fast_ns(),
etc? (I'd personally prefer using the _ns variants, at least.) I can
send a patch for this.
Jason
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time
2019-06-19 20:06 ` Jason A. Donenfeld
@ 2019-06-19 20:57 ` Arnd Bergmann
2019-06-20 13:24 ` Jason A. Donenfeld
0 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-19 20:57 UTC (permalink / raw)
To: Jason A. Donenfeld
Cc: Linux Kernel Mailing List, Thomas Gleixner, Peter Zijlstra,
Andrew Morton
On Wed, Jun 19, 2019 at 10:07 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> On Wed, Jun 19, 2019 at 10:02 PM Arnd Bergmann <arnd@arndb.de> wrote:
> > > get_jiffies_boot_64 26
> > > ktime_get_coarse_boottime 26
> > > ktime_get_boot_fast_ns with tsc 70
> > > ktime_get_boot_fast_ns with hpet 4922
> > > ktime_get_boot_fast_ns with acpi_pm 1884
> > >
> > > As expected, hpet is really quite painful.
> >
> > I would prefer not to add the new interface then. We might in
> > fact move users of get_jiffies_64() to ktime_get_coarse() for
> > consistency given the small overhead of that function.
>
> In light of the measurements, that seems like a good plan to me.
>
> One thing to consider with moving jiffies users over that way is
> ktime_t. Do you want to introduce helpers like
> ktime_get_boot_coarse_ns(), just like there is already with the other
> various functions like ktime_get_boot_ns(), ktime_get_boot_fast_ns(),
> etc? (I'd personally prefer using the _ns variants, at least.) I can
> send a patch for this.
That sounds reasonable, but then I think we should have the full
set of coarse_*_ns() functions, again for consistency:
u64 ktime_get_coarse_ns(void)
u64 ktime_get_coarse_boottime_ns(void)
u64 ktime_get_coarse_real_ns(void)
u64 ktime_get_coarse_clocktai_ns(void)
and document them in Documentation/core-api/timekeeping.rst.
We seem to also be lacking the basic ktime_get_coarse(), which
seems like a major omission.
Both ktime_get_coarse_ns and ktime_get_coarse can be wrappers
around ktime_get_coarse_ts64() then, while the others would
use ktime_get_coarse_with_offset().
Arnd
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time
2019-06-19 20:57 ` Arnd Bergmann
@ 2019-06-20 13:24 ` Jason A. Donenfeld
2019-06-20 14:11 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Jason A. Donenfeld
0 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-20 13:24 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Linux Kernel Mailing List, Thomas Gleixner, Peter Zijlstra,
Andrew Morton
On Wed, Jun 19, 2019 at 10:57 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Wed, Jun 19, 2019 at 10:07 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> >
> > On Wed, Jun 19, 2019 at 10:02 PM Arnd Bergmann <arnd@arndb.de> wrote:
> > > > get_jiffies_boot_64 26
> > > > ktime_get_coarse_boottime 26
> > > > ktime_get_boot_fast_ns with tsc 70
> > > > ktime_get_boot_fast_ns with hpet 4922
> > > > ktime_get_boot_fast_ns with acpi_pm 1884
> > > >
> > > > As expected, hpet is really quite painful.
> > >
> > > I would prefer not to add the new interface then. We might in
> > > fact move users of get_jiffies_64() to ktime_get_coarse() for
> > > consistency given the small overhead of that function.
> >
> > In light of the measurements, that seems like a good plan to me.
> >
> > One thing to consider with moving jiffies users over that way is
> > ktime_t. Do you want to introduce helpers like
> > ktime_get_boot_coarse_ns(), just like there is already with the other
> > various functions like ktime_get_boot_ns(), ktime_get_boot_fast_ns(),
> > etc? (I'd personally prefer using the _ns variants, at least.) I can
> > send a patch for this.
>
> That sounds reasonable, but then I think we should have the full
> set of coarse_*_ns() functions, again for consistency:
>
> u64 ktime_get_coarse_ns(void)
> u64 ktime_get_coarse_boottime_ns(void)
> u64 ktime_get_coarse_real_ns(void)
> u64 ktime_get_coarse_clocktai_ns(void)
>
> and document them in Documentation/core-api/timekeeping.rst.
>
> We seem to also be lacking the basic ktime_get_coarse(), which
> seems like a major omission.
> Both ktime_get_coarse_ns and ktime_get_coarse can be wrappers
> around ktime_get_coarse_ts64() then, while the others would
> use ktime_get_coarse_with_offset().
Exactly what I had in mind. I'll have something posted fairly soon.
Jason
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors
2019-06-20 13:24 ` Jason A. Donenfeld
@ 2019-06-20 14:11 ` Jason A. Donenfeld
2019-06-20 14:11 ` [PATCH 2/3] timekeeping: use proper ktime_add when adding nsecs in coarse offset Jason A. Donenfeld
` (2 more replies)
0 siblings, 3 replies; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-20 14:11 UTC (permalink / raw)
To: linux-kernel; +Cc: Jason A. Donenfeld, Arnd Bergmann, Thomas Gleixner
Previously there was no analogue to get proper ktime_t versions of the
fast variety of ktime invocations. This commit makes the interface
uniform with the other accessors.
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 | 7 +++-
include/linux/timekeeping.h | 28 ++++++++++++--
kernel/time/timekeeping.c | 52 +++++++++++++-------------
3 files changed, 55 insertions(+), 32 deletions(-)
diff --git a/Documentation/core-api/timekeeping.rst b/Documentation/core-api/timekeeping.rst
index 93cbeb9daec0..ad32085174f8 100644
--- a/Documentation/core-api/timekeeping.rst
+++ b/Documentation/core-api/timekeeping.rst
@@ -94,7 +94,7 @@ different format depending on what is required by the user:
down the seconds to the full seconds of the last timer tick
using the respective reference.
-Coarse and fast_ns access
+Coarse and fast access
-------------------------
Some additional variants exist for more specialized cases:
@@ -125,6 +125,11 @@ Some additional variants exist for more specialized cases:
up to several microseconds on older hardware with an external
clocksource.
+.. c:function:: ktime_t ktime_get_mono_fast_ns( void )
+ ktime_t ktime_get_raw_fast_ns( void )
+ ktime_t ktime_get_boottime_fast_ns( void )
+ ktime_t ktime_get_real_fast_ns( void )
+
.. c:function:: u64 ktime_get_mono_fast_ns( void )
u64 ktime_get_raw_fast_ns( void )
u64 ktime_get_boot_fast_ns( void )
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index a8ab0f143ac4..c5d360779fab 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -146,10 +146,30 @@ static inline u64 ktime_get_raw_ns(void)
return ktime_to_ns(ktime_get_raw());
}
-extern u64 ktime_get_mono_fast_ns(void);
-extern u64 ktime_get_raw_fast_ns(void);
-extern u64 ktime_get_boot_fast_ns(void);
-extern u64 ktime_get_real_fast_ns(void);
+extern ktime_t ktime_get_mono_fast(void);
+extern ktime_t ktime_get_raw_fast(void);
+extern ktime_t ktime_get_boottime_fast(void);
+extern ktime_t ktime_get_real_fast(void);
+
+static inline u64 ktime_get_mono_fast_ns(void)
+{
+ return ktime_to_ns(ktime_get_mono_fast());
+}
+
+static inline u64 ktime_get_raw_fast_ns(void)
+{
+ return ktime_to_ns(ktime_get_raw_fast());
+}
+
+static inline u64 ktime_get_boot_fast_ns(void)
+{
+ return ktime_to_ns(ktime_get_boottime_fast());
+}
+
+static inline u64 ktime_get_real_fast_ns(void)
+{
+ return ktime_to_ns(ktime_get_real_fast());
+}
/*
* timespec64/time64_t interfaces utilizing the ktime based ones
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 44b726bab4bd..4c97c9c8c217 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -443,41 +443,40 @@ static void update_fast_timekeeper(const struct tk_read_base *tkr,
* of the following timestamps. Callers need to be aware of that and
* deal with it.
*/
-static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf)
+static __always_inline ktime_t __ktime_get_fast(struct tk_fast *tkf)
{
struct tk_read_base *tkr;
unsigned int seq;
- u64 now;
+ ktime_t now;
do {
seq = raw_read_seqcount_latch(&tkf->seq);
tkr = tkf->base + (seq & 0x01);
- now = ktime_to_ns(tkr->base);
-
- now += timekeeping_delta_to_ns(tkr,
+ now = ktime_add_ns(tkr->base,
+ timekeeping_delta_to_ns(tkr,
clocksource_delta(
tk_clock_read(tkr),
tkr->cycle_last,
- tkr->mask));
+ tkr->mask)));
} while (read_seqcount_retry(&tkf->seq, seq));
return now;
}
-u64 ktime_get_mono_fast_ns(void)
+ktime_t ktime_get_mono_fast(void)
{
- return __ktime_get_fast_ns(&tk_fast_mono);
+ return __ktime_get_fast(&tk_fast_mono);
}
-EXPORT_SYMBOL_GPL(ktime_get_mono_fast_ns);
+EXPORT_SYMBOL_GPL(ktime_get_mono_fast);
-u64 ktime_get_raw_fast_ns(void)
+ktime_t ktime_get_raw_fast(void)
{
- return __ktime_get_fast_ns(&tk_fast_raw);
+ return __ktime_get_fast(&tk_fast_raw);
}
-EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns);
+EXPORT_SYMBOL_GPL(ktime_get_raw_fast);
/**
- * ktime_get_boot_fast_ns - NMI safe and fast access to boot clock.
+ * ktime_get_boottime_fast - NMI safe and fast access to boot clock.
*
* To keep it NMI safe since we're accessing from tracing, we're not using a
* separate timekeeper with updates to monotonic clock and boot offset
@@ -497,47 +496,46 @@ EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns);
* partially updated. Since the tk->offs_boot update is a rare event, this
* should be a rare occurrence which postprocessing should be able to handle.
*/
-u64 notrace ktime_get_boot_fast_ns(void)
+ktime_t notrace ktime_get_boottime_fast(void)
{
struct timekeeper *tk = &tk_core.timekeeper;
- return (ktime_get_mono_fast_ns() + ktime_to_ns(tk->offs_boot));
+ return ktime_add(ktime_get_mono_fast(), tk->offs_boot);
}
-EXPORT_SYMBOL_GPL(ktime_get_boot_fast_ns);
+EXPORT_SYMBOL_GPL(ktime_get_boottime_fast);
/*
- * See comment for __ktime_get_fast_ns() vs. timestamp ordering
+ * See comment for __ktime_get_fast() vs. timestamp ordering
*/
-static __always_inline u64 __ktime_get_real_fast_ns(struct tk_fast *tkf)
+static __always_inline ktime_t __ktime_get_real_fast(struct tk_fast *tkf)
{
struct tk_read_base *tkr;
unsigned int seq;
- u64 now;
+ ktime_t now;
do {
seq = raw_read_seqcount_latch(&tkf->seq);
tkr = tkf->base + (seq & 0x01);
- now = ktime_to_ns(tkr->base_real);
-
- now += timekeeping_delta_to_ns(tkr,
+ now = ktime_add_ns(tkr->base_real,
+ timekeeping_delta_to_ns(tkr,
clocksource_delta(
tk_clock_read(tkr),
tkr->cycle_last,
- tkr->mask));
+ tkr->mask)));
} while (read_seqcount_retry(&tkf->seq, seq));
return now;
}
/**
- * ktime_get_real_fast_ns: - NMI safe and fast access to clock realtime.
+ * ktime_get_real_fast: - NMI safe and fast access to clock realtime.
*/
-u64 ktime_get_real_fast_ns(void)
+ktime_t ktime_get_real_fast(void)
{
- return __ktime_get_real_fast_ns(&tk_fast_mono);
+ return __ktime_get_real_fast(&tk_fast_mono);
}
-EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns);
+EXPORT_SYMBOL_GPL(ktime_get_real_fast);
/**
* halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.
--
2.21.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH 2/3] timekeeping: use proper ktime_add when adding nsecs in coarse offset
2019-06-20 14:11 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Jason A. Donenfeld
@ 2019-06-20 14:11 ` Jason A. Donenfeld
2019-06-21 14:29 ` Arnd Bergmann
2019-06-20 14:11 ` [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors Jason A. Donenfeld
2019-06-21 14:29 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Arnd Bergmann
2 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-20 14:11 UTC (permalink / raw)
To: linux-kernel; +Cc: Jason A. Donenfeld, Arnd Bergmann, Thomas Gleixner
While this doesn't actually amount to a real difference, since the macro
evaluates to the same thing, every place else operates on ktime_t using
these functions, so let's not break the pattern.
Fixes: e3ff9c3678b4 ("timekeeping: Repair ktime_get_coarse*() granularity")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
kernel/time/timekeeping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4c97c9c8c217..db0081a14b90 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -817,7 +817,7 @@ ktime_t ktime_get_coarse_with_offset(enum tk_offsets offs)
} while (read_seqcount_retry(&tk_core.seq, seq));
- return base + nsecs;
+ return ktime_add_ns(base, nsecs);
}
EXPORT_SYMBOL_GPL(ktime_get_coarse_with_offset);
--
2.21.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors
2019-06-20 14:11 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Jason A. Donenfeld
2019-06-20 14:11 ` [PATCH 2/3] timekeeping: use proper ktime_add when adding nsecs in coarse offset Jason A. Donenfeld
@ 2019-06-20 14:11 ` Jason A. Donenfeld
2019-06-21 14:38 ` Arnd Bergmann
2019-06-21 14:29 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Arnd Bergmann
2 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-20 14:11 UTC (permalink / raw)
To: linux-kernel; +Cc: Jason A. Donenfeld, Arnd Bergmann, Thomas Gleixner
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(-)
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
*/
--
2.21.0
^ permalink raw reply related [flat|nested] 19+ messages in thread* Re: [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors
2019-06-20 14:11 ` [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors Jason A. Donenfeld
@ 2019-06-21 14:38 ` Arnd Bergmann
2019-06-21 14:46 ` Jason A. Donenfeld
0 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-21 14:38 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Linux Kernel Mailing List, Thomas Gleixner
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
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors
2019-06-21 14:38 ` Arnd Bergmann
@ 2019-06-21 14:46 ` Jason A. Donenfeld
2019-06-21 14:58 ` Arnd Bergmann
0 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-21 14:46 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Linux Kernel Mailing List, Thomas Gleixner
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?
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors
2019-06-21 14:46 ` Jason A. Donenfeld
@ 2019-06-21 14:58 ` Arnd Bergmann
2019-06-21 15:07 ` Jason A. Donenfeld
0 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-21 14:58 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Linux Kernel Mailing List, Thomas Gleixner
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
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors
2019-06-21 14:58 ` Arnd Bergmann
@ 2019-06-21 15:07 ` Jason A. Donenfeld
2019-06-21 15:20 ` Arnd Bergmann
0 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-21 15:07 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Linux Kernel Mailing List, Thomas Gleixner
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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors
2019-06-21 15:07 ` Jason A. Donenfeld
@ 2019-06-21 15:20 ` Arnd Bergmann
0 siblings, 0 replies; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-21 15:20 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Linux Kernel Mailing List, Thomas Gleixner
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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors
2019-06-20 14:11 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Jason A. Donenfeld
2019-06-20 14:11 ` [PATCH 2/3] timekeeping: use proper ktime_add when adding nsecs in coarse offset Jason A. Donenfeld
2019-06-20 14:11 ` [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors Jason A. Donenfeld
@ 2019-06-21 14:29 ` Arnd Bergmann
2019-06-21 14:33 ` Jason A. Donenfeld
2 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-21 14:29 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Linux Kernel Mailing List, Thomas Gleixner
On Thu, Jun 20, 2019 at 4:12 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> Previously there was no analogue to get proper ktime_t versions of the
> fast variety of ktime invocations. This commit makes the interface
> uniform with the other accessors.
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Thomas Gleixner <tglx@linutronix.de>
Consistent is good, not sure if there is a real use for the *_fast()
functions returning a ktime_t, but I don't mind adding them.
> +.. c:function:: ktime_t ktime_get_mono_fast_ns( void )
> + ktime_t ktime_get_raw_fast_ns( void )
> + ktime_t ktime_get_boottime_fast_ns( void )
> + ktime_t ktime_get_real_fast_ns( void )
> +
> .. c:function:: u64 ktime_get_mono_fast_ns( void )
> u64 ktime_get_raw_fast_ns( void )
> u64 ktime_get_boot_fast_ns( void )
Typo: you have the same function names listed twice here,
one of them should be ktime_get_mono_fast() instead of
ktime_get_mono_fast_ns().
Also, we might want to rename ktime_get_boot_fast_ns()
to ktime_get_boottime_fast_ns in the process. It seems there
is only a single caller.
Arnd
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors
2019-06-21 14:29 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Arnd Bergmann
@ 2019-06-21 14:33 ` Jason A. Donenfeld
2019-06-21 14:40 ` Arnd Bergmann
0 siblings, 1 reply; 19+ messages in thread
From: Jason A. Donenfeld @ 2019-06-21 14:33 UTC (permalink / raw)
To: Arnd Bergmann; +Cc: Linux Kernel Mailing List, Thomas Gleixner
On Fri, Jun 21, 2019 at 4:29 PM Arnd Bergmann <arnd@arndb.de> wrote:
> Typo: you have the same function names listed twice here,
> one of them should be ktime_get_mono_fast() instead of
> ktime_get_mono_fast_ns().
Nice catch. Vim twitches gone crazy.
> Also, we might want to rename ktime_get_boot_fast_ns()
> to ktime_get_boottime_fast_ns in the process. It seems there
> is only a single caller.
And tai -> clocktai on the others. I can send a followup patch to
unify all those after this set.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors
2019-06-21 14:33 ` Jason A. Donenfeld
@ 2019-06-21 14:40 ` Arnd Bergmann
0 siblings, 0 replies; 19+ messages in thread
From: Arnd Bergmann @ 2019-06-21 14:40 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Linux Kernel Mailing List, Thomas Gleixner
On Fri, Jun 21, 2019 at 4:33 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> On Fri, Jun 21, 2019 at 4:29 PM Arnd Bergmann <arnd@arndb.de> wrote:
> > Typo: you have the same function names listed twice here,
> > one of them should be ktime_get_mono_fast() instead of
> > ktime_get_mono_fast_ns().
>
> Nice catch. Vim twitches gone crazy.
>
> > Also, we might want to rename ktime_get_boot_fast_ns()
> > to ktime_get_boottime_fast_ns in the process. It seems there
> > is only a single caller.
>
> And tai -> clocktai on the others. I can send a followup patch to
> unify all those after this set.
Yes, that's probably best.
Arnd
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2019-06-21 15:20 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-19 14:23 [PATCH v2] timekeeping: get_jiffies_boot_64() for jiffies that include sleep time Jason A. Donenfeld
2019-06-19 14:41 ` Arnd Bergmann
2019-06-19 15:31 ` Jason A. Donenfeld
2019-06-19 20:02 ` Arnd Bergmann
2019-06-19 20:06 ` Jason A. Donenfeld
2019-06-19 20:57 ` Arnd Bergmann
2019-06-20 13:24 ` Jason A. Donenfeld
2019-06-20 14:11 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Jason A. Donenfeld
2019-06-20 14:11 ` [PATCH 2/3] timekeeping: use proper ktime_add when adding nsecs in coarse offset Jason A. Donenfeld
2019-06-21 14:29 ` Arnd Bergmann
2019-06-20 14:11 ` [PATCH 3/3] timekeeping: add missing _ns functions for coarse accessors Jason A. Donenfeld
2019-06-21 14:38 ` Arnd Bergmann
2019-06-21 14:46 ` Jason A. Donenfeld
2019-06-21 14:58 ` Arnd Bergmann
2019-06-21 15:07 ` Jason A. Donenfeld
2019-06-21 15:20 ` Arnd Bergmann
2019-06-21 14:29 ` [PATCH 1/3] timekeeping: add missing non-_ns functions for fast accessors Arnd Bergmann
2019-06-21 14:33 ` Jason A. Donenfeld
2019-06-21 14:40 ` Arnd Bergmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.