aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/kernel.h2
-rw-r--r--kernel/printk.c21
2 files changed, 23 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 80f39cab470a..24b611147adb 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -171,6 +171,8 @@ __attribute_const__ roundup_pow_of_two(unsigned long x)
171 171
172extern int printk_ratelimit(void); 172extern int printk_ratelimit(void);
173extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst); 173extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
174extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
175 unsigned int interval_msec);
174 176
175static inline void console_silent(void) 177static inline void console_silent(void)
176{ 178{
diff --git a/kernel/printk.c b/kernel/printk.c
index f7d427ef5038..66426552fbfe 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -31,6 +31,7 @@
31#include <linux/security.h> 31#include <linux/security.h>
32#include <linux/bootmem.h> 32#include <linux/bootmem.h>
33#include <linux/syscalls.h> 33#include <linux/syscalls.h>
34#include <linux/jiffies.h>
34 35
35#include <asm/uaccess.h> 36#include <asm/uaccess.h>
36 37
@@ -1101,3 +1102,23 @@ int printk_ratelimit(void)
1101 printk_ratelimit_burst); 1102 printk_ratelimit_burst);
1102} 1103}
1103EXPORT_SYMBOL(printk_ratelimit); 1104EXPORT_SYMBOL(printk_ratelimit);
1105
1106/**
1107 * printk_timed_ratelimit - caller-controlled printk ratelimiting
1108 * @caller_jiffies: pointer to caller's state
1109 * @interval_msecs: minimum interval between prints
1110 *
1111 * printk_timed_ratelimit() returns true if more than @interval_msecs
1112 * milliseconds have elapsed since the last time printk_timed_ratelimit()
1113 * returned true.
1114 */
1115bool printk_timed_ratelimit(unsigned long *caller_jiffies,
1116 unsigned int interval_msecs)
1117{
1118 if (*caller_jiffies == 0 || time_after(jiffies, *caller_jiffies)) {
1119 *caller_jiffies = jiffies + msecs_to_jiffies(interval_msecs);
1120 return true;
1121 }
1122 return false;
1123}
1124EXPORT_SYMBOL(printk_timed_ratelimit);