brcm2708: add kernel 4.14 support
[openwrt/staging/lynxis.git] / target / linux / brcm2708 / patches-4.14 / 950-0278-Prevent-voltage-low-warnings-from-filling-log.patch
1 From cecce8a9e798fbe8571381b6f9f69fd7a0defa37 Mon Sep 17 00:00:00 2001
2 From: James Hughes <james.hughes@raspberrypi.org>
3 Date: Wed, 18 Apr 2018 13:02:57 +0100
4 Subject: [PATCH 278/454] Prevent voltage low warnings from filling log
5
6 Although the correct fix for low voltage warnings is to
7 improve the power supply, the current implementation
8 of the detection can fill the log if the warning
9 happens freqently. This replaces the logging with
10 slightly custom ratelimited logging.
11
12 Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
13 ---
14 drivers/firmware/raspberrypi.c | 40 ++++++++++++++++++++++++++++++++--
15 1 file changed, 38 insertions(+), 2 deletions(-)
16
17 --- a/drivers/firmware/raspberrypi.c
18 +++ b/drivers/firmware/raspberrypi.c
19 @@ -24,6 +24,38 @@
20
21 #define UNDERVOLTAGE_BIT BIT(0)
22
23 +
24 +/*
25 + * This section defines some rate limited logging that prevent
26 + * repeated messages at much lower Hz than the default kernel settings.
27 + * It's usually 5s, this is 5 minutes.
28 + * Burst 3 means you may get three messages 'quickly', before
29 + * the ratelimiting kicks in.
30 + */
31 +#define LOCAL_RATELIMIT_INTERVAL (5 * 60 * HZ)
32 +#define LOCAL_RATELIMIT_BURST 3
33 +
34 +#ifdef CONFIG_PRINTK
35 +#define printk_ratelimited_local(fmt, ...) \
36 +({ \
37 + static DEFINE_RATELIMIT_STATE(_rs, \
38 + LOCAL_RATELIMIT_INTERVAL, \
39 + LOCAL_RATELIMIT_BURST); \
40 + \
41 + if (__ratelimit(&_rs)) \
42 + printk(fmt, ##__VA_ARGS__); \
43 +})
44 +#else
45 +#define printk_ratelimited_local(fmt, ...) \
46 + no_printk(fmt, ##__VA_ARGS__)
47 +#endif
48 +
49 +#define pr_crit_ratelimited_local(fmt, ...) \
50 + printk_ratelimited_local(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
51 +#define pr_info_ratelimited_local(fmt, ...) \
52 + printk_ratelimited_local(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
53 +
54 +
55 struct rpi_firmware {
56 struct mbox_client cl;
57 struct mbox_chan *chan; /* The property channel. */
58 @@ -216,9 +248,13 @@ static int rpi_firmware_get_throttled(st
59
60 if (new_uv != old_uv) {
61 if (new_uv)
62 - pr_crit("Under-voltage detected! (0x%08x)\n", *value);
63 + pr_crit_ratelimited_local(
64 + "Under-voltage detected! (0x%08x)\n",
65 + *value);
66 else
67 - pr_info("Voltage normalised (0x%08x)\n", *value);
68 + pr_info_ratelimited_local(
69 + "Voltage normalised (0x%08x)\n",
70 + *value);
71 }
72
73 sysfs_notify(&fw->cl.dev->kobj, NULL, "get_throttled");