Skip to contentSkip to conversation

ttyprintk: make the printk log level configurable

PATCH Superseded Peter Korsgaard 2 participants 4 messages Aug 21, 2018 – Sep 7, 2018 Char and misc drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ttyprintk: make the printk log level configurable

For some use cases it is handy to use a different printk log level than the default (info) for the messages written to ttyprintk, so add a Kconfig option similar to what we have for default console loglevel.

---
 drivers/char/Kconfig     | 8 ++++++++
 drivers/char/ttyprintk.c | 4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/char/Kconfig +8 -0
index ce277ee0a28a..14a7f023f20b 100644
@@ -66,6 +66,14 @@ config TTY_PRINTK
 
 	  If unsure, say N.
 
+config TTY_PRINTK_LEVEL
+	depends on TTY_PRINTK
+	int "ttyprintk log level (1-7)"
+	range 1 7
+	default "6"
+	help
+	  Printk log level to use for ttyprintk messages.
+
 config PRINTER
 	tristate "Parallel printer support"
 	depends on PARPORT
drivers/char/ttyprintk.c +3 -1
index 67549ce88cc9..22fbd483b5dc 100644
@@ -37,6 +37,8 @@ static struct ttyprintk_port tpk_port;
  */
 #define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
 #define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
+#define TPK_PREFIX KERN_SOH __stringify(CONFIG_TTY_PRINTK_LEVEL) " [U]"
+
 static int tpk_curr;
 
 static char tpk_buffer[TPK_STR_SIZE + 4];
@@ -45,7 +47,7 @@ static void tpk_flush(void)
 {
 	if (tpk_curr > 0) {
 		tpk_buffer[tpk_curr] = '\0';
-		pr_info("[U] %s\n", tpk_buffer);
+		printk(TPK_PREFIX " %s\n", tpk_buffer);
 		tpk_curr = 0;
 	}
 }
Signature · 1 line
2.11.0
#1 lore raw
Quoted 4 lines · Peter Korsgaard

For some use cases it is handy to use a different printk log level than the default (info) for the messages written to ttyprintk, so add a Kconfig option similar to what we have for default console loglevel.

Ping? Feedback, comments?

Quoted 44 lines
drivers/char/Kconfig +8 -0
index ce277ee0a28a..14a7f023f20b 100644
@@ -66,6 +66,14 @@ config TTY_PRINTK
 
          If unsure, say N.
 
+config TTY_PRINTK_LEVEL
+       depends on TTY_PRINTK
+       int "ttyprintk log level (1-7)"
+       range 1 7
+       default "6"
+       help
+         Printk log level to use for ttyprintk messages.
+
 config PRINTER
        tristate "Parallel printer support"
        depends on PARPORT
drivers/char/ttyprintk.c +3 -2
index 67549ce88cc9..22fbd483b5dc 100644
@@ -37,6 +37,8 @@ static struct ttyprintk_port tpk_port;
  */
 #define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
 #define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
+#define TPK_PREFIX KERN_SOH __stringify(CONFIG_TTY_PRINTK_LEVEL) " [U]"
+
 static int tpk_curr;
 
 static char tpk_buffer[TPK_STR_SIZE + 4];
@@ -45,7 +47,7 @@ static void tpk_flush(void)
 {
        if (tpk_curr > 0) {
                tpk_buffer[tpk_curr] = '\0';
-               pr_info("[U] %s\n", tpk_buffer);
+               printk(TPK_PREFIX " %s\n", tpk_buffer);
                tpk_curr = 0;
        }
 }
--

2.11.0

Signature · 1 line
Bye, Peter Korsgaard
#2 lore raw
Quoted 7 lines · Peter Korsgaard
Quoted 4 lines · Peter Korsgaard

For some use cases it is handy to use a different printk log level than the default (info) for the messages written to ttyprintk, so add a Kconfig option similar to what we have for default console loglevel.

Ping? Feedback, comments?

I think it is moving "[U]" into TPK_LEVEL is an
unnecessary and a tad obfuscating change.

This also adds a leading space for unknown reasons after the KERN_SOH <level>.

Quoted 20 lines
Quoted 20 lines
drivers/char/Kconfig +8 -0
index ce277ee0a28a..14a7f023f20b 100644
@@ -66,6 +66,14 @@ config TTY_PRINTK
 
          If unsure, say N.
 
+config TTY_PRINTK_LEVEL
+       depends on TTY_PRINTK
+       int "ttyprintk log level (1-7)"
+       range 1 7
+       default "6"
+       help
+         Printk log level to use for ttyprintk messages.
+
 config PRINTER
        tristate "Parallel printer support"
        depends on PARPORT
drivers/char/ttyprintk.c +0 -0
Quoted 8 lines

drivers/char/ttyprintk.c static struct ttyprintk_port tpk_port; · line 40

Quoted 8 lines

index 67549ce88cc9..22fbd483b5dc 100644

drivers/char/ttyprintk.c +1 -0
@@ -37,6 +37,8 @@ static struct ttyprintk_port tpk_port;
  */
 #define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
 #define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
+#define TPK_PREFIX KERN_SOH __stringify(CONFIG_TTY_PRINTK_LEVEL) " [U]"

I think this should be

#define TPK_PREFIX KERN_SOH __stringify(CONFIG_TTY_PRINTK_LEVEL)

Quoted 10 lines

drivers/char/ttyprintk.c static void tpk_flush(void) · line 50

Quoted 10 lines
drivers/char/ttyprintk.c +2 -1
+
 static int tpk_curr;
 
 static char tpk_buffer[TPK_STR_SIZE + 4];
@@ -45,7 +47,7 @@ static void tpk_flush(void)
 {
        if (tpk_curr > 0) {
                tpk_buffer[tpk_curr] = '\0';
-               pr_info("[U] %s\n", tpk_buffer);
+               printk(TPK_PREFIX " %s\n", tpk_buffer);

and this

		printk(TPK_PREFIX "[U] %s\n", tpk_buffer);
Quoted 8 lines
Quoted 6 lines
drivers/char/ttyprintk.c +0 -1
                tpk_curr = 0;
        }
 }
--

2.11.0

#3 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Joe" == Joe Perches <[email protected]> writes:

Quoted 2 lines · Peter Korsgaard
Quoted 1 line · Peter Korsgaard
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

For some use cases it is handy to use a different printk log level than the default (info) for the messages written to ttyprintk, so add a Kconfig option similar to what we have for default console loglevel.

Ping? Feedback, comments?

I think it is moving "[U]" into TPK_LEVEL is an
unnecessary and a tad obfuscating change.

It is arguably part of the prefix, but OK - I have no problem leaving it in the printk line.

Quoted 2 lines

This also adds a leading space for unknown reasons after the KERN_SOH <level>.

True. I'll fix that and send a v2 - Thanks.

Quoted 56 lines
Quoted 20 lines
Quoted 20 lines
drivers/char/Kconfig +8 -0
index ce277ee0a28a..14a7f023f20b 100644
@@ -66,6 +66,14 @@ config TTY_PRINTK
 
          If unsure, say N.
 
+config TTY_PRINTK_LEVEL
+       depends on TTY_PRINTK
+       int "ttyprintk log level (1-7)"
+       range 1 7
+       default "6"
+       help
+         Printk log level to use for ttyprintk messages.
+
 config PRINTER
        tristate "Parallel printer support"
        depends on PARPORT
drivers/char/ttyprintk.c +0 -0
Quoted 8 lines

drivers/char/ttyprintk.c static struct ttyprintk_port tpk_port; · line 40

Quoted 8 lines

index 67549ce88cc9..22fbd483b5dc 100644

drivers/char/ttyprintk.c +1 -0
@@ -37,6 +37,8 @@ static struct ttyprintk_port tpk_port;
  */
 #define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
 #define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
+#define TPK_PREFIX KERN_SOH __stringify(CONFIG_TTY_PRINTK_LEVEL) " [U]"

I think this should be

#define TPK_PREFIX KERN_SOH __stringify(CONFIG_TTY_PRINTK_LEVEL)

Quoted 10 lines

drivers/char/ttyprintk.c static void tpk_flush(void) · line 50

Quoted 10 lines
drivers/char/ttyprintk.c +2 -1
+
 static int tpk_curr;
 
 static char tpk_buffer[TPK_STR_SIZE + 4];
@@ -45,7 +47,7 @@ static void tpk_flush(void)
 {
        if (tpk_curr > 0) {
                tpk_buffer[tpk_curr] = '\0';
-               pr_info("[U] %s\n", tpk_buffer);
+               printk(TPK_PREFIX " %s\n", tpk_buffer);

and this

		printk(TPK_PREFIX "[U] %s\n", tpk_buffer);
Quoted 8 lines
Quoted 6 lines
drivers/char/ttyprintk.c +0 -1
                tpk_curr = 0;
        }
 }
--

2.11.0

Signature · 1 line
Bye, Peter Korsgaard