eal: correct log for alarm error
[dpdk.git] / lib / librte_vhost / virtio_net.c
index bd6635c..5b85b83 100644 (file)
@@ -286,6 +286,8 @@ map_one_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
                if (unlikely(!desc_addr))
                        return -1;
 
+               rte_prefetch0((void *)(uintptr_t)desc_addr);
+
                buf_vec[vec_id].buf_iova = desc_iova;
                buf_vec[vec_id].buf_addr = desc_addr;
                buf_vec[vec_id].buf_len  = desc_chunck_len;
@@ -337,7 +339,7 @@ fill_vec_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
                         * The indirect desc table is not contiguous
                         * in process VA space, we have to copy it.
                         */
-                       idesc = alloc_copy_ind_table(dev, vq,
+                       idesc = vhost_alloc_copy_ind_table(dev, vq,
                                        vq->desc[idx].addr, vq->desc[idx].len);
                        if (unlikely(!idesc))
                                return -1;
@@ -454,7 +456,8 @@ fill_vec_buf_packed_indirect(struct virtio_net *dev,
                 * The indirect desc table is not contiguous
                 * in process VA space, we have to copy it.
                 */
-               idescs = alloc_copy_ind_table(dev, vq, desc->addr, desc->len);
+               idescs = vhost_alloc_copy_ind_table(dev,
+                               vq, desc->addr, desc->len);
                if (unlikely(!idescs))
                        return -1;
 
@@ -610,6 +613,36 @@ reserve_avail_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
        return 0;
 }
 
+static __rte_noinline void
+copy_vnet_hdr_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
+               struct buf_vector *buf_vec,
+               struct virtio_net_hdr_mrg_rxbuf *hdr)
+{
+       uint64_t len;
+       uint64_t remain = dev->vhost_hlen;
+       uint64_t src = (uint64_t)(uintptr_t)hdr, dst;
+       uint64_t iova = buf_vec->buf_iova;
+
+       while (remain) {
+               len = RTE_MIN(remain,
+                               buf_vec->buf_len);
+               dst = buf_vec->buf_addr;
+               rte_memcpy((void *)(uintptr_t)dst,
+                               (void *)(uintptr_t)src,
+                               len);
+
+               PRINT_PACKET(dev, (uintptr_t)dst,
+                               (uint32_t)len, 0);
+               vhost_log_cache_write(dev, vq,
+                               iova, len);
+
+               remain -= len;
+               iova += len;
+               src += len;
+               buf_vec++;
+       }
+}
+
 static __rte_always_inline int
 copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
                            struct rte_mbuf *m, struct buf_vector *buf_vec,
@@ -635,9 +668,6 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
        buf_iova = buf_vec[vec_idx].buf_iova;
        buf_len = buf_vec[vec_idx].buf_len;
 
-       if (nr_vec > 1)
-               rte_prefetch0((void *)(uintptr_t)buf_vec[1].buf_addr);
-
        if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) {
                error = -1;
                goto out;
@@ -680,10 +710,6 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
                        buf_iova = buf_vec[vec_idx].buf_iova;
                        buf_len = buf_vec[vec_idx].buf_len;
 
-                       /* Prefetch next buffer address. */
-                       if (vec_idx + 1 < nr_vec)
-                               rte_prefetch0((void *)(uintptr_t)
-                                               buf_vec[vec_idx + 1].buf_addr);
                        buf_offset = 0;
                        buf_avail  = buf_len;
                }
@@ -703,30 +729,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
                                                num_buffers);
 
                        if (unlikely(hdr == &tmp_hdr)) {
-                               uint64_t len;
-                               uint64_t remain = dev->vhost_hlen;
-                               uint64_t src = (uint64_t)(uintptr_t)hdr, dst;
-                               uint64_t iova = buf_vec[0].buf_iova;
-                               uint16_t hdr_vec_idx = 0;
-
-                               while (remain) {
-                                       len = RTE_MIN(remain,
-                                               buf_vec[hdr_vec_idx].buf_len);
-                                       dst = buf_vec[hdr_vec_idx].buf_addr;
-                                       rte_memcpy((void *)(uintptr_t)dst,
-                                                       (void *)(uintptr_t)src,
-                                                       len);
-
-                                       PRINT_PACKET(dev, (uintptr_t)dst,
-                                                       (uint32_t)len, 0);
-                                       vhost_log_cache_write(dev, vq,
-                                                       iova, len);
-
-                                       remain -= len;
-                                       iova += len;
-                                       src += len;
-                                       hdr_vec_idx++;
-                               }
+                               copy_vnet_hdr_to_desc(dev, vq, buf_vec, hdr);
                        } else {
                                PRINT_PACKET(dev, (uintptr_t)hdr_addr,
                                                dev->vhost_hlen, 0);
@@ -771,7 +774,7 @@ out:
        return error;
 }
 
-static __rte_always_inline uint32_t
+static __rte_noinline uint32_t
 virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
        struct rte_mbuf **pkts, uint32_t count)
 {
@@ -804,8 +807,6 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
                        break;
                }
 
-               rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
-
                VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
                        dev->vid, vq->last_avail_idx,
                        vq->last_avail_idx + num_buffers);
@@ -830,7 +831,7 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
        return pkt_idx;
 }
 
-static __rte_always_inline uint32_t
+static __rte_noinline uint32_t
 virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
        struct rte_mbuf **pkts, uint32_t count)
 {
@@ -853,8 +854,6 @@ virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
                        break;
                }
 
-               rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
-
                VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
                        dev->vid, vq->last_avail_idx,
                        vq->last_avail_idx + num_buffers);
@@ -1064,6 +1063,27 @@ vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
        }
 }
 
+static __rte_noinline void
+copy_vnet_hdr_from_desc(struct virtio_net_hdr *hdr,
+               struct buf_vector *buf_vec)
+{
+       uint64_t len;
+       uint64_t remain = sizeof(struct virtio_net_hdr);
+       uint64_t src;
+       uint64_t dst = (uint64_t)(uintptr_t)hdr;
+
+       while (remain) {
+               len = RTE_MIN(remain, buf_vec->buf_len);
+               src = buf_vec->buf_addr;
+               rte_memcpy((void *)(uintptr_t)dst,
+                               (void *)(uintptr_t)src, len);
+
+               remain -= len;
+               dst += len;
+               buf_vec++;
+       }
+}
+
 static __rte_always_inline int
 copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
                  struct buf_vector *buf_vec, uint16_t nr_vec,
@@ -1090,37 +1110,16 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
                goto out;
        }
 
-       if (likely(nr_vec > 1))
-               rte_prefetch0((void *)(uintptr_t)buf_vec[1].buf_addr);
-
        if (virtio_net_with_host_offload(dev)) {
                if (unlikely(buf_len < sizeof(struct virtio_net_hdr))) {
-                       uint64_t len;
-                       uint64_t remain = sizeof(struct virtio_net_hdr);
-                       uint64_t src;
-                       uint64_t dst = (uint64_t)(uintptr_t)&tmp_hdr;
-                       uint16_t hdr_vec_idx = 0;
-
                        /*
                         * No luck, the virtio-net header doesn't fit
                         * in a contiguous virtual area.
                         */
-                       while (remain) {
-                               len = RTE_MIN(remain,
-                                       buf_vec[hdr_vec_idx].buf_len);
-                               src = buf_vec[hdr_vec_idx].buf_addr;
-                               rte_memcpy((void *)(uintptr_t)dst,
-                                                  (void *)(uintptr_t)src, len);
-
-                               remain -= len;
-                               dst += len;
-                               hdr_vec_idx++;
-                       }
-
+                       copy_vnet_hdr_from_desc(&tmp_hdr, buf_vec);
                        hdr = &tmp_hdr;
                } else {
                        hdr = (struct virtio_net_hdr *)((uintptr_t)buf_addr);
-                       rte_prefetch0(hdr);
                }
        }
 
@@ -1150,9 +1149,6 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
                buf_avail = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
        }
 
-       rte_prefetch0((void *)(uintptr_t)
-                       (buf_addr + buf_offset));
-
        PRINT_PACKET(dev,
                        (uintptr_t)(buf_addr + buf_offset),
                        (uint32_t)buf_avail, 0);
@@ -1218,14 +1214,6 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
                        buf_iova = buf_vec[vec_idx].buf_iova;
                        buf_len = buf_vec[vec_idx].buf_len;
 
-                       /*
-                        * Prefecth desc n + 1 buffer while
-                        * desc n buffer is processed.
-                        */
-                       if (vec_idx + 1 < nr_vec)
-                               rte_prefetch0((void *)(uintptr_t)
-                                               buf_vec[vec_idx + 1].buf_addr);
-
                        buf_offset = 0;
                        buf_avail  = buf_len;
 
@@ -1301,7 +1289,7 @@ again:
        return NULL;
 }
 
-static __rte_always_inline uint16_t
+static __rte_noinline uint16_t
 virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
        struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
 {
@@ -1369,8 +1357,6 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
                if (likely(dev->dequeue_zero_copy == 0))
                        update_shadow_used_ring_split(vq, head_idx, 0);
 
-               rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
-
                pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
                if (unlikely(pkts[i] == NULL)) {
                        RTE_LOG(ERR, VHOST_DATA,
@@ -1423,7 +1409,7 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
        return i;
 }
 
-static __rte_always_inline uint16_t
+static __rte_noinline uint16_t
 virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
        struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
 {
@@ -1480,8 +1466,6 @@ virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
                        update_shadow_used_ring_packed(vq, buf_id, 0,
                                        desc_count);
 
-               rte_prefetch0((void *)(uintptr_t)buf_vec[0].buf_addr);
-
                pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
                if (unlikely(pkts[i] == NULL)) {
                        RTE_LOG(ERR, VHOST_DATA,