From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id AB6681B560 for ; Thu, 12 Jul 2018 09:42:23 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id F36B921511; Thu, 12 Jul 2018 03:42:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 12 Jul 2018 03:42:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=mesmtp; bh=1OUnWIoPNRQvVpTFIrGqfCdmzJ +pJj95TMtr1telu4w=; b=UZxjjbVmfA/++HuqpCmG5yEl7oLjip+ORfGngGL33N c6TWbfO3mwk95Da/8xhi2Czqvq5fhV430iRWTqErREJWJgOwJnPk5wpHYZsFulCg 8gWNsLKy8lnMQvPZ2dOpvgWYcyeeFgc7dGzskw7BiClK9pZuOAH2ww/H1u/cVJ+8 k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=1OUnWI oPNRQvVpTFIrGqfCdmzJ+pJj95TMtr1telu4w=; b=tADReJyU4bQ+wm+aXmxL0C 23cW2qIE/AlVSIm3Kd2yreayrUbdHJetMmLbT1dPPZIlFn0ZgOncHQMyyufx9W6h FnHRq1bMUO60zePNmQu4aTp9NsC3by1KGSWST8IDeVy8tD2+ahJidnvoAzWNVQ/k QHhP8NoPzOi75bhZKWSe5lWgyIbcIIvkZuzQzmXF+O5QlQvwABtgFgVSSrEDVxnd 8SB1Z7EfPcTi8zfKxEQ6dNSYrJoS+JQTmyVvApI6kR9noTldDM2SoMj2EIafJD6o Yw5x11ZdzO928ZZPNJdjhNO5aKsuvUMSOdlRgtfSl1cvuPrzGQi8xWNcCS1Y9tjw == X-ME-Proxy: X-ME-Sender: Received: from xps.localnet (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 7333B10285; Thu, 12 Jul 2018 03:42:21 -0400 (EDT) From: Thomas Monjalon To: bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, Honnappa Nagarahalli Date: Thu, 12 Jul 2018 09:42:20 +0200 Message-ID: <3132435.sNHpliEu6c@xps> In-Reply-To: <20180531153049.41306-1-honnappa.nagarahalli@arm.com> References: <20180531153049.41306-1-honnappa.nagarahalli@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [dpdk-dev] [PATCH] hash: validate hash bucket entries while compiling 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: , X-List-Received-Date: Thu, 12 Jul 2018 07:42:24 -0000 Review please? 31/05/2018 17:30, Honnappa Nagarahalli: > Validate RTE_HASH_BUCKET_ENTRIES during compilation instead of > run time. > > Signed-off-by: Honnappa Nagarahalli > Reviewed-by: Gavin Hu > --- > lib/librte_eal/common/include/rte_common.h | 5 +++++ > lib/librte_hash/rte_cuckoo_hash.c | 1 - > lib/librte_hash/rte_cuckoo_hash.h | 4 ++++ > 3 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h > index 434adfd45..a9df7c161 100644 > --- a/lib/librte_eal/common/include/rte_common.h > +++ b/lib/librte_eal/common/include/rte_common.h > @@ -293,6 +293,11 @@ rte_combine64ms1b(register uint64_t v) > > /*********** Macros to work with powers of 2 ********/ > > +/** > + * Macro to return 1 if n is a power of 2, 0 otherwise > + */ > +#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n))) > + > /** > * Returns true if n is a power of 2 > * @param n > diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c > index a07543a29..375e7d208 100644 > --- a/lib/librte_hash/rte_cuckoo_hash.c > +++ b/lib/librte_hash/rte_cuckoo_hash.c > @@ -107,7 +107,6 @@ rte_hash_create(const struct rte_hash_parameters *params) > /* Check for valid parameters */ > if ((params->entries > RTE_HASH_ENTRIES_MAX) || > (params->entries < RTE_HASH_BUCKET_ENTRIES) || > - !rte_is_power_of_2(RTE_HASH_BUCKET_ENTRIES) || > (params->key_len == 0)) { > rte_errno = EINVAL; > RTE_LOG(ERR, HASH, "rte_hash_create has invalid parameters\n"); > diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h > index 7a54e5557..bd6ad1bd6 100644 > --- a/lib/librte_hash/rte_cuckoo_hash.h > +++ b/lib/librte_hash/rte_cuckoo_hash.h > @@ -97,6 +97,10 @@ enum add_key_case { > /** Number of items per bucket. */ > #define RTE_HASH_BUCKET_ENTRIES 8 > > +#if !RTE_IS_POWER_OF_2(RTE_HASH_BUCKET_ENTRIES) > +#error RTE_HASH_BUCKET_ENTRIES must be a power of 2 > +#endif > + > #define NULL_SIGNATURE 0 > > #define EMPTY_SLOT 0 >