As it stands if you include printk.h by itself it will fail to compile because it requires definitions from ratelimit.h. However, simply including ratelimit.h from printk.h does not work due to inclusion loops involving sched.h and kernel.h. This patch solves this by moving bits from ratelimit.h into a new header file which can then be included by printk.h without any worries about header loops. The build bot then revealed some intriguing failures arising out of this patch. On s390 there is an inclusion loop with asm/bug.h and linux/kernel.h that triggers a compile failure, because kernel.h will cause asm-generic/bug.h to be included before s390's own asm/bug.h has finished processing. This has been fixed by not including kernel.h in arch/s390/include/asm/bug.h.
Showing the changes to include/linux (3 of 4 files). Show all
Unified · Split
| @@ -7,6 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | #include <linux/kern_levels.h> |
| 8 | 8 | #include <linux/linkage.h> |
| 9 | 9 | #include <linux/cache.h> |
| 10 | +#include <linux/ratelimit_types.h> | |
| 10 | 11 | |
| 11 | 12 | extern const char linux_banner[]; |
| 12 | 13 | extern const char linux_proc_banner[]; |
| @@ -2,41 +2,10 @@ · 1 unmodified line | ||
| 2 | 2 | #ifndef _LINUX_RATELIMIT_H |
| 3 | 3 | #define _LINUX_RATELIMIT_H |
| 4 | 4 | |
| 5 | −#include <linux/param.h> | |
| 5 | +#include <linux/ratelimit_types.h> | |
| 6 | 6 | #include <linux/sched.h> |
| 7 | 7 | #include <linux/spinlock.h> |
| 8 | 8 | |
| 9 | −#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) | |
| 10 | −#define DEFAULT_RATELIMIT_BURST 10 | |
| 11 | − | |
| 12 | −/* issue num suppressed message on exit */ | |
| 13 | −#define RATELIMIT_MSG_ON_RELEASE BIT(0) | |
| 14 | − | |
| 15 | −struct ratelimit_state { | |
| 16 | − raw_spinlock_t lock; /* protect the state */ | |
| 17 | − | |
| 18 | − int interval; | |
| 19 | − int burst; | |
| 20 | − int printed; | |
| 21 | − int missed; | |
| 22 | − unsigned long begin; | |
| 23 | − unsigned long flags; | |
| 24 | −}; | |
| 25 | − | |
| 26 | −#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \ | |
| 27 | − .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \ | |
| 28 | − .interval = interval_init, \ | |
| 29 | − .burst = burst_init, \ | |
| 30 | − } | |
| 31 | − | |
| 32 | −#define RATELIMIT_STATE_INIT_DISABLED \ | |
| 33 | − RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST) | |
| 34 | − | |
| 35 | −#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \ | |
| 36 | − \ | |
| 37 | − struct ratelimit_state name = \ | |
| 38 | − RATELIMIT_STATE_INIT(name, interval_init, burst_init) \ | |
| 39 | − | |
| 40 | 9 | static inline void ratelimit_state_init(struct ratelimit_state *rs, |
| 41 | 10 | int interval, int burst) |
| 42 | 11 | { |
| @@ -73,9 +42,6 @@ ratelimit_set_flags(struct ratelimit_state *rs, unsigned long flags) · 30 unmodified lines | ||
| 73 | 42 | |
| 74 | 43 | extern struct ratelimit_state printk_ratelimit_state; |
| 75 | 44 | |
| 76 | −extern int ___ratelimit(struct ratelimit_state *rs, const char *func); | |
| 77 | −#define __ratelimit(state) ___ratelimit(state, __func__) | |
| 78 | − | |
| 79 | 45 | #ifdef CONFIG_PRINTK |
| 80 | 46 | |
| 81 | 47 | #define WARN_ON_RATELIMIT(condition, state) ({ \ |
| @@ -0,0 +1,43 @@ | ||
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
| 2 | +#ifndef _LINUX_RATELIMIT_TYPES_H | |
| 3 | +#define _LINUX_RATELIMIT_TYPES_H | |
| 4 | + | |
| 5 | +#include <linux/bits.h> | |
| 6 | +#include <linux/param.h> | |
| 7 | +#include <linux/spinlock_types.h> | |
| 8 | + | |
| 9 | +#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) | |
| 10 | +#define DEFAULT_RATELIMIT_BURST 10 | |
| 11 | + | |
| 12 | +/* issue num suppressed message on exit */ | |
| 13 | +#define RATELIMIT_MSG_ON_RELEASE BIT(0) | |
| 14 | + | |
| 15 | +struct ratelimit_state { | |
| 16 | + raw_spinlock_t lock; /* protect the state */ | |
| 17 | + | |
| 18 | + int interval; | |
| 19 | + int burst; | |
| 20 | + int printed; | |
| 21 | + int missed; | |
| 22 | + unsigned long begin; | |
| 23 | + unsigned long flags; | |
| 24 | +}; | |
| 25 | + | |
| 26 | +#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \ | |
| 27 | + .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \ | |
| 28 | + .interval = interval_init, \ | |
| 29 | + .burst = burst_init, \ | |
| 30 | + } | |
| 31 | + | |
| 32 | +#define RATELIMIT_STATE_INIT_DISABLED \ | |
| 33 | + RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST) | |
| 34 | + | |
| 35 | +#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \ | |
| 36 | + \ | |
| 37 | + struct ratelimit_state name = \ | |
| 38 | + RATELIMIT_STATE_INIT(name, interval_init, burst_init) \ | |
| 39 | + | |
| 40 | +extern int ___ratelimit(struct ratelimit_state *rs, const char *func); | |
| 41 | +#define __ratelimit(state) ___ratelimit(state, __func__) | |
| 42 | + | |
| 43 | +#endif /* _LINUX_RATELIMIT_TYPES_H */ | |