fe75cb5edc1dd3b270feecaa22f45fa039693a80
[openwrt/staging/nbd.git] /
1 From 0952d9da1123bb3046db0d9f8a316729ed3a0212 Mon Sep 17 00:00:00 2001
2 From: Stefan Wahren <stefan.wahren@i2se.com>
3 Date: Sat, 6 Oct 2018 16:46:18 +0200
4 Subject: [PATCH 146/782] hwmon: raspberrypi: Prevent voltage low warnings from
5 filling log
6
7 Although the correct fix for low voltage warnings is to
8 improve the power supply, the current implementation
9 of the detection can fill the log if the warning
10 happens freqently. This replaces the logging with
11 slightly custom ratelimited logging.
12
13 Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
14 Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
15 ---
16 drivers/hwmon/raspberrypi-hwmon.c | 41 ++++++++++++++++++++++++++++---
17 1 file changed, 37 insertions(+), 4 deletions(-)
18
19 --- a/drivers/hwmon/raspberrypi-hwmon.c
20 +++ b/drivers/hwmon/raspberrypi-hwmon.c
21 @@ -15,6 +15,36 @@
22 #include <linux/workqueue.h>
23 #include <soc/bcm2835/raspberrypi-firmware.h>
24
25 +/*
26 + * This section defines some rate limited logging that prevent
27 + * repeated messages at much lower Hz than the default kernel settings.
28 + * It's usually 5s, this is 5 minutes.
29 + * Burst 3 means you may get three messages 'quickly', before
30 + * the ratelimiting kicks in.
31 + */
32 +#define LOCAL_RATELIMIT_INTERVAL (5 * 60 * HZ)
33 +#define LOCAL_RATELIMIT_BURST 3
34 +
35 +#ifdef CONFIG_PRINTK
36 +#define printk_ratelimited_local(fmt, ...) \
37 +({ \
38 + static DEFINE_RATELIMIT_STATE(_rs, \
39 + LOCAL_RATELIMIT_INTERVAL, \
40 + LOCAL_RATELIMIT_BURST); \
41 + \
42 + if (__ratelimit(&_rs)) \
43 + printk(fmt, ##__VA_ARGS__); \
44 +})
45 +#else
46 +#define printk_ratelimited_local(fmt, ...) \
47 + no_printk(fmt, ##__VA_ARGS__)
48 +#endif
49 +
50 +#define pr_crit_ratelimited_local(fmt, ...) \
51 + printk_ratelimited_local(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
52 +#define pr_info_ratelimited_local(fmt, ...) \
53 +printk_ratelimited_local(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
54 +
55 #define UNDERVOLTAGE_STICKY_BIT BIT(16)
56
57 struct rpi_hwmon_data {
58 @@ -47,10 +77,13 @@ static void rpi_firmware_get_throttled(s
59 if (new_uv == old_uv)
60 return;
61
62 - if (new_uv)
63 - dev_crit(data->hwmon_dev, "Undervoltage detected!\n");
64 - else
65 - dev_info(data->hwmon_dev, "Voltage normalised\n");
66 + if (new_uv) {
67 + pr_crit_ratelimited_local("Under-voltage detected! (0x%08x)\n",
68 + value);
69 + } else {
70 + pr_info_ratelimited_local("Voltage normalised (0x%08x)\n",
71 + value);
72 + }
73
74 sysfs_notify(&data->hwmon_dev->kobj, NULL, "in0_lcrit_alarm");
75 }