diff options
author | jaszha03 <jason.zhang2@arm.com> | 2019-06-12 16:01:19 -0500 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2019-07-30 16:22:03 +0000 |
commit | f25e7cfa5c615e1972d5823b65ca579f951d68a5 (patch) | |
tree | 47c4e91b45710d861081d1933e2e8cbe3f56fe42 /src/vppinfra | |
parent | 6b03ab73116a7746f9480ea00c3924dcecb2799f (diff) |
vppinfra: refactor use of CLIB_MEMORY_BARRIER ()
All instances of test_and_set locks used the following sequence
to release the locks:
CLIB_MEMORY_BARRIER ();
p->lock = 0; // p is a generic struct with a TAS lock
Use clib_atomic_release to generate more efficient assembly code.
Type: refactor
Change-Id: Idca3a38b1cf43578108bdd1afe83b6ebc17a4c68
Signed-off-by: Jason Zhang <jason.zhang2@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Lijian Zhang <Lijian.Zhang@arm.com>
Diffstat (limited to 'src/vppinfra')
-rw-r--r-- | src/vppinfra/elog.c | 3 | ||||
-rw-r--r-- | src/vppinfra/lock.h | 19 | ||||
-rw-r--r-- | src/vppinfra/mheap.c | 3 |
3 files changed, 8 insertions, 17 deletions
diff --git a/src/vppinfra/elog.c b/src/vppinfra/elog.c index 489ccf436d9..caddf6f3757 100644 --- a/src/vppinfra/elog.c +++ b/src/vppinfra/elog.c @@ -56,8 +56,7 @@ elog_unlock (elog_main_t * em) { if (PREDICT_FALSE (em->lock != 0)) { - CLIB_MEMORY_BARRIER (); - *em->lock = 0; + clib_atomic_release (em->lock); } } diff --git a/src/vppinfra/lock.h b/src/vppinfra/lock.h index 337c5a3f0ad..59ab0e33c51 100644 --- a/src/vppinfra/lock.h +++ b/src/vppinfra/lock.h @@ -89,9 +89,8 @@ static_always_inline void clib_spinlock_unlock (clib_spinlock_t * p) { CLIB_LOCK_DBG_CLEAR (p); - /* Make sure all writes are complete before releasing the lock */ - CLIB_MEMORY_BARRIER (); - (*p)->lock = 0; + /* Make sure all reads/writes are complete before releasing the lock */ + clib_atomic_release (&(*p)->lock); } static_always_inline void @@ -147,9 +146,7 @@ clib_rwlock_reader_lock (clib_rwlock_t * p) while (clib_atomic_test_and_set (&(*p)->writer_lock)) CLIB_PAUSE (); } - CLIB_MEMORY_BARRIER (); - (*p)->n_readers_lock = 0; - + clib_atomic_release (&(*p)->n_readers_lock); CLIB_LOCK_DBG (p); } @@ -165,12 +162,9 @@ clib_rwlock_reader_unlock (clib_rwlock_t * p) (*p)->n_readers -= 1; if ((*p)->n_readers == 0) { - CLIB_MEMORY_BARRIER (); - (*p)->writer_lock = 0; + clib_atomic_release (&(*p)->writer_lock); } - - CLIB_MEMORY_BARRIER (); - (*p)->n_readers_lock = 0; + clib_atomic_release (&(*p)->n_readers_lock); } always_inline void @@ -185,8 +179,7 @@ always_inline void clib_rwlock_writer_unlock (clib_rwlock_t * p) { CLIB_LOCK_DBG_CLEAR (p); - CLIB_MEMORY_BARRIER (); - (*p)->writer_lock = 0; + clib_atomic_release (&(*p)->writer_lock); } #endif diff --git a/src/vppinfra/mheap.c b/src/vppinfra/mheap.c index 2769838d4ba..b5566bd6389 100644 --- a/src/vppinfra/mheap.c +++ b/src/vppinfra/mheap.c @@ -82,8 +82,7 @@ mheap_maybe_unlock (void *v) if (--h->recursion_count == 0) { h->owner_cpu = ~0; - CLIB_MEMORY_BARRIER (); - h->lock = 0; + clib_atomic_release (&h->lock); } } } |