From patchwork Tue Jan 30 16:00:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 126267 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp3485903ljd; Tue, 30 Jan 2018 08:01:44 -0800 (PST) X-Google-Smtp-Source: AH8x225Orc/6idQZhuZ2yvAc4phdYDciRg8QL/fIZ/48smcH5SRc/6hnwIfVCqxtcjOezu2zLNw6 X-Received: by 10.55.121.130 with SMTP id u124mr42279474qkc.329.1517328104392; Tue, 30 Jan 2018 08:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517328104; cv=none; d=google.com; s=arc-20160816; b=p/vtEx4DXPPWzBkTJdiwZIptDvZlKWyVwOvYFSF/aLESJbfF9usGFKEaBFoK8RI0w/ JWqjjdtL9zznZNTKmbtMaP0hucLLBwSvnjtD8u1Q1AzlubIr29vpBiFZ2JXMqlv2IjfR J7Rl/bXZ6u0FeUTdnPWlfAoC9zioW7s4hDwWpaLV2VGb2J4kN9O5Cu6pgxl2cngGzFfH U2BqUCz+iy47tAbBtu+mjkqCPyZC5r6ZmdFHCJzKjKixQqyVJZXZrQOM4TwfVluyM/dF kRLGcpicXHEek0D+rpWyH6GQperLlMbH3yJrXSR/Icdk8A1imLtTA3V29geBnbVjULyf lgCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=Y3dVULvkketJkFVXcnWgeVGpBm8/JZhGolPeSVvzlhA=; b=HjY9EC6mbm3BEtuC2lonodBw2fxBWwXhP9PV703DMyx4k6qYUmMSply6hvHUgIrPdv xfwFqJOQ/v09lMPux0TnepCWFzMirKoZYjL5OnZ8VkdPDL1gqo5e1dGYUmzmTw/9LOVP MRDqQYVu7dd62KbNDctegrCFx9BGTpRGIi0n0eewyOcMppoWT7KHivB87vkw9qsSgb0v zFnk1rfGDEWmoBkmAiJ43Odv2eTvzBlnvDlBVGiakWU2+UO0RZH5ET4kqsnmesWSaTFp W6ti3EmSQ3x5Fy7vFvQC0MKgGE+Uf645Pk3YTN0N/cTpa7eBBvi57v0sLCAyomTtH7rm Gp9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id y11si1512976qtb.118.2018.01.30.08.01.44; Tue, 30 Jan 2018 08:01:44 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 0666A61512; Tue, 30 Jan 2018 16:01:44 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2 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 BBE026104E; Tue, 30 Jan 2018 16:00:31 +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 A728B61512; Tue, 30 Jan 2018 16:00:19 +0000 (UTC) Received: from forward105j.mail.yandex.net (forward105j.mail.yandex.net [5.45.198.248]) by lists.linaro.org (Postfix) with ESMTPS id 0372E60C5E for ; Tue, 30 Jan 2018 16:00:16 +0000 (UTC) Received: from mxback15j.mail.yandex.net (mxback15j.mail.yandex.net [IPv6:2a02:6b8:0:1619::91]) by forward105j.mail.yandex.net (Yandex) with ESMTP id 7BD7F1841A8 for ; Tue, 30 Jan 2018 19:00:13 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback15j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id u3B6ky2PNa-0DhSNXcR; Tue, 30 Jan 2018 19:00:13 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Nz8CQ597Mi-0CRifAUx; Tue, 30 Jan 2018 19:00:12 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 30 Jan 2018 19:00:01 +0300 Message-Id: <1517328009-16379-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517328009-16379-1-git-send-email-odpbot@yandex.ru> References: <1517328009-16379-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 437 Subject: [lng-odp] [PATCH v1 3/11] linux-gen: packet: inline copy functions 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" From: Petri Savolainen Inline commonly used packet to/from memory copy functions. Signed-off-by: Petri Savolainen --- /** Email created from pull request 437 (psavol:master-packet-optim) ** https://github.com/Linaro/odp/pull/437 ** Patch: https://github.com/Linaro/odp/pull/437.patch ** Base sha: b95ccd3db6eeb7358a877541747e06354429acdd ** Merge commit sha: ab7875c186fe80cfe103c5be5634b0eda312aed4 **/ .../include/odp/api/plat/packet_inlines.h | 36 ++++++++ .../include/odp/api/plat/packet_inlines_api.h | 12 +++ platform/linux-generic/odp_packet.c | 96 +++++++++++----------- 3 files changed, 96 insertions(+), 48 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines.h b/platform/linux-generic/include/odp/api/plat/packet_inlines.h index 765bafb4f..90e205fd4 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines.h @@ -23,11 +23,19 @@ #include #include +#include + /** @cond _ODP_HIDE_FROM_DOXYGEN_ */ void *_odp_packet_map(void *pkt_ptr, uint32_t offset, uint32_t *seg_len, int *seg_idx); +int _odp_packet_copy_from_mem_seg(odp_packet_t pkt, uint32_t offset, + uint32_t len, const void *src); + +int _odp_packet_copy_to_mem_seg(odp_packet_t pkt, uint32_t offset, + uint32_t len, void *dst); + extern const _odp_packet_inline_offset_t _odp_packet_inline; extern const _odp_pool_inline_offset_t _odp_pool_inline; @@ -225,6 +233,34 @@ static inline odp_buffer_t packet_to_buffer(odp_packet_t pkt) return (odp_buffer_t)pkt; } +static inline int _odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, + uint32_t len, const void *src) +{ + uint32_t seg_len = _odp_packet_seg_len(pkt); + uint8_t *data = (uint8_t *)_odp_packet_data(pkt); + + if (odp_unlikely(offset + len > seg_len)) + return _odp_packet_copy_from_mem_seg(pkt, offset, len, src); + + memcpy(data + offset, src, len); + + return 0; +} + +static inline int _odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset, + uint32_t len, void *dst) +{ + uint32_t seg_len = _odp_packet_seg_len(pkt); + uint8_t *data = (uint8_t *)_odp_packet_data(pkt); + + if (odp_unlikely(offset + len > seg_len)) + return _odp_packet_copy_to_mem_seg(pkt, offset, len, dst); + + memcpy(dst, data + offset, len); + + return 0; +} + /** @endcond */ #endif diff --git a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h index c90a69c52..9b31c923f 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inlines_api.h @@ -140,4 +140,16 @@ _ODP_INLINE void odp_packet_prefetch(odp_packet_t pkt, uint32_t offset, return _odp_packet_prefetch(pkt, offset, len); } +_ODP_INLINE int odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, + uint32_t len, const void *src) +{ + return _odp_packet_copy_from_mem(pkt, offset, len, src); +} + +_ODP_INLINE int odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset, + uint32_t len, void *dst) +{ + return _odp_packet_copy_to_mem(pkt, offset, len, dst); +} + #endif diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 8d6185987..2867e67e9 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -334,6 +334,54 @@ void *_odp_packet_map(void *pkt_ptr, uint32_t offset, uint32_t *seg_len, return packet_map(pkt_ptr, offset, seg_len, seg_idx); } +int _odp_packet_copy_from_mem_seg(odp_packet_t pkt, uint32_t offset, + uint32_t len, const void *src) +{ + void *mapaddr; + uint32_t seglen = 0; /* GCC */ + uint32_t cpylen; + const uint8_t *srcaddr = (const uint8_t *)src; + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + if (offset + len > pkt_hdr->frame_len) + return -1; + + while (len > 0) { + mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); + cpylen = len > seglen ? seglen : len; + memcpy(mapaddr, srcaddr, cpylen); + offset += cpylen; + srcaddr += cpylen; + len -= cpylen; + } + + return 0; +} + +int _odp_packet_copy_to_mem_seg(odp_packet_t pkt, uint32_t offset, + uint32_t len, void *dst) +{ + void *mapaddr; + uint32_t seglen = 0; /* GCC */ + uint32_t cpylen; + uint8_t *dstaddr = (uint8_t *)dst; + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + if (offset + len > pkt_hdr->frame_len) + return -1; + + while (len > 0) { + mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); + cpylen = len > seglen ? seglen : len; + memcpy(dstaddr, mapaddr, cpylen); + offset += cpylen; + dstaddr += cpylen; + len -= cpylen; + } + + return 0; +} + #include void packet_parse_reset(odp_packet_hdr_t *pkt_hdr) @@ -1595,54 +1643,6 @@ odp_packet_t odp_packet_copy_part(odp_packet_t pkt, uint32_t offset, return newpkt; } -int odp_packet_copy_to_mem(odp_packet_t pkt, uint32_t offset, - uint32_t len, void *dst) -{ - void *mapaddr; - uint32_t seglen = 0; /* GCC */ - uint32_t cpylen; - uint8_t *dstaddr = (uint8_t *)dst; - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - if (offset + len > pkt_hdr->frame_len) - return -1; - - while (len > 0) { - mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); - cpylen = len > seglen ? seglen : len; - memcpy(dstaddr, mapaddr, cpylen); - offset += cpylen; - dstaddr += cpylen; - len -= cpylen; - } - - return 0; -} - -int odp_packet_copy_from_mem(odp_packet_t pkt, uint32_t offset, - uint32_t len, const void *src) -{ - void *mapaddr; - uint32_t seglen = 0; /* GCC */ - uint32_t cpylen; - const uint8_t *srcaddr = (const uint8_t *)src; - odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); - - if (offset + len > pkt_hdr->frame_len) - return -1; - - while (len > 0) { - mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); - cpylen = len > seglen ? seglen : len; - memcpy(mapaddr, srcaddr, cpylen); - offset += cpylen; - srcaddr += cpylen; - len -= cpylen; - } - - return 0; -} - int odp_packet_copy_from_pkt(odp_packet_t dst, uint32_t dst_offset, odp_packet_t src, uint32_t src_offset, uint32_t len)