Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

include/linux/kernel.h: Move logging bits to include/linux/printk.h

Move the logging bits from kernel.h into printk.h so that
there is a bit more logical separation of the generic from
the printk logging specific parts.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+249 -244
+1 -244
include/linux/kernel.h
··· 17 17 #include <linux/bitops.h> 18 18 #include <linux/log2.h> 19 19 #include <linux/typecheck.h> 20 + #include <linux/printk.h> 20 21 #include <linux/dynamic_debug.h> 21 22 #include <asm/byteorder.h> 22 23 #include <asm/bug.h> 23 - 24 - extern const char linux_banner[]; 25 - extern const char linux_proc_banner[]; 26 24 27 25 #define USHRT_MAX ((u16)(~0U)) 28 26 #define SHRT_MAX ((s16)(USHRT_MAX>>1)) ··· 108 110 */ 109 111 #define lower_32_bits(n) ((u32)(n)) 110 112 111 - #define KERN_EMERG "<0>" /* system is unusable */ 112 - #define KERN_ALERT "<1>" /* action must be taken immediately */ 113 - #define KERN_CRIT "<2>" /* critical conditions */ 114 - #define KERN_ERR "<3>" /* error conditions */ 115 - #define KERN_WARNING "<4>" /* warning conditions */ 116 - #define KERN_NOTICE "<5>" /* normal but significant condition */ 117 - #define KERN_INFO "<6>" /* informational */ 118 - #define KERN_DEBUG "<7>" /* debug-level messages */ 119 - 120 - /* Use the default kernel loglevel */ 121 - #define KERN_DEFAULT "<d>" 122 - /* 123 - * Annotation for a "continued" line of log printout (only done after a 124 - * line that had no enclosing \n). Only to be used by core/arch code 125 - * during early bootup (a continued line is not SMP-safe otherwise). 126 - */ 127 - #define KERN_CONT "<c>" 128 - 129 - extern int console_printk[]; 130 - 131 - #define console_loglevel (console_printk[0]) 132 - #define default_message_loglevel (console_printk[1]) 133 - #define minimum_console_loglevel (console_printk[2]) 134 - #define default_console_loglevel (console_printk[3]) 135 - 136 113 struct completion; 137 114 struct pt_regs; 138 115 struct user; ··· 159 186 might_sleep(); 160 187 } 161 188 #endif 162 - 163 - struct va_format { 164 - const char *fmt; 165 - va_list *va; 166 - }; 167 189 168 190 extern struct atomic_notifier_head panic_notifier_list; 169 191 extern long (*panic_blink)(int state); ··· 213 245 struct pid; 214 246 extern struct pid *session_of_pgrp(struct pid *pgrp); 215 247 216 - /* 217 - * FW_BUG 218 - * Add this to a message where you are sure the firmware is buggy or behaves 219 - * really stupid or out of spec. Be aware that the responsible BIOS developer 220 - * should be able to fix this issue or at least get a concrete idea of the 221 - * problem by reading your message without the need of looking at the kernel 222 - * code. 223 - * 224 - * Use it for definite and high priority BIOS bugs. 225 - * 226 - * FW_WARN 227 - * Use it for not that clear (e.g. could the kernel messed up things already?) 228 - * and medium priority BIOS bugs. 229 - * 230 - * FW_INFO 231 - * Use this one if you want to tell the user or vendor about something 232 - * suspicious, but generally harmless related to the firmware. 233 - * 234 - * Use it for information or very low priority BIOS bugs. 235 - */ 236 - #define FW_BUG "[Firmware Bug]: " 237 - #define FW_WARN "[Firmware Warn]: " 238 - #define FW_INFO "[Firmware Info]: " 239 - 240 - /* 241 - * HW_ERR 242 - * Add this to a message for hardware errors, so that user can report 243 - * it to hardware vendor instead of LKML or software vendor. 244 - */ 245 - #define HW_ERR "[Hardware Error]: " 246 - 247 - #ifdef CONFIG_PRINTK 248 - asmlinkage int vprintk(const char *fmt, va_list args) 249 - __attribute__ ((format (printf, 1, 0))); 250 - asmlinkage int printk(const char * fmt, ...) 251 - __attribute__ ((format (printf, 1, 2))) __cold; 252 - 253 - /* 254 - * Please don't use printk_ratelimit(), because it shares ratelimiting state 255 - * with all other unrelated printk_ratelimit() callsites. Instead use 256 - * printk_ratelimited() or plain old __ratelimit(). 257 - */ 258 - extern int __printk_ratelimit(const char *func); 259 - #define printk_ratelimit() __printk_ratelimit(__func__) 260 - extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, 261 - unsigned int interval_msec); 262 - 263 - extern int printk_delay_msec; 264 - extern int dmesg_restrict; 265 - 266 - /* 267 - * Print a one-time message (analogous to WARN_ONCE() et al): 268 - */ 269 - #define printk_once(x...) ({ \ 270 - static bool __print_once; \ 271 - \ 272 - if (!__print_once) { \ 273 - __print_once = true; \ 274 - printk(x); \ 275 - } \ 276 - }) 277 - 278 - void log_buf_kexec_setup(void); 279 - #else 280 - static inline int vprintk(const char *s, va_list args) 281 - __attribute__ ((format (printf, 1, 0))); 282 - static inline int vprintk(const char *s, va_list args) { return 0; } 283 - static inline int printk(const char *s, ...) 284 - __attribute__ ((format (printf, 1, 2))); 285 - static inline int __cold printk(const char *s, ...) { return 0; } 286 - static inline int printk_ratelimit(void) { return 0; } 287 - static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ 288 - unsigned int interval_msec) \ 289 - { return false; } 290 - 291 - /* No effect, but we still get type checking even in the !PRINTK case: */ 292 - #define printk_once(x...) printk(x) 293 - 294 - static inline void log_buf_kexec_setup(void) 295 - { 296 - } 297 - #endif 298 - 299 - /* 300 - * Dummy printk for disabled debugging statements to use whilst maintaining 301 - * gcc's format and side-effect checking. 302 - */ 303 - static inline __attribute__ ((format (printf, 1, 2))) 304 - int no_printk(const char *s, ...) { return 0; } 305 - 306 - extern int printk_needs_cpu(int cpu); 307 - extern void printk_tick(void); 308 - 309 - extern void asmlinkage __attribute__((format(printf, 1, 2))) 310 - early_printk(const char *fmt, ...); 311 - 312 248 unsigned long int_sqrt(unsigned long); 313 - 314 - static inline void console_silent(void) 315 - { 316 - console_loglevel = 0; 317 - } 318 - 319 - static inline void console_verbose(void) 320 - { 321 - if (console_loglevel) 322 - console_loglevel = 15; 323 - } 324 249 325 250 extern void bust_spinlocks(int yes); 326 251 extern void wake_up_klogd(void); ··· 251 390 #define TAINT_CRAP 10 252 391 #define TAINT_FIRMWARE_WORKAROUND 11 253 392 254 - extern void dump_stack(void) __cold; 255 - 256 - enum { 257 - DUMP_PREFIX_NONE, 258 - DUMP_PREFIX_ADDRESS, 259 - DUMP_PREFIX_OFFSET 260 - }; 261 - extern void hex_dump_to_buffer(const void *buf, size_t len, 262 - int rowsize, int groupsize, 263 - char *linebuf, size_t linebuflen, bool ascii); 264 - extern void print_hex_dump(const char *level, const char *prefix_str, 265 - int prefix_type, int rowsize, int groupsize, 266 - const void *buf, size_t len, bool ascii); 267 - extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, 268 - const void *buf, size_t len); 269 - 270 393 extern const char hex_asc[]; 271 394 #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] 272 395 #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] ··· 263 418 } 264 419 265 420 extern int hex_to_bin(char ch); 266 - 267 - #ifndef pr_fmt 268 - #define pr_fmt(fmt) fmt 269 - #endif 270 - 271 - #define pr_emerg(fmt, ...) \ 272 - printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 273 - #define pr_alert(fmt, ...) \ 274 - printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 275 - #define pr_crit(fmt, ...) \ 276 - printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 277 - #define pr_err(fmt, ...) \ 278 - printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 279 - #define pr_warning(fmt, ...) \ 280 - printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 281 - #define pr_warn pr_warning 282 - #define pr_notice(fmt, ...) \ 283 - printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 284 - #define pr_info(fmt, ...) \ 285 - printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 286 - #define pr_cont(fmt, ...) \ 287 - printk(KERN_CONT fmt, ##__VA_ARGS__) 288 - 289 - /* pr_devel() should produce zero code unless DEBUG is defined */ 290 - #ifdef DEBUG 291 - #define pr_devel(fmt, ...) \ 292 - printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 293 - #else 294 - #define pr_devel(fmt, ...) \ 295 - ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 296 - #endif 297 - 298 - /* If you are writing a driver, please use dev_dbg instead */ 299 - #if defined(DEBUG) 300 - #define pr_debug(fmt, ...) \ 301 - printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 302 - #elif defined(CONFIG_DYNAMIC_DEBUG) 303 - /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ 304 - #define pr_debug(fmt, ...) \ 305 - dynamic_pr_debug(fmt, ##__VA_ARGS__) 306 - #else 307 - #define pr_debug(fmt, ...) \ 308 - ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 309 - #endif 310 - 311 - /* 312 - * ratelimited messages with local ratelimit_state, 313 - * no local ratelimit_state used in the !PRINTK case 314 - */ 315 - #ifdef CONFIG_PRINTK 316 - #define printk_ratelimited(fmt, ...) ({ \ 317 - static DEFINE_RATELIMIT_STATE(_rs, \ 318 - DEFAULT_RATELIMIT_INTERVAL, \ 319 - DEFAULT_RATELIMIT_BURST); \ 320 - \ 321 - if (__ratelimit(&_rs)) \ 322 - printk(fmt, ##__VA_ARGS__); \ 323 - }) 324 - #else 325 - /* No effect, but we still get type checking even in the !PRINTK case: */ 326 - #define printk_ratelimited printk 327 - #endif 328 - 329 - #define pr_emerg_ratelimited(fmt, ...) \ 330 - printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 331 - #define pr_alert_ratelimited(fmt, ...) \ 332 - printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 333 - #define pr_crit_ratelimited(fmt, ...) \ 334 - printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 335 - #define pr_err_ratelimited(fmt, ...) \ 336 - printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 337 - #define pr_warning_ratelimited(fmt, ...) \ 338 - printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 339 - #define pr_warn_ratelimited pr_warning_ratelimited 340 - #define pr_notice_ratelimited(fmt, ...) \ 341 - printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 342 - #define pr_info_ratelimited(fmt, ...) \ 343 - printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 344 - /* no pr_cont_ratelimited, don't do that... */ 345 - /* If you are writing a driver, please use dev_dbg instead */ 346 - #if defined(DEBUG) 347 - #define pr_debug_ratelimited(fmt, ...) \ 348 - printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 349 - #else 350 - #define pr_debug_ratelimited(fmt, ...) \ 351 - ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ 352 - ##__VA_ARGS__); 0; }) 353 - #endif 354 421 355 422 /* 356 423 * General tracing related utility functions - trace_printk(),
+248
include/linux/printk.h
··· 1 + #ifndef __KERNEL_PRINTK__ 2 + #define __KERNEL_PRINTK__ 3 + 4 + extern const char linux_banner[]; 5 + extern const char linux_proc_banner[]; 6 + 7 + #define KERN_EMERG "<0>" /* system is unusable */ 8 + #define KERN_ALERT "<1>" /* action must be taken immediately */ 9 + #define KERN_CRIT "<2>" /* critical conditions */ 10 + #define KERN_ERR "<3>" /* error conditions */ 11 + #define KERN_WARNING "<4>" /* warning conditions */ 12 + #define KERN_NOTICE "<5>" /* normal but significant condition */ 13 + #define KERN_INFO "<6>" /* informational */ 14 + #define KERN_DEBUG "<7>" /* debug-level messages */ 15 + 16 + /* Use the default kernel loglevel */ 17 + #define KERN_DEFAULT "<d>" 18 + /* 19 + * Annotation for a "continued" line of log printout (only done after a 20 + * line that had no enclosing \n). Only to be used by core/arch code 21 + * during early bootup (a continued line is not SMP-safe otherwise). 22 + */ 23 + #define KERN_CONT "<c>" 24 + 25 + extern int console_printk[]; 26 + 27 + #define console_loglevel (console_printk[0]) 28 + #define default_message_loglevel (console_printk[1]) 29 + #define minimum_console_loglevel (console_printk[2]) 30 + #define default_console_loglevel (console_printk[3]) 31 + 32 + struct va_format { 33 + const char *fmt; 34 + va_list *va; 35 + }; 36 + 37 + /* 38 + * FW_BUG 39 + * Add this to a message where you are sure the firmware is buggy or behaves 40 + * really stupid or out of spec. Be aware that the responsible BIOS developer 41 + * should be able to fix this issue or at least get a concrete idea of the 42 + * problem by reading your message without the need of looking at the kernel 43 + * code. 44 + * 45 + * Use it for definite and high priority BIOS bugs. 46 + * 47 + * FW_WARN 48 + * Use it for not that clear (e.g. could the kernel messed up things already?) 49 + * and medium priority BIOS bugs. 50 + * 51 + * FW_INFO 52 + * Use this one if you want to tell the user or vendor about something 53 + * suspicious, but generally harmless related to the firmware. 54 + * 55 + * Use it for information or very low priority BIOS bugs. 56 + */ 57 + #define FW_BUG "[Firmware Bug]: " 58 + #define FW_WARN "[Firmware Warn]: " 59 + #define FW_INFO "[Firmware Info]: " 60 + 61 + /* 62 + * HW_ERR 63 + * Add this to a message for hardware errors, so that user can report 64 + * it to hardware vendor instead of LKML or software vendor. 65 + */ 66 + #define HW_ERR "[Hardware Error]: " 67 + 68 + #ifdef CONFIG_PRINTK 69 + asmlinkage int vprintk(const char *fmt, va_list args) 70 + __attribute__ ((format (printf, 1, 0))); 71 + asmlinkage int printk(const char * fmt, ...) 72 + __attribute__ ((format (printf, 1, 2))) __cold; 73 + 74 + /* 75 + * Please don't use printk_ratelimit(), because it shares ratelimiting state 76 + * with all other unrelated printk_ratelimit() callsites. Instead use 77 + * printk_ratelimited() or plain old __ratelimit(). 78 + */ 79 + extern int __printk_ratelimit(const char *func); 80 + #define printk_ratelimit() __printk_ratelimit(__func__) 81 + extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, 82 + unsigned int interval_msec); 83 + 84 + extern int printk_delay_msec; 85 + extern int dmesg_restrict; 86 + 87 + /* 88 + * Print a one-time message (analogous to WARN_ONCE() et al): 89 + */ 90 + #define printk_once(x...) ({ \ 91 + static bool __print_once; \ 92 + \ 93 + if (!__print_once) { \ 94 + __print_once = true; \ 95 + printk(x); \ 96 + } \ 97 + }) 98 + 99 + void log_buf_kexec_setup(void); 100 + #else 101 + static inline int vprintk(const char *s, va_list args) 102 + __attribute__ ((format (printf, 1, 0))); 103 + static inline int vprintk(const char *s, va_list args) { return 0; } 104 + static inline int printk(const char *s, ...) 105 + __attribute__ ((format (printf, 1, 2))); 106 + static inline int __cold printk(const char *s, ...) { return 0; } 107 + static inline int printk_ratelimit(void) { return 0; } 108 + static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ 109 + unsigned int interval_msec) \ 110 + { return false; } 111 + 112 + /* No effect, but we still get type checking even in the !PRINTK case: */ 113 + #define printk_once(x...) printk(x) 114 + 115 + static inline void log_buf_kexec_setup(void) 116 + { 117 + } 118 + #endif 119 + 120 + /* 121 + * Dummy printk for disabled debugging statements to use whilst maintaining 122 + * gcc's format and side-effect checking. 123 + */ 124 + static inline __attribute__ ((format (printf, 1, 2))) 125 + int no_printk(const char *s, ...) { return 0; } 126 + 127 + extern int printk_needs_cpu(int cpu); 128 + extern void printk_tick(void); 129 + 130 + extern void asmlinkage __attribute__((format(printf, 1, 2))) 131 + early_printk(const char *fmt, ...); 132 + 133 + static inline void console_silent(void) 134 + { 135 + console_loglevel = 0; 136 + } 137 + 138 + static inline void console_verbose(void) 139 + { 140 + if (console_loglevel) 141 + console_loglevel = 15; 142 + } 143 + 144 + extern void dump_stack(void) __cold; 145 + 146 + enum { 147 + DUMP_PREFIX_NONE, 148 + DUMP_PREFIX_ADDRESS, 149 + DUMP_PREFIX_OFFSET 150 + }; 151 + extern void hex_dump_to_buffer(const void *buf, size_t len, 152 + int rowsize, int groupsize, 153 + char *linebuf, size_t linebuflen, bool ascii); 154 + extern void print_hex_dump(const char *level, const char *prefix_str, 155 + int prefix_type, int rowsize, int groupsize, 156 + const void *buf, size_t len, bool ascii); 157 + extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, 158 + const void *buf, size_t len); 159 + 160 + #ifndef pr_fmt 161 + #define pr_fmt(fmt) fmt 162 + #endif 163 + 164 + #define pr_emerg(fmt, ...) \ 165 + printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 166 + #define pr_alert(fmt, ...) \ 167 + printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 168 + #define pr_crit(fmt, ...) \ 169 + printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 170 + #define pr_err(fmt, ...) \ 171 + printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 172 + #define pr_warning(fmt, ...) \ 173 + printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 174 + #define pr_warn pr_warning 175 + #define pr_notice(fmt, ...) \ 176 + printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 177 + #define pr_info(fmt, ...) \ 178 + printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 179 + #define pr_cont(fmt, ...) \ 180 + printk(KERN_CONT fmt, ##__VA_ARGS__) 181 + 182 + /* pr_devel() should produce zero code unless DEBUG is defined */ 183 + #ifdef DEBUG 184 + #define pr_devel(fmt, ...) \ 185 + printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 186 + #else 187 + #define pr_devel(fmt, ...) \ 188 + ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 189 + #endif 190 + 191 + /* If you are writing a driver, please use dev_dbg instead */ 192 + #if defined(DEBUG) 193 + #define pr_debug(fmt, ...) \ 194 + printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 195 + #elif defined(CONFIG_DYNAMIC_DEBUG) 196 + /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ 197 + #define pr_debug(fmt, ...) \ 198 + dynamic_pr_debug(fmt, ##__VA_ARGS__) 199 + #else 200 + #define pr_debug(fmt, ...) \ 201 + ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; }) 202 + #endif 203 + 204 + /* 205 + * ratelimited messages with local ratelimit_state, 206 + * no local ratelimit_state used in the !PRINTK case 207 + */ 208 + #ifdef CONFIG_PRINTK 209 + #define printk_ratelimited(fmt, ...) ({ \ 210 + static DEFINE_RATELIMIT_STATE(_rs, \ 211 + DEFAULT_RATELIMIT_INTERVAL, \ 212 + DEFAULT_RATELIMIT_BURST); \ 213 + \ 214 + if (__ratelimit(&_rs)) \ 215 + printk(fmt, ##__VA_ARGS__); \ 216 + }) 217 + #else 218 + /* No effect, but we still get type checking even in the !PRINTK case: */ 219 + #define printk_ratelimited printk 220 + #endif 221 + 222 + #define pr_emerg_ratelimited(fmt, ...) \ 223 + printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) 224 + #define pr_alert_ratelimited(fmt, ...) \ 225 + printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) 226 + #define pr_crit_ratelimited(fmt, ...) \ 227 + printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) 228 + #define pr_err_ratelimited(fmt, ...) \ 229 + printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) 230 + #define pr_warning_ratelimited(fmt, ...) \ 231 + printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) 232 + #define pr_warn_ratelimited pr_warning_ratelimited 233 + #define pr_notice_ratelimited(fmt, ...) \ 234 + printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) 235 + #define pr_info_ratelimited(fmt, ...) \ 236 + printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) 237 + /* no pr_cont_ratelimited, don't do that... */ 238 + /* If you are writing a driver, please use dev_dbg instead */ 239 + #if defined(DEBUG) 240 + #define pr_debug_ratelimited(fmt, ...) \ 241 + printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 242 + #else 243 + #define pr_debug_ratelimited(fmt, ...) \ 244 + ({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \ 245 + ##__VA_ARGS__); 0; }) 246 + #endif 247 + 248 + #endif