lkml.org 
[lkml]   [2018]   [Jul]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCHv2] lib/ratelimit: Lockless ratelimiting
From
Date
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

\
 
 \ /
  Last update: 2018-07-03 23:00    [W:0.058 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site