Hello,
How significant can printf() degrade kernel performance, even it’s under unreachable line (i.e. if (false))?
Regards
Abdoulaye
Hello,
How significant can printf() degrade kernel performance, even it’s under unreachable line (i.e. if (false))?
Regards
Abdoulaye
Even if the printf() is in fact unreachable, it could still add to register pressure. Also, like any non-inlined function call, it may inhibit code motion across the call site, as the compiler cannot know what state (if any) the function modifies.
The performance impact cannot be determined on a theoretical basis as much depends on the nature of the kernel. Best to measure it within the context of your actual code if this a concern.
and write logs into a file is better? what is the best practice?
One cannot perform file operations from inside a kernel. Pretty much the only time I use printf() inside a kernel is for debugging or test purposes, in which case performance aspects are secondary.
IMHO the best practice is to not perform I/O from inside kernels.