From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30058.outbound.protection.outlook.com [40.107.3.58]) by dpdk.org (Postfix) with ESMTP id 4EB59378B for ; Mon, 10 Sep 2018 12:56:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4EpXgBwlc8B4ie3ILvXnmV7EqE1OHsvI4vh45ew0jYM=; b=sMejjN/BOvZ1H2V1CoIOnIPFp7wPl8iKCzydUgtnBRraf4KFCuchXZqR96e5OdG8Ssfgq99HD5UMtk9DbJw5KLaJlQ/VjWUWyodi+fzyPyySMWdP3F+L3BywCNkRkLUrtH2ZLSmk3xaPzikxWkXh8wrQQzPXJugyt+rWRac/Mrw= Received: from VI1PR08MB3167.eurprd08.prod.outlook.com (52.133.15.142) by VI1PR08MB1101.eurprd08.prod.outlook.com (10.166.45.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.17; Mon, 10 Sep 2018 10:56:47 +0000 Received: from VI1PR08MB3167.eurprd08.prod.outlook.com ([fe80::b91d:e285:4647:f3e8]) by VI1PR08MB3167.eurprd08.prod.outlook.com ([fe80::b91d:e285:4647:f3e8%2]) with mapi id 15.20.1122.019; Mon, 10 Sep 2018 10:56:47 +0000 From: "Gavin Hu (Arm Technology China)" To: Jens Freimann , "dev@dpdk.org" CC: "tiwei.bie@intel.com" , "maxime.coquelin@redhat.com" Thread-Topic: [dpdk-dev] [PATCH v5 08/11] net/virtio: implement receive path for packed queues Thread-Index: AQHURg5j3f+8jFRpikaQNaeH5HGHa6TpXTOQ Date: Mon, 10 Sep 2018 10:56:47 +0000 Message-ID: References: <20180906181947.20646-1-jfreimann@redhat.com> <20180906181947.20646-9-jfreimann@redhat.com> In-Reply-To: <20180906181947.20646-9-jfreimann@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Gavin.Hu@arm.com; x-originating-ip: [113.29.88.7] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR08MB1101; 6:uNw3XOZa7HIKgtAwZKZpEqb4yS3DnIZY149BLw9ZX+4IAoFiH9i0saZQwOAUphC8M8URzQ5hfeeOahEFcVF58LS1RYI0jo8J6WprNLn+CYAqiw7zfSone8DYFiXCHbAF+Q8Q7Zt4/orGupv+hz3ebpTSIOgcpID2xFbBl5AgzVN813LFW5QVDI/nSDTGDUtE+JpQJPA5ULBq3BVWXR3Y5upN4H0Ho8YZ/4PIB9md/gqBQmSXm49u+8zAo54Zq5qbIUGQ2L5Xjend3anaQZi5Im5A+reRjJDG9ZIdRn+visVQZf9QQVZC40Szdc2mac7Bc8HlPM8k0alf0DAH5mSzGYLAFd1dE4PyRnMhLBA27F0mEcIIiJM1nl45yAYndiHROEL1BuTszNPWFziHcgrW/iL80zbHQRTRMlN5+M0IterzUcug/tv5eQDkbJeQnbFAB7sCgYjIO50KKnb4jxc24Q==; 5:orsLY+Vs5QyzUrsp4K7upWSRPg7B36jupFY+OFTB7ZC3Pew4q3ymsp+BEZfzK2GKycMPzA4SiJheY8zDdbe1lHyqNjmuMOd6fojz5+HX9wX+xJ2zdxFkII9vO4VFNUKG6JbV3x1nOPlqXGCy2KktEmMSYKYJP2q2ojFMqLKU+u4=; 7:1o9PDK6zzzNpSnguJA5uNGmwcE50WsQqHaIX3giKfVGiynLqFdFrmoRKpW7Kd2+lszCMtdhu78w0L2j9hdfcu6tuQ7CAaat0X51oPIx96x11mG8F3Gf+hXk0GhJ7sjSCC0d/lB8iew4TWk/P/+jSSc2+esRNVW6Q0gIfSxLgFoAr0tYjo9LTHH7ejyMIbusIkH8GPx4zvxgLUUvaL+x8bjAZ815RnnozPp09q+awQEQ1VB80e4i/TxeBBbtQ4JYC x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 72da6522-d916-4736-f61c-08d6170c1ac7 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR08MB1101; x-ms-traffictypediagnostic: VI1PR08MB1101: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(131327999870524)(103651359005742)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699050); SRVR:VI1PR08MB1101; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB1101; x-forefront-prvs: 07915F544A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(346002)(396003)(376002)(136003)(366004)(40434004)(13464003)(199004)(189003)(476003)(72206003)(66066001)(229853002)(9686003)(11346002)(26005)(446003)(6436002)(478600001)(55016002)(2501003)(97736004)(256004)(5024004)(14444005)(4326008)(86362001)(6246003)(25786009)(5660300001)(14454004)(5250100002)(54906003)(81166006)(53936002)(81156014)(76176011)(110136005)(316002)(2900100001)(74316002)(53546011)(6506007)(33656002)(305945005)(8936002)(486006)(99286004)(105586002)(106356001)(55236004)(102836004)(7696005)(2906002)(68736007)(6116002)(3846002)(186003)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB1101; H:VI1PR08MB3167.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Xuos1YhADduW+kLYlY2Up/H3QER6McFWi1/twCPb+CEX6DPOaks/wWPgc8YIm2ugfgD5xnO0Y/f+PM6QtIqLyMIDU09V26NFK2EY9x9x+z2t6Zw5Ll5iVIdjYMInBjqSBhjiV0XRedclOTcQhrFumdqu531fiS8BT/ktg2hHXLkK6IBjMgAN2F5gnEoVmDTdGC2qRPdO2ebMwPgAbk3BfkI8tboaQunF0k74K6S9CAE2bLaIFuotZCwJ0omd/jvMkPS9jropHgdxHJRW2MhitdKX158FeJ5gipWeUIBAcm8LgQJ7IdD5ipdMTTenSDwZPvVcunStMXkRudW/k2RomEfP/Ozdr7/V27pPSAK2xe4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72da6522-d916-4736-f61c-08d6170c1ac7 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Sep 2018 10:56:47.4211 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB1101 Subject: Re: [dpdk-dev] [PATCH v5 08/11] net/virtio: implement receive path for packed queues X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Sep 2018 10:56:49 -0000 > -----Original Message----- > From: dev On Behalf Of Jens Freimann > Sent: Friday, September 7, 2018 2:20 AM > To: dev@dpdk.org > Cc: tiwei.bie@intel.com; maxime.coquelin@redhat.com > Subject: [dpdk-dev] [PATCH v5 08/11] net/virtio: implement receive path f= or > packed queues > > Implement the receive part. > > Signed-off-by: Jens Freimann > --- > drivers/net/virtio/virtio_ethdev.c | 15 +++- > drivers/net/virtio/virtio_ethdev.h | 2 + > drivers/net/virtio/virtio_rxtx.c | 131 +++++++++++++++++++++++++++++ > 3 files changed, 145 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/virtio/virtio_ethdev.c > b/drivers/net/virtio/virtio_ethdev.c > index d2c5755bb..a2bb726ba 100644 > --- a/drivers/net/virtio/virtio_ethdev.c > +++ b/drivers/net/virtio/virtio_ethdev.c > @@ -384,8 +384,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t > vtpci_queue_idx) > vq->hw =3D hw; > vq->vq_queue_index =3D vtpci_queue_idx; > vq->vq_nentries =3D vq_size; > -if (vtpci_packed_queue(hw)) > +if (vtpci_packed_queue(hw)) { > vq->vq_ring.avail_wrap_counter =3D 1; > +vq->vq_ring.used_wrap_counter =3D 1; > +} > > /* > * Reserve a memzone for vring elements @@ -1320,7 +1322,13 @@ > set_rxtx_funcs(struct rte_eth_dev *eth_dev) { > struct virtio_hw *hw =3D eth_dev->data->dev_private; > > -if (hw->use_simple_rx) { > +/* > + * workarount for packed vqs which don't support > + * mrg_rxbuf at this point > + */ > +if (vtpci_packed_queue(hw)) { > +eth_dev->rx_pkt_burst =3D &virtio_recv_pkts_packed; > +} else if (hw->use_simple_rx) { > PMD_INIT_LOG(INFO, "virtio: using simple Rx path on > port %u", > eth_dev->data->port_id); > eth_dev->rx_pkt_burst =3D virtio_recv_pkts_vec; @@ -1484,7 > +1492,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t > req_features) > > /* Setting up rx_header size for the device */ > if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) || > - vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) > + vtpci_with_feature(hw, VIRTIO_F_VERSION_1) || > + vtpci_with_feature(hw, VIRTIO_F_RING_PACKED)) > hw->vtnet_hdr_size =3D sizeof(struct > virtio_net_hdr_mrg_rxbuf); > else > hw->vtnet_hdr_size =3D sizeof(struct virtio_net_hdr); diff --git > a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h > index 04161b461..25eaff224 100644 > --- a/drivers/net/virtio/virtio_ethdev.h > +++ b/drivers/net/virtio/virtio_ethdev.h > @@ -70,6 +70,8 @@ int virtio_dev_tx_queue_setup_finish(struct > rte_eth_dev *dev, > > uint16_t virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, > uint16_t nb_pkts); > +uint16_t virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf > **rx_pkts, > +uint16_t nb_pkts); > > uint16_t virtio_recv_mergeable_pkts(void *rx_queue, struct rte_mbuf > **rx_pkts, > uint16_t nb_pkts); > diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio= _rxtx.c > index 12787070e..3f5fa7366 100644 > --- a/drivers/net/virtio/virtio_rxtx.c > +++ b/drivers/net/virtio/virtio_rxtx.c > @@ -31,6 +31,7 @@ > #include "virtqueue.h" > #include "virtio_rxtx.h" > #include "virtio_rxtx_simple.h" > +#include "virtio_ring.h" > > #ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP > #define VIRTIO_DUMP_PACKET(m, len) rte_pktmbuf_dump(stdout, m, len) > @@ -710,6 +711,34 @@ virtio_dev_rx_queue_setup_finish(struct > rte_eth_dev *dev, uint16_t queue_idx) > > PMD_INIT_FUNC_TRACE(); > > +if (vtpci_packed_queue(hw)) { > +struct vring_desc_packed *desc; > +struct vq_desc_extra *dxp; > + > +for (desc_idx =3D 0; desc_idx < vq->vq_nentries; > +desc_idx++) { > +m =3D rte_mbuf_raw_alloc(rxvq->mpool); > +if (unlikely(m =3D=3D NULL)) > +return -ENOMEM; > + > +dxp =3D &vq->vq_descx[desc_idx]; > +dxp->cookie =3D m; > +dxp->ndescs =3D 1; > + > +desc =3D &vq->vq_ring.desc_packed[desc_idx]; > +desc->addr =3D VIRTIO_MBUF_ADDR(m, vq) + > +RTE_PKTMBUF_HEADROOM - hw- > >vtnet_hdr_size; > +desc->len =3D m->buf_len - > RTE_PKTMBUF_HEADROOM + > +hw->vtnet_hdr_size; > +desc->flags |=3D VRING_DESC_F_WRITE; > +rte_smp_wmb(); > +set_desc_avail(&vq->vq_ring, desc); > +} > +vq->vq_ring.avail_wrap_counter ^=3D 1; > +nbufs =3D desc_idx; > +goto out; > +} > + > /* Allocate blank mbufs for the each rx descriptor */ > nbufs =3D 0; > > @@ -773,6 +802,7 @@ virtio_dev_rx_queue_setup_finish(struct > rte_eth_dev *dev, uint16_t queue_idx) > vq_update_avail_idx(vq); > } > > +out: > PMD_INIT_LOG(DEBUG, "Allocated %d bufs", nbufs); > > VIRTQUEUE_DUMP(vq); > @@ -993,6 +1023,107 @@ virtio_rx_offload(struct rte_mbuf *m, struct > virtio_net_hdr *hdr) > return 0; > } > > +uint16_t > +virtio_recv_pkts_packed(void *rx_queue, struct rte_mbuf **rx_pkts, > + uint16_t nb_pkts) > +{ > +struct virtnet_rx *rxvq =3D rx_queue; > +struct virtqueue *vq =3D rxvq->vq; > +struct virtio_hw *hw =3D vq->hw; > +struct rte_mbuf *rxm, *nmb; > +uint16_t nb_rx; > +uint32_t len; > +uint32_t i; > +uint32_t hdr_size; > +struct virtio_net_hdr *hdr; > +struct vring_desc_packed *descs =3D vq->vq_ring.desc_packed; > +struct vring_desc_packed *desc; > +uint16_t used_idx, id; > +struct vq_desc_extra *dxp; > + > +nb_rx =3D 0; > +if (unlikely(hw->started =3D=3D 0)) > +return nb_rx; > + > +hdr_size =3D hw->vtnet_hdr_size; > + > +for (i =3D 0; i < nb_pkts; i++) { > +rte_smp_rmb(); > +used_idx =3D vq->vq_used_cons_idx; > +desc =3D &descs[used_idx]; > +id =3D desc->index; > +if (!desc_is_used(desc, &vq->vq_ring)) > +break; > + > +nmb =3D rte_mbuf_raw_alloc(rxvq->mpool); > +if (unlikely(nmb =3D=3D NULL)) { > +struct rte_eth_dev *dev > +=3D &rte_eth_devices[rxvq->port_id]; > +dev->data->rx_mbuf_alloc_failed++; > +break; > +} > + > +dxp =3D &vq->vq_descx[id]; > +len =3D desc->len; > +rxm =3D dxp->cookie; > +dxp->cookie =3D nmb; > +dxp->ndescs =3D 1; > + > +desc->addr =3D VIRTIO_MBUF_ADDR(nmb, vq) + > +RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size; > +desc->len =3D nmb->buf_len - RTE_PKTMBUF_HEADROOM + > +hw->vtnet_hdr_size; There should be a wmb here? > +desc->flags =3D VRING_DESC_F_WRITE; > + > +PMD_RX_LOG(DEBUG, "packet len:%d", len); > + > +if (unlikely(len < hdr_size + ETHER_HDR_LEN)) { > +PMD_RX_LOG(ERR, "Packet drop"); > +rte_pktmbuf_free(rxm); > +rxvq->stats.errors++; > +continue; > +} > + > +rxm->port =3D rxvq->port_id; > +rxm->data_off =3D RTE_PKTMBUF_HEADROOM; > +rxm->ol_flags =3D 0; > +rxm->vlan_tci =3D 0; > + > +rxm->pkt_len =3D (uint32_t)(len - hdr_size); > +rxm->data_len =3D (uint16_t)(len - hdr_size); > + > +hdr =3D (struct virtio_net_hdr *)((char *)rxm->buf_addr + > +RTE_PKTMBUF_HEADROOM - hdr_size); > + > +if (hw->vlan_strip) > +rte_vlan_strip(rxm); > + > +if (hw->has_rx_offload && virtio_rx_offload(rxm, hdr) < 0) { > +rte_pktmbuf_free(rxm); > +rxvq->stats.errors++; > +continue; > +} > + > +VIRTIO_DUMP_PACKET(rxm, rxm->data_len); > + > +rxvq->stats.bytes +=3D rxm->pkt_len; > +virtio_update_packet_stats(&rxvq->stats, rxm); > + > +rte_smp_wmb(); What's this wmb for? > + > +rx_pkts[nb_rx++] =3D rxm; > +vq->vq_used_cons_idx +=3D dxp->ndescs; > +if (vq->vq_used_cons_idx >=3D vq->vq_nentries) { > +vq->vq_used_cons_idx -=3D vq->vq_nentries; > +vq->vq_ring.used_wrap_counter ^=3D 1; > +} > +} > + > +rxvq->stats.packets +=3D nb_rx; > + > +return nb_rx; > +} > + > #define VIRTIO_MBUF_BURST_SZ 64 > #define DESC_PER_CACHELINE (RTE_CACHE_LINE_SIZE / sizeof(struct > vring_desc)) uint16_t > -- > 2.17.1 IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you.