[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221121172157.2457df06@gandalf.local.home>
Date: Mon, 21 Nov 2022 17:21:57 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: LKML <linux-kernel@...r.kernel.org>,
Linus Torvalds <torvalds@...uxfoundation.org>,
Anna-Maria Behnsen <anna-maria@...utronix.de>,
Peter Zijlstra <peterz@...radead.org>,
Stephen Boyd <sboyd@...nel.org>,
Guenter Roeck <linux@...ck-us.net>,
Andrew Morton <akpm@...ux-foundation.org>,
Julia Lawall <Julia.Lawall@...ia.fr>,
Arnd Bergmann <arnd@...db.de>,
Viresh Kumar <viresh.kumar@...aro.org>,
Marc Zyngier <maz@...nel.org>,
Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Luiz Augusto von Dentz <luiz.dentz@...il.com>,
linux-bluetooth@...r.kernel.org,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, netdev@...r.kernel.org
Subject: Re: [patch 13/15] timers: Provide timer_shutdown[_sync]()
On Tue, 15 Nov 2022 21:28:54 +0100 (CET)
Thomas Gleixner <tglx@...utronix.de> wrote:
> +/**
> + * timer_shutdown_sync - Shutdown a timer and prevent rearming
> + * @timer: The timer to be shutdown
> + *
> + * When the function returns it is guaranteed that:
> + * - @timer is not queued
> + * - The callback function of @timer is not running
> + * - @timer cannot be enqueued again. Any attempt to rearm
> + * @timer is silently ignored.
> + *
> + * See timer_delete_sync() for synchronization rules.
"See timer_delete_sync() for synchronization and context rules."
As where it can be executed is as important as the synchronization that is
needed.
-- Steve
> + *
> + * This function is useful for final teardown of an infrastructure where
> + * the timer is subject to a circular dependency problem.
> + *
> + * A common pattern for this is a timer and a workqueue where the timer can
> + * schedule work and work can arm the timer. On shutdown the workqueue must
> + * be destroyed and the timer must be prevented from rearming. Unless the
> + * code has conditionals like 'if (mything->in_shutdown)' to prevent that
> + * there is no way to get this correct with timer_delete_sync().
> + *
> + * timer_shutdown_sync() is solving the problem. The correct ordering of
> + * calls in this case is:
> + *
> + * timer_shutdown_sync(&mything->timer);
> + * workqueue_destroy(&mything->workqueue);
> + *
> + * After this 'mything' can be safely freed.
> + *
> + * This obviously requires that the timer is not required to be functional
> + * for the rest of the shutdown operation.
> + *
> + * Return:
> + * * %0 - The timer was not pending
> + * * %1 - The timer was pending
> + */
> +int timer_shutdown_sync(struct timer_list *timer)
> +{
> + return __timer_delete_sync(timer, true);
> +}
> +EXPORT_SYMBOL_GPL(timer_shutdown_sync);
> +
Powered by blists - more mailing lists