From patchwork Thu Feb 8 15:00:07 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: 127671 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1567950ljc; Thu, 8 Feb 2018 07:01:51 -0800 (PST) X-Google-Smtp-Source: AH8x227LNJ+bMAoLH6AqKwRWyGRuRHe4hH02dOUdxp9gZBgGzEy1OkGeQctKpirGROkLUY9RXrBa X-Received: by 10.37.44.22 with SMTP id s22mr686674ybs.248.1518102111574; Thu, 08 Feb 2018 07:01:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518102111; cv=none; d=google.com; s=arc-20160816; b=VZxcI9qAha7PrSAO9uUhf766jhsrjdhZe826CWuk/349B+2BvKg+kKfOtdkuUPPDi+ rlD+B1jfMYgvBuC49iBM0TypGj369spq6KboToHIcFzgSZ6My9T4U6cw7sX7dHz6d62n Zau4zTeoMPyvqkNPl3ZDZ3f/AWWS/3M8BgPehkQkiWv+uiZ1sv6rECyc5UE/wiwZcFTK IOm+qjXui74Gp/rKZH4IM8lD1BASQlqueWydmxMDsF+Opp6LqDr+PkO1/zqqpq78WGBp qfVFESvhgKua+jWmP42qt/CHXdoRC0kNsqIDA7efnMqLssB412g49zPfnvhytnvwWha7 Khwg== 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=LFK5hQmIx3xdmRVNmWqTaDI03t1ErGiXjZywjyIaRgY=; b=VzCSwTV8rwlebTe2rd27GnEN4Y6T2N13lSd1A8lHkzgPmbqxTs0VPVC1apzDYjbYVJ WiC9y/uaPm+TXNvIi9GiC48xKShmHODAcyzXExOn3/0IMGFveXMwxTmjvXOmItoO4bhV ZlDqr84emN2QqCgkmaGCSEQs56Gs2JOFxVyxmol0rExEKfX7hA6qC8+I5isQz9BEbvbB 0tBD7A3z2bN8IL39v0OrNTaCIdFraQsYFWm9Dge5qhMg+Jwve58MUj2d/PRRsQdK9l8d 4JPhwYa8b/Gso/edUPiKLvn3Kqy0a+JBObrhu8xP1cz+Rjo3JFFMw/Yv+lvbGiAK5ckZ U6Jw== 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 205si93589qkn.388.2018.02.08.07.01.51; Thu, 08 Feb 2018 07:01:51 -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 344E7617F1; Thu, 8 Feb 2018 15:01:51 +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 2746F616E3; Thu, 8 Feb 2018 15:00:53 +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 B6FC7608C3; Thu, 8 Feb 2018 15:00:39 +0000 (UTC) Received: from forward105o.mail.yandex.net (forward105o.mail.yandex.net [37.140.190.183]) by lists.linaro.org (Postfix) with ESMTPS id D9D68617EF for ; Thu, 8 Feb 2018 15:00:13 +0000 (UTC) Received: from mxback2o.mail.yandex.net (mxback2o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1c]) by forward105o.mail.yandex.net (Yandex) with ESMTP id 5F49D44463F4 for ; Thu, 8 Feb 2018 18:00:12 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback2o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id jy2baiINo5-0C50Oj0m; Thu, 08 Feb 2018 18:00:12 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id gewqgjGlTb-0BnSjMU3; Thu, 08 Feb 2018 18:00:11 +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: Thu, 8 Feb 2018 18:00:07 +0300 Message-Id: <1518102010-6353-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518102010-6353-1-git-send-email-odpbot@yandex.ru> References: <1518102010-6353-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 461 Subject: [lng-odp] [PATCH v1 1/4] linux-gen: packet: optimize parse ipv4 and udp 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 Optimize IPv4 and UDP parse functions. Signed-off-by: Petri Savolainen --- /** Email created from pull request 461 (psavol:master-parse-optim) ** https://github.com/Linaro/odp/pull/461 ** Patch: https://github.com/Linaro/odp/pull/461.patch ** Base sha: 257b08b35ceea41bad5a7f1c626496cf111e657a ** Merge commit sha: e004cabc6971bf41b8674db708fd8eaa543f7dae **/ platform/linux-generic/odp_packet.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 9c3be1bcc..92a64801f 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -1988,15 +1988,15 @@ static inline uint8_t parse_ipv4(packet_parser_t *prs, const uint8_t **parseptr, uint32_t *offset, uint32_t frame_len) { const _odp_ipv4hdr_t *ipv4 = (const _odp_ipv4hdr_t *)*parseptr; - uint8_t ver = _ODP_IPV4HDR_VER(ipv4->ver_ihl); - uint8_t ihl = _ODP_IPV4HDR_IHL(ipv4->ver_ihl); - uint16_t frag_offset; uint32_t dstaddr = _odp_be_to_cpu_32(ipv4->dst_addr); uint32_t l3_len = _odp_be_to_cpu_16(ipv4->tot_len); + uint16_t frag_offset = _odp_be_to_cpu_16(ipv4->frag_offset); + uint8_t ver = _ODP_IPV4HDR_VER(ipv4->ver_ihl); + uint8_t ihl = _ODP_IPV4HDR_IHL(ipv4->ver_ihl); - if (odp_unlikely(ihl < _ODP_IPV4HDR_IHL_MIN) || - odp_unlikely(ver != 4) || - (l3_len > frame_len - *offset)) { + if (odp_unlikely(ihl < _ODP_IPV4HDR_IHL_MIN || + ver != 4 || + (l3_len > frame_len - *offset))) { prs->error_flags.ip_err = 1; return 0; } @@ -2012,13 +2012,15 @@ static inline uint8_t parse_ipv4(packet_parser_t *prs, const uint8_t **parseptr, * OR * "fragment offset" field is nonzero (all fragments except the first) */ - frag_offset = _odp_be_to_cpu_16(ipv4->frag_offset); if (odp_unlikely(_ODP_IPV4HDR_IS_FRAGMENT(frag_offset))) prs->input_flags.ipfrag = 1; /* Handle IPv4 broadcast / multicast */ - prs->input_flags.ip_bcast = (dstaddr == 0xffffffff); - prs->input_flags.ip_mcast = (dstaddr >> 28) == 0xd; + if (odp_unlikely(dstaddr == 0xffffffff)) + prs->input_flags.ip_bcast = 1; + + if (odp_unlikely((dstaddr >> 28) == 0xd)) + prs->input_flags.ip_mcast = 1; return ipv4->proto; } @@ -2107,17 +2109,16 @@ static inline void parse_tcp(packet_parser_t *prs, /** * Parser helper function for UDP */ -static inline void parse_udp(packet_parser_t *prs, - const uint8_t **parseptr, uint32_t *offset) +static inline void parse_udp(packet_parser_t *prs, const uint8_t **parseptr) { const _odp_udphdr_t *udp = (const _odp_udphdr_t *)*parseptr; uint32_t udplen = _odp_be_to_cpu_16(udp->length); + uint16_t ipsec_port = _odp_cpu_to_be_16(_ODP_UDP_IPSEC_PORT); if (odp_unlikely(udplen < sizeof(_odp_udphdr_t))) prs->error_flags.udp_err = 1; - if (_odp_cpu_to_be_16(_ODP_UDP_IPSEC_PORT) == udp->dst_port && - udplen > 4) { + if (odp_unlikely(ipsec_port == udp->dst_port && udplen > 4)) { uint32_t val; memcpy(&val, udp + 1, 4); @@ -2127,8 +2128,6 @@ static inline void parse_udp(packet_parser_t *prs, } } - if (offset) - *offset += sizeof(_odp_udphdr_t); *parseptr += sizeof(_odp_udphdr_t); } @@ -2142,7 +2141,7 @@ int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, prs->l3_offset = offset; - if (layer <= ODP_PROTO_LAYER_L2) + if (odp_unlikely(layer <= ODP_PROTO_LAYER_L2)) return prs->error_flags.all != 0; /* Set l3 flag only for known ethtypes */ @@ -2203,7 +2202,7 @@ int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, if (odp_unlikely(offset + _ODP_UDPHDR_LEN > seg_len)) return -1; prs->input_flags.udp = 1; - parse_udp(prs, &parseptr, NULL); + parse_udp(prs, &parseptr); break; case _ODP_IPPROTO_AH: @@ -2232,7 +2231,7 @@ int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, * Parse common packet headers up to given layer * * The function expects at least PACKET_PARSE_SEG_LEN bytes of data to be - * available from the ptr. + * available from the ptr. Also parse metadata must be already initialized. */ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, uint32_t frame_len, uint32_t seg_len,