Kent Overstreet <koverstr...@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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to