* [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time
@ 2025-08-12 6:08 Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 1/8] posix-timers: Avoid direct access to hrtimer clockbase Thomas Weißschuh
` (8 more replies)
0 siblings, 9 replies; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The get_time() callbacks always need to match the bases clockid.
Instead of maintaining that association twice in hrtimer_bases,
use a helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (8):
posix-timers: Avoid direct access to hrtimer clockbase
timers/itimer: Avoid direct access to hrtimer clockbase
sched/core: Avoid direct access to hrtimer clockbase
lib: test_objpool: Avoid direct access to hrtimer clockbase
ALSA: hrtimer: Avoid direct access to hrtimer clockbase
media: pwm-ir-tx: Avoid direct access to hrtimer clockbase
hrtimer: Use hrtimer_cb_get_time() helper
hrtimer: Remove hrtimer_clock_base::get_time
drivers/media/rc/pwm-ir-tx.c | 5 +----
include/linux/hrtimer.h | 14 +++++---------
include/linux/hrtimer_defs.h | 2 --
kernel/sched/core.c | 2 +-
kernel/time/hrtimer.c | 34 +++++++++++++++++++++++++---------
kernel/time/itimer.c | 3 +--
kernel/time/posix-timers.c | 5 ++---
kernel/time/timer_list.c | 2 --
lib/test_objpool.c | 2 +-
scripts/gdb/linux/timerlist.py | 2 --
sound/core/hrtimer.c | 2 +-
11 files changed, 37 insertions(+), 36 deletions(-)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250728-hrtimer-cleanup-get_time-8ac9d797a685
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/8] posix-timers: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 2/8] timers/itimer: " Thomas Weißschuh
` (7 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The field timer->base->get_time is a private implementation detail and
should not be accessed outside of the hrtimer core.
Switch to the equivalent helpers.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
kernel/time/posix-timers.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 8b582174b1f9498a548fc1c214185577f994a647..2741f3725de48ea8f73cc279287631f9d5a6e960 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -299,8 +299,7 @@ static void common_hrtimer_rearm(struct k_itimer *timr)
{
struct hrtimer *timer = &timr->it.real.timer;
- timr->it_overrun += hrtimer_forward(timer, timer->base->get_time(),
- timr->it_interval);
+ timr->it_overrun += hrtimer_forward_now(timer, timr->it_interval);
hrtimer_restart(timer);
}
@@ -825,7 +824,7 @@ static void common_hrtimer_arm(struct k_itimer *timr, ktime_t expires,
hrtimer_setup(&timr->it.real.timer, posix_timer_fn, timr->it_clock, mode);
if (!absolute)
- expires = ktime_add_safe(expires, timer->base->get_time());
+ expires = ktime_add_safe(expires, hrtimer_cb_get_time(timer));
hrtimer_set_expires(timer, expires);
if (!sigev_none)
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/8] timers/itimer: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 1/8] posix-timers: Avoid direct access to hrtimer clockbase Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 3/8] sched/core: " Thomas Weißschuh
` (6 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The field timer->base->get_time is a private implementation detail and
should not be accessed outside of the hrtimer core.
Switch to the equivalent helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
kernel/time/itimer.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
index 876d389b2e219a10c0dbddb6a06dd3252c502e99..7c6110e964e7ecd19ab8c5c9b81f1b113c1ae7bd 100644
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -163,8 +163,7 @@ void posixtimer_rearm_itimer(struct task_struct *tsk)
struct hrtimer *tmr = &tsk->signal->real_timer;
if (!hrtimer_is_queued(tmr) && tsk->signal->it_real_incr != 0) {
- hrtimer_forward(tmr, tmr->base->get_time(),
- tsk->signal->it_real_incr);
+ hrtimer_forward_now(tmr, tsk->signal->it_real_incr);
hrtimer_restart(tmr);
}
}
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/8] sched/core: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 1/8] posix-timers: Avoid direct access to hrtimer clockbase Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 2/8] timers/itimer: " Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 4/8] lib: test_objpool: " Thomas Weißschuh
` (5 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The field timer->base->get_time is a private implementation detail and
should not be accessed outside of the hrtimer core.
Switch to the equivalent helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
kernel/sched/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index be00629f0ba4cc5832189c0052b0b632deb4ea2e..4dc12838ad4fdf086b3f3f1168072d6301f51aa3 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -917,7 +917,7 @@ void hrtick_start(struct rq *rq, u64 delay)
* doesn't make sense and can cause timer DoS.
*/
delta = max_t(s64, delay, 10000LL);
- rq->hrtick_time = ktime_add_ns(timer->base->get_time(), delta);
+ rq->hrtick_time = ktime_add_ns(hrtimer_cb_get_time(timer), delta);
if (rq == this_rq())
__hrtick_restart(rq);
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/8] lib: test_objpool: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
` (2 preceding siblings ...)
2025-08-12 6:08 ` [PATCH 3/8] sched/core: " Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 5/8] ALSA: hrtimer: " Thomas Weißschuh
` (4 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The field timer->base->get_time is a private implementation detail and
should not be accessed outside of the hrtimer core.
Switch to the equivalent helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
lib/test_objpool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/test_objpool.c b/lib/test_objpool.c
index 8f688187fa8727e26d2d065c46e789ee15fd55b5..6a34a7582fdbf50b5632043ec19e77c8fd4dad78 100644
--- a/lib/test_objpool.c
+++ b/lib/test_objpool.c
@@ -164,7 +164,7 @@ static enum hrtimer_restart ot_hrtimer_handler(struct hrtimer *hrt)
/* do bulk-testings for objects pop/push */
item->worker(item, 1);
- hrtimer_forward(hrt, hrt->base->get_time(), item->hrtcycle);
+ hrtimer_forward_now(hrt, item->hrtcycle);
return HRTIMER_RESTART;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/8] ALSA: hrtimer: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
` (3 preceding siblings ...)
2025-08-12 6:08 ` [PATCH 4/8] lib: test_objpool: " Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 11:07 ` Takashi Iwai
2025-08-12 6:08 ` [PATCH 6/8] media: pwm-ir-tx: " Thomas Weißschuh
` (3 subsequent siblings)
8 siblings, 1 reply; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The field timer->base->get_time is a private implementation detail and
should not be accessed outside of the hrtimer core.
Switch to the equivalent helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
sound/core/hrtimer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
index c364bd126ac8b311e3ce899e226ff9fd82c4485f..2d5f4d47071f79d7db24c8f004f0f4154808fdd8 100644
--- a/sound/core/hrtimer.c
+++ b/sound/core/hrtimer.c
@@ -44,7 +44,7 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
}
/* calculate the drift */
- delta = ktime_sub(hrt->base->get_time(), hrtimer_get_expires(hrt));
+ delta = ktime_sub(hrtimer_cb_get_time(hrt), hrtimer_get_expires(hrt));
if (delta > 0)
ticks += ktime_divns(delta, ticks * resolution);
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 6/8] media: pwm-ir-tx: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
` (4 preceding siblings ...)
2025-08-12 6:08 ` [PATCH 5/8] ALSA: hrtimer: " Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 12:06 ` Sean Young
2025-08-12 6:08 ` [PATCH 7/8] hrtimer: Use hrtimer_cb_get_time() helper Thomas Weißschuh
` (2 subsequent siblings)
8 siblings, 1 reply; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The field timer->base->get_time is a private implementation detail and
should not be accessed outside of the hrtimer core.
Switch to an equivalent higher-level helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
drivers/media/rc/pwm-ir-tx.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/media/rc/pwm-ir-tx.c b/drivers/media/rc/pwm-ir-tx.c
index 84533fdd61aa6ce3c0f8593aaefe5919fd05c7f9..047472dc9244afe0e56e505be20f36fd7d9c449a 100644
--- a/drivers/media/rc/pwm-ir-tx.c
+++ b/drivers/media/rc/pwm-ir-tx.c
@@ -117,7 +117,6 @@ static int pwm_ir_tx_atomic(struct rc_dev *dev, unsigned int *txbuf,
static enum hrtimer_restart pwm_ir_timer(struct hrtimer *timer)
{
struct pwm_ir *pwm_ir = container_of(timer, struct pwm_ir, timer);
- ktime_t now;
/*
* If we happen to hit an odd latency spike, loop through the
@@ -139,9 +138,7 @@ static enum hrtimer_restart pwm_ir_timer(struct hrtimer *timer)
hrtimer_add_expires_ns(timer, ns);
pwm_ir->txbuf_index++;
-
- now = timer->base->get_time();
- } while (hrtimer_get_expires_tv64(timer) < now);
+ } while (hrtimer_expires_remaining(timer) > 0);
return HRTIMER_RESTART;
}
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 7/8] hrtimer: Use hrtimer_cb_get_time() helper
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
` (5 preceding siblings ...)
2025-08-12 6:08 ` [PATCH 6/8] media: pwm-ir-tx: " Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
2025-08-12 7:43 ` [PATCH 0/8] " Peter Zijlstra
8 siblings, 0 replies; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
Various other helpers contain open-coded implementations of
hrtimer_cb_get_time(). This prevents refactoring the implementation.
Reuse the existing helper.
For this to work, move hrtimer_cb_get_time() a bit up in the file and also
make its argument 'const'.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
include/linux/hrtimer.h | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 1ef867bb8c44b06812d8552441d4092922bfe170..e655502b14e6c4b1a69b67c997132d628bd1470f 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -154,14 +154,14 @@ static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer)
return ktime_to_ns(timer->node.expires);
}
-static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer)
+static inline ktime_t hrtimer_cb_get_time(const struct hrtimer *timer)
{
- return ktime_sub(timer->node.expires, timer->base->get_time());
+ return timer->base->get_time();
}
-static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
+static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer)
{
- return timer->base->get_time();
+ return ktime_sub(timer->node.expires, hrtimer_cb_get_time(timer));
}
static inline int hrtimer_is_hres_active(struct hrtimer *timer)
@@ -200,8 +200,7 @@ __hrtimer_expires_remaining_adjusted(const struct hrtimer *timer, ktime_t now)
static inline ktime_t
hrtimer_expires_remaining_adjusted(const struct hrtimer *timer)
{
- return __hrtimer_expires_remaining_adjusted(timer,
- timer->base->get_time());
+ return __hrtimer_expires_remaining_adjusted(timer, hrtimer_cb_get_time(timer));
}
#ifdef CONFIG_TIMERFD
@@ -363,7 +362,7 @@ hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
static inline u64 hrtimer_forward_now(struct hrtimer *timer,
ktime_t interval)
{
- return hrtimer_forward(timer, timer->base->get_time(), interval);
+ return hrtimer_forward(timer, hrtimer_cb_get_time(timer), interval);
}
/* Precise sleep: */
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
` (6 preceding siblings ...)
2025-08-12 6:08 ` [PATCH 7/8] hrtimer: Use hrtimer_cb_get_time() helper Thomas Weißschuh
@ 2025-08-12 6:08 ` Thomas Weißschuh
2025-08-12 7:42 ` Peter Zijlstra
2025-08-12 7:43 ` [PATCH 0/8] " Peter Zijlstra
8 siblings, 1 reply; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 6:08 UTC (permalink / raw)
To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham
Cc: linux-kernel, linux-sound, linux-media, Thomas Weißschuh
The get_time() callbacks always need to match the bases clockid.
Instead of maintaining that association twice in hrtimer_bases,
use a helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
include/linux/hrtimer.h | 5 +----
include/linux/hrtimer_defs.h | 2 --
kernel/time/hrtimer.c | 34 +++++++++++++++++++++++++---------
kernel/time/timer_list.c | 2 --
scripts/gdb/linux/timerlist.py | 2 --
5 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index e655502b14e6c4b1a69b67c997132d628bd1470f..2cf1bf65b22578499e7de5417dbda1d34cf12fce 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -154,10 +154,7 @@ static inline s64 hrtimer_get_expires_ns(const struct hrtimer *timer)
return ktime_to_ns(timer->node.expires);
}
-static inline ktime_t hrtimer_cb_get_time(const struct hrtimer *timer)
-{
- return timer->base->get_time();
-}
+ktime_t hrtimer_cb_get_time(const struct hrtimer *timer);
static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer)
{
diff --git a/include/linux/hrtimer_defs.h b/include/linux/hrtimer_defs.h
index 84a5045f80f36f88cb47bf23a62a4d0afbd1a2c6..aa49ffa130e57f7278a7d9f96a6d86e6630c69de 100644
--- a/include/linux/hrtimer_defs.h
+++ b/include/linux/hrtimer_defs.h
@@ -41,7 +41,6 @@
* @seq: seqcount around __run_hrtimer
* @running: pointer to the currently running hrtimer
* @active: red black tree root node for the active timers
- * @get_time: function to retrieve the current time of the clock
* @offset: offset of this clock to the monotonic base
*/
struct hrtimer_clock_base {
@@ -51,7 +50,6 @@ struct hrtimer_clock_base {
seqcount_raw_spinlock_t seq;
struct hrtimer *running;
struct timerqueue_head active;
- ktime_t (*get_time)(void);
ktime_t offset;
} __hrtimer_clock_base_align;
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 30899a8cc52c0a9203ce0216fe47f5f19a7bf6ec..4ce754a76ece537570a9a569dbdd95f51b575d78 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -59,6 +59,7 @@
#define HRTIMER_ACTIVE_ALL (HRTIMER_ACTIVE_SOFT | HRTIMER_ACTIVE_HARD)
static void retrigger_next_event(void *arg);
+static ktime_t __hrtimer_cb_get_time(clockid_t clock_id);
/*
* The timer bases:
@@ -76,42 +77,34 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
{
.index = HRTIMER_BASE_MONOTONIC,
.clockid = CLOCK_MONOTONIC,
- .get_time = &ktime_get,
},
{
.index = HRTIMER_BASE_REALTIME,
.clockid = CLOCK_REALTIME,
- .get_time = &ktime_get_real,
},
{
.index = HRTIMER_BASE_BOOTTIME,
.clockid = CLOCK_BOOTTIME,
- .get_time = &ktime_get_boottime,
},
{
.index = HRTIMER_BASE_TAI,
.clockid = CLOCK_TAI,
- .get_time = &ktime_get_clocktai,
},
{
.index = HRTIMER_BASE_MONOTONIC_SOFT,
.clockid = CLOCK_MONOTONIC,
- .get_time = &ktime_get,
},
{
.index = HRTIMER_BASE_REALTIME_SOFT,
.clockid = CLOCK_REALTIME,
- .get_time = &ktime_get_real,
},
{
.index = HRTIMER_BASE_BOOTTIME_SOFT,
.clockid = CLOCK_BOOTTIME,
- .get_time = &ktime_get_boottime,
},
{
.index = HRTIMER_BASE_TAI_SOFT,
.clockid = CLOCK_TAI,
- .get_time = &ktime_get_clocktai,
},
},
.csd = CSD_INIT(retrigger_next_event, NULL)
@@ -1253,7 +1246,7 @@ static int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
remove_hrtimer(timer, base, true, force_local);
if (mode & HRTIMER_MODE_REL)
- tim = ktime_add_safe(tim, base->get_time());
+ tim = ktime_add_safe(tim, __hrtimer_cb_get_time(base->clockid));
tim = hrtimer_update_lowres(timer, tim, mode);
@@ -1588,6 +1581,29 @@ static inline int hrtimer_clockid_to_base(clockid_t clock_id)
}
}
+static ktime_t __hrtimer_cb_get_time(clockid_t clock_id)
+{
+ switch (clock_id) {
+ case CLOCK_REALTIME:
+ return ktime_get_real();
+ case CLOCK_MONOTONIC:
+ return ktime_get();
+ case CLOCK_BOOTTIME:
+ return ktime_get_boottime();
+ case CLOCK_TAI:
+ return ktime_get_clocktai();
+ default:
+ WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
+ return ktime_get();
+ }
+}
+
+ktime_t hrtimer_cb_get_time(const struct hrtimer *timer)
+{
+ return __hrtimer_cb_get_time(timer->base->clockid);
+}
+EXPORT_SYMBOL_GPL(hrtimer_cb_get_time);
+
static void __hrtimer_setup(struct hrtimer *timer,
enum hrtimer_restart (*function)(struct hrtimer *),
clockid_t clock_id, enum hrtimer_mode mode)
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index b03d0ada64695058d4c57f3e29d546ba18bff591..488e47e96e93f96a5a18c0f72b8f4df36270943f 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -102,8 +102,6 @@ print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
SEQ_printf(m, " .index: %d\n", base->index);
SEQ_printf(m, " .resolution: %u nsecs\n", hrtimer_resolution);
-
- SEQ_printf(m, " .get_time: %ps\n", base->get_time);
#ifdef CONFIG_HIGH_RES_TIMERS
SEQ_printf(m, " .offset: %Lu nsecs\n",
(unsigned long long) ktime_to_ns(base->offset));
diff --git a/scripts/gdb/linux/timerlist.py b/scripts/gdb/linux/timerlist.py
index 98445671fe83897d50187f302f844919729388dc..ccc24d30de8063b28e0a3068416af341f8951876 100644
--- a/scripts/gdb/linux/timerlist.py
+++ b/scripts/gdb/linux/timerlist.py
@@ -56,8 +56,6 @@ def print_base(base):
text += " .index: {}\n".format(base['index'])
text += " .resolution: {} nsecs\n".format(constants.LX_hrtimer_resolution)
-
- text += " .get_time: {}\n".format(base['get_time'])
if constants.LX_CONFIG_HIGH_RES_TIMERS:
text += " .offset: {} nsecs\n".format(base['offset'])
text += "active timers:\n"
--
2.50.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time
2025-08-12 6:08 ` [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
@ 2025-08-12 7:42 ` Peter Zijlstra
2025-08-12 7:51 ` Thomas Weißschuh
0 siblings, 1 reply; 14+ messages in thread
From: Peter Zijlstra @ 2025-08-12 7:42 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Matt Wu, Andrew Morton, Jaroslav Kysela, Takashi Iwai, Sean Young,
Mauro Carvalho Chehab, Jan Kiszka, Kieran Bingham, linux-kernel,
linux-sound, linux-media
On Tue, Aug 12, 2025 at 08:08:16AM +0200, Thomas Weißschuh wrote:
> @@ -76,42 +77,34 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
> {
> .index = HRTIMER_BASE_MONOTONIC,
> .clockid = CLOCK_MONOTONIC,
> - .get_time = &ktime_get,
> },
> {
> .index = HRTIMER_BASE_REALTIME,
> .clockid = CLOCK_REALTIME,
> - .get_time = &ktime_get_real,
> },
> {
> .index = HRTIMER_BASE_BOOTTIME,
> .clockid = CLOCK_BOOTTIME,
> - .get_time = &ktime_get_boottime,
> },
> {
> .index = HRTIMER_BASE_TAI,
> .clockid = CLOCK_TAI,
> - .get_time = &ktime_get_clocktai,
> },
> {
> .index = HRTIMER_BASE_MONOTONIC_SOFT,
> .clockid = CLOCK_MONOTONIC,
> - .get_time = &ktime_get,
> },
> {
> .index = HRTIMER_BASE_REALTIME_SOFT,
> .clockid = CLOCK_REALTIME,
> - .get_time = &ktime_get_real,
> },
> {
> .index = HRTIMER_BASE_BOOTTIME_SOFT,
> .clockid = CLOCK_BOOTTIME,
> - .get_time = &ktime_get_boottime,
> },
> {
> .index = HRTIMER_BASE_TAI_SOFT,
> .clockid = CLOCK_TAI,
> - .get_time = &ktime_get_clocktai,
> },
> },
> .csd = CSD_INIT(retrigger_next_event, NULL)
> @@ -1253,7 +1246,7 @@ static int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
> remove_hrtimer(timer, base, true, force_local);
>
> if (mode & HRTIMER_MODE_REL)
> - tim = ktime_add_safe(tim, base->get_time());
> + tim = ktime_add_safe(tim, __hrtimer_cb_get_time(base->clockid));
>
> tim = hrtimer_update_lowres(timer, tim, mode);
>
> @@ -1588,6 +1581,29 @@ static inline int hrtimer_clockid_to_base(clockid_t clock_id)
> }
> }
>
> +static ktime_t __hrtimer_cb_get_time(clockid_t clock_id)
> +{
> + switch (clock_id) {
> + case CLOCK_REALTIME:
> + return ktime_get_real();
> + case CLOCK_MONOTONIC:
> + return ktime_get();
> + case CLOCK_BOOTTIME:
> + return ktime_get_boottime();
> + case CLOCK_TAI:
> + return ktime_get_clocktai();
It would've been nice if these had the same order as the other array.
> + default:
> + WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
> + return ktime_get();
> + }
> +}
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
` (7 preceding siblings ...)
2025-08-12 6:08 ` [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
@ 2025-08-12 7:43 ` Peter Zijlstra
8 siblings, 0 replies; 14+ messages in thread
From: Peter Zijlstra @ 2025-08-12 7:43 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Matt Wu, Andrew Morton, Jaroslav Kysela, Takashi Iwai, Sean Young,
Mauro Carvalho Chehab, Jan Kiszka, Kieran Bingham, linux-kernel,
linux-sound, linux-media
On Tue, Aug 12, 2025 at 08:08:08AM +0200, Thomas Weißschuh wrote:
> The get_time() callbacks always need to match the bases clockid.
> Instead of maintaining that association twice in hrtimer_bases,
> use a helper.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Thomas Weißschuh (8):
> posix-timers: Avoid direct access to hrtimer clockbase
> timers/itimer: Avoid direct access to hrtimer clockbase
> sched/core: Avoid direct access to hrtimer clockbase
> lib: test_objpool: Avoid direct access to hrtimer clockbase
> ALSA: hrtimer: Avoid direct access to hrtimer clockbase
> media: pwm-ir-tx: Avoid direct access to hrtimer clockbase
> hrtimer: Use hrtimer_cb_get_time() helper
> hrtimer: Remove hrtimer_clock_base::get_time
>
> drivers/media/rc/pwm-ir-tx.c | 5 +----
> include/linux/hrtimer.h | 14 +++++---------
> include/linux/hrtimer_defs.h | 2 --
> kernel/sched/core.c | 2 +-
> kernel/time/hrtimer.c | 34 +++++++++++++++++++++++++---------
> kernel/time/itimer.c | 3 +--
> kernel/time/posix-timers.c | 5 ++---
> kernel/time/timer_list.c | 2 --
> lib/test_objpool.c | 2 +-
> scripts/gdb/linux/timerlist.py | 2 --
> sound/core/hrtimer.c | 2 +-
> 11 files changed, 37 insertions(+), 36 deletions(-)
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time
2025-08-12 7:42 ` Peter Zijlstra
@ 2025-08-12 7:51 ` Thomas Weißschuh
0 siblings, 0 replies; 14+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 7:51 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
Matt Wu, Andrew Morton, Jaroslav Kysela, Takashi Iwai, Sean Young,
Mauro Carvalho Chehab, Jan Kiszka, Kieran Bingham, linux-kernel,
linux-sound, linux-media
On Tue, Aug 12, 2025 at 09:42:46AM +0200, Peter Zijlstra wrote:
> On Tue, Aug 12, 2025 at 08:08:16AM +0200, Thomas Weißschuh wrote:
>
> > @@ -76,42 +77,34 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
> > {
> > .index = HRTIMER_BASE_MONOTONIC,
> > .clockid = CLOCK_MONOTONIC,
> > - .get_time = &ktime_get,
> > },
> > {
> > .index = HRTIMER_BASE_REALTIME,
> > .clockid = CLOCK_REALTIME,
> > - .get_time = &ktime_get_real,
> > },
> > {
> > .index = HRTIMER_BASE_BOOTTIME,
> > .clockid = CLOCK_BOOTTIME,
> > - .get_time = &ktime_get_boottime,
> > },
> > {
> > .index = HRTIMER_BASE_TAI,
> > .clockid = CLOCK_TAI,
> > - .get_time = &ktime_get_clocktai,
> > },
> > {
> > .index = HRTIMER_BASE_MONOTONIC_SOFT,
> > .clockid = CLOCK_MONOTONIC,
> > - .get_time = &ktime_get,
> > },
> > {
> > .index = HRTIMER_BASE_REALTIME_SOFT,
> > .clockid = CLOCK_REALTIME,
> > - .get_time = &ktime_get_real,
> > },
> > {
> > .index = HRTIMER_BASE_BOOTTIME_SOFT,
> > .clockid = CLOCK_BOOTTIME,
> > - .get_time = &ktime_get_boottime,
> > },
> > {
> > .index = HRTIMER_BASE_TAI_SOFT,
> > .clockid = CLOCK_TAI,
> > - .get_time = &ktime_get_clocktai,
> > },
> > },
> > .csd = CSD_INIT(retrigger_next_event, NULL)
> > @@ -1253,7 +1246,7 @@ static int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
> > remove_hrtimer(timer, base, true, force_local);
> >
> > if (mode & HRTIMER_MODE_REL)
> > - tim = ktime_add_safe(tim, base->get_time());
> > + tim = ktime_add_safe(tim, __hrtimer_cb_get_time(base->clockid));
> >
> > tim = hrtimer_update_lowres(timer, tim, mode);
> >
> > @@ -1588,6 +1581,29 @@ static inline int hrtimer_clockid_to_base(clockid_t clock_id)
> > }
> > }
> >
> > +static ktime_t __hrtimer_cb_get_time(clockid_t clock_id)
> > +{
> > + switch (clock_id) {
> > + case CLOCK_REALTIME:
> > + return ktime_get_real();
> > + case CLOCK_MONOTONIC:
> > + return ktime_get();
> > + case CLOCK_BOOTTIME:
> > + return ktime_get_boottime();
> > + case CLOCK_TAI:
> > + return ktime_get_clocktai();
>
> It would've been nice if these had the same order as the other array.
Yeah. This is the same order as in hrtimer_clockid_to_base(), right above
this function. I'll add a patch to reorder that one, too.
>
> > + default:
> > + WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
> > + return ktime_get();
> > + }
> > +}
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 5/8] ALSA: hrtimer: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 ` [PATCH 5/8] ALSA: hrtimer: " Thomas Weißschuh
@ 2025-08-12 11:07 ` Takashi Iwai
0 siblings, 0 replies; 14+ messages in thread
From: Takashi Iwai @ 2025-08-12 11:07 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Sean Young, Mauro Carvalho Chehab, Jan Kiszka,
Kieran Bingham, linux-kernel, linux-sound, linux-media
On Tue, 12 Aug 2025 08:08:13 +0200,
Thomas Weißschuh wrote:
>
> The field timer->base->get_time is a private implementation detail and
> should not be accessed outside of the hrtimer core.
>
> Switch to the equivalent helper.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> sound/core/hrtimer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
> index c364bd126ac8b311e3ce899e226ff9fd82c4485f..2d5f4d47071f79d7db24c8f004f0f4154808fdd8 100644
> --- a/sound/core/hrtimer.c
> +++ b/sound/core/hrtimer.c
> @@ -44,7 +44,7 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
> }
>
> /* calculate the drift */
> - delta = ktime_sub(hrt->base->get_time(), hrtimer_get_expires(hrt));
> + delta = ktime_sub(hrtimer_cb_get_time(hrt), hrtimer_get_expires(hrt));
> if (delta > 0)
> ticks += ktime_divns(delta, ticks * resolution);
Acked-by: Takashi Iwai <tiwai@suse.de>
thanks,
Takashi
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 6/8] media: pwm-ir-tx: Avoid direct access to hrtimer clockbase
2025-08-12 6:08 ` [PATCH 6/8] media: pwm-ir-tx: " Thomas Weißschuh
@ 2025-08-12 12:06 ` Sean Young
0 siblings, 0 replies; 14+ messages in thread
From: Sean Young @ 2025-08-12 12:06 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, Matt Wu, Andrew Morton, Jaroslav Kysela,
Takashi Iwai, Mauro Carvalho Chehab, Jan Kiszka, Kieran Bingham,
linux-kernel, linux-sound, linux-media
On Tue, Aug 12, 2025 at 08:08:14AM +0200, Thomas Weißschuh wrote:
> The field timer->base->get_time is a private implementation detail and
> should not be accessed outside of the hrtimer core.
>
> Switch to an equivalent higher-level helper.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> drivers/media/rc/pwm-ir-tx.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/media/rc/pwm-ir-tx.c b/drivers/media/rc/pwm-ir-tx.c
> index 84533fdd61aa6ce3c0f8593aaefe5919fd05c7f9..047472dc9244afe0e56e505be20f36fd7d9c449a 100644
> --- a/drivers/media/rc/pwm-ir-tx.c
> +++ b/drivers/media/rc/pwm-ir-tx.c
> @@ -117,7 +117,6 @@ static int pwm_ir_tx_atomic(struct rc_dev *dev, unsigned int *txbuf,
> static enum hrtimer_restart pwm_ir_timer(struct hrtimer *timer)
> {
> struct pwm_ir *pwm_ir = container_of(timer, struct pwm_ir, timer);
> - ktime_t now;
>
> /*
> * If we happen to hit an odd latency spike, loop through the
> @@ -139,9 +138,7 @@ static enum hrtimer_restart pwm_ir_timer(struct hrtimer *timer)
> hrtimer_add_expires_ns(timer, ns);
>
> pwm_ir->txbuf_index++;
> -
> - now = timer->base->get_time();
> - } while (hrtimer_get_expires_tv64(timer) < now);
> + } while (hrtimer_expires_remaining(timer) > 0);
Acked-by: Sean Young <sean@mess.org>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2025-08-12 12:07 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 6:08 [PATCH 0/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 1/8] posix-timers: Avoid direct access to hrtimer clockbase Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 2/8] timers/itimer: " Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 3/8] sched/core: " Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 4/8] lib: test_objpool: " Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 5/8] ALSA: hrtimer: " Thomas Weißschuh
2025-08-12 11:07 ` Takashi Iwai
2025-08-12 6:08 ` [PATCH 6/8] media: pwm-ir-tx: " Thomas Weißschuh
2025-08-12 12:06 ` Sean Young
2025-08-12 6:08 ` [PATCH 7/8] hrtimer: Use hrtimer_cb_get_time() helper Thomas Weißschuh
2025-08-12 6:08 ` [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time Thomas Weißschuh
2025-08-12 7:42 ` Peter Zijlstra
2025-08-12 7:51 ` Thomas Weißschuh
2025-08-12 7:43 ` [PATCH 0/8] " Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).