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)
24 int i = vsnprintf(buf, size, fmt, args);
27 return (i >= ssize) ? (ssize - 1) : i;
30 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
37 i = vsnprintf(buf, size, fmt, args);
40 return (i >= ssize) ? (ssize - 1) : i;
43 #define printk(...) printf(__VA_ARGS__)
45 #define no_printk(fmt, ...) \
49 printk(fmt, ##__VA_ARGS__); \
54 #define pr_emerg(fmt, ...) \
55 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
56 #define pr_alert(fmt, ...) \
57 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
58 #define pr_crit(fmt, ...) \
59 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
60 #define pr_err(fmt, ...) \
61 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
62 #define pr_warning(fmt, ...) \
63 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
64 #define pr_warn pr_warning
65 #define pr_notice(fmt, ...) \
66 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
67 #define pr_info(fmt, ...) \
68 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
70 * Like KERN_CONT, pr_cont() should only be used when continuing
71 * a line with no newline ('\n') enclosed. Otherwise it defaults
72 * back to KERN_DEFAULT.
74 #define pr_cont(fmt, ...) \
75 printk(KERN_CONT fmt, ##__VA_ARGS__)
77 /* pr_devel() should produce zero code unless DEBUG is defined */
79 #define pr_devel(fmt, ...) \
80 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
82 #define pr_devel(fmt, ...) \
83 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
87 /* If you are writing a driver, please use dev_dbg instead */
88 #if defined(CONFIG_DYNAMIC_DEBUG)
89 #include <linux/dynamic_debug.h>
91 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
92 #define pr_debug(fmt, ...) \
93 dynamic_pr_debug(fmt, ##__VA_ARGS__)
95 #define pr_debug(fmt, ...) \
96 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
98 #define pr_debug(fmt, ...) \
99 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
103 * Print a one-time message (analogous to WARN_ONCE() et al):
106 #define printk_once(fmt, ...) \
108 static bool __print_once __read_mostly; \
109 bool __ret_print_once = !__print_once; \
111 if (!__print_once) { \
112 __print_once = true; \
113 printk(fmt, ##__VA_ARGS__); \
115 unlikely(__ret_print_once); \
117 #define printk_deferred_once(fmt, ...) \
119 static bool __print_once __read_mostly; \
120 bool __ret_print_once = !__print_once; \
122 if (!__print_once) { \
123 __print_once = true; \
124 printk_deferred(fmt, ##__VA_ARGS__); \
126 unlikely(__ret_print_once); \
129 #define pr_emerg_once(fmt, ...) \
130 printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
131 #define pr_alert_once(fmt, ...) \
132 printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
133 #define pr_crit_once(fmt, ...) \
134 printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
135 #define pr_err_once(fmt, ...) \
136 printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
137 #define pr_warn_once(fmt, ...) \
138 printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
139 #define pr_notice_once(fmt, ...) \
140 printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
141 #define pr_info_once(fmt, ...) \
142 printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
143 #define pr_cont_once(fmt, ...) \
144 printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
147 #define pr_devel_once(fmt, ...) \
148 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
150 #define pr_devel_once(fmt, ...) \
151 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
154 /* If you are writing a driver, please use dev_dbg instead */
156 #define pr_debug_once(fmt, ...) \
157 printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
159 #define pr_debug_once(fmt, ...) \
160 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
164 * ratelimited messages with local ratelimit_state,
165 * no local ratelimit_state used in the !PRINTK case
168 #define printk_ratelimited(fmt, ...) \
170 static DEFINE_RATELIMIT_STATE(_rs, \
171 DEFAULT_RATELIMIT_INTERVAL, \
172 DEFAULT_RATELIMIT_BURST); \
174 if (__ratelimit(&_rs)) \
175 printk(fmt, ##__VA_ARGS__); \
178 #define printk_ratelimited(fmt, ...) \
179 no_printk(fmt, ##__VA_ARGS__)
182 #define pr_emerg_ratelimited(fmt, ...) \
183 printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
184 #define pr_alert_ratelimited(fmt, ...) \
185 printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
186 #define pr_crit_ratelimited(fmt, ...) \
187 printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
188 #define pr_err_ratelimited(fmt, ...) \
189 printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
190 #define pr_warn_ratelimited(fmt, ...) \
191 printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
192 #define pr_notice_ratelimited(fmt, ...) \
193 printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
194 #define pr_info_ratelimited(fmt, ...) \
195 printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
196 /* no pr_cont_ratelimited, don't do that... */
199 #define pr_devel_ratelimited(fmt, ...) \
200 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
202 #define pr_devel_ratelimited(fmt, ...) \
203 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
205 #endif /* __TOOLS_LINUX_PRINTK_H */