* [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple
@ 2018-03-14 9:40 Pavan Nikhilesh
2018-03-14 9:41 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Pavan Nikhilesh @ 2018-03-14 9:40 UTC (permalink / raw)
To: jerin.jacob, thomas; +Cc: dev, Pavan Nikhilesh
Add macros to align given value to the multiple of the supplied
integer.
Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
Common code needed for OcteonTx event timer device.
lib/librte_eal/common/include/rte_common.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index c7803e41c..2052b5300 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -190,6 +190,22 @@ static void __attribute__((constructor(prio), used)) func(void)
*/
#define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
+/**
+ * Macro to align a value to the multiple of given value. The resultant
+ * value will be of the same type as the first parameter and will be no lower
+ * than the first parameter.
+ */
+#define RTE_ALIGN_MUL_CEIL(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
+ * value will be of the same type as the first parameter and will be no higher
+ * than the first parameter.
+ */
+#define RTE_ALIGN_MUL_FLOOR(v, mul) \
+ ((v / ((typeof(v)) mul)) * (typeof(v))mul)
+
/**
* Checks if a pointer is aligned to a given power-of-two value
*
--
2.16.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [dpdk-dev] [PATCH 2/2] test: update common auto test
2018-03-14 9:40 [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Pavan Nikhilesh
@ 2018-03-14 9:41 ` Pavan Nikhilesh
2018-03-15 23:53 ` Thomas Monjalon
2018-03-14 10:42 ` [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Ananyev, Konstantin
2018-03-20 13:24 ` [dpdk-dev] [PATCH v2] " Pavan Nikhilesh
2 siblings, 1 reply; 8+ messages in thread
From: Pavan Nikhilesh @ 2018-03-14 9:41 UTC (permalink / raw)
To: jerin.jacob, thomas; +Cc: dev, Pavan Nikhilesh
Update common auto test to include test for aligning values to multiples
of given integer.
Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
test/test/test_common.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/test/test/test_common.c b/test/test/test_common.c
index d0342430f..e43cba49b 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -128,6 +128,18 @@ test_align(void)
FAIL("rte_is_aligned");
}
}
+
+ for (p = 1; p <= MAX_NUM / 2; p++) {
+ for (i = 1; i <= MAX_NUM / 2; i++) {
+ val = RTE_ALIGN_MUL_CEIL(i, p);
+ if (val % p != 0 || val < i)
+ FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
+ val = RTE_ALIGN_MUL_FLOOR(i, p);
+ if (val % p != 0 || val > i)
+ FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
+ }
+ }
+
return 0;
}
--
2.16.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple
2018-03-14 9:40 [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Pavan Nikhilesh
2018-03-14 9:41 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
@ 2018-03-14 10:42 ` Ananyev, Konstantin
2018-03-16 8:41 ` Pavan Nikhilesh
2018-03-20 13:24 ` [dpdk-dev] [PATCH v2] " Pavan Nikhilesh
2 siblings, 1 reply; 8+ messages in thread
From: Ananyev, Konstantin @ 2018-03-14 10:42 UTC (permalink / raw)
To: Pavan Nikhilesh, jerin.jacob, thomas; +Cc: dev
Hi Pavan,
>
> Add macros to align given value to the multiple of the supplied
> integer.
>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> ---
>
> Common code needed for OcteonTx event timer device.
>
> lib/librte_eal/common/include/rte_common.h | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index c7803e41c..2052b5300 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -190,6 +190,22 @@ static void __attribute__((constructor(prio), used)) func(void)
> */
> #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
>
> +/**
> + * Macro to align a value to the multiple of given value. The resultant
> + * value will be of the same type as the first parameter and will be no lower
> + * than the first parameter.
> + */
> +#define RTE_ALIGN_MUL_CEIL(v, mul) \
> + (((v + (typeof(v)) mul - 1) / ((typeof(v)) mul)) * (typeof(v))mul)
I think you need to add braces around mul:
(((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
Same above.
Konstantin
> +
> +/**
> + * Macro to align a value to the multiple of given value. The resultant
> + * value will be of the same type as the first parameter and will be no higher
> + * than the first parameter.
> + */
> +#define RTE_ALIGN_MUL_FLOOR(v, mul) \
> + ((v / ((typeof(v)) mul)) * (typeof(v))mul)
> +
> /**
> * Checks if a pointer is aligned to a given power-of-two value
> *
> --
> 2.16.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] test: update common auto test
2018-03-14 9:41 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
@ 2018-03-15 23:53 ` Thomas Monjalon
2018-03-16 8:56 ` Pavan Nikhilesh
0 siblings, 1 reply; 8+ messages in thread
From: Thomas Monjalon @ 2018-03-15 23:53 UTC (permalink / raw)
To: Pavan Nikhilesh; +Cc: jerin.jacob, dev
14/03/2018 10:41, Pavan Nikhilesh:
> Update common auto test to include test for aligning values to multiples
> of given integer.
>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> ---
> test/test/test_common.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
The unit test can be in the same patch as the code.
A single patch is fine here.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple
2018-03-14 10:42 ` [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Ananyev, Konstantin
@ 2018-03-16 8:41 ` Pavan Nikhilesh
0 siblings, 0 replies; 8+ messages in thread
From: Pavan Nikhilesh @ 2018-03-16 8:41 UTC (permalink / raw)
To: Ananyev, Konstantin, jerin.jacob, thomas; +Cc: dev
Hi Konstantin,
On Wed, Mar 14, 2018 at 10:42:54AM +0000, Ananyev, Konstantin wrote:
> Hi Pavan,
>
> >
> > Add macros to align given value to the multiple of the supplied
> > integer.
> >
> > Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > ---
> >
> > Common code needed for OcteonTx event timer device.
> >
> > lib/librte_eal/common/include/rte_common.h | 16 ++++++++++++++++
> > 1 file changed, 16 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> > index c7803e41c..2052b5300 100644
> > --- a/lib/librte_eal/common/include/rte_common.h
> > +++ b/lib/librte_eal/common/include/rte_common.h
> > @@ -190,6 +190,22 @@ static void __attribute__((constructor(prio), used)) func(void)
> > */
> > #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
> >
> > +/**
> > + * Macro to align a value to the multiple of given value. The resultant
> > + * value will be of the same type as the first parameter and will be no lower
> > + * than the first parameter.
> > + */
> > +#define RTE_ALIGN_MUL_CEIL(v, mul) \
> > + (((v + (typeof(v)) mul - 1) / ((typeof(v)) mul)) * (typeof(v))mul)
>
> I think you need to add braces around mul:
> (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul))
> Same above.
Agreed, will roll up a v2.
> Konstantin
Thanks for reviewing,
Pavan.
>
> > +
> > +/**
> > + * Macro to align a value to the multiple of given value. The resultant
> > + * value will be of the same type as the first parameter and will be no higher
> > + * than the first parameter.
> > + */
> > +#define RTE_ALIGN_MUL_FLOOR(v, mul) \
> > + ((v / ((typeof(v)) mul)) * (typeof(v))mul)
> > +
> > /**
> > * Checks if a pointer is aligned to a given power-of-two value
> > *
> > --
> > 2.16.2
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] test: update common auto test
2018-03-15 23:53 ` Thomas Monjalon
@ 2018-03-16 8:56 ` Pavan Nikhilesh
0 siblings, 0 replies; 8+ messages in thread
From: Pavan Nikhilesh @ 2018-03-16 8:56 UTC (permalink / raw)
To: Thomas Monjalon, jerin.jacob; +Cc: dev
On Fri, Mar 16, 2018 at 12:53:27AM +0100, Thomas Monjalon wrote:
> 14/03/2018 10:41, Pavan Nikhilesh:
> > Update common auto test to include test for aligning values to multiples
> > of given integer.
> >
> > Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> > ---
> > test/test/test_common.c | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
>
> The unit test can be in the same patch as the code.
> A single patch is fine here.
Sure, will merge them in v2.
>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [dpdk-dev] [PATCH v2] eal: add macros to align value to multiple
2018-03-14 9:40 [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Pavan Nikhilesh
2018-03-14 9:41 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
2018-03-14 10:42 ` [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Ananyev, Konstantin
@ 2018-03-20 13:24 ` Pavan Nikhilesh
2018-04-04 9:14 ` Thomas Monjalon
2 siblings, 1 reply; 8+ messages in thread
From: Pavan Nikhilesh @ 2018-03-20 13:24 UTC (permalink / raw)
To: jerin.jacob, thomas, konstantin.ananyev; +Cc: dev, Pavan Nikhilesh
Add macros to align given value to the multiple of the supplied
integer.
Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
Common code needed for OcteonTx event timer device.
v2 Changes:
- Use paranthesis around mul (Konstantin).
- Squash test_common patch.
lib/librte_eal/common/include/rte_common.h | 16 ++++++++++++++++
test/test/test_common.c | 12 ++++++++++++
2 files changed, 28 insertions(+)
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index c7803e41c..4469affb9 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -190,6 +190,22 @@ static void __attribute__((constructor(prio), used)) func(void)
*/
#define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align)
+/**
+ * Macro to align a value to the multiple of given value. The resultant
+ * value will be of the same type as the first parameter and will be no lower
+ * than the first parameter.
+ */
+#define RTE_ALIGN_MUL_CEIL(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
+ * value will be of the same type as the first parameter and will be no higher
+ * than the first parameter.
+ */
+#define RTE_ALIGN_MUL_FLOOR(v, mul) \
+ ((v / ((typeof(v))(mul))) * (typeof(v))(mul))
+
/**
* Checks if a pointer is aligned to a given power-of-two value
*
diff --git a/test/test/test_common.c b/test/test/test_common.c
index d0342430f..e43cba49b 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -128,6 +128,18 @@ test_align(void)
FAIL("rte_is_aligned");
}
}
+
+ for (p = 1; p <= MAX_NUM / 2; p++) {
+ for (i = 1; i <= MAX_NUM / 2; i++) {
+ val = RTE_ALIGN_MUL_CEIL(i, p);
+ if (val % p != 0 || val < i)
+ FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p);
+ val = RTE_ALIGN_MUL_FLOOR(i, p);
+ if (val % p != 0 || val > i)
+ FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p);
+ }
+ }
+
return 0;
}
--
2.16.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [dpdk-dev] [PATCH v2] eal: add macros to align value to multiple
2018-03-20 13:24 ` [dpdk-dev] [PATCH v2] " Pavan Nikhilesh
@ 2018-04-04 9:14 ` Thomas Monjalon
0 siblings, 0 replies; 8+ messages in thread
From: Thomas Monjalon @ 2018-04-04 9:14 UTC (permalink / raw)
To: Pavan Nikhilesh; +Cc: dev, jerin.jacob, konstantin.ananyev
20/03/2018 14:24, Pavan Nikhilesh:
> Add macros to align given value to the multiple of the supplied
> integer.
>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> ---
> Common code needed for OcteonTx event timer device.
>
> v2 Changes:
> - Use paranthesis around mul (Konstantin).
> - Squash test_common patch.
Applied, thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-04-04 9:14 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14 9:40 [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Pavan Nikhilesh
2018-03-14 9:41 ` [dpdk-dev] [PATCH 2/2] test: update common auto test Pavan Nikhilesh
2018-03-15 23:53 ` Thomas Monjalon
2018-03-16 8:56 ` Pavan Nikhilesh
2018-03-14 10:42 ` [dpdk-dev] [PATCH 1/2] eal: add macros to align value to multiple Ananyev, Konstantin
2018-03-16 8:41 ` Pavan Nikhilesh
2018-03-20 13:24 ` [dpdk-dev] [PATCH v2] " Pavan Nikhilesh
2018-04-04 9:14 ` 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).