From: Shashank Mohan Jain <jain.sm@gmail.com>
To: Thomas Gleixner <tglx@kernel.org>,
John Stultz <jstultz@google.com>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>
Cc: Stephen Boyd <sboyd@kernel.org>,
Miroslav Lichvar <mlichvar@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Todd Poynor <toddpoynor@google.com>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH 0/3] timers: Report disarmed alarm timerfds and SIGEV_NONE timers as disarmed
Date: Sun, 11 Oct 2026 10:49:40 +0530 [thread overview]
Message-ID: <20261011051943.60520-1-jain.sm@gmail.com> (raw)
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
next reply other threads:[~2026-10-11 5:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 5:19 Shashank Mohan Jain [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261011051943.60520-1-jain.sm@gmail.com \
--to=jain.sm@gmail.com \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=sboyd@kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=toddpoynor@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®