summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/virtio/virtio.c
diff options
context:
space:
mode:
authorMohsin Kazmi <sykazmi@cisco.com>2019-05-10 17:28:28 +0200
committerDamjan Marion <dmarion@me.com>2019-05-23 11:37:45 +0000
commit55203e745f5e3f1f6c4dbe99d6eab8dee4d13ea6 (patch)
tree48fdc80575b701fd1efea7c61a87c66903326f7c /src/vnet/devices/virtio/virtio.c
parentf60be11516911669a41f44286aeb28c8b3b2a2d7 (diff)
Tap: Fix the indirect buffers allocation VPP-1660
Indirect buffers are used to store indirect descriptors to xmit big packets. This patch moves the indirect buffer allocation from interface creation to device node. Now it allocates or deallocates buffers during tx for chained buffers. Change-Id: I55cec208a2a7432e12fe9254a7f8ef84a9302bd5 Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Diffstat (limited to 'src/vnet/devices/virtio/virtio.c')
-rw-r--r--src/vnet/devices/virtio/virtio.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/vnet/devices/virtio/virtio.c b/src/vnet/devices/virtio/virtio.c
index 9fbbc1bf508..90acb75fa6d 100644
--- a/src/vnet/devices/virtio/virtio.c
+++ b/src/vnet/devices/virtio/virtio.c
@@ -113,20 +113,6 @@ virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz)
vring->queue_id = idx;
ASSERT (vring->buffers == 0);
vec_validate_aligned (vring->buffers, sz, CLIB_CACHE_LINE_BYTES);
- ASSERT (vring->indirect_buffers == 0);
- vec_validate_aligned (vring->indirect_buffers, sz, CLIB_CACHE_LINE_BYTES);
- if (idx % 2)
- {
- u32 n_alloc = 0;
- do
- {
- if (n_alloc < sz)
- n_alloc +=
- vlib_buffer_alloc (vm, vring->indirect_buffers + n_alloc,
- sz - n_alloc);
- }
- while (n_alloc != sz);
- }
vring->size = sz;
vring->call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
@@ -196,10 +182,35 @@ virtio_vring_free_rx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
if (vring->avail)
clib_mem_free (vring->avail);
vec_free (vring->buffers);
- vec_free (vring->indirect_buffers);
return 0;
}
+inline void
+virtio_free_used_desc (vlib_main_t * vm, virtio_vring_t * vring)
+{
+ u16 used = vring->desc_in_use;
+ u16 sz = vring->size;
+ u16 mask = sz - 1;
+ u16 last = vring->last_used_idx;
+ u16 n_left = vring->used->idx - last;
+
+ if (n_left == 0)
+ return;
+
+ while (n_left)
+ {
+ struct vring_used_elem *e = &vring->used->ring[last & mask];
+ u16 slot = e->id;
+
+ vlib_buffer_free (vm, &vring->buffers[slot], 1);
+ used--;
+ last++;
+ n_left--;
+ }
+ vring->desc_in_use = used;
+ vring->last_used_idx = last;
+}
+
clib_error_t *
virtio_vring_free_tx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
{
@@ -218,9 +229,7 @@ virtio_vring_free_tx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
clib_mem_free (vring->desc);
if (vring->avail)
clib_mem_free (vring->avail);
- vlib_buffer_free_no_next (vm, vring->indirect_buffers, vring->size);
vec_free (vring->buffers);
- vec_free (vring->indirect_buffers);
return 0;
}