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 45004A04BC for ; Thu, 8 Oct 2020 07:24:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F14491B952; Thu, 8 Oct 2020 07:23:56 +0200 (CEST) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 2C8B71B6C5 for ; Thu, 8 Oct 2020 07:23:43 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20201008052341euoutp0131f3aa499b9603876b8f53559cb1c1e0~77PNA1Qul2347823478euoutp018 for ; Thu, 8 Oct 2020 05:23:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20201008052341euoutp0131f3aa499b9603876b8f53559cb1c1e0~77PNA1Qul2347823478euoutp018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1602134622; bh=Ac7zUxbaUtkPUHeaPly+rcwUzr6TKwAmXEJAVMzD+lE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HaFxjrHgPkDnlyFc2KGEpZnHv+f5eiMVlEWWAlyjktDdx7XV2/+Si3ixFe+BwpdHD p2RjDUxqVN6tOm4RMKkjAl4gRTGaQomHNHowiZTprh6tIfmMAm0FjpkRzzpnqALf5V btulH4GT1JtWD1eYSQWy9lVzmVnlrAg/8H77AQz4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20201008052341eucas1p17cddb94aabddf6cd16600ae12904bcc4~77PMywzRH1294712947eucas1p1E; Thu, 8 Oct 2020 05:23:41 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 90.93.06456.D52AE7F5; Thu, 8 Oct 2020 06:23:41 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20201008052341eucas1p2379b186206e5bf481e3c680de46e5c16~77PMY5Ghp2348123481eucas1p28; Thu, 8 Oct 2020 05:23:41 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20201008052341eusmtrp189b078d52c662bcd37df7080735bd401~77PMYXd_c2941529415eusmtrp1V; Thu, 8 Oct 2020 05:23:41 +0000 (GMT) X-AuditID: cbfec7f2-7efff70000001938-43-5f7ea25d2008 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 57.89.06314.D52AE7F5; Thu, 8 Oct 2020 06:23:41 +0100 (BST) Received: from Padamandas.fritz.box (unknown [106.210.88.70]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20201008052340eusmtip16daea8d9a3ed5f8c04dfd977ac04d13a~77PLxLsa22784127841eusmtip17; Thu, 8 Oct 2020 05:23:40 +0000 (GMT) From: Lukasz Wojciechowski To: David Hunt , Bruce Richardson Cc: dev@dpdk.org, l.wojciechow@partner.samsung.com, stable@dpdk.org Date: Thu, 8 Oct 2020 07:23:14 +0200 Message-Id: <20201008052323.11547-7-l.wojciechow@partner.samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201008052323.11547-1-l.wojciechow@partner.samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOIsWRmVeSWpSXmKPExsWy7djP87qxi+riDU5/0LK4screom/SRyaL d5+2M1k861nHaPGv4w+7A6vHrwVLWT0W73nJ5HHw3R6mAOYoLpuU1JzMstQifbsErozLnWcZ Cx7qVvTu2snYwDhJtYuRk0NCwETi8MWtrF2MXBxCAisYJV6vWcwE4XxhlNh5op8FwvnMKNH/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CbxNn/d1khrmlklLh5fibbBEa+BYwMqxhFUkuLc9Nziw31ihNzi0vz0vWS 83M3MQLDcNuxn5t3MF7aGHyIUYCDUYmH1+BobbwQa2JZcWXuIUYJDmYlEV6ns6fjhHhTEiur Uovy44tKc1KLDzGaAl01kVlKNDkfGCN5JfGGpobmFpaG5sbmxmYWSuK8HQIHY4QE0hNLUrNT UwtSi2D6mDg4pRoYk/LXFmZo9B/4OvUSl9GZ6donC518ry9+cWiHv87J0tbbaz027J0QN69z y7xTTzJilL8dncDFeIV9Xwqf0p8pJTytLXHhzz556Nbvf7/an81FZQLvnAdKH7s/HL/Af6dp zsPWp0piezdNeTVt/dOl3D16/lu2rLRmdN1R52v561D/wQ2XJi86wqfEUpyRaKjFXFScCACl cyK0WQIAAA== X-CMS-MailID: 20201008052341eucas1p2379b186206e5bf481e3c680de46e5c16 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20201008052341eucas1p2379b186206e5bf481e3c680de46e5c16 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201008052341eucas1p2379b186206e5bf481e3c680de46e5c16 References: <20200925224209.12173-1-l.wojciechow@partner.samsung.com> <20201008052323.11547-1-l.wojciechow@partner.samsung.com> Subject: [dpdk-stable] [PATCH v5 06/15] 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 acquire/release mechanisms to synchronize. 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 | 43 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c index 6cd7a2edd..838459392 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_ACQUIRE); 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_RELEASE); } /* this is the basic worker function for sanity test @@ -69,13 +73,13 @@ handle_work(void *arg) num = rte_distributor_get_pkt(db, id, buf, NULL, 0); while (!quit) { __atomic_fetch_add(&worker_stats[id].handled_packets, num, - __ATOMIC_RELAXED); + __ATOMIC_ACQ_REL); count += num; num = rte_distributor_get_pkt(db, id, buf, buf, num); } __atomic_fetch_add(&worker_stats[id].handled_packets, num, - __ATOMIC_RELAXED); + __ATOMIC_ACQ_REL); count += num; rte_distributor_return_pkt(db, id, buf, num); return 0; @@ -131,7 +135,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_ACQUIRE)); printf("Sanity test with all zero hashes done.\n"); /* pick two flows and check they go correctly */ @@ -156,7 +161,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_ACQUIRE)); printf("Sanity test with two hash values done\n"); } @@ -182,7 +189,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_ACQUIRE)); printf("Sanity test with non-zero hashes done\n"); rte_mempool_put_bulk(p, (void *)bufs, BURST); @@ -275,14 +283,16 @@ 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; count += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_ACQ_REL); 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; count += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_ACQ_REL); rte_distributor_return_pkt(d, id, buf, num); return 0; } @@ -358,8 +368,9 @@ 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; count += num; + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_ACQ_REL); for (i = 0; i < num; i++) rte_pktmbuf_free(buf[i]); num = rte_distributor_get_pkt(d, id, buf, NULL, 0); @@ -373,10 +384,11 @@ handle_work_for_shutdown_test(void *arg) total += num; } - worker_stats[id].handled_packets += num; count += num; returned = rte_distributor_return_pkt(d, id, buf, num); + __atomic_fetch_add(&worker_stats[id].handled_packets, num, + __ATOMIC_ACQ_REL); if (id == zero_id) { /* for worker zero, allow it to restart to pick up last packet * when all workers are shutting down. @@ -387,7 +399,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_ACQ_REL); count += num; rte_pktmbuf_free(pkt); num = rte_distributor_get_pkt(d, id, buf, NULL, 0); @@ -454,7 +467,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_ACQUIRE)); if (total_packet_count() != BURST * 2) { printf("Line %d: Error, not all packets flushed. " @@ -507,7 +521,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_ACQUIRE)); if (total_packet_count() != BURST) { printf("Line %d: Error, not all packets flushed. " -- 2.17.1