patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] eal: fix macros to align value
@ 2020-06-09 19:17 Harman Kalra
  2020-06-24  8:13 ` Thomas Monjalon
  0 siblings, 1 reply; 7+ messages in thread
From: Harman Kalra @ 2020-06-09 19:17 UTC (permalink / raw)
  To: stephen, thomas, pbhagavatula; +Cc: dev, Harman Kalra, stable

Found an issue while using RTE_ALIGN_MUL_NEAR with an
expression, like as passed in estimate_tsc_freq().
RTE_ALIGN_MUL_FLOOR resulted in unexpected value in the
above function as division has more precedence over
substraction.

Fixes: 5120203d753f ("eal: add macros to align value to multiple")
Cc: stable@dpdk.org

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
 lib/librte_eal/include/rte_common.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h
index 0843ce69e..0d834001c 100644
--- a/lib/librte_eal/include/rte_common.h
+++ b/lib/librte_eal/include/rte_common.h
@@ -295,7 +295,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  * than the first parameter.
  */
 #define RTE_ALIGN_MUL_CEIL(v, mul) \
-	(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
+	((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
 
 /**
  * Macro to align a value to the multiple of given value. The resultant
@@ -303,7 +303,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  * than the first parameter.
  */
 #define RTE_ALIGN_MUL_FLOOR(v, mul) \
-	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
+	(((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
 
 /**
  * Macro to align value to the nearest multiple of the given value.
@@ -314,7 +314,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 	({							\
 		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
 		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
-		(ceil - v) > (v - floor) ? floor : ceil;	\
+		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
 	})
 
 /**
-- 
2.18.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [PATCH] eal: fix macros to align value
  2020-06-09 19:17 [dpdk-stable] [PATCH] eal: fix macros to align value Harman Kalra
@ 2020-06-24  8:13 ` Thomas Monjalon
  2020-06-24  8:24   ` [dpdk-stable] [EXT] " Harman Kalra
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Monjalon @ 2020-06-24  8:13 UTC (permalink / raw)
  To: Harman Kalra; +Cc: stephen, pbhagavatula, stable, dev, david.marchand

09/06/2020 21:17, Harman Kalra:
> Found an issue while using RTE_ALIGN_MUL_NEAR with an
> expression, like as passed in estimate_tsc_freq().
> RTE_ALIGN_MUL_FLOOR resulted in unexpected value in the
> above function as division has more precedence over
> substraction.

The only change I see is adding parenthesis around v.
Am I right?

>  #define RTE_ALIGN_MUL_CEIL(v, mul) \
> -	(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> +	((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
[...]
>  #define RTE_ALIGN_MUL_FLOOR(v, mul) \
> -	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
> +	(((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
[...]
>  	({							\
>  		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
>  		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
> -		(ceil - v) > (v - floor) ? floor : ceil;	\
> +		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
>  	})





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [EXT] Re: [PATCH] eal: fix macros to align value
  2020-06-24  8:13 ` Thomas Monjalon
@ 2020-06-24  8:24   ` Harman Kalra
  2020-06-24  8:30     ` Thomas Monjalon
  0 siblings, 1 reply; 7+ messages in thread
From: Harman Kalra @ 2020-06-24  8:24 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: stephen, pbhagavatula, stable, dev, david.marchand

On Wed, Jun 24, 2020 at 10:13:18AM +0200, Thomas Monjalon wrote:
> External Email
> 
> ----------------------------------------------------------------------
> 09/06/2020 21:17, Harman Kalra:
> > Found an issue while using RTE_ALIGN_MUL_NEAR with an
> > expression, like as passed in estimate_tsc_freq().
> > RTE_ALIGN_MUL_FLOOR resulted in unexpected value in the
> > above function as division has more precedence over
> > substraction.
> 
> The only change I see is adding parenthesis around v.
> Am I right?

Yes, parathesis are required if an expression is passed.

> 
> >  #define RTE_ALIGN_MUL_CEIL(v, mul) \
> > -	(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > +	((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> [...]
> >  #define RTE_ALIGN_MUL_FLOOR(v, mul) \
> > -	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
> > +	(((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
> [...]
> >  	({							\
> >  		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
> >  		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
> > -		(ceil - v) > (v - floor) ? floor : ceil;	\
> > +		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
> >  	})
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [EXT] Re: [PATCH] eal: fix macros to align value
  2020-06-24  8:24   ` [dpdk-stable] [EXT] " Harman Kalra
@ 2020-06-24  8:30     ` Thomas Monjalon
  2020-06-24 10:02       ` Harman Kalra
  2020-06-24 10:20       ` [dpdk-stable] [PATCH v2] " Harman Kalra
  0 siblings, 2 replies; 7+ messages in thread
From: Thomas Monjalon @ 2020-06-24  8:30 UTC (permalink / raw)
  To: Harman Kalra; +Cc: stephen, pbhagavatula, stable, dev, david.marchand

24/06/2020 10:24, Harman Kalra:
> On Wed, Jun 24, 2020 at 10:13:18AM +0200, Thomas Monjalon wrote:
> > 09/06/2020 21:17, Harman Kalra:
> > > Found an issue while using RTE_ALIGN_MUL_NEAR with an
> > > expression, like as passed in estimate_tsc_freq().
> > > RTE_ALIGN_MUL_FLOOR resulted in unexpected value in the
> > > above function as division has more precedence over
> > > substraction.
> > 
> > The only change I see is adding parenthesis around v.
> > Am I right?
> 
> Yes, parathesis are required if an expression is passed.

I think the commit log needs to be updated.
I don't see the relation between
	"division has more precedence over substraction"
and
	"parathesis are required if an expression is passed"


> > >  #define RTE_ALIGN_MUL_CEIL(v, mul) \
> > > -	(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > +	((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > [...]
> > >  #define RTE_ALIGN_MUL_FLOOR(v, mul) \
> > > -	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > +	(((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > [...]
> > >  	({							\
> > >  		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
> > >  		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
> > > -		(ceil - v) > (v - floor) ? floor : ceil;	\
> > > +		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
> > >  	})
> > 
> > 
> > 
> > 
> 






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [EXT] Re: [PATCH] eal: fix macros to align value
  2020-06-24  8:30     ` Thomas Monjalon
@ 2020-06-24 10:02       ` Harman Kalra
  2020-06-24 10:20       ` [dpdk-stable] [PATCH v2] " Harman Kalra
  1 sibling, 0 replies; 7+ messages in thread
From: Harman Kalra @ 2020-06-24 10:02 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: stephen, pbhagavatula, stable, dev, david.marchand

On Wed, Jun 24, 2020 at 10:30:18AM +0200, Thomas Monjalon wrote:
> 24/06/2020 10:24, Harman Kalra:
> > On Wed, Jun 24, 2020 at 10:13:18AM +0200, Thomas Monjalon wrote:
> > > 09/06/2020 21:17, Harman Kalra:
> > > > Found an issue while using RTE_ALIGN_MUL_NEAR with an
> > > > expression, like as passed in estimate_tsc_freq().
> > > > RTE_ALIGN_MUL_FLOOR resulted in unexpected value in the
> > > > above function as division has more precedence over
> > > > substraction.
> > > 
> > > The only change I see is adding parenthesis around v.
> > > Am I right?
> > 
> > Yes, parathesis are required if an expression is passed.
> 
> I think the commit log needs to be updated.
> I don't see the relation between
> 	"division has more precedence over substraction"
> and
> 	"parathesis are required if an expression is passed"

By "division has more precedence over substraction", I tried to
highlight the issue which resulted in unexpected value, but yes
it is sounding confusing. I will reword the commit message and send
V2.

> 
> 
> > > >  #define RTE_ALIGN_MUL_CEIL(v, mul) \
> > > > -	(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > > +	((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > [...]
> > > >  #define RTE_ALIGN_MUL_FLOOR(v, mul) \
> > > > -	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > > +	(((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
> > > [...]
> > > >  	({							\
> > > >  		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
> > > >  		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
> > > > -		(ceil - v) > (v - floor) ? floor : ceil;	\
> > > > +		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
> > > >  	})
> > > 
> > > 
> > > 
> > > 
> > 
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [dpdk-stable] [PATCH v2] eal: fix macros to align value
  2020-06-24  8:30     ` Thomas Monjalon
  2020-06-24 10:02       ` Harman Kalra
@ 2020-06-24 10:20       ` Harman Kalra
  2020-07-11  9:44         ` Thomas Monjalon
  1 sibling, 1 reply; 7+ messages in thread
From: Harman Kalra @ 2020-06-24 10:20 UTC (permalink / raw)
  To: stephen, thomas, pbhagavatula; +Cc: dev, Harman Kalra, stable

Found an issue while using RTE_ALIGN_MUL_NEAR with an
expression, like as passed in estimate_tsc_freq().
RTE_ALIGN_MUL_FLOOR resulted in unexpected value as
parathesis are required to evaluate an expression.

Fixes: 5120203d753f ("eal: add macros to align value to multiple")
Cc: stable@dpdk.org

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
*V2: improved commit message.

 lib/librte_eal/include/rte_common.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h
index 0843ce69e..0d834001c 100644
--- a/lib/librte_eal/include/rte_common.h
+++ b/lib/librte_eal/include/rte_common.h
@@ -295,7 +295,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  * than the first parameter.
  */
 #define RTE_ALIGN_MUL_CEIL(v, mul) \
-	(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
+	((((v) + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
 
 /**
  * Macro to align a value to the multiple of given value. The resultant
@@ -303,7 +303,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  * than the first parameter.
  */
 #define RTE_ALIGN_MUL_FLOOR(v, mul) \
-	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
+	(((v) / ((typeof(v))(mul))) * (typeof(v))(mul))
 
 /**
  * Macro to align value to the nearest multiple of the given value.
@@ -314,7 +314,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 	({							\
 		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
 		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
-		(ceil - v) > (v - floor) ? floor : ceil;	\
+		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
 	})
 
 /**
-- 
2.18.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [dpdk-stable] [PATCH v2] eal: fix macros to align value
  2020-06-24 10:20       ` [dpdk-stable] [PATCH v2] " Harman Kalra
@ 2020-07-11  9:44         ` Thomas Monjalon
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2020-07-11  9:44 UTC (permalink / raw)
  To: Harman Kalra; +Cc: stephen, pbhagavatula, dev, stable

24/06/2020 12:20, Harman Kalra:
> Found an issue while using RTE_ALIGN_MUL_NEAR with an
> expression, like as passed in estimate_tsc_freq().
> RTE_ALIGN_MUL_FLOOR resulted in unexpected value as
> parathesis are required to evaluate an expression.
> 
> Fixes: 5120203d753f ("eal: add macros to align value to multiple")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Harman Kalra <hkalra@marvell.com>

Applied, thanks





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-11  9:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 19:17 [dpdk-stable] [PATCH] eal: fix macros to align value Harman Kalra
2020-06-24  8:13 ` Thomas Monjalon
2020-06-24  8:24   ` [dpdk-stable] [EXT] " Harman Kalra
2020-06-24  8:30     ` Thomas Monjalon
2020-06-24 10:02       ` Harman Kalra
2020-06-24 10:20       ` [dpdk-stable] [PATCH v2] " Harman Kalra
2020-07-11  9:44         ` Thomas Monjalon

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).