Skip to content

hrtimer: Add cleanup class for on-stack timers

Hui Su lkml 1 version Applied

Status from this message: The following commit has been merged into the timers/urgent branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest2 patches 0 repliesApplied

Changes in v2 from the cover letter

- 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.

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/2hrtimer: Add cleanup class for on-stack timersinclude/linux/hrtimer.h kernel/time/hrtimer.c+30 -20 replies
2/2sched/idle: Use hrtimer cleanup class in play_idle_precise()kernel/sched/idle.c+10 -60 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] hrtimer: Add cleanup class for on-stack timers

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/[email protected]/

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

Signature · 1 line
2.55.0