← Back to Pull requests

FreeBSD: use eventfd and timerfd for CFRunloop #5539

Closed
unknown closed this pull request without merging on Oct 03, 2026 03:37 UTC
View on GitHub
unknown unknown commented on Sep 04, 2026 01:22 UTC
Author

FreeBSD currently use the generic kqueue / pipe2 mechanism from to crash if more more MAX_TIMERS are created (hardcoded to 16)

Since both eventfd and timerfd are available on FreeBSD, use that instead of pipe2 and EVFILT_TIMER

This is an ABI change on FreeBSD and also requires a libdispatch change: https://github.com/swiftlang/swift-corelibs-libdispatch/pull/957

Motivation:

FreeBSD currently use the EVFILT_TIMER mechanism for timer, and pipe2 as trigger from #3004. There are few
issues with this

  • it only creating MAX_TIMERS(currently 16+1) timers, and led to crashes if extra timer are created. https://github.com/swiftlang/swift-corelibs-foundation/blob/761b621da93a856a48995efc29ed11028c283306/Sources/CoreFoundation/CFRunLoop.c#L522

  • https://github.com/swiftlang/swift-corelibs-foundation/blob/761b621da93a856a48995efc29ed11028c283306/Sources/CoreFoundation/CFRunLoop.c#L1146
  • Even if we increase MAX_TIMERS, there's a system-wise limit (kern.kq_calloutmax) on how many timers allowed in kqueue (default is 4096 timers across the entire system). timerfd does not have such limitation

  • with the pipe2 mechanism, __CFPort is encoded in a specific way to be able to both encode 2 file descriptors and a EVFILT_TIMER. since we're moving to timerfd, we can just that the eventfd branch instead. This also resolve a potential issue where in theory the runloop wakeup can stall if we write to a pipe with full buffer.
  • Modifications:

    Align FreeBSD runloop timer and awaking mechanism with Linux, using timerfd and eventfd instead of EVFILT_TIMER and pipe2

    CFPortSet is still a kqueue

    Result:

    Running on FreeBSD not longer bounded by the MAX_TIMERS limit and system-wise kern.kq_calloutmax limit

    Diff: 222 lines (+166 / -56) across 2 files Reviewer: michael-yuji Review duration: 41894m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.37) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 222 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.323
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5539"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.8% (MEDIUM) · Higher = larger blast radius
    36.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.9% · Safe to merge
    15.9%