Linux内核:立即取消调度的代价

发布于 2024-08-21 09:36:10 字数 532 浏览 2 评论 0原文

来自 http://lkml.indiana.edu/hypermail/linux/ kernel/0103.1/0030.html 我了解了 linux 中的一种新型互斥体,adaptive_np 互斥体:

PTHRED_MUTEX_ADAPTIVE_NP 是一个新的 互斥体旨在用于高 吞吐量的牺牲 公平性,甚至 CPU 周期。这 互斥体不会将所有权转移给 等待线程,而是允许 竞赛。此外,通过 SMP 内核, 锁定操作使用旋转来 重试锁定以避免成本 立即取消安排。

提到了“立即取消调度的成本”。这个费用是多少? (就CPU节拍而言;TLB、TSS、smth else重新加载)在“立即取消调度请求”和再次重新调度回运行状态之间,内核做了什么?

如何进行明确的取消调度以及如何衡量其成本?

From the http://lkml.indiana.edu/hypermail/linux/kernel/0103.1/0030.html I learn about a new type of mutexes in linux, an adaptive_np one:

The PTHRED_MUTEX_ADAPTIVE_NP is a new
mutex that is intended for high
throughput at the sacrifice of
fairness and even CPU cycles. This
mutex does not transfer ownership to a
waiting thread, but rather allows for
competition. Also, over an SMP kernel,
the lock operation uses spinning to
retry the lock to avoid the cost of
immediate descheduling.

There is mentioned "Cost of immediate descheduling". How much is this cost? (In terms of cpu ticks; TLB, TSS, smth else reloading) What is done in kernel between an "immediate descheduling request" and rescheduling back to the run state again?

How can I do a explicit descheduling and how can I measure its cost?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

压抑⊿情绪 2024-08-28 09:36:10

看起来它只是一个轻量级互锁,旨在允许线程避开调度程序。

这个想法是用自旋锁中花费的较短时间来取代相对繁重的基于上下文切换的操作。

忽略“新”的使用,自旋锁就像山一样古老。我想,大约 10 年前,pthread 库还是个新东西。

“显式取消调度”大概与上下文切换相同,因此您可以通过让两个线程 yield() 相互使用 CPU 一百万次并测量运行时间来测量这一点。

It looks like it's just a lightweight interlock intended to allow threads to avoid the scheduler.

The idea is to replace a relatively heavy context-switch-based operation with a hopefully-short period of time spent in a spinlock.

Disregard the use of "new", spinlocks are as old as the hills. It was, I guess, new to that pthread library almost 10 years ago.

An "explicit descheduling" is presumably the same thing as a context switch, so you could measure this by having two threads yield() the CPU to each other a million times and measure the runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文