[ovs-dev] [PATCH 00/18] Use relaxed atomic operations when possible.
jrajahalme at nicira.com
Fri Aug 22 20:58:11 UTC 2014
The default memory order for atomic operations is
memory_order_seq_cst, which synchronizes the whole system, i.e., locks
the memory bus, which is very expensive. memory_order_relaxed, on the
other hand, does not impose any kind of memory barrier (not even a
compiler barrier), which allows for better code optimization. The
cost of atomic access itself remains: an atomic access always causes a
memory system access (which usually is cached).
In general, the relaxed memory order can be used when the atomic
operation is not expected to synchronize the state of any other
(atomic or non-atomic) variable. Simple counters usually fall into
this category. However, reference counters may provide
synchronization when the last reference is released. Also, if an
atomic variable is used to signal state of initialization of some
state, relaxed memory order can not be used, so that the atomic store
signaling the completion of the initialization is not reordered to
take place before the initialization is complete.
This series of patches first does some fixes, then provides a slightly
simplified syntax for relaxed atomic operations, and adds a simple
atomic_count abstraction. Later patches go through all existing
non-explicit atomic operations and changes them to use relaxed
semantics when possible.
The changes are done in small patches to aid the review: I hope it is
easier to focus on the semantics of each atomic variable this way.
Also, if there is a problem not cought in the review, it may be easier
to find the problem if the commits are not squashed into one big one.
Jarno Rajahalme (18):
lib/ovs-atomic: Add missing macro argument parentheses.
lib/ovs-atomic: Clarified comments on ovs_refcount_unref().
lib/ovs-atomic: Add helpers for relaxed atomic access.
lib/ovs-atomic: Add atomic_count.
lib: Use shorter form of relaxed atomic access.
lib/ovs-thread: Use atomic_count.
lib/ovs-thread: Avoid atomic read in ovsthread_once_start().
lib/jsonrpc, lib/ofp-msgs, lib/ofp-parse: Use atomic_count.
lib/bfd: Used relaxed atomics and optimize bfd_should_process_flow().
lib/cfm: Use relaxed atomics and optimize cfm_should_process_flow().
lib/dpif-linux: Use relaxed atomics for 'dump->status'.
lib/netdev: Do not use atomics when not needed.
lib/netdev-dummy: Use relaxed atomics for a trivial counter.
lib/netdev-linux: Use atomic_count for 'miimon_cnt'.
ofproto/netflow: Use atomic_count for 'netflow_count'.
ofproto/ofproto-dpif-upcall: Use relaxed atomic operations.
lib/timeval: Use relaxed atomics also when writing on 'slow_path'.
ofproto/ofproto: Use relaxed atomics.
lib/bfd.c | 47 +++++++++++---------
lib/cfm.c | 42 +++++++++++++-----
lib/dpif-linux.c | 7 +--
lib/dpif-netdev.c | 4 +-
lib/jsonrpc.c | 4 +-
lib/netdev-dummy.c | 4 +-
lib/netdev-linux.c | 21 ++++-----
lib/netdev.c | 24 +++++-----
lib/ofp-msgs.c | 6 +--
lib/ofp-parse.c | 4 +-
lib/ovs-atomic-gcc4+.h | 8 ++--
lib/ovs-atomic-i586.h | 32 +++++++-------
lib/ovs-atomic-x86_64.h | 14 +++---
lib/ovs-atomic.h | 98 +++++++++++++++++++++++++++++++++++++++--
lib/ovs-thread.c | 21 ++++++---
lib/ovs-thread.h | 11 +++--
lib/timeval.c | 6 +--
ofproto/netflow.c | 19 ++++----
ofproto/ofproto-dpif-upcall.c | 42 ++++++++++--------
ofproto/ofproto-dpif.c | 10 +++--
ofproto/ofproto.c | 12 ++---
21 files changed, 282 insertions(+), 154 deletions(-)
More information about the dev