Re: [patch V3 14/17] timers: Add shutdown mechanism to the internal functions
From: Anna-Maria Behnsen
Date: Thu Nov 24 2022 - 08:48:08 EST
On Wed, 23 Nov 2022, Thomas Gleixner wrote:
> Tearing down timers which have circular dependencies to other
> functionality, e.g. workqueues, where the timer can schedule work and work
> can arm timers, is not trivial.
>
> In those cases it is desired to shutdown the timer in a way which prevents
> rearming of the timer. The mechanism to do so is to set timer->function to
> NULL and use this as an indicator for the timer arming functions to ignore
> the (re)arm request.
>
> Add a shutdown argument to the relevant internal functions which makes the
> actual deactivation code set timer->function to NULL which in turn prevents
> rearming of the timer.
>
> Co-developed-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Tested-by: Guenter Roeck <linux@xxxxxxxxxxxx>
> Reviewed-by: Jacob Keller <jacob.e.keller@xxxxxxxxx>
> Link: https://lore.kernel.org/all/20220407161745.7d6754b3@xxxxxxxxxxxxxxxxxx
> Link: https://lore.kernel.org/all/20221110064101.429013735@xxxxxxxxxxx
> ---
> V2: Add missing commata (Steven)
> V3: Changelog updates (Anna-Maria)
> ---
> kernel/time/timer.c | 64 ++++++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 55 insertions(+), 9 deletions(-)
>
> --- a/kernel/time/timer.c
> +++ b/kernel/time/timer.c
> @@ -1297,14 +1297,21 @@ void add_timer_on(struct timer_list *tim
> EXPORT_SYMBOL_GPL(add_timer_on);
>
> /**
> - * __timer_delete - Internal function: Deactivate a timer.
> + * __timer_delete - Internal function: Deactivate a timer
Some more NIT: You already updated the line a patch before. Maybe remove
the dot in the patch before and you get rid of this unneccessary
delete/insert of the above line in this hunk.
> * @timer: The timer to be deactivated
> + * @shutdown: If true, this indicates that the timer is about to be
> + * shutdown permanently.
> + *
> + * If @shutdown is true then @timer->function is set to NULL under the
> + * timer base lock which prevents further rearming of the time. In that
> + * case any attempt to rearm @timer after this function returns will be
> + * silently ignored.
> *
> * Return:
> * * %0 - The timer was not pending
> * * %1 - The timer was pending and deactivated
> */
> -static int __timer_delete(struct timer_list *timer)
> +static int __timer_delete(struct timer_list *timer, bool shutdown)
> {
> struct timer_base *base;
> unsigned long flags;
Thanks,
Anna-Maria