[ovs-dev] [PATCH v2 1/5] ovs-atomic: Use explicit memory order for ovs_refcount.
Ben Pfaff
blp at nicira.com
Mon Jul 7 16:46:05 UTC 2014
On Fri, Jul 04, 2014 at 07:21:15AM -0700, Jarno Rajahalme wrote:
> Use explicit variants of atomic operations for the ovs_refcount to
> avoid the overhead of the default memory_order_seq_cst.
>
> Adding a reference requires no memory ordering, as the calling thread
> is already assumed to have protected access to the object being
> reference counted. Hence, memory_order_relaxed is used for
> ovs_refcount_ref(). ovs_refcount_read() does not change the reference
> count, so it can also use memory_order_relaxed.
>
> Unreferencing an object needs a release barrier, so that none of the
> accesses to the protected object are reordered after the atomic
> decrement operation. Additionally, an explicit acquire barrier is
> needed before the object is recycled, to keep the subsequent accesses
> to the object's memory from being reordered before the atomic
> decrement operation.
>
> This patch follows the memory ordering and argumentation discussed
> here:
>
> http://www.chaoticmind.net/~hcb/projects/boost.atomic/doc/atomic/usage_examples.html
>
> Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
Acked-by: Ben Pfaff <blp at nicira.com>
More information about the dev
mailing list