Skip to content

Commit

Permalink
percpu-refcount: one bit is enough for REF_STATUS
Browse files Browse the repository at this point in the history
percpu-refcount currently reserves two lowest bits of its percpu
pointer to indicate its state; however, only one bit is used for
PCPU_REF_DEAD.

Simplify it by removing PCPU_STATUS_BITS/MASK and testing
PCPU_REF_DEAD directly.  This also allows the compiler to choose a
more efficient instruction depending on the architecture.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Kent Overstreet <kmo@daterainc.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
  • Loading branch information
Tejun Heo committed Jun 28, 2014
1 parent 55c6c81 commit d630dc4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions include/linux/percpu-refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ static inline void percpu_ref_kill(struct percpu_ref *ref)
return percpu_ref_kill_and_confirm(ref, NULL);
}

#define PCPU_STATUS_BITS 2
#define PCPU_STATUS_MASK ((1 << PCPU_STATUS_BITS) - 1)
#define PCPU_REF_PTR 0
#define PCPU_REF_DEAD 1

#define REF_STATUS(count) (((unsigned long) count) & PCPU_STATUS_MASK)
#define REF_STATUS(count) (((unsigned long) count) & PCPU_REF_DEAD)

/**
* percpu_ref_get - increment a percpu refcount
Expand Down
2 changes: 1 addition & 1 deletion lib/percpu-refcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void percpu_ref_kill_rcu(struct rcu_head *rcu)

/* Mask out PCPU_REF_DEAD */
pcpu_count = (unsigned __percpu *)
(((unsigned long) pcpu_count) & ~PCPU_STATUS_MASK);
(((unsigned long) pcpu_count) & ~PCPU_REF_DEAD);

for_each_possible_cpu(cpu)
count += *per_cpu_ptr(pcpu_count, cpu);
Expand Down

0 comments on commit d630dc4

Please sign in to comment.