From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7CA8742C4C; Wed, 7 Jun 2023 10:10:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6BB82410FC; Wed, 7 Jun 2023 10:10:24 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by mails.dpdk.org (Postfix) with ESMTP id 06CAB410F9 for ; Wed, 7 Jun 2023 10:10:23 +0200 (CEST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 98C565C01E1; Wed, 7 Jun 2023 04:10:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 07 Jun 2023 04:10:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1686125422; x=1686211822; bh=icWWrTjwAEd4kX+jTd8w/HtZDUfTitpOeJK dK1yizqc=; b=yu/WS77qRIzLhb2mwtLQnYuywaKOiVzXKSOBzPR4RwueqZkl/l+ QclBrT9M6nRTPBEREpHqF1vZURul9mwtjMcAnCBjInUgtV0d8WazXKhPAL2THb2f Ks9/75ObsTJMMXXv0Gbw4vM2XpE3277w291IuK3ug+Hq2SUZu9gPBhNSNgC9h4VN UL/pN5apOd/2r/vRfUieMPSSoR9zdiFektTVAufhYVJ0S9tSfkvaCHmbV3DvZG6q 23lyJRA0s4i2pFNCiuOVm3ZArReatSwILry4+tNzraRU82MngWdH9sgGfZnfdgyv Wdzh9ECgiZcRb9k7sRSSq6V/zWeIRVozBsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1686125422; x=1686211822; bh=icWWrTjwAEd4kX+jTd8w/HtZDUfTitpOeJK dK1yizqc=; b=PipeQLmT/zZ3YiP3ts4GJqq5FKD35EK4MrAWG3uh3hbAhAHwV+X h96/KNaKDVOpdweY9ULg5VwlASzCDLC9yTEaThX2t36Bbub9etPMHwwSwjdSR4W0 Rp2r18r1Z8t2Oz1hm9jffxkk0rcLIA5uzBXX4VkuEUAJzbgV504P7RKGeQc8Iu05 bvE4L87xmzIU5NW94hfuPLbAUL442YZgE/3x0qc5SWKKwNnL0hnlOTwCOq8GL3Ad wbEcvEhfSGT6S/Kewe7vtQdRJVS9nltIvf76U+p8QQl6S+/yT7y/dK77vBiKYKay 99ugtHhkh2MfSJJxxwOTgin5zkrzLKqmbGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtfedgleduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkjghfggfgtgesthhqredttddtudenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc ggtffrrghtthgvrhhnpeefhfejleeuvdevtddutdeutdevhfeijeethfffueejhfetuddu vedtkedtieekffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehthhhomhgrshesmhhonhhjrghlohhnrdhnvght X-ME-Proxy: Feedback-ID: i47234305:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 7 Jun 2023 04:10:21 -0400 (EDT) From: Thomas Monjalon To: Morten =?ISO-8859-1?Q?Br=F8rup?= Cc: Bruce Richardson , dev@dpdk.org, olivier.matz@6wind.com, andrew.rybchenko@oktetlabs.ru Subject: Re: [PATCH] mempool: optimize get objects with constant n Date: Wed, 07 Jun 2023 10:10:20 +0200 Message-ID: <3590085.WbyNdk4fJJ@thomas> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D87995@smartserver.smartshare.dk> References: <20230411064845.37713-1-mb@smartsharesystems.com> <1739067.KUTt5R2Mg1@thomas> <98CBD80474FA8B44BF855DF32C47DC35D87995@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" 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 07/06/2023 10:03, Morten Br=F8rup: > > From: Thomas Monjalon [mailto:thomas@monjalon.net] > > Sent: Wednesday, 7 June 2023 09.52 > >=20 > > 18/04/2023 14:55, Bruce Richardson: > > > On Tue, Apr 18, 2023 at 01:29:49PM +0200, Morten Br=F8rup wrote: > > > > From: Bruce Richardson [mailto:bruce.richardson@intel.com] > > > > > On Tue, Apr 11, 2023 at 08:48:45AM +0200, Morten Br=F8rup wrote: > > > > > > + if (__extension__(__builtin_constant_p(n)) && n <=3D cache->l= en) { > > > > > > + /* > > > > > > + * The request size is known at build time, and > > > > > > + * the entire request can be satisfied from the cache, > > > > > > + * so let the compiler unroll the fixed length copy loop. > > > > > > + */ > > > > > > + cache->len -=3D n; > > > > > > + for (index =3D 0; index < n; index++) > > > > > > + *obj_table++ =3D *--cache_objs; > > > > > > + > > > > > > > > > > This loop looks a little awkward to me. Would it be clearer (and = perhaps > > > > > easier for compilers to unroll efficiently if it was rewritten as: > > > > > > > > > > cache->len -=3D n; > > > > > cache_objs =3D &cache->objs[cache->len]; > > > > > for (index =3D 0; index < n; index++) > > > > > obj_table[index] =3D cache_objs[index]; > > > > > > > > The mempool cache is a stack, so the copy loop needs get the object= s in > > decrementing order. I.e. the source index decrements and the destinatio= n index > > increments. > > > > > > > > > > BTW: Please add this as a comment in the code too, above the loop to = avoid > > > future developers (or even future me), asking this question again! > >=20 > > Looks like this request was missed. >=20 > I intentionally omitted it, because I disagree with the suggestion. >=20 > Otherwise, reminders that the mempool cache is a stack should be plastere= d all over the source code, not just here. For reference, this copy loop (w= ithout such a reminder) also exists elsewhere in the same file. >=20 > Apologies for not responding to Bruce's request earlier. What about doing a general comment at the top of the function, with the assignment of the pointer at the end of the array: /* The cache is a stack, so copy will be in reverse order. */ cache_objs =3D &cache->objs[cache->len]; I could do it on apply if there is an agreement.