[PATCH v2 0/2] timerfd: Support CLOCK_TAI

From: Chris Down

Date: Sat Nov 28 2026 - 04:37:04 EST


Both hrtimers and POSIX timers accept CLOCK_TAI, but timerfd_create()
rejects it. An application with TAI deadlines and an epoll based event
loop is left with two options. It can convert the deadlines to
CLOCK_REALTIME, which brings back the exposure to wall clock jumps it
was trying to avoid, or it can stop using timerfd.

Patch 1 makes timerfd_create() accept CLOCK_TAI and makes
TFD_TIMER_CANCEL_ON_SET work for it. A CLOCK_TAI timer is cancelled when
CLOCK_REALTIME is set and when adjtimex(ADJ_TAI) changes the TAI offset.
Nothing changes for CLOCK_REALTIME timers.

Patch 2 adds a selftest for this.

There are two existing limitations I noticed which I have not fixed here:

- Relative CLOCK_TAI timers stay on the TAI base, but hrtimer_setup()
moves relative CLOCK_REALTIME timers to CLOCK_MONOTONIC. That makes a
relative CLOCK_TAI timerfd expire early if the clock is stepped
forwards. The same happens with timer_settime() and clock_nanosleep()
on CLOCK_TAI today. TFD_TIMER_CANCEL_ON_SET does not report it because
it only applies to absolute timers.
- The offset which cancel on set compares against is first recorded in
timerfd_create() rather than when the timer is armed. If the clock is
stepped between the two, the next clock_was_set() cancels the timer
even if nothing moved, and a later step back by the same amount is not
reported. This happens with CLOCK_REALTIME timers today.

I can send patches for these separately if you think they are worth
fixing.

v2:

- Make TFD_TIMER_CANCEL_ON_SET work for CLOCK_TAI timers (tglx)
- Add a selftest
- Rebase onto tip timers/core

v1: https://lore.kernel.org/r/abuTTv9FC__H_8RC@xxxxxxxxxxxxxx

Chris Down (2):
timerfd: Support CLOCK_TAI
selftests: timers: Add a test for CLOCK_TAI timerfds

fs/timerfd.c | 20 +-
tools/testing/selftests/timers/.gitignore | 1 +
tools/testing/selftests/timers/Makefile | 2 +-
tools/testing/selftests/timers/timerfd-tai.c | 183 +++++++++++++++++++
4 files changed, 201 insertions(+), 5 deletions(-)
create mode 100644 tools/testing/selftests/timers/timerfd-tai.c


base-commit: 0359ecff58853a491dd0f09792fea8e87235ae06
--
2.56.1