All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] printk: Refactor processing of line severity tokens
@ 2008-04-13 11:53 Nick Andrew
  2008-04-13 11:54 ` [PATCH 2/2] printk: Remember the message level for multi-line output Nick Andrew
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Nick Andrew @ 2008-04-13 11:53 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, Linus Torvalds
  Cc: linux-kernel, Andrew Morton, joe

printk: Refactor processing of line severity tokens

Restructure the logic of vprintk() so the processing of the leading
3 characters of each input line is in one place, regardless whether
printk_time is enabled. This makes the code smaller and easier to
understand.

Signed-off-by: Nick Andrew <nick@nick-andrew.net>
---

 kernel/printk.c |   63 +++++++++++++++++++++++++------------------------------
 1 files changed, 29 insertions(+), 34 deletions(-)


diff --git a/kernel/printk.c b/kernel/printk.c
index c46a20a..bca9359 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -656,11 +656,12 @@ static int printk_recursion_bug;
 
 asmlinkage int vprintk(const char *fmt, va_list args)
 {
-	static int log_level_unknown = 1;
+	static int new_text_line = 1;
 	static char printk_buf[1024];
 
-	unsigned long flags;
 	int printed_len = 0;
+	int current_log_level = default_message_loglevel;
+	unsigned long flags;
 	int this_cpu;
 	char *p;
 
@@ -702,61 +703,55 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 	printed_len += vscnprintf(printk_buf + printed_len,
 				  sizeof(printk_buf) - printed_len, fmt, args);
 
+
 	/*
 	 * Copy the output into log_buf.  If the caller didn't provide
 	 * appropriate log level tags, we insert them here
 	 */
 	for (p = printk_buf; *p; p++) {
-		if (log_level_unknown) {
-                        /* log_level_unknown signals the start of a new line */
+		if (new_text_line) {
+			/* If a token, set current_log_level and skip over */
+			if (p[0] == '<' && p[1] >= '0' && p[1] <= '7' &&
+			    p[2] == '>') {
+				current_log_level = p[1] - '0';
+				p += 3;
+				printed_len -= 3;
+			} else {
+				current_log_level = default_message_loglevel;
+			}
+
+			/* Always output the token */
+			emit_log_char('<');
+			emit_log_char(current_log_level + '0');
+			emit_log_char('>');
+			printed_len += 3;
+			new_text_line = 0;
+
 			if (printk_time) {
-				int loglev_char;
+				/* Follow the token with the time */
 				char tbuf[50], *tp;
 				unsigned tlen;
 				unsigned long long t;
 				unsigned long nanosec_rem;
 
-				/*
-				 * force the log level token to be
-				 * before the time output.
-				 */
-				if (p[0] == '<' && p[1] >='0' &&
-				   p[1] <= '7' && p[2] == '>') {
-					loglev_char = p[1];
-					p += 3;
-					printed_len -= 3;
-				} else {
-					loglev_char = default_message_loglevel
-						+ '0';
-				}
 				t = cpu_clock(printk_cpu);
 				nanosec_rem = do_div(t, 1000000000);
-				tlen = sprintf(tbuf,
-						"<%c>[%5lu.%06lu] ",
-						loglev_char,
-						(unsigned long)t,
-						nanosec_rem/1000);
+				tlen = sprintf(tbuf, "[%5lu.%06lu] ",
+						(unsigned long) t,
+						nanosec_rem / 1000);
 
 				for (tp = tbuf; tp < tbuf + tlen; tp++)
 					emit_log_char(*tp);
 				printed_len += tlen;
-			} else {
-				if (p[0] != '<' || p[1] < '0' ||
-				   p[1] > '7' || p[2] != '>') {
-					emit_log_char('<');
-					emit_log_char(default_message_loglevel
-						+ '0');
-					emit_log_char('>');
-					printed_len += 3;
-				}
 			}
-			log_level_unknown = 0;
+
 			if (!*p)
 				break;
 		}
+
 		emit_log_char(*p);
 		if (*p == '\n')
-			log_level_unknown = 1;
+			new_text_line = 1;
 	}
 
 	/*


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-04-14 12:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-13 11:53 [PATCH 1/2] printk: Refactor processing of line severity tokens Nick Andrew
2008-04-13 11:54 ` [PATCH 2/2] printk: Remember the message level for multi-line output Nick Andrew
2008-04-13 12:26 ` [PATCH 1/2] printk: Refactor processing of line severity tokens Nick Andrew
2008-04-14  7:58   ` Ingo Molnar
2008-04-13 12:27 ` [PATCH 2/2] printk: Remember the message level for multi-line output Nick Andrew
2008-04-14  8:03   ` Ingo Molnar
2008-04-14 10:12     ` Nick Andrew
2008-04-14 10:26       ` Ingo Molnar
2008-04-14 11:03         ` Nick Andrew
2008-04-14 11:43         ` Johannes Weiner
2008-04-14 12:21           ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.