From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steven Rostedt Subject: [PATCH 1/6 V2] log level printk rate limit Date: Fri, 27 Oct 2006 11:31:57 -0400 Message-ID: <4542266D.4090404@redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030401080304050902010108" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com, Keir.Fraser@cl.cam.ac.uk List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------030401080304050902010108 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit (Uses milliseconds instead of jiffies) Taken from Andi Kleen's rate limit in the Linux kernel. This keeps large amounts of prints in the HV down. Signed-off-by: Steven Rostedt -- Steve --------------030401080304050902010108 Content-Type: text/x-patch; name="xen-linux-hv-print-rate-limit.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xen-linux-hv-print-rate-limit.patch" diff -r 4a320d26fc24 xen/arch/x86/mm.c --- a/xen/arch/x86/mm.c Thu Oct 26 16:56:16 2006 +0100 +++ b/xen/arch/x86/mm.c Fri Oct 27 11:11:33 2006 -0400 @@ -109,9 +109,13 @@ #include #ifdef VERBOSE -#define MEM_LOG(_f, _a...) \ - printk("DOM%u: (file=mm.c, line=%d) " _f "\n", \ - current->domain->domain_id , __LINE__ , ## _a ) +#define MEM_LOG(_f, _a...) \ + do { \ + if (printk_ratelimit()) { \ + printk("DOM%u: (file=mm.c, line=%d) " _f "\n", \ + current->domain->domain_id , __LINE__ , ## _a ); \ + } \ + } while (0) #else #define MEM_LOG(_f, _a...) ((void)0) #endif diff -r 4a320d26fc24 xen/drivers/char/console.c --- a/xen/drivers/char/console.c Thu Oct 26 16:56:16 2006 +0100 +++ b/xen/drivers/char/console.c Fri Oct 27 11:11:33 2006 -0400 @@ -4,6 +4,10 @@ * Emergency console I/O for Xen and the domain-0 guest OS. * * Copyright (c) 2002-2004, K A Fraser. + * + * Added printf_ratelimit + * Taken from Linux - Author: Andi Kleen (net_ratelimit) + * Ported to Xen - Steven Rostedt - Red Hat */ #include @@ -26,6 +30,7 @@ #include #include #include +#include /* console: comma-separated list of console outputs. */ static char opt_console[30] = OPT_CONSOLE_STR; @@ -448,6 +453,56 @@ int console_getc(void) return serial_getc(sercon_handle); } +/* + * printk rate limiting, lifted from Linux. + * + * This enforces a rate limit: not more than one kernel message + * every printk_ratelimit_ms (millisecs). + */ +int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst) +{ + static DEFINE_SPINLOCK(ratelimit_lock); + static unsigned long toks = 10 * 5 * 1000; + static unsigned long last_msg; + static int missed; + unsigned long flags; + unsigned long long now = NOW(); /* ns */ + unsigned long ms; + + do_div(now, 1000000); + ms = (unsigned long)now; + + spin_lock_irqsave(&ratelimit_lock, flags); + toks += ms - last_msg; + last_msg = ms; + if (toks > (ratelimit_burst * ratelimit_ms)) + toks = ratelimit_burst * ratelimit_ms; + if (toks >= ratelimit_ms) { + int lost = missed; + + missed = 0; + toks -= ratelimit_ms; + spin_unlock_irqrestore(&ratelimit_lock, flags); + if (lost) + printk("printk: %d messages suppressed.\n", lost); + return 1; + } + missed++; + spin_unlock_irqrestore(&ratelimit_lock, flags); + return 0; +} + +/* minimum time in ms between messages */ +int printk_ratelimit_ms = 5 * 1000; + +/* number of messages we send before ratelimiting */ +int printk_ratelimit_burst = 10; + +int printk_ratelimit(void) +{ + return __printk_ratelimit(printk_ratelimit_ms, + printk_ratelimit_burst); +} /* * ************************************************************** diff -r 4a320d26fc24 xen/include/xen/lib.h --- a/xen/include/xen/lib.h Thu Oct 26 16:56:16 2006 +0100 +++ b/xen/include/xen/lib.h Fri Oct 27 11:11:33 2006 -0400 @@ -56,6 +56,8 @@ extern void panic(const char *format, .. extern void panic(const char *format, ...) __attribute__ ((format (printf, 1, 2))); extern long vm_assist(struct domain *, unsigned int, unsigned int); +extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst); +extern int printk_ratelimit(void); /* vsprintf.c */ extern int sprintf(char * buf, const char * fmt, ...) --------------030401080304050902010108 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------030401080304050902010108--