* [PATCH 1/6] log level printk rate limit
@ 2006-10-27 3:19 Steven Rostedt
0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2006-10-27 3:19 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 171 bytes --]
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 <srostedt@redhat.com>
-- Steve
[-- Attachment #2: xen-linux-hv-print-rate-limit.patch --]
[-- Type: text/x-patch, Size: 3328 bytes --]
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 Thu Oct 26 22:17:40 2006 -0400
@@ -109,9 +109,13 @@
#include <public/memory.h>
#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 Thu Oct 26 22:17:40 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 <xen/stdarg.h>
@@ -448,6 +452,52 @@ 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_jiffies.
+ */
+int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst)
+{
+ static DEFINE_SPINLOCK(ratelimit_lock);
+ static unsigned long toks = 10 * 5 * HZ;
+ static unsigned long last_msg;
+ static int missed;
+ unsigned long flags;
+ unsigned long now = jiffies;
+
+ spin_lock_irqsave(&ratelimit_lock, flags);
+ toks += now - last_msg;
+ last_msg = now;
+ if (toks > (ratelimit_burst * ratelimit_jiffies))
+ toks = ratelimit_burst * ratelimit_jiffies;
+ if (toks >= ratelimit_jiffies) {
+ int lost = missed;
+
+ missed = 0;
+ toks -= ratelimit_jiffies;
+ 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 jiffies between messages */
+int printk_ratelimit_jiffies = 5 * HZ;
+
+/* number of messages we send before ratelimiting */
+int printk_ratelimit_burst = 10;
+
+int printk_ratelimit(void)
+{
+ return __printk_ratelimit(printk_ratelimit_jiffies,
+ 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 Thu Oct 26 22:17:40 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_jiffies, int ratelimit_burst);
+extern int printk_ratelimit(void);
/* vsprintf.c */
extern int sprintf(char * buf, const char * fmt, ...)
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-10-27 3:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-27 3:19 [PATCH 1/6] log level printk rate limit Steven Rostedt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.