From patchwork Thu Feb 8 15:00:09 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: 127674 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1570359ljc; Thu, 8 Feb 2018 07:03:51 -0800 (PST) X-Google-Smtp-Source: AH8x226AMK/lzF0l4cPPKwkjkJpTzqdNXDm+fwMt7tZy/FHZzVgApvMUNowIPowLIFNOCgzfrXfW X-Received: by 10.37.65.197 with SMTP id o188mr730201yba.302.1518102231774; Thu, 08 Feb 2018 07:03:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518102231; cv=none; d=google.com; s=arc-20160816; b=OvP4/Jg6lGTNs4/Feex7oImyXn8mTVnHNqBP+TfTyAhKnDKVW1I5X0+oqi+apefX4n /NyKuxkKE8rNBoX7MNEpa6cRvn2jG7lZQQ5UfeKCSqIa9CcNaVDglLjGMVpuVzeMyie8 8dO2BgnvexZSLiUeHlF3oph4qMVzZP7hN3N3q176X/pDTSwLh5x6eDYpwiFemNRQybJD u2MWjSc02FKUf4AIjUQ+IaFECzT1MZnhc5Ntq9Q22dLoS9435KnqOjTWTGIbczCXqQLr v4XQsmv4TkiCEHkhnX5l0ql5dj3b/in+diZMOyAXs+LWiTmta5snHjmoEAutPkwmw1Sg oLDw== 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=svUbAsMYdL+gMEeyMebz/EyawLPn+7OHuM2qwqEkzho=; b=SOie3BUvyNB960pOULfkfpiUWSzxSRuoXU3SS+/CkjRwbYfJPi7+LjYZ2hrEAk7aAu enBnp3IxbnvTA70IO/QKXW8c2UzGupibdxlzsorCTAoOUw78CC1jctq+n8enh+CqNmiS wTqkABogaKpddx60KnuBwzKHqUGji/UOzYLeJSlWF2sezFLwwi6dnl8shrg7fq3d9H7g pZmPV7xLPiuPcrAth+zkXHzT2mOwgcSeNkfTL3s7eYuJS9ma54nrXC0O00wL3gfTRvKs AOPxXJp3/BZXH17+rTH8HUMJweN2YA65QBbEnNxeHXkV7boXdNT1qBMPLYtJnFO9MinD Nf4g== 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 h68si119113qkd.81.2018.02.08.07.03.50; Thu, 08 Feb 2018 07:03: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 A749A61805; Thu, 8 Feb 2018 15:03:50 +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 05976617E2; Thu, 8 Feb 2018 15:01:04 +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 29CF76081B; Thu, 8 Feb 2018 15:00:46 +0000 (UTC) Received: from forward102p.mail.yandex.net (forward102p.mail.yandex.net [77.88.28.102]) by lists.linaro.org (Postfix) with ESMTPS id 432B2617F8 for ; Thu, 8 Feb 2018 15:00:15 +0000 (UTC) Received: from mxback5j.mail.yandex.net (mxback5j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10e]) by forward102p.mail.yandex.net (Yandex) with ESMTP id B0D94430616F for ; Thu, 8 Feb 2018 18:00:13 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback5j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id BH53hZt35l-0D5amXDG; Thu, 08 Feb 2018 18:00:13 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id gewqgjGlTb-0DnSRMIi; Thu, 08 Feb 2018 18:00:13 +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:09 +0300 Message-Id: <1518102010-6353-4-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 3/4] linux-gen: packet: optimize parse eth 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 parse ethernet function. 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 | 46 +++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 480cea194..b2a22903c 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -1917,28 +1917,33 @@ static inline uint16_t parse_eth(packet_parser_t *prs, const uint8_t **parseptr, const _odp_ethhdr_t *eth; uint16_t macaddr0, macaddr2, macaddr4; const _odp_vlanhdr_t *vlan; + _odp_packet_input_flags_t input_flags; - /* Detect jumbo frames */ - if (frame_len > _ODP_ETH_LEN_MAX) - prs->input_flags.jumbo = 1; + input_flags.all = 0; + input_flags.l2 = 1; + input_flags.eth = 1; eth = (const _odp_ethhdr_t *)*parseptr; + /* Detect jumbo frames */ + if (odp_unlikely(frame_len > _ODP_ETH_LEN_MAX)) + input_flags.jumbo = 1; + /* Handle Ethernet broadcast/multicast addresses */ macaddr0 = _odp_be_to_cpu_16(*((const uint16_t *)(const void *)eth)); - prs->input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; + if (odp_unlikely((macaddr0 & 0x0100) == 0x0100)) + input_flags.eth_mcast = 1; - if (macaddr0 == 0xffff) { + if (odp_unlikely(macaddr0 == 0xffff)) { macaddr2 = _odp_be_to_cpu_16(*((const uint16_t *) (const void *)eth + 1)); macaddr4 = _odp_be_to_cpu_16(*((const uint16_t *) (const void *)eth + 2)); - prs->input_flags.eth_bcast = - (macaddr2 == 0xffff) && (macaddr4 == 0xffff); - } else { - prs->input_flags.eth_bcast = 0; + + if ((macaddr2 == 0xffff) && (macaddr4 == 0xffff)) + input_flags.eth_bcast = 1; } /* Get Ethertype */ @@ -1947,11 +1952,12 @@ static inline uint16_t parse_eth(packet_parser_t *prs, const uint8_t **parseptr, *parseptr += sizeof(*eth); /* Check for SNAP vs. DIX */ - if (ethtype < _ODP_ETH_LEN_MAX) { - prs->input_flags.snap = 1; + if (odp_unlikely(ethtype < _ODP_ETH_LEN_MAX)) { + input_flags.snap = 1; if (ethtype > frame_len - *offset) { prs->error_flags.snap_len = 1; - return 0; + ethtype = 0; + goto error; } ethtype = _odp_be_to_cpu_16(*((const uint16_t *)(uintptr_t) (parseptr + 6))); @@ -1960,9 +1966,9 @@ static inline uint16_t parse_eth(packet_parser_t *prs, const uint8_t **parseptr, } /* Parse the VLAN header(s), if present */ - if (ethtype == _ODP_ETHTYPE_VLAN_OUTER) { - prs->input_flags.vlan_qinq = 1; - prs->input_flags.vlan = 1; + if (odp_unlikely(ethtype == _ODP_ETHTYPE_VLAN_OUTER)) { + input_flags.vlan_qinq = 1; + input_flags.vlan = 1; vlan = (const _odp_vlanhdr_t *)*parseptr; ethtype = _odp_be_to_cpu_16(vlan->type); @@ -1971,13 +1977,16 @@ static inline uint16_t parse_eth(packet_parser_t *prs, const uint8_t **parseptr, } if (ethtype == _ODP_ETHTYPE_VLAN) { - prs->input_flags.vlan = 1; + input_flags.vlan = 1; vlan = (const _odp_vlanhdr_t *)*parseptr; ethtype = _odp_be_to_cpu_16(vlan->type); *offset += sizeof(_odp_vlanhdr_t); *parseptr += sizeof(_odp_vlanhdr_t); } +error: + prs->input_flags.all |= input_flags.all; + return ethtype; } @@ -2240,14 +2249,11 @@ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, parseptr = ptr; offset = 0; - if (layer == ODP_PROTO_LAYER_NONE) + if (odp_unlikely(layer == ODP_PROTO_LAYER_NONE)) return 0; /* Assume valid L2 header, no CRC/FCS check in SW */ prs->l2_offset = offset; - prs->input_flags.l2 = 1; - /* We only support Ethernet for now */ - prs->input_flags.eth = 1; ethtype = parse_eth(prs, &parseptr, &offset, frame_len);