Skip to contentSkip to conversation

sched: support 64 bits greatest common divisor

PATCH New Xueming Li 3 participants 10 messages Aug 23, 2021 – Sep 28, 2021

Subsystems (2)
lore
Share & tools
lore

Xueming Li

author
#0 lore raw

PATCH 1/1 sched: support 64 bits greatest common divisor

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

---
 lib/sched/rte_sched_common.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/sched/rte_sched_common.h +3 -3
index 96706df7bd..65c03329f6 100644
@@ -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;
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/1 sched: adds function to get 64 bits greatest common divisor

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.

---
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(-)
lib/sched/rte_sched_common.h +16 -3
index 96706df7bd..1056543a84 100644
@@ -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:
Signature · 1 line
2.33.0
#2 lore raw

Re: [dpdk-dev] [PATCH v1] sched: adds function to get 64 bits greatest common divisor

Quoted 4 lines · Xueming Li

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.

Quoted 26 lines

---
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(-)
lib/sched/rte_sched_common.h +3 -3
index 96706df7bd..1056543a84 100644
@@ -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;

lib/sched/rte_sched_common.h rte_get_gcd(uint32_t a, uint32_t b) · line 85

Quoted 10 lines
lib/sched/rte_sched_common.h +7 -0
@@ -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.

Quoted 10 lines
lib/sched/rte_sched_common.h +6 -0
+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:
#3 lore raw

Re: [dpdk-dev] [PATCH v1] sched: adds function to get 64 bits greatest common divisor

Quoted 8 lines · Kevin Traynor
Quoted 4 lines · Xueming Li

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.

Quoted 30 lines
Quoted 30 lines

---
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(-)
lib/sched/rte_sched_common.h +3 -3
index 96706df7bd..1056543a84 100644
@@ -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;
  }
 
Quoted 10 lines

lib/sched/rte_sched_common.h rte_get_gcd(uint32_t a, uint32_t b) · line 85

Quoted 7 lines
lib/sched/rte_sched_common.h +7 -0
+/*
+ * 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.

Quoted 12 lines
Quoted 11 lines
lib/sched/rte_sched_common.h +6 -0
+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:
author
#4 lore raw

v2 cover sched: adds function to get 64 bits greatest common divisor

In reply to 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(-)
Signature · 1 line
2.33.0
author
#5 lore raw

PATCH v2 1/2 sched: adds function to get 64 bits greatest common divisor

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.

---
 lib/sched/rte_sched_common.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
lib/sched/rte_sched_common.h +12 -3
index 96706df7bd..340a0df312 100644
@@ -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:
Signature · 1 line
2.33.0
author
#7 lore raw

PATCH v2 2/2 vdpa/mlx5: fix large VM memory region registration

In reply to Xueming Li

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")
---
 drivers/vdpa/mlx5/mlx5_vdpa_mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/vdpa/mlx5/mlx5_vdpa_mem.c +3 -3
index 59ce4e891c..a06681b494 100644
@@ -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);
 
Signature · 1 line
2.33.0
#8 lore raw

Re: [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor

In reply to Xueming Li
Quoted 3 lines

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.

#9 lore raw

Re: [dpdk-dev] [PATCH v2 0/2] sched: adds function to get 64 bits greatest common divisor

Quoted 8 lines · Thomas Monjalon
Quoted 3 lines

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!

Quoted 2 lines