|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v5 1/2] xen/console: re-calibrate rate-limiter based on user input
From: Denis Mukhin <dmukhin@xxxxxxxx>
Current __printk_ratelimit() relies on hardcoded values 5000 and 10
respectively to program leaky-bucket message limiting.
Use 'ratelimit_ms' and 'ratelimit_burst' variables to re-calibrate
limiter.
Ensure rate limiter is disabled if either 'ratelimit_ms' or
'ratelimit_burst' is 0.
Fixes: 26cf03554a75 ("[XEN] Implement rate-limited logging.")
Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
Changes since v4:
- dropped 'initialized' flag
- updated commit message, including Fixes tag
---
xen/drivers/char/console.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index ea4e3ff34178..56bf111ef181 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -33,6 +33,7 @@
#include <asm/setup.h>
#include <xen/sections.h>
#include <xen/consoled.h>
+#include <xen/xvmalloc.h>
#ifdef CONFIG_X86
#include <asm/guest.h>
@@ -1286,21 +1287,34 @@ bool __printk_ratelimit(unsigned int ratelimit_ms,
unsigned int ratelimit_burst)
{
static DEFINE_SPINLOCK(ratelimit_lock);
- static unsigned long toks = 10 * 5 * 1000;
+ static unsigned long toks = ~0;
static unsigned long last_msg;
static unsigned int missed;
+ unsigned long limit;
+ unsigned long elapsed;
unsigned long flags;
- unsigned long long now = NOW(); /* ns */
unsigned long ms;
+ s_time_t now;
- do_div(now, 1000000);
- ms = (unsigned long)now;
+ if ( !ratelimit_ms || !ratelimit_burst )
+ return true;
+
+ limit = DIM_MUL2(ratelimit_burst, ratelimit_ms);
+
+ now = NOW(); /* ns */
+ do_div(now, MILLISECS(1));
+ ms = now;
spin_lock_irqsave(&ratelimit_lock, flags);
- toks += ms - last_msg;
+
+ elapsed = ms - last_msg;
+ if ( toks >= limit || elapsed >= limit - toks )
+ toks = limit;
+ else
+ toks += elapsed;
+
last_msg = ms;
- if ( toks > (ratelimit_burst * ratelimit_ms))
- toks = ratelimit_burst * ratelimit_ms;
+
if ( toks >= ratelimit_ms )
{
unsigned int lost = missed;
--
2.54.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |