summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/bihash_template.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-04-21 19:42:30 +0200
committerDamjan Marion <dmarion@me.com>2020-04-22 08:45:29 +0000
commit801ec2a080d9414b3fab80906333bdb94b5d4043 (patch)
treed6434fcfaa0d11097f1a5d53d859ab4123018ddd /src/vppinfra/bihash_template.h
parent7f83738b46e6e0dd17c7a23392ceaaef686ac08a (diff)
vppinfra: improve bihash add/del performance
Measured improvement is from 439 to 167 clocks for add operation in 16_8 case... Type: improvement Change-Id: I975ff46ff30b983a3ec80a5cde25ccb68d7fa03b Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/bihash_template.h')
-rw-r--r--src/vppinfra/bihash_template.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h
index 13a348fbcf4..b8e0a239013 100644
--- a/src/vppinfra/bihash_template.h
+++ b/src/vppinfra/bihash_template.h
@@ -262,23 +262,25 @@ static inline void BV (clib_bihash_lock_bucket) (BVT (clib_bihash_bucket) * b)
{
BVT (clib_bihash_bucket) unlocked_bucket, locked_bucket;
- do
+ locked_bucket.as_u64 = unlocked_bucket.as_u64 = b->as_u64;
+ unlocked_bucket.lock = 0;
+ locked_bucket.lock = 1;
+
+ while (__atomic_compare_exchange_n (&b->as_u64, &unlocked_bucket.as_u64,
+ locked_bucket.as_u64, 1 /* weak */ ,
+ __ATOMIC_ACQUIRE,
+ __ATOMIC_ACQUIRE) == 0)
{
+ CLIB_PAUSE ();
locked_bucket.as_u64 = unlocked_bucket.as_u64 = b->as_u64;
unlocked_bucket.lock = 0;
locked_bucket.lock = 1;
- CLIB_PAUSE ();
}
- while (__atomic_compare_exchange_n (&b->as_u64, &unlocked_bucket.as_u64,
- locked_bucket.as_u64, 1 /* weak */ ,
- __ATOMIC_ACQUIRE,
- __ATOMIC_ACQUIRE) == 0);
}
static inline void BV (clib_bihash_unlock_bucket)
(BVT (clib_bihash_bucket) * b)
{
- CLIB_MEMORY_BARRIER ();
b->lock = 0;
}