Skip to content

Commit 04d2c8c

Browse files
JoePerchestorvalds
authored andcommitted
printk: convert the format for KERN_<LEVEL> to a 2 byte pattern
Instead of "<.>", use an ASCII SOH for the KERN_<LEVEL> prefix initiator. This saves 1 byte per printk, thousands of bytes in a normal kernel. No output changes are produced as vprintk_emit converts these uses to "<.>". Signed-off-by: Joe Perches <[email protected]> Cc: Kay Sievers <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b778b3f commit 04d2c8c

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

include/linux/kern_levels.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#ifndef __KERN_LEVELS_H__
22
#define __KERN_LEVELS_H__
33

4-
#define KERN_EMERG "<0>" /* system is unusable */
5-
#define KERN_ALERT "<1>" /* action must be taken immediately */
6-
#define KERN_CRIT "<2>" /* critical conditions */
7-
#define KERN_ERR "<3>" /* error conditions */
8-
#define KERN_WARNING "<4>" /* warning conditions */
9-
#define KERN_NOTICE "<5>" /* normal but significant condition */
10-
#define KERN_INFO "<6>" /* informational */
11-
#define KERN_DEBUG "<7>" /* debug-level messages */
4+
#define KERN_SOH "\001" /* ASCII Start Of Header */
5+
#define KERN_SOH_ASCII '\001'
6+
7+
#define KERN_EMERG KERN_SOH "0" /* system is unusable */
8+
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
9+
#define KERN_CRIT KERN_SOH "2" /* critical conditions */
10+
#define KERN_ERR KERN_SOH "3" /* error conditions */
11+
#define KERN_WARNING KERN_SOH "4" /* warning conditions */
12+
#define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
13+
#define KERN_INFO KERN_SOH "6" /* informational */
14+
#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
15+
16+
#define KERN_DEFAULT KERN_SOH "d" /* the default kernel loglevel */
1217

13-
/* Use the default kernel loglevel */
14-
#define KERN_DEFAULT "<d>"
1518
/*
1619
* Annotation for a "continued" line of log printout (only done after a
1720
* line that had no enclosing \n). Only to be used by core/arch code
1821
* during early bootup (a continued line is not SMP-safe otherwise).
1922
*/
20-
#define KERN_CONT "<c>"
23+
#define KERN_CONT KERN_SOH "c"
2124

2225
#endif

include/linux/printk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern const char linux_proc_banner[];
99

1010
static inline int printk_get_level(const char *buffer)
1111
{
12-
if (buffer[0] == '<' && buffer[1] && buffer[2] == '>') {
12+
if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
1313
switch (buffer[1]) {
1414
case '0' ... '7':
1515
case 'd': /* KERN_DEFAULT */
@@ -27,7 +27,7 @@ static inline const char *printk_skip_level(const char *buffer)
2727
case '0' ... '7':
2828
case 'd': /* KERN_DEFAULT */
2929
case 'c': /* KERN_CONT */
30-
return buffer + 3;
30+
return buffer + 2;
3131
}
3232
}
3333
return buffer;

0 commit comments

Comments
 (0)