aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDave Young <hidave.darkstar@gmail.com>2008-07-25 04:45:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-25 13:53:29 -0400
commit717115e1a5856b57af0f71e1df7149108294fc10 (patch)
tree9528a992245c2fb993a0cf0bc8221dc7dea5d259 /include
parent2711b793eb62a5873a0ba583a69252040aef176e (diff)
printk ratelimiting rewrite
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. - rewrite __ratelimit, and use a ratelimit_state as parameter. Thanks for hints from andrew. - Add WARN_ON_RATELIMIT, update rcupreempt.h - remove __printk_ratelimit - use __ratelimit in net_ratelimit Signed-off-by: Dave Young <hidave.darkstar@gmail.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: "Paul E. McKenney" <paulmck@us.ibm.com> Cc: Dave Young <hidave.darkstar@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/asm-generic/bug.h3
-rw-r--r--include/linux/kernel.h8
-rw-r--r--include/linux/net.h3
-rw-r--r--include/linux/ratelimit.h27
-rw-r--r--include/linux/rcupreempt.h9
5 files changed, 40 insertions, 10 deletions
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index a346e744e770..a3f738cffdb6 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -97,6 +97,9 @@ extern void warn_slowpath(const char *file, const int line,
97 unlikely(__ret_warn_once); \ 97 unlikely(__ret_warn_once); \
98}) 98})
99 99
100#define WARN_ON_RATELIMIT(condition, state) \
101 WARN_ON((condition) && __ratelimit(state))
102
100#ifdef CONFIG_SMP 103#ifdef CONFIG_SMP
101# define WARN_ON_SMP(x) WARN_ON(x) 104# define WARN_ON_SMP(x) WARN_ON(x)
102#else 105#else
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 5c4b1251e110..fdbbf72ca2eb 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -15,6 +15,7 @@
15#include <linux/bitops.h> 15#include <linux/bitops.h>
16#include <linux/log2.h> 16#include <linux/log2.h>
17#include <linux/typecheck.h> 17#include <linux/typecheck.h>
18#include <linux/ratelimit.h>
18#include <asm/byteorder.h> 19#include <asm/byteorder.h>
19#include <asm/bug.h> 20#include <asm/bug.h>
20 21
@@ -189,11 +190,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
189asmlinkage int printk(const char * fmt, ...) 190asmlinkage int printk(const char * fmt, ...)
190 __attribute__ ((format (printf, 1, 2))) __cold; 191 __attribute__ ((format (printf, 1, 2))) __cold;
191 192
192extern int printk_ratelimit_jiffies; 193extern struct ratelimit_state printk_ratelimit_state;
193extern int printk_ratelimit_burst;
194extern int printk_ratelimit(void); 194extern int printk_ratelimit(void);
195extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst);
196extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
197extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, 195extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
198 unsigned int interval_msec); 196 unsigned int interval_msec);
199#else 197#else
@@ -204,8 +202,6 @@ static inline int printk(const char *s, ...)
204 __attribute__ ((format (printf, 1, 2))); 202 __attribute__ ((format (printf, 1, 2)));
205static inline int __cold printk(const char *s, ...) { return 0; } 203static inline int __cold printk(const char *s, ...) { return 0; }
206static inline int printk_ratelimit(void) { return 0; } 204static inline int printk_ratelimit(void) { return 0; }
207static inline int __printk_ratelimit(int ratelimit_jiffies, \
208 int ratelimit_burst) { return 0; }
209static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ 205static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
210 unsigned int interval_msec) \ 206 unsigned int interval_msec) \
211 { return false; } 207 { return false; }
diff --git a/include/linux/net.h b/include/linux/net.h
index 2f999fbb188d..4a9a30f2d68f 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -351,8 +351,7 @@ static const struct proto_ops name##_ops = { \
351 351
352#ifdef CONFIG_SYSCTL 352#ifdef CONFIG_SYSCTL
353#include <linux/sysctl.h> 353#include <linux/sysctl.h>
354extern int net_msg_cost; 354extern struct ratelimit_state net_ratelimit_state;
355extern int net_msg_burst;
356#endif 355#endif
357 356
358#endif /* __KERNEL__ */ 357#endif /* __KERNEL__ */
diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
new file mode 100644
index 000000000000..18a5b9ba9d40
--- /dev/null
+++ b/include/linux/ratelimit.h
@@ -0,0 +1,27 @@
1#ifndef _LINUX_RATELIMIT_H
2#define _LINUX_RATELIMIT_H
3#include <linux/param.h>
4
5#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
6#define DEFAULT_RATELIMIT_BURST 10
7
8struct ratelimit_state {
9 int interval;
10 int burst;
11 int printed;
12 int missed;
13 unsigned long begin;
14};
15
16#define DEFINE_RATELIMIT_STATE(name, interval, burst) \
17 struct ratelimit_state name = {interval, burst,}
18
19extern int __ratelimit(struct ratelimit_state *rs);
20
21static inline int ratelimit(void)
22{
23 static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
24 DEFAULT_RATELIMIT_BURST);
25 return __ratelimit(&rs);
26}
27#endif
diff --git a/include/linux/rcupreempt.h b/include/linux/rcupreempt.h
index f04b64eca636..0967f03b0705 100644
--- a/include/linux/rcupreempt.h
+++ b/include/linux/rcupreempt.h
@@ -115,16 +115,21 @@ DECLARE_PER_CPU(struct rcu_dyntick_sched, rcu_dyntick_sched);
115 115
116static inline void rcu_enter_nohz(void) 116static inline void rcu_enter_nohz(void)
117{ 117{
118 static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
119
118 smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ 120 smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
119 __get_cpu_var(rcu_dyntick_sched).dynticks++; 121 __get_cpu_var(rcu_dyntick_sched).dynticks++;
120 WARN_ON(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1); 122 WARN_ON_RATELIMIT(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, &rs);
121} 123}
122 124
123static inline void rcu_exit_nohz(void) 125static inline void rcu_exit_nohz(void)
124{ 126{
127 static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
128
125 smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ 129 smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
126 __get_cpu_var(rcu_dyntick_sched).dynticks++; 130 __get_cpu_var(rcu_dyntick_sched).dynticks++;
127 WARN_ON(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1)); 131 WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1),
132 &rs);
128} 133}
129 134
130#else /* CONFIG_NO_HZ */ 135#else /* CONFIG_NO_HZ */