History

printk: Make linux/printk.h self-contained

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.

Herbert Xu committed 6 years ago

Commit b4a461e1 parent bc885f14 files · +46 −36Browse files

Showing the changes to include/linux (3 of 4 files). Show all

Unified · Split

3 files
  1. include/linux/printk.h +1 −0
  2. include/linux/ratelimit.h +1 −35
  3. include/linux/ratelimit_types.h +43 −0
include/linux/printk.h+1−0
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 #include <linux/kern_levels.h>
88 #include <linux/linkage.h>
99 #include <linux/cache.h>
10+#include <linux/ratelimit_types.h>
1011
1112 extern const char linux_banner[];
1213 extern const char linux_proc_banner[];
include/linux/ratelimit.h+1−35
@@ -2,41 +2,10 @@ · 1 unmodified line
22 #ifndef _LINUX_RATELIMIT_H
33 #define _LINUX_RATELIMIT_H
44
5−#include <linux/param.h>
5+#include <linux/ratelimit_types.h>
66 #include <linux/sched.h>
77 #include <linux/spinlock.h>
88
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−
409 static inline void ratelimit_state_init(struct ratelimit_state *rs,
4110 int interval, int burst)
4211 {
@@ -73,9 +42,6 @@ ratelimit_set_flags(struct ratelimit_state *rs, unsigned long flags) · 30 unmodified lines
7342
7443 extern struct ratelimit_state printk_ratelimit_state;
7544
76−extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
77−#define __ratelimit(state) ___ratelimit(state, __func__)
78−
7945 #ifdef CONFIG_PRINTK
8046
8147 #define WARN_ON_RATELIMIT(condition, state) ({ \
include/linux/ratelimit_types.h+43−0
@@ -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 */