为什么 Linux 不通过 TSS 使用硬件上下文切换?

发布于 2024-08-30 02:25:51 字数 506 浏览 7 评论 0原文

我读了以下声明:

x86 架构包括 称为任务的特定段类型 状态段(TSS),用于存储硬件 上下文。虽然Linux不使用 硬件上下文切换,它是 尽管如此,还是被迫建立了一个 TSS 系统中每个不同的CPU。

我想知道:

  • 为什么Linux不使用上下文切换的硬件支持?
  • 硬件方法不是比软件方法快得多吗?
  • 是否有任何操作系统可以利用硬件上下文切换? windows使用它吗?

最后,一如既往,感谢您的耐心和回复。

-----------添加--------------

http ://wiki.osdev.org/Context_Switching 得到了一些解释。

像我一样困惑的人可以看看。 8^)

I read the following statement:

The x86 architecture includes a
specific segment type called the Task
State Segment (TSS), to store hardware
contexts. Although Linux doesn't use
hardware context switches, it is
nonetheless forced to set up a TSS for
each distinct CPU in the system.

I am wondering:

  • Why doesn't Linux use the hardware support for context switch?
  • Isn't the hardware approach much faster than the software approach?
  • Is there any OS which does take advantage of the hardware context switch? Does windows use it?

At last and as always, thanks for your patience and reply.

-----------Added--------------

http://wiki.osdev.org/Context_Switching got some explanation.

People as confused as me could take a look at it. 8^)

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

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

发布评论

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

评论(3

哎呦我呸! 2024-09-06 02:25:51

x86 TSS 的硬件多任务处理速度非常慢,并且与软件任务切换相比几乎没有任何优势。 (事实上​​,我认为手动执行此操作很多时候会击败 TSS)

TSS 也因使用起来烦人且乏味而闻名,并且它不可移植,甚至对于 x86-64 也是如此。 Linux 的目标是在多种架构上工作,因此他们可能选择使用软件任务切换,因为它可以以独立于机器的方式编写。此外,软件任务切换提供了更多的功能,并且通常比 TSS 更容易设置。

我相信Windows 3.1使用了TSS,但至少NT>5内核没有。我不知道有任何类 Unix 操作系统使用 TSS。

请注意,TSS 是强制性的。操作系统所做的事情是创建单个 TSS 条目(每个处理器),每次需要切换任务时,他们只需更改此单个 TSS。软件任务切换在 TSS 中使用的唯一字段是 ESP0 和 SS0。这用于从环 3 代码到达环 0 以进行中断。如果没有 TSS,就不会有已知的 Ring 0 堆栈,这当然会导致 GPF 并最终导致三重故障。

The x86 TSS is very slow for hardware multitasking and offers almost no benefits when compared to software task switching. (In fact, I think doing it manually beats the TSS a lot of times)

The TSS is known also for being annoying and tedious to work with and it is not portable, even to x86-64. Linux aims at working on multiple architectures so they probably opted to use software task switching because it can be written in a machine independent way. Also, Software task switching provides a lot more power over what can be done and is generally easier to setup than the TSS is.

I believe Windows 3.1 used the TSS, but at least the NT >5 kernel does not. I do not know of any Unix-like OS that uses the TSS.

Do note that the TSS is mandatory. The thing that OSs do though is create a single TSS entry(per processor) and everytime they need to switch tasks, they just change out this single TSS. And also the only fields used in the TSS by software task switching is ESP0 and SS0. This is used to get to ring 0 from ring 3 code for interrupts. Without a TSS, there would be no known Ring 0 stack which would of course lead to a GPF and eventually triple fault.

萌面超妹 2024-09-06 02:25:51

Linux 在 1.3 之前的时间框架 iirc 中曾经使用基于硬件的交换。我相信基于 sw 的上下文切换速度更快,而且更灵活。

另一个原因可能是最小化特定于架构的代码。 Linux 向非 x86 架构的第一个移植是 Alpha。 Alpha 没有 TSS,因此如果所有架构都使用软件切换,则可以共享更多代码。 (只是猜测。)不幸的是,1.2-1.3 内核时期的内核更改日志没有得到很好的保存,所以我无法提供更具体的信息。

Linux used to use HW-based switching, in the pre-1.3 timeframe iirc. I believe sw-based context switching turned out to be faster, and it is more flexible.

Another reason may have been minimizing arch-specific code. The first port of Linux to a non-x86 architecture was Alpha. Alpha didn't have TSS, so more code could be shared if all archs used SW switching. (Just a guess.) Unfortunately the kernel changelogs for the 1.2-1.3 kernel period are not well-preserved, so I can't be more specific.

枯叶蝶 2024-09-06 02:25:51

Linux 不使用分段内存模型,因此不使用此分段特定功能。

x86 CPU 有许多不同类型的硬件支持上下文切换,因此区别不在于硬件与软件,而在于操作系统如何使用各种可用的硬件功能。没有必要全部使用它们。

Linux 是如此注重效率,以至于您可以打赌有人已经分析了所有可能的选项,并且当前使用的选项是最佳的可用折衷方案。

Linux doesn't use a segmented memory model, so this segmentation specific feature isn't used.

x86 CPUs have many different kinds of hardware support for context switching, so the distinction isn't hardware vs software, but more how does an OS use the various hardware features available. It isn't necessary to use them all.

Linux is so efficiency focussed that you can bet that someone has profiled every option that is possible, and that the options currently used are the best available compromise.

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