diff options
author | Damjan Marion <damarion@cisco.com> | 2018-02-16 16:13:32 +0100 |
---|---|---|
committer | Marco Varlese <marco.varlese@suse.de> | 2018-02-25 11:56:46 +0000 |
commit | eed6a2b22f85aea2e3104cca2b78e325b9c9f8e5 (patch) | |
tree | 4aa9bffd9afed97833b2be3c490e8669494ad763 | |
parent | c17f55d31f2e2f45939e37eccf2cd1c7ea4acd07 (diff) |
virtio: add missing tx lock when running multithreaded
Change-Id: I373f429c53c6f66ad38322addcfaccddb7761392
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | src/vnet/devices/tap/tap.c | 4 | ||||
-rw-r--r-- | src/vnet/devices/virtio/device.c | 4 | ||||
-rw-r--r-- | src/vnet/devices/virtio/virtio.h | 2 |
3 files changed, 10 insertions, 0 deletions
diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c index a7d10fe5473..7177de7be06 100644 --- a/src/vnet/devices/tap/tap.c +++ b/src/vnet/devices/tap/tap.c @@ -80,6 +80,7 @@ void tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) { vnet_main_t *vnm = vnet_get_main (); + vlib_thread_main_t *thm = vlib_get_thread_main (); virtio_main_t *vim = &virtio_main; tap_main_t *tm = &tap_main; vnet_sw_interface_t *sw; @@ -377,6 +378,8 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP; vnet_hw_interface_set_flags (vnm, vif->hw_if_index, VNET_HW_INTERFACE_FLAG_LINK_UP); + if (thm->n_vlib_mains > 1) + clib_spinlock_init (&vif->lockp); goto done; error: @@ -433,6 +436,7 @@ tap_delete_if (vlib_main_t * vm, u32 sw_if_index) vec_free (vif->vrings); hash_unset (tm->dev_instance_by_interface_id, vif->id); + clib_spinlock_free (&vif->lockp); memset (vif, 0, sizeof (*vif)); pool_put (mm->interfaces, vif); diff --git a/src/vnet/devices/virtio/device.c b/src/vnet/devices/virtio/device.c index ae8a116efee..c7efe6519cd 100644 --- a/src/vnet/devices/virtio/device.c +++ b/src/vnet/devices/virtio/device.c @@ -182,6 +182,8 @@ virtio_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, u16 mask = sz - 1; u32 *buffers = vlib_frame_args (frame); + clib_spinlock_lock_if_init (&vif->lockp); + /* free consumed buffers */ virtio_free_used_desc (vm, vring); @@ -221,6 +223,8 @@ virtio_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_buffer_free (vm, buffers, n_left); } + clib_spinlock_unlock_if_init (&vif->lockp); + return frame->n_vectors - n_left; } diff --git a/src/vnet/devices/virtio/virtio.h b/src/vnet/devices/virtio/virtio.h index 90eeb536ab1..89c02aa8bb7 100644 --- a/src/vnet/devices/virtio/virtio.h +++ b/src/vnet/devices/virtio/virtio.h @@ -91,6 +91,8 @@ typedef struct typedef struct { u32 flags; + clib_spinlock_t lockp; + u32 id; u32 dev_instance; u32 hw_if_index; |