fmt
...
This is printk. It can be called from any context. We want it to work.
We try to grab the console_sem. If we succeed, it's easy - we log the output and call the console drivers. If we fail to get the semaphore we place the output into the log buffer and return. The current holder of the console_sem will notice the new output in release_console_sem and will send it to the consoles before releasing the semaphore.
One effect of this deferred printing is that code which calls printk and then changes console_loglevel may break. This is because console_loglevel is inspected when the actual printing occurs.
printf(3)
See the vsnprintf documentation for format string extensions over C99.