From: David Marchand <david.marchand@redhat.com>
To: Tyler Retzlaff <roretzla@linux.microsoft.com>
Cc: dev <dev@dpdk.org>, Thomas Monjalon <thomas@monjalon.net>,
Aaron Conole <aconole@redhat.com>,
Pavan Nikhilesh <pbhagavatula@marvell.com>
Subject: Re: [dpdk-dev] [PATCH] eal: avoid side effects in RTE_ALIGN_MUL_NEAR(v, mul) for v and mul
Date: Wed, 5 May 2021 22:28:34 +0200 [thread overview]
Message-ID: <CAJFAV8wtugN+b2E4B_AEPhASSqibOrdCC70fZtLtp0OskZkjMw@mail.gmail.com> (raw)
In-Reply-To: <20210505163034.GA27627@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
On Wed, May 5, 2021 at 6:30 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> On Fri, Mar 12, 2021 at 09:07:22AM +0100, David Marchand wrote:
> > On Thu, Mar 11, 2021 at 10:08 PM Tyler Retzlaff
> > <roretzla@linux.microsoft.com> wrote:
> > >
> > > Avoid expanding v and mul parameters multiple times in the macro. based
> > > on usage of the macro it seems like side effects were not intended.
> > >
> > > For example:
> > > ``return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);''
> >
> > That's the beauty of macros.
> > How about updating the unit tests so that this kind of issue is not
> > reintroduced?
>
> i'm afraid i don't have the schedule budget to do this. i get very
> little dpdk time.
I started to write a test earlier (see below) but I did not finish either.
We can wait until somebody has the time to investigate/finish the work.
I copied Pavan who authored RTE_ALIGN_MUL_*.
There are more macros affected than the one you fixed (see commented
lines with FIXME:), and there are probably more macros to check in
rte_common.h:
diff --git a/app/test/test_common.c b/app/test/test_common.c
index 12bd1cad90..44770722a7 100644
--- a/app/test/test_common.c
+++ b/app/test/test_common.c
@@ -18,6 +18,13 @@
{printf(x "() test failed!\n");\
return -1;}
+static uintptr_t callcount;
+static uintptr_t
+inc_callcount(void)
+{
+ return callcount++;
+}
+
/* this is really a sanity check */
static int
test_macros(int __rte_unused unused_parm)
@@ -28,8 +35,18 @@ test_macros(int __rte_unused unused_parm)
#define FAIL_MACRO(x)\
{printf(#x "() test failed!\n");\
return -1;}
+#define TEST_SIDE_EFFECT_2(macro, type1, type2) do { \
+ callcount = 0; \
+ (void)macro((type1)inc_callcount(), (type2)inc_callcount()); \
+ if (callcount != 2) { \
+ printf(#macro" has side effects: callcount=%u\n", \
+ (unsigned int)callcount); \
+ ret = -1; \
+ } \
+} while (0)
uintptr_t unused = 0;
+ int ret = 0;
RTE_SET_USED(unused);
@@ -47,7 +64,19 @@ test_macros(int __rte_unused unused_parm)
if (strncmp(RTE_STR(test), "test", sizeof("test")))
FAIL_MACRO(RTE_STR);
- return 0;
+ TEST_SIDE_EFFECT_2(RTE_PTR_ADD, void *, size_t);
+ TEST_SIDE_EFFECT_2(RTE_PTR_DIFF, void *, void *);
+ TEST_SIDE_EFFECT_2(RTE_PTR_SUB, void *, size_t);
+ /* FIXME: TEST_SIDE_EFFECT_2(RTE_PTR_ALIGN, void *, size_t); */
+ /* FIXME: TEST_SIDE_EFFECT_2(RTE_PTR_ALIGN_CEIL, void *, size_t); */
+ TEST_SIDE_EFFECT_2(RTE_PTR_ALIGN_FLOOR, void *, size_t);
+ /* FIXME: TEST_SIDE_EFFECT_2(RTE_ALIGN, unsigned int, unsigned int); */
+ /* FIXME: TEST_SIDE_EFFECT_2(RTE_ALIGN_CEIL, unsigned int,
unsigned int); */
+ TEST_SIDE_EFFECT_2(RTE_ALIGN_FLOOR, unsigned int, unsigned int);
+ /* FIXME: TEST_SIDE_EFFECT_2(RTE_ALIGN_MUL_CEIL, unsigned int,
unsigned int); */
+ /* FIXME: TEST_SIDE_EFFECT_2(RTE_ALIGN_MUL_FLOOR, unsigned
int, unsigned int); */
+ /* FIXME: TEST_SIDE_EFFECT_2(RTE_ALIGN_MUL_NEAR, unsigned int,
unsigned int); */
+ return ret;
}
static int
--
David Marchand
next prev parent reply other threads:[~2021-05-05 20:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-11 21:08 Tyler Retzlaff
2021-03-12 0:40 ` Ranjit Menon
2021-03-12 1:34 ` Tyler Retzlaff
2021-03-12 4:41 ` Ranjit Menon
2021-03-12 6:28 ` Tyler Retzlaff
2021-03-12 8:07 ` David Marchand
2021-03-12 18:49 ` Tyler Retzlaff
2021-05-05 16:30 ` Tyler Retzlaff
2021-05-05 20:28 ` David Marchand [this message]
2021-05-06 12:24 ` [dpdk-dev] [EXT] " Pavan Nikhilesh Bhagavatula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJFAV8wtugN+b2E4B_AEPhASSqibOrdCC70fZtLtp0OskZkjMw@mail.gmail.com \
--to=david.marchand@redhat.com \
--cc=aconole@redhat.com \
--cc=dev@dpdk.org \
--cc=pbhagavatula@marvell.com \
--cc=roretzla@linux.microsoft.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).