Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 717115e1 authored by Dave Young's avatar Dave Young Committed by Linus Torvalds
Browse files

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: default avatarDave 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2711b793
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -97,6 +97,9 @@ extern void warn_slowpath(const char *file, const int line,
	unlikely(__ret_warn_once);				\
})

#define WARN_ON_RATELIMIT(condition, state)			\
		WARN_ON((condition) && __ratelimit(state))

#ifdef CONFIG_SMP
# define WARN_ON_SMP(x)			WARN_ON(x)
#else
+2 −6
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <linux/bitops.h>
#include <linux/log2.h>
#include <linux/typecheck.h>
#include <linux/ratelimit.h>
#include <asm/byteorder.h>
#include <asm/bug.h>

@@ -189,11 +190,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
asmlinkage int printk(const char * fmt, ...)
	__attribute__ ((format (printf, 1, 2))) __cold;

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
@@ -204,8 +202,6 @@ 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 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; }
+1 −2
Original line number Diff line number Diff line
@@ -351,8 +351,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__ */
+27 −0
Original line number Diff line number Diff line
#ifndef _LINUX_RATELIMIT_H
#define _LINUX_RATELIMIT_H
#include <linux/param.h>

#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
#define DEFAULT_RATELIMIT_BURST 10

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 DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
					DEFAULT_RATELIMIT_BURST);
	return __ratelimit(&rs);
}
#endif
+7 −2
Original line number Diff line number Diff line
@@ -115,16 +115,21 @@ DECLARE_PER_CPU(struct rcu_dyntick_sched, 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(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1);
	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);

	smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
	__get_cpu_var(rcu_dyntick_sched).dynticks++;
	WARN_ON(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1));
	WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1),
				&rs);
}

#else /* CONFIG_NO_HZ */
Loading