All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <srostedt@redhat.com>
To: xen-devel@lists.xensource.com, Keir.Fraser@cl.cam.ac.uk
Subject: [PATCH] add printf_ratelimit
Date: Mon, 02 Oct 2006 12:39:14 -0400	[thread overview]
Message-ID: <452140B2.3060307@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 843 bytes --]

I sent this patch back on 9/19 and it never went anywhere.  I'm sending 
it again, against the lastest unstable.

-- Steve

==== Originally sent 9/19/2006 ====

If someone turns on verbose and/or debug the hypervisor slams the serial 
pretty badly when starting a FV domain.  So I pulled the 
printk_ratelimit from Linux and put it into the hypervisor.  Right now 
the only user of it is the MEM_LOG in arch/x86/mm.c which can really 
spit out a lot.

Since printk_ratelimit is very helpful in the Linux kernel, I can see it 
being also used in HV.  I changed it slightly from Linux to match the 
naming convention in Xen.  Since printk is defined to printf, I declared 
the function printf_ratelimit and made a define of printk_ratelimit to 
just be a clone of printf_ratelimit.

-- Steve

Signed-off-by: Steven Rostedt <srostedt@redhat.com>

[-- Attachment #2: xen-linux-hv-print-rate-limit.patch --]
[-- Type: text/x-patch, Size: 3557 bytes --]

diff -r f0302ed1ac62 xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c	Mon Oct 02 11:47:55 2006 -0400
+++ b/xen/arch/x86/mm.c	Mon Oct 02 11:48:22 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 f0302ed1ac62 xen/drivers/char/console.c
--- a/xen/drivers/char/console.c	Mon Oct 02 11:47:55 2006 -0400
+++ b/xen/drivers/char/console.c	Mon Oct 02 11:48:22 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 <stdarg.h>
@@ -465,6 +469,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 printf_ratelimit_jiffies.
+ */
+int __printf_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 printf_ratelimit_jiffies = 5 * HZ;
+
+/* number of messages we send before ratelimiting */
+int printf_ratelimit_burst = 10;
+
+int printf_ratelimit(void)
+{
+	return __printf_ratelimit(printf_ratelimit_jiffies,
+				printf_ratelimit_burst);
+}
 
 /*
  * **************************************************************
diff -r f0302ed1ac62 xen/include/xen/lib.h
--- a/xen/include/xen/lib.h	Mon Oct 02 11:47:55 2006 -0400
+++ b/xen/include/xen/lib.h	Mon Oct 02 11:48:22 2006 -0400
@@ -52,8 +52,11 @@ extern void debugtrace_printk(const char
 /* Allows us to use '%p' as general-purpose machine-word format char. */
 #define _p(_x) ((void *)(unsigned long)(_x))
 #define printk(_f , _a...) printf( _f , ## _a )
+#define printk_ratelimit() printf_ratelimit()
 extern void printf(const char *format, ...)
     __attribute__ ((format (printf, 1, 2)));
+extern int __printf_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
+extern int printf_ratelimit(void);
 extern void panic(const char *format, ...)
     __attribute__ ((format (printf, 1, 2)));
 extern long vm_assist(struct domain *, unsigned int, unsigned int);

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

             reply	other threads:[~2006-10-02 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-02 16:39 Steven Rostedt [this message]
2006-10-02 21:55 ` [PATCH] add printf_ratelimit Stephen C. Tweedie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=452140B2.3060307@redhat.com \
    --to=srostedt@redhat.com \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.