netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -mm] __ratelimit rewrite
@ 2008-05-04  7:07 Dave Young
  2008-05-04  7:54 ` David Miller
  2008-05-04 14:47 ` Joe Perches
  0 siblings, 2 replies; 11+ messages in thread
From: Dave Young @ 2008-05-04  7:07 UTC (permalink / raw)
  To: akpm; +Cc: paulmck, netdev, linux-kernel

All ratelimit user use same jiffies and burst params, so some messages
(callbacks) will be lost.

For example:
a call printk_ratelimit(5 * HZ, 1)
b call printk_ratelimit(5 * HZ, 1) before the 5*HZ timeout of a, then b will
will be supressed.

Here rewrite the __ratelimit function, and use a ratelimit_state as parameter.
Thanks for hints from andrew.

Signed-off-by: Dave Young <hidave.darkstar@gmail.com>

---
include/asm-generic/bug.h  |    4 +--
include/linux/kernel.h     |    9 +------
include/linux/net.h        |    3 --
include/linux/ratelimit.h  |   20 +++++++++++++++
include/linux/rcupreempt.h |    7 +++--
kernel/printk.c            |   17 ++-----------
kernel/sysctl.c            |    4 +--
lib/ratelimit.c            |   57 ++++++++++++++++++++++++---------------------
net/core/sysctl_net_core.c |    4 +--
net/core/utils.c           |    5 +--
10 files changed, 70 insertions(+), 60 deletions(-)

diff -uprN linux/include/asm-generic/bug.h linux.new/include/asm-generic/bug.h
--- linux/include/asm-generic/bug.h	2008-04-30 17:32:54.000000000 +0800
+++ linux.new/include/asm-generic/bug.h	2008-05-04 13:46:38.000000000 +0800
@@ -76,8 +76,8 @@ extern void warn_on_slowpath(const char 
 	unlikely(__ret_warn_once);				\
 })
 
-#define WARN_ON_SECS(condition, state, secs)			\
-		WARN_ON((condition) && __ratelimit(state))
+#define WARN_ON_RATELIMIT(condition, state)			\
+		WARN_ON((condition) && __ratelimit(state));
 
 #ifdef CONFIG_SMP
 # define WARN_ON_SMP(x)			WARN_ON(x)
diff -uprN linux/include/linux/kernel.h linux.new/include/linux/kernel.h
--- linux/include/linux/kernel.h	2008-04-30 17:33:59.000000000 +0800
+++ linux.new/include/linux/kernel.h	2008-04-30 17:33:52.000000000 +0800
@@ -14,6 +14,7 @@
 #include <linux/compiler.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
+#include <linux/ratelimit.h>
 #include <asm/byteorder.h>
 #include <asm/bug.h>
 
@@ -187,12 +188,8 @@ asmlinkage int printk(const char * fmt, 
 extern int log_buf_get_len(void);
 extern int log_buf_read(int idx);
 extern int log_buf_copy(char *dest, int idx, int len);
-
-extern int printk_ratelimit_jiffies;
-extern int printk_ratelimit_burst;
+extern struct ratelimit_state printk_ratelimit_state;
 extern int printk_ratelimit(void);
-extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
-extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
 				   unsigned int interval_msec);
 #else
@@ -206,8 +203,6 @@ static inline int log_buf_get_len(void) 
 static inline int log_buf_read(int idx) { return 0; }
 static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
 static inline int printk_ratelimit(void) { return 0; }
-static inline int __printk_ratelimit(int ratelimit_jiffies, \
-				     int ratelimit_burst) { return 0; }
 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
 					  unsigned int interval_msec)	\
 		{ return false; }
diff -uprN linux/include/linux/net.h linux.new/include/linux/net.h
--- linux/include/linux/net.h	2008-04-30 17:35:36.000000000 +0800
+++ linux.new/include/linux/net.h	2008-04-30 17:35:45.000000000 +0800
@@ -338,8 +338,7 @@ static const struct proto_ops name##_ops
 
 #ifdef CONFIG_SYSCTL
 #include <linux/sysctl.h>
-extern int net_msg_cost;
-extern int net_msg_burst;
+extern struct ratelimit_state net_ratelimit_state;
 #endif
 
 #endif /* __KERNEL__ */
diff -uprN linux/include/linux/ratelimit.h linux.new/include/linux/ratelimit.h
--- linux/include/linux/ratelimit.h	1970-01-01 07:00:00.000000000 +0700
+++ linux.new/include/linux/ratelimit.h	2008-05-04 14:33:50.000000000 +0800
@@ -0,0 +1,20 @@
+#ifndef _LINUX_RATELIMIT_H
+#define _LINUX_RATELIMIT_H
+
+struct ratelimit_state {
+	int interval;
+	int burst;
+	int printed;
+	int missed;
+	unsigned long begin;
+};
+
+#define DEFINE_RATELIMIT_STATE(name, interval, burst)		\
+		struct ratelimit_state name = {interval, burst,}
+extern int __ratelimit(struct ratelimit_state *rs);
+static inline int ratelimit(void)
+{
+	static struct ratelimit_state rs;
+	return __ratelimit(&rs);
+}
+#endif
diff -uprN linux/include/linux/rcupreempt.h linux.new/include/linux/rcupreempt.h
--- linux/include/linux/rcupreempt.h	2008-04-30 17:35:00.000000000 +0800
+++ linux.new/include/linux/rcupreempt.h	2008-05-04 13:48:35.000000000 +0800
@@ -115,16 +115,19 @@ DECLARE_PER_CPU(struct rcu_dyntick_sched
 
 static inline void rcu_enter_nohz(void)
 {
+	static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
 	smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
 	__get_cpu_var(rcu_dyntick_sched).dynticks++;
-	WARN_ON_SECS(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, 10);
+	WARN_ON_RATELIMIT(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, &rs);
 }
 
 static inline void rcu_exit_nohz(void)
 {
+	static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
 	__get_cpu_var(rcu_dyntick_sched).dynticks++;
 	smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
-	WARN_ON_SECS(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1), 10);
+	WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1),
+			&rs);
 }
 
 #else /* CONFIG_NO_HZ */
diff -uprN linux/kernel/printk.c linux.new/kernel/printk.c
--- linux/kernel/printk.c	2008-04-30 17:36:20.000000000 +0800
+++ linux.new/kernel/printk.c	2008-05-04 14:01:35.000000000 +0800
@@ -1323,6 +1323,8 @@ void tty_write_message(struct tty_struct
 }
 
 #if defined CONFIG_PRINTK
+
+DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
 /*
  * printk rate limiting, lifted from the networking subsystem.
  *
@@ -1330,22 +1332,9 @@ void tty_write_message(struct tty_struct
  * every printk_ratelimit_jiffies to make a denial-of-service
  * attack impossible.
  */
-int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst)
-{
-	return __ratelimit(ratelimit_jiffies, ratelimit_burst);
-}
-EXPORT_SYMBOL(__printk_ratelimit);
-
-/* 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);
+	return __ratelimit(&printk_ratelimit_state);
 }
 EXPORT_SYMBOL(printk_ratelimit);
 
diff -uprN linux/kernel/sysctl.c linux.new/kernel/sysctl.c
--- linux/kernel/sysctl.c	2008-04-30 17:36:39.000000000 +0800
+++ linux.new/kernel/sysctl.c	2008-04-30 17:36:46.000000000 +0800
@@ -623,7 +623,7 @@ static struct ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_PRINTK_RATELIMIT,
 		.procname	= "printk_ratelimit",
-		.data		= &printk_ratelimit_jiffies,
+		.data		= &printk_ratelimit_state.interval,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec_jiffies,
@@ -632,7 +632,7 @@ static struct ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
 		.procname	= "printk_ratelimit_burst",
-		.data		= &printk_ratelimit_burst,
+		.data		= &printk_ratelimit_state.burst,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
diff -uprN linux/lib/ratelimit.c linux.new/lib/ratelimit.c
--- linux/lib/ratelimit.c	2008-04-30 17:37:31.000000000 +0800
+++ linux.new/lib/ratelimit.c	2008-05-04 14:46:20.000000000 +0800
@@ -3,6 +3,9 @@
  *
  * Isolated from kernel/printk.c by Dave Young <hidave.darkstar@gmail.com>
  *
+ * 2008-05-01 rewrite the function and use a ratelimit_state data struct as
+ * parameter. Now every user can use their own standalone ratelimit_state.
+ *
  * This file is released under the GPLv2.
  *
  */
@@ -11,41 +14,43 @@
 #include <linux/jiffies.h>
 #include <linux/module.h>
 
+static DEFINE_SPINLOCK(ratelimit_lock);
+static unsigned long flags;
+
 /*
  * __ratelimit - rate limiting
- * @ratelimit_jiffies: minimum time in jiffies between two callbacks
- * @ratelimit_burst: number of callbacks we do before ratelimiting
+ * @rs: ratelimit_state data
  *
- * This enforces a rate limit: not more than @ratelimit_burst callbacks
- * in every ratelimit_jiffies
+ * This enforces a rate limit: not more than @rs->ratelimit_burst callbacks
+ * in every @rs->ratelimit_jiffies
  */
-int __ratelimit(int ratelimit_jiffies, int ratelimit_burst)
+int __ratelimit(struct ratelimit_state *rs)
 {
-	static DEFINE_SPINLOCK(ratelimit_lock);
-	static unsigned toks = 10 * 5 * HZ;
-	static unsigned long last_msg;
-	static int missed;
-	unsigned long flags;
-	unsigned long now = jiffies;
+	if (!rs->interval)
+		return 1;
 
 	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(KERN_WARNING "%s: %d messages suppressed\n",
-				__func__, lost);
-		return 1;
+	if (!rs->begin)
+		rs->begin = jiffies;
+
+	if (time_is_before_jiffies(rs->begin + rs->interval)) {
+		if (rs->missed)
+			printk(KERN_WARNING "%s: %d callbacks suppressed\n",
+				__func__, rs->missed);
+		rs->begin = 0;
+		rs->printed = 0;
+		rs->missed = 0;
 	}
-	missed++;
+	if (rs->burst && rs->burst > rs->printed)
+		goto print;
+
+	rs->missed++;
 	spin_unlock_irqrestore(&ratelimit_lock, flags);
 	return 0;
+
+print:
+	rs->printed++;
+	spin_unlock_irqrestore(&ratelimit_lock, flags);
+	return 1;
 }
 EXPORT_SYMBOL(__ratelimit);
diff -uprN linux/net/core/sysctl_net_core.c linux.new/net/core/sysctl_net_core.c
--- linux/net/core/sysctl_net_core.c	2008-04-30 17:38:59.000000000 +0800
+++ linux.new/net/core/sysctl_net_core.c	2008-04-30 17:38:46.000000000 +0800
@@ -67,7 +67,7 @@ static struct ctl_table net_core_table[]
 	{
 		.ctl_name	= NET_CORE_MSG_COST,
 		.procname	= "message_cost",
-		.data		= &net_msg_cost,
+		.data		= &net_ratelimit_state.interval,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec_jiffies,
@@ -76,7 +76,7 @@ static struct ctl_table net_core_table[]
 	{
 		.ctl_name	= NET_CORE_MSG_BURST,
 		.procname	= "message_burst",
-		.data		= &net_msg_burst,
+		.data		= &net_ratelimit_state.burst,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
diff -uprN linux/net/core/utils.c linux.new/net/core/utils.c
--- linux/net/core/utils.c	2008-04-30 17:38:29.000000000 +0800
+++ linux.new/net/core/utils.c	2008-05-04 14:02:09.000000000 +0800
@@ -31,17 +31,16 @@
 #include <asm/system.h>
 #include <asm/uaccess.h>
 
-int net_msg_cost __read_mostly = 5*HZ;
-int net_msg_burst __read_mostly = 10;
 int net_msg_warn __read_mostly = 1;
 EXPORT_SYMBOL(net_msg_warn);
 
+DEFINE_RATELIMIT_STATE(net_ratelimit_state, 5 * HZ, 10);
 /*
  * All net warning printk()s should be guarded by this function.
  */
 int net_ratelimit(void)
 {
-	return __printk_ratelimit(net_msg_cost, net_msg_burst);
+	return __ratelimit(&net_ratelimit_state);
 }
 EXPORT_SYMBOL(net_ratelimit);
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-04  7:07 [PATCH -mm] __ratelimit rewrite Dave Young
@ 2008-05-04  7:54 ` David Miller
  2008-05-04  8:13   ` Dave Young
  2008-05-04 14:47 ` Joe Perches
  1 sibling, 1 reply; 11+ messages in thread
From: David Miller @ 2008-05-04  7:54 UTC (permalink / raw)
  To: hidave.darkstar; +Cc: akpm, paulmck, netdev, linux-kernel

From: Dave Young <hidave.darkstar@gmail.com>
Date: Sun, 4 May 2008 15:07:38 +0800

Hi Dave,

> @@ -76,8 +76,8 @@ extern void warn_on_slowpath(const char 
>  	unlikely(__ret_warn_once);				\
>  })
>  
> -#define WARN_ON_SECS(condition, state, secs)			\
> -		WARN_ON((condition) && __ratelimit(state))
> +#define WARN_ON_RATELIMIT(condition, state)			\
> +		WARN_ON((condition) && __ratelimit(state));
>  
>  #ifdef CONFIG_SMP
>  # define WARN_ON_SMP(x)			WARN_ON(x)

Are you sure you want that new semicolon there?

	if (foo)
		WARN_ON_RATELIMIT(...);
	else

will result in a compile error.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-04  7:54 ` David Miller
@ 2008-05-04  8:13   ` Dave Young
  0 siblings, 0 replies; 11+ messages in thread
From: Dave Young @ 2008-05-04  8:13 UTC (permalink / raw)
  To: David Miller; +Cc: akpm, paulmck, netdev, linux-kernel

On Sun, May 4, 2008 at 3:54 PM, David Miller <davem@davemloft.net> wrote:
> From: Dave Young <hidave.darkstar@gmail.com>
>  Date: Sun, 4 May 2008 15:07:38 +0800
>
>  Hi Dave,
>
>
>  > @@ -76,8 +76,8 @@ extern void warn_on_slowpath(const char
>  >       unlikely(__ret_warn_once);                              \
>  >  })
>  >
>  > -#define WARN_ON_SECS(condition, state, secs)                 \
>  > -             WARN_ON((condition) && __ratelimit(state))
>  > +#define WARN_ON_RATELIMIT(condition, state)                  \
>  > +             WARN_ON((condition) && __ratelimit(state));
>  >
>  >  #ifdef CONFIG_SMP
>  >  # define WARN_ON_SMP(x)                      WARN_ON(x)
>
>  Are you sure you want that new semicolon there?

David, thanks for your review. Will fix.

>
>         if (foo)
>                 WARN_ON_RATELIMIT(...);
>         else
>
>  will result in a compile error.
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-04  7:07 [PATCH -mm] __ratelimit rewrite Dave Young
  2008-05-04  7:54 ` David Miller
@ 2008-05-04 14:47 ` Joe Perches
  2008-05-05  1:37   ` Dave Young
  1 sibling, 1 reply; 11+ messages in thread
From: Joe Perches @ 2008-05-04 14:47 UTC (permalink / raw)
  To: Dave Young; +Cc: akpm, paulmck, netdev, linux-kernel

On Sun, 2008-05-04 at 15:07 +0800, Dave Young wrote:
> diff -uprN linux/include/linux/kernel.h linux.new/include/linux/kernel.h
> --- linux/include/linux/kernel.h	2008-04-30 17:33:59.000000000 +0800
> +++ linux.new/include/linux/kernel.h	2008-04-30 17:33:52.000000000 +0800
> @@ -14,6 +14,7 @@
>  #include <linux/compiler.h>
>  #include <linux/bitops.h>
>  #include <linux/log2.h>
> +#include <linux/ratelimit.h>
>  #include <asm/byteorder.h>
>  #include <asm/bug.h> 

Good idea.

I think #include <linux/printk.h>
and a reorganization of all the printk related
elements from kernel.h to printk.h would be better
and should be done first.

I think your changes should then be done in
printk.h not creating a new ratelimit.h.

Signed-off-by: Joe Perches <joe@perches.com>
---
 include/linux/kernel.h |  113 +---------------------------------------
 include/linux/printk.h |  137 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 138 insertions(+), 112 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4d46e29..51ae259 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -14,6 +14,7 @@
 #include <linux/compiler.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
+#include <linux/printk.h>
 #include <asm/byteorder.h>
 #include <asm/bug.h>
 
@@ -70,29 +71,6 @@ extern const char linux_proc_banner[];
  */
 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
 
-#define	KERN_EMERG	"<0>"	/* system is unusable			*/
-#define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
-#define	KERN_CRIT	"<2>"	/* critical conditions			*/
-#define	KERN_ERR	"<3>"	/* error conditions			*/
-#define	KERN_WARNING	"<4>"	/* warning conditions			*/
-#define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
-#define	KERN_INFO	"<6>"	/* informational			*/
-#define	KERN_DEBUG	"<7>"	/* debug-level messages			*/
-
-/*
- * Annotation for a "continued" line of log printout (only done after a
- * line that had no enclosing \n). Only to be used by core/arch code
- * during early bootup (a continued line is not SMP-safe otherwise).
- */
-#define	KERN_CONT	""
-
-extern int console_printk[];
-
-#define console_loglevel (console_printk[0])
-#define default_message_loglevel (console_printk[1])
-#define minimum_console_loglevel (console_printk[2])
-#define default_console_loglevel (console_printk[3])
-
 struct completion;
 struct pt_regs;
 struct user;
@@ -179,56 +157,8 @@ extern int kernel_text_address(unsigned long addr);
 struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
-#ifdef CONFIG_PRINTK
-asmlinkage int vprintk(const char *fmt, va_list args)
-	__attribute__ ((format (printf, 1, 0)));
-asmlinkage int printk(const char * fmt, ...)
-	__attribute__ ((format (printf, 1, 2))) __cold;
-extern int log_buf_get_len(void);
-extern int log_buf_read(int idx);
-extern int log_buf_copy(char *dest, int idx, int len);
-
-extern int printk_ratelimit_jiffies;
-extern int printk_ratelimit_burst;
-extern int printk_ratelimit(void);
-extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
-extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
-extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
-				   unsigned int interval_msec);
-#else
-static inline int vprintk(const char *s, va_list args)
-	__attribute__ ((format (printf, 1, 0)));
-static inline int vprintk(const char *s, va_list args) { return 0; }
-static inline int printk(const char *s, ...)
-	__attribute__ ((format (printf, 1, 2)));
-static inline int __cold printk(const char *s, ...) { return 0; }
-static inline int log_buf_get_len(void) { return 0; }
-static inline int log_buf_read(int idx) { return 0; }
-static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
-static inline int printk_ratelimit(void) { return 0; }
-static inline int __printk_ratelimit(int ratelimit_jiffies, \
-				     int ratelimit_burst) { return 0; }
-static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
-					  unsigned int interval_msec)	\
-		{ return false; }
-#endif
-
-extern void __attribute__((format(printf, 1, 2)))
-	early_printk(const char *fmt, ...);
-
 unsigned long int_sqrt(unsigned long);
 
-static inline void console_silent(void)
-{
-	console_loglevel = 0;
-}
-
-static inline void console_verbose(void)
-{
-	if (console_loglevel)
-		console_loglevel = 15;
-}
-
 extern void bust_spinlocks(int yes);
 extern void wake_up_klogd(void);
 extern int oops_in_progress;		/* If set, an oops, panic(), BUG() or die() is in progress */
@@ -261,47 +191,6 @@ extern enum system_states {
 #define TAINT_OVERRIDDEN_ACPI_TABLE	(1<<8)
 #define TAINT_WARN			(1<<9)
 
-extern void dump_stack(void) __cold;
-
-enum {
-	DUMP_PREFIX_NONE,
-	DUMP_PREFIX_ADDRESS,
-	DUMP_PREFIX_OFFSET
-};
-extern void hex_dump_to_buffer(const void *buf, size_t len,
-				int rowsize, int groupsize,
-				char *linebuf, size_t linebuflen, bool ascii);
-extern void print_hex_dump(const char *level, const char *prefix_str,
-				int prefix_type, int rowsize, int groupsize,
-				const void *buf, size_t len, bool ascii);
-extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
-			const void *buf, size_t len);
-#define hex_asc(x)	"0123456789abcdef"[x]
-
-#define pr_emerg(fmt, arg...) \
-	printk(KERN_EMERG fmt, ##arg)
-#define pr_alert(fmt, arg...) \
-	printk(KERN_ALERT fmt, ##arg)
-#define pr_crit(fmt, arg...) \
-	printk(KERN_CRIT fmt, ##arg)
-#define pr_err(fmt, arg...) \
-	printk(KERN_ERR fmt, ##arg)
-#define pr_warning(fmt, arg...) \
-	printk(KERN_WARNING fmt, ##arg)
-#define pr_notice(fmt, arg...) \
-	printk(KERN_NOTICE fmt, ##arg)
-#define pr_info(fmt, arg...) \
-	printk(KERN_INFO fmt, ##arg)
-
-#ifdef DEBUG
-/* If you are writing a driver, please use dev_dbg instead */
-#define pr_debug(fmt, arg...) \
-	printk(KERN_DEBUG fmt, ##arg)
-#else
-#define pr_debug(fmt, arg...) \
-	({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
-#endif
-
 /*
  *      Display an IP address in readable format.
  */
diff --git a/include/linux/printk.h b/include/linux/printk.h
new file mode 100644
index 0000000..732ee9c
--- /dev/null
+++ b/include/linux/printk.h
@@ -0,0 +1,137 @@
+#ifndef _LINUX_PRINTK_H
+#define _LINUX_PRINTK_H
+
+#define	KERN_EMERG	"<0>"	/* system is unusable			*/
+#define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
+#define	KERN_CRIT	"<2>"	/* critical conditions			*/
+#define	KERN_ERR	"<3>"	/* error conditions			*/
+#define	KERN_WARNING	"<4>"	/* warning conditions			*/
+#define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
+#define	KERN_INFO	"<6>"	/* informational			*/
+#define	KERN_DEBUG	"<7>"	/* debug-level messages			*/
+
+/*
+ * Annotation for a "continued" line of log printout (only done after a
+ * line that had no enclosing \n). Only to be used by core/arch code
+ * during early bootup (a continued line is not SMP-safe otherwise).
+ */
+#define	KERN_CONT	""
+
+extern int console_printk[];
+
+#define console_loglevel (console_printk[0])
+#define default_message_loglevel (console_printk[1])
+#define minimum_console_loglevel (console_printk[2])
+#define default_console_loglevel (console_printk[3])
+
+#ifdef CONFIG_PRINTK
+asmlinkage int vprintk(const char *fmt, va_list args)
+	__attribute__ ((format (printf, 1, 0)));
+asmlinkage int printk(const char *fmt, ...)
+	__attribute__ ((format (printf, 1, 2))) __cold;
+extern int log_buf_get_len(void);
+extern int log_buf_read(int idx);
+extern int log_buf_copy(char *dest, int idx, int len);
+
+extern int printk_ratelimit_jiffies;
+extern int printk_ratelimit_burst;
+extern int printk_ratelimit(void);
+extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
+extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
+extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
+				   unsigned int interval_msec);
+#else
+static inline int __attribute__ ((format (printf, 1, 0)))
+vprintk(const char *s, va_list args)
+{
+	return 0;
+}
+static inline int __attribute__ ((format (printf, 1, 2))) __cold
+printk(const char *s, ...)
+{
+	return 0;
+}
+static inline int log_buf_get_len(void)
+{
+	return 0;
+}
+static inline int log_buf_read(int idx)
+{
+	return 0;
+}
+static inline int log_buf_copy(char *dest, int idx, int len)
+{
+	return 0;
+}
+static inline int printk_ratelimit(void)
+{
+	return 0;
+}
+static inline int __printk_ratelimit(int ratelimit_jiffies,
+				     int ratelimit_burst)
+{
+	return 0;
+}
+static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
+					  unsigned int interval_msec)
+{
+	return false;
+}
+#endif
+
+extern void __attribute__((format(printf, 1, 2)))
+	early_printk(const char *fmt, ...);
+
+static inline void console_silent(void)
+{
+	console_loglevel = 0;
+}
+
+static inline void console_verbose(void)
+{
+	if (console_loglevel)
+		console_loglevel = 15;
+}
+
+extern void dump_stack(void) __cold;
+
+enum {
+	DUMP_PREFIX_NONE,
+	DUMP_PREFIX_ADDRESS,
+	DUMP_PREFIX_OFFSET
+};
+extern void hex_dump_to_buffer(const void *buf, size_t len,
+			       int rowsize, int groupsize,
+			       char *linebuf, size_t linebuflen, bool ascii);
+extern void print_hex_dump(const char *level, const char *prefix_str,
+			   int prefix_type, int rowsize, int groupsize,
+			   const void *buf, size_t len, bool ascii);
+extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
+				 const void *buf, size_t len);
+#define hex_asc(x)	"0123456789abcdef"[x]
+
+#define pr_emerg(fmt, arg...) \
+	printk(KERN_EMERG fmt, ##arg)
+#define pr_alert(fmt, arg...) \
+	printk(KERN_ALERT fmt, ##arg)
+#define pr_crit(fmt, arg...) \
+	printk(KERN_CRIT fmt, ##arg)
+#define pr_err(fmt, arg...) \
+	printk(KERN_ERR fmt, ##arg)
+#define pr_warning(fmt, arg...) \
+	printk(KERN_WARNING fmt, ##arg)
+#define pr_notice(fmt, arg...) \
+	printk(KERN_NOTICE fmt, ##arg)
+#define pr_info(fmt, arg...) \
+	printk(KERN_INFO fmt, ##arg)
+
+#ifdef DEBUG
+/* If you are writing a driver, please use dev_dbg instead */
+#define pr_debug(fmt, arg...) \
+	printk(KERN_DEBUG fmt, ##arg)
+#else
+#define pr_debug(fmt, arg...) \
+	({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
+#endif
+
+#endif



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-04 14:47 ` Joe Perches
@ 2008-05-05  1:37   ` Dave Young
  2008-05-05  2:25     ` Joe Perches
  2008-05-05  2:27     ` Dave Young
  0 siblings, 2 replies; 11+ messages in thread
From: Dave Young @ 2008-05-05  1:37 UTC (permalink / raw)
  To: Joe Perches; +Cc: akpm, paulmck, netdev, linux-kernel

Hi,
Thanks for comment.

On Sun, May 4, 2008 at 10:47 PM, Joe Perches <joe@perches.com> wrote:
> On Sun, 2008-05-04 at 15:07 +0800, Dave Young wrote:
>  > diff -uprN linux/include/linux/kernel.h linux.new/include/linux/kernel.h
>  > --- linux/include/linux/kernel.h      2008-04-30 17:33:59.000000000 +0800
>  > +++ linux.new/include/linux/kernel.h  2008-04-30 17:33:52.000000000 +0800
>  > @@ -14,6 +14,7 @@
>  >  #include <linux/compiler.h>
>  >  #include <linux/bitops.h>
>  >  #include <linux/log2.h>
>  > +#include <linux/ratelimit.h>
>  >  #include <asm/byteorder.h>
>  >  #include <asm/bug.h>
>
>  Good idea.
>
>  I think #include <linux/printk.h>
>  and a reorganization of all the printk related
>  elements from kernel.h to printk.h would be better
>  and should be done first.

Sounds good.

>
>  I think your changes should then be done in
>  printk.h not creating a new ratelimit.h.

IMO ratelimit is not just for printk use now, so a standalone head
file is necessary.

>
>  Signed-off-by: Joe Perches <joe@perches.com>
>  ---
>   include/linux/kernel.h |  113 +---------------------------------------
>   include/linux/printk.h |  137 ++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 138 insertions(+), 112 deletions(-)
>
>  diff --git a/include/linux/kernel.h b/include/linux/kernel.h
>  index 4d46e29..51ae259 100644
>  --- a/include/linux/kernel.h
>  +++ b/include/linux/kernel.h
>
> @@ -14,6 +14,7 @@
>   #include <linux/compiler.h>
>   #include <linux/bitops.h>
>   #include <linux/log2.h>
>  +#include <linux/printk.h>
>
>  #include <asm/byteorder.h>
>   #include <asm/bug.h>
>
>  @@ -70,29 +71,6 @@ extern const char linux_proc_banner[];
>   */
>   #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
>
>  -#define        KERN_EMERG      "<0>"   /* system is unusable                   */
>  -#define        KERN_ALERT      "<1>"   /* action must be taken immediately     */
>  -#define        KERN_CRIT       "<2>"   /* critical conditions                  */
>  -#define        KERN_ERR        "<3>"   /* error conditions                     */
>  -#define        KERN_WARNING    "<4>"   /* warning conditions                   */
>  -#define        KERN_NOTICE     "<5>"   /* normal but significant condition     */
>  -#define        KERN_INFO       "<6>"   /* informational                        */
>  -#define        KERN_DEBUG      "<7>"   /* debug-level messages                 */
>  -
>  -/*
>  - * Annotation for a "continued" line of log printout (only done after a
>  - * line that had no enclosing \n). Only to be used by core/arch code
>  - * during early bootup (a continued line is not SMP-safe otherwise).
>  - */
>  -#define        KERN_CONT       ""
>  -
>  -extern int console_printk[];
>  -
>  -#define console_loglevel (console_printk[0])
>  -#define default_message_loglevel (console_printk[1])
>  -#define minimum_console_loglevel (console_printk[2])
>  -#define default_console_loglevel (console_printk[3])
>  -
>   struct completion;
>   struct pt_regs;
>   struct user;
>  @@ -179,56 +157,8 @@ extern int kernel_text_address(unsigned long addr);
>   struct pid;
>   extern struct pid *session_of_pgrp(struct pid *pgrp);
>
>  -#ifdef CONFIG_PRINTK
>  -asmlinkage int vprintk(const char *fmt, va_list args)
>  -       __attribute__ ((format (printf, 1, 0)));
>  -asmlinkage int printk(const char * fmt, ...)
>  -       __attribute__ ((format (printf, 1, 2))) __cold;
>  -extern int log_buf_get_len(void);
>
> -extern int log_buf_read(int idx);
>  -extern int log_buf_copy(char *dest, int idx, int len);
>  -
>  -extern int printk_ratelimit_jiffies;
>  -extern int printk_ratelimit_burst;
>  -extern int printk_ratelimit(void);
>
> -extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  -extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  -extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
>  -                                  unsigned int interval_msec);
>  -#else
>  -static inline int vprintk(const char *s, va_list args)
>  -       __attribute__ ((format (printf, 1, 0)));
>  -static inline int vprintk(const char *s, va_list args) { return 0; }
>  -static inline int printk(const char *s, ...)
>  -       __attribute__ ((format (printf, 1, 2)));
>  -static inline int __cold printk(const char *s, ...) { return 0; }
>  -static inline int log_buf_get_len(void) { return 0; }
>  -static inline int log_buf_read(int idx) { return 0; }
>
> -static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
>  -static inline int printk_ratelimit(void) { return 0; }
>  -static inline int __printk_ratelimit(int ratelimit_jiffies, \
>  -                                    int ratelimit_burst) { return 0; }
>  -static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
>  -                                         unsigned int interval_msec)   \
>  -               { return false; }
>  -#endif
>  -
>  -extern void __attribute__((format(printf, 1, 2)))
>  -       early_printk(const char *fmt, ...);
>  -
>   unsigned long int_sqrt(unsigned long);
>
>  -static inline void console_silent(void)
>  -{
>  -       console_loglevel = 0;
>  -}
>  -
>  -static inline void console_verbose(void)
>  -{
>  -       if (console_loglevel)
>  -               console_loglevel = 15;
>  -}
>  -
>   extern void bust_spinlocks(int yes);
>   extern void wake_up_klogd(void);
>   extern int oops_in_progress;           /* If set, an oops, panic(), BUG() or die() is in progress */
>  @@ -261,47 +191,6 @@ extern enum system_states {
>   #define TAINT_OVERRIDDEN_ACPI_TABLE    (1<<8)
>   #define TAINT_WARN                     (1<<9)
>
>  -extern void dump_stack(void) __cold;
>  -
>  -enum {
>  -       DUMP_PREFIX_NONE,
>  -       DUMP_PREFIX_ADDRESS,
>  -       DUMP_PREFIX_OFFSET
>  -};
>  -extern void hex_dump_to_buffer(const void *buf, size_t len,
>  -                               int rowsize, int groupsize,
>  -                               char *linebuf, size_t linebuflen, bool ascii);
>  -extern void print_hex_dump(const char *level, const char *prefix_str,
>  -                               int prefix_type, int rowsize, int groupsize,
>  -                               const void *buf, size_t len, bool ascii);
>  -extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
>  -                       const void *buf, size_t len);
>  -#define hex_asc(x)     "0123456789abcdef"[x]
>  -
>  -#define pr_emerg(fmt, arg...) \
>  -       printk(KERN_EMERG fmt, ##arg)
>  -#define pr_alert(fmt, arg...) \
>  -       printk(KERN_ALERT fmt, ##arg)
>  -#define pr_crit(fmt, arg...) \
>  -       printk(KERN_CRIT fmt, ##arg)
>  -#define pr_err(fmt, arg...) \
>  -       printk(KERN_ERR fmt, ##arg)
>  -#define pr_warning(fmt, arg...) \
>  -       printk(KERN_WARNING fmt, ##arg)
>  -#define pr_notice(fmt, arg...) \
>  -       printk(KERN_NOTICE fmt, ##arg)
>  -#define pr_info(fmt, arg...) \
>  -       printk(KERN_INFO fmt, ##arg)
>  -
>  -#ifdef DEBUG
>  -/* If you are writing a driver, please use dev_dbg instead */
>  -#define pr_debug(fmt, arg...) \
>  -       printk(KERN_DEBUG fmt, ##arg)
>  -#else
>  -#define pr_debug(fmt, arg...) \
>  -       ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
>  -#endif
>  -
>   /*
>   *      Display an IP address in readable format.
>   */
>  diff --git a/include/linux/printk.h b/include/linux/printk.h
>  new file mode 100644
>  index 0000000..732ee9c
>  --- /dev/null
>  +++ b/include/linux/printk.h
>  @@ -0,0 +1,137 @@
>  +#ifndef _LINUX_PRINTK_H
>  +#define _LINUX_PRINTK_H
>  +
>  +#define        KERN_EMERG      "<0>"   /* system is unusable                   */
>  +#define        KERN_ALERT      "<1>"   /* action must be taken immediately     */
>  +#define        KERN_CRIT       "<2>"   /* critical conditions                  */
>  +#define        KERN_ERR        "<3>"   /* error conditions                     */
>  +#define        KERN_WARNING    "<4>"   /* warning conditions                   */
>  +#define        KERN_NOTICE     "<5>"   /* normal but significant condition     */
>  +#define        KERN_INFO       "<6>"   /* informational                        */
>  +#define        KERN_DEBUG      "<7>"   /* debug-level messages                 */
>  +
>  +/*
>  + * Annotation for a "continued" line of log printout (only done after a
>  + * line that had no enclosing \n). Only to be used by core/arch code
>  + * during early bootup (a continued line is not SMP-safe otherwise).
>  + */
>  +#define        KERN_CONT       ""
>  +
>  +extern int console_printk[];
>  +
>  +#define console_loglevel (console_printk[0])
>  +#define default_message_loglevel (console_printk[1])
>  +#define minimum_console_loglevel (console_printk[2])
>  +#define default_console_loglevel (console_printk[3])
>  +
>  +#ifdef CONFIG_PRINTK
>  +asmlinkage int vprintk(const char *fmt, va_list args)
>  +       __attribute__ ((format (printf, 1, 0)));
>  +asmlinkage int printk(const char *fmt, ...)
>  +       __attribute__ ((format (printf, 1, 2))) __cold;
>  +extern int log_buf_get_len(void);
>
> +extern int log_buf_read(int idx);
>  +extern int log_buf_copy(char *dest, int idx, int len);
>  +
>  +extern int printk_ratelimit_jiffies;
>  +extern int printk_ratelimit_burst;
>  +extern int printk_ratelimit(void);
>
> +extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  +extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  +extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
>  +                                  unsigned int interval_msec);
>  +#else
>  +static inline int __attribute__ ((format (printf, 1, 0)))
>  +vprintk(const char *s, va_list args)
>  +{
>  +       return 0;
>  +}
>  +static inline int __attribute__ ((format (printf, 1, 2))) __cold
>  +printk(const char *s, ...)
>  +{
>  +       return 0;
>  +}
>  +static inline int log_buf_get_len(void)
>  +{
>  +       return 0;
>  +}
>  +static inline int log_buf_read(int idx)
>
> +{
>  +       return 0;
>  +}
>  +static inline int log_buf_copy(char *dest, int idx, int len)
>  +{
>  +       return 0;
>  +}
>  +static inline int printk_ratelimit(void)
>  +{
>  +       return 0;
>  +}
>  +static inline int __printk_ratelimit(int ratelimit_jiffies,
>  +                                    int ratelimit_burst)
>  +{
>  +       return 0;
>  +}
>  +static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
>  +                                         unsigned int interval_msec)
>  +{
>  +       return false;
>  +}
>  +#endif
>  +
>  +extern void __attribute__((format(printf, 1, 2)))
>  +       early_printk(const char *fmt, ...);
>  +
>  +static inline void console_silent(void)
>  +{
>  +       console_loglevel = 0;
>  +}
>  +
>  +static inline void console_verbose(void)
>  +{
>  +       if (console_loglevel)
>  +               console_loglevel = 15;
>  +}
>  +
>  +extern void dump_stack(void) __cold;
>  +
>  +enum {
>  +       DUMP_PREFIX_NONE,
>  +       DUMP_PREFIX_ADDRESS,
>  +       DUMP_PREFIX_OFFSET
>  +};
>  +extern void hex_dump_to_buffer(const void *buf, size_t len,
>  +                              int rowsize, int groupsize,
>  +                              char *linebuf, size_t linebuflen, bool ascii);
>  +extern void print_hex_dump(const char *level, const char *prefix_str,
>  +                          int prefix_type, int rowsize, int groupsize,
>  +                          const void *buf, size_t len, bool ascii);
>  +extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
>  +                                const void *buf, size_t len);
>  +#define hex_asc(x)     "0123456789abcdef"[x]
>  +
>  +#define pr_emerg(fmt, arg...) \
>  +       printk(KERN_EMERG fmt, ##arg)
>  +#define pr_alert(fmt, arg...) \
>  +       printk(KERN_ALERT fmt, ##arg)
>  +#define pr_crit(fmt, arg...) \
>  +       printk(KERN_CRIT fmt, ##arg)
>  +#define pr_err(fmt, arg...) \
>  +       printk(KERN_ERR fmt, ##arg)
>  +#define pr_warning(fmt, arg...) \
>  +       printk(KERN_WARNING fmt, ##arg)
>  +#define pr_notice(fmt, arg...) \
>  +       printk(KERN_NOTICE fmt, ##arg)
>  +#define pr_info(fmt, arg...) \
>  +       printk(KERN_INFO fmt, ##arg)
>  +
>  +#ifdef DEBUG
>  +/* If you are writing a driver, please use dev_dbg instead */
>  +#define pr_debug(fmt, arg...) \
>  +       printk(KERN_DEBUG fmt, ##arg)
>  +#else
>  +#define pr_debug(fmt, arg...) \
>  +       ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
>  +#endif
>  +
>  +#endif
>
>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-05  1:37   ` Dave Young
@ 2008-05-05  2:25     ` Joe Perches
  2008-05-05  2:58       ` Dave Young
  2008-05-05  2:27     ` Dave Young
  1 sibling, 1 reply; 11+ messages in thread
From: Joe Perches @ 2008-05-05  2:25 UTC (permalink / raw)
  To: Dave Young; +Cc: akpm, paulmck, netdev, linux-kernel

On Mon, 2008-05-05 at 09:37 +0800, Dave Young wrote:
> >  I think your changes should then be done in
> >  printk.h not creating a new ratelimit.h.
> 
> IMO ratelimit is not just for printk use now, so a standalone head
> file is necessary.

What other uses would ratelimit have?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-05  1:37   ` Dave Young
  2008-05-05  2:25     ` Joe Perches
@ 2008-05-05  2:27     ` Dave Young
  1 sibling, 0 replies; 11+ messages in thread
From: Dave Young @ 2008-05-05  2:27 UTC (permalink / raw)
  To: Joe Perches; +Cc: akpm, paulmck, netdev, linux-kernel

On Mon, May 5, 2008 at 9:37 AM, Dave Young <hidave.darkstar@gmail.com> wrote:
> Hi,
>  Thanks for comment.
>
>
>  On Sun, May 4, 2008 at 10:47 PM, Joe Perches <joe@perches.com> wrote:
>  > On Sun, 2008-05-04 at 15:07 +0800, Dave Young wrote:
>  >  > diff -uprN linux/include/linux/kernel.h linux.new/include/linux/kernel.h
>  >  > --- linux/include/linux/kernel.h      2008-04-30 17:33:59.000000000 +0800
>  >  > +++ linux.new/include/linux/kernel.h  2008-04-30 17:33:52.000000000 +0800
>  >  > @@ -14,6 +14,7 @@
>  >  >  #include <linux/compiler.h>
>  >  >  #include <linux/bitops.h>
>  >  >  #include <linux/log2.h>
>  >  > +#include <linux/ratelimit.h>
>  >  >  #include <asm/byteorder.h>
>  >  >  #include <asm/bug.h>
>  >
>  >  Good idea.
>  >
>  >  I think #include <linux/printk.h>
>  >  and a reorganization of all the printk related
>  >  elements from kernel.h to printk.h would be better
>  >  and should be done first.

If split printk.h from kernel.h, then kernel.h had better don't
include printk.h.
Instead every printk user include "printk.h". This seems too much changes.

Right?

>
>  Sounds good.
>
>
>  >
>  >  I think your changes should then be done in
>  >  printk.h not creating a new ratelimit.h.
>
>  IMO ratelimit is not just for printk use now, so a standalone head
>  file is necessary.
>
>
>
>  >
>  >  Signed-off-by: Joe Perches <joe@perches.com>
>  >  ---
>  >   include/linux/kernel.h |  113 +---------------------------------------
>  >   include/linux/printk.h |  137 ++++++++++++++++++++++++++++++++++++++++++++++++
>  >   2 files changed, 138 insertions(+), 112 deletions(-)
>  >
>  >  diff --git a/include/linux/kernel.h b/include/linux/kernel.h
>  >  index 4d46e29..51ae259 100644
>  >  --- a/include/linux/kernel.h
>  >  +++ b/include/linux/kernel.h
>  >
>  > @@ -14,6 +14,7 @@
>  >   #include <linux/compiler.h>
>  >   #include <linux/bitops.h>
>  >   #include <linux/log2.h>
>  >  +#include <linux/printk.h>
>  >
>  >  #include <asm/byteorder.h>
>  >   #include <asm/bug.h>
>  >
>  >  @@ -70,29 +71,6 @@ extern const char linux_proc_banner[];
>  >   */
>  >   #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
>  >
>  >  -#define        KERN_EMERG      "<0>"   /* system is unusable                   */
>  >  -#define        KERN_ALERT      "<1>"   /* action must be taken immediately     */
>  >  -#define        KERN_CRIT       "<2>"   /* critical conditions                  */
>  >  -#define        KERN_ERR        "<3>"   /* error conditions                     */
>  >  -#define        KERN_WARNING    "<4>"   /* warning conditions                   */
>  >  -#define        KERN_NOTICE     "<5>"   /* normal but significant condition     */
>  >  -#define        KERN_INFO       "<6>"   /* informational                        */
>  >  -#define        KERN_DEBUG      "<7>"   /* debug-level messages                 */
>  >  -
>  >  -/*
>  >  - * Annotation for a "continued" line of log printout (only done after a
>  >  - * line that had no enclosing \n). Only to be used by core/arch code
>  >  - * during early bootup (a continued line is not SMP-safe otherwise).
>  >  - */
>  >  -#define        KERN_CONT       ""
>  >  -
>  >  -extern int console_printk[];
>  >  -
>  >  -#define console_loglevel (console_printk[0])
>  >  -#define default_message_loglevel (console_printk[1])
>  >  -#define minimum_console_loglevel (console_printk[2])
>  >  -#define default_console_loglevel (console_printk[3])
>  >  -
>  >   struct completion;
>  >   struct pt_regs;
>  >   struct user;
>  >  @@ -179,56 +157,8 @@ extern int kernel_text_address(unsigned long addr);
>  >   struct pid;
>  >   extern struct pid *session_of_pgrp(struct pid *pgrp);
>  >
>  >  -#ifdef CONFIG_PRINTK
>  >  -asmlinkage int vprintk(const char *fmt, va_list args)
>  >  -       __attribute__ ((format (printf, 1, 0)));
>  >  -asmlinkage int printk(const char * fmt, ...)
>  >  -       __attribute__ ((format (printf, 1, 2))) __cold;
>  >  -extern int log_buf_get_len(void);
>  >
>  > -extern int log_buf_read(int idx);
>  >  -extern int log_buf_copy(char *dest, int idx, int len);
>  >  -
>  >  -extern int printk_ratelimit_jiffies;
>  >  -extern int printk_ratelimit_burst;
>  >  -extern int printk_ratelimit(void);
>  >
>  > -extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  >  -extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  >  -extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
>  >  -                                  unsigned int interval_msec);
>  >  -#else
>  >  -static inline int vprintk(const char *s, va_list args)
>  >  -       __attribute__ ((format (printf, 1, 0)));
>  >  -static inline int vprintk(const char *s, va_list args) { return 0; }
>  >  -static inline int printk(const char *s, ...)
>  >  -       __attribute__ ((format (printf, 1, 2)));
>  >  -static inline int __cold printk(const char *s, ...) { return 0; }
>  >  -static inline int log_buf_get_len(void) { return 0; }
>  >  -static inline int log_buf_read(int idx) { return 0; }
>  >
>  > -static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
>  >  -static inline int printk_ratelimit(void) { return 0; }
>  >  -static inline int __printk_ratelimit(int ratelimit_jiffies, \
>  >  -                                    int ratelimit_burst) { return 0; }
>  >  -static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
>  >  -                                         unsigned int interval_msec)   \
>  >  -               { return false; }
>  >  -#endif
>  >  -
>  >  -extern void __attribute__((format(printf, 1, 2)))
>  >  -       early_printk(const char *fmt, ...);
>  >  -
>  >   unsigned long int_sqrt(unsigned long);
>  >
>  >  -static inline void console_silent(void)
>  >  -{
>  >  -       console_loglevel = 0;
>  >  -}
>  >  -
>  >  -static inline void console_verbose(void)
>  >  -{
>  >  -       if (console_loglevel)
>  >  -               console_loglevel = 15;
>  >  -}
>  >  -
>  >   extern void bust_spinlocks(int yes);
>  >   extern void wake_up_klogd(void);
>  >   extern int oops_in_progress;           /* If set, an oops, panic(), BUG() or die() is in progress */
>  >  @@ -261,47 +191,6 @@ extern enum system_states {
>  >   #define TAINT_OVERRIDDEN_ACPI_TABLE    (1<<8)
>  >   #define TAINT_WARN                     (1<<9)
>  >
>  >  -extern void dump_stack(void) __cold;
>  >  -
>  >  -enum {
>  >  -       DUMP_PREFIX_NONE,
>  >  -       DUMP_PREFIX_ADDRESS,
>  >  -       DUMP_PREFIX_OFFSET
>  >  -};
>  >  -extern void hex_dump_to_buffer(const void *buf, size_t len,
>  >  -                               int rowsize, int groupsize,
>  >  -                               char *linebuf, size_t linebuflen, bool ascii);
>  >  -extern void print_hex_dump(const char *level, const char *prefix_str,
>  >  -                               int prefix_type, int rowsize, int groupsize,
>  >  -                               const void *buf, size_t len, bool ascii);
>  >  -extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
>  >  -                       const void *buf, size_t len);
>  >  -#define hex_asc(x)     "0123456789abcdef"[x]
>  >  -
>  >  -#define pr_emerg(fmt, arg...) \
>  >  -       printk(KERN_EMERG fmt, ##arg)
>  >  -#define pr_alert(fmt, arg...) \
>  >  -       printk(KERN_ALERT fmt, ##arg)
>  >  -#define pr_crit(fmt, arg...) \
>  >  -       printk(KERN_CRIT fmt, ##arg)
>  >  -#define pr_err(fmt, arg...) \
>  >  -       printk(KERN_ERR fmt, ##arg)
>  >  -#define pr_warning(fmt, arg...) \
>  >  -       printk(KERN_WARNING fmt, ##arg)
>  >  -#define pr_notice(fmt, arg...) \
>  >  -       printk(KERN_NOTICE fmt, ##arg)
>  >  -#define pr_info(fmt, arg...) \
>  >  -       printk(KERN_INFO fmt, ##arg)
>  >  -
>  >  -#ifdef DEBUG
>  >  -/* If you are writing a driver, please use dev_dbg instead */
>  >  -#define pr_debug(fmt, arg...) \
>  >  -       printk(KERN_DEBUG fmt, ##arg)
>  >  -#else
>  >  -#define pr_debug(fmt, arg...) \
>  >  -       ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
>  >  -#endif
>  >  -
>  >   /*
>  >   *      Display an IP address in readable format.
>  >   */
>  >  diff --git a/include/linux/printk.h b/include/linux/printk.h
>  >  new file mode 100644
>  >  index 0000000..732ee9c
>  >  --- /dev/null
>  >  +++ b/include/linux/printk.h
>  >  @@ -0,0 +1,137 @@
>  >  +#ifndef _LINUX_PRINTK_H
>  >  +#define _LINUX_PRINTK_H
>  >  +
>  >  +#define        KERN_EMERG      "<0>"   /* system is unusable                   */
>  >  +#define        KERN_ALERT      "<1>"   /* action must be taken immediately     */
>  >  +#define        KERN_CRIT       "<2>"   /* critical conditions                  */
>  >  +#define        KERN_ERR        "<3>"   /* error conditions                     */
>  >  +#define        KERN_WARNING    "<4>"   /* warning conditions                   */
>  >  +#define        KERN_NOTICE     "<5>"   /* normal but significant condition     */
>  >  +#define        KERN_INFO       "<6>"   /* informational                        */
>  >  +#define        KERN_DEBUG      "<7>"   /* debug-level messages                 */
>  >  +
>  >  +/*
>  >  + * Annotation for a "continued" line of log printout (only done after a
>  >  + * line that had no enclosing \n). Only to be used by core/arch code
>  >  + * during early bootup (a continued line is not SMP-safe otherwise).
>  >  + */
>  >  +#define        KERN_CONT       ""
>  >  +
>  >  +extern int console_printk[];
>  >  +
>  >  +#define console_loglevel (console_printk[0])
>  >  +#define default_message_loglevel (console_printk[1])
>  >  +#define minimum_console_loglevel (console_printk[2])
>  >  +#define default_console_loglevel (console_printk[3])
>  >  +
>  >  +#ifdef CONFIG_PRINTK
>  >  +asmlinkage int vprintk(const char *fmt, va_list args)
>  >  +       __attribute__ ((format (printf, 1, 0)));
>  >  +asmlinkage int printk(const char *fmt, ...)
>  >  +       __attribute__ ((format (printf, 1, 2))) __cold;
>  >  +extern int log_buf_get_len(void);
>  >
>  > +extern int log_buf_read(int idx);
>  >  +extern int log_buf_copy(char *dest, int idx, int len);
>  >  +
>  >  +extern int printk_ratelimit_jiffies;
>  >  +extern int printk_ratelimit_burst;
>  >  +extern int printk_ratelimit(void);
>  >
>  > +extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  >  +extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
>  >  +extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
>  >  +                                  unsigned int interval_msec);
>  >  +#else
>  >  +static inline int __attribute__ ((format (printf, 1, 0)))
>  >  +vprintk(const char *s, va_list args)
>  >  +{
>  >  +       return 0;
>  >  +}
>  >  +static inline int __attribute__ ((format (printf, 1, 2))) __cold
>  >  +printk(const char *s, ...)
>  >  +{
>  >  +       return 0;
>  >  +}
>  >  +static inline int log_buf_get_len(void)
>  >  +{
>  >  +       return 0;
>  >  +}
>  >  +static inline int log_buf_read(int idx)
>  >
>  > +{
>  >  +       return 0;
>  >  +}
>  >  +static inline int log_buf_copy(char *dest, int idx, int len)
>  >  +{
>  >  +       return 0;
>  >  +}
>  >  +static inline int printk_ratelimit(void)
>  >  +{
>  >  +       return 0;
>  >  +}
>  >  +static inline int __printk_ratelimit(int ratelimit_jiffies,
>  >  +                                    int ratelimit_burst)
>  >  +{
>  >  +       return 0;
>  >  +}
>  >  +static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
>  >  +                                         unsigned int interval_msec)
>  >  +{
>  >  +       return false;
>  >  +}
>  >  +#endif
>  >  +
>  >  +extern void __attribute__((format(printf, 1, 2)))
>  >  +       early_printk(const char *fmt, ...);
>  >  +
>  >  +static inline void console_silent(void)
>  >  +{
>  >  +       console_loglevel = 0;
>  >  +}
>  >  +
>  >  +static inline void console_verbose(void)
>  >  +{
>  >  +       if (console_loglevel)
>  >  +               console_loglevel = 15;
>  >  +}
>  >  +
>  >  +extern void dump_stack(void) __cold;
>  >  +
>  >  +enum {
>  >  +       DUMP_PREFIX_NONE,
>  >  +       DUMP_PREFIX_ADDRESS,
>  >  +       DUMP_PREFIX_OFFSET
>  >  +};
>  >  +extern void hex_dump_to_buffer(const void *buf, size_t len,
>  >  +                              int rowsize, int groupsize,
>  >  +                              char *linebuf, size_t linebuflen, bool ascii);
>  >  +extern void print_hex_dump(const char *level, const char *prefix_str,
>  >  +                          int prefix_type, int rowsize, int groupsize,
>  >  +                          const void *buf, size_t len, bool ascii);
>  >  +extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
>  >  +                                const void *buf, size_t len);
>  >  +#define hex_asc(x)     "0123456789abcdef"[x]
>  >  +
>  >  +#define pr_emerg(fmt, arg...) \
>  >  +       printk(KERN_EMERG fmt, ##arg)
>  >  +#define pr_alert(fmt, arg...) \
>  >  +       printk(KERN_ALERT fmt, ##arg)
>  >  +#define pr_crit(fmt, arg...) \
>  >  +       printk(KERN_CRIT fmt, ##arg)
>  >  +#define pr_err(fmt, arg...) \
>  >  +       printk(KERN_ERR fmt, ##arg)
>  >  +#define pr_warning(fmt, arg...) \
>  >  +       printk(KERN_WARNING fmt, ##arg)
>  >  +#define pr_notice(fmt, arg...) \
>  >  +       printk(KERN_NOTICE fmt, ##arg)
>  >  +#define pr_info(fmt, arg...) \
>  >  +       printk(KERN_INFO fmt, ##arg)
>  >  +
>  >  +#ifdef DEBUG
>  >  +/* If you are writing a driver, please use dev_dbg instead */
>  >  +#define pr_debug(fmt, arg...) \
>  >  +       printk(KERN_DEBUG fmt, ##arg)
>  >  +#else
>  >  +#define pr_debug(fmt, arg...) \
>  >  +       ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
>  >  +#endif
>  >  +
>  >  +#endif
>  >
>  >
>  >
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-05  2:58       ` Dave Young
@ 2008-05-05  2:52         ` Joe Perches
  2008-05-05  5:18           ` Dave Young
  0 siblings, 1 reply; 11+ messages in thread
From: Joe Perches @ 2008-05-05  2:52 UTC (permalink / raw)
  To: Dave Young; +Cc: akpm, paulmck, netdev, linux-kernel

On Mon, 2008-05-05 at 10:58 +0800, Dave Young wrote:
> On Mon, May 5, 2008 at 10:25 AM, Joe Perches <joe@perches.com> wrote:
> > On Mon, 2008-05-05 at 09:37 +0800, Dave Young wrote:
> >  > >  I think your changes should then be done in
> >  > >  printk.h not creating a new ratelimit.h.
> >  > IMO ratelimit is not just for printk use now, so a standalone head
> >  > file is necessary.
> >  What other uses would ratelimit have?
> ratelimit is a general function,  another user of it is
> WARN_ON_RATELIMIT in this patch. It could have other usage in future.

You put WARN_ON_RATELIMIT in bug.h right?
WARN_ON in bug.h is a printk

printk.h should #include <asm/bug.h>
kernel.h should not include that file.

What non print related function could be served by ratelimit?




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-05  2:25     ` Joe Perches
@ 2008-05-05  2:58       ` Dave Young
  2008-05-05  2:52         ` Joe Perches
  0 siblings, 1 reply; 11+ messages in thread
From: Dave Young @ 2008-05-05  2:58 UTC (permalink / raw)
  To: Joe Perches; +Cc: akpm, paulmck, netdev, linux-kernel

On Mon, May 5, 2008 at 10:25 AM, Joe Perches <joe@perches.com> wrote:
> On Mon, 2008-05-05 at 09:37 +0800, Dave Young wrote:
>  > >  I think your changes should then be done in
>  > >  printk.h not creating a new ratelimit.h.
>  >
>  > IMO ratelimit is not just for printk use now, so a standalone head
>  > file is necessary.
>
>  What other uses would ratelimit have?

ratelimit is a general function,  another user of it is
WARN_ON_RATELIMIT in this patch. It could have other usage in future.

>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-05  2:52         ` Joe Perches
@ 2008-05-05  5:18           ` Dave Young
  2008-05-05  5:20             ` David Miller
  0 siblings, 1 reply; 11+ messages in thread
From: Dave Young @ 2008-05-05  5:18 UTC (permalink / raw)
  To: Joe Perches; +Cc: akpm, paulmck, netdev, linux-kernel, David Miller

On Mon, May 5, 2008 at 10:52 AM, Joe Perches <joe@perches.com> wrote:
>
> On Mon, 2008-05-05 at 10:58 +0800, Dave Young wrote:
>  > On Mon, May 5, 2008 at 10:25 AM, Joe Perches <joe@perches.com> wrote:
>  > > On Mon, 2008-05-05 at 09:37 +0800, Dave Young wrote:
>  > >  > >  I think your changes should then be done in
>  > >  > >  printk.h not creating a new ratelimit.h.
>  > >  > IMO ratelimit is not just for printk use now, so a standalone head
>  > >  > file is necessary.
>  > >  What other uses would ratelimit have?
>  > ratelimit is a general function,  another user of it is
>  > WARN_ON_RATELIMIT in this patch. It could have other usage in future.
>
>  You put WARN_ON_RATELIMIT in bug.h right?
>  WARN_ON in bug.h is a printk

Yes, warn is indeed printk, but it's not equal to printk.

>
>  printk.h should #include <asm/bug.h>
>  kernel.h should not include that file.
>
>  What non print related function could be served by ratelimit?

You can do some other handling except printk in ratelimit logic.

After searching the code, I guess DCCP-Sync ratelimit can use this feature.
David, am I right?

BTW, most of printk_ratelimit users should use their own
ratelimit_state, maybe I should do the replace work as a patch series.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH -mm] __ratelimit rewrite
  2008-05-05  5:18           ` Dave Young
@ 2008-05-05  5:20             ` David Miller
  0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2008-05-05  5:20 UTC (permalink / raw)
  To: hidave.darkstar; +Cc: joe, akpm, paulmck, netdev, linux-kernel

From: "Dave Young" <hidave.darkstar@gmail.com>
Date: Mon, 5 May 2008 13:18:30 +0800

> After searching the code, I guess DCCP-Sync ratelimit can use this feature.
> David, am I right?

I'm not familiar with the DCCP-Sync code, sorry.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-05-05  5:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-04  7:07 [PATCH -mm] __ratelimit rewrite Dave Young
2008-05-04  7:54 ` David Miller
2008-05-04  8:13   ` Dave Young
2008-05-04 14:47 ` Joe Perches
2008-05-05  1:37   ` Dave Young
2008-05-05  2:25     ` Joe Perches
2008-05-05  2:58       ` Dave Young
2008-05-05  2:52         ` Joe Perches
2008-05-05  5:18           ` Dave Young
2008-05-05  5:20             ` David Miller
2008-05-05  2:27     ` Dave Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).