From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7FC5BA04DB for ; Sat, 17 Oct 2020 05:07:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2B4CEE2B7; Sat, 17 Oct 2020 05:07:45 +0200 (CEST) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 59E5DE2A1 for ; Sat, 17 Oct 2020 05:07:31 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20201017030720euoutp020f7d75ebb50daf239bd58b0019cfc503~_qLti6rPw2305523055euoutp02W for ; Sat, 17 Oct 2020 03:07:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20201017030720euoutp020f7d75ebb50daf239bd58b0019cfc503~_qLti6rPw2305523055euoutp02W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1602904040; bh=QAISyyr3ZOV4JCVDYbcde2TX6o3fexIKja9MtfGYUK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KtML+14qc7lni12dakkJ9Srywdi5EmLBlGOoVvfzXgFrSON5m/oTczuYy2KHQFrBa ZUkMJfgWHORz//mPfdDOVJUIQntjnoy0X4DlXf5wFnnDsqesblVpLxdVM9tjdZCGET TEeGEuIG7BsUMkrDNF+huXDGynRwi+2JZAvO8taY= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20201017030717eucas1p2aa02624ef1d361529b5a3e76a4efe4bd~_qLq001It1097310973eucas1p25; Sat, 17 Oct 2020 03:07:17 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 33.42.05997.5EF5A8F5; Sat, 17 Oct 2020 04:07:17 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20201017030716eucas1p2911112ee3c9e0a3f3dd9a811cbafe77b~_qLqEILay2441224412eucas1p2_; Sat, 17 Oct 2020 03:07:16 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20201017030716eusmtrp1c7a13402ea20fe783d1f8e7f0c1b9e0b~_qLqDjldS3018830188eusmtrp1W; Sat, 17 Oct 2020 03:07:16 +0000 (GMT) X-AuditID: cbfec7f4-65dff7000000176d-c0-5f8a5fe54eec Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CD.DE.06017.4EF5A8F5; Sat, 17 Oct 2020 04:07:16 +0100 (BST) Received: from localhost.localdomain (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20201017030715eusmtip1b8491a2fd8e4e0b99f5ae0317809edd4~_qLpKYN250424404244eusmtip1O; Sat, 17 Oct 2020 03:07:15 +0000 (GMT) From: Lukasz Wojciechowski To: David Hunt , Bruce Richardson Cc: dev@dpdk.org, l.wojciechow@partner.samsung.com, stable@dpdk.org Date: Sat, 17 Oct 2020 05:06:52 +0200 Message-Id: <20201017030701.16134-9-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201017030701.16134-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCIsWRmVeSWpSXmKPExsWy7djP87pP47viDWY0cVncWGVv0TfpI5PF u0/bmSye9axjtPjX8YfdgdXj14KlrB6L97xk8jj4bg9TAHMUl01Kak5mWWqRvl0CV8bc63uZ C2ZoVHQdT2lgfK7QxcjJISFgInHk6TS2LkYuDiGBFYwSXy6uYIJwvjBKTH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L7F6wwGwak4BN4nG464QixoZJc7OWscygZFvASPDKkaR1NLi3PTcYiO94sTc4tK8dL3k/NxN jMAQ3Hbs55YdjF3vgg8xCnAwKvHwbljUGS/EmlhWXJl7iFGCg1lJhNfp7Ok4Id6UxMqq1KL8 +KLSnNTiQ4ymQDdNZJYSTc4HxkdeSbyhqaG5haWhubG5sZmFkjhvh8DBGCGB9MSS1OzU1ILU Ipg+Jg5OqQbGLNfs9fOfrj3qWGlY9/+uVWHpPiEJ/iXv+kQ836wrKNpwxOeByqtnGT2MMsXz lvf7fopN3vj2d47Y29ZHUZdFnA9tnRmnsjvhoMaGqRuXp7ituuP9mr1QhPX5M6NHJV8uOrYt XMBx4761FNvaDwHPVbQfl75NrRH+eKmLMe7firTSjPOPnm9JUWIpzkg01GIuKk4EAPdETI5X AgAA X-CMS-MailID: 20201017030716eucas1p2911112ee3c9e0a3f3dd9a811cbafe77b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20201017030716eucas1p2911112ee3c9e0a3f3dd9a811cbafe77b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201017030716eucas1p2911112ee3c9e0a3f3dd9a811cbafe77b References: <20201010160508.19709-1-l.wojciechow@partner.samsung.com> <20201017030701.16134-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-stable] [PATCH v8 08/17] test/distributor: synchronize lcores statistics X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Statistics of handled packets are cleared and read on main lcore, while they are increased in workers handlers on different lcores. Without synchronization occasionally showed invalid values. This patch uses atomic mechanisms to synchronize. Relaxed memory model is used. Fixes: c3eabff124e6 ("distributor: add unit tests") Cc: bruce.richardson@intel.com Cc: stable@dpdk.org Signed-off-by: Lukasz Wojciechowski Acked-by: David Hunt --- app/test/test_distributor.c | 39 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c index ec1fe348b..4343efed1 100644 --- a/app/test/test_distributor.c +++ b/app/test/test_distributor.c @@ -43,7 +43,8 @@ total_packet_count(void) { unsigned i, count = 0; for (i = 0; i < worker_idx; i++) - count += worker_stats[i].handled_packets; + count += __atomic_load_n(&worker_stats[i].handled_packets, + __ATOMIC_RELAXED); return count; } @@ -51,7 +52,10 @@ total_packet_count(void) static inline void clear_packet_count(void) { - memset(&worker_stats, 0, sizeof(worker_stats)); + unsigned int i; + for (i = 0; i < RTE_MAX_LCORE; i++) + __atomic_store_n(&worker_stats[i].handled_packets, 0, + __ATOMIC_RELAXED); } /* this is the basic worker function for sanity test @@ -129,7 +133,8 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p) for (i = 0; i < rte_lcore_count() - 1; i++) printf("Worker %u handled %u packets\n", i, - worker_stats[i].handled_packets); + __atomic_load_n(&worker_stats[i].handled_packets, + __ATOMIC_RELAXED)); printf("Sanity test with all zero hashes done.\n"); /* pick two flows and check they go correctly */ @@ -154,7 +159,9 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p) for (i = 0; i < rte_lcore_count() - 1; i++) printf("Worker %u handled %u packets\n", i, - worker_stats[i].handled_packets); + __atomic_load_n( + &worker_stats[i].handled_packets, + __ATOMIC_RELAXED)); printf("Sanity test with two hash values done\n"); } @@ -180,7 +187,8 @@ sanity_test(struct worker_params *wp, struct rte_mempool *p) for (i = 0; i < rte_lcore_count() - 1; i++) printf("Worker %u handled %u packets\n", i, - worker_stats[i].handled_packets); + __atomic_load_n(&worker_stats[i].handled_packets, + __ATOMIC_RELAXED)); printf("Sanity test with non-zero hashes done\n"); rte_mempool_put_bulk(p, (void *)bufs, BURST); @@ -272,12 +280,14 @@ handle_work_with_free_mbufs(void *arg) num = rte_distributor_get_pkt(d, id, buf, NULL, 0); while (!quit) { - worker_stats[id].handled_packets += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_RELAXED); for (i = 0; i < num; i++) rte_pktmbuf_free(buf[i]); num = rte_distributor_get_pkt(d, id, buf, NULL, 0); } - worker_stats[id].handled_packets += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_RELAXED); rte_distributor_return_pkt(d, id, buf, num); return 0; } @@ -347,7 +357,8 @@ handle_work_for_shutdown_test(void *arg) /* wait for quit single globally, or for worker zero, wait * for zero_quit */ while (!quit && !(id == zero_id && zero_quit)) { - worker_stats[id].handled_packets += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_RELAXED); num = rte_distributor_get_pkt(d, id, buf, NULL, 0); if (num > 0) { @@ -357,8 +368,9 @@ handle_work_for_shutdown_test(void *arg) } zero_id = __atomic_load_n(&zero_idx, __ATOMIC_ACQUIRE); } - worker_stats[id].handled_packets += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_RELAXED); if (id == zero_id) { rte_distributor_return_pkt(d, id, NULL, 0); @@ -371,7 +383,8 @@ handle_work_for_shutdown_test(void *arg) num = rte_distributor_get_pkt(d, id, buf, NULL, 0); while (!quit) { - worker_stats[id].handled_packets += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, + num, __ATOMIC_RELAXED); num = rte_distributor_get_pkt(d, id, buf, NULL, 0); } } @@ -437,7 +450,8 @@ sanity_test_with_worker_shutdown(struct worker_params *wp, for (i = 0; i < rte_lcore_count() - 1; i++) printf("Worker %u handled %u packets\n", i, - worker_stats[i].handled_packets); + __atomic_load_n(&worker_stats[i].handled_packets, + __ATOMIC_RELAXED)); if (total_packet_count() != BURST * 2) { printf("Line %d: Error, not all packets flushed. " @@ -497,7 +511,8 @@ test_flush_with_worker_shutdown(struct worker_params *wp, zero_quit = 0; for (i = 0; i < rte_lcore_count() - 1; i++) printf("Worker %u handled %u packets\n", i, - worker_stats[i].handled_packets); + __atomic_load_n(&worker_stats[i].handled_packets, + __ATOMIC_RELAXED)); if (total_packet_count() != BURST) { printf("Line %d: Error, not all packets flushed. " -- 2.17.1