From patchwork Fri Jul 22 10:04:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Elo, Matias \(Nokia - FI/Espoo\)" X-Patchwork-Id: 72608 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp912933qga; Fri, 22 Jul 2016 03:08:57 -0700 (PDT) X-Received: by 10.237.45.34 with SMTP id h31mr4829123qtd.101.1469182136933; Fri, 22 Jul 2016 03:08:56 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f6si8205251qka.311.2016.07.22.03.08.56; Fri, 22 Jul 2016 03:08:56 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE dis=NONE) header.from=nokia.com Received: by lists.linaro.org (Postfix, from userid 109) id 6E26768413; Fri, 22 Jul 2016 10:08:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 3559D68254; Fri, 22 Jul 2016 10:08:48 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id CE49868410; Fri, 22 Jul 2016 10:08:45 +0000 (UTC) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40090.outbound.protection.outlook.com [40.107.4.90]) by lists.linaro.org (Postfix) with ESMTPS id 16EF4615D2 for ; Fri, 22 Jul 2016 10:08:44 +0000 (UTC) Received: from DB6PR0701CA0007.eurprd07.prod.outlook.com (10.168.7.145) by DB4PR07MB0495.eurprd07.prod.outlook.com (10.242.195.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.10; Fri, 22 Jul 2016 10:05:54 +0000 Received: from AM1FFO11FD031.protection.gbl (2a01:111:f400:7e00::182) by DB6PR0701CA0007.outlook.office365.com (2603:10a6:4:3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.10 via Frontend Transport; Fri, 22 Jul 2016 10:05:54 +0000 Received-SPF: Pass (protection.outlook.com: domain of nokia.com designates 131.228.2.241 as permitted sender) receiver=protection.outlook.com; client-ip=131.228.2.241; helo=fihe3nok0735.emea.nsn-net.net; Received: from fihe3nok0735.emea.nsn-net.net (131.228.2.241) by AM1FFO11FD031.mail.protection.outlook.com (10.174.64.220) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Fri, 22 Jul 2016 10:05:55 +0000 Received: from fihe3nok0735.emea.nsn-net.net (localhost [127.0.0.1]) by fihe3nok0735.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id u6MA5WfN013415 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Jul 2016 13:05:32 +0300 Received: from 10.144.19.15 ([10.144.104.111]) by fihe3nok0735.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id u6MA5MWT013147 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NOT); Fri, 22 Jul 2016 13:05:32 +0300 X-HPESVCS-Source-Ip: 10.144.104.111 From: Matias Elo To: Date: Fri, 22 Jul 2016 13:04:55 +0300 Message-ID: <1469181897-19168-2-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469181897-19168-1-git-send-email-matias.elo@nokia.com> References: <1469181897-19168-1-git-send-email-matias.elo@nokia.com> X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:131.228.2.241; IPV:NLI; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(7916002)(2980300002)(438002)(199003)(189002)(2906002)(68736007)(2950100001)(50466002)(48376002)(356003)(586003)(305945005)(4326007)(4001430100002)(8676002)(7846002)(47776003)(11100500001)(19580405001)(5003940100001)(575784001)(16796002)(50986999)(76176999)(450100001)(6806005)(92566002)(87936001)(19580395003)(33646002)(229853001)(2351001)(8936002)(50226002)(36756003)(106466001)(77096005)(189998001)(97736004)(110136002)(81156014)(81166006)(107886002)(42882005); DIR:OUT; SFP:1102; SCL:1; SRVR:DB4PR07MB0495; H:fihe3nok0735.emea.nsn-net.net; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD031; 1:DEWsL5VZe9RuxS4+9qiN6jrwSJYlDnedoh6nE1iA43hW929qdb1Uw4JRY3qInXPdYLGo8jr5UuAxoC91dgXpTr/E4n4/xYtKkgl4OhOG+rLL3Ju4c9ljsmLWQHsYYnzAIgYEmYp5Tn9kAS4uZnHw8p0wyLUpUVokmSgcazSiWIBC+7mU07ZbAhgc+a2zpQu/gfR/FvgK/Fi+rWM7LcI2yFzSrhCzCWwvT1tnQ0eJBSOr12VnQ07dsBjFaAs1WfP8C3u6S+489Vqwm/cblOxTGQWONX1JW8oTxR5m3bl8bNwA3r623CxzcFeHaJfzxmgDGR0GHjSy28PpFQY41DWIphGrMuNZHPIsvEEYI8PAPeF/f8PdwfCvYafGI2L3hJ96AeLrKIo+sX8IK9BvH/bwtfZewbuZH3ds9lQCYCmtlD94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nVPZgwxwfJ9GafGF/+LseqKIyITepU6wCrTn6acK57KGpy5Pg= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:DB4PR07MB0495; X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB0495; 31:4zEIZY6RaWop2eiZ+OIMDxysBonEHWKsDz2UIZNSj+mkMa3lWtrOV1/kKySBnOR9jP2atauVXirvbdN5UwWzrExTjlyIxR3c+H1wMVWALb1NwlOF9odhrrKJw5oEAAD8dvvCrxr3tx4FiiQ9uwMnaXf9xllHSAYYl7VTMA3zKkucZDBZE+IqD6r3WejIvEY7UCczKtBcnlHCfVnY8CE28A==; 20:bDnK1qaEvdgOlqi1yAfI8hhA0WmIYtm4w4M+xdPbPR2DZVwLJB65yqjHT0b5Dks+jnRyVaGVV8FdEg2oC9aMA1ZMGW2YRmruQuYCxhuH99cx2hU22V8bGTdqSoF+WN5PZmTdHy+LpkkIIUXyc76sgi+LYn12JV0m+Q39PZnzjQwIeG6CrwdNPSpg9Hv1fvvFqLMlHj0BaaDcnc1+eHc2e2umrs3JB2HgaOofKkRmauBN8haDVtvjrBlk023DV0gzcZ5IZ8O3L4TgZfGf5VdG+ai1HdSbJgtYE5rm6XRjQVunXZ5aUjw9HHcbh3dZg1I06+EhajisuQEqfzakjjV8g/y9S3StXSZoq2Zr/at27uqcWmaUT6RYYCSbgg400uFJJUGgYSZRCpU+PcDFWMVBRoojDMZ3Ah1Ztg1HZiEArKQQ+GTquW/gM5b8RSDveRxhG9Rf8lPfGLbU44kRZxRhrY4RMvYBdoupuGAzubG7Tj/oGqHAAOQ/R9kfCT/ZyMPeaA4wFbb1xIFPas+5BH4RcNWytkKM3wZ4G4FwFzhW5rOx1orWlsAR/ERvnLor6nmnTvUU6AZNFE+w37Pm5BhDF2ckq15Yi3C6ngrVFo1zUNA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(82608151540597)(22766785571888); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(13016025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:DB4PR07MB0495; BCL:0; PCL:0; RULEID:; SRVR:DB4PR07MB0495; X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB0495; 4:bON9AOaArc9shHqGYIuiUu9xN3QffTw02lFXuihP5NN3QgZl2THGE8nyrPctOP3DWpzvGHO73z1Yh4GEhH6N2v6dXjnYcgDPVZ4MxzDjnBav/nNb2qamGFwEpbppVmM8Cw7IqlE2BHI73t0Apsq4T7c5w4ytOD+qUS475RQxGOBxIaD7aiZFdjd1wcg6OnLB9FQhCZoCzitiAFGrhjDbB2uw//rCUP6FZmzzRQx6hdfSCRCh/3HgsKZI/iT7KnIgzBLz1Al4zwAuXW4wy7aakaKNfe0mSR/exWxvGpd30ATlaqgne5DZAPvLrPvGl5RrRcEjsaVqj35pMcZlNO600svpZ0Hs2VThqFKskVr14qgtbIX9ksJXq01afriP0jfdfHIm7WhvsGItmd5mEj43ea17JNi7g7sIkBYyY2QiYv3j0skaVcanotLk5ytr7eZGovpEUmiigiTZLp+yX4Tf7saypv8wFGBv6x8isG1QIqEssD6F0E37VbL2dtxBGNbk X-Forefront-PRVS: 0011612A55 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB4PR07MB0495; 23:js059hzGZkQH/fBaWky99uO+8D1F3h+lomlJHET+h?= =?us-ascii?Q?/XjcOt+AK1jf5qGhP3PDXF1Mtrai1A2tofe0pl/OBnYpBQBTAhuZnJKJDDiP?= =?us-ascii?Q?B8dD6TQd/sOoATUTgfvnF2nDgJR9GeqVOfsK/P7jXmO9WLrk0q1fu8g1KKeJ?= =?us-ascii?Q?5J8fHrj/zoPhVYpAFetVd0LSE/ENlwC0OrP+171VPoAYEidTFptRRyZ4Lg/k?= =?us-ascii?Q?tegO/fcgzdhkm1t0+PiYAwqqeoE1mBIRCw/LM9+908NHLLUO+OitVitoe8AR?= =?us-ascii?Q?NK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9RAfjHU2k+MGg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB4PR07MB0495; 6:R01OzRfvcLA/hGWrHZDuEjVIJnUbyhDYIzR2Q4m92jWpohpyG2QJNmsAb9oonwcixbE84H2ZIhUdEghHsvfkqDVWB/6yyMlr+IDGvH944uykxonSFMjgcp9X/Gvpo2/pbiEZAmHPmrgPPYPb0nuQQkDCdOMTcs36BWUanaav21nDN6bfUf4g3VaCKZ9FGGWyLLLlkey8qIlUXXMkrNbNRk1M1b0tKVIo3HV0KhEvr/6JF3A+IY5+FqNmRDPVgXHKFQEHNv01RPoZscR3+eJdD0ri9rZYUR9QLbD1DHT+i0sqvV7TqJvXIQlon0mUzftRfksOmTTWgZ1BXD6B8W7dMQ==; 5:J1yIBQwmGNmStH7zhxrYaIIO3C9QkVOX/jsBH2HS2ztB2Yq0Z9SdITGTEd2F1bah+QecICVo4ttCAmNF4mrNbub9YlZQ1/m3OysRNJ6bvIvD5sa7hAphTcuwJnypO+RqS9WQ8zvw33i5xg8qIsC9qw==; 24:H26cZobonEJPb5R7bnDdQo+8pkX2R94PTyE0RyDh59MEENZxeGnzAMmUyS7apk//GWtxnlrbo8elsG+BohvVBKg0h7kMMwRJOZXkasHwSJg=; 7:pBOPPMO1zGq7Wm1r9FFkRyg8Nod8JBq6yY3krWDmE+YfjkxI5Kd0GzIwFycpCkx/s5wvfcyGf3QAQf93vKHFn6eYKI+DZr9b+LCf5yeDdyJcS4xW0NzBktXCVSBdC9/KgkqrET5oJxlhG3ntj8F3bpi8yV9X//x8w4/fqj5O5FFOzLx1PS5dpMMbtJvOLpme4DdTGgwznviyy1SEmT7XbZIQPQQmwHyd6+jR5x3Vy09PG+mUUMWGjFqntQkwNv5P SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2016 10:05:55.0966 (UTC) X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.241]; Helo=[fihe3nok0735.emea.nsn-net.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR07MB0495 X-Topics: patch Cc: Petri Savolainen Subject: [lng-odp] [PATCH v3 2/4] linux-gen: pktio: use multi alloc X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Modify dpdk pktio to take advantage of multi-alloc/free. Others pktios do alloc/free still one packet at a time. For example, l2fwd test application packet throughput is increased about 10% (with dpdk pktio). Signed-off-by: Petri Savolainen Signed-off-by: Matias Elo --- V2: - Allocate MTU sized packets with socket pktio .../linux-generic/include/odp_packet_internal.h | 4 +- platform/linux-generic/include/odp_packet_socket.h | 1 + platform/linux-generic/odp_packet.c | 71 +++++++++++++--------- platform/linux-generic/pktio/dpdk.c | 24 +++++--- platform/linux-generic/pktio/netmap.c | 5 +- platform/linux-generic/pktio/pcap.c | 26 ++------ platform/linux-generic/pktio/socket.c | 21 +++++-- platform/linux-generic/pktio/socket_mmap.c | 7 ++- platform/linux-generic/pktio/tap.c | 7 ++- 9 files changed, 94 insertions(+), 72 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 4c4e36c..392d670 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -306,7 +306,9 @@ static inline int packet_parse_not_complete(odp_packet_hdr_t *pkt_hdr) /* Forward declarations */ int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt); -odp_packet_t packet_alloc(odp_pool_t pool_hdl, uint32_t len, int parse); +/* Packet alloc of pktios */ +int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, + odp_packet_t pkt[], int max_num); /* Fill in parser metadata for L2 */ void packet_parse_l2(packet_parser_t *prs, uint32_t frame_len); diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h index ccff69a..dbfc9f1 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_packet_socket.h @@ -45,6 +45,7 @@ typedef struct { int sockfd; /**< socket descriptor */ odp_pool_t pool; /**< pool to alloc packets from */ + uint32_t mtu; /**< maximum transmission unit */ unsigned char if_mac[ETH_ALEN]; /**< IF eth mac addr */ uint8_t *cache_ptr[ODP_PACKET_SOCKET_MAX_BURST_RX]; odp_shm_t shm; diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 474fa81..c4cf324 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -76,35 +76,46 @@ static void packet_init(pool_entry_t *pool, odp_packet_hdr_t *pkt_hdr, pkt_hdr->input = ODP_PKTIO_INVALID; } -odp_packet_t packet_alloc(odp_pool_t pool_hdl, uint32_t len, int parse) +int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, + odp_packet_t pkt[], int max_num) { + odp_packet_hdr_t *pkt_hdr; + pool_entry_t *pool = odp_pool_to_entry(pool_hdl); + int num, i; + + num = buffer_alloc_multi(pool_hdl, len, (odp_buffer_t *)pkt, max_num); + + for (i = 0; i < num; i++) { + pkt_hdr = odp_packet_hdr(pkt[i]); + packet_init(pool, pkt_hdr, len, 1 /* do parse */); + + if (pkt_hdr->tailroom >= pkt_hdr->buf_hdr.segsize) + pull_tail_seg(pkt_hdr); + } + + return num; +} + +odp_packet_t odp_packet_alloc(odp_pool_t pool_hdl, uint32_t len) +{ + pool_entry_t *pool = odp_pool_to_entry(pool_hdl); + size_t pkt_size = len ? len : pool->s.params.buf.size; odp_packet_t pkt; odp_packet_hdr_t *pkt_hdr; - pool_entry_t *pool = odp_pool_to_entry(pool_hdl); - if (pool->s.params.type != ODP_POOL_PACKET) + if (pool->s.params.type != ODP_POOL_PACKET) { + __odp_errno = EINVAL; return ODP_PACKET_INVALID; - - /* Handle special case for zero-length packets */ - if (len == 0) { - len = pool->s.params.buf.size; - - pkt = (odp_packet_t)buffer_alloc(pool_hdl, len); - - if (pkt == ODP_PACKET_INVALID) - return ODP_PACKET_INVALID; - - pull_tail(odp_packet_hdr(pkt), len); - - } else { - pkt = (odp_packet_t)buffer_alloc(pool_hdl, len); - - if (pkt == ODP_PACKET_INVALID) - return ODP_PACKET_INVALID; } + pkt = (odp_packet_t)buffer_alloc(pool_hdl, pkt_size); + if (pkt == ODP_PACKET_INVALID) + return ODP_PACKET_INVALID; + pkt_hdr = odp_packet_hdr(pkt); - packet_init(pool, pkt_hdr, len, parse); + packet_init(pool, pkt_hdr, pkt_size, 0 /* do not parse */); + if (len == 0) + pull_tail(pkt_hdr, pkt_size); if (pkt_hdr->tailroom >= pkt_hdr->buf_hdr.segsize) pull_tail_seg(pkt_hdr); @@ -112,11 +123,6 @@ odp_packet_t packet_alloc(odp_pool_t pool_hdl, uint32_t len, int parse) return pkt; } -odp_packet_t odp_packet_alloc(odp_pool_t pool_hdl, uint32_t len) -{ - return packet_alloc(pool_hdl, len, 0); -} - int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, odp_packet_t pkt[], int num) { @@ -135,9 +141,12 @@ int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, for (i = 0; i < count; ++i) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt[i]); - packet_init(pool, pkt_hdr, pkt_size, 0); + packet_init(pool, pkt_hdr, pkt_size, 0 /* do not parse */); if (len == 0) pull_tail(pkt_hdr, pkt_size); + + if (pkt_hdr->tailroom >= pkt_hdr->buf_hdr.segsize) + pull_tail_seg(pkt_hdr); } return count; @@ -145,12 +154,16 @@ int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, void odp_packet_free(odp_packet_t pkt) { - odp_buffer_free((odp_buffer_t)pkt); + uint32_t pool_id = pool_id_from_buf((odp_buffer_t)pkt); + + buffer_free(pool_id, (odp_buffer_t)pkt); } void odp_packet_free_multi(const odp_packet_t pkt[], int num) { - odp_buffer_free_multi((const odp_buffer_t *)pkt, num); + uint32_t pool_id = pool_id_from_buf((odp_buffer_t)pkt[0]); + + buffer_free_multi(pool_id, (const odp_buffer_t * const)pkt, num); } int odp_packet_reset(odp_packet_t pkt, uint32_t len) diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index a5934a5..1fad8a9 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -706,7 +706,7 @@ static int dpdk_stop(pktio_entry_t *pktio_entry) static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[], struct rte_mbuf *mbuf_table[], - uint16_t num, odp_time_t *ts) + uint16_t mbuf_num, odp_time_t *ts) { odp_packet_t pkt; odp_packet_hdr_t *pkt_hdr; @@ -715,9 +715,15 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, void *buf; int i, j; int nb_pkts = 0; + int alloc_len, num; + odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool; + + /* Allocate maximum sized packets */ + alloc_len = pktio_entry->s.pkt_dpdk.data_room; + + num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num); for (i = 0; i < num; i++) { - odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool; odp_packet_hdr_t parsed_hdr; mbuf = mbuf_table[i]; @@ -738,18 +744,16 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, &parsed_hdr)) goto fail; } - pkt = packet_alloc(pool, pkt_len, 1); - if (pkt == ODP_PACKET_INVALID) - goto fail; + pkt = pkt_table[i]; pkt_hdr = odp_packet_hdr(pkt); + pull_tail(pkt_hdr, alloc_len - pkt_len); /* For now copy the data in the mbuf, worry about zero-copy later */ - if (odp_packet_copy_from_mem(pkt, 0, pkt_len, buf) != 0) { - odp_packet_free(pkt); + if (odp_packet_copy_from_mem(pkt, 0, pkt_len, buf) != 0) goto fail; - } + pkt_hdr->input = pktio_entry->s.handle; if (pktio_cls_enabled(pktio_entry)) @@ -770,7 +774,9 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, return nb_pkts; fail: - for (j = i; j < num; j++) + odp_packet_free_multi(&pkt_table[i], mbuf_num - i); + + for (j = i; j < mbuf_num; j++) rte_pktmbuf_free(mbuf_table[j]); return (i > 0 ? i : -1); diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index 3017e40..6498429 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -599,6 +599,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, odp_pool_t pool = pktio_entry->s.pkt_nm.pool; odp_packet_hdr_t *pkt_hdr; odp_packet_hdr_t parsed_hdr; + int num; if (odp_unlikely(len > pktio_entry->s.pkt_nm.max_frame_len)) { ODP_ERR("RX: frame too big %" PRIu16 " %zu!\n", len, @@ -616,8 +617,8 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, len, &pool, &parsed_hdr)) return -1; } - pkt = packet_alloc(pool, len, 1); - if (pkt == ODP_PACKET_INVALID) + num = packet_alloc_multi(pool, len, &pkt, 1); + if (num != 1) return -1; pkt_hdr = odp_packet_hdr(pkt); diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index e501858..e54a56f 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -224,19 +224,9 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, pktio_entry->s.config.pktin.bit.ts_ptp) ts = &ts_val; - pkt = ODP_PACKET_INVALID; - pkt_len = 0; - for (i = 0; i < len; ) { int ret; - if (pkt == ODP_PACKET_INVALID) { - pkt = packet_alloc(pcap->pool, 0 /*default len*/, 1); - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; - pkt_len = odp_packet_len(pkt); - } - ret = pcap_next_ex(pcap->rx, &hdr, &data); /* end of file, attempt to reopen if within loop limit */ @@ -246,17 +236,17 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, if (ret != 1) break; + pkt_len = hdr->caplen; + + ret = packet_alloc_multi(pcap->pool, pkt_len, &pkt, 1); + if (odp_unlikely(ret != 1)) + break; + if (ts != NULL) ts_val = odp_time_global(); pkt_hdr = odp_packet_hdr(pkt); - if (!odp_packet_pull_tail(pkt, pkt_len - hdr->caplen)) { - ODP_ERR("failed to pull tail: pkt_len: %d caplen: %d\n", - pkt_len, hdr->caplen); - break; - } - if (odp_packet_copy_from_mem(pkt, 0, hdr->caplen, data) != 0) { ODP_ERR("failed to copy packet data\n"); break; @@ -269,7 +259,6 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, pkt_hdr->input = pktio_entry->s.handle; pkts[i] = pkt; - pkt = ODP_PACKET_INVALID; i++; } @@ -277,9 +266,6 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_ticketlock_unlock(&pktio_entry->s.rxl); - if (pkt != ODP_PACKET_INVALID) - odp_packet_free(pkt); - return i; } diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index 0309b0d..e01b0a5 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -527,6 +527,10 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, if (err != 0) goto error; + pkt_sock->mtu = mtu_get_fd(sockfd, netdev); + if (!pkt_sock->mtu) + goto error; + /* bind socket to if */ memset(&sa_ll, 0, sizeof(sa_ll)); sa_ll.sll_family = AF_PACKET; @@ -659,6 +663,7 @@ static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, void *base = msgvec[i].msg_hdr.msg_iov->iov_base; struct ethhdr *eth_hdr = base; uint16_t pkt_len = msgvec[i].msg_len; + int num; /* Don't receive packets sent by ourselves */ if (odp_unlikely(ethaddrs_equal(pkt_sock->if_mac, @@ -668,8 +673,8 @@ static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, if (cls_classify_packet(pktio_entry, base, pkt_len, pkt_len, &pool, &parsed_hdr)) continue; - pkt = packet_alloc(pool, pkt_len, 1); - if (pkt == ODP_PACKET_INVALID) + num = packet_alloc_multi(pool, pkt_len, &pkt, 1); + if (num != 1) continue; pkt_hdr = odp_packet_hdr(pkt); @@ -690,10 +695,14 @@ static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, [ODP_BUFFER_MAX_SEG]; for (i = 0; i < (int)len; i++) { - pkt_table[i] = packet_alloc(pkt_sock->pool, - 0 /*default*/, 1); - if (odp_unlikely(pkt_table[i] == ODP_PACKET_INVALID)) + int num; + + num = packet_alloc_multi(pkt_sock->pool, pkt_sock->mtu, + &pkt_table[i], 1); + if (odp_unlikely(num != 1)) { + pkt_table[i] = ODP_PACKET_INVALID; break; + } msgvec[i].msg_hdr.msg_iovlen = _rx_pkt_to_iovec(pkt_table[i], iovecs[i]); @@ -818,7 +827,7 @@ static int sock_mmsg_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, */ static uint32_t sock_mtu_get(pktio_entry_t *pktio_entry) { - return mtu_get_fd(pktio_entry->s.pkt_sock.sockfd, pktio_entry->s.name); + return pktio_entry->s.pkt_sock.mtu; } /* diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index b6be81a..8b24c99 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -171,6 +171,7 @@ static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, odp_packet_hdr_t *hdr; odp_packet_hdr_t parsed_hdr; odp_pool_t pool = pkt_sock->pool; + int num; if (!mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) break; @@ -208,8 +209,10 @@ static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, } } - pkt_table[nb_rx] = packet_alloc(pool, pkt_len, 1); - if (odp_unlikely(pkt_table[nb_rx] == ODP_PACKET_INVALID)) { + num = packet_alloc_multi(pool, pkt_len, &pkt_table[nb_rx], 1); + + if (odp_unlikely(num != 1)) { + pkt_table[nb_rx] = ODP_PACKET_INVALID; mmap_rx_user_ready(ppd.raw); /* drop */ frame_num = next_frame_num; continue; diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index a9a8886..d758a39 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -185,11 +185,12 @@ static odp_packet_t pack_odp_pkt(pktio_entry_t *pktio_entry, const void *data, { odp_packet_t pkt; odp_packet_hdr_t *pkt_hdr; + int num; - pkt = packet_alloc(pktio_entry->s.pkt_tap.pool, len, 1); + num = packet_alloc_multi(pktio_entry->s.pkt_tap.pool, len, &pkt, 1); - if (pkt == ODP_PACKET_INVALID) - return pkt; + if (num != 1) + return ODP_PACKET_INVALID; if (odp_packet_copy_from_mem(pkt, 0, len, data) < 0) { ODP_ERR("failed to copy packet data\n");