Raulp
Raulp

Reputation: 8196

Printk for Floating Values inside kernel

Is there a way to log/Print the floating values inside the kernel.Does it depends on the FPU on which the kernel is running?

While compiling printk(KERN_DEBUG "error = %f " ,floatvalue) ,I am getting the error :

undefined reference to __aeabi_f2d

Upvotes: 0

Views: 4512

Answers (2)

Joe Kul
Joe Kul

Reputation: 2534

I used to think that. But actually, floating point is supported sometimes. It depends on CPU architecture, and on kernel version. For example, Linus's answer. I am not saying you should use FP, but it is possible. It may have come in to kernel around 2.6.32, see lxr.free-electrons.

Raulp, your undefined reference error looks like it is trying to use a lib routine. That won't work, Linus points to gcc in-line. I am not too familiar but maybe see this or this.

Upvotes: 1

gby
gby

Reputation: 15218

Using any kind of floating point arithmetic inside the Linux kernel is a bug.

If the processor you are running on does not have an FPU, then there is nothing to perform the calculation you are trying to do (software FPUs are driven from the kernel and does not work inside of it).

If the processor you are running on does have an FPU, the situation is even worse - since the kernel switches contexts between tasks it needs to save the context (set of registers) of each task. The time it takes to conetxt switch depends on the how much context needs to be saved. As an optimization, the kernel only saves and restores the context of the FPU when it schedules in and out a task that used the PFU but not when a system call or interrupt has triggered the context switch into the kernel and the same task stays the current task.

This means that if you write code that uses the FPU inside the kernel, you have potentially corrupted the FPU state of the currently running user space task.

Upvotes: 1

Related Questions