Skip to content

Commit 70309dc

Browse files
Vasily GorbikAlexander Gordeev
authored andcommitted
s390/boot: Add timestamps to early boot messages
When CONFIG_PRINTK_TIME is enabled, add timestamps to boot messages in the same format as regular printk. Timestamps appear only with earlyprintk and are stored in the boot messages ring buffer, but are not propagated to main kernel messages (if earlyprintk is not enabled). This prevents double timestamps in the output. Signed-off-by: Vasily Gorbik <[email protected]> Acked-by: Heiko Carstens <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent b2a992a commit 70309dc

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

arch/s390/boot/printk.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,29 @@ static void boot_console_earlyprintk(const char *buf)
190190
return;
191191
buf = printk_skip_level(buf);
192192
/* print debug messages only when bootdebug is enabled */
193-
if (level == LOGLEVEL_DEBUG && (!bootdebug || !bootdebug_filter_match(buf)))
193+
if (level == LOGLEVEL_DEBUG && (!bootdebug || !bootdebug_filter_match(skip_timestamp(buf))))
194194
return;
195195
if (boot_ignore_loglevel || level < boot_console_loglevel)
196196
sclp_early_printk(buf);
197197
}
198198

199+
static char *add_timestamp(char *buf)
200+
{
201+
#ifdef CONFIG_PRINTK_TIME
202+
union tod_clock *boot_clock = (union tod_clock *)&get_lowcore()->boot_clock;
203+
unsigned long ns = tod_to_ns(get_tod_clock() - boot_clock->tod);
204+
char ts[MAX_NUMLEN];
205+
206+
*buf++ = '[';
207+
buf += strpad(buf, MAX_NUMLEN, as_dec(ts, ns / NSEC_PER_SEC, 0), 5, 0, 0);
208+
*buf++ = '.';
209+
buf += strpad(buf, MAX_NUMLEN, as_dec(ts, (ns % NSEC_PER_SEC) / NSEC_PER_USEC, 0), 6, 1, 0);
210+
*buf++ = ']';
211+
*buf++ = ' ';
212+
#endif
213+
return buf;
214+
}
215+
199216
#define va_arg_len_type(args, lenmod, typemod) \
200217
((lenmod == 'l') ? va_arg(args, typemod long) : \
201218
(lenmod == 'h') ? (typemod short)va_arg(args, typemod int) : \
@@ -215,10 +232,10 @@ int boot_printk(const char *fmt, ...)
215232
ssize_t len;
216233
int pad;
217234

218-
if (!printk_get_level(fmt)) {
219-
*p++ = KERN_SOH_ASCII;
220-
*p++ = '0' + MESSAGE_LOGLEVEL_DEFAULT;
221-
}
235+
*p++ = KERN_SOH_ASCII;
236+
*p++ = printk_get_level(fmt) ?: '0' + MESSAGE_LOGLEVEL_DEFAULT;
237+
p = add_timestamp(p);
238+
fmt = printk_skip_level(fmt);
222239

223240
va_start(args, fmt);
224241
for (; p < end && *fmt; fmt++) {

arch/s390/include/asm/boot_data.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ static inline bool bootdebug_filter_match(const char *buf)
5555
return false;
5656
}
5757

58+
static inline const char *skip_timestamp(const char *buf)
59+
{
60+
#ifdef CONFIG_PRINTK_TIME
61+
const char *p = memchr(buf, ']', strlen(buf));
62+
63+
if (p && p[1] == ' ')
64+
return p + 2;
65+
#endif
66+
return buf;
67+
}
68+
5869
#endif /* _ASM_S390_BOOT_DATA_H */

arch/s390/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ static void __init print_rb_entry(const char *buf)
892892
char fmt[] = KERN_SOH "0boot: %s";
893893
int level = printk_get_level(buf);
894894

895-
buf = printk_skip_level(buf);
895+
buf = skip_timestamp(printk_skip_level(buf));
896896
if (level == KERN_DEBUG[1] && (!bootdebug || !bootdebug_filter_match(buf)))
897897
return;
898898

0 commit comments

Comments
 (0)