1 #ifndef __TOOLS_LINUX_PRINTK_H
2 #define __TOOLS_LINUX_PRINTK_H
5 #define pr_fmt(fmt) fmt
15 #define KERN_WARNING ""
16 #define KERN_NOTICE ""
19 #define KERN_DEFAULT ""
22 static inline int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
26 i = vsnprintf(buf, size, fmt, args);
35 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
41 i = vscnprintf(buf, size, fmt, args);
47 #define printk(...) printf(__VA_ARGS__)
48 #define vprintk(...) vprintf(__VA_ARGS__)
50 #define no_printk(fmt, ...) \
54 printk(fmt, ##__VA_ARGS__); \
59 #define pr_emerg(fmt, ...) \
60 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
61 #define pr_alert(fmt, ...) \
62 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
63 #define pr_crit(fmt, ...) \
64 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
65 #define pr_err(fmt, ...) \
66 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
67 #define pr_warning(fmt, ...) \
68 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
69 #define pr_warn pr_warning
70 #define pr_notice(fmt, ...) \
71 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
72 #define pr_info(fmt, ...) \
73 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
75 * Like KERN_CONT, pr_cont() should only be used when continuing
76 * a line with no newline ('\n') enclosed. Otherwise it defaults
77 * back to KERN_DEFAULT.
79 #define pr_cont(fmt, ...) \
80 printk(KERN_CONT fmt, ##__VA_ARGS__)
82 /* pr_devel() should produce zero code unless DEBUG is defined */
84 #define pr_devel(fmt, ...) \
85 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
87 #define pr_devel(fmt, ...) \
88 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
92 /* If you are writing a driver, please use dev_dbg instead */
93 #if defined(CONFIG_DYNAMIC_DEBUG)
94 #include <linux/dynamic_debug.h>
96 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
97 #define pr_debug(fmt, ...) \
98 dynamic_pr_debug(fmt, ##__VA_ARGS__)
100 #define pr_debug(fmt, ...) \
101 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
103 #define pr_debug(fmt, ...) \
104 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
108 * Print a one-time message (analogous to WARN_ONCE() et al):
111 #define printk_once(fmt, ...) \
113 static bool __print_once __read_mostly; \
114 bool __ret_print_once = !__print_once; \
116 if (!__print_once) { \
117 __print_once = true; \
118 printk(fmt, ##__VA_ARGS__); \
120 unlikely(__ret_print_once); \
122 #define printk_deferred_once(fmt, ...) \
124 static bool __print_once __read_mostly; \
125 bool __ret_print_once = !__print_once; \
127 if (!__print_once) { \
128 __print_once = true; \
129 printk_deferred(fmt, ##__VA_ARGS__); \
131 unlikely(__ret_print_once); \
134 #define pr_emerg_once(fmt, ...) \
135 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
136 #define pr_alert_once(fmt, ...) \
137 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
138 #define pr_crit_once(fmt, ...) \
139 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
140 #define pr_err_once(fmt, ...) \
141 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
142 #define pr_warn_once(fmt, ...) \
143 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
144 #define pr_notice_once(fmt, ...) \
145 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
146 #define pr_info_once(fmt, ...) \
147 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
148 #define pr_cont_once(fmt, ...) \
149 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
152 #define pr_devel_once(fmt, ...) \
153 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
155 #define pr_devel_once(fmt, ...) \
156 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
159 /* If you are writing a driver, please use dev_dbg instead */
161 #define pr_debug_once(fmt, ...) \
162 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
164 #define pr_debug_once(fmt, ...) \
165 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
169 * ratelimited messages with local ratelimit_state,
170 * 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 printk_ratelimited(fmt, ...) \
184 no_printk(fmt, ##__VA_ARGS__)
187 #define pr_emerg_ratelimited(fmt, ...) \
188 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
189 #define pr_alert_ratelimited(fmt, ...) \
190 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
191 #define pr_crit_ratelimited(fmt, ...) \
192 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
193 #define pr_err_ratelimited(fmt, ...) \
194 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
195 #define pr_warn_ratelimited(fmt, ...) \
196 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
197 #define pr_notice_ratelimited(fmt, ...) \
198 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
199 #define pr_info_ratelimited(fmt, ...) \
200 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
201 /* no pr_cont_ratelimited, don't do that... */
204 #define pr_devel_ratelimited(fmt, ...) \
205 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
207 #define pr_devel_ratelimited(fmt, ...) \
208 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
210 #endif /* __TOOLS_LINUX_PRINTK_H */