From: Yiming Wang <yiming050305@gmail.com>
To: Alex Shi <alexs@kernel.org>
Cc: Yanteng Si <si.yanteng@linux.dev>,
Dongliang Mu <dzm91@hust.edu.cn>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] docs/zh_CN: Add locking/pi-futex Chinese translation
Date: Sat, 5 Dec 2026 21:59:29 +0000 [thread overview]
Message-ID: <20261205215929.97891-1-yiming050305@gmail.com> (raw)
Translate .../locking/pi-futex.rst into Chinese.
Update the translation through commit 95ca6d73a8a9
("docs: move locking-specific documents to locking/")
Signed-off-by: Yiming Wang <yiming050305@gmail.com>
---
The initial Chinese translation draft was generated with an AI
assistant (Claude) and then reviewed and revised line by line against
the English original by me. Verified with scripts/checkpatch.pl --strict
(only the MAINTAINERS warning about the new file) and htmldocs builds
via tools/docs/sphinx-build-wrapper, both full and restricted to
translations/zh_CN, with no new warnings.
.../translations/zh_CN/locking/index.rst | 2 +-
.../translations/zh_CN/locking/pi-futex.rst | 99 +++++++++++++++++++
2 files changed, 100 insertions(+), 1 deletion(-)
create mode 100644 Documentation/translations/zh_CN/locking/pi-futex.rst
diff --git a/Documentation/translations/zh_CN/locking/index.rst b/Documentation/translations/zh_CN/locking/index.rst
index c3b1c9ae8..88953d234 100644
--- a/Documentation/translations/zh_CN/locking/index.rst
+++ b/Documentation/translations/zh_CN/locking/index.rst
@@ -12,6 +12,7 @@
mutex-design
spinlocks
+ pi-futex
TODOList:
@@ -24,7 +25,6 @@ TODOList:
* seqlock
* ww-mutex-design
* preempt-locking
- * pi-futex
* futex-requeue-pi
* hwspinlock
* percpu-rw-semaphore
diff --git a/Documentation/translations/zh_CN/locking/pi-futex.rst b/Documentation/translations/zh_CN/locking/pi-futex.rst
new file mode 100644
index 000000000..58f8dbb0b
--- /dev/null
+++ b/Documentation/translations/zh_CN/locking/pi-futex.rst
@@ -0,0 +1,99 @@
+.. SPDX-License-Identifier: GPL-2.0
+.. include:: ../disclaimer-zh_CN.rst
+
+:Original: Documentation/locking/pi-futex.rst
+
+===============
+轻量级 PI-futex
+===============
+
+我们称其为“轻量级”,原因有三:
+
+ - 在用户空间的快速路径中,启用了 PI 的 futex 完全不涉及内核工作(也不
+ 涉及任何其他 PI 相关的复杂性)。无需注册,无需额外的内核调用——只有
+ 在用户空间执行的纯粹的快速原子操作。
+
+ - 即使在慢速路径中,其系统调用和调度模式也与普通 futex 非常相似。
+
+ - 内核中的 PI 实现围绕互斥锁(mutex)这一抽象进行了精简,并通过严格的
+ 规则使实现保持相对简单:一把锁只能有一个所有者(即不支持读写锁),
+ 只有所有者才能解锁,不支持递归加锁,等等。
+
+为什么需要优先级继承(priority inheritance)?
+----------------------------------------------
+
+简短的回答:用户空间的 PI 有助于实现/改善用户空间应用程序的确定性。在
+最好的情况下,它可以帮助实现确定性和良好有界的延迟。即使在最坏的
+情况下,PI 也能改善应用程序中与加锁相关的延迟的统计分布。
+
+详细的回答
+----------
+
+首先,在多个任务之间共享锁是一种常见的编程技术,通常无法用无锁算法取代。
+正如我们在内核(其本身就是一个相当复杂的程序)中所看到的,无锁结构是例外
+而非常态——目前在共享数据结构中,无锁代码与有锁代码的比例大约在 1:10 到
+1:100 之间。无锁编程很难,而且无锁算法的复杂性常常会妨碍对这类代码进行
+可靠的审查。也就是说,关键的 RT 应用程序通常会选择用锁结构而不是无锁算法
+来保护关键数据结构。此外,在某些情况下(例如共享硬件或其他资源限制),
+无锁访问在数学上是不可能的。
+
+媒体播放器(例如 Jack)就是一个合理的应用程序设计示例:多个(具有多个
+优先级的)任务共享持有时间很短的锁。例如,一个高优先级的音频播放线程,
+与中优先级的音频数据构建线程以及低优先级的界面显示线程协同工作。再加上
+视频和解码,优先级层次还会更多。
+
+因此,一旦我们承认同步对象(锁)是不可避免的现实,并且承认多任务的
+用户空间应用程序完全有理由期望能够使用锁,我们就必须考虑如何让用户空间
+能够选用一种具有确定性的锁实现。
+
+大多数反对实现优先级继承的技术论点只适用于内核空间的锁。但用户空间的锁
+不同:在用户空间中,我们无法在临界区内关闭中断或使任务不可抢占,因此
+“使用自旋锁”的论点并不适用(用户空间的自旋锁与其他用户空间的加锁结构
+一样存在优先级反转问题)。事实上,目前几乎唯一能让用户空间的锁(例如基于
+futex 的 pthread 互斥锁)获得良好确定性的技术就是优先级继承:
+
+目前(在没有 PI 的情况下),如果一个高优先级任务和一个低优先级任务共享
+一把锁(这对于大多数稍具规模的 RT 应用程序来说是相当常见的场景),即使
+所有临界区都经过精心编写以保证确定性(即所有临界区的持续时间都很短,并且
+只执行有限数量的指令),内核也无法保证高优先级任务的确定性执行:在低
+优先级任务持有共享锁并执行临界区时,任何一个中优先级任务都可能抢占它,
+并可能无限期地推迟它的执行。
+
+实现
+----
+
+如前所述,启用了 PI 的 pthread 互斥锁在用户空间的快速路径中完全不涉及
+内核工作——它们的行为与普通的基于 futex 的锁非常相似:值为 0 表示未加锁,
+值等于 TID 表示已加锁。(这与基于链表的 robust futex 所用的方法相同。)
+用户空间使用原子操作来加锁/解锁这些互斥锁,而无需进入内核。
+
+为了处理慢速路径,我们新增了两个 futex 操作:
+
+ - FUTEX_LOCK_PI
+ - FUTEX_UNLOCK_PI
+
+如果加锁的快速路径失败(即从 0 到 TID 的原子转换失败),则调用
+FUTEX_LOCK_PI。剩下的工作全部由内核完成:如果该 futex 地址上尚未附加
+futex 队列,代码就会查找拥有该 futex 的任务(该任务已将自己的 TID 写入
+futex 值),并将一个“PI 状态”结构附加到该 futex 队列上。pi_state 中包含
+一个 rt-mutex,它是一种支持 PI、基于内核的同步对象。“另一个”任务被设为
+该 rt-mutex 的所有者,并且 futex 值中的 FUTEX_WAITERS 位被原子地置位。
+随后,当前任务尝试对该 rt-mutex 加锁,并阻塞在它上面。一旦返回,它就已
+获得该互斥锁,接着它将 futex 值设为自己的 TID 并返回。用户空间无需再做
+其他工作——它现在拥有这把锁,并且 futex 值为 FUTEX_WAITERS|TID。
+
+如果解锁一侧的快速路径成功(即用户空间成功地将 futex 值从 TID 原子地转换
+为 0),则不会触发任何内核工作。
+
+如果解锁的快速路径失败(因为 FUTEX_WAITERS 位已被置位),则调用
+FUTEX_UNLOCK_PI,由内核代表用户空间解锁该 futex——同时它也会解锁所附加的
+pi_state->rt_mutex,从而唤醒所有可能存在的等待者。
+
+请注意,在这种方法下,与以往的 PI-futex 方法不同,PI-futex 无需事先
+“注册”。(而由于 pthread 互斥锁现有的 ABI 特性,事先注册本来也不太
+可行。)
+
+此外,在该方案下,“健壮性”(robustness)和“PI”是 futex 的两个正交属性,
+四种组合都是可能的:futex、robust-futex、PI-futex、robust+PI-futex。
+
+有关优先级继承的更多细节,请参阅 Documentation/locking/rt-mutex.rst。
--
2.54.0 (Apple Git-157)
reply other threads:[~2026-12-05 22:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205215929.97891-1-yiming050305@gmail.com \
--to=yiming050305@gmail.com \
--cc=alexs@kernel.org \
--cc=corbet@lwn.net \
--cc=dzm91@hust.edu.cn \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=si.yanteng@linux.dev \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox