Skip to contentSkip to conversation

printk: introduce pr_default() macro

PATCH In review Chen Yucong 3 participants 5 messages Feb 5, 2016 – Feb 9, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 printk: introduce pr_default() macro

Until now, we cover all log-levels by pr_<level> macros except KERN_DEFAULT one. Add it for convenience.

---
 include/linux/printk.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/linux/printk.h +6 -0
index 51dd6b8..9808130 100644
@@ -274,6 +274,8 @@ extern asmlinkage void dump_stack(void) __cold;
  */
 #define pr_cont(fmt, ...) \
 	printk(KERN_CONT fmt, ##__VA_ARGS__)
+#define pr_default(fmt, ...) \
+	printk(KERN_DEFAULT pr_fmt(fmt), ##__VA_ARGS__)
 
 /* pr_devel() should produce zero code unless DEBUG is defined */
 #ifdef DEBUG
@@ -345,6 +347,8 @@ extern asmlinkage void dump_stack(void) __cold;
 	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_cont_once(fmt, ...)					\
 	printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_default_once(fmt, ...)				\
+	printk_once(KERN_DEFAULT pr_fmt(fmt), ##__VA_ARGS__)
 
 #if defined(DEBUG)
 #define pr_devel_once(fmt, ...)					\
@@ -396,6 +400,8 @@ extern asmlinkage void dump_stack(void) __cold;
 	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_info_ratelimited(fmt, ...)					\
 	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_default_ratelimited(fmt, ...)				\
+	printk_ratelimited(KERN_DEFAULT pr_fmt(fmt), ##__VA_ARGS__)
 /* no pr_cont_ratelimited, don't do that... */
 
 #if defined(DEBUG)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 x86: use pr_default() macro

- convert printk(KERN_DEFAULT ...) to pr_default(...)

---
 arch/x86/kernel/dumpstack.c    |  3 +--
 arch/x86/kernel/dumpstack_64.c |  4 ++--
 arch/x86/kernel/process_32.c   | 29 ++++++++++++++---------------
 arch/x86/kernel/process_64.c   | 41 ++++++++++++++++++++---------------------
 arch/x86/mm/fault.c            |  2 +-
 5 files changed, 38 insertions(+), 41 deletions(-)
arch/x86/kernel/dumpstack.c +1 -2
index 993706a..1ae9a6d 100644
@@ -257,8 +257,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
 	unsigned short ss;
 	unsigned long sp;
 #endif
-	printk(KERN_DEFAULT
-	       "%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
+	pr_default("%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
 #ifdef CONFIG_PREEMPT
 	printk("PREEMPT ");
 #endif
arch/x86/kernel/dumpstack_64.c +2 -2
index 5f1c626..8e6c739 100644
@@ -316,11 +316,11 @@ void show_regs(struct pt_regs *regs)
 		unsigned char c;
 		u8 *ip;
 
-		printk(KERN_DEFAULT "Stack:\n");
+		pr_default("Stack:\n");
 		show_stack_log_lvl(NULL, regs, (unsigned long *)sp,
 				   0, KERN_DEFAULT);
 
-		printk(KERN_DEFAULT "Code: ");
+		pr_default("Code: ");
 
 		ip = (u8 *)regs->ip - code_prologue;
 		if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
arch/x86/kernel/process_32.c +14 -15
index 9f95091..4039da4 100644
@@ -83,17 +83,17 @@ void __show_regs(struct pt_regs *regs, int all)
 		savesegment(gs, gs);
 	}
 
-	printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
-			(u16)regs->cs, regs->ip, regs->flags,
-			smp_processor_id());
+	pr_default("EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
+		   (u16)regs->cs, regs->ip, regs->flags,
+		   smp_processor_id());
 	print_symbol("EIP is at %s\n", regs->ip);
 
-	printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
-		regs->ax, regs->bx, regs->cx, regs->dx);
-	printk(KERN_DEFAULT "ESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n",
-		regs->si, regs->di, regs->bp, sp);
-	printk(KERN_DEFAULT " DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x\n",
-	       (u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss);
+	pr_default("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
+		   regs->ax, regs->bx, regs->cx, regs->dx);
+	pr_default("ESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n",
+		   regs->si, regs->di, regs->bp, sp);
+	pr_default(" DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x\n",
+		   (u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss);
 
 	if (!all)
 		return;
@@ -102,8 +102,8 @@ void __show_regs(struct pt_regs *regs, int all)
 	cr2 = read_cr2();
 	cr3 = read_cr3();
 	cr4 = __read_cr4_safe();
-	printk(KERN_DEFAULT "CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n",
-			cr0, cr2, cr3, cr4);
+	pr_default("CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n",
+		   cr0, cr2, cr3, cr4);
 
 	get_debugreg(d0, 0);
 	get_debugreg(d1, 1);
@@ -117,10 +117,9 @@ void __show_regs(struct pt_regs *regs, int all)
 	    (d6 == DR6_RESERVED) && (d7 == 0x400))
 		return;
 
-	printk(KERN_DEFAULT "DR0: %08lx DR1: %08lx DR2: %08lx DR3: %08lx\n",
-			d0, d1, d2, d3);
-	printk(KERN_DEFAULT "DR6: %08lx DR7: %08lx\n",
-			d6, d7);
+	pr_default("DR0: %08lx DR1: %08lx DR2: %08lx DR3: %08lx\n",
+		   d0, d1, d2, d3);
+	pr_default("DR6: %08lx DR7: %08lx\n", d6, d7);
 }
 
 void release_thread(struct task_struct *dead_task)
arch/x86/kernel/process_64.c +20 -21

60 lines not on this page · raw message

arch/x86/mm/fault.c +1 -1
index eef44d9..531fe75 100644
@@ -723,7 +723,7 @@ no_context(struct pt_regs *regs, unsigned long error_code,
 		sig = 0;
 
 	/* Executive summary in case the body of the oops scrolled away */
-	printk(KERN_DEFAULT "CR2: %016lx\n", address);
+	pr_default("CR2: %016lx\n", address);
 
 	oops_end(flags, regs, sig);
 }
Signature · 1 line
1.8.3.1
#2 lore raw
In reply to Chen Yucong
Quoted 43 lines · Chen Yucong

Until now, we cover all log-levels by pr_<level>  macros except KERN_DEFAULT one. Add it for convenience.

---
 include/linux/printk.h | 6 ++++++

 1 file changed, 6 insertions(+)
include/linux/printk.h +2 -0
index 51dd6b8..9808130 100644
@@ -274,6 +274,8 @@ extern asmlinkage void dump_stack(void) __cold;
   */
  #define pr_cont(fmt, ...) \
  	printk(KERN_CONT fmt, ##__VA_ARGS__)
+#define pr_default(fmt, ...) \
+	printk(KERN_DEFAULT pr_fmt(fmt), ##__VA_ARGS__)


 /* pr_devel() should produce zero code unless DEBUG is defined */ #ifdef DEBUG

include/linux/printk.h +2 -0
@@ -345,6 +347,8 @@ extern asmlinkage void dump_stack(void) __cold;
  	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
  #define pr_cont_once(fmt, ...)					
 \
  	printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_default_once(fmt, ...)				\
+	printk_once(KERN_DEFAULT pr_fmt(fmt), ##__VA_ARGS__)


 #if defined(DEBUG)
 #define pr_devel_once(fmt, ...)
\

include/linux/printk.h +2 -0
@@ -396,6 +400,8 @@ extern asmlinkage void dump_stack(void) __cold;
  	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
  #define pr_info_ratelimited(fmt, ...)				
 	\
  	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_default_ratelimited(fmt, ...)				
 \
+	printk_ratelimited(KERN_DEFAULT pr_fmt(fmt), ##__VA_ARGS__)
  /* no pr_cont_ratelimited, don't do that... */


 #if defined(DEBUG)

#3 lore raw
In reply to Chen Yucong
Quoted 2 lines · Chen Yucong

Until now, we cover all log-levels by pr_  macros except KERN_DEFAULT one. Add it for convenience.

I'd rather it be removed altogether.

#4 lore raw
Quoted 5 lines · Joe Perches
Quoted 2 lines · Chen Yucong

Until now, we cover all log-levels by pr_  macros except KERN_DEFAULT one. Add it for convenience.

I'd rather it be removed altogether.

Yes, they should be converted to KERN_WARNING (which is the default loglevel), and another patch should remove KERN_DEFAULT altogether.

Thanks,

Ingo