在Linux设备驱动程序中使用浮点的编码约定是什么? [英] What are coding conventions for using floating-point in Linux device drivers?

查看:126
本文介绍了在Linux设备驱动程序中使用浮点的编码约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与 这个问题.

我不是Linux设备驱动程序或内核模块方面的专家,但我一直在阅读Rubini&的"Linux设备驱动程序" [O'Reilly]. Corbet和许多在线资源,但在这个特定问题上我还找不到任何东西.

I'm not an expert on Linux device drivers or kernel modules, but I've been reading "Linux Device Drivers" [O'Reilly] by Rubini & Corbet and a number of online sources, but I haven't been able to find anything on this specific issue yet.

何时允许内核或驱动程序模块使用浮点寄存器?
如果是这样,谁负责保存和还原其内容?
(假设x86-64体系结构)

When is a kernel or driver module allowed to use floating-point registers?
If so, who is responsible for saving and restoring their contents?
(Assume x86-64 architecture)

如果我正确理解,则每当KM运行时,它就使用了已从某个应用程序线程中抢占的硬件上下文(或硬件线程或寄存器集-无论您要调用什么).如果您使用c编写KM,则编译器将正确地确保正确保存和还原了通用寄存器(就像在应用程序中一样),但是浮点寄存器不会自动发生这种情况.因此,许多KM甚至无法假设处理器具有任何浮点功能.

If I understand correctly, whenever a KM is running, it is using a hardware context (or hardware thread or register set -- whatever you want to call it) that has been preempted from some application thread. If you write your KM in c, the compiler will correctly insure that the general-purpose registers are properly saved and restored (much as in an application), but that doesn't automatically happen with floating-point registers. For that matter, a lot of KMs can't even assume that the processor has any floating-point capability.

在猜测要使用浮点的KM必须仔细保存和恢复浮点状态的情况下,我是否正确?有标准的内核函数可以做到这一点吗?

Am I correct in guessing that a KM that wants to use floating-point has to carefully save and restore the floating-point state? Are there standard kernel functions for doing this?

此代码的约定在任何地方都有说明吗?
对于非SMP SMP驱动程序,它们是否有所不同?
对于较早的非抢先内核和较新的抢先内核,它们是否有所不同?

Are the coding conventions for this spelled out anywhere?
Are they different for SMP-non SMP drivers?
Are they different for older non-preemptive kernels and newer preemptive kernels?

推荐答案

简短答案:如果内核代码被kernel_fpu_begin()/kernel_fpu_end()包围,则内核代码可以使用浮点.这些函数处理保存和还原fpu上下文.而且,它们调用preempt_disable()/preempt_enable(),这意味着这些功能之间的代码中没有休眠,页面错误等. Google函数名称以获取更多信息.

Short answer: Kernel code can use floating point if this use is surrounded by kernel_fpu_begin()/kernel_fpu_end(). These function handle saving and restoring the fpu context. Also, they call preempt_disable()/preempt_enable(), which means no sleeping, page faults etc. in the code between those functions. Google the function names for more information.

如果我理解正确,每当 KM正在运行,它正在使用硬件 上下文(或硬件线程或 寄存器组-无论您想要什么 称之为)已被抢占 一些应用程序线程.

If I understand correctly, whenever a KM is running, it is using a hardware context (or hardware thread or register set -- whatever you want to call it) that has been preempted from some application thread.

否,内核模块也可以在用户上下文中运行(例如,当用户空间在KM提供的设备上调用syscall时).但是,它与浮动问题无关.

No, a kernel module can run in user context as well (eg. when userspace calls syscalls on a device provided by the KM). It has, however, no relation to the float issue.

如果您使用c编写KM, 编译器将正确确保 通用寄存器是 正确保存和还原(如 在应用程序中),但这不是 自动发生 浮点寄存器.

If you write your KM in c, the compiler will correctly insure that the general-purpose registers are properly saved and restored (much as in an application), but that doesn't automatically happen with floating-point registers.

那不是因为编译器,而是因为内核上下文切换代码.

That is not because of the compiler, but because of the kernel context-switching code.

这篇关于在Linux设备驱动程序中使用浮点的编码约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆