Skip to content

Implement timerfd(2) from FreeBSD 14 #516

Description

@laffer1

MidnightBSD 4.0 (FreeBSD 13-stable base) does not provide sys/timerfd.h or the timerfd_create(2) / timerfd_settime(2) / timerfd_gettime(2) syscalls. FreeBSD added these in 14.0.

Why this matters

Upstream software increasingly assumes timerfd is available on any non-Windows platform, because it is present on Linux and on FreeBSD >= 14. Ports that use it need MidnightBSD-specific patches that FreeBSD does not carry, which means the divergence is ours to maintain.

The first concrete case is KDE Plasma 6.6.6. plasma-workspace added libclock/alignedtimer.cpp, which uses timerfd unconditionally:

#include <sys/timerfd.h>
...
m_timerFd = timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK);
...
const int flags = TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET;
timerfd_settime(m_timerFd, flags, &timespec, nullptr);

libclock is not optional (unconditional add_subdirectory(libclock)), and the digital clock applet links it, so x11/plasma6-plasma-workspace does not build without it. FreeBSD's port needs no patch here because their base provides the API.

Current workaround

x11/plasma6-plasma-workspace now carries an mports-local patch that guards the timerfd path with __has_include(<sys/timerfd.h>) and falls back to a single-shot QTimer re-armed against the wall clock.

The fallback is functional but not equivalent. TFD_TIMER_CANCEL_ON_SET makes the kernel cancel the timer when the realtime clock is stepped, so the application learns about a clock change immediately. The QTimer fallback only re-aligns on its next tick, so after a clock step (NTP correction, suspend/resume, manual change) the clock applet can display a stale time for up to one interval — a minute for the minute timer.

The patch also has to be carried forward across future Plasma releases, and any other port adopting timerfd will need the same treatment.

Request

Import timerfd(2) from FreeBSD 14 into the MidnightBSD base system:

  • sys/sys/timerfd.h
  • the timerfd_create / timerfd_settime / timerfd_gettime syscalls
  • TFD_TIMER_ABSTIME, TFD_TIMER_CANCEL_ON_SET, TFD_CLOEXEC, TFD_NONBLOCK

Once base provides it, the __has_include guard in the Plasma patch resolves to the native path automatically and the fallback becomes dead code, so the port needs no further change to benefit.

References

  • FreeBSD implementation: sys/kern/sys_timerfd.c, sys/sys/timerfd.h (added in 14.0)
  • Affected port: x11/plasma6-plasma-workspace (Plasma 6.6.6)
  • Upstream source: libclock/alignedtimer.cpp in plasma-workspace

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions