问题描述
我阅读了以下声明:
x86 架构包括一个称为任务的特定段类型状态段 (TSS),用于存储硬件上下文.虽然Linux不使用硬件上下文切换,它是尽管如此,还是被迫为系统中每个不同的 CPU.
我想知道:
- 为什么 Linux 不使用上下文切换的硬件支持?
- 硬件方法不是比软件方法快得多吗?
- 是否有任何操作系统可以利用硬件上下文切换?Windows 使用它吗?
最后,一如既往,感谢您的耐心和回复.
At last and as always, thanks for your patience and reply.
-----------已添加--------------
-----------Added--------------
http://wiki.osdev.org/Context_Switching 得到了一些解释.
像我一样困惑的人可以看看它.8^)
People as confused as me could take a look at it. 8^)
推荐答案
x86 TSS 对于硬件多任务处理速度非常慢,与软件任务切换相比几乎没有任何好处.(实际上,我认为手动完成很多次会击败 TSS)
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)
TSS 也以使用起来烦人和乏味而著称,而且它不可移植,即使对于 x86-64 也是如此.Linux 旨在处理多种架构,因此他们可能选择使用软件任务切换,因为它可以以独立于机器的方式编写.此外,软件任务切换为可以完成的任务提供了更多的权力,并且通常比 TSS 更容易设置.
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.
我相信 Windows 3.1 使用了 TSS,但至少 NT > 5 内核没有.我不知道任何使用 TSS 的类 Unix 操作系统.
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.
请注意 TSS 是强制性的. 操作系统所做的事情是创建单个 TSS 条目(每个处理器),每次他们需要切换任务时,他们只需更改这个单个 TSS.并且软件任务切换在 TSS 中使用的唯一字段是 ESP0
和 SS0
.这用于从中断的环 3 代码到达环 0.如果没有 TSS,就不会有已知的 Ring 0 堆栈,这当然会导致 GPF 并最终导致三重故障.
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.
这篇关于为什么 Linux 不通过 TSS 使用硬件上下文切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!