Linux 中的上下文切换会保存什么寄存器状态?
在 Linux 中,您会在哪里查找上下文切换中保存了哪些寄存器?例如,我想知道在内核模式驱动程序代码中使用 FP 或向量寄存器是否安全(主要对 x86-64 和 ARM 感兴趣,但我希望得到一个独立于体系结构的答案)。
Where in Linux would you look to find out what registers are saved on a context switch? I'm wondering, for example, if it is safe to use FP or vector registers in kernel-mode driver code (mostly interested in x86-64 and ARM, but I'm hoping for an architecture-independent answer).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于似乎没有人回答这个问题,让我冒险一下。
看一下 _math_restore_cpu 和 __unlazy_fpu 方法。
您可以在这里找到它们:
像 x86 的处理器有单独的指令保存(fnsave)和恢复(frstor)FPU状态,因此看起来操作系统正在承担保存/恢复它们的负担。
我认为除非 FPU 单元已被用户模式进程使用,否则 linux 上下文切换不会为您保存它。
因此,您需要自己(在您的驱动程序中)执行此操作才能确定。您可以使用 kernel_fpu_begin/end 在驱动程序中执行此操作,但这通常不是一个好主意。
为什么这不是一个好主意?来自 Linus 本人: http://lkml.indiana.edu/hypermail/linux /kernel/0405.3/1620.html
引用:
无论如何,你真的想依赖英特尔的浮点单元吗? http://en.wikipedia.org/wiki/Pentium_FDIV_bug(开玩笑:-))。
Since no one seems to have answered this, let me venture.
Take a look at the _math_restore_cpu and __unlazy_fpu methods.
You can find them here:
The x86 like processors have separate instructions for saving (fnsave) and restore (frstor) FPU state and so it looks like the OS is burdened with saving/restoring them.
I presume unless the FPU unit has been used by the usermode process, linux context switch will not save it for you.
So you need to do it yourself (in your driver) to be sure. You can use kernel_fpu_begin/end to do it in your driver, but is generally not a good idea.
Why it is not a good idea? From Linus himself: http://lkml.indiana.edu/hypermail/linux/kernel/0405.3/1620.html
Quoted:
In any case, do you really want to rely on Intel's floating point unit? http://en.wikipedia.org/wiki/Pentium_FDIV_bug (just kidding :-)).