Electronic – An overhead of running program on Linux vs embedded bare-metal

armlinuxmicrocontrollerprogramming

Let's say I have some multi-core ARM Cortex-A.

Now I have there a Linux, with RT_PREEMPT patch (so called real-time Linux). I run a processes with affinity set to one core and high priority (above 50).

Thanks to real-time patch, even the kernel scheduler cannot preempt my process, and thanks to affinity it can run all the time on a single core (and OS on others).

In such conditions, is there any difference (i.e. overhead) of running such code on Linux vs bare-metal?
Will the performance be the same? If not, why?

Best Answer

Overhead does not relate to preemption. Preemption stops your process and runs another process. If you disable that for e.g. one CPU core, you have the CPU core alone for your process.

Still, there's an overhead if you do I/O through the Linux I/O functions instead e.g. controlling the I/O lines directly through your process. But, for any reasonably complicated I/O, you had to implement a function with similar overhead yourself and you can assume the Linux folks are better than you in that – more experience and more test cases.

So, the only way you could win the overhead race is with very basal I/O functions (e.g. bitbanging an exotic, fast protocol) you implement yourself in "your kernel" instead of running it through the various abstraction layers of the Linux GPIO subsystem and do the same in "your userspace process".