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 63B5542E74; Fri, 14 Jul 2023 18:37:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E3F2E40A81; Fri, 14 Jul 2023 18:37:50 +0200 (CEST) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id C3AB1406B8 for ; Fri, 14 Jul 2023 18:37:49 +0200 (CEST) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1b8b2886364so12494245ad.0 for ; Fri, 14 Jul 2023 09:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1689352669; x=1691944669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=lHf7OmANQXMrc53szkGRjuoznCuk+ba8HakInrWS4hg=; b=bVO2NDz2GkSy8yKSniw0krtN86w4dKl6xsA8AdsLNlerJSdZTlsOiWH6xodY9JOEVz 69PUGlR/DzNpbCEtrtcaUur5THHYskWD/P5mWLAfz7cuoZI/xLyQIixpab5e7SkG80y+ E+my3XMv/mAU3dvuy6OyHLLVHiOE5T5QTU00KelrnYKhr/iCt4j9f60XxQtA/PVXfv7U pKkFiubBqRBgQdYJ2S6jihhs/hGsQvCKS0WKtCACUD1/JHPlpK8Q/ddLmZJxyHbEVL2Y fSCB5rjBG8lsoG64RId1MjUjz1IKdd35eTT7TXiG/1vrpvPOfbyX/r45aDifyNQX5BU+ Bljg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689352669; x=1691944669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lHf7OmANQXMrc53szkGRjuoznCuk+ba8HakInrWS4hg=; b=acWDXw/ho1C06plhHHtlDAJSyUzAHycve3FcxKE6JO1kT0+CcNNjKufdQ2hM5vL23c lsgGX6w/KVXPo+s7o2blof9Mt91YJyCzgNE6pw5NTEbxpis19nQScvwjEnTnKJ4hp9Xo BmJAScX9j8OLRMvIr56gjeU83uvPDNqQNYRZGLQjIcTx2Lpfe1OAELbE00lAp/dDY6Ja bY9qJMnyBNkr5qYSoECGwPqax/oGAqA+Fsy3NeGcvjf0YMScKLV6sUe8AW4X3gzuw/SN UEckgs4HmnsZ5vuO4ZtV6iCSRD+yqupu6Kn7EVQBJ3kHzCRW2+U9URHfvRobnHWGIcbx crkA== X-Gm-Message-State: ABy/qLYkFLrO7lwwXfSsKnNnc4nus5PicnDPg1jiNnAdNdyskt0l6S9h lH7l19iYwQOrJcaTEl9VEsrAHA== X-Google-Smtp-Source: APBJJlEbBrjFWTB+eL9xjbXntjZOLOb0PKMxyZWNMSMt9x4fKgN4kZyghg8wNTmv0hpNADsRjECb2Q== X-Received: by 2002:a17:902:d3c6:b0:1b8:9552:2249 with SMTP id w6-20020a170902d3c600b001b895522249mr3589691plb.43.1689352668571; Fri, 14 Jul 2023 09:37:48 -0700 (PDT) Received: from hermes.local (204-195-116-219.wavecable.com. [204.195.116.219]) by smtp.gmail.com with ESMTPSA id jh2-20020a170903328200b001b7feed285csm7974281plb.36.2023.07.14.09.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 09:37:48 -0700 (PDT) Date: Fri, 14 Jul 2023 09:37:46 -0700 From: Stephen Hemminger To: Morten =?UTF-8?B?QnLDuHJ1cA==?= Cc: , Subject: Re: [PATCH v2] eal: avoid issues in macro expansion of alignment Message-ID: <20230714093746.037279bf@hermes.local> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D87A60@smartserver.smartshare.dk> References: <20230703185551.57908-1-stephen@networkplumber.org> <20230703232357.122084-1-stephen@networkplumber.org> <98CBD80474FA8B44BF855DF32C47DC35D87A5D@smartserver.smartshare.dk> <20230704090056.086363d9@hermes.local> <98CBD80474FA8B44BF855DF32C47DC35D87A60@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 Wed, 5 Jul 2023 00:16:50 +0200 Morten Br=C3=B8rup wrote: > > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > > Sent: Tuesday, 4 July 2023 18.01 > >=20 > > On Tue, 4 Jul 2023 10:43:40 +0200 > > Morten Br=C3=B8rup wrote: > > =20 > > > > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > > > > Sent: Tuesday, 4 July 2023 01.24 > > > > > > > > RTE_ALIGN_MUL_NEAR is a macro so the cycle argument could > > > > get evaluated twice causing some potential skew. Fix by > > > > computing value once. > > > > > > > > Suggested by patch to fix side effects. > > > > > > > > Fixes: 5cbd14b3e5f9 ("eal: roundup TSC frequency when estimating") > > > > Cc: pbhagavatula@marvell.com > > > > Signed-off-by: Stephen Hemminger > > > > --- > > > > v2 - fix spelling error in commit message > > > > > > > > lib/eal/common/eal_common_timer.c | 8 ++++++-- > > > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > > > > > 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); > > > > } > > > > > > > > void > > > > -- > > > > 2.39.2 =20 > > > > > > Please fix the RTE_ALIGN_MUL_NEAR() macro instead. It already uses =20 > > temporary variables with typeof() anyway. =20 > > > > > > Other macros might have similar behavior of using their parameters =20 > > more than once, and could be improved too. =20 > > > =20 > >=20 > > It is already fixed, so this patch can be dropped. =20 >=20 > The macro is not fixed in 23.07-rc2 [1], but evaluates the "v" parameter = four times; first two times to calculate respectively "ceil" and "floor", a= nd then two times in the trigraph to determine which way to round. The "mul= " parameter is evaluated twice by the macro. >=20 > #define RTE_ALIGN_MUL_NEAR(v, mul) \ > ({ \ > typeof(v) ceil =3D RTE_ALIGN_MUL_CEIL(v, mul); \ > typeof(v) floor =3D RTE_ALIGN_MUL_FLOOR(v, mul); \ > (ceil - (v)) > ((v) - floor) ? floor : ceil; \ > }) >=20 > [1]: https://elixir.bootlin.com/dpdk/v23.07-rc2/source/lib/eal/include/rt= e_common.h#L388 >=20 Still working on sorting this out. Discovered this new issue. If I fix RTE_ALIGN_CEIL to only evaluate arguments once. -#define RTE_ALIGN_CEIL(val, align) \ - RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align) +#define RTE_ALIGN_CEIL(val, align) \ + __extension__ ({ \ + uintptr_t _align =3D align; \ + RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (_align) - 1)), _align); \ + }) =20 Then compiler won't allow it to be used in initialization of globals like t= his. In file included from ../lib/telemetry/rte_telemetry.h:14, from ../lib/ethdev/rte_ethdev_telemetry.c:9: ../lib/eal/include/rte_common.h:350:23: error: braced-group within expressi= on allowed only inside a function 350 | __extension__ ({ \ | ^ ../lib/eal/include/rte_common.h:371:31: note: in expansion of macro =E2=80= =98RTE_ALIGN_CEIL=E2=80=99 371 | #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) | ^~~~~~~~~~~~~~ ../lib/ethdev/rte_eth_ctrl.h:435:10: note: in expansion of macro =E2=80=98R= TE_ALIGN=E2=80=99 435 | (RTE_ALIGN(RTE_ETH_FLOW_MAX, UINT64_BIT)/UINT64_BIT) | ^~~~~~~~~ ../lib/ethdev/rte_eth_ctrl.h:452:34: note: in expansion of macro =E2=80=98R= TE_FLOW_MASK_ARRAY_SIZE=E2=80=99 452 | uint64_t flow_types_mask[RTE_FLOW_MASK_ARRAY_SIZE];