aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk.c
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2006-11-03 01:07:16 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-11-03 15:27:58 -0500
commitf46c483357c2d87606bbefb511321e3efd4baae0 (patch)
treee3276379337a56353cce051d8f7efbc87dc61fdb /kernel/printk.c
parent7f6b8876c7e66b0d15af134e2a5b87e55514eb6d (diff)
[PATCH] Add printk_timed_ratelimit()
printk_ratelimit() has global state which makes it not useful for callers which wish to perform ratelimiting at a particular frequency. Add a printk_timed_ratelimit() which utilises caller-provided state storage to permit more flexibility. This function can in fact be used for things other than printk ratelimiting and is perhaps poorly named. Cc: Ulrich Drepper <drepper@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/printk.c')
-rw-r--r--kernel/printk.c21
1 files changed, 21 insertions, 0 deletions
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);