mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh (Schneider Electric)" <thomas.weissschuh@linutronix.de>
To: Jan Kiszka <jan.kiszka@siemens.com>,
	 Kieran Bingham <kbingham@kernel.org>,
	John Stultz <jstultz@google.com>,
	 Thomas Gleixner <tglx@kernel.org>,
	 Anna-Maria Behnsen <anna-maria@linutronix.de>,
	 Steven Rostedt <rostedt@goodmis.org>,
	 Masami Hiramatsu <mhiramat@kernel.org>,
	 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	 Frederic Weisbecker <frederic@kernel.org>,
	Stephen Boyd <sboyd@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	"Thomas Weißschuh (Schneider Electric)"
	<thomas.weissschuh@linutronix.de>
Subject: [PATCH 12/12] hrtimer: Add a helper to retrieve a hrtimer from its timerqueue node
Date: Wed, 11 Mar 2026 11:15:21 +0100	[thread overview]
Message-ID: <20260311-hrtimer-cleanups-v1-12-095357392669@linutronix.de> (raw)
In-Reply-To: <20260311-hrtimer-cleanups-v1-0-095357392669@linutronix.de>

The container_of() call is open-coded multiple times.

Add a helper macro.

Use container_of_const() to preserve constness.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
---
 kernel/time/hrtimer.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index d350bceb3c95..94955f967207 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -534,6 +534,8 @@ static inline void debug_activate(struct hrtimer *timer, enum hrtimer_mode mode,
 		for (bool done = false; !done; active &= ~(1U << idx))			\
 			for (base = &cpu_base->clock_base[idx]; !done; done = true)
 
+#define hrtimer_from_timerqueue_node(_n) container_of_const(_n, struct hrtimer, node)
+
 #if defined(CONFIG_NO_HZ_COMMON)
 /*
  * Same as hrtimer_bases_next_event() below, but skips the excluded timer and
@@ -578,7 +580,7 @@ static __always_inline struct hrtimer *clock_base_next_timer(struct hrtimer_cloc
 {
 	struct timerqueue_linked_node *next = timerqueue_linked_first(&base->active);
 
-	return container_of(next, struct hrtimer, node);
+	return hrtimer_from_timerqueue_node(next);
 }
 
 /* Find the base with the earliest expiry */
@@ -1960,7 +1962,7 @@ static __always_inline struct hrtimer *clock_base_next_timer_safe(struct hrtimer
 {
 	struct timerqueue_linked_node *next = timerqueue_linked_first(&base->active);
 
-	return next ? container_of(next, struct hrtimer, node) : NULL;
+	return next ? hrtimer_from_timerqueue_node(next) : NULL;
 }
 
 static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now,
@@ -2438,7 +2440,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
 	struct hrtimer *timer;
 
 	while ((node = timerqueue_linked_first(&old_base->active))) {
-		timer = container_of(node, struct hrtimer, node);
+		timer = hrtimer_from_timerqueue_node(node);
 		BUG_ON(hrtimer_callback_running(timer));
 		debug_hrtimer_deactivate(timer);
 

-- 
2.53.0


  parent reply	other threads:[~2026-03-11 10:16 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 10:15 [PATCH 00/12] hrtimer, timekeeping, tracing: various cleanups Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 01/12] scripts/gdb: timerlist: Adapt to move of tk_core Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 02/12] tracing: Use explicit array size instead of sentinel elements in symbol printing Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 03/12] timer_list: Print offset as signed integer Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 04/12] timekeeping: auxclock: Consistently use raw timekeeper for tk_setup_internals() Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] timekeeping/auxclock: " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 05/12] timekeeping: Mark offsets array as const Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 06/12] hrtimer: Remove hrtimer_get_expires_ns() Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 07/12] hrtimer: Don't zero-initialize ret in hrtimer_nanosleep() Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 08/12] hrtimer: Drop spurious space in 'enum hrtimer_base_type' Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 09/12] hrtimer: Drop unnecessary pointer indirection in hrtimer_expire_entry event Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 10/12] hrtimer: Mark index and clockid of clock base as const Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` [PATCH 11/12] hrtimer: Remove trailing comma after HRTIMER_MAX_CLOCK_BASES Thomas Weißschuh (Schneider Electric)
2026-03-12 11:25   ` [tip: timers/core] " tip-bot2 for Thomas Weißschuh (Schneider Electric)
2026-03-11 10:15 ` Thomas Weißschuh (Schneider Electric) [this message]
2026-03-12 11:25   ` [tip: timers/core] hrtimer: Add a helper to retrieve a hrtimer from its timerqueue node 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=20260311-hrtimer-cleanups-v1-12-095357392669@linutronix.de \
    --to=thomas.weissschuh@linutronix.de \
    --cc=anna-maria@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=jan.kiszka@siemens.com \
    --cc=jstultz@google.com \
    --cc=kbingham@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@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®