From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0960BC10F1B for ; Tue, 27 Dec 2022 08:54:11 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C7EC7410FC; Tue, 27 Dec 2022 09:54:10 +0100 (CET) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 21AD840E2D for ; Tue, 27 Dec 2022 09:54:10 +0100 (CET) Received: from [192.168.38.17] (aros.oktetlabs.ru [192.168.38.17]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by shelob.oktetlabs.ru (Postfix) with ESMTPSA id 47A2C62; Tue, 27 Dec 2022 11:54:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 47A2C62 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1672131249; bh=BL0/ri3hXQpuj/AVb4vz1WAUukgqZu+yrZX15fPC9tA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=iFPcqnZ4mkILbJ5+iIeWcNvWOmf6CFwZvwFi+4gUEqXRhyhzq/0jOOVSAy++pd7vo ZUMJaSsH+42SP4BJ7ygBli04iK564aP6EcKwihFQ2waL01OJaghbePzeIienqmIhlr 9ZAE6nZwVsBEUDA94gUh2/mGWqGcl29djE3thif0= Message-ID: Date: Tue, 27 Dec 2022 11:54:08 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v3] mempool: micro-optimize put function Content-Language: en-US To: =?UTF-8?Q?Morten_Br=c3=b8rup?= , olivier.matz@6wind.com, dev@dpdk.org Cc: honnappa.nagarahalli@arm.com, bruce.richardson@intel.com, konstantin.ananyev@huawei.com References: <20221116101855.93297-1-mb@smartsharesystems.com> <20221224104630.32235-1-mb@smartsharesystems.com> From: Andrew Rybchenko Organization: OKTET Labs In-Reply-To: <20221224104630.32235-1-mb@smartsharesystems.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 12/24/22 13:46, Morten Brørup wrote: > Micro-optimization: > Reduced the most likely code path in the generic put function by moving an > unlikely check out of the most likely code path and further down. > > Also updated the comments in the function. > > v3 (feedback from Konstantin Ananyev): > * Removed assertion and comment about the invariant preventing overflow > in the comparison. They were more confusing than enlightening. > v2 (feedback from Andrew Rybchenko): > * Modified comparison to prevent overflow if n is really huge and len is > non-zero. > * Added assertion about the invariant preventing overflow in the > comparison. > * Crossing the threshold is not extremely unlikely, so removed likely() > from that comparison. > The compiler will generate code with optimal static branch prediction > here anyway. > > Signed-off-by: Morten Brørup > Acked-by: Konstantin Ananyev Thanks for optimizing it further. Reviewed-by: Andrew Rybchenko > --- > lib/mempool/rte_mempool.h | 35 ++++++++++++++++++----------------- > 1 file changed, 18 insertions(+), 17 deletions(-) > > diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h > index 9f530db24b..61ca0c6b65 100644 > --- a/lib/mempool/rte_mempool.h > +++ b/lib/mempool/rte_mempool.h > @@ -1364,32 +1364,33 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table, > { > void **cache_objs; > > - /* No cache provided */ > + /* No cache provided? */ IMHO such changes do not add value and just add noise. There are few similar cases below. No strong opinion in any case.