From: Jens Freimann <jfreiman@redhat.com>
To: yuanhan.liu@linux.intel.com
Cc: dev@dpdk.org
Subject: [dpdk-dev] [RFC PATCH 09/11] xxx: virtio: remove overheads
Date: Fri, 5 May 2017 09:57:20 -0400 [thread overview]
Message-ID: <1493992642-52756-10-git-send-email-jfreiman@redhat.com> (raw)
In-Reply-To: <1493992642-52756-1-git-send-email-jfreiman@redhat.com>
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
for better performance comparing
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
drivers/net/virtio/virtio_rxtx.c | 188 +++------------------------------------
1 file changed, 12 insertions(+), 176 deletions(-)
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index e697192..c49ac0d 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -218,76 +218,16 @@
return 0;
}
-/* When doing TSO, the IP length is not included in the pseudo header
- * checksum of the packet given to the PMD, but for virtio it is
- * expected.
- */
-static void
-virtio_tso_fix_cksum(struct rte_mbuf *m)
-{
- /* common case: header is not fragmented */
- if (likely(rte_pktmbuf_data_len(m) >= m->l2_len + m->l3_len +
- m->l4_len)) {
- struct ipv4_hdr *iph;
- struct ipv6_hdr *ip6h;
- struct tcp_hdr *th;
- uint16_t prev_cksum, new_cksum, ip_len, ip_paylen;
- uint32_t tmp;
-
- iph = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, m->l2_len);
- th = RTE_PTR_ADD(iph, m->l3_len);
- if ((iph->version_ihl >> 4) == 4) {
- iph->hdr_checksum = 0;
- iph->hdr_checksum = rte_ipv4_cksum(iph);
- ip_len = iph->total_length;
- ip_paylen = rte_cpu_to_be_16(rte_be_to_cpu_16(ip_len) -
- m->l3_len);
- } else {
- ip6h = (struct ipv6_hdr *)iph;
- ip_paylen = ip6h->payload_len;
- }
-
- /* calculate the new phdr checksum not including ip_paylen */
- prev_cksum = th->cksum;
- tmp = prev_cksum;
- tmp += ip_paylen;
- tmp = (tmp & 0xffff) + (tmp >> 16);
- new_cksum = tmp;
-
- /* replace it in the packet */
- th->cksum = new_cksum;
- }
-}
-
-static inline int
-tx_offload_enabled(struct virtio_hw *hw)
-{
- return vtpci_with_feature(hw, VIRTIO_NET_F_CSUM) ||
- vtpci_with_feature(hw, VIRTIO_NET_F_HOST_TSO4) ||
- vtpci_with_feature(hw, VIRTIO_NET_F_HOST_TSO6);
-}
-
-/* avoid write operation when necessary, to lessen cache issues */
-#define ASSIGN_UNLESS_EQUAL(var, val) do { \
- if ((var) != (val)) \
- (var) = (val); \
-} while (0)
-
static inline void
virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie,
- uint16_t needed, int use_indirect, int can_push)
+ uint16_t needed)
{
struct virtio_tx_region *txr = txvq->virtio_net_hdr_mz->addr;
struct vq_desc_extra *dxp;
struct virtqueue *vq = txvq->vq;
struct vring_desc *start_dp;
- uint16_t seg_num = cookie->nb_segs;
uint16_t head_idx, idx;
- uint16_t head_size = vq->hw->vtnet_hdr_size;
- struct virtio_net_hdr *hdr;
- int offload;
- offload = tx_offload_enabled(vq->hw);
head_idx = vq->vq_desc_head_idx;
idx = head_idx;
dxp = &vq->vq_descx[idx];
@@ -296,91 +236,15 @@
start_dp = vq->vq_ring.desc;
- if (can_push) {
- /* prepend cannot fail, checked by caller */
- hdr = (struct virtio_net_hdr *)
- rte_pktmbuf_prepend(cookie, head_size);
- /* if offload disabled, it is not zeroed below, do it now */
- if (offload == 0) {
- ASSIGN_UNLESS_EQUAL(hdr->csum_start, 0);
- ASSIGN_UNLESS_EQUAL(hdr->csum_offset, 0);
- ASSIGN_UNLESS_EQUAL(hdr->flags, 0);
- ASSIGN_UNLESS_EQUAL(hdr->gso_type, 0);
- ASSIGN_UNLESS_EQUAL(hdr->gso_size, 0);
- ASSIGN_UNLESS_EQUAL(hdr->hdr_len, 0);
- }
- } else if (use_indirect) {
- /* setup tx ring slot to point to indirect
- * descriptor list stored in reserved region.
- *
- * the first slot in indirect ring is already preset
- * to point to the header in reserved region
- */
- start_dp[idx].addr = txvq->virtio_net_hdr_mem +
- RTE_PTR_DIFF(&txr[idx].tx_indir, txr);
- start_dp[idx].len = (seg_num + 1) * sizeof(struct vring_desc);
- start_dp[idx].flags = VRING_DESC_F_INDIRECT;
- hdr = (struct virtio_net_hdr *)&txr[idx].tx_hdr;
-
- /* loop below will fill in rest of the indirect elements */
- start_dp = txr[idx].tx_indir;
- idx = 1;
- } else {
- /* setup first tx ring slot to point to header
- * stored in reserved region.
- */
- start_dp[idx].addr = txvq->virtio_net_hdr_mem +
- RTE_PTR_DIFF(&txr[idx].tx_hdr, txr);
- start_dp[idx].len = vq->hw->vtnet_hdr_size;
- start_dp[idx].flags = VRING_DESC_F_NEXT;
- hdr = (struct virtio_net_hdr *)&txr[idx].tx_hdr;
-
- idx = start_dp[idx].next;
- }
-
- /* Checksum Offload / TSO */
- if (offload) {
- if (cookie->ol_flags & PKT_TX_TCP_SEG)
- cookie->ol_flags |= PKT_TX_TCP_CKSUM;
-
- switch (cookie->ol_flags & PKT_TX_L4_MASK) {
- case PKT_TX_UDP_CKSUM:
- hdr->csum_start = cookie->l2_len + cookie->l3_len;
- hdr->csum_offset = offsetof(struct udp_hdr,
- dgram_cksum);
- hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
- break;
-
- case PKT_TX_TCP_CKSUM:
- hdr->csum_start = cookie->l2_len + cookie->l3_len;
- hdr->csum_offset = offsetof(struct tcp_hdr, cksum);
- hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
- break;
+ /* setup first tx ring slot to point to header
+ * stored in reserved region.
+ */
+ start_dp[idx].addr = txvq->virtio_net_hdr_mem +
+ RTE_PTR_DIFF(&txr[idx].tx_hdr, txr);
+ start_dp[idx].len = vq->hw->vtnet_hdr_size;
+ start_dp[idx].flags = VRING_DESC_F_NEXT;
- default:
- ASSIGN_UNLESS_EQUAL(hdr->csum_start, 0);
- ASSIGN_UNLESS_EQUAL(hdr->csum_offset, 0);
- ASSIGN_UNLESS_EQUAL(hdr->flags, 0);
- break;
- }
-
- /* TCP Segmentation Offload */
- if (cookie->ol_flags & PKT_TX_TCP_SEG) {
- virtio_tso_fix_cksum(cookie);
- hdr->gso_type = (cookie->ol_flags & PKT_TX_IPV6) ?
- VIRTIO_NET_HDR_GSO_TCPV6 :
- VIRTIO_NET_HDR_GSO_TCPV4;
- hdr->gso_size = cookie->tso_segsz;
- hdr->hdr_len =
- cookie->l2_len +
- cookie->l3_len +
- cookie->l4_len;
- } else {
- ASSIGN_UNLESS_EQUAL(hdr->gso_type, 0);
- ASSIGN_UNLESS_EQUAL(hdr->gso_size, 0);
- ASSIGN_UNLESS_EQUAL(hdr->hdr_len, 0);
- }
- }
+ idx = start_dp[idx].next;
do {
start_dp[idx].addr = VIRTIO_MBUF_DATA_DMA_ADDR(cookie, vq);
@@ -389,9 +253,6 @@
idx = start_dp[idx].next;
} while ((cookie = cookie->next) != NULL);
- if (use_indirect)
- idx = vq->vq_ring.desc[head_idx].next;
-
vq->vq_desc_head_idx = idx;
if (vq->vq_desc_head_idx == VQ_RING_DESC_CHAIN_END)
vq->vq_desc_tail_idx = idx;
@@ -1011,9 +872,7 @@
struct virtnet_tx *txvq = tx_queue;
struct virtqueue *vq = txvq->vq;
struct virtio_hw *hw = vq->hw;
- uint16_t hdr_size = hw->vtnet_hdr_size;
uint16_t nb_used, nb_tx = 0;
- int error;
if (unlikely(hw->started == 0))
return nb_tx;
@@ -1030,37 +889,14 @@
for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
struct rte_mbuf *txm = tx_pkts[nb_tx];
- int can_push = 0, use_indirect = 0, slots, need;
-
- /* Do VLAN tag insertion */
- if (unlikely(txm->ol_flags & PKT_TX_VLAN_PKT)) {
- error = rte_vlan_insert(&txm);
- if (unlikely(error)) {
- rte_pktmbuf_free(txm);
- continue;
- }
- }
-
- /* optimize ring usage */
- if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
- vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
- rte_mbuf_refcnt_read(txm) == 1 &&
- RTE_MBUF_DIRECT(txm) &&
- txm->nb_segs == 1 &&
- rte_pktmbuf_headroom(txm) >= hdr_size &&
- rte_is_aligned(rte_pktmbuf_mtod(txm, char *),
- __alignof__(struct virtio_net_hdr_mrg_rxbuf)))
- can_push = 1;
- else if (vtpci_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
- txm->nb_segs < VIRTIO_MAX_TX_INDIRECT)
- use_indirect = 1;
+ int slots, need;
/* How many main ring entries are needed to this Tx?
* any_layout => number of segments
* indirect => 1
* default => number of segments + 1
*/
- slots = use_indirect ? 1 : (txm->nb_segs + !can_push);
+ slots =txm->nb_segs + 1;
need = slots - vq->vq_free_cnt;
/* Positive value indicates it need free vring descriptors */
@@ -1079,7 +915,7 @@
}
/* Enqueue Packet buffers */
- virtqueue_enqueue_xmit(txvq, txm, slots, use_indirect, can_push);
+ virtqueue_enqueue_xmit(txvq, txm, slots);
txvq->stats.bytes += txm->pkt_len;
virtio_update_packet_stats(&txvq->stats, txm);
--
1.8.3.1
next prev parent reply other threads:[~2017-05-05 13:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-05 13:57 [dpdk-dev] [RFC PATCH 00/11] net/virtio: packed ring layout Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 01/11] net/virtio: vring init for 1.1 Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 02/11] net/virtio: implement 1.1 guest Tx Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 03/11] net/virtio-user: add option to enable 1.1 Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 04/11] vhost: enable 1.1 for testing Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 05/11] vhost: set desc addr for 1.1 Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 06/11] vhost: implement virtio 1.1 dequeue path Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 07/11] vhost: mark desc being used Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 08/11] xxx: batch the desc_hw update? Jens Freimann
2017-05-05 13:57 ` Jens Freimann [this message]
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 10/11] vhost: prefetch desc Jens Freimann
2017-05-05 13:57 ` [dpdk-dev] [RFC PATCH 11/11] add virtio 1.1 test guide Jens Freimann
2017-05-08 5:02 ` [dpdk-dev] [RFC PATCH 00/11] net/virtio: packed ring layout Yuanhan Liu
2017-05-08 7:36 ` Jens Freimann
2017-05-17 11:30 ` Jens Freimann
2017-05-18 14:24 ` Yuanhan Liu
2017-05-22 9:14 ` Yuanhan Liu
2017-05-22 9:23 ` Jens Freimann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1493992642-52756-10-git-send-email-jfreiman@redhat.com \
--to=jfreiman@redhat.com \
--cc=dev@dpdk.org \
--cc=yuanhan.liu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).