Messages in this thread | | | From | Rusty Russell <> | Subject | Re: [PATCH] Generic percpu refcounting | Date | Wed, 05 Jun 2013 17:05:09 +0930 |
| |
Kent Overstreet <koverstreet@google.com> writes:
> This implements a refcount with similar semantics to > atomic_get()/atomic_dec_and_test() - but percpu. > > It also implements two stage shutdown, as we need it to tear down the > percpu counts. Before dropping the initial refcount, you must call > percpu_ref_kill(); this puts the refcount in "shutting down mode" and > switches back to a single atomic refcount with the appropriate barriers > (synchronize_rcu()). > > It's also legal to call percpu_ref_kill() multiple times - it only returns > true once, so callers don't have to reimplement shutdown synchronization.
> +static inline void percpu_ref_get(struct percpu_ref *ref) > +{ > + unsigned __percpu *pcpu_count; > + > + preempt_disable(); > + > + pcpu_count = ACCESS_ONCE(ref->pcpu_count); > + > + if (likely(REF_STATUS(pcpu_count) == PCPU_REF_PTR)) > + __this_cpu_inc(*pcpu_count); > + else > + atomic_inc(&ref->count); > + > + preempt_enable(); > +}
I think this should be rcu_read_lock(), which is currently equivalent but theoretically different.
Does your percpu_ref_kill() *really* need to be nonblocking? (I'd have to read your other patches which use this to be sure). Otherwise, just use synchronize_rcu(), and get rid of the release function...
Cheers, Rusty.
| |