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

[PATCH v2 6/7] xen/console: use s_time_t for time accounting in do_printk_ratelimit()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: dmukhin@xxxxxxxx
  • Date: Fri, 6 Feb 2026 12:24:23 -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=91uvrCfmE9p9OckTdvelbOLI6FReGTxP9EGg8jerJOM=; b=x3MRFUR7ldCqQoqGY6zMcFT2qzYpKQoYYJwpZg+mC8yRac8LNXt1rGbuCot8dw8d1cyKkyi/kemZkkmkHS0KLWE6zUnYaB/MSTy/dy/au3YXpaSuCY2qZKByIBAyCgSssFxN5eGvuya8dvG37lXNFJcF0MpJ+HYHOqDxE9wicJMESCe6VPchen8yzxoLEkn76e5bmDyLanDRA2MQG9UKoSg16y4RqAxGDC33c02kRi9jAhYlhI6lfa2R+Rosb/t/F0Nxeu0p2s7FNBAjP2KerENTByf375zildnoz1+FwjNjalm/9cqshB9efNNkfC9OZVML7z/UjE6BGromlKvcvw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p2ifvxee0qkO0LQ/SYqMzf/VexVVtz0LtQ3AyikPi5t3TFl8gDNnHVnll8gJ0sthZQKTl9bguZLVzy66DCkM30L+Ms3bG9otL8xRLfZjlzB4GNADNKcbch6j3UbfqLDZgzoUfln1r/ME2WahpobhSZ01ko+T+x60h8o4WccA4d1iWTpnd1GGh256njoxnDOgW8OF9saj+WwI0Xkh2DHwiGyQaglDRCeo7kJaR0AII1fhzm/ZiA6T5Q4l7dTZLlTiuSAQ1lPIlLP8Ilj5bCsnvQXbIgFTGuHM+LwpYhPKZNWVW3R9NfNB+yi2V2n87TfckwspD1FiA+AbttnzNc5lTQ==
  • 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 appropriate s_time_t for time window calculation in the rate limiting
algorithm.

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

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index e3962512d282..536b883d5dcf 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -1291,12 +1291,10 @@ static bool do_printk_ratelimit(unsigned int 
ratelimit_ms,
                                 unsigned int ratelimit_burst)
 {
     static DEFINE_SPINLOCK(ratelimit_lock);
-    static unsigned long toks;
-    static unsigned long last_msg;
+    static s_time_t toks, last_msg;
+    s_time_t now, ms;
     static unsigned int missed;
     unsigned long flags;
-    unsigned long long now;
-    unsigned long ms;
 
     if ( !printk_ratelimit_burst || !printk_ratelimit_burst )
         return true;
@@ -1305,13 +1303,12 @@ static bool do_printk_ratelimit(unsigned int 
ratelimit_ms,
         toks = printk_ratelimit_burst * printk_ratelimit_ms;
 
     now = NOW(); /* ns */
-    do_div(now, 1000000);
-    ms = (unsigned long)now;
+    ms = do_div(now, MILLISECS(1));
 
     spin_lock_irqsave(&ratelimit_lock, flags);
     toks += ms - last_msg;
     last_msg = ms;
-    toks = min(toks, (unsigned long)(ratelimit_burst * ratelimit_ms));
+    toks = min(toks, (s_time_t)(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®.