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

[PATCH v2 5/7] xen/console: correct leaky-bucket rate limiter


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: dmukhin@xxxxxxxx
  • Date: Fri, 6 Feb 2026 12:24:22 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 148.163.138.245) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=ford.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ford.com; dkim=pass (signature was verified) header.d=saarlouis.ford.com; dkim=pass (signature was verified) header.d=ford.com; arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ua9UEn7fZ+IMjj0dFXJV6pVmJk5FwzdwF5Yb/oZBC3U=; b=w7at9vRpzdJImxf1xXCuVDdnao26A0Tdyij7pyUTPgoFczZDs9HcxO7YjK5MHWHioil+Sev+Sn+lvbxHdv9cV7/vI7qQD5gGOI5kwfswiWb2Z6suuoDF4acUsbZwW5FUU0CrouD8+e7taLMlB5Y2yaSc3EwzUXoAMB1yfgJzK9SQBTQnJGtEzzmitLGal36oneIg45euRDVbe7x4kkhLN01Yjpspp3HFkTO2ZrVjvlM2XfpIKFMjUhYWmZrfOeH4gZP2FmhRHgjxdxvAkOuPexuidCq62lxEBSo34h1lveJCx2JaCIG2ZgEKEDTPQ4VImWxBMEMzW7974z5RbJLrfw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k0Y+EuevjmOHL4FxYqqxsKvJYw6OnHVBNpdnfxN4x0TWjPdGuMAOJ29Q04iVwYJuh0QqP4PouWY84fuP25yFomiocEYBCuOTc3H4LnJfFNuDW9CqS+01piOofksU6v+IGLhf7ZNUu7LqzjFvW5JpCbXeBlJK1xDjVP2J5J3XLsHfdR5poDBkvONYrliO5AjkCZFPHUIlqIFrWGPWSefq+8OhzN3Ta91GGSedfBlXwfud061MjHU428+Tf1ONShvdEzv5hlJaTezfY1f4SdFZkooiCTUQfiNBbTrlitKo5ZDiFZeUI+ZMRToY/MlArMPWecvUauKogR1M3yfCn0V1Xw==
  • Cc: andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, julien@xxxxxxx, michal.orzel@xxxxxxx, roger.pau@xxxxxxxxxx, sstabellini@xxxxxxxxxx, dmukhin@xxxxxxxx
  • Delivery-date: Fri, 06 Feb 2026 20:24:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Pser-m365-app: SER-APP

From: Denis Mukhin <dmukhin@xxxxxxxx> 

Use existing printk_ratelimit_ms and printk_ratelimit_burst variables in
do_printk_ratelimit() instead of hardcoded values 5000 and 10 respectively.

Ensure rate limiter is disabled if either printk_ratelimit_ms or
printk_ratelimit_burst is 0. Make sure no unnecessary initialization is done
in the corner case.

Also, simplify the limiter code by using min().

Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
Changes since v1:
- new patch
---
 xen/drivers/char/console.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index f607e8f84d7a..e3962512d282 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -1291,21 +1291,27 @@ static bool do_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;
     static unsigned long last_msg;
     static unsigned int missed;
     unsigned long flags;
-    unsigned long long now = NOW(); /* ns */
+    unsigned long long now;
     unsigned long ms;
 
+    if ( !printk_ratelimit_burst || !printk_ratelimit_burst )
+        return true;
+
+    if ( !toks )
+        toks = printk_ratelimit_burst * printk_ratelimit_ms;
+
+    now = NOW(); /* ns */
     do_div(now, 1000000);
     ms = (unsigned long)now;
 
     spin_lock_irqsave(&ratelimit_lock, flags);
     toks += ms - last_msg;
     last_msg = ms;
-    if ( toks > (ratelimit_burst * ratelimit_ms))
-        toks = ratelimit_burst * ratelimit_ms;
+    toks = min(toks, (unsigned long)(ratelimit_burst * ratelimit_ms));
     if ( toks >= ratelimit_ms )
     {
         unsigned int lost = missed;
-- 
2.52.0




 


Rackspace

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