diff options
author | Nick Andrew <nick@nick-andrew.net> | 2008-05-12 15:21:04 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2008-05-24 17:15:12 -0400 |
commit | ac60ad7413ca8208094609a3b88ed9b1ed012fbc (patch) | |
tree | addd789d3839619b97bb36886ef7f597d1a49ea2 /kernel | |
parent | cd3a1b8562d28490b334a61d5eb05df3d722d91e (diff) |
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.
size reduction in kernel/printk.o:
text data bss dec hex filename
6157 397 1049804 1056358 101e66 printk.o.before
6117 397 1049804 1056318 101e3e printk.o.after
and some style uncleanlinesses removed as well as a side-effect:
Before:
total: 19 errors, 22 warnings, 1340 lines checked
After:
total: 17 errors, 22 warnings, 1333 lines checked
Signed-off-by: Nick Andrew <nick@nick-andrew.net>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/printk.c | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/kernel/printk.c b/kernel/printk.c index 7d5556152234..98ca1b76277f 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -655,13 +655,13 @@ static int acquire_console_semaphore_for_printk(unsigned int cpu) | |||
655 | static const char recursion_bug_msg [] = | 655 | static const char recursion_bug_msg [] = |
656 | KERN_CRIT "BUG: recent printk recursion!\n"; | 656 | KERN_CRIT "BUG: recent printk recursion!\n"; |
657 | static int recursion_bug; | 657 | static int recursion_bug; |
658 | static int log_level_unknown = 1; | 658 | static int new_text_line = 1; |
659 | static char printk_buf[1024]; | 659 | static char printk_buf[1024]; |
660 | 660 | ||
661 | asmlinkage int vprintk(const char *fmt, va_list args) | 661 | asmlinkage int vprintk(const char *fmt, va_list args) |
662 | { | 662 | { |
663 | unsigned long flags; | ||
664 | int printed_len = 0; | 663 | int printed_len = 0; |
664 | unsigned long flags; | ||
665 | int this_cpu; | 665 | int this_cpu; |
666 | char *p; | 666 | char *p; |
667 | 667 | ||
@@ -703,61 +703,54 @@ asmlinkage int vprintk(const char *fmt, va_list args) | |||
703 | printed_len += vscnprintf(printk_buf + printed_len, | 703 | printed_len += vscnprintf(printk_buf + printed_len, |
704 | sizeof(printk_buf) - printed_len, fmt, args); | 704 | sizeof(printk_buf) - printed_len, fmt, args); |
705 | 705 | ||
706 | |||
706 | /* | 707 | /* |
707 | * Copy the output into log_buf. If the caller didn't provide | 708 | * Copy the output into log_buf. If the caller didn't provide |
708 | * appropriate log level tags, we insert them here | 709 | * appropriate log level tags, we insert them here |
709 | */ | 710 | */ |
710 | for (p = printk_buf; *p; p++) { | 711 | for (p = printk_buf; *p; p++) { |
711 | if (log_level_unknown) { | 712 | if (new_text_line) { |
712 | /* log_level_unknown signals the start of a new line */ | 713 | int current_log_level = default_message_loglevel; |
714 | /* If a token, set current_log_level and skip over */ | ||
715 | if (p[0] == '<' && p[1] >= '0' && p[1] <= '7' && | ||
716 | p[2] == '>') { | ||
717 | current_log_level = p[1] - '0'; | ||
718 | p += 3; | ||
719 | printed_len -= 3; | ||
720 | } | ||
721 | |||
722 | /* Always output the token */ | ||
723 | emit_log_char('<'); | ||
724 | emit_log_char(current_log_level + '0'); | ||
725 | emit_log_char('>'); | ||
726 | printed_len += 3; | ||
727 | new_text_line = 0; | ||
728 | |||
713 | if (printk_time) { | 729 | if (printk_time) { |
714 | int loglev_char; | 730 | /* Follow the token with the time */ |
715 | char tbuf[50], *tp; | 731 | char tbuf[50], *tp; |
716 | unsigned tlen; | 732 | unsigned tlen; |
717 | unsigned long long t; | 733 | unsigned long long t; |
718 | unsigned long nanosec_rem; | 734 | unsigned long nanosec_rem; |
719 | 735 | ||
720 | /* | ||
721 | * force the log level token to be | ||
722 | * before the time output. | ||
723 | */ | ||
724 | if (p[0] == '<' && p[1] >='0' && | ||
725 | p[1] <= '7' && p[2] == '>') { | ||
726 | loglev_char = p[1]; | ||
727 | p += 3; | ||
728 | printed_len -= 3; | ||
729 | } else { | ||
730 | loglev_char = default_message_loglevel | ||
731 | + '0'; | ||
732 | } | ||
733 | t = cpu_clock(printk_cpu); | 736 | t = cpu_clock(printk_cpu); |
734 | nanosec_rem = do_div(t, 1000000000); | 737 | nanosec_rem = do_div(t, 1000000000); |
735 | tlen = sprintf(tbuf, | 738 | tlen = sprintf(tbuf, "[%5lu.%06lu] ", |
736 | "<%c>[%5lu.%06lu] ", | 739 | (unsigned long) t, |
737 | loglev_char, | 740 | nanosec_rem / 1000); |
738 | (unsigned long)t, | ||
739 | nanosec_rem/1000); | ||
740 | 741 | ||
741 | for (tp = tbuf; tp < tbuf + tlen; tp++) | 742 | for (tp = tbuf; tp < tbuf + tlen; tp++) |
742 | emit_log_char(*tp); | 743 | emit_log_char(*tp); |
743 | printed_len += tlen; | 744 | printed_len += tlen; |
744 | } else { | ||
745 | if (p[0] != '<' || p[1] < '0' || | ||
746 | p[1] > '7' || p[2] != '>') { | ||
747 | emit_log_char('<'); | ||
748 | emit_log_char(default_message_loglevel | ||
749 | + '0'); | ||
750 | emit_log_char('>'); | ||
751 | printed_len += 3; | ||
752 | } | ||
753 | } | 745 | } |
754 | log_level_unknown = 0; | 746 | |
755 | if (!*p) | 747 | if (!*p) |
756 | break; | 748 | break; |
757 | } | 749 | } |
750 | |||
758 | emit_log_char(*p); | 751 | emit_log_char(*p); |
759 | if (*p == '\n') | 752 | if (*p == '\n') |
760 | log_level_unknown = 1; | 753 | new_text_line = 1; |
761 | } | 754 | } |
762 | 755 | ||
763 | /* | 756 | /* |