[v9,17/32] timers: Introduce add_timer() variants which modify timer flags

Message ID 20231201092654.34614-18-anna-maria@linutronix.de
State New
Headers
Series timers: Move from a push remote at enqueue to a pull at expiry model |

Commit Message

Anna-Maria Behnsen Dec. 1, 2023, 9:26 a.m. UTC
  Timer might be used as pinned timer (using add_timer_on()) and later on as
non pinned timers using add_timer(). When the NOHZ timer pull at expiry
model is in place, TIMER_PINNED flag is required to be used whenever a
timer needs to expire on a dedicated CPU. Flag must no be set, if
expiration on a dedicated CPU is not required.

add_timer_on()'s behavior will be changed during the preparation patches
for the NOHZ timer pull at expiry model to unconditionally set TIMER_PINNED
flag. To be able to reset/set the flag when queueing a timer, two variants
of add_timer() are introduced.

This is a preparatory patch and has no functional change.

Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
---
v9: Update documentation to match kernel-doc style (missing brackets after
    function names)

New in v6
---
 include/linux/timer.h |  2 ++
 kernel/time/timer.c   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
  

Comments

Sebastian Andrzej Siewior Dec. 5, 2023, 6:28 p.m. UTC | #1
On 2023-12-01 10:26:39 [+0100], Anna-Maria Behnsen wrote:
> Timer might be used as pinned timer (using add_timer_on()) and later on as
> non pinned timers using add_timer(). When the NOHZ timer pull at expiry
> model is in place, TIMER_PINNED flag is required to be used whenever a
> timer needs to expire on a dedicated CPU. Flag must no be set, if
> expiration on a dedicated CPU is not required.

Slightly reworded.

| A timer might be used as a pinned timer (using add_timer_on()) and later
| on as non-pinned timer using add_timer(). When the "NOHZ timer pull at
| expiry model" is in place, the TIMER_PINNED flag is required to be used
| whenever a timer needs to expire on a dedicated CPU. Otherwise the flag
| must not be set if expiration on a dedicated CPU is not required.

> add_timer_on()'s behavior will be changed during the preparation patches
> for the NOHZ timer pull at expiry model to unconditionally set TIMER_PINNED
> flag. To be able to reset/set the flag when queueing a timer, two variants
> of add_timer() are introduced.

and here.

| add_timer_on()'s behavior will be changed during the preparation patches
| for the "NOHZ timer pull at expiry model" to unconditionally set
| TIMER_PINNED flag. To be able to clear/ set the flag when queueing a
| timer, two variants of add_timer() are introduced.

I let you be judge of this.

Sebastian
  
Anna-Maria Behnsen Dec. 6, 2023, 9:24 a.m. UTC | #2
Sebastian Siewior <bigeasy@linutronix.de> writes:

> On 2023-12-01 10:26:39 [+0100], Anna-Maria Behnsen wrote:
>> Timer might be used as pinned timer (using add_timer_on()) and later on as
>> non pinned timers using add_timer(). When the NOHZ timer pull at expiry
>> model is in place, TIMER_PINNED flag is required to be used whenever a
>> timer needs to expire on a dedicated CPU. Flag must no be set, if
>> expiration on a dedicated CPU is not required.
>
> Slightly reworded.
>
> | A timer might be used as a pinned timer (using add_timer_on()) and later
> | on as non-pinned timer using add_timer(). When the "NOHZ timer pull at
> | expiry model" is in place, the TIMER_PINNED flag is required to be used
> | whenever a timer needs to expire on a dedicated CPU. Otherwise the flag
> | must not be set if expiration on a dedicated CPU is not required.
>
>> add_timer_on()'s behavior will be changed during the preparation patches
>> for the NOHZ timer pull at expiry model to unconditionally set TIMER_PINNED
>> flag. To be able to reset/set the flag when queueing a timer, two variants
>> of add_timer() are introduced.
>
> and here.
>
> | add_timer_on()'s behavior will be changed during the preparation patches
> | for the "NOHZ timer pull at expiry model" to unconditionally set
> | TIMER_PINNED flag. To be able to clear/ set the flag when queueing a
> | timer, two variants of add_timer() are introduced.
>
> I let you be judge of this.

I will take your reworded version.

Thanks,
	Anna-Maria
  

Patch

diff --git a/include/linux/timer.h b/include/linux/timer.h
index 26a545bb0153..404bb31a95c7 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -179,6 +179,8 @@  extern int timer_reduce(struct timer_list *timer, unsigned long expires);
 #define NEXT_TIMER_MAX_DELTA	((1UL << 30) - 1)
 
 extern void add_timer(struct timer_list *timer);
+extern void add_timer_local(struct timer_list *timer);
+extern void add_timer_global(struct timer_list *timer);
 
 extern int try_to_del_timer_sync(struct timer_list *timer);
 extern int timer_delete_sync(struct timer_list *timer);
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 177bcde8a2c0..0ce0e6b25482 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1245,6 +1245,40 @@  void add_timer(struct timer_list *timer)
 }
 EXPORT_SYMBOL(add_timer);
 
+/**
+ * add_timer_local() - Start a timer on the local CPU
+ * @timer:	The timer to be started
+ *
+ * Same as add_timer() except that the timer flag TIMER_PINNED is set.
+ *
+ * See add_timer() for further details.
+ */
+void add_timer_local(struct timer_list *timer)
+{
+	if (WARN_ON_ONCE(timer_pending(timer)))
+		return;
+	timer->flags |= TIMER_PINNED;
+	__mod_timer(timer, timer->expires, MOD_TIMER_NOTPENDING);
+}
+EXPORT_SYMBOL(add_timer_local);
+
+/**
+ * add_timer_global() - Start a timer without TIMER_PINNED flag set
+ * @timer:	The timer to be started
+ *
+ * Same as add_timer() except that the timer flag TIMER_PINNED is unset.
+ *
+ * See add_timer() for further details.
+ */
+void add_timer_global(struct timer_list *timer)
+{
+	if (WARN_ON_ONCE(timer_pending(timer)))
+		return;
+	timer->flags &= ~TIMER_PINNED;
+	__mod_timer(timer, timer->expires, MOD_TIMER_NOTPENDING);
+}
+EXPORT_SYMBOL(add_timer_global);
+
 /**
  * add_timer_on - Start a timer on a particular CPU
  * @timer:	The timer to be started