[3/8] lpm: enable on Windows

Message ID 20221201014440.11896-4-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Enable building more on Windows |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Dec. 1, 2022, 1:44 a.m. UTC
  This builds on Windows without changes.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_lpm.c       | 15 +--------------
 app/test/test_lpm6.c      | 12 ------------
 app/test/test_lpm6_data.h |  3 ++-
 app/test/test_lpm6_perf.c | 14 +-------------
 app/test/test_lpm_perf.c  | 39 ++++++++++++---------------------------
 lib/lpm/meson.build       |  6 ------
 6 files changed, 16 insertions(+), 73 deletions(-)
  

Comments

Tyler Retzlaff Dec. 1, 2022, 11:53 p.m. UTC | #1
On Wed, Nov 30, 2022 at 05:44:34PM -0800, Stephen Hemminger wrote:
> This builds on Windows without changes.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---

Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  

Patch

diff --git a/app/test/test_lpm.c b/app/test/test_lpm.c
index bceb9ae743d7..37b460af3a96 100644
--- a/app/test/test_lpm.c
+++ b/app/test/test_lpm.c
@@ -2,18 +2,6 @@ 
  * Copyright(c) 2010-2014 Intel Corporation
  */
 
-#include "test.h"
-
-#ifdef RTE_EXEC_ENV_WINDOWS
-static int
-test_lpm(void)
-{
-	printf("lpm not supported on Windows, skipping test\n");
-	return TEST_SKIPPED;
-}
-
-#else
-
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -22,6 +10,7 @@  test_lpm(void)
 #include <rte_lpm.h>
 #include <rte_malloc.h>
 
+#include "test.h"
 #include "test_xmmt_ops.h"
 
 #define TEST_LPM_ASSERT(cond) do {                                            \
@@ -1595,6 +1584,4 @@  test_lpm(void)
 	return global_status;
 }
 
-#endif /* !RTE_EXEC_ENV_WINDOWS */
-
 REGISTER_TEST_COMMAND(lpm_autotest, test_lpm);
diff --git a/app/test/test_lpm6.c b/app/test/test_lpm6.c
index 1f44392db739..b6b6f8615ea5 100644
--- a/app/test/test_lpm6.c
+++ b/app/test/test_lpm6.c
@@ -10,16 +10,6 @@ 
 #include <string.h>
 
 #include <rte_memory.h>
-#ifdef RTE_EXEC_ENV_WINDOWS
-static int
-test_lpm6(void)
-{
-	printf("lpm6 not supported on Windows, skipping test\n");
-	return TEST_SKIPPED;
-}
-
-#else
-
 #include <rte_lpm6.h>
 
 #include "test_lpm6_data.h"
@@ -1803,6 +1793,4 @@  test_lpm6(void)
 	return global_status;
 }
 
-#endif /* !RTE_EXEC_ENV_WINDOWS */
-
 REGISTER_TEST_COMMAND(lpm6_autotest, test_lpm6);
diff --git a/app/test/test_lpm6_data.h b/app/test/test_lpm6_data.h
index da9b161f20e5..3a1fa25f8433 100644
--- a/app/test/test_lpm6_data.h
+++ b/app/test/test_lpm6_data.h
@@ -6,6 +6,7 @@ 
 
 #include <stdint.h>
 #include <stdlib.h>
+#include <rte_random.h>
 
 struct rules_tbl_entry {
 	uint8_t ip[16];
@@ -1129,7 +1130,7 @@  static void generate_large_ips_table(int gen_expected_next_hop)
 
 	for (i = 0; i < NUM_IPS_ENTRIES; i++) {
 		for (j = 0; j < 16; j++)
-			large_ips_table[i].ip[j] = lrand48();
+			large_ips_table[i].ip[j] = rte_rand();
 	}
 
 	for (k = j = 0, i = 0; i < NUM_IPS_ENTRIES; i++) {
diff --git a/app/test/test_lpm6_perf.c b/app/test/test_lpm6_perf.c
index aaf2773b6fac..5b684686a687 100644
--- a/app/test/test_lpm6_perf.c
+++ b/app/test/test_lpm6_perf.c
@@ -2,17 +2,6 @@ 
  * Copyright(c) 2010-2014 Intel Corporation
  */
 
-#include "test.h"
-
-#ifdef RTE_EXEC_ENV_WINDOWS
-static int
-test_lpm6_perf(void)
-{
-	printf("lpm6_perf not supported on Windows, skipping test\n");
-	return TEST_SKIPPED;
-}
-
-#else
 
 #include <stdio.h>
 #include <stdint.h>
@@ -24,6 +13,7 @@  test_lpm6_perf(void)
 #include <rte_memory.h>
 #include <rte_lpm6.h>
 
+#include "test.h"
 #include "test_lpm6_data.h"
 
 #define TEST_LPM_ASSERT(cond) do {                                            \
@@ -171,6 +161,4 @@  test_lpm6_perf(void)
 	return 0;
 }
 
-#endif /* !RTE_EXEC_ENV_WINDOWS */
-
 REGISTER_TEST_COMMAND(lpm6_perf_autotest, test_lpm6_perf);
diff --git a/app/test/test_lpm_perf.c b/app/test/test_lpm_perf.c
index e858716f909b..e72437ba3850 100644
--- a/app/test/test_lpm_perf.c
+++ b/app/test/test_lpm_perf.c
@@ -3,17 +3,6 @@ 
  * Copyright(c) 2020 Arm Limited
  */
 
-#include "test.h"
-
-#ifdef RTE_EXEC_ENV_WINDOWS
-static int
-test_lpm_perf(void)
-{
-	printf("lpm_perf not supported on Windows, skipping test\n");
-	return TEST_SKIPPED;
-}
-
-#else
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -25,7 +14,9 @@  test_lpm_perf(void)
 #include <rte_malloc.h>
 #include <rte_ip.h>
 #include <rte_lpm.h>
+#include <rte_spinlock.h>
 
+#include "test.h"
 #include "test_xmmt_ops.h"
 
 struct rte_lpm *lpm;
@@ -34,8 +25,9 @@  static volatile uint8_t writer_done;
 static volatile uint32_t thr_id;
 static uint64_t gwrite_cycles;
 static uint32_t num_writers;
-/* LPM APIs are not thread safe, use mutex to provide thread safety */
-static pthread_mutex_t lpm_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/* LPM APIs are not thread safe, use spinlock */
+static rte_spinlock_t lpm_lock = RTE_SPINLOCK_INITIALIZER;
 
 /* Report quiescent state interval every 1024 lookups. Larger critical
  * sections in reader will result in writer polling multiple times.
@@ -267,7 +259,7 @@  static void generate_random_rule_prefix(uint32_t ip_class, uint8_t depth)
 	/* Only generate rest bits except the most significant
 	 * fixed bits for IP address class
 	 */
-	start = lrand48() & mask;
+	start = rte_rand() & mask;
 	ptr_rule = &large_route_table[num_route_entries];
 	ptr_ldepth_rule = &large_ldepth_route_table[num_ldepth_route_entries];
 	for (k = 0; k < rule_num; k++) {
@@ -296,7 +288,7 @@  static void insert_rule_in_random_pos(uint32_t ip, uint8_t depth)
 	struct route_rule tmp;
 
 	do {
-		pos = lrand48();
+		pos = rte_rand();
 		try_count++;
 	} while ((try_count < 10) && (pos > num_route_entries));
 
@@ -452,8 +444,7 @@  test_lpm_rcu_qsbr_writer(void *arg)
 	for (i = 0; i < RCU_ITERATIONS; i++) {
 		/* Add all the entries */
 		for (j = si; j < ei; j++) {
-			if (num_writers > 1)
-				pthread_mutex_lock(&lpm_mutex);
+			rte_spinlock_lock(&lpm_lock);
 			if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip,
 					large_ldepth_route_table[j].depth,
 					next_hop_add) != 0) {
@@ -461,22 +452,19 @@  test_lpm_rcu_qsbr_writer(void *arg)
 					i, j);
 				goto error;
 			}
-			if (num_writers > 1)
-				pthread_mutex_unlock(&lpm_mutex);
+			rte_spinlock_unlock(&lpm_lock);
 		}
 
 		/* Delete all the entries */
 		for (j = si; j < ei; j++) {
-			if (num_writers > 1)
-				pthread_mutex_lock(&lpm_mutex);
+			rte_spinlock_lock(&lpm_lock);
 			if (rte_lpm_delete(lpm, large_ldepth_route_table[j].ip,
 				large_ldepth_route_table[j].depth) != 0) {
 				printf("Failed to delete iteration %d, route# %d\n",
 					i, j);
 				goto error;
 			}
-			if (num_writers > 1)
-				pthread_mutex_unlock(&lpm_mutex);
+			rte_spinlock_unlock(&lpm_lock);
 		}
 	}
 
@@ -487,8 +475,7 @@  test_lpm_rcu_qsbr_writer(void *arg)
 	return 0;
 
 error:
-	if (num_writers > 1)
-		pthread_mutex_unlock(&lpm_mutex);
+	rte_spinlock_unlock(&lpm_lock);
 	return -1;
 }
 
@@ -773,6 +760,4 @@  test_lpm_perf(void)
 	return 0;
 }
 
-#endif /* !RTE_EXEC_ENV_WINDOWS */
-
 REGISTER_TEST_COMMAND(lpm_perf_autotest, test_lpm_perf);
diff --git a/lib/lpm/meson.build b/lib/lpm/meson.build
index 6b47361fcec0..4cd48886fc41 100644
--- a/lib/lpm/meson.build
+++ b/lib/lpm/meson.build
@@ -1,12 +1,6 @@ 
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-if is_windows
-    build = false
-    reason = 'not supported on Windows'
-    subdir_done()
-endif
-
 sources = files('rte_lpm.c', 'rte_lpm6.c')
 headers = files('rte_lpm.h', 'rte_lpm6.h')
 # since header files have different names, we can install all vector headers