From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 7C14C324D for ; Tue, 26 Mar 2019 13:27:16 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2QCQZIV009078; Tue, 26 Mar 2019 05:27:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=NfmrZrzzjOtYt4TNFgi0vZ432rjK11NCIvsF0hRt/uI=; b=MISPA4IHXUJCEt4Ofw3hvbRA2npRun7AQN5TSHtg7p+tZX8vVyR8TnDcpgTbNoMFSK8Z Yw12Db8a4BomU4MynDb2RwRla8QIpZMH0IeVTl4Ktky41Gf35Dd5RJG14typUdb+g1WL NGBXQ9qUFg+uS+iH30c49LyVEoC5+5BbZ5w4PFJhk76VhXYQdyRVPB/U4qLWXvUex9HL pVUynUgc/8y406aFYoF7IQ51LpNCmgpt7nmBQ+/BuI23tQ2RJa07D+pBfM78IQMId+jc IqUPPr6iclrsg4wrr0NRf2EmDHlK7O21umU1xdRsgiWokZRY1hUhTHFGLwD5c35dabsr DA== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 2rfhk90e3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 26 Mar 2019 05:27:15 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 26 Mar 2019 05:27:04 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.53) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Tue, 26 Mar 2019 05:27:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NfmrZrzzjOtYt4TNFgi0vZ432rjK11NCIvsF0hRt/uI=; b=qI3ASZne1IN/r7cFTEpOW1/Ug2ZNFeug8jCz31v0xXXeIRmqfdMiDaJ7ZPTpwfRZEbNqdRGHQ6++3VyiGCdU8ghRcnmd0oGiRgVLOJue0wlGXFwvHnu6aQMbkFMlXj5y9NcLxuqg3E5BuCQkuBvtazNWBB2L1DHZLM6SyS3iQi4= Received: from CY4PR1801MB1863.namprd18.prod.outlook.com (10.171.255.14) by CY4PR1801MB1942.namprd18.prod.outlook.com (10.171.255.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.15; Tue, 26 Mar 2019 12:26:59 +0000 Received: from CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa]) by CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa%2]) with mapi id 15.20.1750.014; Tue, 26 Mar 2019 12:26:59 +0000 From: Pavan Nikhilesh Bhagavatula To: Jerin Jacob Kollanukkaran , "thomas@monjalon.net" , "arybchenko@solarflare.com" , "ferruh.yigit@intel.com" , "bernard.iremonger@intel.com" CC: "dev@dpdk.org" , Pavan Nikhilesh Bhagavatula Thread-Topic: [dpdk-dev] [PATCH v3 1/2] app/testpmd: optimize testpmd txonly mode Thread-Index: AQHU4881I23/sTBCOkyOWVgRSqsDCQ== Date: Tue, 26 Mar 2019 12:26:59 +0000 Message-ID: <20190326122625.10540-1-pbhagavatula@marvell.com> References: <20190228194128.14236-1-pbhagavatula@marvell.com> In-Reply-To: <20190228194128.14236-1-pbhagavatula@marvell.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR0401CA0022.apcprd04.prod.outlook.com (2603:1096:3:1::32) To CY4PR1801MB1863.namprd18.prod.outlook.com (2603:10b6:910:7a::14) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [183.82.23.126] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5d6d308e-82df-4c58-4f8b-08d6b1e657a5 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:CY4PR1801MB1942; x-ms-traffictypediagnostic: CY4PR1801MB1942: x-microsoft-antispam-prvs: x-forefront-prvs: 09888BC01D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(376002)(346002)(199004)(189003)(8936002)(50226002)(110136005)(54906003)(97736004)(36756003)(316002)(2906002)(105586002)(68736007)(66066001)(106356001)(8676002)(81156014)(486006)(86362001)(102836004)(76176011)(6506007)(386003)(2201001)(52116002)(26005)(81166006)(186003)(4326008)(78486014)(6512007)(71200400001)(53936002)(6486002)(7736002)(305945005)(6436002)(1076003)(14454004)(3846002)(2501003)(25786009)(6116002)(478600001)(99286004)(11346002)(107886003)(2616005)(476003)(446003)(256004)(71190400001)(5660300002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1801MB1942; H:CY4PR1801MB1863.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: /hw75/u/4z0c9cvxolnSJfcfkdARkNBcgWUhJGQ7B47EViIt4K6Q9r8cKorwN6coFmX/SRxgRX/GgbNSEhVA6OzLasKFphagAhpFjXaq+fOrn+37/BkSinnUatWi4dxsCzTcEx3HDA/yLBYNcnMcKNglgNpfOUMU9V8bRfT6hLaLV2Mge+CCdQ6crnW8is27BO5iw9A74ijMAX5HmeR/lBDFEPml+7xk4OXrj8Ef/PjkgBCNcZZ7VZkxgEZYIcJTMeRKpORuUZnrvSThf0zE4TY9aD1hhlAGcovgXgBjONFREIorNhy0SEFfkSx20uYSU0Htg5xyclYPMJdDsMvQcPhvjlu/htIpVQmjxerkHmdjgDvxz8kv/ziy4X0/bmeNC6puytylgV2CFU3KVpgjUWxP+DOxuO0SOfwYUOGbifE= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 5d6d308e-82df-4c58-4f8b-08d6b1e657a5 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Mar 2019 12:26:59.6083 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1801MB1942 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-26_09:, , signatures=0 Subject: [dpdk-dev] [PATCH v3 1/2] app/testpmd: optimize testpmd txonly mode 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: Tue, 26 Mar 2019 12:27:16 -0000 From: Pavan Nikhilesh Optimize testpmd txonly mode by 1. Moving per packet ethernet header copy above the loop. 2. Use bulk ops for allocating segments instead of having a inner loop for every segment. Also, move the packet prepare logic into a separate function so that it can be reused later. Signed-off-by: Pavan Nikhilesh --- v3 Changes: - Split the patches for easier review. (Thomas) - Remove unnecessary assignments to 0. (Bernard) v2 Changes: - Use bulk ops for fetching segments. (Andrew Rybchenko) - Fallback to rte_mbuf_raw_alloc if bulk get fails. (Andrew Rybchenko) - Fix mbufs not being freed when there is no more mbufs available for segments. (Andrew Rybchenko) app/test-pmd/txonly.c | 140 +++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 64 deletions(-) diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 1f08b6ed3..5610e0e42 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -147,6 +147,62 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr, ip_hdr->hdr_checksum =3D (uint16_t) ip_cksum; } +static inline bool +pkt_burst_prepare(struct rte_mbuf *pkt, struct rte_mempool *mbp, + struct ether_hdr *eth_hdr, const uint16_t vlan_tci, + const uint16_t vlan_tci_outer, const uint64_t ol_flags) +{ + struct rte_mbuf *pkt_segs[RTE_MAX_SEGS_PER_PKT]; + struct rte_mbuf *pkt_seg; + uint32_t nb_segs, pkt_len; + uint8_t i; + + if (unlikely(tx_pkt_split =3D=3D TX_PKT_SPLIT_RND)) + nb_segs =3D random() % tx_pkt_nb_segs + 1; + else + nb_segs =3D tx_pkt_nb_segs; + + if (nb_segs > 1) { + if (rte_mempool_get_bulk(mbp, (void **)pkt_segs, nb_segs)) + return false; + } + + rte_pktmbuf_reset_headroom(pkt); + pkt->data_len =3D tx_pkt_seg_lengths[0]; + pkt->ol_flags =3D ol_flags; + pkt->vlan_tci =3D vlan_tci; + pkt->vlan_tci_outer =3D vlan_tci_outer; + pkt->l2_len =3D sizeof(struct ether_hdr); + pkt->l3_len =3D sizeof(struct ipv4_hdr); + + pkt_seg =3D pkt; + for (i =3D 1; i < nb_segs; i++) { + pkt_seg->next =3D pkt_segs[i - 1]; + pkt_seg =3D pkt_seg->next; + pkt_seg->data_len =3D tx_pkt_seg_lengths[i]; + pkt_len +=3D pkt_seg->data_len; + } + pkt_seg->next =3D NULL; /* Last segment of packet. */ + /* + * Copy headers in first packet segment(s). + */ + copy_buf_to_pkt(eth_hdr, sizeof(eth_hdr), pkt, 0); + copy_buf_to_pkt(&pkt_ip_hdr, sizeof(pkt_ip_hdr), pkt, + sizeof(struct ether_hdr)); + copy_buf_to_pkt(&pkt_udp_hdr, sizeof(pkt_udp_hdr), pkt, + sizeof(struct ether_hdr) + + sizeof(struct ipv4_hdr)); + + /* + * Complete first mbuf of packet and append it to the + * burst of packets to be transmitted. + */ + pkt->nb_segs =3D nb_segs; + pkt->pkt_len +=3D pkt_len; + + return true; +} + /* * Transmit a burst of multi-segments packets. */ @@ -154,9 +210,8 @@ static void pkt_burst_transmit(struct fwd_stream *fs) { struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; - struct rte_port *txp; struct rte_mbuf *pkt; - struct rte_mbuf *pkt_seg; + struct rte_port *txp; struct rte_mempool *mbp; struct ether_hdr eth_hdr; uint16_t nb_tx; @@ -164,14 +219,12 @@ pkt_burst_transmit(struct fwd_stream *fs) uint16_t vlan_tci, vlan_tci_outer; uint32_t retry; uint64_t ol_flags =3D 0; - uint8_t i; uint64_t tx_offloads; #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES uint64_t start_tsc; uint64_t end_tsc; uint64_t core_cycles; #endif - uint32_t nb_segs, pkt_len; #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES start_tsc =3D rte_rdtsc(); @@ -188,72 +241,31 @@ pkt_burst_transmit(struct fwd_stream *fs) ol_flags |=3D PKT_TX_QINQ_PKT; if (tx_offloads & DEV_TX_OFFLOAD_MACSEC_INSERT) ol_flags |=3D PKT_TX_MACSEC; + + /* + * Initialize Ethernet header. + */ + ether_addr_copy(&peer_eth_addrs[fs->peer_addr], ð_hdr.d_addr); + ether_addr_copy(&ports[fs->tx_port].eth_addr, ð_hdr.s_addr); + eth_hdr.ether_type =3D rte_cpu_to_be_16(ETHER_TYPE_IPv4); + for (nb_pkt =3D 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) { pkt =3D rte_mbuf_raw_alloc(mbp); - if (pkt =3D=3D NULL) { - nomore_mbuf: - if (nb_pkt =3D=3D 0) - return; + if (pkt =3D=3D NULL) + break; + if (unlikely(!pkt_burst_prepare(pkt, mbp, + ð_hdr, vlan_tci, + vlan_tci_outer, + ol_flags))) { + rte_mempool_put(mbp, pkt); break; } - - /* - * Using raw alloc is good to improve performance, - * but some consumers may use the headroom and so - * decrement data_off. We need to make sure it is - * reset to default value. - */ - rte_pktmbuf_reset_headroom(pkt); - pkt->data_len =3D tx_pkt_seg_lengths[0]; - pkt_seg =3D pkt; - if (tx_pkt_split =3D=3D TX_PKT_SPLIT_RND) - nb_segs =3D random() % tx_pkt_nb_segs + 1; - else - nb_segs =3D tx_pkt_nb_segs; - pkt_len =3D pkt->data_len; - for (i =3D 1; i < nb_segs; i++) { - pkt_seg->next =3D rte_mbuf_raw_alloc(mbp); - if (pkt_seg->next =3D=3D NULL) { - pkt->nb_segs =3D i; - rte_pktmbuf_free(pkt); - goto nomore_mbuf; - } - pkt_seg =3D pkt_seg->next; - pkt_seg->data_len =3D tx_pkt_seg_lengths[i]; - pkt_len +=3D pkt_seg->data_len; - } - pkt_seg->next =3D NULL; /* Last segment of packet. */ - - /* - * Initialize Ethernet header. - */ - ether_addr_copy(&peer_eth_addrs[fs->peer_addr],ð_hdr.d_addr); - ether_addr_copy(&ports[fs->tx_port].eth_addr, ð_hdr.s_addr); - eth_hdr.ether_type =3D rte_cpu_to_be_16(ETHER_TYPE_IPv4); - - /* - * Copy headers in first packet segment(s). - */ - copy_buf_to_pkt(ð_hdr, sizeof(eth_hdr), pkt, 0); - copy_buf_to_pkt(&pkt_ip_hdr, sizeof(pkt_ip_hdr), pkt, - sizeof(struct ether_hdr)); - copy_buf_to_pkt(&pkt_udp_hdr, sizeof(pkt_udp_hdr), pkt, - sizeof(struct ether_hdr) + - sizeof(struct ipv4_hdr)); - - /* - * Complete first mbuf of packet and append it to the - * burst of packets to be transmitted. - */ - pkt->nb_segs =3D nb_segs; - pkt->pkt_len =3D pkt_len; - pkt->ol_flags =3D ol_flags; - pkt->vlan_tci =3D vlan_tci; - pkt->vlan_tci_outer =3D vlan_tci_outer; - pkt->l2_len =3D sizeof(struct ether_hdr); - pkt->l3_len =3D sizeof(struct ipv4_hdr); pkts_burst[nb_pkt] =3D pkt; } + + if (nb_pkt =3D=3D 0) + return; + nb_tx =3D rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt)= ; /* * Retry if necessary -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 394ABA05D3 for ; Tue, 26 Mar 2019 13:27:18 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 031EC3572; Tue, 26 Mar 2019 13:27:18 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 7C14C324D for ; Tue, 26 Mar 2019 13:27:16 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2QCQZIV009078; Tue, 26 Mar 2019 05:27:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=NfmrZrzzjOtYt4TNFgi0vZ432rjK11NCIvsF0hRt/uI=; b=MISPA4IHXUJCEt4Ofw3hvbRA2npRun7AQN5TSHtg7p+tZX8vVyR8TnDcpgTbNoMFSK8Z Yw12Db8a4BomU4MynDb2RwRla8QIpZMH0IeVTl4Ktky41Gf35Dd5RJG14typUdb+g1WL NGBXQ9qUFg+uS+iH30c49LyVEoC5+5BbZ5w4PFJhk76VhXYQdyRVPB/U4qLWXvUex9HL pVUynUgc/8y406aFYoF7IQ51LpNCmgpt7nmBQ+/BuI23tQ2RJa07D+pBfM78IQMId+jc IqUPPr6iclrsg4wrr0NRf2EmDHlK7O21umU1xdRsgiWokZRY1hUhTHFGLwD5c35dabsr DA== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0a-0016f401.pphosted.com with ESMTP id 2rfhk90e3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 26 Mar 2019 05:27:15 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 26 Mar 2019 05:27:04 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.53) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Tue, 26 Mar 2019 05:27:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NfmrZrzzjOtYt4TNFgi0vZ432rjK11NCIvsF0hRt/uI=; b=qI3ASZne1IN/r7cFTEpOW1/Ug2ZNFeug8jCz31v0xXXeIRmqfdMiDaJ7ZPTpwfRZEbNqdRGHQ6++3VyiGCdU8ghRcnmd0oGiRgVLOJue0wlGXFwvHnu6aQMbkFMlXj5y9NcLxuqg3E5BuCQkuBvtazNWBB2L1DHZLM6SyS3iQi4= Received: from CY4PR1801MB1863.namprd18.prod.outlook.com (10.171.255.14) by CY4PR1801MB1942.namprd18.prod.outlook.com (10.171.255.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.15; Tue, 26 Mar 2019 12:26:59 +0000 Received: from CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa]) by CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa%2]) with mapi id 15.20.1750.014; Tue, 26 Mar 2019 12:26:59 +0000 From: Pavan Nikhilesh Bhagavatula To: Jerin Jacob Kollanukkaran , "thomas@monjalon.net" , "arybchenko@solarflare.com" , "ferruh.yigit@intel.com" , "bernard.iremonger@intel.com" CC: "dev@dpdk.org" , Pavan Nikhilesh Bhagavatula Thread-Topic: [dpdk-dev] [PATCH v3 1/2] app/testpmd: optimize testpmd txonly mode Thread-Index: AQHU4881I23/sTBCOkyOWVgRSqsDCQ== Date: Tue, 26 Mar 2019 12:26:59 +0000 Message-ID: <20190326122625.10540-1-pbhagavatula@marvell.com> References: <20190228194128.14236-1-pbhagavatula@marvell.com> In-Reply-To: <20190228194128.14236-1-pbhagavatula@marvell.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR0401CA0022.apcprd04.prod.outlook.com (2603:1096:3:1::32) To CY4PR1801MB1863.namprd18.prod.outlook.com (2603:10b6:910:7a::14) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [183.82.23.126] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5d6d308e-82df-4c58-4f8b-08d6b1e657a5 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:CY4PR1801MB1942; x-ms-traffictypediagnostic: CY4PR1801MB1942: x-microsoft-antispam-prvs: x-forefront-prvs: 09888BC01D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(376002)(346002)(199004)(189003)(8936002)(50226002)(110136005)(54906003)(97736004)(36756003)(316002)(2906002)(105586002)(68736007)(66066001)(106356001)(8676002)(81156014)(486006)(86362001)(102836004)(76176011)(6506007)(386003)(2201001)(52116002)(26005)(81166006)(186003)(4326008)(78486014)(6512007)(71200400001)(53936002)(6486002)(7736002)(305945005)(6436002)(1076003)(14454004)(3846002)(2501003)(25786009)(6116002)(478600001)(99286004)(11346002)(107886003)(2616005)(476003)(446003)(256004)(71190400001)(5660300002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1801MB1942; H:CY4PR1801MB1863.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: /hw75/u/4z0c9cvxolnSJfcfkdARkNBcgWUhJGQ7B47EViIt4K6Q9r8cKorwN6coFmX/SRxgRX/GgbNSEhVA6OzLasKFphagAhpFjXaq+fOrn+37/BkSinnUatWi4dxsCzTcEx3HDA/yLBYNcnMcKNglgNpfOUMU9V8bRfT6hLaLV2Mge+CCdQ6crnW8is27BO5iw9A74ijMAX5HmeR/lBDFEPml+7xk4OXrj8Ef/PjkgBCNcZZ7VZkxgEZYIcJTMeRKpORuUZnrvSThf0zE4TY9aD1hhlAGcovgXgBjONFREIorNhy0SEFfkSx20uYSU0Htg5xyclYPMJdDsMvQcPhvjlu/htIpVQmjxerkHmdjgDvxz8kv/ziy4X0/bmeNC6puytylgV2CFU3KVpgjUWxP+DOxuO0SOfwYUOGbifE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 5d6d308e-82df-4c58-4f8b-08d6b1e657a5 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Mar 2019 12:26:59.6083 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1801MB1942 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-26_09:, , signatures=0 Subject: [dpdk-dev] [PATCH v3 1/2] app/testpmd: optimize testpmd txonly mode 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190326122659.dJ8T39IzD1zA79aE4zujS9DKbAZcs4bffVBgK58GfUU@z> From: Pavan Nikhilesh Optimize testpmd txonly mode by 1. Moving per packet ethernet header copy above the loop. 2. Use bulk ops for allocating segments instead of having a inner loop for every segment. Also, move the packet prepare logic into a separate function so that it can be reused later. Signed-off-by: Pavan Nikhilesh --- v3 Changes: - Split the patches for easier review. (Thomas) - Remove unnecessary assignments to 0. (Bernard) v2 Changes: - Use bulk ops for fetching segments. (Andrew Rybchenko) - Fallback to rte_mbuf_raw_alloc if bulk get fails. (Andrew Rybchenko) - Fix mbufs not being freed when there is no more mbufs available for segments. (Andrew Rybchenko) app/test-pmd/txonly.c | 140 +++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 64 deletions(-) diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 1f08b6ed3..5610e0e42 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -147,6 +147,62 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr, ip_hdr->hdr_checksum =3D (uint16_t) ip_cksum; } +static inline bool +pkt_burst_prepare(struct rte_mbuf *pkt, struct rte_mempool *mbp, + struct ether_hdr *eth_hdr, const uint16_t vlan_tci, + const uint16_t vlan_tci_outer, const uint64_t ol_flags) +{ + struct rte_mbuf *pkt_segs[RTE_MAX_SEGS_PER_PKT]; + struct rte_mbuf *pkt_seg; + uint32_t nb_segs, pkt_len; + uint8_t i; + + if (unlikely(tx_pkt_split =3D=3D TX_PKT_SPLIT_RND)) + nb_segs =3D random() % tx_pkt_nb_segs + 1; + else + nb_segs =3D tx_pkt_nb_segs; + + if (nb_segs > 1) { + if (rte_mempool_get_bulk(mbp, (void **)pkt_segs, nb_segs)) + return false; + } + + rte_pktmbuf_reset_headroom(pkt); + pkt->data_len =3D tx_pkt_seg_lengths[0]; + pkt->ol_flags =3D ol_flags; + pkt->vlan_tci =3D vlan_tci; + pkt->vlan_tci_outer =3D vlan_tci_outer; + pkt->l2_len =3D sizeof(struct ether_hdr); + pkt->l3_len =3D sizeof(struct ipv4_hdr); + + pkt_seg =3D pkt; + for (i =3D 1; i < nb_segs; i++) { + pkt_seg->next =3D pkt_segs[i - 1]; + pkt_seg =3D pkt_seg->next; + pkt_seg->data_len =3D tx_pkt_seg_lengths[i]; + pkt_len +=3D pkt_seg->data_len; + } + pkt_seg->next =3D NULL; /* Last segment of packet. */ + /* + * Copy headers in first packet segment(s). + */ + copy_buf_to_pkt(eth_hdr, sizeof(eth_hdr), pkt, 0); + copy_buf_to_pkt(&pkt_ip_hdr, sizeof(pkt_ip_hdr), pkt, + sizeof(struct ether_hdr)); + copy_buf_to_pkt(&pkt_udp_hdr, sizeof(pkt_udp_hdr), pkt, + sizeof(struct ether_hdr) + + sizeof(struct ipv4_hdr)); + + /* + * Complete first mbuf of packet and append it to the + * burst of packets to be transmitted. + */ + pkt->nb_segs =3D nb_segs; + pkt->pkt_len +=3D pkt_len; + + return true; +} + /* * Transmit a burst of multi-segments packets. */ @@ -154,9 +210,8 @@ static void pkt_burst_transmit(struct fwd_stream *fs) { struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; - struct rte_port *txp; struct rte_mbuf *pkt; - struct rte_mbuf *pkt_seg; + struct rte_port *txp; struct rte_mempool *mbp; struct ether_hdr eth_hdr; uint16_t nb_tx; @@ -164,14 +219,12 @@ pkt_burst_transmit(struct fwd_stream *fs) uint16_t vlan_tci, vlan_tci_outer; uint32_t retry; uint64_t ol_flags =3D 0; - uint8_t i; uint64_t tx_offloads; #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES uint64_t start_tsc; uint64_t end_tsc; uint64_t core_cycles; #endif - uint32_t nb_segs, pkt_len; #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES start_tsc =3D rte_rdtsc(); @@ -188,72 +241,31 @@ pkt_burst_transmit(struct fwd_stream *fs) ol_flags |=3D PKT_TX_QINQ_PKT; if (tx_offloads & DEV_TX_OFFLOAD_MACSEC_INSERT) ol_flags |=3D PKT_TX_MACSEC; + + /* + * Initialize Ethernet header. + */ + ether_addr_copy(&peer_eth_addrs[fs->peer_addr], ð_hdr.d_addr); + ether_addr_copy(&ports[fs->tx_port].eth_addr, ð_hdr.s_addr); + eth_hdr.ether_type =3D rte_cpu_to_be_16(ETHER_TYPE_IPv4); + for (nb_pkt =3D 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) { pkt =3D rte_mbuf_raw_alloc(mbp); - if (pkt =3D=3D NULL) { - nomore_mbuf: - if (nb_pkt =3D=3D 0) - return; + if (pkt =3D=3D NULL) + break; + if (unlikely(!pkt_burst_prepare(pkt, mbp, + ð_hdr, vlan_tci, + vlan_tci_outer, + ol_flags))) { + rte_mempool_put(mbp, pkt); break; } - - /* - * Using raw alloc is good to improve performance, - * but some consumers may use the headroom and so - * decrement data_off. We need to make sure it is - * reset to default value. - */ - rte_pktmbuf_reset_headroom(pkt); - pkt->data_len =3D tx_pkt_seg_lengths[0]; - pkt_seg =3D pkt; - if (tx_pkt_split =3D=3D TX_PKT_SPLIT_RND) - nb_segs =3D random() % tx_pkt_nb_segs + 1; - else - nb_segs =3D tx_pkt_nb_segs; - pkt_len =3D pkt->data_len; - for (i =3D 1; i < nb_segs; i++) { - pkt_seg->next =3D rte_mbuf_raw_alloc(mbp); - if (pkt_seg->next =3D=3D NULL) { - pkt->nb_segs =3D i; - rte_pktmbuf_free(pkt); - goto nomore_mbuf; - } - pkt_seg =3D pkt_seg->next; - pkt_seg->data_len =3D tx_pkt_seg_lengths[i]; - pkt_len +=3D pkt_seg->data_len; - } - pkt_seg->next =3D NULL; /* Last segment of packet. */ - - /* - * Initialize Ethernet header. - */ - ether_addr_copy(&peer_eth_addrs[fs->peer_addr],ð_hdr.d_addr); - ether_addr_copy(&ports[fs->tx_port].eth_addr, ð_hdr.s_addr); - eth_hdr.ether_type =3D rte_cpu_to_be_16(ETHER_TYPE_IPv4); - - /* - * Copy headers in first packet segment(s). - */ - copy_buf_to_pkt(ð_hdr, sizeof(eth_hdr), pkt, 0); - copy_buf_to_pkt(&pkt_ip_hdr, sizeof(pkt_ip_hdr), pkt, - sizeof(struct ether_hdr)); - copy_buf_to_pkt(&pkt_udp_hdr, sizeof(pkt_udp_hdr), pkt, - sizeof(struct ether_hdr) + - sizeof(struct ipv4_hdr)); - - /* - * Complete first mbuf of packet and append it to the - * burst of packets to be transmitted. - */ - pkt->nb_segs =3D nb_segs; - pkt->pkt_len =3D pkt_len; - pkt->ol_flags =3D ol_flags; - pkt->vlan_tci =3D vlan_tci; - pkt->vlan_tci_outer =3D vlan_tci_outer; - pkt->l2_len =3D sizeof(struct ether_hdr); - pkt->l3_len =3D sizeof(struct ipv4_hdr); pkts_burst[nb_pkt] =3D pkt; } + + if (nb_pkt =3D=3D 0) + return; + nb_tx =3D rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_pkt)= ; /* * Retry if necessary -- 2.20.1