From 0eae8cc98b9d9bba593f565ed3a2d214a3c39962 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 7 Jan 2019 13:09:47 +0000 Subject: [PATCH] Introduce new helper printf functions that get passed output flags. Add a new kprintf flag to avoid adding time stamps when outputing to the console. Mostly from Christos, any bugs added by me. Use above to print the "twiddle" (when using boot -z) without timestamps. --- sys/kern/subr_prf.c | 55 ++++++++++++++++++++++----------------------- sys/sys/kprintf.h | 3 ++- sys/sys/systm.h | 6 ++++- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index b2b797af54f4..5ea3d8b5e508 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_prf.c,v 1.174 2018/07/15 07:24:11 martin Exp $ */ +/* $NetBSD: subr_prf.c,v 1.175 2019/01/07 13:09:48 martin Exp $ */ /*- * Copyright (c) 1986, 1988, 1991, 1993 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.174 2018/07/15 07:24:11 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.175 2019/01/07 13:09:48 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -232,8 +232,8 @@ twiddle(void) kprintf_lock(); - putchar(twiddle_chars[pos++ & 3], TOCONS, NULL); - putchar('\b', TOCONS, NULL); + putchar(twiddle_chars[pos++ & 3], TOCONS|NOTSTAMP, NULL); + putchar('\b', TOCONS|NOTSTAMP, NULL); kprintf_unlock(); } @@ -526,7 +526,7 @@ putchar(int c, int flags, struct tty *tp) } #ifndef KLOG_NOTIMESTAMP - if (c != '\0' && c != '\n' && needtstamp) { + if (c != '\0' && c != '\n' && needtstamp && (flags & NOTSTAMP) == 0) { addtstamp(flags, tp); needtstamp = 0; } @@ -1051,18 +1051,32 @@ aprint_debug_ifnet(struct ifnet *ifp, const char *fmt, ...) va_end(ap); } +void +vprintf_flags(int flags, const char *fmt, va_list ap) +{ + kprintf_lock(); + kprintf(fmt, flags, NULL, NULL, ap); + kprintf_unlock(); +} + +void +printf_flags(int flags, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintf_flags(flags, fmt, ap); + va_end(ap); +} + void printf_tolog(const char *fmt, ...) { va_list ap; - kprintf_lock(); - va_start(ap, fmt); - kprintf(fmt, TOLOG, NULL, NULL, ap); + vprintf_flags(TOLOG, fmt, ap); va_end(ap); - - kprintf_unlock(); } /* @@ -1074,13 +1088,9 @@ printf_nolog(const char *fmt, ...) { va_list ap; - kprintf_lock(); - va_start(ap, fmt); - kprintf(fmt, TOCONS, NULL, NULL, ap); + vprintf_flags(TOCONS, fmt, ap); va_end(ap); - - kprintf_unlock(); } /* @@ -1095,16 +1105,9 @@ printf(const char *fmt, ...) { va_list ap; - kprintf_lock(); - va_start(ap, fmt); - kprintf(fmt, TOCONS | TOLOG, NULL, NULL, ap); + vprintf_flags(TOCONS | TOLOG, fmt, ap); va_end(ap); - - kprintf_unlock(); - - if (!panicstr) - logwakeup(); } /* @@ -1115,11 +1118,7 @@ printf(const char *fmt, ...) void vprintf(const char *fmt, va_list ap) { - kprintf_lock(); - - kprintf(fmt, TOCONS | TOLOG, NULL, NULL, ap); - - kprintf_unlock(); + vprintf_flags(TOCONS | TOLOG, fmt, ap); if (!panicstr) logwakeup(); diff --git a/sys/sys/kprintf.h b/sys/sys/kprintf.h index bd84ceec193d..f2d634edcfae 100644 --- a/sys/sys/kprintf.h +++ b/sys/sys/kprintf.h @@ -1,4 +1,4 @@ -/* $NetBSD: kprintf.h,v 1.12 2014/08/10 16:44:36 tls Exp $ */ +/* $NetBSD: kprintf.h,v 1.13 2019/01/07 13:09:47 martin Exp $ */ /*- * Copyright (c) 1986, 1988, 1991, 1993 @@ -55,6 +55,7 @@ #define TOBUFONLY 0x0008 /* to the buffer (only) [for snprintf] */ #define TODDB 0x0010 /* to ddb console */ #define NOLOCK 0x1000 /* don't acquire a tty lock */ +#define NOTSTAMP 0x2000 /* no time stamp on console */ void kprintf_init(void); void kprintf_init_callout(void); diff --git a/sys/sys/systm.h b/sys/sys/systm.h index d7a32cddfee1..5abaf1256b51 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $NetBSD: systm.h,v 1.280 2018/12/02 21:00:13 maxv Exp $ */ +/* $NetBSD: systm.h,v 1.281 2019/01/07 13:09:47 martin Exp $ */ /*- * Copyright (c) 1982, 1988, 1991, 1993 @@ -240,6 +240,10 @@ void vprintf(const char *, va_list) __printflike(1, 0); int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0); +void vprintf_flags(int, const char *, va_list) __printflike(2, 0); + +void printf_flags(int, const char *, ...) __printflike(2, 3); + int humanize_number(char *, size_t, uint64_t, const char *, int); void twiddle(void);