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

Unified · Split

4 files
  1. arch/s390/include/asm/bug.h +1 −1
  2. include/linux/printk.h +1 −0
  3. include/linux/ratelimit.h +1 −35
  4. include/linux/ratelimit_types.h +43 −0
arch/s390/include/asm/bug.h+1−1
@@ -2,7 +2,7 @@ · 1 unmodified line
2#ifndef _ASM_S390_BUG_H2#ifndef _ASM_S390_BUG_H
3#define _ASM_S390_BUG_H3#define _ASM_S390_BUG_H
4 4
5#include <linux/kernel.h>5#include <linux/compiler.h>
6 6
7#ifdef CONFIG_BUG7#ifdef CONFIG_BUG
8 8
include/linux/printk.h+1−0
@@ -7,6 +7,7 @@ · 6 unmodified lines
7#include <linux/kern_levels.h>7#include <linux/kern_levels.h>
8#include <linux/linkage.h>8#include <linux/linkage.h>
9#include <linux/cache.h>9#include <linux/cache.h>
10#include <linux/ratelimit_types.h>
10 11
11extern const char linux_banner[];12extern const char linux_banner[];
12extern const char linux_proc_banner[];13extern const char linux_proc_banner[];
include/linux/ratelimit.h+1−35
@@ -2,41 +2,10 @@ · 1 unmodified line
2#ifndef _LINUX_RATELIMIT_H2#ifndef _LINUX_RATELIMIT_H
3#define _LINUX_RATELIMIT_H3#define _LINUX_RATELIMIT_H
4 4
5#include <linux/param.h>5#include <linux/ratelimit_types.h>
6#include <linux/sched.h>6#include <linux/sched.h>
7#include <linux/spinlock.h>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
15struct 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
40static inline void ratelimit_state_init(struct ratelimit_state *rs,9static inline void ratelimit_state_init(struct ratelimit_state *rs,
41 int interval, int burst)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
74extern struct ratelimit_state printk_ratelimit_state;43extern struct ratelimit_state printk_ratelimit_state;
75 44
76extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
77#define __ratelimit(state) ___ratelimit(state, __func__)
78
79#ifdef CONFIG_PRINTK45#ifdef CONFIG_PRINTK
80 46
81#define WARN_ON_RATELIMIT(condition, state) ({ \47#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
15struct 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
40extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
41#define __ratelimit(state) ___ratelimit(state, __func__)
42
43#endif /* _LINUX_RATELIMIT_TYPES_H */