From: Huawei Xie Date: Wed, 8 Oct 2014 18:54:45 +0000 (+0800) Subject: vhost: enqueue/dequeue burst X-Git-Tag: spdx-start~10295 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=a4fff3bba82b79637a25622652481c973fdb3c9f;p=dpdk.git vhost: enqueue/dequeue burst rte_vhost_enqueue_burst copies host packets to guest. rte_vhost_enqueue_burst will call virtio_dev_rx and virtio_dev_merge_rx respectively depending on whether merge-able feature is negotiated or not in the vhost device. virtio_dev_merge_tx is renamed to rte_vhost_dequeue_burst. rte_vhost_dequeue_burst gets to-be-sent packets from guest. Signed-off-by: Huawei Xie Acked-by: Changchun Ouyang [Thomas: merged patches] --- diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index 5bb429a159..0c9c716b62 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -146,4 +146,37 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa) return vhost_va; } +/* Register vhost driver. dev_name could be different for multiple instance support. */ +int rte_vhost_driver_register(const char *dev_name); + +/* Start vhost driver session blocking loop. */ +int rte_vhost_driver_session_start(void); + +/** + * This function adds buffers to the virtio devices RX virtqueue. Buffers can + * be received from the physical port or from another virtual device. A packet + * count is returned to indicate the number of packets that were succesfully + * added to the RX queue. + * @param queue_id + * virtio queue index in mq case + * @return + * num of packets enqueued + */ +uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id, + struct rte_mbuf **pkts, uint16_t count); + +/** + * This function gets guest buffers from the virtio device TX virtqueue, + * construct host mbufs, copies guest buffer content to host mbufs and + * store them in pkts to be processed. + * @param mbuf_pool + * mbuf_pool where host mbuf is allocated. + * @param queue_id + * virtio queue index in mq case. + * @return + * num of packets dequeued + */ +uint16_t rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count); + #endif /* _VIRTIO_NET_H_ */ diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c index 0d177b9f88..b13965bd78 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -522,9 +522,17 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, struct rte_mbuf * return count; } -/* This function works for TX packets with mergeable feature enabled. */ -static inline uint16_t __attribute__((always_inline)) -virtio_dev_merge_tx(struct virtio_net *dev, uint16_t queue_id, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count) +uint16_t +rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count) +{ + if (unlikely(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF))) + return virtio_dev_merge_rx(dev, queue_id, pkts, count); + else + return virtio_dev_rx(dev, queue_id, pkts, count); +} + +uint16_t +rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count) { struct rte_mbuf *m, *prev; struct vhost_virtqueue *vq; @@ -548,7 +556,7 @@ virtio_dev_merge_tx(struct virtio_net *dev, uint16_t queue_id, struct rte_mempoo if (vq->last_used_idx == avail_idx) return 0; - LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_merge_tx()\n", + LOG_DEBUG(VHOST_DATA, "%s (%"PRIu64")\n", __func__, dev->device_fh); /* Prefetch available ring to retrieve head indexes. */