Re: [PATCH v3 2/4] xen/console: correct leaky-bucket rate limiter
Jan Beulich <[email protected]>
| Newsgroups | org.xenproject.lists.xen-devel |
|---|---|
| Message-ID | <[email protected]> |
On 15.07.2026 22:19, [email protected] wrote: > --- 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; Along the lines of what Teddy said, I question the need to widen the variables. > 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; This is the type to use for e.g. NOW() return values; it isn't ... > - 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)); ... a type to hold a millisecond granularity value. Jan