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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: dmukhin@xxxxxxxx
  • Date: Thu, 12 Nov 2026 10:20:42 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 205.220.161.53) 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=cbU2Q/j6AzfoIqdHBWmymmyRc3Mf/dsqmJnX+cnrAp8=; b=u/hjAYr6nOgyWwGkN//Fnd7Znjptdb09mK71MTjvOf7pEqZZRpeJrqUPieUwILXxb74EKBNLpEbztWNJkr2aAfFG4vCRm5sYEz5iZ+sDfSM/CCgSPeNH9Db2zy4pq84LWwBhGLDenAh7X6C2t+DM41AFUhC0bCm9buFUWPT3TWc3VGLTaz9uOoFsC1ptG8Ud2ZO3+UBfsHZI7HVGz1liyc12L/X5SwyUFu25IZH5dK8uDrMh77qDGBXtiTVTKDk8yFGl+ce6u5KZTkQ0JRjYfBZEcIJJO2NXNvuNyWaAyADuku8Ql0FoLEgQtR7PcO5fsAcBP1lU935vFdByBmoBjA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dgIfxY7GCw7GOdgbCR9uDZmSObRc/LZM5AaH9vlhjcymOyUBHXzUPDc+5w7JcXffCKm2RGHoyy8Znjz85N6VrvFfr+98S/wKUg+GdBi7DrA3ODit4JOv4S76T1I9lpP///DcMfCe3aLOeZ8VIWOItbZ0oFuhRTOPI5pPGpIzrt7J+mk668Xp/iyW1ZQWXP74JUCwGvD3JdzHAzZ6pdWlbhAKrIBelXTPY4rPJuFBiMCjh0Lks/WG9WFwZV6JH6xIc9tycaSh3EoK5DC+PfTrGINPMDSx6ewINgM0FA4kMNSOpSNDty9m6x6HuUqLHiu8qGqc+RTcJW4hCuC/NSaQOw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=ppford header.d=ford.com header.i="@ford.com" header.h="Cc:Content-Transfer-Encoding:Content-Type:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"; dkim=pass header.s=selector2-azureford-onmicrosoft-com header.d=azureford.onmicrosoft.com header.i="@azureford.onmicrosoft.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=ppserprodsaar header.d=saarlouis.ford.com header.i="@saarlouis.ford.com" header.h="Cc:Content-Transfer-Encoding:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"; dkim=pass header.s=ppfserpocford header.d=ford.com header.i="@ford.com" header.h="Cc:Content-Transfer-Encoding:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"
  • Cc: andrew.cooper3@xxxxxxxxxx, anthony.perard@xxxxxxxxxx, jbeulich@xxxxxxxx, julien@xxxxxxx, michal.orzel@xxxxxxx, roger@xxxxxxxxxxxxxx, sstabellini@xxxxxxxxxx, dmukhin@xxxxxxx, Denis Mukhin <dmukhin@xxxxxxxx>
  • Delivery-date: Thu, 12 Nov 2026 18:21:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Pser-m365-app: SER-APP

From: Denis Mukhin <dmukhin@xxxxxxxx>

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>
---
Changes since v5:
- dropped "Fixes:" tag
- updated commit message
- dropped use of DIM_MUL2() in favor of open-coded __builtin_umul_overflow
- re-aligned use of integer arithmetics across 32- and 64-bit hosts
---
 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 1a8beb6665c1..e2310b9d3c9a 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;
-- 
2.56.0




 


Rackspace

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