[PATCHv2] lib/ratelimit: Lockless ratelimiting
Dmitry Safonov
dima at arista.com
Tue Jul 3 20:59:14 UTC 2018
On Tue, 2018-06-26 at 21:41 +0300, Andy Shevchenko wrote:
> > > > @@ -42,9 +41,10 @@ static inline void
> > > > ratelimit_state_init(struct
> > > > ratelimit_state *rs,
> > > > {
> > > > memset(rs, 0, sizeof(*rs));
> > > >
> > > > - raw_spin_lock_init(&rs->lock);
> > > > rs->interval = interval;
> > > > rs->burst = burst;
> > > > + atomic_set(&rs->printed, 0);
> > > > + atomic_set(&rs->missed, 0);
> > >
> > > Can it be
> > >
> > > *rs = RATELIMIT_STATE_INIT(interval, burst);
> > >
> > > ?
> > >
> > > (Yes, the '(struct ratelimit_state)' has to be added to macro to
> > > allow this)
> >
> > Sure.
>
> This part, by the way, potentially can be split into preparatory
> patch. Please, double check if it possible to do this way.
Hmm, I tried this way:
:#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) ({ \
: struct ratelimit_state name = { \
: .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
: .interval = interval_init, \
: .burst = burst_init, \
: }; \
: name; \
: })
but the expression becomes non-constant, so it fails to compile in
definitions of globals.
I think I'll change it to
struct ratelimit_state tmp = RATELIMIT_STATE_INIT(...);
*rs = tmp;
Not perfect, but we did memset() and set elements after, so it's kinda
the same.
--
Thanks,
Dmitry
More information about the dri-devel
mailing list