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 8800242DD0; Tue, 4 Jul 2023 10:43:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 151F340E03; Tue, 4 Jul 2023 10:43:45 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id D8CBD40042 for ; Tue, 4 Jul 2023 10:43:43 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 9BE3E2110B; Tue, 4 Jul 2023 10:43:43 +0200 (CEST) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH v2] eal: avoid issues in macro expansion of alignment Date: Tue, 4 Jul 2023 10:43:40 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D87A5D@smartserver.smartshare.dk> X-MimeOLE: Produced By Microsoft Exchange V6.5 In-Reply-To: <20230703232357.122084-1-stephen@networkplumber.org> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH v2] eal: avoid issues in macro expansion of alignment Thread-Index: AdmuBXWIV2wfeCDCRU+XzrlvDbDPTwATZINw References: <20230703185551.57908-1-stephen@networkplumber.org> <20230703232357.122084-1-stephen@networkplumber.org> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Stephen Hemminger" , Cc: 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 > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > Sent: Tuesday, 4 July 2023 01.24 >=20 > RTE_ALIGN_MUL_NEAR is a macro so the cycle argument could > get evaluated twice causing some potential skew. Fix by > computing value once. >=20 > Suggested by patch to fix side effects. >=20 > Fixes: 5cbd14b3e5f9 ("eal: roundup TSC frequency when estimating") > Cc: pbhagavatula@marvell.com > Signed-off-by: Stephen Hemminger > --- > v2 - fix spelling error in commit message >=20 > lib/eal/common/eal_common_timer.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) >=20 > diff --git a/lib/eal/common/eal_common_timer.c > b/lib/eal/common/eal_common_timer.c > index 5686a5102b66..05614b0503cf 100644 > --- a/lib/eal/common/eal_common_timer.c > +++ b/lib/eal/common/eal_common_timer.c > @@ -42,10 +42,14 @@ estimate_tsc_freq(void) > RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly" > " - clock timings may be less accurate.\n"); > /* assume that the rte_delay_us_sleep() will sleep for 1 second */ > - uint64_t start =3D rte_rdtsc(); > + uint64_t start, elapsed; > + > + start =3D rte_rdtsc(); > rte_delay_us_sleep(US_PER_S); > + elapsed =3D rte_rdtsc() - start; > + > /* Round up to 10Mhz. 1E7 ~ 10Mhz */ > - return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ); > + return RTE_ALIGN_MUL_NEAR(elapsed, CYC_PER_10MHZ); > } >=20 > void > -- > 2.39.2 Please fix the RTE_ALIGN_MUL_NEAR() macro instead. It already uses = temporary variables with typeof() anyway. Other macros might have similar behavior of using their parameters more = than once, and could be improved too.