public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "he, bo" <bo.he@intel.com>
To: Ingo Molnar <mingo@kernel.org>,
	akpm@linux-foudation.org, mingo@elte.hu, rusty@rustcorp.com.au,
	a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org,
	william.douglas@intel.com
Cc: yanmin_zhang@linux.intel.com
Subject: [PATCH_V2 2/2] enable dumpstack() to printk log level
Date: Mon, 26 Mar 2012 09:36:30 +0800	[thread overview]
Message-ID: <1332725790.2359.28.camel@hebo> (raw)
In-Reply-To: <20120323122208.GB13920@gmail.com>

From: he bo <bo.he@intel.com>

Function dump_stack calls printk with default log level.
At some scenarios, we need dump the logs at special log level.
For example, Android aplog saves log at a low level to reduce
log storage. With __might_sleep checking, it just prints out
the warning source line with KERNE_ERR and Android saves it to aplog,
but later dump_stack log is not saved. We couldn’t see the
important information when developers check it.
the patch adds function dump_stack_log_lvl to support this capability.

Signed-off-by: he, bo <bo.he@intel.com>
Reviewed-by: zhang, yanmin <yanmin.zhang@intel.com>
---
 arch/x86/kernel/dumpstack.c |   19 ++++++++++++++-----
 include/linux/printk.h      |    1 +
 kernel/sched/core.c         |    2 +-
 lib/dump_stack.c            |    7 ++++++-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 4025fe4..2ffa890 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -177,20 +177,29 @@ void show_stack(struct task_struct *task, unsigned long *sp)
 }
 
 /*
- * The architecture-independent dump_stack generator
+ * The architecture-dependent dump_stack_log_lvl generator
  */
-void dump_stack(void)
+void dump_stack_log_lvl(char *log_lvl)
 {
 	unsigned long bp;
 	unsigned long stack;
 
 	bp = stack_frame(current, NULL);
-	printk("Pid: %d, comm: %.20s %s %s %.*s\n",
-		current->pid, current->comm, print_tainted(),
+	printk("%sPid: %d, comm: %.20s %s %s %.*s\n",
+		log_lvl, current->pid, current->comm, print_tainted(),
 		init_utsname()->release,
 		(int)strcspn(init_utsname()->version, " "),
 		init_utsname()->version);
-	show_trace(NULL, NULL, &stack, bp);
+	show_trace_log_lvl(NULL, NULL, &stack, bp, log_lvl);
+}
+EXPORT_SYMBOL_GPL(dump_stack_log_lvl);
+
+/*
+ * The architecture-dependent dump_stack generator
+ */
+void dump_stack(void)
+{
+	dump_stack_log_lvl("");
 }
 EXPORT_SYMBOL(dump_stack);
 
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 0525927..2a13dd8 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -157,6 +157,7 @@ static inline void setup_log_buf(int early)
 #endif
 
 extern void dump_stack(void) __cold;
+extern void dump_stack_log_lvl(char *log_lvl) __cold;
 
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 503d642..ab0dcdf 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7060,7 +7060,7 @@ void __might_sleep(const char *file, int line, int preempt_offset)
 	debug_show_held_locks(current);
 	if (irqs_disabled())
 		print_irqtrace_events(current);
-	dump_stack();
+	dump_stack_log_lvl(KERN_ERR);
 }
 EXPORT_SYMBOL(__might_sleep);
 #endif
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index 53bff4c..fd14940 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -11,5 +11,10 @@ void dump_stack(void)
 	printk(KERN_NOTICE
 		"This architecture does not implement dump_stack()\n");
 }
-
 EXPORT_SYMBOL(dump_stack);
+
+void dump_stack_log_lvl(char *log_lvl)
+{
+	dump_stack();
+}
+EXPORT_SYMBOL_GPL(dump_stack_log_lvl);
-- 
1.7.1




      parent reply	other threads:[~2012-03-26  1:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1332493027.2359.5.camel@hebo>
2012-03-23  9:01 ` [PATCH 2/2] enable dumpstack() to printk log level he, bo
2012-03-23 12:22   ` Ingo Molnar
2012-03-26  0:59     ` he, bo
2012-03-26  1:36     ` [PATCH_V2 1/2] fix the bug that printk can't support printk(KERN_LEVEL) he, bo
2012-03-28  3:28       ` Yanmin Zhang
2012-04-06  0:57       ` he, bo
2012-03-26  1:36     ` he, bo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332725790.2359.28.camel@hebo \
    --to=bo.he@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foudation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=william.douglas@intel.com \
    --cc=yanmin_zhang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox