From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 EC29A42BC3E for ; Wed, 12 Aug 2026 14:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786546495; cv=none; b=KCOdY2dW2xFi0otuPKGnWj13MSmmFDpBHVaR6FhgdWLiq55bVZupRo2Dd9rtqFUpk3SwKZrVw8DdlakUT85QMc6NMWUo1XvO+r20b3zSx27qMK6XiN1glMOCAL6vg8mejaiZo6ON7HIFpCFiXc879qruTSOdScaeMXvfNwURAX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786546495; c=relaxed/simple; bh=ggZWb/rBiqtP7g2mRVkG7zh3PqK153hqDL94sI8DK4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=reZDXC6TSKMF17eaf02TTM3qW8d23G2v5PzJy9t+N/uwW1Z3sYEAhI+O9x7WgdQd0aD1/tAGkqbtURXF8/skACXH9fWE33nERP6QDIt0HqOSppkvpJSBPi0vRyWxjtlwGxcsw9hnGGCemb8VoU4bzUxGtQhjDel+Jxq21BWL4vg= 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=ktYDDo+s; arc=none smtp.client-ip=209.85.214.181 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="ktYDDo+s" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2cc73e322dbso14040485ad.1 for ; Wed, 12 Aug 2026 07:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786546486; x=1787151286; 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=QyYu/EtrXs6+w7joY9KRy5CcVEubQhW0BF1ueyFLgVE=; b=ktYDDo+sE5NBjy5adEWnV5XHGQ6uYJ1ThDPWGN4+7Smz9dC/9ZcbBe8GVCEN3m5wWX +GpgmaU58bQVXs7V9ml6nNnrxNN22hxsNoq+V//gKgslrPzyenZSV2CTN8jPONcLtYE/ hYHpMw5FVgBsw4DLhCBgWQkgY48dpjTaf6TQuae+5Xb4tDj1nVr8jUs/LXO9q0ACQN9p gRn/A5S3JigKmRcZb8E3CEhWviFsZWBdqFMx8RQl/1oMEfxG8mSkJxgY/SW/+hUNGo83 uUM9cB4O+cbFUTFD2NihoaoqxM533mduzcmaOzJFBpxObuPHYzKpxg9tPUAJnyPolKrq HXZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786546486; x=1787151286; 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=QyYu/EtrXs6+w7joY9KRy5CcVEubQhW0BF1ueyFLgVE=; b=aT602IwoQHuZzcr7GqVg8Jq98PjFWPAvrykcB3rZHJcydMjv0VsqzstntAuSVsmchj lK4p9o0NKIUU4mWeju9aIwLBvmystO0V+TdRPs3peTFqiwxE1RUBpk3TileD3PNgPNzZ G7wsym7ioFII+4LAP/+F2yT41gQy9OTRfOclv7Fr0LI6oJZOtnuAvPxqyqDoACR7hdj5 CO8OnfVAGcvRiNDPnYSoxCu1j8I1vGpITxMO7Uj6HoWn4eXhyFb5C5/XofiALAgWPDto xDWC4D2JgyxMamAi8QWGYcGUSfNeFVStlfB1iCJz/GIJA/uLe10GaLTXULDr3oQg26ra oAqA== X-Forwarded-Encrypted: i=1; AHgh+RqSLEyx0rpf2X+ffrPRVCdOTo+gwkEsEyv90kaVzbDR3/7chg9UAyaxgcyhZF0KDVPUAJECcnYkv1WgBjU=@vger.kernel.org X-Gm-Message-State: AOJu0YyT730+4TpxfF149kS/UVGUCY8dWRAZ8k1ZjGchiA2PUEUD6DF6 cOO5HVTIWg2D+Cnxd/TZsvmO75wfXsIm/fx+f0re0B8OQQh6VzNpfsVt X-Gm-Gg: AR+sD10EweXlxH74ukgEKTflyAsba1A+9xpss1FPu3ejM2W/NWYRBSiYYwF7PJiUgG9 X3P7697W+fZbybfyaKtcffZdmk79xsIhjEn7lVaDg5xH2Q5TuWY9DsuMTjn3Xyev1fu7zjXSXDg QpxCnRuyq3H4pnA0tF8xzxzB+Wu+mNZLlcnuwxE68jSHVhzPGNSZkBtKR4Bao29l5Pq9MIj3M+7 NCoGRm6VqZRjOf8WGCWcAGnkGfDKZ9wZZz15rf/7QORIYTWJPdUB6mslVGlp5Md1joxmbV19tHo 50kwrSGPQWnttOneA2fTzLRJAl32YtsHz/Mw8S6wfcnkaXxhDWzZkF2jZjFOG65YIUml2/kkETH mchW4S8k8ReKWi56NYLmt1tFZPG68jfpeNJDa7/6PgG8BxeeivrMS6ScRi1W0VOnQvkCIuS/ZLx IETQneJbCm06O6Sz9t/4Du5/bq5ODKYFyrYmYQAxeDOTm1v59/kOh6f5BKqbOAh7i+W+offEycs Q== X-Received: by 2002:a17:90b:288b:b0:38e:f6eb:2b38 with SMTP id 98e67ed59e1d1-393014944a5mr6567009a91.17.1786546486135; Wed, 12 Aug 2026 07:54:46 -0700 (PDT) Received: from localhost ([220.196.228.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-392fe4b1659sm1334683a91.3.2026.08.12.07.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2026 07:54:45 -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 v2] docs: timers: hrtimers: clarify expiry modes and ktimersd on PREEMPT_RT Date: Wed, 12 Aug 2026 22:54:40 +0800 Message-ID: <20260812145440.23528-1-haohlliang@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260807161929.49913-1-haohlliang@gmail.com> References: <20260807161929.49913-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() 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 --- v1 -> v2: - shorten the RT overview; link to real-time/differences - state the arming-path priority consequence (priority not inherited; PI is for the cancel handshake) - drop the hrtimer_start trace debugging section - use the ktimers/%u thread name, with ktimersd as its doc alias Documentation/timers/hrtimers.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Documentation/timers/hrtimers.rst b/Documentation/timers/hrtimers.rst index f88ff8bae89c..fae191550c5d 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()`` (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)