为什么我能够执行浮动Linux内核模块内部浮点运算? [英] Why am I able to perform floating point operations inside a Linux kernel module?

查看:190
本文介绍了为什么我能够执行浮动Linux内核模块内部浮点运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在x86的CentOS 6.3(内核v2.6.32)系统中运行。

I'm running on an x86 CentOS 6.3 (kernel v2.6.32) system.

我整理了以下功能成为最基本的字符驱动程序模块作为一个实验,看看Linux内核是如何反应浮点运算。

I compiled the following function into a bare-bones character driver module as an experiment to see how the Linux kernel reacts to floating point operations.

static unsigned floatstuff(void){
    float x = 3.14;
    x *= 2.5;
    return x;
}

...

printk(KERN_INFO "x: %u", x);

在code编译(这没想到),所以我插入模块,并检查了日志,的dmesg 。日志显示: X:7

这似乎很奇怪;我以为你不能执行浮点运算在Linux内核 - 节省一些例外,如 kernel_fpu_begin()。该模块是如何执行浮点运算?

This seems strange; I thought you couldn't perform floating point operations in the Linux kernel -- save some exceptions such as kernel_fpu_begin(). How did the module perform the floating point operation?

这是因为我在x86处理器上?

Is this because I'm on an x86 processor?

推荐答案

不知道在哪里这种看法的来源。但是内核执行相同的处理器为用户模式code上,因此,可以访问相同的指令集。如果处理器可以执行浮点(直接或通过一个协处理器),内核也能。

Not sure where this perception is coming from. But the kernel executes on the same processor as the user mode code, and therefore has access to the same instruction set. If the processor can do floating point (directly or by a co-processor), the kernel can too.

也许你正在考虑在哪里浮点运算,是在软件仿真的情况下。但即便如此,它会在内核可(当然,除非以某种方式禁用)。

Maybe you are thinking of cases where floating point arithmetic is emulated in software. But even so, it would be available in kernel (well, unless disabled somehow).

我很好奇,其中这种看法来自何处?也许我失去了一些东西。

I am curious, where is this perception coming from? Maybe I am missing something.

发现这个。似乎是一个很好的解释。

Found this. Seems to be a good explanation.

这篇关于为什么我能够执行浮动Linux内核模块内部浮点运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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