From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 501DB41E23;
	Thu,  9 Mar 2023 22:31:49 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 3CA8C427E9;
	Thu,  9 Mar 2023 22:31:37 +0100 (CET)
Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com
 [209.85.216.47]) by mails.dpdk.org (Postfix) with ESMTP id 4BFB241140
 for <dev@dpdk.org>; Thu,  9 Mar 2023 22:31:34 +0100 (CET)
Received: by mail-pj1-f47.google.com with SMTP id y2so3355624pjg.3
 for <dev@dpdk.org>; Thu, 09 Mar 2023 13:31:34 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1678397493;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=ax5mZInRB4fc1yOT3KLLkfHkCQkB6zmILq1uP29xQS0=;
 b=GuCU8yZlQDED8xab6zW5Vx8PbQkApf1Vnmk8H+2n6bQnpqTsawWUbWO718/CPdnL+X
 qzZx2MBjmS6kaZjra+6FjfzGb0Ump3RxjRoJcjZtkDk1h+GJAVyLAsBBijEY9zWUw3Gp
 5+5MvVz/0U3VT9tp7GEfB1lSvGFgfHy7r/f24JSAp2KDCR0W28RCvulThGmXjpoZXFo/
 sqFmQcBQYCXjGG0fU31XfmPCM4jRd+LXEt9UKbb10CbzPYxnqmHSlJSmaXECZYGjdTWl
 mzn1cOwwq8ORRTWlRYRuqWOfeWH+PvcyMGNtfPgRx+XsRZFW1a2U38APSXWED+SoXkKi
 o8rQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112; t=1678397493;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=ax5mZInRB4fc1yOT3KLLkfHkCQkB6zmILq1uP29xQS0=;
 b=04jzh3HoSLUaHy2jp32GWbDxi8+H1xZamCWBiAgIKjOTfrPHPsVasGRrio2omi+ViJ
 EU11EmwernXGvGluWq03gfKf0PqitfzHatzxUJqyaxM8Lo9Wnck7ED/gPHdMPkDLcg1P
 GVWsSCmQup9HX/vWnaOwxJN6pomD3QveeQLyGR67F4ilCT0rUngdAlh94EbYzejRNkSq
 qp4rX5vhLdwaLmGzEWr/l5MgEkTEHQ/M/sYEumMJ97JzuGz+VVo7DQ5sUJpPy3Tmwjux
 Tb7g9IsNKNBa5kB5Pp3sdVnL5jSv45DTG2Mez6BuyiOC6klQGKxhm/LRTW57gaWiSKP1
 SDZw==
X-Gm-Message-State: AO0yUKUGVV3o+ho84lCyEVk8D5OuFtshj7ELhek3ZKU5Zx4Iwqu2RYww
 +2g/IA+jBzY2bqt2CspIO8BMmhXrKCU0QMzPM3I8gg==
X-Google-Smtp-Source: AK7set+GECYX71U8To4CqaHT/eeZBBuAgDHO+Osko4FBcn7vxK+rxxL+iQ9O1fn9fny9Cy75jOmCkg==
X-Received: by 2002:a17:903:41c6:b0:19d:181f:511 with SMTP id
 u6-20020a17090341c600b0019d181f0511mr27479487ple.30.1678397493132; 
 Thu, 09 Mar 2023 13:31:33 -0800 (PST)
Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218])
 by smtp.gmail.com with ESMTPSA id
 q3-20020a63cc43000000b00502e4015ff7sm64225pgi.23.2023.03.09.13.31.32
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 09 Mar 2023 13:31:32 -0800 (PST)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
 Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v5 3/9] lpm: enable on Windows
Date: Thu,  9 Mar 2023 13:31:22 -0800
Message-Id: <20230309213128.34146-4-stephen@networkplumber.org>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20230309213128.34146-1-stephen@networkplumber.org>
References: <20221201014440.11896-1-stephen@networkplumber.org>
 <20230309213128.34146-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

This builds on Windows without changes.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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(-)

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
-- 
2.39.2