1 #ifndef __TOOLS_LINUX_PRINTK_H
2 #define __TOOLS_LINUX_PRINTK_H
5 #define pr_fmt(fmt) fmt
8 #include <linux/compiler.h>
16 #define KERN_WARNING ""
17 #define KERN_NOTICE ""
20 #define KERN_DEFAULT ""
23 static inline int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
27 i = vsnprintf(buf, size, fmt, args);
36 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
42 i = vscnprintf(buf, size, fmt, args);
48 #define printk(...) printf(__VA_ARGS__)
49 #define vprintk(...) vprintf(__VA_ARGS__)
51 #define no_printk(fmt, ...) \
55 printk(fmt, ##__VA_ARGS__); \
60 #define pr_emerg(fmt, ...) \
61 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
62 #define pr_alert(fmt, ...) \
63 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
64 #define pr_crit(fmt, ...) \
65 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
66 #define pr_err(fmt, ...) \
67 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
68 #define pr_warning(fmt, ...) \
69 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
70 #define pr_warn pr_warning
71 #define pr_notice(fmt, ...) \
72 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
73 #define pr_info(fmt, ...) \
74 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
76 * Like KERN_CONT, pr_cont() should only be used when continuing
77 * a line with no newline ('\n') enclosed. Otherwise it defaults
78 * back to KERN_DEFAULT.
80 #define pr_cont(fmt, ...) \
81 printk(KERN_CONT fmt, ##__VA_ARGS__)
83 /* pr_devel() should produce zero code unless DEBUG is defined */
85 #define pr_devel(fmt, ...) \
86 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
88 #define pr_devel(fmt, ...) \
89 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
93 /* If you are writing a driver, please use dev_dbg instead */
94 #if defined(CONFIG_DYNAMIC_DEBUG)
95 #include <linux/dynamic_debug.h>
97 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
98 #define pr_debug(fmt, ...) \
99 dynamic_pr_debug(fmt, ##__VA_ARGS__)
101 #define pr_debug(fmt, ...) \
102 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
104 #define pr_debug(fmt, ...) \
105 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
109 * Print a one-time message (analogous to WARN_ONCE() et al):
112 #define printk_once(fmt, ...) \
114 static bool __print_once __read_mostly; \
115 bool __ret_print_once = !__print_once; \
117 if (!__print_once) { \
118 __print_once = true; \
119 printk(fmt, ##__VA_ARGS__); \
121 unlikely(__ret_print_once); \
123 #define printk_deferred_once(fmt, ...) \
125 static bool __print_once __read_mostly; \
126 bool __ret_print_once = !__print_once; \
128 if (!__print_once) { \
129 __print_once = true; \
130 printk_deferred(fmt, ##__VA_ARGS__); \
132 unlikely(__ret_print_once); \
135 #define pr_emerg_once(fmt, ...) \
136 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
137 #define pr_alert_once(fmt, ...) \
138 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
139 #define pr_crit_once(fmt, ...) \
140 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
141 #define pr_err_once(fmt, ...) \
142 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
143 #define pr_warn_once(fmt, ...) \
144 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
145 #define pr_notice_once(fmt, ...) \
146 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
147 #define pr_info_once(fmt, ...) \
148 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
149 #define pr_cont_once(fmt, ...) \
150 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
153 #define pr_devel_once(fmt, ...) \
154 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
156 #define pr_devel_once(fmt, ...) \
157 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
160 /* If you are writing a driver, please use dev_dbg instead */
162 #define pr_debug_once(fmt, ...) \
163 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
165 #define pr_debug_once(fmt, ...) \
166 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
170 * ratelimited messages with local ratelimit_state,
171 * no local ratelimit_state used in the !PRINTK case
173 #define printk_ratelimited(fmt, ...) \
175 static DEFINE_RATELIMIT_STATE(_rs, \
176 DEFAULT_RATELIMIT_INTERVAL, \
177 DEFAULT_RATELIMIT_BURST); \
179 if (__ratelimit(&_rs)) \
180 printk(fmt, ##__VA_ARGS__); \
183 #define pr_emerg_ratelimited(fmt, ...) \
184 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
185 #define pr_alert_ratelimited(fmt, ...) \
186 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
187 #define pr_crit_ratelimited(fmt, ...) \
188 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
189 #define pr_err_ratelimited(fmt, ...) \
190 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
191 #define pr_warn_ratelimited(fmt, ...) \
192 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
193 #define pr_notice_ratelimited(fmt, ...) \
194 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
195 #define pr_info_ratelimited(fmt, ...) \
196 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
197 /* no pr_cont_ratelimited, don't do that... */
200 #define pr_devel_ratelimited(fmt, ...) \
201 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
203 #define pr_devel_ratelimited(fmt, ...) \
204 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
206 #endif /* __TOOLS_LINUX_PRINTK_H */