From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id CA3353421 for ; Fri, 1 Mar 2019 14:47:30 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x21Dkedr009621; Fri, 1 Mar 2019 05:47:30 -0800 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=vQBvQ1KaxBhxdS/XmTYd50ZyUiN48BptVz25qlCUAPM=; b=wWSfa4bK9wvgJ8ht6J3KyxJlfk4hgCZzxFbEX5McDgd/m/9DeNjMouNFhwBCTi5kLJco HwshPY5SeIzSVf6Bssvxv6yWYv16F2XqByj9oBXbz281hYk3fqgC2Rm8cYdRe69SDKET wQVWLLF/WKTLjSZLmg2hkUx/YmByDczYQzWGArGe6wDpMyAOtPOLg930H8eLgozcweTP /CW+FlMn/NsOZu/SQ8L2AS+s43qcIV5P9QJAjgIgXOxb1Q+S7bg/NgLtgBvqNfSRjvFZ JZR4aVz0ys+8k/gxhByGxvcRUwRRvqWiJAfJBrBz92scQqgszf7xID4ozmIYAzM44Vrv bw== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2qxce63p7w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 01 Mar 2019 05:47:30 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 1 Mar 2019 05:47:27 -0800 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (104.47.42.57) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Fri, 1 Mar 2019 05:47:27 -0800 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=vQBvQ1KaxBhxdS/XmTYd50ZyUiN48BptVz25qlCUAPM=; b=Q7WA1FMsAoGGndVTz2iyUlv+J3JJ8DGncfqwYdP3t/t+onWX8rPBYnKXSCVAbdH5wzVGpruJs0WI7TyseqXqZpSYcC2YAOgdXM2yipmGZls7mttvd8vZjoExzmQz/3ckSOZhJOMXxIhoryJa4kPJ9stEZ6BfzD7qLCruq+4BVIM= Received: from BN6PR1801MB1859.namprd18.prod.outlook.com (10.161.154.35) by BN6PR1801MB2002.namprd18.prod.outlook.com (10.161.154.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1643.20; Fri, 1 Mar 2019 13:47:23 +0000 Received: from BN6PR1801MB1859.namprd18.prod.outlook.com ([10.161.154.35]) by BN6PR1801MB1859.namprd18.prod.outlook.com ([10.161.154.35]) with mapi id 15.20.1665.015; Fri, 1 Mar 2019 13:47:22 +0000 From: Pavan Nikhilesh Bhagavatula To: Jerin Jacob Kollanukkaran , "arybchenko@solarflare.com" , "ferruh.yigit@intel.com" , "bernard.iremonger@intel.com" CC: "dev@dpdk.org" , Pavan Nikhilesh Bhagavatula Thread-Topic: [dpdk-dev] [PATCH v2] app/testpmd: add mempool bulk get for txonly mode Thread-Index: AQHU0DVLuB7P1XSHSEu5lxG4QknqzA== Date: Fri, 1 Mar 2019 13:47:22 +0000 Message-ID: <20190301134700.8220-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: LNXP265CA0025.GBRP265.PROD.OUTLOOK.COM (10.166.179.13) To BN6PR1801MB1859.namprd18.prod.outlook.com (10.161.154.35) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [223.226.78.85] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 403cfffb-f329-45c9-8f89-08d69e4c6e32 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:BN6PR1801MB2002; x-ms-traffictypediagnostic: BN6PR1801MB2002: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1; BN6PR1801MB2002; 23:rsy4M8sZ6oFoCUh0zfvY8tv8OWyRk5H5tiFNp?= =?iso-8859-1?Q?v6V62+ylNN0d54yaAmIUfjDGLzL4XN2boi93XfB9YG6qUMdMq1GEajn5ZW?= =?iso-8859-1?Q?jfGdpWMCuH1x8nx9oFDQ7xs0xz1bYnLhTh0bpKfKCwhPAdoIw9u7+aG3mG?= =?iso-8859-1?Q?GQ1xtUaX5mtM/bQDnUpnCjX5q5ajLGmjhrweF6/NmsmX7mPsMrM0gtlAHL?= =?iso-8859-1?Q?QkcAPsGSf7BBQOet1iaLXEKPoPfwOLk/d+CoGR5JtAnKGcLKFrEBE459AR?= =?iso-8859-1?Q?78M+LLVs+Vuw15hoQ0YmwDVY+t2iQaS56i0qEBSU9Hvzc8gvZYRfu3qv/i?= =?iso-8859-1?Q?+7chEL8y0JL5zpnA4z/Fx6rmbWnR/lZL2q1ouktapR+Uh1VGHP2q+bwg98?= =?iso-8859-1?Q?1NPCNg9HwxMK5Ys31GGDFP/COPqMQywB7tPwciz1ELSidH1BzJEApBgLqQ?= =?iso-8859-1?Q?B139x4fJ2kvN6cmYczWXM2gBqLwDhlZi6dbgMCAiRPfIVrA8kHFr+q2gkV?= =?iso-8859-1?Q?TvjobOv1Xs9ELA41ekGY5r0KoGDcYtTBtKrtIR2nf1bAbADTef/vQ3wtT3?= =?iso-8859-1?Q?MQMjjU7vpoy5br6he2EQNY+rjlvPfXxyrZ8ilEuwChlw0pjmQETGhL2mMU?= =?iso-8859-1?Q?R4SZzWgy9jwauG/6LvOglqRZ+lZKRhQEr5O2XcEh+h08JZKhWfVeYEN6qr?= =?iso-8859-1?Q?KeMpb60ZTiGPGDgQA+9FuZTa78ETYoA1CNWxMVkVBgqa3NVyERT4CLXAy8?= =?iso-8859-1?Q?GDTcgt6BFAOwlD+H9cvi/AaovX/iksFTh05m6AEm5CC/o3GJjUUIhXzj9k?= =?iso-8859-1?Q?puCXHnIjCX03WgYgh2fnrN10erOEKXPuWaHT8HhxGhvE3UCaiAlHD8XNBv?= =?iso-8859-1?Q?hB9dthJV3YP6FPXxvmivtKbuHfWwwJpObAlMiRvcU82ExWXP40c0n1a121?= =?iso-8859-1?Q?pFJKRlIt+khZ4rbxFZl1LEThuXt+KWMclW29spqLZOEVOa4TaV8TUIMhjd?= =?iso-8859-1?Q?K+CvF04EvKsFaBVxxe/yDMd2TBgwjJa4bBYNfo42dTyIfeVs7WwoAf9QaK?= =?iso-8859-1?Q?C7t7owGR3jvQUi/T/cT58YxrR7d45thhAPniPdAEC4h5zEzjosSx65Bbhk?= =?iso-8859-1?Q?JDdOl6nX8w11RoaGlPvtvKH6xrS+29bQOcq6FkSo+FZSc10K6o+ZtcUV6U?= =?iso-8859-1?Q?RBNTo0tvlZPkL6QSPzRa6UhSu9Y3JZy+oR5NCQTeym6is9EFUZggQZREe4?= =?iso-8859-1?Q?vEyQBUbPNiWgu7dILc/ubrO2Su5HTMBthNBCGq4mHqGzHe5FRAWvX4CfGJ?= =?iso-8859-1?Q?SbCWwBhOtjdbNDadXhKPLLUjte4gLGZA/LW88HQc6phnfVQaQc7/vd4CcQ?= =?iso-8859-1?Q?7Ycl4oqELM=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 09634B1196 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(346002)(376002)(396003)(136003)(366004)(199004)(189003)(86362001)(1076003)(110136005)(316002)(81156014)(8676002)(81166006)(76176011)(486006)(446003)(99286004)(11346002)(2616005)(476003)(52116002)(2501003)(54906003)(386003)(6506007)(102836004)(256004)(26005)(77096007)(25786009)(2201001)(55236004)(66066001)(186003)(8936002)(3846002)(6116002)(7736002)(14454004)(305945005)(4326008)(6486002)(6436002)(478600001)(71190400001)(71200400001)(68736007)(5660300002)(106356001)(97736004)(105586002)(36756003)(2906002)(50226002)(107886003)(6512007)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1801MB2002; H:BN6PR1801MB1859.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: tkqkLd+v2YG8W5QtB3SjjW+bYWG0yCVJQrdgjGanKDZ44qrKrhKiV+f+34lp5rlLvLEyI/gMmk6zLd4vdIcfBBcwKeqq8iKZoepNSOSXMdGq0j4BOvUSziclpi3fYZKVK9eIGCCCY3sm8HTr5xEC2HIGKJfT+zlIKxl5FyR6fMVxZCXf9wdtbGv0wOXFuVnpXwRLv/YGo8JquNX/83oFxISUQWET9XDwtbFsLj/Er4FydqXNz0REeV4/ZB9Rsqno+SdHWpRP/NTp0Z11gwtZ9bnfQCnTygZz0YRgUSVPQp9VhJheRuWjgkKWuRj6oVYWoAlkaN+Shgt3G2MdTdI8YetjOvzmJEytiD8MKe942K7wtRRC61LOduMSu5MuUfFMbcoa4Rk36lyqRUVYimJHzO4BbWcsaIHRrzD4p/y95Zw= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 403cfffb-f329-45c9-8f89-08d69e4c6e32 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Mar 2019 13:47:22.7597 (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: BN6PR1801MB2002 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-01_10:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903010097 Subject: [dpdk-dev] [PATCH v2] app/testpmd: add mempool bulk get for 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: Fri, 01 Mar 2019 13:47:31 -0000 From: Pavan Nikhilesh Use mempool bulk get ops to alloc burst of packets and process them. If bulk get fails fallback to rte_mbuf_raw_alloc. Suggested-by: Andrew Rybchenko Signed-off-by: Pavan Nikhilesh --- 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 | 159 ++++++++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 66 deletions(-) diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 1f08b6ed3..af0be89ca 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 =3D 0; + 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,46 @@ 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; - 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; - 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; + /* + * 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); + + if (rte_mempool_get_bulk(mbp, (void **)pkts_burst, + nb_pkt_per_burst) =3D=3D 0) { + for (nb_pkt =3D 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) { + if (unlikely(!pkt_burst_prepare(pkts_burst[nb_pkt], mbp, + ð_hdr, vlan_tci, + vlan_tci_outer, + ol_flags))) { + rte_mempool_put_bulk(mbp, + (void **)&pkts_burst[nb_pkt], + nb_pkt_per_burst - nb_pkt); + break; + } + } + } else { + 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) + break; + if (unlikely(!pkt_burst_prepare(pkt, mbp, + ð_hdr, vlan_tci, + vlan_tci_outer, + ol_flags))) { + rte_mempool_put(mbp, pkt); + break; } - pkt_seg =3D pkt_seg->next; - pkt_seg->data_len =3D tx_pkt_seg_lengths[i]; - pkt_len +=3D pkt_seg->data_len; + pkts_burst[nb_pkt] =3D pkt; } - 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.21.0