mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] timers: Report disarmed alarm timerfds and SIGEV_NONE timers as disarmed
@ 2026-10-11  5:19 Shashank Mohan Jain
  2026-10-11  5:19 ` [PATCH 1/3] alarmtimer: Reset the expiry time in alarm_init() Shashank Mohan Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Shashank Mohan Jain @ 2026-10-11  5:19 UTC (permalink / raw)
  To: Thomas Gleixner, John Stultz, Anna-Maria Behnsen, Frederic Weisbecker
  Cc: Stephen Boyd, Miroslav Lichvar, Shuah Khan, Todd Poynor,
	linux-kernel, linux-kselftest

Two interfaces keep reporting the remaining time of the previous
setting after a timer was disarmed with a zero it_value, until the old
expiry time has passed:

 - timerfd_gettime() for timerfds on CLOCK_REALTIME_ALARM and
   CLOCK_BOOTTIME_ALARM (patch 1). The timerfds on the hrtimer based
   clocks report zero.

 - timer_gettime() for SIGEV_NONE timers on CLOCK_MONOTONIC,
   CLOCK_BOOTTIME, CLOCK_REALTIME and the alarm clocks (patch 2).
   Timers with signal delivery and the CPU time clocks report zero.

In both cases the stale expiry time of a timer which is not queued is
used to compute the remaining time. Patch 1 resets it in alarm_init(),
patch 2 moves it into the past when a SIGEV_NONE timer is disarmed.
Patch 3 adds a test for the second case to the posix_timers selftest.

The first problem was found by reading fs/timerfd.c, the second one
when the test program for the first was extended to POSIX timers.
Both are old: the first exists since timerfd got alarm clock support,
the second is also there in a v6.8 based distribution kernel.

Patch 2 uses the timer_arm() callback with an expiry time of 0 to
reset the stored expiry time, because that needs no new callback. If
a dedicated callback or a different place is preferred, I can redo it
that way.

Tested in qemu (x86_64) on top of mainline a5ebb76233b7 (v7.3-rc6+)
with a program which runs the arm/disarm/gettime sequence on all five
clocks for timerfd and for POSIX timers with SIGEV_SIGNAL and
SIGEV_NONE: 9 wrong results without the series, none with it. The
posix_timers selftest with patch 3 fails the new CLOCK_MONOTONIC test
without patch 2 and passes all 21 tests with it. The patches also
apply to next-20261009.

Shashank Mohan Jain (3):
  alarmtimer: Reset the expiry time in alarm_init()
  posix-timers: Report a disarmed SIGEV_NONE timer as disarmed
  selftests/timers: Test timer_gettime() on a disarmed SIGEV_NONE timer

 kernel/time/alarmtimer.c                      |  1 +
 kernel/time/posix-timers.c                    | 12 +++++-
 tools/testing/selftests/timers/posix_timers.c | 38 ++++++++++++++++++-
 3 files changed, 48 insertions(+), 3 deletions(-)


base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-11  5:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-11  5:19 [PATCH 0/3] timers: Report disarmed alarm timerfds and SIGEV_NONE timers as disarmed Shashank Mohan Jain
2026-10-11  5:19 ` [PATCH 1/3] alarmtimer: Reset the expiry time in alarm_init() Shashank Mohan Jain
2026-10-11  5:19 ` [PATCH 2/3] posix-timers: Report a disarmed SIGEV_NONE timer as disarmed Shashank Mohan Jain
2026-10-11  5:19 ` [PATCH 3/3] selftests/timers: Test timer_gettime() on a disarmed SIGEV_NONE timer Shashank Mohan Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®