From c8dfd00d5e628272a037a1dc7a9e12f0afcb3130 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 30 Jul 2007 21:40:31 +0000 Subject: [PATCH] Introduce krateprintf(), a rate-controlled kprintf(), and the related struct krate structure. This takes all the effort out of outputting rate-limited warnings to the console. --- sys/kern/subr_prf.c | 24 +++++++++++++++++++++++- sys/sys/systm.h | 4 +++- sys/sys/time.h | 15 ++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 80304407dc..38994fd758 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -37,7 +37,7 @@ * * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/subr_prf.c,v 1.61.2.5 2002/08/31 18:22:08 dwmalone Exp $ - * $DragonFly: src/sys/kern/subr_prf.c,v 1.17 2006/12/26 11:01:07 swildner Exp $ + * $DragonFly: src/sys/kern/subr_prf.c,v 1.18 2007/07/30 21:40:30 dillon Exp $ */ #include "opt_ddb.h" @@ -331,6 +331,28 @@ kvprintf(const char *fmt, __va_list ap) return (retval); } +/* + * Limited rate kprintf. The passed rate structure must be initialized + * with the desired reporting frequency. A frequency of 0 will result in + * no output. + */ +void +krateprintf(struct krate *rate, const char *fmt, ...) +{ + __va_list ap; + + if (rate->ticks != ticks) { + rate->ticks = ticks; + rate->count = 0; + } + if (rate->count < rate->freq) { + ++rate->count; + __va_start(ap, fmt); + kvprintf(fmt, ap); + __va_end(ap); + } +} + /* * Print a character on console or users terminal. If destination is * the console then the last bunch of characters are saved in msgbuf for diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 688cc111ff..f9f3ebae5e 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -37,7 +37,7 @@ * * @(#)systm.h 8.7 (Berkeley) 3/29/95 * $FreeBSD: src/sys/sys/systm.h,v 1.111.2.18 2002/12/17 18:04:02 sam Exp $ - * $DragonFly: src/sys/sys/systm.h,v 1.73 2007/07/02 16:52:01 dillon Exp $ + * $DragonFly: src/sys/sys/systm.h,v 1.74 2007/07/30 21:40:31 dillon Exp $ */ #ifndef _SYS_SYSTM_H_ @@ -132,6 +132,7 @@ struct trapframe; struct user; struct vmspace; struct savetls; +struct krate; void Debugger (const char *msg); void backtrace(void); @@ -172,6 +173,7 @@ int log (int, const char *, ...) __printflike(2, 3); void logwakeup (void); void log_console (struct uio *); int kprintf (const char *, ...) __printflike(1, 2); +void krateprintf (struct krate *, const char *, ...) __printflike(2, 3); int ksnprintf (char *, size_t, const char *, ...) __printflike(3, 4); int ksprintf (char *buf, const char *, ...) __printflike(2, 3); int uprintf (const char *, ...) __printflike(1, 2); diff --git a/sys/sys/time.h b/sys/sys/time.h index 330412e68b..4f75c22ad9 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -32,7 +32,7 @@ * * @(#)time.h 8.5 (Berkeley) 5/4/95 * $FreeBSD: src/sys/sys/time.h,v 1.42 1999/12/29 04:24:48 peter Exp $ - * $DragonFly: src/sys/sys/time.h,v 1.16 2007/01/07 00:42:55 dillon Exp $ + * $DragonFly: src/sys/sys/time.h,v 1.17 2007/07/30 21:40:31 dillon Exp $ */ #ifndef _SYS_TIME_H_ @@ -191,6 +191,19 @@ struct clockinfo { #define TIMER_ABSTIME 0x1 /* absolute timer */ #endif +#ifdef _KERNEL + +/* + * For krateprintf() + */ +struct krate { + int freq; + int ticks; + int count; +}; + +#endif + #ifdef _KERNEL extern time_t time_second; extern int64_t ntp_tick_permanent; -- 2.41.0