1 From 8c5cc4ccdeb3bfbd0fb93dff2ac8afd49cb1f839 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/773] hwmon: raspberrypi: Prevent voltage low warnings from
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.
13 Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
14 Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
16 drivers/hwmon/raspberrypi-hwmon.c | 41 ++++++++++++++++++++++++++++---
17 1 file changed, 37 insertions(+), 4 deletions(-)
19 --- a/drivers/hwmon/raspberrypi-hwmon.c
20 +++ b/drivers/hwmon/raspberrypi-hwmon.c
22 #include <linux/workqueue.h>
23 #include <soc/bcm2835/raspberrypi-firmware.h>
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.
32 +#define LOCAL_RATELIMIT_INTERVAL (5 * 60 * HZ)
33 +#define LOCAL_RATELIMIT_BURST 3
36 +#define printk_ratelimited_local(fmt, ...) \
38 + static DEFINE_RATELIMIT_STATE(_rs, \
39 + LOCAL_RATELIMIT_INTERVAL, \
40 + LOCAL_RATELIMIT_BURST); \
42 + if (__ratelimit(&_rs)) \
43 + printk(fmt, ##__VA_ARGS__); \
46 +#define printk_ratelimited_local(fmt, ...) \
47 + no_printk(fmt, ##__VA_ARGS__)
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__)
55 #define UNDERVOLTAGE_STICKY_BIT BIT(16)
57 struct rpi_hwmon_data {
58 @@ -47,10 +77,13 @@ static void rpi_firmware_get_throttled(s
63 - dev_crit(data->hwmon_dev, "Undervoltage detected!\n");
65 - dev_info(data->hwmon_dev, "Voltage normalised\n");
67 + pr_crit_ratelimited_local("Under-voltage detected! (0x%08x)\n",
70 + pr_info_ratelimited_local("Voltage normalised (0x%08x)\n",
74 sysfs_notify(&data->hwmon_dev->kobj, NULL, "in0_lcrit_alarm");