Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
printk.h File Reference
#include <zephyr/toolchain.h>
#include <stddef.h>
#include <stdarg.h>
#include <inttypes.h>

Go to the source code of this file.

Functions

void printk (const char *fmt,...)
 Print kernel debugging message.
void vprintk (const char *fmt, va_list ap)
 Print kernel debugging message, va_list version.
void printk_unlocked (const char *fmt,...)
 Output a string without taking the printk lock.
void vprintk_unlocked (const char *fmt, va_list ap)
 Output a string without any locking, va_list version.
void printk_panic (void)
 Stop printk() taking its lock, for crash reporting.
int snprintk (char *str, size_t size, const char *fmt,...)
 Print a kernel debugging message to a buffer.
int vsnprintk (char *str, size_t size, const char *fmt, va_list ap)
 Print a kernel debugging message to a buffer, va_list version.

Function Documentation

◆ printk()

void printk ( const char * fmt,
... )

Print kernel debugging message.

This routine prints a kernel debugging message to the system console. Output is send immediately, without any mutual exclusion or buffering.

A basic set of conversion specifier characters are supported:

  • signed decimal: %d, %i
  • unsigned decimal: %u
  • unsigned hexadecimal: %x (%X is treated as %x)
  • pointer: %p
  • string: %s
  • character: %c
  • percent: %%

Field width (with or without leading zeroes) is supported. Length attributes h, hh, l, ll and z are supported. However, integral values with lld and lli are only printed if they fit in a long otherwise 'ERR' is printed. Full 64-bit values may be printed with llx. Flags and precision attributes are not supported.

Parameters
fmtFormat string.
...Optional list of format arguments.

◆ printk_panic()

void printk_panic ( void )

Stop printk() taking its lock, for crash reporting.

After this, printk() behaves as if every caller had used printk_unlocked(). Once a fatal error is being handled the lock cannot be trusted: the faulting context may have died holding it, or a CPU that will never run again may own it, and any later printk() would block for ever. Individual call sites cannot fix that, because code reached after the failure does not know it is in a crash.

Called by the fatal error path. One way, for the rest of the system's life.

◆ printk_unlocked()

void printk_unlocked ( const char * fmt,
... )

Output a string without taking the printk lock.

Same output as printk(), but the spinlock is never taken and both the logging subsystem and the user mode buffer are bypassed: text goes straight to the platform's character output hook.

For callers that cannot take the lock: a crash whose lock holder is dead, output re-entered from inside printk() itself, or early boot before the atomics a spinlock needs are usable. Output may interleave with a concurrent printk(), which beats hanging or losing it.

Note
Kernel context only, and only as lock free as the output hook.
Parameters
fmtFormat string.
...Optional list of format arguments.

◆ snprintk()

int snprintk ( char * str,
size_t size,
const char * fmt,
... )

Print a kernel debugging message to a buffer.

Formats as printk() does, but writes to str instead of the console. The output is truncated if it does not fit, and is NUL terminated as long as size is not zero.

Parameters
strBuffer to write to.
sizeSize of the buffer, in bytes.
fmtFormat string.
...Optional list of format arguments.
Returns
Number of characters that would have been written, not counting the terminating NUL. A value of size or more means the output was truncated.

◆ vprintk()

void vprintk ( const char * fmt,
va_list ap )

Print kernel debugging message, va_list version.

See printk() for the output format.

Parameters
fmtFormat string.
apFormat arguments.

◆ vprintk_unlocked()

void vprintk_unlocked ( const char * fmt,
va_list ap )

Output a string without any locking, va_list version.

See printk_unlocked() for when this is appropriate and what it gives up.

Parameters
fmtFormat string.
apFormat arguments.

◆ vsnprintk()

int vsnprintk ( char * str,
size_t size,
const char * fmt,
va_list ap )

Print a kernel debugging message to a buffer, va_list version.

See snprintk() for the formatting and the buffer handling.

Parameters
strBuffer to write to.
sizeSize of the buffer, in bytes.
fmtFormat string.
apFormat arguments.
Returns
Number of characters that would have been written, not counting the terminating NUL.