Skip to content

Commit d2cf662

Browse files
James Hughespelwell
James Hughes
authored andcommitted
Prevent voltage low warnings from filling log
Although the correct fix for low voltage warnings is to improve the power supply, the current implementation of the detection can fill the log if the warning happens freqently. This replaces the logging with slightly custom ratelimited logging. Signed-off-by: James Hughes <[email protected]>
1 parent 2a9ef94 commit d2cf662

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

drivers/firmware/raspberrypi.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,38 @@
2424

2525
#define UNDERVOLTAGE_BIT BIT(0)
2626

27+
28+
/*
29+
* This section defines some rate limited logging that prevent
30+
* repeated messages at much lower Hz than the default kernel settings.
31+
* It's usually 5s, this is 5 minutes.
32+
* Burst 3 means you may get three messages 'quickly', before
33+
* the ratelimiting kicks in.
34+
*/
35+
#define LOCAL_RATELIMIT_INTERVAL (5 * 60 * HZ)
36+
#define LOCAL_RATELIMIT_BURST 3
37+
38+
#ifdef CONFIG_PRINTK
39+
#define printk_ratelimited_local(fmt, ...) \
40+
({ \
41+
static DEFINE_RATELIMIT_STATE(_rs, \
42+
LOCAL_RATELIMIT_INTERVAL, \
43+
LOCAL_RATELIMIT_BURST); \
44+
\
45+
if (__ratelimit(&_rs)) \
46+
printk(fmt, ##__VA_ARGS__); \
47+
})
48+
#else
49+
#define printk_ratelimited_local(fmt, ...) \
50+
no_printk(fmt, ##__VA_ARGS__)
51+
#endif
52+
53+
#define pr_crit_ratelimited_local(fmt, ...) \
54+
printk_ratelimited_local(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
55+
#define pr_info_ratelimited_local(fmt, ...) \
56+
printk_ratelimited_local(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
57+
58+
2759
struct rpi_firmware {
2860
struct mbox_client cl;
2961
struct mbox_chan *chan; /* The property channel. */
@@ -216,9 +248,13 @@ static int rpi_firmware_get_throttled(struct rpi_firmware *fw, u32 *value)
216248

217249
if (new_uv != old_uv) {
218250
if (new_uv)
219-
pr_crit("Under-voltage detected! (0x%08x)\n", *value);
251+
pr_crit_ratelimited_local(
252+
"Under-voltage detected! (0x%08x)\n",
253+
*value);
220254
else
221-
pr_info("Voltage normalised (0x%08x)\n", *value);
255+
pr_info_ratelimited_local(
256+
"Voltage normalised (0x%08x)\n",
257+
*value);
222258
}
223259

224260
sysfs_notify(&fw->cl.dev->kobj, NULL, "get_throttled");

0 commit comments

Comments
 (0)