From patchwork Mon Nov 2 23:52:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dharmik Thakkar X-Patchwork-Id: 83449 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EDB95A04E7; Tue, 3 Nov 2020 00:55:44 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 54AAD5946; Tue, 3 Nov 2020 00:54:51 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id EF083378B; Tue, 3 Nov 2020 00:54:43 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5B3331424; Mon, 2 Nov 2020 15:54:42 -0800 (PST) Received: from localhost.localdomain (2p2660v4-1.austin.arm.com [10.118.13.220]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 53C133F718; Mon, 2 Nov 2020 15:54:42 -0800 (PST) From: Dharmik Thakkar To: Bruce Richardson , Vladimir Medvedkin , Honnappa Nagarahalli , Ruifeng Wang , Gavin Hu Cc: dev@dpdk.org, nd@arm.com, Dharmik Thakkar , stable@dpdk.org Date: Mon, 2 Nov 2020 17:52:00 -0600 Message-Id: <20201102235203.6342-2-dharmik.thakkar@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201102235203.6342-1-dharmik.thakkar@arm.com> References: <20201029153634.10647-1-dharmik.thakkar@arm.com> <20201102235203.6342-1-dharmik.thakkar@arm.com> Subject: [dpdk-dev] [PATCH v2 1/4] test/lpm: fix cycle calculation in rcu qsbr perf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Fix incorrect calculations for LPM adds, LPM deletes, and average cycles in RCU QSBR perf tests Since, rcu qsbr tests run for 'RCU_ITERATIONS' and not 'ITERATIONS', replace 'ITERATIONS' with 'RCU_ITERATIONS' for calculating adds, deletes, and cycles. Also, for multi-writer perf test, each writer only writes half of NUM_LDEPTH_ROUTE_ENTRIES. For 2 writers, total adds (or deletes) should be (RCU_ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES) instead of (2 * RCU_ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES). Since, for both the single and multi writer tests, total adds/deletes is equal to (RCU_ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES), this has been replaced with a macro 'TOTAL_WRITES' and furthermore, 'g_writes' has been removed since it is always a fixed value equal to TOTAL_WRITES. Fixes: eff30b59cc2e ("test/lpm: add RCU performance tests") Cc: honnappa.nagarahalli@arm.com Cc: stable@dpdk.org Signed-off-by: Dharmik Thakkar Reviewed-by: Ruifeng Wang Reviewed-by: Honnappa Nagarahalli --- app/test/test_lpm_perf.c | 45 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/app/test/test_lpm_perf.c b/app/test/test_lpm_perf.c index c5a238b9d1e8..45164b23214b 100644 --- a/app/test/test_lpm_perf.c +++ b/app/test/test_lpm_perf.c @@ -23,7 +23,6 @@ static struct rte_rcu_qsbr *rv; static volatile uint8_t writer_done; static volatile uint32_t thr_id; static uint64_t gwrite_cycles; -static uint64_t gwrites; /* LPM APIs are not thread safe, use mutex to provide thread safety */ static pthread_mutex_t lpm_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -60,6 +59,8 @@ static uint32_t num_ldepth_route_entries; #define NUM_ROUTE_ENTRIES num_route_entries #define NUM_LDEPTH_ROUTE_ENTRIES num_ldepth_route_entries +#define TOTAL_WRITES (RCU_ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES) + enum { IP_CLASS_A, IP_CLASS_B, @@ -432,7 +433,6 @@ test_lpm_rcu_qsbr_writer(void *arg) uint8_t core_id = (uint8_t)((uintptr_t)arg); uint32_t next_hop_add = 0xAA; - RTE_SET_USED(arg); /* 2 writer threads are used */ if (core_id % 2 == 0) { si = 0; @@ -472,9 +472,6 @@ test_lpm_rcu_qsbr_writer(void *arg) total_cycles = rte_rdtsc_precise() - begin; __atomic_fetch_add(&gwrite_cycles, total_cycles, __ATOMIC_RELAXED); - __atomic_fetch_add(&gwrites, - 2 * NUM_LDEPTH_ROUTE_ENTRIES * RCU_ITERATIONS, - __ATOMIC_RELAXED); return 0; } @@ -528,7 +525,6 @@ test_lpm_rcu_perf_multi_writer(void) writer_done = 0; __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED); - __atomic_store_n(&gwrites, 0, __ATOMIC_RELAXED); __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST); @@ -548,14 +544,11 @@ test_lpm_rcu_perf_multi_writer(void) if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) goto error; - printf("Total LPM Adds: %d\n", - 2 * ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); - printf("Total LPM Deletes: %d\n", - 2 * ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); + printf("Total LPM Adds: %d\n", TOTAL_WRITES); + printf("Total LPM Deletes: %d\n", TOTAL_WRITES); printf("Average LPM Add/Del: %"PRIu64" cycles\n", - __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) / - __atomic_load_n(&gwrites, __ATOMIC_RELAXED) - ); + __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) + / TOTAL_WRITES); /* Wait and check return value from reader threads */ writer_done = 1; @@ -581,7 +574,6 @@ test_lpm_rcu_perf_multi_writer(void) writer_done = 0; __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED); - __atomic_store_n(&gwrites, 0, __ATOMIC_RELAXED); __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST); /* Launch reader threads */ @@ -600,14 +592,11 @@ test_lpm_rcu_perf_multi_writer(void) if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) goto error; - printf("Total LPM Adds: %d\n", - 2 * ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); - printf("Total LPM Deletes: %d\n", - 2 * ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); + printf("Total LPM Adds: %d\n", TOTAL_WRITES); + printf("Total LPM Deletes: %d\n", TOTAL_WRITES); printf("Average LPM Add/Del: %"PRIu64" cycles\n", - __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) / - __atomic_load_n(&gwrites, __ATOMIC_RELAXED) - ); + __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) + / TOTAL_WRITES); writer_done = 1; /* Wait and check return value from reader threads */ @@ -711,11 +700,10 @@ test_lpm_rcu_perf(void) } total_cycles = rte_rdtsc_precise() - begin; - printf("Total LPM Adds: %d\n", ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); - printf("Total LPM Deletes: %d\n", - ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); + printf("Total LPM Adds: %d\n", TOTAL_WRITES); + printf("Total LPM Deletes: %d\n", TOTAL_WRITES); printf("Average LPM Add/Del: %g cycles\n", - (double)total_cycles / (NUM_LDEPTH_ROUTE_ENTRIES * ITERATIONS)); + (double)total_cycles / TOTAL_WRITES); writer_done = 1; /* Wait and check return value from reader threads */ @@ -771,11 +759,10 @@ test_lpm_rcu_perf(void) } total_cycles = rte_rdtsc_precise() - begin; - printf("Total LPM Adds: %d\n", ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); - printf("Total LPM Deletes: %d\n", - ITERATIONS * NUM_LDEPTH_ROUTE_ENTRIES); + printf("Total LPM Adds: %d\n", TOTAL_WRITES); + printf("Total LPM Deletes: %d\n", TOTAL_WRITES); printf("Average LPM Add/Del: %g cycles\n", - (double)total_cycles / (NUM_LDEPTH_ROUTE_ENTRIES * ITERATIONS)); + (double)total_cycles / TOTAL_WRITES); writer_done = 1; /* Wait and check return value from reader threads */ From patchwork Mon Nov 2 23:52:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dharmik Thakkar X-Patchwork-Id: 83448 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B51DAA04E7; Tue, 3 Nov 2020 00:55:25 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9C7574C96; Tue, 3 Nov 2020 00:54:49 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 151C137AF; Tue, 3 Nov 2020 00:54:44 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 73A58142F; Mon, 2 Nov 2020 15:54:42 -0800 (PST) Received: from localhost.localdomain (2p2660v4-1.austin.arm.com [10.118.13.220]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6D37F3F718; Mon, 2 Nov 2020 15:54:42 -0800 (PST) From: Dharmik Thakkar To: Bruce Richardson , Vladimir Medvedkin , Honnappa Nagarahalli , Gavin Hu , Ruifeng Wang Cc: dev@dpdk.org, nd@arm.com, Dharmik Thakkar , stable@dpdk.org Date: Mon, 2 Nov 2020 17:52:01 -0600 Message-Id: <20201102235203.6342-3-dharmik.thakkar@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201102235203.6342-1-dharmik.thakkar@arm.com> References: <20201029153634.10647-1-dharmik.thakkar@arm.com> <20201102235203.6342-1-dharmik.thakkar@arm.com> Subject: [dpdk-dev] [PATCH v2 2/4] test/lpm: return error on failure in rcu qsbr perf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Return error if Add/Delete fail in multiwriter perf test Fixes: eff30b59cc2e ("test/lpm: add RCU performance tests") Cc: honnappa.nagarahalli@arm.com Cc: stable@dpdk.org Signed-off-by: Dharmik Thakkar Reviewed-by: Ruifeng Wang --- app/test/test_lpm_perf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/test/test_lpm_perf.c b/app/test/test_lpm_perf.c index 45164b23214b..55084816ab91 100644 --- a/app/test/test_lpm_perf.c +++ b/app/test/test_lpm_perf.c @@ -453,6 +453,8 @@ test_lpm_rcu_qsbr_writer(void *arg) next_hop_add) != 0) { printf("Failed to add iteration %d, route# %d\n", i, j); + pthread_mutex_unlock(&lpm_mutex); + return -1; } pthread_mutex_unlock(&lpm_mutex); } @@ -464,6 +466,8 @@ test_lpm_rcu_qsbr_writer(void *arg) large_ldepth_route_table[j].depth) != 0) { printf("Failed to delete iteration %d, route# %d\n", i, j); + pthread_mutex_unlock(&lpm_mutex); + return -1; } pthread_mutex_unlock(&lpm_mutex); } From patchwork Mon Nov 2 23:52:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dharmik Thakkar X-Patchwork-Id: 83450 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D0C13A04E7; Tue, 3 Nov 2020 00:56:03 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BCF2D5AB2; Tue, 3 Nov 2020 00:54:52 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 301583976; Tue, 3 Nov 2020 00:54:44 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8CA0F143B; Mon, 2 Nov 2020 15:54:42 -0800 (PST) Received: from localhost.localdomain (2p2660v4-1.austin.arm.com [10.118.13.220]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 85D073F718; Mon, 2 Nov 2020 15:54:42 -0800 (PST) From: Dharmik Thakkar To: Bruce Richardson , Vladimir Medvedkin , Ruifeng Wang , Honnappa Nagarahalli , Gavin Hu Cc: dev@dpdk.org, nd@arm.com, Dharmik Thakkar , stable@dpdk.org Date: Mon, 2 Nov 2020 17:52:02 -0600 Message-Id: <20201102235203.6342-4-dharmik.thakkar@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201102235203.6342-1-dharmik.thakkar@arm.com> References: <20201029153634.10647-1-dharmik.thakkar@arm.com> <20201102235203.6342-1-dharmik.thakkar@arm.com> Subject: [dpdk-dev] [PATCH v2 3/4] test/lpm: remove error checking in rcu qsbr perf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Remove redundant error checking for reader threads since they never return error. Fixes: eff30b59cc2e ("test/lpm: add RCU performance tests") Cc: honnappa.nagarahalli@arm.com Cc: stable@dpdk.org Signed-off-by: Dharmik Thakkar Reviewed-by: Ruifeng Wang --- app/test/test_lpm_perf.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/test/test_lpm_perf.c b/app/test/test_lpm_perf.c index 55084816ab91..224c92fa3d65 100644 --- a/app/test/test_lpm_perf.c +++ b/app/test/test_lpm_perf.c @@ -554,11 +554,10 @@ test_lpm_rcu_perf_multi_writer(void) __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) / TOTAL_WRITES); - /* Wait and check return value from reader threads */ writer_done = 1; + /* Wait until all readers have exited */ for (i = 2; i < num_cores; i++) - if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) - goto error; + rte_eal_wait_lcore(enabled_core_ids[i]); rte_lpm_free(lpm); rte_free(rv); @@ -603,10 +602,9 @@ test_lpm_rcu_perf_multi_writer(void) / TOTAL_WRITES); writer_done = 1; - /* Wait and check return value from reader threads */ + /* Wait until all readers have exited */ for (i = 2; i < num_cores; i++) - if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) - goto error; + rte_eal_wait_lcore(enabled_core_ids[i]); rte_lpm_free(lpm); @@ -710,10 +708,9 @@ test_lpm_rcu_perf(void) (double)total_cycles / TOTAL_WRITES); writer_done = 1; - /* Wait and check return value from reader threads */ + /* Wait until all readers have exited */ for (i = 0; i < num_cores; i++) - if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) - goto error; + if (rte_eal_wait_lcore(enabled_core_ids[i]); rte_lpm_free(lpm); rte_free(rv); @@ -769,11 +766,9 @@ test_lpm_rcu_perf(void) (double)total_cycles / TOTAL_WRITES); writer_done = 1; - /* Wait and check return value from reader threads */ + /* Wait until all readers have exited */ for (i = 0; i < num_cores; i++) - if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) - printf("Warning: lcore %u not finished.\n", - enabled_core_ids[i]); + rte_eal_wait_lcore(enabled_core_ids[i]); rte_lpm_free(lpm); From patchwork Mon Nov 2 23:52:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dharmik Thakkar X-Patchwork-Id: 83447 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9F1ECA04E7; Tue, 3 Nov 2020 00:55:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 206004C7A; Tue, 3 Nov 2020 00:54:48 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 904BC354D for ; Tue, 3 Nov 2020 00:54:44 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A4A33143D; Mon, 2 Nov 2020 15:54:42 -0800 (PST) Received: from localhost.localdomain (2p2660v4-1.austin.arm.com [10.118.13.220]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9CDEA3F718; Mon, 2 Nov 2020 15:54:42 -0800 (PST) From: Dharmik Thakkar To: Bruce Richardson , Vladimir Medvedkin Cc: dev@dpdk.org, nd@arm.com, Dharmik Thakkar Date: Mon, 2 Nov 2020 17:52:03 -0600 Message-Id: <20201102235203.6342-5-dharmik.thakkar@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201102235203.6342-1-dharmik.thakkar@arm.com> References: <20201029153634.10647-1-dharmik.thakkar@arm.com> <20201102235203.6342-1-dharmik.thakkar@arm.com> Subject: [dpdk-dev] [PATCH v2 4/4] test/lpm: avoid code duplication in rcu qsbr perf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Avoid code duplication by combining single and multi threaded tests Signed-off-by: Dharmik Thakkar Reviewed-by: Ruifeng Wang --- app/test/test_lpm_perf.c | 362 ++++++++++----------------------------- 1 file changed, 91 insertions(+), 271 deletions(-) diff --git a/app/test/test_lpm_perf.c b/app/test/test_lpm_perf.c index 224c92fa3d65..229c835c23f7 100644 --- a/app/test/test_lpm_perf.c +++ b/app/test/test_lpm_perf.c @@ -67,6 +67,12 @@ enum { IP_CLASS_C }; +enum { + SINGLE_WRITER = 1, + MULTI_WRITER_1, + MULTI_WRITER_2 +}; + /* struct route_rule_count defines the total number of rules in following a/b/c * each item in a[]/b[]/c[] is the number of common IP address class A/B/C, not * including the ones for private local network. @@ -430,11 +436,16 @@ test_lpm_rcu_qsbr_writer(void *arg) { unsigned int i, j, si, ei; uint64_t begin, total_cycles; - uint8_t core_id = (uint8_t)((uintptr_t)arg); + uint8_t writer_id = (uint8_t)((uintptr_t)arg); uint32_t next_hop_add = 0xAA; - /* 2 writer threads are used */ - if (core_id % 2 == 0) { + /* Single writer (writer_id = 1) */ + if (writer_id == SINGLE_WRITER) { + si = 0; + ei = NUM_LDEPTH_ROUTE_ENTRIES; + } + /* 2 Writers (writer_id = 2/3)*/ + else if (writer_id == MULTI_WRITER_1) { si = 0; ei = NUM_LDEPTH_ROUTE_ENTRIES / 2; } else { @@ -447,29 +458,35 @@ test_lpm_rcu_qsbr_writer(void *arg) for (i = 0; i < RCU_ITERATIONS; i++) { /* Add all the entries */ for (j = si; j < ei; j++) { - pthread_mutex_lock(&lpm_mutex); + if (writer_id != SINGLE_WRITER) + pthread_mutex_lock(&lpm_mutex); if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip, large_ldepth_route_table[j].depth, next_hop_add) != 0) { printf("Failed to add iteration %d, route# %d\n", i, j); - pthread_mutex_unlock(&lpm_mutex); + if (writer_id != SINGLE_WRITER) + pthread_mutex_unlock(&lpm_mutex); return -1; } - pthread_mutex_unlock(&lpm_mutex); + if (writer_id != SINGLE_WRITER) + pthread_mutex_unlock(&lpm_mutex); } /* Delete all the entries */ for (j = si; j < ei; j++) { - pthread_mutex_lock(&lpm_mutex); + if (writer_id != SINGLE_WRITER) + pthread_mutex_lock(&lpm_mutex); 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); - pthread_mutex_unlock(&lpm_mutex); + if (writer_id != SINGLE_WRITER) + pthread_mutex_unlock(&lpm_mutex); return -1; } - pthread_mutex_unlock(&lpm_mutex); + if (writer_id != SINGLE_WRITER) + pthread_mutex_unlock(&lpm_mutex); } } @@ -482,16 +499,17 @@ test_lpm_rcu_qsbr_writer(void *arg) /* * Functional test: - * 2 writers, rest are readers + * 1/2 writers, rest are readers */ static int -test_lpm_rcu_perf_multi_writer(void) +test_lpm_rcu_perf_multi_writer(uint8_t use_rcu) { struct rte_lpm_config config; size_t sz; - unsigned int i; + unsigned int i, j; uint16_t core_id; struct rte_lpm_rcu_config rcu_cfg = {0}; + int (*reader_f)(void *arg) = NULL; if (rte_lcore_count() < 3) { printf("Not enough cores for lpm_rcu_perf_autotest, expecting at least 3\n"); @@ -504,273 +522,76 @@ test_lpm_rcu_perf_multi_writer(void) num_cores++; } - printf("\nPerf test: 2 writers, %d readers, RCU integration enabled\n", - num_cores - 2); - - /* Create LPM table */ - config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES; - config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES; - config.flags = 0; - lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config); - TEST_LPM_ASSERT(lpm != NULL); - - /* Init RCU variable */ - sz = rte_rcu_qsbr_get_memsize(num_cores); - rv = (struct rte_rcu_qsbr *)rte_zmalloc("rcu0", sz, - RTE_CACHE_LINE_SIZE); - rte_rcu_qsbr_init(rv, num_cores); - - rcu_cfg.v = rv; - /* Assign the RCU variable to LPM */ - if (rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg) != 0) { - printf("RCU variable assignment failed\n"); - goto error; - } - - writer_done = 0; - __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED); - - __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST); - - /* Launch reader threads */ - for (i = 2; i < num_cores; i++) - rte_eal_remote_launch(test_lpm_rcu_qsbr_reader, NULL, - enabled_core_ids[i]); - - /* Launch writer threads */ - for (i = 0; i < 2; i++) - rte_eal_remote_launch(test_lpm_rcu_qsbr_writer, - (void *)(uintptr_t)i, - enabled_core_ids[i]); - - /* Wait for writer threads */ - for (i = 0; i < 2; i++) - if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) - goto error; - - printf("Total LPM Adds: %d\n", TOTAL_WRITES); - printf("Total LPM Deletes: %d\n", TOTAL_WRITES); - printf("Average LPM Add/Del: %"PRIu64" cycles\n", - __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) - / TOTAL_WRITES); - - writer_done = 1; - /* Wait until all readers have exited */ - for (i = 2; i < num_cores; i++) - rte_eal_wait_lcore(enabled_core_ids[i]); - - rte_lpm_free(lpm); - rte_free(rv); - lpm = NULL; - rv = NULL; - - /* Test without RCU integration */ - printf("\nPerf test: 2 writers, %d readers, RCU integration disabled\n", - num_cores - 2); - - /* Create LPM table */ - config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES; - config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES; - config.flags = 0; - lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config); - TEST_LPM_ASSERT(lpm != NULL); - - writer_done = 0; - __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED); - __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST); - - /* Launch reader threads */ - for (i = 2; i < num_cores; i++) - rte_eal_remote_launch(test_lpm_reader, NULL, - enabled_core_ids[i]); - - /* Launch writer threads */ - for (i = 0; i < 2; i++) - rte_eal_remote_launch(test_lpm_rcu_qsbr_writer, - (void *)(uintptr_t)i, - enabled_core_ids[i]); - - /* Wait for writer threads */ - for (i = 0; i < 2; i++) - if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) - goto error; - - printf("Total LPM Adds: %d\n", TOTAL_WRITES); - printf("Total LPM Deletes: %d\n", TOTAL_WRITES); - printf("Average LPM Add/Del: %"PRIu64" cycles\n", - __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) - / TOTAL_WRITES); - - writer_done = 1; - /* Wait until all readers have exited */ - for (i = 2; i < num_cores; i++) - rte_eal_wait_lcore(enabled_core_ids[i]); - - rte_lpm_free(lpm); - - return 0; - -error: - writer_done = 1; - /* Wait until all readers have exited */ - rte_eal_mp_wait_lcore(); - - rte_lpm_free(lpm); - rte_free(rv); - - return -1; -} - -/* - * Functional test: - * Single writer, rest are readers - */ -static int -test_lpm_rcu_perf(void) -{ - struct rte_lpm_config config; - uint64_t begin, total_cycles; - size_t sz; - unsigned int i, j; - uint16_t core_id; - uint32_t next_hop_add = 0xAA; - struct rte_lpm_rcu_config rcu_cfg = {0}; - - if (rte_lcore_count() < 2) { - printf("Not enough cores for lpm_rcu_perf_autotest, expecting at least 2\n"); - return TEST_SKIPPED; - } - - num_cores = 0; - RTE_LCORE_FOREACH_WORKER(core_id) { - enabled_core_ids[num_cores] = core_id; - num_cores++; - } - - printf("\nPerf test: 1 writer, %d readers, RCU integration enabled\n", - num_cores); - - /* Create LPM table */ - config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES; - config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES; - config.flags = 0; - lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config); - TEST_LPM_ASSERT(lpm != NULL); - - /* Init RCU variable */ - sz = rte_rcu_qsbr_get_memsize(num_cores); - rv = (struct rte_rcu_qsbr *)rte_zmalloc("rcu0", sz, - RTE_CACHE_LINE_SIZE); - rte_rcu_qsbr_init(rv, num_cores); - - rcu_cfg.v = rv; - /* Assign the RCU variable to LPM */ - if (rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg) != 0) { - printf("RCU variable assignment failed\n"); - goto error; - } - - writer_done = 0; - __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST); - - /* Launch reader threads */ - for (i = 0; i < num_cores; i++) - rte_eal_remote_launch(test_lpm_rcu_qsbr_reader, NULL, - enabled_core_ids[i]); - - /* Measure add/delete. */ - begin = rte_rdtsc_precise(); - for (i = 0; i < RCU_ITERATIONS; i++) { - /* Add all the entries */ - for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++) - if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip, - large_ldepth_route_table[j].depth, - next_hop_add) != 0) { - printf("Failed to add iteration %d, route# %d\n", - i, j); + for (j = 1; j < 3; j++) { + if (use_rcu) + printf("\nPerf test: %d writer(s), %d reader(s)," + " RCU integration enabled\n", j, num_cores - j); + else + printf("\nPerf test: %d writer(s), %d reader(s)," + " RCU integration disabled\n", j, num_cores - j); + + /* Create LPM table */ + config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES; + config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES; + config.flags = 0; + lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config); + TEST_LPM_ASSERT(lpm != NULL); + + /* Init RCU variable */ + if (use_rcu) { + sz = rte_rcu_qsbr_get_memsize(num_cores); + rv = (struct rte_rcu_qsbr *)rte_zmalloc("rcu0", sz, + RTE_CACHE_LINE_SIZE); + rte_rcu_qsbr_init(rv, num_cores); + + rcu_cfg.v = rv; + /* Assign the RCU variable to LPM */ + if (rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg) != 0) { + printf("RCU variable assignment failed\n"); goto error; } - /* Delete all the entries */ - for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++) - 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; - } - } - total_cycles = rte_rdtsc_precise() - begin; + reader_f = test_lpm_rcu_qsbr_reader; + } else + reader_f = test_lpm_reader; - printf("Total LPM Adds: %d\n", TOTAL_WRITES); - printf("Total LPM Deletes: %d\n", TOTAL_WRITES); - printf("Average LPM Add/Del: %g cycles\n", - (double)total_cycles / TOTAL_WRITES); + writer_done = 0; + __atomic_store_n(&gwrite_cycles, 0, __ATOMIC_RELAXED); - writer_done = 1; - /* Wait until all readers have exited */ - for (i = 0; i < num_cores; i++) - if (rte_eal_wait_lcore(enabled_core_ids[i]); - - rte_lpm_free(lpm); - rte_free(rv); - lpm = NULL; - rv = NULL; - - /* Test without RCU integration */ - printf("\nPerf test: 1 writer, %d readers, RCU integration disabled\n", - num_cores); - - /* Create LPM table */ - config.max_rules = NUM_LDEPTH_ROUTE_ENTRIES; - config.number_tbl8s = NUM_LDEPTH_ROUTE_ENTRIES; - config.flags = 0; - lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config); - TEST_LPM_ASSERT(lpm != NULL); + __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST); - writer_done = 0; - __atomic_store_n(&thr_id, 0, __ATOMIC_SEQ_CST); + /* Launch reader threads */ + for (i = j; i < num_cores; i++) + rte_eal_remote_launch(reader_f, NULL, + enabled_core_ids[i]); - /* Launch reader threads */ - for (i = 0; i < num_cores; i++) - rte_eal_remote_launch(test_lpm_reader, NULL, - enabled_core_ids[i]); + /* Launch writer threads */ + for (i = 0; i < j; i++) + rte_eal_remote_launch(test_lpm_rcu_qsbr_writer, + (void *)(uintptr_t)(i + j), + enabled_core_ids[i]); - /* Measure add/delete. */ - begin = rte_rdtsc_precise(); - for (i = 0; i < RCU_ITERATIONS; i++) { - /* Add all the entries */ - for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++) - if (rte_lpm_add(lpm, large_ldepth_route_table[j].ip, - large_ldepth_route_table[j].depth, - next_hop_add) != 0) { - printf("Failed to add iteration %d, route# %d\n", - i, j); + /* Wait for writer threads */ + for (i = 0; i < j; i++) + if (rte_eal_wait_lcore(enabled_core_ids[i]) < 0) goto error; - } - /* Delete all the entries */ - for (j = 0; j < NUM_LDEPTH_ROUTE_ENTRIES; j++) - 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; - } + printf("Total LPM Adds: %d\n", TOTAL_WRITES); + printf("Total LPM Deletes: %d\n", TOTAL_WRITES); + printf("Average LPM Add/Del: %"PRIu64" cycles\n", + __atomic_load_n(&gwrite_cycles, __ATOMIC_RELAXED) + / TOTAL_WRITES); + + writer_done = 1; + /* Wait until all readers have exited */ + for (i = j; i < num_cores; i++) + rte_eal_wait_lcore(enabled_core_ids[i]); + + rte_lpm_free(lpm); + rte_free(rv); + lpm = NULL; + rv = NULL; } - total_cycles = rte_rdtsc_precise() - begin; - - printf("Total LPM Adds: %d\n", TOTAL_WRITES); - printf("Total LPM Deletes: %d\n", TOTAL_WRITES); - printf("Average LPM Add/Del: %g cycles\n", - (double)total_cycles / TOTAL_WRITES); - - writer_done = 1; - /* Wait until all readers have exited */ - for (i = 0; i < num_cores; i++) - rte_eal_wait_lcore(enabled_core_ids[i]); - - rte_lpm_free(lpm); return 0; @@ -946,9 +767,8 @@ test_lpm_perf(void) rte_lpm_delete_all(lpm); rte_lpm_free(lpm); - test_lpm_rcu_perf(); - - test_lpm_rcu_perf_multi_writer(); + test_lpm_rcu_perf_multi_writer(0); + test_lpm_rcu_perf_multi_writer(1); return 0; }