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 ""
22 #define KERN_SOH "\001"
24 static inline int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
28 i = vsnprintf(buf, size, fmt, args);
37 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
43 i = vscnprintf(buf, size, fmt, args);
49 #define printk(...) printf(__VA_ARGS__)
50 #define vprintk(...) vprintf(__VA_ARGS__)
52 #define no_printk(fmt, ...) \
56 printk(fmt, ##__VA_ARGS__); \
61 #define pr_emerg(fmt, ...) \
62 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
63 #define pr_alert(fmt, ...) \
64 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
65 #define pr_crit(fmt, ...) \
66 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
67 #define pr_err(fmt, ...) \
68 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
69 #define pr_warning(fmt, ...) \
70 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
71 #define pr_warn pr_warning
72 #define pr_notice(fmt, ...) \
73 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
74 #define pr_info(fmt, ...) \
75 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
77 * Like KERN_CONT, pr_cont() should only be used when continuing
78 * a line with no newline ('\n') enclosed. Otherwise it defaults
79 * back to KERN_DEFAULT.
81 #define pr_cont(fmt, ...) \
82 printk(KERN_CONT fmt, ##__VA_ARGS__)
84 /* pr_devel() should produce zero code unless DEBUG is defined */
86 #define pr_devel(fmt, ...) \
87 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
89 #define pr_devel(fmt, ...) \
90 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
94 /* If you are writing a driver, please use dev_dbg instead */
95 #if defined(CONFIG_DYNAMIC_DEBUG)
96 #include <linux/dynamic_debug.h>
98 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
99 #define pr_debug(fmt, ...) \
100 dynamic_pr_debug(fmt, ##__VA_ARGS__)
102 #define pr_debug(fmt, ...) \
103 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
105 #define pr_debug(fmt, ...) \
106 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
110 * Print a one-time message (analogous to WARN_ONCE() et al):
113 #define printk_once(fmt, ...) \
115 static bool __print_once __read_mostly; \
116 bool __ret_print_once = !__print_once; \
118 if (!__print_once) { \
119 __print_once = true; \
120 printk(fmt, ##__VA_ARGS__); \
122 unlikely(__ret_print_once); \
124 #define printk_deferred_once(fmt, ...) \
126 static bool __print_once __read_mostly; \
127 bool __ret_print_once = !__print_once; \
129 if (!__print_once) { \
130 __print_once = true; \
131 printk_deferred(fmt, ##__VA_ARGS__); \
133 unlikely(__ret_print_once); \
136 #define pr_emerg_once(fmt, ...) \
137 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
138 #define pr_alert_once(fmt, ...) \
139 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
140 #define pr_crit_once(fmt, ...) \
141 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
142 #define pr_err_once(fmt, ...) \
143 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
144 #define pr_warn_once(fmt, ...) \
145 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
146 #define pr_notice_once(fmt, ...) \
147 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
148 #define pr_info_once(fmt, ...) \
149 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
150 #define pr_cont_once(fmt, ...) \
151 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
154 #define pr_devel_once(fmt, ...) \
155 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
157 #define pr_devel_once(fmt, ...) \
158 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
161 /* If you are writing a driver, please use dev_dbg instead */
163 #define pr_debug_once(fmt, ...) \
164 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
166 #define pr_debug_once(fmt, ...) \
167 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
171 * ratelimited messages with local ratelimit_state,
172 * no local ratelimit_state used in the !PRINTK case
174 #define printk_ratelimited(fmt, ...) \
176 static DEFINE_RATELIMIT_STATE(_rs, \
177 DEFAULT_RATELIMIT_INTERVAL, \
178 DEFAULT_RATELIMIT_BURST); \
180 if (__ratelimit(&_rs)) \
181 printk(fmt, ##__VA_ARGS__); \
184 #define pr_emerg_ratelimited(fmt, ...) \
185 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
186 #define pr_alert_ratelimited(fmt, ...) \
187 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
188 #define pr_crit_ratelimited(fmt, ...) \
189 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
190 #define pr_err_ratelimited(fmt, ...) \
191 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
192 #define pr_warn_ratelimited(fmt, ...) \
193 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
194 #define pr_notice_ratelimited(fmt, ...) \
195 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
196 #define pr_info_ratelimited(fmt, ...) \
197 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
198 /* no pr_cont_ratelimited, don't do that... */
201 #define pr_devel_ratelimited(fmt, ...) \
202 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
204 #define pr_devel_ratelimited(fmt, ...) \
205 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
207 #endif /* __TOOLS_LINUX_PRINTK_H */