vppinfra: conformed spinlocks to use CLIB_PAUSE 56/20856/2
authorjaszha03 <jason.zhang2@arm.com>
Wed, 12 Jun 2019 21:01:19 +0000 (16:01 -0500)
committerDave Barach <openvpp@barachs.net>
Tue, 30 Jul 2019 11:46:19 +0000 (11:46 +0000)
Modified test-and-set spin locks to call CLIB_PAUSE () when spinning
for code consistency. Decreases the memory bandwidth consumed.

Type: fix

Change-Id: I1cca4f87f44f23f257c7a35466cd2e7767072f51
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>
src/plugins/map/map.h
src/svm/ssvm.h
src/vnet/classify/vnet_classify.c
src/vnet/dns/dns.h
src/vppinfra/elog.c
src/vppinfra/mheap.c

index abafb4e..d96c7b8 100644 (file)
@@ -22,6 +22,7 @@
 #include <vnet/adj/adj.h>
 #include <vnet/dpo/load_balance.h>
 #include "lpm.h"
+#include <vppinfra/lock.h>
 
 #define MAP_SKIP_IP6_LOOKUP 1
 
@@ -501,7 +502,7 @@ map_ip4_reass_get(u32 src, u32 dst, u16 fragment_id,
 void
 map_ip4_reass_free(map_ip4_reass_t *r, u32 **pi_to_drop);
 
-#define map_ip4_reass_lock() while (clib_atomic_test_and_set (map_main.ip4_reass_lock)) {}
+#define map_ip4_reass_lock() while (clib_atomic_test_and_set (map_main.ip4_reass_lock)) { CLIB_PAUSE (); }
 #define map_ip4_reass_unlock() do {CLIB_MEMORY_BARRIER(); *map_main.ip4_reass_lock = 0;} while(0)
 
 static_always_inline void
@@ -526,7 +527,7 @@ map_ip6_reass_get(ip6_address_t *src, ip6_address_t *dst, u32 fragment_id,
 void
 map_ip6_reass_free(map_ip6_reass_t *r, u32 **pi_to_drop);
 
-#define map_ip6_reass_lock() while (clib_atomic_test_and_set (map_main.ip6_reass_lock)) {}
+#define map_ip6_reass_lock() while (clib_atomic_test_and_set (map_main.ip6_reass_lock)) { CLIB_PAUSE (); }
 #define map_ip6_reass_unlock() do {CLIB_MEMORY_BARRIER(); *map_main.ip6_reass_lock = 0;} while(0)
 
 int
index 1c0373f..6c67945 100644 (file)
@@ -37,6 +37,7 @@
 #include <vppinfra/heap.h>
 #include <vppinfra/pool.h>
 #include <vppinfra/format.h>
+#include <vppinfra/lock.h>
 
 #ifndef MMAP_PAGESIZE
 #define MMAP_PAGESIZE (clib_mem_get_page_size())
@@ -104,7 +105,7 @@ ssvm_lock (ssvm_shared_header_t * h, u32 my_pid, u32 tag)
     }
 
   while (clib_atomic_test_and_set (&h->lock))
-    ;
+    CLIB_PAUSE ();
 
   h->owner_pid = my_pid;
   h->recursion_count = 1;
@@ -115,7 +116,7 @@ always_inline void
 ssvm_lock_non_recursive (ssvm_shared_header_t * h, u32 tag)
 {
   while (clib_atomic_test_and_set (&h->lock))
-    ;
+    CLIB_PAUSE ();
 
   h->tag = tag;
 }
index 90086f0..64549a6 100755 (executable)
@@ -18,6 +18,7 @@
 #include <vnet/api_errno.h>    /* for API error numbers */
 #include <vnet/l2/l2_classify.h>       /* for L2_INPUT_CLASSIFY_NEXT_xxx */
 #include <vnet/fib/fib_table.h>
+#include <vppinfra/lock.h>
 
 vnet_classify_main_t vnet_classify_main;
 
@@ -447,7 +448,7 @@ vnet_classify_add_del (vnet_classify_table_t * t,
   hash >>= t->log2_nbuckets;
 
   while (clib_atomic_test_and_set (t->writer_lock))
-    ;
+    CLIB_PAUSE ();
 
   /* First elt in the bucket? */
   if (b->offset == 0)
index b2e3e9b..19de69c 100644 (file)
@@ -23,6 +23,7 @@
 #include <vppinfra/hash.h>
 #include <vnet/dns/dns_packet.h>
 #include <vnet/ip/ip.h>
+#include <vppinfra/lock.h>
 
 typedef struct
 {
@@ -196,7 +197,7 @@ dns_cache_lock (dns_main_t * dm)
   if (dm->cache_lock)
     {
       while (clib_atomic_test_and_set (dm->cache_lock))
-       ;
+       CLIB_PAUSE ();
     }
 }
 
index 12ac3a5..489ccf4 100644 (file)
 #include <vppinfra/format.h>
 #include <vppinfra/hash.h>
 #include <vppinfra/math.h>
+#include <vppinfra/lock.h>
 
 static inline void
 elog_lock (elog_main_t * em)
 {
   if (PREDICT_FALSE (em->lock != 0))
     while (clib_atomic_test_and_set (em->lock))
-      ;
+      CLIB_PAUSE ();
 }
 
 static inline void
index ba5bbc9..2769838 100644 (file)
@@ -41,6 +41,7 @@
 #include <vppinfra/mheap.h>
 #include <vppinfra/os.h>
 #include <vppinfra/time.h>
+#include <vppinfra/lock.h>
 
 #ifdef CLIB_UNIX
 #include <vppinfra/elf_clib.h>
@@ -64,7 +65,7 @@ mheap_maybe_lock (void *v)
        }
 
       while (clib_atomic_test_and_set (&h->lock))
-       ;
+       CLIB_PAUSE ();
 
       h->owner_cpu = my_cpu;
       h->recursion_count = 1;