[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] xen/console: re-calibrate rate-limiter based on compile-time options



commit 73d23cc1f0d7bbe1b7bcf197220ba8f12d83cac8
Author:     Denis Mukhin <dmukhin@xxxxxxxx>
AuthorDate: Tue Nov 17 10:03:17 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Nov 17 10:03:17 2026 +0100

    xen/console: re-calibrate rate-limiter based on compile-time options
    
    Current printk_ratelimit() relies on hardcoded values 5000 and 10
    respectively to program leaky-bucket message limiting. Now that there's
    compile-time rate-limiting settings, the algorithm needs adjustment.
    
    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.
    
    Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
    Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 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 1a8beb6665..e2310b9d3c 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -1286,21 +1286,35 @@ 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 int toks = UINT_MAX;
     static unsigned long last_msg;
     static unsigned int missed;
+    unsigned int limit;
+    unsigned int 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;
+
+    if ( __builtin_umul_overflow(ratelimit_burst, ratelimit_ms, &limit) )
+        limit = UINT_MAX;
+
+    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;
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.