[PATCH v2 0/2] hrtimer: Add cleanup class for on-stack timers
From: Hui Su
Date: Thu Oct 15 2026 - 21:16:43 EST
Add an opt-in cleanup class that pairs hrtimer_setup_on_stack() with
destroy_hrtimer_on_stack(), and convert play_idle_precise() to use it.
The class provides debug-object teardown, not timer cancellation. The
converted caller limits the cleanup object's lifetime to the block covering
timer start and the idle wait, which ends only after the pinned hard hrtimer
callback has completed.
Testing:
- x86_64 QEMU with CONFIG_DEBUG_OBJECTS_TIMERS=y: baseline setup=301,
play_idle_precise return=301, free=0; the patched kernel recorded
setup=301, play_idle_precise return=301, free=301 for the same timer
address, with no ODEBUG warning.
- x86_64 GCC 15.2.0: the series built bzImage/modules, and
kernel/sched/idle.o also built with CONFIG_DEBUG_OBJECTS_TIMERS=n.
Changes in v2:
- Add an hrtimer_on_stack cleanup class following Peter's suggestion to use
__cleanup() for the setup/destroy pairing.
- Document the hrtimer_setup_on_stack() lifetime requirements.
- Convert play_idle_precise() using CLASS() in an explicit block and explain
the callback ordering.
v1: https://lore.kernel.org/lkml/20261015025029.3356060-1-sh_def@xxxxxxx/
Hui Su (2):
hrtimer: Add cleanup class for on-stack timers
sched/idle: Use hrtimer cleanup class in play_idle_precise()
include/linux/hrtimer.h | 24 ++++++++++++++++++++++++
kernel/sched/idle.c | 16 ++++++++++------
kernel/time/hrtimer.c | 8 ++++++--
3 files changed, 40 insertions(+), 8 deletions(-)
base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
--
2.55.0