X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fmemif%2Fdevice.c;h=fc66420a6ad2c0ce9911d4cc03c38fd91bcadd8b;hb=1a19552eee24e447e6087de43a2eeb9250b8cae7;hp=befc0b50eabbba49c42de8a4b3db61d0a0658e5f;hpb=3d2c6743f4e0958df3189c9e8e08e7d56f1e0df7;p=vpp.git diff --git a/src/plugins/memif/device.c b/src/plugins/memif/device.c index befc0b50eab..fc66420a6ad 100644 --- a/src/plugins/memif/device.c +++ b/src/plugins/memif/device.c @@ -97,14 +97,12 @@ memif_add_copy_op (memif_per_thread_data_t * ptd, void *data, u32 len, } static_always_inline uword -memif_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame, memif_if_t * mif, - memif_ring_type_t type, memif_queue_t * mq, - memif_per_thread_data_t * ptd) +memif_interface_tx_inline (vlib_main_t *vm, vlib_node_runtime_t *node, + u32 *buffers, memif_if_t *mif, + memif_ring_type_t type, memif_queue_t *mq, + memif_per_thread_data_t *ptd, u32 n_left) { memif_ring_t *ring; - u32 *buffers = vlib_frame_vector_args (frame); - u32 n_left = frame->n_vectors; u32 n_copy_op; u16 ring_size, mask, slot, free_slots; int n_retries = 5; @@ -145,8 +143,7 @@ retry: u32 saved_ptd_buffers_len = _vec_len (ptd->buffers); u16 saved_slot = slot; - CLIB_PREFETCH (&ring->desc[(slot + 8) & mask], CLIB_CACHE_LINE_BYTES, - LOAD); + clib_prefetch_load (&ring->desc[(slot + 8) & mask]); d0 = &ring->desc[slot & mask]; if (PREDICT_FALSE (last_region != d0->region)) @@ -179,6 +176,7 @@ retry: { slot++; free_slots--; + d0->length = dst_off; d0->flags = MEMIF_DESC_FLAG_NEXT; d0 = &ring->desc[slot & mask]; dst_off = 0; @@ -236,10 +234,10 @@ no_free_slots: co = ptd->copy_ops; while (n_copy_op >= 8) { - CLIB_PREFETCH (co[4].data, CLIB_CACHE_LINE_BYTES, LOAD); - CLIB_PREFETCH (co[5].data, CLIB_CACHE_LINE_BYTES, LOAD); - CLIB_PREFETCH (co[6].data, CLIB_CACHE_LINE_BYTES, LOAD); - CLIB_PREFETCH (co[7].data, CLIB_CACHE_LINE_BYTES, LOAD); + clib_prefetch_load (co[4].data); + clib_prefetch_load (co[5].data); + clib_prefetch_load (co[6].data); + clib_prefetch_load (co[7].data); b0 = vlib_get_buffer (vm, ptd->buffers[co[0].buffer_vec_index]); b1 = vlib_get_buffer (vm, ptd->buffers[co[1].buffer_vec_index]); @@ -278,35 +276,15 @@ no_free_slots: if (n_left && n_retries--) goto retry; - clib_spinlock_unlock_if_init (&mif->lockp); - - if (n_left) - { - vlib_error_count (vm, node->node_index, MEMIF_TX_ERROR_NO_FREE_SLOTS, - n_left); - } - - if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0 && mq->int_fd > -1) - { - u64 b = 1; - CLIB_UNUSED (int r) = write (mq->int_fd, &b, sizeof (b)); - mq->int_count++; - } - - vlib_buffer_free (vm, vlib_frame_vector_args (frame), frame->n_vectors); - - return frame->n_vectors; + return n_left; } static_always_inline uword -memif_interface_tx_zc_inline (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame, memif_if_t * mif, - memif_queue_t * mq, - memif_per_thread_data_t * ptd) +memif_interface_tx_zc_inline (vlib_main_t *vm, vlib_node_runtime_t *node, + u32 *buffers, memif_if_t *mif, memif_queue_t *mq, + memif_per_thread_data_t *ptd, u32 n_left) { memif_ring_t *ring = mq->ring; - u32 *buffers = vlib_frame_vector_args (frame); - u32 n_left = frame->n_vectors; u16 slot, free_slots, n_free; u16 ring_size = 1 << mq->log2_ring_size; u16 mask = ring_size - 1; @@ -315,8 +293,8 @@ memif_interface_tx_zc_inline (vlib_main_t * vm, vlib_node_runtime_t * node, u16 head, tail; retry: - slot = tail = __atomic_load_n (&ring->tail, __ATOMIC_ACQUIRE); - head = ring->head; + tail = __atomic_load_n (&ring->tail, __ATOMIC_ACQUIRE); + slot = head = ring->head; n_free = tail - mq->last_tail; if (n_free >= 16) @@ -336,8 +314,7 @@ retry: memif_desc_t *d0; u32 bi0; - CLIB_PREFETCH (&ring->desc[(slot + 8) & mask], CLIB_CACHE_LINE_BYTES, - STORE); + clib_prefetch_store (&ring->desc[(slot + 8) & mask]); if (PREDICT_TRUE (n_left >= 4)) vlib_prefetch_buffer_header (vlib_get_buffer (vm, buffers[3]), LOAD); @@ -389,23 +366,7 @@ no_free_slots: if (n_left && n_retries--) goto retry; - clib_spinlock_unlock_if_init (&mif->lockp); - - if (n_left) - { - vlib_error_count (vm, node->node_index, MEMIF_TX_ERROR_NO_FREE_SLOTS, - n_left); - vlib_buffer_free (vm, buffers, n_left); - } - - if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0 && mq->int_fd > -1) - { - u64 b = 1; - CLIB_UNUSED (int r) = write (mq->int_fd, &b, sizeof (b)); - mq->int_count++; - } - - return frame->n_vectors; + return n_left; } VNET_DEVICE_CLASS_TX_FN (memif_device_class) (vlib_main_t * vm, @@ -416,28 +377,53 @@ VNET_DEVICE_CLASS_TX_FN (memif_device_class) (vlib_main_t * vm, vnet_interface_output_runtime_t *rund = (void *) node->runtime_data; memif_if_t *mif = pool_elt_at_index (nm->interfaces, rund->dev_instance); memif_queue_t *mq; - u32 thread_index = vm->thread_index; + u32 *from, thread_index = vm->thread_index; memif_per_thread_data_t *ptd = vec_elt_at_index (memif_main.per_thread_data, thread_index); u8 tx_queues = vec_len (mif->tx_queues); + uword n_left; if (tx_queues < vlib_get_n_threads ()) { ASSERT (tx_queues > 0); mq = vec_elt_at_index (mif->tx_queues, thread_index % tx_queues); - clib_spinlock_lock_if_init (&mif->lockp); } else mq = vec_elt_at_index (mif->tx_queues, thread_index); + clib_spinlock_lock_if_init (&mif->lockp); + + from = vlib_frame_vector_args (frame); + n_left = frame->n_vectors; if (mif->flags & MEMIF_IF_FLAG_ZERO_COPY) - return memif_interface_tx_zc_inline (vm, node, frame, mif, mq, ptd); + n_left = + memif_interface_tx_zc_inline (vm, node, from, mif, mq, ptd, n_left); else if (mif->flags & MEMIF_IF_FLAG_IS_SLAVE) - return memif_interface_tx_inline (vm, node, frame, mif, MEMIF_RING_S2M, - mq, ptd); + n_left = memif_interface_tx_inline (vm, node, from, mif, MEMIF_RING_S2M, + mq, ptd, n_left); else - return memif_interface_tx_inline (vm, node, frame, mif, MEMIF_RING_M2S, - mq, ptd); + n_left = memif_interface_tx_inline (vm, node, from, mif, MEMIF_RING_M2S, + mq, ptd, n_left); + + clib_spinlock_unlock_if_init (&mif->lockp); + + if (n_left) + vlib_error_count (vm, node->node_index, MEMIF_TX_ERROR_NO_FREE_SLOTS, + n_left); + + if ((mq->ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0 && mq->int_fd > -1) + { + u64 b = 1; + int __clib_unused r = write (mq->int_fd, &b, sizeof (b)); + mq->int_count++; + } + + if ((mif->flags & MEMIF_IF_FLAG_ZERO_COPY) == 0) + vlib_buffer_free (vm, from, frame->n_vectors); + else if (n_left) + vlib_buffer_free (vm, from + frame->n_vectors - n_left, n_left); + + return frame->n_vectors - n_left; } static void