0

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

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
Raulp
  • 7,758
  • 20
  • 93
  • 155

2 Answers2

1

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.

gby
  • 14,900
  • 40
  • 57
1

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.

Community
  • 1
  • 1
Joe Kul
  • 2,454
  • 16
  • 16
  • What does “I used to think that” refer to? If it refers to another answer, you should know that answers are displayed out of order. StackOverflow is not a discussion site and questions are not discussion threads. Write self-contained answers. If you want to comment on an existing question, use the corresponding feature (perhaps after having reach the reputation that allows to use it). – Pascal Cuoq Nov 02 '13 at 06:07