From patchwork Tue Aug 22 12:02:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt X-Patchwork-Id: 27714 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 169E37CDB; Tue, 22 Aug 2017 14:02:43 +0200 (CEST) Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by dpdk.org (Postfix) with ESMTP id 41FFB7CD8 for ; Tue, 22 Aug 2017 14:02:41 +0200 (CEST) Received: by mail-pg0-f66.google.com with SMTP id 83so27252694pgb.4 for ; Tue, 22 Aug 2017 05:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=e0l32Omz3XPsRTp2lparCHguIUu+YeOdABsEaqbIVvI=; b=bOFvlG4ZMAx7ELfPbyv7VgtVFsqVkio7+7egrs0813jEOJNXlHdUy9FhxoYc4PPIbl IHllzdlW+46fYMAY3V35i6Nzr8Ry7GOTXT+cJyoROdg+3QaGwWS6+q+y9YNgIQeztngO pcIRvSlmJhnYccjTvTLGEATnViQ6j/vVAzMfYnsCAlZkyNyU5tIYjeG0k8YTrmQrK4MI deCVD0iVb+GTzNznP9umIQWqxW2U/hahOaJczymVo5arNWtzuA14lyntiJWrlZAIw7Gq 2a0WJd0s6Ab7q6bE195phjkmxkQ4nySgNnIz35LO3ZuV5z9ZH9Wv42lefr8mcI22gGLw fMrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=e0l32Omz3XPsRTp2lparCHguIUu+YeOdABsEaqbIVvI=; b=RP52hZRRa7iDuIQMRW5WaPxDndJspLcv9vTohCAK3WxdBpPVlW+qJcG9Y9G2w8gzaL Ug8v9xFc3frNMcL+3NU7A79FATEt3MOMjFnCh7SUU8E8I5ZTzHV1bQXVCD8HCPVaMgjz IauV0UWr7kXgE5fkJgO5MKbf4t778++Xo9K4/Zk0AbGRIiXBZMAgB21CaguoVRZQJLcU 9bzKl1ReOfA0Ix+2pnodaQD7/TOjGnfoTOTABpyKKLZbBcZsd0vfZzVMZoCI6oyeBEQ4 k4Mz1CKI8C3vTdMSMnBHW66sE8rOOYdEqTA9SbtqdJa5KRnSPJAlZUMIyhi0vSeGz4lu +MNQ== X-Gm-Message-State: AHYfb5jmSfrJz0JDNSrcR2cwBOp+8rqKZfOltcdOmWCZa1YJ5JElEtAj q4whwkHvjcmCf9IT X-Received: by 10.98.133.81 with SMTP id u78mr444815pfd.189.1503403360155; Tue, 22 Aug 2017 05:02:40 -0700 (PDT) Received: from localhost.localdomain ([119.61.11.226]) by smtp.gmail.com with ESMTPSA id t5sm27621592pfd.96.2017.08.22.05.02.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Aug 2017 05:02:39 -0700 (PDT) From: Yangchao Zhou To: dev@dpdk.org Date: Tue, 22 Aug 2017 20:02:35 +0800 Message-Id: <1503403355-4917-1-git-send-email-zhouyates@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] hash: optimize the softrss computation 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use rte_bsf32 and fast bit unset operation to optimize the softrss computation. The following measurements shows improvement over the default softrss computation function. tuple lens old(cycles) new(cycles) 3 1225 337 9 3743 992 Signed-off-by: Yangchao Zhou Reviewed-by: Medvedkin Vladimir --- lib/librte_hash/rte_thash.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/librte_hash/rte_thash.h b/lib/librte_hash/rte_thash.h index 2fffd61..4fa5e07 100644 --- a/lib/librte_hash/rte_thash.h +++ b/lib/librte_hash/rte_thash.h @@ -207,15 +207,14 @@ static inline uint32_t rte_softrss(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key) { - uint32_t i, j, ret = 0; + uint32_t i, j, map, ret = 0; for (j = 0; j < input_len; j++) { - for (i = 0; i < 32; i++) { - if (input_tuple[j] & (1 << (31 - i))) { - ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << i | + for (map = input_tuple[j]; map; map &= (map - 1)) { + i = rte_bsf32(map); + ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << (31 - i) | (uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t *)rss_key)[j + 1])) >> - (32 - i)); - } + (i + 1)); } } return ret; @@ -238,14 +237,13 @@ static inline uint32_t rte_softrss_be(uint32_t *input_tuple, uint32_t input_len, const uint8_t *rss_key) { - uint32_t i, j, ret = 0; + uint32_t i, j, map, ret = 0; for (j = 0; j < input_len; j++) { - for (i = 0; i < 32; i++) { - if (input_tuple[j] & (1 << (31 - i))) { - ret ^= ((const uint32_t *)rss_key)[j] << i | - (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (32 - i)); - } + for (map = input_tuple[j]; map; map &= (map - 1)) { + i = rte_bsf32(map); + ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) | + (uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1)); } } return ret;