timerfd: Support CLOCK_TAI
Subsystems (2)
PATCH 1/1 timerfd: Support CLOCK_TAI
Despite hrtimer and POSIX timers both accepting CLOCK_TAI, timerfd_create() rejects it. This usually corners userspace into one of two bad options:
1. Convert TAI deadlines through CLOCK_REALTIME, which reintroduces the leap second exposure the application was trying to avoid in the first place.
2. Abandon timerfd entirely and use POSIX timers or busy wait approaches that do not compose well with epoll based event loops.
Avoid these bad outcomes by allowing timerfd to support CLOCK_TAI. The underlying hrtimer and k_clock infrastructure already supports this.
With this, epoll based applications can arm TAI based file descriptor timers natively.
--- fs/timerfd.c | 1 + 1 file changed, 1 insertion(+)
fs/timerfd.c +1 -0
@@ -404,6 +404,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) (clockid !=CLOCK_MONOTONIC && clockid !=CLOCK_REALTIME && clockid !=CLOCK_REALTIME_ALARM && + clockid !=CLOCK_TAI && clockid !=CLOCK_BOOTTIME && clockid != CLOCK_BOOTTIME_ALARM)) return -EINVAL;
base-commit: a989fde763f4f24209e4702f50a45be572340e68
Signature · 1 line
2.53.0
To proactively reply to what Sashiko said in https://sashiko.dev/#/patchset/abuTTv9FC__H_8RC%40chrisdown.name:
Quoted 19 lines
If a user creates a
CLOCK_TAItimer and later callstimerfd_settimewith theTFD_TIMER_CANCEL_ON_SETflag, does the kernel silently ignore the flag?Looking at
timerfd_setup_cancelinfs/timerfd.c, the cancellation logic appears to be explicitly restricted toCLOCK_REALTIMEandCLOCK_REALTIME_ALARM:static void
timerfd_setup_cancel(struct timerfd_ctx *ctx, int flags){ ... if ((ctx->clockid == CLOCK_REALTIME || ctx->clockid == CLOCK_REALTIME_ALARM) && (flags & TFD_TIMER_ABSTIME) && (flags & TFD_TIMER_CANCEL_ON_SET)) { ... } else { __timerfd_remove_cancel(ctx); } }
Quoted 7 lines
Will this cause a silent API failure where the timer is never added to the cancel list for
CLOCK_TAI, meaning the timer won't be canceled during administrative clock jumps?Additionally, if it were added,
timerfd_clock_was_setandtimerfd_canceledhardcode the jump-detection check toktime_mono_to_real(0). Does this miss independent jumps inCLOCK_TAIcaused byadjtimex(ADJ_TAI)?
So, timerfd_setup_cancel() is currently restricted to CLOCK_REALTIME and CLOCK_REALTIME_ALARM, so a CLOCK_TAI timerfd created by this patch will behave like the other non-REALTIME timerfds here. The behaviour is that the flag is accepted by timerfd_settime(), but no cancel on set tracking is armed and the timer will not report ECANCELED on clock changes.
So what Sashiko says does not block this patch, because the patch is only lifting the timerfd_create() allowlist restriction. The underlying hrtimer/k_clock paths already support basic CLOCK_TAI timerfds, which is what this patch is enabling.
If we wanted TFD_TIMER_CANCEL_ON_SET support for CLOCK_TAI, that would need separate work. As Sashiko also said, the current cancel detection is based on ktime_mono_to_real(0) (that is, REALTIME movement) and would not be sufficient for standalone TAI offset changes such as adjtimex(ADJ_TAI). So supporting cancel on set for CLOCK_TAI is not just a matter of adding CLOCK_TAI to timerfd_setup_cancel() and would require defining the desired semantics and adding distinct change detection for TAI. That's a much bigger change and discussion.
So let's leave this patch as is for now.
Thomas Gleixner
maintainerQuoted 8 lines · Chris Down
Quoted 7 lines
Will this cause a silent API failure where the timer is never added to the cancel list for
CLOCK_TAI, meaning the timer won't be canceled during administrative clock jumps?Additionally, if it were added,
timerfd_clock_was_setandtimerfd_canceledhardcode the jump-detection check toktime_mono_to_real(0). Does this miss independent jumps inCLOCK_TAIcaused byadjtimex(ADJ_TAI)?
Quoted 5 lines
So,
timerfd_setup_cancel()is currently restricted toCLOCK_REALTIMEandCLOCK_REALTIME_ALARM, so aCLOCK_TAItimerfd created by this patch will behave like the other non-REALTIME timerfds here. The behaviour is that the flag is accepted bytimerfd_settime(), but no cancel on set tracking is armed and the timer will not report ECANCELED on clock changes.
Which is wrong.
Quoted 4 lines
So what Sashiko says does not block this patch, because the patch is only lifting the
timerfd_create()allowlist restriction. The underlying hrtimer/k_clock paths already support basicCLOCK_TAItimerfds, which is what this patch is enabling.
Your new friend Sashiko and me have to agree that we disagree.
Quoted 8 lines
If we wanted
TFD_TIMER_CANCEL_ON_SETsupport forCLOCK_TAI, that would need separate work. As Sashiko also said, the current cancel detection is based onktime_mono_to_real(0)(that is, REALTIME movement) and would not be sufficient for standalone TAI offset changes such asadjtimex(ADJ_TAI). So supporting cancel on set forCLOCK_TAIis not just a matter of addingCLOCK_TAItotimerfd_setup_cancel()and would require defining the desired semantics and adding distinct change detection for TAI. That's a much bigger change and discussion.
Q: What's the discusison required?
A: None. Because it's already well defined.
Q: What's the big change?
A: Nothing. Because TAI changes are already propagated
Q: Did you actually look at the code?
A: No. You just paraphrased the output of an AI bot. Nice try.
Quoted 1 line
So let's leave this patch as is for now.
Correct. I moved it already into the not-for-merging bin and that's where I'll leave it. I'm not merging half baked crap based on the lousiest argument I've heard in a long time.
That said, I'm not afraid of AI itself, but of the humans using it the wrong way.
Thanks,
tglx