DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] sched: support 64 bits greatest common divisor
@ 2021-08-23  8:15 Xueming Li
  2021-09-15 10:26 ` [dpdk-dev] [PATCH v1] sched: adds function to get " Xueming Li
  0 siblings, 1 reply; 10+ messages in thread
From: Xueming Li @ 2021-08-23  8:15 UTC (permalink / raw)
  Cc: dev, xuemingl, Cristian Dumitrescu, Jasvinder Singh

This patch changes inline function that compute the greatest common
divisor to 64 bits.

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
 lib/sched/rte_sched_common.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
index 96706df7bd..65c03329f6 100644
--- a/lib/sched/rte_sched_common.h
+++ b/lib/sched/rte_sched_common.h
@@ -51,10 +51,10 @@ rte_min_pos_4_u16(uint16_t *x)
  *    gcd(a, b) = gcd(b, a mod b)
  *
  */
-static inline uint32_t
-rte_get_gcd(uint32_t a, uint32_t b)
+static inline uint64_t
+rte_get_gcd(uint64_t a, uint64_t b)
 {
-	uint32_t c;
+	uint64_t c;
 
 	if (a == 0)
 		return b;
-- 
2.25.1


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

* [dpdk-dev] [PATCH v1] sched: adds function to get 64 bits greatest common divisor
  2021-08-23  8:15 [dpdk-dev] [PATCH] sched: support 64 bits greatest common divisor Xueming Li
@ 2021-09-15 10:26 ` Xueming Li
  2021-09-22 17:09   ` Kevin Traynor
  0 siblings, 1 reply; 10+ messages in thread
From: Xueming Li @ 2021-09-15 10:26 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, xuemingl, Cristian Dumitrescu, Jasvinder Singh

This patch adds new function that compute the greatest common
divisor of 64 bits, also changes the original 32 bits function to call
this new 64 bits version.

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
v1: add 64 bits version and make 32 bits api call it

 lib/sched/rte_sched_common.h | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
index 96706df7bd..1056543a84 100644
--- a/lib/sched/rte_sched_common.h
+++ b/lib/sched/rte_sched_common.h
@@ -51,10 +51,10 @@ rte_min_pos_4_u16(uint16_t *x)
  *    gcd(a, b) = gcd(b, a mod b)
  *
  */
-static inline uint32_t
-rte_get_gcd(uint32_t a, uint32_t b)
+static inline uint64_t
+rte_get_gcd64(uint64_t a, uint64_t b)
 {
-	uint32_t c;
+	uint64_t c;
 
 	if (a == 0)
 		return b;
@@ -76,6 +76,19 @@ rte_get_gcd(uint32_t a, uint32_t b)
 	return a;
 }
 
+/*
+ * Compute the Greatest Common Divisor (GCD) of two u32 numbers.
+ * This implementation uses Euclid's algorithm:
+ *    gcd(a, 0) = a
+ *    gcd(a, b) = gcd(b, a mod b)
+ *
+ */
+static inline uint32_t
+rte_get_gcd(uint32_t a, uint32_t b)
+{
+	return rte_get_gcd64(a, b);
+}
+
 /*
  * Compute the Lowest Common Denominator (LCD) of two numbers.
  * This implementation computes GCD first:
-- 
2.33.0


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

* Re: [dpdk-dev] [PATCH v1] sched: adds function to get 64 bits greatest common divisor
  2021-09-15 10:26 ` [dpdk-dev] [PATCH v1] sched: adds function to get " Xueming Li
@ 2021-09-22 17:09   ` Kevin Traynor
  2021-09-23  5:34     ` Xueming(Steven) Li
  2021-09-23  8:11     ` [dpdk-dev] [PATCH v2 0/2] " Xueming Li
  0 siblings, 2 replies; 10+ messages in thread
From: Kevin Traynor @ 2021-09-22 17:09 UTC (permalink / raw)
  To: Xueming Li, dev; +Cc: Thomas Monjalon, Cristian Dumitrescu, Jasvinder Singh

On 15/09/2021 11:26, Xueming Li wrote:
> This patch adds new function that compute the greatest common
> divisor of 64 bits, also changes the original 32 bits function to call
> this new 64 bits version.
> 

Can you say why it is needed? It's unused apart from being called for 
the original 32 bit version.

> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> ---
> v1: add 64 bits version and make 32 bits api call it
> 
>   lib/sched/rte_sched_common.h | 19 ++++++++++++++++---
>   1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
> index 96706df7bd..1056543a84 100644
> --- a/lib/sched/rte_sched_common.h
> +++ b/lib/sched/rte_sched_common.h
> @@ -51,10 +51,10 @@ rte_min_pos_4_u16(uint16_t *x)
>    *    gcd(a, b) = gcd(b, a mod b)
>    *
>    */
> -static inline uint32_t
> -rte_get_gcd(uint32_t a, uint32_t b)
> +static inline uint64_t
> +rte_get_gcd64(uint64_t a, uint64_t b)
>   {
> -	uint32_t c;
> +	uint64_t c;
>   
>   	if (a == 0)
>   		return b;
> @@ -76,6 +76,19 @@ rte_get_gcd(uint32_t a, uint32_t b)
>   	return a;
>   }
>   
> +/*
> + * Compute the Greatest Common Divisor (GCD) of two u32 numbers.
> + * This implementation uses Euclid's algorithm:
> + *    gcd(a, 0) = a
> + *    gcd(a, b) = gcd(b, a mod b)
> + *
> + */

I would probably not describe the algorithm here as it is not 
implemented in this function.

> +static inline uint32_t
> +rte_get_gcd(uint32_t a, uint32_t b)
> +{
> +	return rte_get_gcd64(a, b);
> +}
> +
>   /*
>    * Compute the Lowest Common Denominator (LCD) of two numbers.
>    * This implementation computes GCD first:
> 


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

* Re: [dpdk-dev] [PATCH v1] sched: adds function to get 64 bits greatest common divisor
  2021-09-22 17:09   ` Kevin Traynor
@ 2021-09-23  5:34     ` Xueming(Steven) Li
  2021-09-23  8:11     ` [dpdk-dev] [PATCH v2 0/2] " Xueming Li
  1 sibling, 0 replies; 10+ messages in thread
From: Xueming(Steven) Li @ 2021-09-23  5:34 UTC (permalink / raw)
  To: ktraynor, dev
  Cc: NBU-Contact-Thomas Monjalon, cristian.dumitrescu, jasvinder.singh

On Wed, 2021-09-22 at 18:09 +0100, Kevin Traynor wrote:
> On 15/09/2021 11:26, Xueming Li wrote:
> > This patch adds new function that compute the greatest common
> > divisor of 64 bits, also changes the original 32 bits function to call
> > this new 64 bits version.
> > 
> 
> Can you say why it is needed? It's unused apart from being called for 
> the original 32 bit version.

mlx5 vdpa driver is expecting to use a 64 bit version.

> 
> > Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> > ---
> > v1: add 64 bits version and make 32 bits api call it
> > 
> >   lib/sched/rte_sched_common.h | 19 ++++++++++++++++---
> >   1 file changed, 16 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
> > index 96706df7bd..1056543a84 100644
> > --- a/lib/sched/rte_sched_common.h
> > +++ b/lib/sched/rte_sched_common.h
> > @@ -51,10 +51,10 @@ rte_min_pos_4_u16(uint16_t *x)
> >    *    gcd(a, b) = gcd(b, a mod b)
> >    *
> >    */
> > -static inline uint32_t
> > -rte_get_gcd(uint32_t a, uint32_t b)
> > +static inline uint64_t
> > +rte_get_gcd64(uint64_t a, uint64_t b)
> >   {
> > -	uint32_t c;
> > +	uint64_t c;
> >   
> >   	if (a == 0)
> >   		return b;
> > @@ -76,6 +76,19 @@ rte_get_gcd(uint32_t a, uint32_t b)
> >   	return a;
> >   }
> >   
> > +/*
> > + * Compute the Greatest Common Divisor (GCD) of two u32 numbers.
> > + * This implementation uses Euclid's algorithm:
> > + *    gcd(a, 0) = a
> > + *    gcd(a, b) = gcd(b, a mod b)
> > + *
> > + */
> 
> I would probably not describe the algorithm here as it is not 
> implemented in this function.

Thanks, I'll just mention that a 32 bit version of GCD.

> 
> > +static inline uint32_t
> > +rte_get_gcd(uint32_t a, uint32_t b)
> > +{
> > +	return rte_get_gcd64(a, b);
> > +}
> > +
> >   /*
> >    * Compute the Lowest Common Denominator (LCD) of two numbers.
> >    * This implementation computes GCD first:
> > 
> 


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

* [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor
  2021-09-22 17:09   ` Kevin Traynor
  2021-09-23  5:34     ` Xueming(Steven) Li
@ 2021-09-23  8:11     ` Xueming Li
  2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 1/2] " Xueming Li
                         ` (2 more replies)
  1 sibling, 3 replies; 10+ messages in thread
From: Xueming Li @ 2021-09-23  8:11 UTC (permalink / raw)
  To: Matan Azrad, dev; +Cc: xuemingl, Kevin Traynor

Adds 64bit version of GCD.

v1: keep both 32 and 64 bit version
v2:
 - update 32bit function comments
 - add mlx5 patch

Xueming Li (2):
  sched: adds function to get 64 bits greatest common divisor
  vdpa/mlx5: fix large VM memory region registration

 drivers/vdpa/mlx5/mlx5_vdpa_mem.c |  6 +++---
 lib/sched/rte_sched_common.h      | 15 ++++++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

-- 
2.33.0


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

* [dpdk-dev] [PATCH v2 1/2] sched: adds function to get 64 bits greatest common divisor
  2021-09-23  8:11     ` [dpdk-dev] [PATCH v2 0/2] " Xueming Li
@ 2021-09-23  8:11       ` Xueming Li
  2021-09-23  9:53         ` Kevin Traynor
  2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 2/2] vdpa/mlx5: fix large VM memory region registration Xueming Li
  2021-09-27 15:26       ` [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor Thomas Monjalon
  2 siblings, 1 reply; 10+ messages in thread
From: Xueming Li @ 2021-09-23  8:11 UTC (permalink / raw)
  To: Matan Azrad, dev
  Cc: xuemingl, Kevin Traynor, stable, Cristian Dumitrescu, Jasvinder Singh

This patch adds new function that compute the greatest common
divisor of 64 bits, also changes the original 32 bits function to call
this new 64 bits version.

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
Cc: stable@dpdk.org
---
 lib/sched/rte_sched_common.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/sched/rte_sched_common.h b/lib/sched/rte_sched_common.h
index 96706df7bd..340a0df312 100644
--- a/lib/sched/rte_sched_common.h
+++ b/lib/sched/rte_sched_common.h
@@ -51,10 +51,10 @@ rte_min_pos_4_u16(uint16_t *x)
  *    gcd(a, b) = gcd(b, a mod b)
  *
  */
-static inline uint32_t
-rte_get_gcd(uint32_t a, uint32_t b)
+static inline uint64_t
+rte_get_gcd64(uint64_t a, uint64_t b)
 {
-	uint32_t c;
+	uint64_t c;
 
 	if (a == 0)
 		return b;
@@ -76,6 +76,15 @@ rte_get_gcd(uint32_t a, uint32_t b)
 	return a;
 }
 
+/*
+ * 32bit version of Compute the Greatest Common Divisor (GCD).
+ */
+static inline uint32_t
+rte_get_gcd(uint32_t a, uint32_t b)
+{
+	return rte_get_gcd64(a, b);
+}
+
 /*
  * Compute the Lowest Common Denominator (LCD) of two numbers.
  * This implementation computes GCD first:
-- 
2.33.0


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

* [dpdk-dev] [PATCH v2 2/2] vdpa/mlx5: fix large VM memory region registration
  2021-09-23  8:11     ` [dpdk-dev] [PATCH v2 0/2] " Xueming Li
  2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 1/2] " Xueming Li
@ 2021-09-23  8:11       ` Xueming Li
  2021-09-27 15:26       ` [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor Thomas Monjalon
  2 siblings, 0 replies; 10+ messages in thread
From: Xueming Li @ 2021-09-23  8:11 UTC (permalink / raw)
  To: Matan Azrad, dev
  Cc: xuemingl, Kevin Traynor, matan, stable, Viacheslav Ovsiienko,
	Maxime Coquelin

When VM size larger than 4G(u32) and memory region larger than 4G, the
32 bits GCD function overflow and returned wrong value that resulted
memory registration failed.

This patch calls 64 bits GCD function to avoid overflow.

Fixes: cc07a42da250 ("vdpa/mlx5: prepare memory regions")
Cc: matan@mellanox.com
Cc: stable@dpdk.org
Reviewed-by: Matan Azrad <matan@nvidia.com>

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
 drivers/vdpa/mlx5/mlx5_vdpa_mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_mem.c b/drivers/vdpa/mlx5/mlx5_vdpa_mem.c
index 59ce4e891c..a06681b494 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_mem.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_mem.c
@@ -103,15 +103,15 @@ mlx5_vdpa_vhost_mem_regions_prepare(int vid, uint8_t *mode, uint64_t *mem_size,
 			size = mem->regions[i].guest_phys_addr -
 				(mem->regions[i - 1].guest_phys_addr +
 				 mem->regions[i - 1].size);
-			*gcd = rte_get_gcd(*gcd, size);
+			*gcd = rte_get_gcd64(*gcd, size);
 			klm_entries_num += KLM_NUM_MAX_ALIGN(size);
 		}
 		size = mem->regions[i].size;
-		*gcd = rte_get_gcd(*gcd, size);
+		*gcd = rte_get_gcd64(*gcd, size);
 		klm_entries_num += KLM_NUM_MAX_ALIGN(size);
 	}
 	if (*gcd > MLX5_MAX_KLM_BYTE_COUNT)
-		*gcd = rte_get_gcd(*gcd, MLX5_MAX_KLM_BYTE_COUNT);
+		*gcd = rte_get_gcd64(*gcd, MLX5_MAX_KLM_BYTE_COUNT);
 	if (!RTE_IS_POWER_OF_2(*gcd)) {
 		uint64_t candidate_gcd = rte_align64prevpow2(*gcd);
 
-- 
2.33.0


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

* Re: [dpdk-dev] [PATCH v2 1/2] sched: adds function to get 64 bits greatest common divisor
  2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 1/2] " Xueming Li
@ 2021-09-23  9:53         ` Kevin Traynor
  0 siblings, 0 replies; 10+ messages in thread
From: Kevin Traynor @ 2021-09-23  9:53 UTC (permalink / raw)
  To: Xueming Li, Matan Azrad, dev; +Cc: stable, Cristian Dumitrescu, Jasvinder Singh

On 23/09/2021 09:11, Xueming Li wrote:
> This patch adds new function that compute the greatest common
> divisor of 64 bits, also changes the original 32 bits function to call
> this new 64 bits version.
> 
> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> Cc: stable@dpdk.org
> ---

lgtm.

Acked-by: Kevin Traynor <ktraynor@redhat.com>


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

* Re: [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor
  2021-09-23  8:11     ` [dpdk-dev] [PATCH v2 0/2] " Xueming Li
  2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 1/2] " Xueming Li
  2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 2/2] vdpa/mlx5: fix large VM memory region registration Xueming Li
@ 2021-09-27 15:26       ` Thomas Monjalon
  2021-09-28  5:47         ` Xueming(Steven) Li
  2 siblings, 1 reply; 10+ messages in thread
From: Thomas Monjalon @ 2021-09-27 15:26 UTC (permalink / raw)
  To: Xueming Li; +Cc: Matan Azrad, dev, Kevin Traynor

> Xueming Li (2):
>   sched: adds function to get 64 bits greatest common divisor
>   vdpa/mlx5: fix large VM memory region registration

Series applied, thanks.

Note: commit logs are arranged, especially for adding verbs
and sorting tags.



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

* Re: [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor
  2021-09-27 15:26       ` [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor Thomas Monjalon
@ 2021-09-28  5:47         ` Xueming(Steven) Li
  0 siblings, 0 replies; 10+ messages in thread
From: Xueming(Steven) Li @ 2021-09-28  5:47 UTC (permalink / raw)
  To: NBU-Contact-Thomas Monjalon; +Cc: Matan Azrad, dev, ktraynor

On Mon, 2021-09-27 at 17:26 +0200, Thomas Monjalon wrote:
> > Xueming Li (2):
> >   sched: adds function to get 64 bits greatest common divisor
> >   vdpa/mlx5: fix large VM memory region registration
> 
> Series applied, thanks.
> 
> Note: commit logs are arranged, especially for adding verbs
> and sorting tags.

Thanks very much!

> 
> 


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

end of thread, other threads:[~2021-09-28  5:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23  8:15 [dpdk-dev] [PATCH] sched: support 64 bits greatest common divisor Xueming Li
2021-09-15 10:26 ` [dpdk-dev] [PATCH v1] sched: adds function to get " Xueming Li
2021-09-22 17:09   ` Kevin Traynor
2021-09-23  5:34     ` Xueming(Steven) Li
2021-09-23  8:11     ` [dpdk-dev] [PATCH v2 0/2] " Xueming Li
2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 1/2] " Xueming Li
2021-09-23  9:53         ` Kevin Traynor
2021-09-23  8:11       ` [dpdk-dev] [PATCH v2 2/2] vdpa/mlx5: fix large VM memory region registration Xueming Li
2021-09-27 15:26       ` [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor Thomas Monjalon
2021-09-28  5:47         ` Xueming(Steven) Li

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