[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 2/4] xen/console: correct leaky-bucket rate limiter
- To: xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: dmukhin@xxxxxxxx
- Date: Wed, 15 Jul 2026 13:19:00 -0700
- 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=5LPXre7WHxzRpNUWwTfqR7IVxEsybrZ0r9yBOHRPlAY=; b=ftZEIC8xwwoetHlDII521WnqszepaEhmuo0OtmE/7CEex/HVRNHzfmGeOTVl1+ayF8r5bkFz+q+xGaMqcipQzd26pOZlofnzFyBq6MdnAiVJjE63Mcr8ZCz3ZgMskVTC9tpooHyfs8yfeHzLZ5bhVNegwf/Hrubrgafj/Om52rMqcWbnMv1J82TYrqd0hrIS/KX44wHac16/2X8WSwqCJy+g/jaHK5Sq70eu7YgkuHzjEIGf13fb8JA+AU9/oqt0Eaf/5J20eApPC4fTsrFyXmcJn2WQ+lg9GCwkUzMqGl46u77D46GkATbVpwI/bdeFw5hWgjCcBudf3PCDbESL8A==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iN0/RhDXiYZKkHFqFCQvshTZIggLuXNE+2CTczydI2lXAVxk10NzHVvx2xYZRZJ7OajAjLOlCoag33f0JWpgK3+9mITUMGRm0TfMIMaKvRdv9dC6dxGyAMnxD4DWh+AAa74nNlSDQeKtCIHe5ED+qx8Y+u+X7K7HsQgJwv6REwrVaQGGXIweyjI0F6pn9WQp26Ot9wthFNP8sgAcj9MnL1VESZq4fGGcB9Efkn835cIApeotOf/EF51eDm5FoYEokCSa0PWWdxo4GXhNBp6nJ0qVE2QZGyLXNAqdM4M2skuRv4IsK+lXTDvT0e/rt0HEXz+dpvtOdjfYAIFyOW44jg==
- 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.pau@xxxxxxxxxx, sstabellini@xxxxxxxxxx, dmukhin@xxxxxxxx
- Delivery-date: Wed, 15 Jul 2026 20:19:42 +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 v2:
- fixed typing and 32-bit integer overflow problem
---
xen/drivers/char/console.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 5d395f882e08..de9f2432445d 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -1274,21 +1274,26 @@ 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 last_msg;
+ static unsigned long long toks, last_msg;
static unsigned int missed;
+ unsigned long long now, limit;
unsigned long flags;
- unsigned long long now = NOW(); /* ns */
- unsigned long ms;
+ s_time_t ms;
- do_div(now, 1000000);
- ms = (unsigned long)now;
+ if ( !ratelimit_burst || !ratelimit_burst )
+ return true;
+
+ limit = min(ratelimit_burst * ratelimit_ms, UINT_MAX);
+ if ( !toks )
+ toks = limit;
+
+ now = NOW(); /* ns */
+ ms = do_div(now, MILLISECS(1));
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, limit);
if ( toks >= ratelimit_ms )
{
unsigned int lost = missed;
--
2.54.0
|