aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-03-27 17:08:20 +0200
committerDave Barach <openvpp@barachs.net>2017-03-30 14:14:26 +0000
commit1927da29ccbe1d4cc8e59ccfa197eb41c257814f (patch)
tree226487b33921b9a45f78016d078548a6815c3431 /src/vnet
parentb18e0de1f9630fab8b3d6ffe85c7a6ee35a6fdac (diff)
vppinfra: add spinlock inline functions
Change-Id: I86089e9bb604adfc260a111685001be1c897ce53 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/devices/af_packet/af_packet.c6
-rw-r--r--src/vnet/devices/af_packet/af_packet.h4
-rw-r--r--src/vnet/devices/af_packet/device.c9
-rw-r--r--src/vnet/devices/netmap/device.c9
-rw-r--r--src/vnet/devices/netmap/netmap.c6
-rw-r--r--src/vnet/devices/netmap/netmap.h4
6 files changed, 12 insertions, 26 deletions
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index 5fdc59f2a20..2028510716e 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -229,11 +229,7 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
apif->next_rx_frame = 0;
if (tm->n_vlib_mains > 1)
- {
- apif->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
- CLIB_CACHE_LINE_BYTES);
- memset ((void *) apif->lockp, 0, CLIB_CACHE_LINE_BYTES);
- }
+ clib_spinlock_init (&apif->lockp);
{
unix_file_t template = { 0 };
diff --git a/src/vnet/devices/af_packet/af_packet.h b/src/vnet/devices/af_packet/af_packet.h
index 50ec23785ae..77a2c7a3753 100644
--- a/src/vnet/devices/af_packet/af_packet.h
+++ b/src/vnet/devices/af_packet/af_packet.h
@@ -17,10 +17,12 @@
*------------------------------------------------------------------
*/
+#include <vppinfra/lock.h>
+
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- volatile u32 *lockp;
+ clib_spinlock_t lockp;
u8 *host_if_name;
int fd;
struct tpacket_req *rx_req;
diff --git a/src/vnet/devices/af_packet/device.c b/src/vnet/devices/af_packet/device.c
index 9a94fc5e4a9..2ba3f579c00 100644
--- a/src/vnet/devices/af_packet/device.c
+++ b/src/vnet/devices/af_packet/device.c
@@ -92,11 +92,7 @@ af_packet_interface_tx (vlib_main_t * vm,
struct tpacket2_hdr *tph;
u32 frame_not_ready = 0;
- if (PREDICT_FALSE (apif->lockp != 0))
- {
- while (__sync_lock_test_and_set (apif->lockp, 1))
- ;
- }
+ clib_spinlock_lock_if_init (&apif->lockp);
while (n_left > 0)
{
@@ -159,8 +155,7 @@ af_packet_interface_tx (vlib_main_t * vm,
}
}
- if (PREDICT_FALSE (apif->lockp != 0))
- *apif->lockp = 0;
+ clib_spinlock_unlock_if_init (&apif->lockp);
if (PREDICT_FALSE (frame_not_ready))
vlib_error_count (vm, node->node_index,
diff --git a/src/vnet/devices/netmap/device.c b/src/vnet/devices/netmap/device.c
index 2152824f733..aea9ddf4eb1 100644
--- a/src/vnet/devices/netmap/device.c
+++ b/src/vnet/devices/netmap/device.c
@@ -105,11 +105,7 @@ netmap_interface_tx (vlib_main_t * vm,
netmap_if_t *nif = pool_elt_at_index (nm->interfaces, rd->dev_instance);
int cur_ring;
- if (PREDICT_FALSE (nif->lockp != 0))
- {
- while (__sync_lock_test_and_set (nif->lockp, 1))
- ;
- }
+ clib_spinlock_lock_if_init (&nif->lockp);
cur_ring = nif->first_tx_ring;
@@ -165,8 +161,7 @@ netmap_interface_tx (vlib_main_t * vm,
if (n_left < frame->n_vectors)
ioctl (nif->fd, NIOCTXSYNC, NULL);
- if (PREDICT_FALSE (nif->lockp != 0))
- *nif->lockp = 0;
+ clib_spinlock_unlock_if_init (&nif->lockp);
if (n_left)
vlib_error_count (vm, node->node_index,
diff --git a/src/vnet/devices/netmap/netmap.c b/src/vnet/devices/netmap/netmap.c
index 3bdb442dda2..09afc7640ad 100644
--- a/src/vnet/devices/netmap/netmap.c
+++ b/src/vnet/devices/netmap/netmap.c
@@ -185,11 +185,7 @@ netmap_create_if (vlib_main_t * vm, u8 * if_name, u8 * hw_addr_set,
nif->per_interface_next_index = ~0;
if (tm->n_vlib_mains > 1)
- {
- nif->lockp = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
- CLIB_CACHE_LINE_BYTES);
- memset ((void *) nif->lockp, 0, CLIB_CACHE_LINE_BYTES);
- }
+ clib_spinlock_init (&nif->lockp);
{
unix_file_t template = { 0 };
diff --git a/src/vnet/devices/netmap/netmap.h b/src/vnet/devices/netmap/netmap.h
index 39a94043c3c..e04f045d6e2 100644
--- a/src/vnet/devices/netmap/netmap.h
+++ b/src/vnet/devices/netmap/netmap.h
@@ -40,10 +40,12 @@
* SUCH DAMAGE.
*/
+#include <vppinfra/lock.h>
+
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
- volatile u32 *lockp;
+ clib_spinlock_t lockp;
u8 *host_if_name;
uword if_index;
u32 hw_if_index;