From: "tip-bot2 for Thomas Weißschuh (Schneider Electric)" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: thomas.weissschuh@linutronix.de,
Thomas Gleixner <tglx@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: timers/core] timer_list: Use ktime_t over nanoseconds
Date: Tue, 11 Aug 2026 16:14:16 -0000 [thread overview]
Message-ID: <178646485692.442315.8170288796459373772.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260803-auxclock-nanosleep-prep-v2-5-910cbd485390@linutronix.de>
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 859b069ec5a328bd0bca301f6b9d87ff1dfc4b1d
Gitweb: https://git.kernel.org/tip/859b069ec5a328bd0bca301f6b9d87ff1dfc4b1d
Author: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate: Mon, 03 Aug 2026 12:04:36 +02:00
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00
timer_list: Use ktime_t over nanoseconds
hrtimers use ktime_t in their implementation and API.
The timer list performs a lot of unnecessary conversion to nanoseconds
which make the code harder to read and are also wrong in case the values
ever become negative.
Remove the conversions.
Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-5-910cbd485390@linutronix.de
---
kernel/time/timer_list.c | 57 ++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index ccbbb2a..0406bf4 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -20,7 +20,7 @@
struct timer_list_iter {
int cpu;
bool second_pass;
- u64 now;
+ ktime_t now;
};
/*
@@ -44,19 +44,19 @@ static void SEQ_printf(struct seq_file *m, const char *fmt, ...)
static void
print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
- int idx, u64 now)
+ int idx, ktime_t now)
{
SEQ_printf(m, " #%d: <%p>, %ps", idx, taddr, ACCESS_PRIVATE(timer, function));
SEQ_printf(m, ", S:%02x", timer->is_queued);
SEQ_printf(m, "\n");
- SEQ_printf(m, " # expires at %llu-%llu nsecs [in %lld to %lld nsecs]\n",
- (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
- (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
- (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
- (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
+ SEQ_printf(m, " # expires at %lld-%lld nsecs [in %lld to %lld nsecs]\n",
+ (long long)hrtimer_get_softexpires(timer),
+ (long long)hrtimer_get_expires(timer),
+ (long long)ktime_sub(hrtimer_get_softexpires(timer), now),
+ (long long)ktime_sub(hrtimer_get_expires(timer), now));
}
-static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
+static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base, ktime_t now)
{
struct timerqueue_linked_node *curr;
struct hrtimer *timer, tmp;
@@ -94,7 +94,7 @@ next_one:
}
static void
-print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
+print_base(struct seq_file *m, struct hrtimer_clock_base *base, ktime_t now)
{
SEQ_printf(m, " .base: %p\n", base);
SEQ_printf(m, " .index: %d\n", base->index);
@@ -105,10 +105,10 @@ print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
(long long) base->offset);
#endif
SEQ_printf(m, "active timers:\n");
- print_active_timers(m, base, now + ktime_to_ns(base->offset));
+ print_active_timers(m, base, ktime_add(now, base->offset));
}
-static void print_cpu(struct seq_file *m, int cpu, u64 now)
+static void print_cpu(struct seq_file *m, int cpu, ktime_t now)
{
struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
int i;
@@ -124,12 +124,11 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
#define P(x) \
SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(cpu_base->x))
-#define P_ns(x) \
- SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
- (unsigned long long)ktime_to_ns(DIAG_READ(cpu_base->x)))
+#define P_ktime(x) \
+ SEQ_printf(m, " .%-15s: %lld nsecs\n", #x, (long long)DIAG_READ(cpu_base->x))
#ifdef CONFIG_HIGH_RES_TIMERS
- P_ns(expires_next);
+ P_ktime(expires_next);
P(hres_active);
P(nr_events);
P(nr_retries);
@@ -137,15 +136,14 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
P(max_hang_time);
#endif
#undef P
-#undef P_ns
+#undef P_ktime
#ifdef CONFIG_TICK_ONESHOT
# define P(x) \
SEQ_printf(m, " .%-15s: %llu\n", #x, \
(unsigned long long)DIAG_READ(ts->x))
-# define P_ns(x) \
- SEQ_printf(m, " .%-15s: %llu nsecs\n", #x, \
- (unsigned long long)ktime_to_ns(DIAG_READ(ts->x)))
+# define P_ktime(x) \
+ SEQ_printf(m, " .%-15s: %lld nsecs\n", #x, (long long)DIAG_READ(ts->x))
# define P_flag(x, f) \
SEQ_printf(m, " .%-15s: %d\n", #x, !!(DIAG_READ(ts->flags) & (f)))
@@ -153,22 +151,22 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
struct tick_sched *ts = tick_get_tick_sched(cpu);
P_flag(nohz, TS_FLAG_NOHZ);
P_flag(highres, TS_FLAG_HIGHRES);
- P_ns(last_tick);
+ P_ktime(last_tick);
P_flag(tick_stopped, TS_FLAG_STOPPED);
P(idle_calls);
P(idle_sleeps);
- P_ns(idle_entrytime);
- P_ns(idle_waketime);
+ P_ktime(idle_entrytime);
+ P_ktime(idle_waketime);
P(last_jiffies);
P(next_timer);
- P_ns(idle_expires);
+ P_ktime(idle_expires);
SEQ_printf(m, "jiffies: %llu\n",
(unsigned long long)jiffies);
}
#endif
#undef P
-#undef P_ns
+#undef P_ktime
#undef P_flag
#undef DIAG_READ
SEQ_printf(m, "\n");
@@ -201,8 +199,7 @@ print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
SEQ_printf(m, " mult: %u\n", dev->mult);
SEQ_printf(m, " shift: %u\n", dev->shift);
SEQ_printf(m, " mode: %d\n", clockevent_get_state(dev));
- SEQ_printf(m, " next_event: %lld nsecs\n",
- (unsigned long long) ktime_to_ns(dev->next_event));
+ SEQ_printf(m, " next_event: %lld nsecs\n", (long long)dev->next_event);
SEQ_printf(m, " set_next_event: %ps\n", dev->set_next_event);
@@ -255,17 +252,17 @@ static void timer_list_show_tickdevices_header(struct seq_file *m)
}
#endif
-static inline void timer_list_header(struct seq_file *m, u64 now)
+static inline void timer_list_header(struct seq_file *m, ktime_t now)
{
SEQ_printf(m, "Timer List Version: v0.11\n");
SEQ_printf(m, "HRTIMER_MAX_CLOCK_BASES: %d\n", HRTIMER_MAX_CLOCK_BASES);
- SEQ_printf(m, "now at %lld nsecs\n", (unsigned long long)now);
+ SEQ_printf(m, "now at %lld nsecs\n", (long long)now);
SEQ_printf(m, "\n");
}
void sysrq_timer_list_show(void)
{
- u64 now = ktime_to_ns(ktime_get());
+ ktime_t now = ktime_get();
int cpu;
timer_list_header(NULL, now);
@@ -323,7 +320,7 @@ static void *timer_list_start(struct seq_file *file, loff_t *offset)
struct timer_list_iter *iter = file->private;
if (!*offset)
- iter->now = ktime_to_ns(ktime_get());
+ iter->now = ktime_get();
iter->cpu = -1;
iter->second_pass = false;
return move_iter(iter, *offset);
next prev parent reply other threads:[~2026-08-11 16:14 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 10:04 [PATCH v2 00/17] timekeeping, hrtimer: Assorted cleanups Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 01/17] timekeeping: Rename clockid_aux_valid() to clockid_is_aux_clock() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 02/17] timekeeping: Use u32 for clock_was_set_seq Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 03/17] hrtimer: Add a lockdep assertion to hrtimer_update_base() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 04/17] timer_list: Use standard 'long long' format placeholders Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 05/17] timer_list: Use ktime_t over nanoseconds Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` tip-bot2 for Thomas Weißschuh (Schneider Electric) [this message]
2026-08-03 10:04 ` [PATCH v2 06/17] selftests: add clock-helpers.h Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] selftests: Add clock-helpers.h tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 07/17] selftests: timers: Use clock_name() and constants from clock-helpers.h Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 08/17] selftests: timers: nanosleep: Drop output alignment Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 09/17] selftests: timers: nanosleep: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 10/17] selftests: timers: nanosleep: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 11/17] selftests: timers: nanosleep: Move all single clock tests out of the loop in main() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 12/17] selftests: timers: nanosleep: Explicitly handle timer_delete() failure Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 13/17] selftests: timers: nanosleep: Report each test separately Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 14/17] selftests: timers: nsleep-lat: Use NSEC_PER_MSEC define for unreasonable latency Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 15/17] selftests: timers: nsleep-lat: Explicitly list the tested clocks Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 16/17] selftests: timers: nsleep-lat: Reuse kselftest error numbers Thomas Weißschuh (Schneider Electric)
2026-08-11 16:14 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-08-03 10:04 ` [PATCH v2 17/17] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime() Thomas Weißschuh (Schneider Electric)
2026-08-11 16:13 ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178646485692.442315.8170288796459373772.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®