The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	Fengguang Wu <fengguang.wu@intel.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"kay.sievers" <kay.sievers@vrfy.org>,
	"Paul E. McKenney" <paulmck@us.ibm.com>,
	Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [RFC PATCH] printk: Enable/disable buffering and add printk_flush()
Date: Thu, 21 Jun 2012 13:01:38 -0700	[thread overview]
Message-ID: <1340308898.22218.24.camel@joe2Laptop> (raw)
In-Reply-To: <1340307523.27036.207.camel@gandalf.stny.rr.com>

Add functions to enable/disable printk buffering.
Add a function to force any buffered output to be emitted.

printk_flush() also emits "printk_flush\n" at KERN_DEFAULT.

---

Perhaps something like this instead of just the one printk_flush()?
Doesn't require any additional KERN_LEVEL '<f>' addition.

Compiled but completely untested...

 include/linux/printk.h |   18 ++++++++++++++++++
 kernel/printk.c        |   36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 1bec2f7..165b6a2 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -111,6 +111,11 @@ asmlinkage int printk_emit(int facility, int level,
 asmlinkage __printf(1, 2) __cold
 int printk(const char *fmt, ...);
 
+bool printk_set_buffering(bool enable);
+bool printk_get_buffering(void);
+void printk_flush(void);	/* forcibly emit any internal buffers */
+
+
 /*
  * Special printk facility for scheduler use only, _DO_NOT_USE_ !
  */
@@ -143,6 +148,17 @@ int printk(const char *s, ...)
 {
 	return 0;
 }
+static bool printk_set_buffering(bool enable)
+{
+	return false;
+}
+bool printk_get_buffering(void)
+{
+	return false;
+}
+static inline void printk_flush(void)
+{
+}
 static inline __printf(1, 2) __cold
 int printk_sched(const char *s, ...)
 {
@@ -191,6 +207,8 @@ extern void dump_stack(void) __cold;
 #define pr_cont(fmt, ...) \
 	printk(KERN_CONT fmt, ##__VA_ARGS__)
 
+#define pr_flush printk_flush
+
 /* pr_devel() should produce zero code unless DEBUG is defined */
 #ifdef DEBUG
 #define pr_devel(fmt, ...) \
diff --git a/kernel/printk.c b/kernel/printk.c
index a2276b9..0e35931 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1144,6 +1144,23 @@ module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting, to"
 	"print all kernel messages to the console.");
 
+atomic_t printk_buffering = ATOMIC_INIT(1);
+
+bool printk_set_buffering(bool enable)
+{
+	if (enable)
+		return atomic_inc_and_test(&printk_buffering);
+
+	return atomic_dec_and_test(&printk_buffering);
+}
+EXPORT_SYMBOL(printk_set_buffering);
+
+bool printk_get_buffering(void)
+{
+        return atomic_read(&printk_buffering);
+}
+EXPORT_SYMBOL(printk_get_buffering);
+
 /*
  * Call the console drivers, asking them to write out
  * log_buf[start] to log_buf[end - 1].
@@ -1288,6 +1305,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 	int this_cpu;
 	bool newline = false;
 	bool prefix = false;
+	bool buffered = atomic_read(&printk_buffering);
 	int printed_len = 0;
 
 	boot_delay_msec();
@@ -1355,8 +1373,16 @@ asmlinkage int vprintk_emit(int facility, int level,
 		}
 	}
 
-	if (level == -1)
+	switch (level) {
+	case -1:
 		level = default_message_loglevel;
+		break;
+	case -2:
+		prefix = true;
+		level = default_message_loglevel;
+		buffered = false;
+		break;
+	}
 
 	if (dict) {
 		prefix = true;
@@ -1364,7 +1390,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 	}
 
 	if (!newline) {
-		if (cont_len && (prefix || cont_task != current)) {
+		if (cont_len && (prefix || cont_task != current || !buffered)) {
 			/*
 			 * Flush earlier buffer, which is either from a
 			 * different thread, or when we got a new prefix.
@@ -1454,6 +1480,12 @@ asmlinkage int printk_emit(int facility, int level,
 }
 EXPORT_SYMBOL(printk_emit);
 
+void printk_flush(void)
+{
+	printk_emit(0, -2, NULL, 0, "printk_flush\n");
+}
+EXPORT_SYMBOL(printk_flush);
+
 /**
  * printk - print a kernel message
  * @fmt: format string



  reply	other threads:[~2012-06-21 20:01 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-14  4:46 [PATCH] printk: Add printk_flush() to force buffered text to console Steven Rostedt
2012-06-14  4:59 ` Greg Kroah-Hartman
2012-06-14 11:01   ` Steven Rostedt
2012-06-14 15:41     ` Greg Kroah-Hartman
2012-06-14 17:07       ` Steven Rostedt
2012-06-15  4:22         ` Fengguang Wu
2012-06-15  4:30           ` Greg Kroah-Hartman
2012-06-15  4:37             ` Fengguang Wu
2012-06-15 12:04             ` Ingo Molnar
2012-06-15 23:13               ` Greg Kroah-Hartman
2012-06-15 23:53                 ` Steven Rostedt
2012-06-18 23:03                   ` Greg Kroah-Hartman
2012-06-19  1:28                     ` Steven Rostedt
2012-06-20 12:25                       ` Ingo Molnar
2012-06-21 17:13                         ` Greg Kroah-Hartman
2012-06-21 17:41                           ` Steven Rostedt
2012-06-21 18:17                             ` Joe Perches
2012-06-21 18:22                               ` Joe Perches
2012-06-21 18:29                               ` Steven Rostedt
2012-06-21 18:39                                 ` Joe Perches
2012-06-21 18:49                                   ` Steven Rostedt
2012-06-21 18:55                                     ` Joe Perches
2012-06-21 19:38                                       ` Steven Rostedt
2012-06-21 20:01                                         ` Joe Perches [this message]
2012-06-16  6:59                 ` Ingo Molnar
2012-06-16 12:51                   ` Joe Perches
2012-06-16 15:38                     ` Greg Kroah-Hartman
2012-06-16 15:40                   ` Greg Kroah-Hartman

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=1340308898.22218.24.camel@joe2Laptop \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@kernel.org \
    --cc=paulmck@us.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    /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