From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ouyang Changchun Subject: [PATCH v5] virtio: Fix vring entry number issue Date: Wed, 15 Oct 2014 11:11:00 +0800 Message-ID: <1413342660-17894-1-git-send-email-changchun.ouyang@intel.com> References: <1413302634-848-1-git-send-email-changchun.ouyang@intel.com> To: dev-VfR2kkLFssw@public.gmane.org Return-path: In-Reply-To: <1413302634-848-1-git-send-email-changchun.ouyang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" Fix one issue in virtio TX: it needs one more vring descriptor to hold the virtio header when transmitting packets, it is used later to determine whether to free more entries from used vring. It fixes failing to transmit any packet with 1 segment in the circumstance of only 1 descriptor in the vring free list. Signed-off-by: Changchun Ouyang Reviewed-by: Olivier Matz --- -V5 change: Use 'likely' to hint compiler to generate favorable codes. -V4 change: Relocate those changelog and annotation here. -V3 change: Resolve compilation issue due to mbuf re-structure. -V2 change: Refine description, 'vring descriptor' is more accurate than 'vring entry'; Accordingly update test condition (it needs one more descriptor for virtio header) to put packets to transmit queue. -V1 change: Fix the vring descriptor issue in virtio TX, it needs one more vring descriptor to hold the virtio header. lib/librte_pmd_virtio/virtio_rxtx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/librte_pmd_virtio/virtio_rxtx.c b/lib/librte_pmd_virtio/virtio_rxtx.c index ad6401c..3f6bad2 100644 --- a/lib/librte_pmd_virtio/virtio_rxtx.c +++ b/lib/librte_pmd_virtio/virtio_rxtx.c @@ -699,7 +699,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) num = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ? nb_used : VIRTIO_MBUF_BURST_SZ); while (nb_tx < nb_pkts) { - int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt; + /* Need one more descriptor for virtio header. */ + int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1; int deq_cnt = RTE_MIN(need, (int)num); num -= (deq_cnt > 0) ? deq_cnt : 0; @@ -708,7 +709,12 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) deq_cnt--; } - if (tx_pkts[nb_tx]->nb_segs <= txvq->vq_free_cnt) { + need = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1; + /* + * Zero or negative value indicates it has enough free + * descriptors to use for transmitting. + */ + if (likely(need <= 0)) { txm = tx_pkts[nb_tx]; /* Enqueue Packet buffers */ error = virtqueue_enqueue_xmit(txvq, txm); -- 1.8.4.2