From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF6513A872C for ; Thu, 13 Aug 2026 14:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786633075; cv=none; b=FITUSuALhNeVhfrekh6GV86kYpERyit8Dtn0Ewctejo6soJ+zFZneMd5jk+kukEPsP0DWleI9RE2Af6j7QxiT66qEV0G1ku1YlccuSaYquq1utyB4qj6Tzh6/HO0j+wnMGzXt0befUQwqZ/8cmyOyr2qI6O2+BltpBffbsZ3Em0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786633075; c=relaxed/simple; bh=UzDJRYzn8/XIL+G2itjXNV/UKIkP2Zl5tn0cjd5eH1M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uPLiZa410sdQFqR3a2Wd2Bvqgt5zwUWCQJ2GrKnsltsACSntH2945LMoYq71KybuRAiqSD4nfSq3qKEeoiqUenSrI/5vu1Bj48qBGnIvcxUfCHso1f+NfT0JLW9UqMDSYM1JuobQu+5J6uKrdVx8whDQfc72i33H151XJYMx0no= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SZhH/LlP; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SZhH/LlP" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2d01663d816so53245ad.1 for ; Thu, 13 Aug 2026 07:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786633071; x=1787237871; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6zYINpSgOxSLHev+n0fE2laFlkLhiN8CqX0AHvm/85M=; b=SZhH/LlPofaMk1OJbKlkFJeTl/nY/8lwj6vXxzKBdjT1h8yzVWXx+nb2/iBZ1yzp14 9cTYeGak1oEf0Ir0VM6FIdCJsvjtWWUe4wCVXjMj6ULVHJlVdorhFh6v8f4Ncx2HOLYt w4rgTlMJYdrHt/49bbrjSjaBmZPftMIARBVlhg8y2Z4qpJXFvKYk01pnhuBO5dCwgpft LO5iuQk9fyrR5WPW+OkGIvy974djA6ru28+TW2PeFKVZE4qd27JDspTyuBVxzx9EAsYQ Pv6aq7izq7eGYJdVhISrz9/D3Zq57TXu4s6cPTRTLMJ1vex9/HpGKndkGF60RTHStA5/ OwOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786633071; x=1787237871; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6zYINpSgOxSLHev+n0fE2laFlkLhiN8CqX0AHvm/85M=; b=MVYHovz5IJ4K9EnuEH2HzkD7idtMGGJqPYgYQvQwKzgDV3OthbDdqMWQ+rW4qYAHPo W3M1sqzmRqMb6mr7ch/UQ2U0MjFvyVZhFxmuERRsBwCCLL/GKtcp+tbAZyuoe0BU6FBA MICTrB/kzrVmaogCdXsgXpTQsJ/T4UlrGEtM5ln80+yN+PAxeujTsV1gG3Fx4/1e2zLQ P8YbP0wIB2PxHCG/wvmp04fm4JIYdxRdO/XmHFWLGrqP4gZZB3PORYTHaUlAAtQta21S +eRrZZXles2wb9spQNEuLaRbrb1kHEYtH96j6y2oJseXAGHzSKS9Y6lFHHthaGYrg/rb E1QA== X-Forwarded-Encrypted: i=1; AHgh+Ro4HFExWedlgNnKWgOdgsmexDGnJSsI5kHa+ehGxbkgr/Rj4s3ZtwQPp2hO4RZ3sVg2ed1Qbt9oB9L7r9E=@vger.kernel.org X-Gm-Message-State: AOJu0YwCzW9tRqW9NmwPVf2/wvK10Y8eyWgVJPekExU5QrWZeSsQ0Zr6 w0xZsOXw1PnVqG4xJMMkqlpxhbj1sb+rEwHt0x11IuGPS9Y7OI5Cd+TR X-Gm-Gg: AR+sD11mWQxCXgFwga7JBPGCZ2Qy2lo6m2Fhm/dtS9lKABMD+G0KHo8pKo6L3hG5VBq oZGvbM/LIuJOGy0h8B+YXXdiZK9KgPf+5MUEmmIcFq98vpTFSPUL0Wa0WwJZ6wCq5nLsO6Q7iYX tvTOJeCxfwCDbKLE/nPXYj2ae91aI8nvRN1n6PSw2Hr6MHsKd9yzfyrkgYeR9WHCqTYSEzhOPlV f8ER0tXyxah6w2f6rT0kJ3zQG+JMWMzzaUOBsw0tNdkDDrJrnD3fgv9ryr+oyYA/1rtZ2o3/SJR Z3AltGiikpppCNwxiIndpvo5NDMd75Pfku8SY0cgPH1ewR3qaDtfICPJ++sj5B6D+crfnuJ68Li WswvanjGlDcdwjeW2qpwLDvUBFwwwPeWkS2liFkgdejlq0KLTmlQj2SROd+PqFUNfylfW4knBa0 Fm061ElBHtVRbDbt/Hr/+AR9DRMloabPk6JPMs1rmYvN3H1TEEFyoG0Vl9UysFnV+xe5gAzWgQd zcoRuyuqgJJsA== X-Received: by 2002:a17:902:f550:b0:2cf:7fab:3cf with SMTP id d9443c01a7336-2d37ebcefa5mr59040865ad.23.1786633071088; Thu, 13 Aug 2026 07:57:51 -0700 (PDT) Received: from localhost ([220.196.228.78]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d37c40e8c4sm11313775ad.45.2026.08.13.07.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 07:57:50 -0700 (PDT) From: Liang Hao To: Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Sebastian Andrzej Siewior Cc: Jonathan Corbet , Shuah Khan , Randy Dunlap , Clark Williams , Steven Rostedt , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-rt-devel@lists.linux.dev, Liang Hao Subject: [PATCH v3] docs: timers: hrtimers: clarify expiry modes and ktimersd on PREEMPT_RT Date: Thu, 13 Aug 2026 22:57:46 +0800 Message-ID: <20260813145746.26612-1-haohlliang@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260812145440.23528-1-haohlliang@gmail.com> References: <20260812145440.23528-1-haohlliang@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Documentation/timers/hrtimers.rst did not cover the PREEMPT_RT expiry-mode semantics. On a PREEMPT_RT kernel a timer that is not explicitly marked HRTIMER_MODE_HARD is forced into softirq expiry and its callback runs on the per-CPU ktimers/%u thread at the lowest SCHED_FIFO priority (sched_set_fifo_low), regardless of the priority of the task that armed it -- a SCHED_FIFO task running at priority 99 that starts an unmarked timer still expires on ktimers/%u (lowest SCHED_FIFO priority), not at priority 99. Add an "Expiry modes and PREEMPT_RT" section that, rather than duplicating the default-context description in Documentation/core-api/real-time/differences.rst (Timers), cross-references it and focuses on what that document does not spell out: - the callback does not inherit the arming task's priority, and priority inheritance on PREEMPT_RT is used for the cancel handshake, not the arming path (the "Spin until ready" section of the same document); - the sleeper exception: hrtimer_setup_sleeper_on_stack() marks RT/DL-armed timers HRTIMER_MODE_HARD, so their wakeups do not go through ktimers/%u. Documentation only; no code or behaviour change. Signed-off-by: Liang Hao --- v2 -> v3: - use hrtimer_setup_sleeper_on_stack(); there is no hrtimer_setup_sleeper() Documentation/timers/hrtimers.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Documentation/timers/hrtimers.rst b/Documentation/timers/hrtimers.rst index f88ff8bae89c..b81785e0310e 100644 --- a/Documentation/timers/hrtimers.rst +++ b/Documentation/timers/hrtimers.rst @@ -171,3 +171,31 @@ hrtimers-based high-resolution clock implementation, so the hrtimers code got a healthy amount of testing and use in practice. Thomas Gleixner, Ingo Molnar + + +Expiry modes and PREEMPT_RT +--------------------------- + +The default expiry context on PREEMPT_RT and the role of the ktimersd +thread are documented in :doc:`/core-api/real-time/differences` +(Timers). Those details are not repeated here. + +The per-CPU ``ktimers/%u`` thread (referred to as ktimersd in that +document) runs at the lowest ``SCHED_FIFO`` priority via +``sched_set_fifo_low()``. That priority is fixed: the callback does +not inherit the priority of the task that armed the timer. A +``SCHED_FIFO`` task running at priority 99 that starts an unmarked +timer still expires on ``ktimers/%u`` (lowest ``SCHED_FIFO`` priority), +not at priority 99. +Priority inheritance on PREEMPT_RT is used for the cancel handshake, +not for the arming path; see the "Spin until ready" section of the same +document. + +``hrtimer_setup_sleeper_on_stack()`` (used by ``clock_nanosleep()`` and similar) +is an exception: when armed by an RT or DEADLINE task it is marked +``HRTIMER_MODE_HARD``, so the wakeup runs in hardirq context and does +not go through ``ktimers/%u``. + +If callback work must run at the owning task's RT priority, either +mark the timer ``HRTIMER_MODE_HARD`` (and keep the callback +hardirq-safe) or wake a dedicated kthread from the callback. -- 2.50.1 (Apple Git-155)