Re: [PATCH v5 1/2] xen/console: re-calibrate rate-limiter based on user input

Jan Beulich <[email protected]>
Newsgroups org.xenproject.lists.xen-devel
Message-ID <[email protected]>
On 12.08.2026 01:38, [email protected] wrote:
> From: Denis Mukhin <[email protected]> 

First: What user input is the subject talking about?

> Current __printk_ratelimit() relies on hardcoded values 5000 and 10
> respectively to program leaky-bucket message limiting.

Which doesn't change, as ...

> Use 'ratelimit_ms' and 'ratelimit_burst' variables to re-calibrate
> limiter.

... the values of the two static variables never change.

> Ensure rate limiter is disabled if either 'ratelimit_ms' or
> 'ratelimit_burst' is 0.
> 
> Fixes: 26cf03554a75 ("[XEN] Implement rate-limited logging.")

I don't think anything is being fixed here.

> --- a/xen/drivers/char/console.c
> +++ b/xen/drivers/char/console.c
> @@ -33,6 +33,7 @@
>  #include <asm/setup.h>
>  #include <xen/sections.h>
>  #include <xen/consoled.h>
> +#include <xen/xvmalloc.h>

This shouldn't be needed, as ...

> @@ -1286,21 +1287,34 @@ 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 toks = ~0;
>      static unsigned long last_msg;
>      static unsigned int missed;
> +    unsigned long limit;
> +    unsigned long 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;
> +
> +    limit = DIM_MUL2(ratelimit_burst, ratelimit_ms);

... this helper shouldn't be (ab)used here. I further wonder whether we
really want differing behavior here for 32- and 64-bit hosts.

Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.