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

[xen staging] console: make printk_ratelimit_{burst,ms} const



commit 3d79573f0251b432e03bcb03c382c28446065b5d
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Wed Aug 6 14:48:02 2025 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Aug 6 14:48:02 2025 +0200

    console: make printk_ratelimit_{burst,ms} const
    
    Them not being altered by any means, their __read_mostly attribute is
    actually counter-productive: It causes the compiler to instantiate the
    variables, when already with just the attributes dropped the compiler
    can constant-propagate the values into the sole use site. Make the
    situation yet more explicit by adding const.
    
    Also switch the variables away from being plain int, and have the
    parameters of __printk_ratelimit() follow suit. While there also
    similarly adjust the type of "missed" and "lost", and - while touching
    the adjacent line - increase lost_str[] to accommodate any unsigned
    32-bit number.
    
    Fixes: a8b1845a7845 ("Miscellaneous data placement adjustments")
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Denis Mukhin <dmukhin@xxxxxxxx>
    Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
 xen/drivers/char/console.c | 20 +++++++++++---------
 xen/include/xen/lib.h      |  3 ++-
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index a5af660239..9bd5b4825d 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -1267,12 +1267,12 @@ void console_end_sync(void)
  * This enforces a rate limit: not more than one kernel message
  * every printk_ratelimit_ms (millisecs).
  */
-int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst)
+int __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 int missed;
+    static unsigned int missed;
     unsigned long flags;
     unsigned long long now = NOW(); /* ns */
     unsigned long ms;
@@ -1287,14 +1287,16 @@ int __printk_ratelimit(int ratelimit_ms, int 
ratelimit_burst)
         toks = ratelimit_burst * ratelimit_ms;
     if ( toks >= ratelimit_ms )
     {
-        int lost = missed;
+        unsigned int lost = missed;
+
         missed = 0;
         toks -= ratelimit_ms;
         spin_unlock(&ratelimit_lock);
         if ( lost )
         {
-            char lost_str[8];
-            snprintf(lost_str, sizeof(lost_str), "%d", lost);
+            char lost_str[10];
+
+            snprintf(lost_str, sizeof(lost_str), "%u", lost);
             /* console_lock may already be acquired by printk(). */
             rspin_lock(&console_lock);
             printk_start_of_line(CONSOLE_PREFIX);
@@ -1311,11 +1313,11 @@ int __printk_ratelimit(int ratelimit_ms, int 
ratelimit_burst)
     return 0;
 }
 
-/* minimum time in ms between messages */
-static int __read_mostly printk_ratelimit_ms = 5 * 1000;
+/* Minimum time in ms between messages */
+static const unsigned int printk_ratelimit_ms = 5 * 1000;
 
-/* number of messages we send before ratelimiting */
-static int __read_mostly printk_ratelimit_burst = 10;
+/* Number of messages we send before ratelimiting */
+static const unsigned int printk_ratelimit_burst = 10;
 
 int printk_ratelimit(void)
 {
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 36d904ba1a..c434dd5f16 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -79,7 +79,8 @@ extern void guest_printk(const struct domain *d, const char 
*fmt, ...)
     __attribute__ ((format (printf, 2, 3)));
 extern void noreturn panic(const char *fmt, ...)
     __attribute__ ((format (printf, 1, 2)));
-extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
+extern int __printk_ratelimit(unsigned int ratelimit_ms,
+                              unsigned int ratelimit_burst);
 extern int printk_ratelimit(void);
 
 #define gprintk(lvl, fmt, args...) \
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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