From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 38DD2A04B1;
	Sat, 10 Oct 2020 18:07:43 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id AA4D21D927;
	Sat, 10 Oct 2020 18:05:46 +0200 (CEST)
Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com
 [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id D33601D921
 for <dev@dpdk.org>; Sat, 10 Oct 2020 18:05:42 +0200 (CEST)
Received: from eucas1p1.samsung.com (unknown [182.198.249.206])
 by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id
 20201010160532euoutp02515c29b9ed173ef60d88a2c9588e38d1~8rSLdotYh2850728507euoutp02a
 for <dev@dpdk.org>; Sat, 10 Oct 2020 16:05:32 +0000 (GMT)
DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com
 20201010160532euoutp02515c29b9ed173ef60d88a2c9588e38d1~8rSLdotYh2850728507euoutp02a
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com;
 s=mail20170921; t=1602345932;
 bh=LemR1YjnE+c23RXwEQzxMBn4x6DVQHDmQWboTCBU/MI=;
 h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
 b=tO/HaCrMQIuMloPaWnpJgqDngHnbt3Pp0ZH8l6nhmwfBcrrnRmcDkrGJpGAe9r21C
 4TG+1e5wM55IDlHM/7U4l2vhiavtb4IQ7DvVxoz91O7Uwd8oyA62j3gLe7wmuREUFU
 uZYnEVqs3lsafyayxE42N+OJumC5mSqu5GyzNbkE=
Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by
 eucas1p2.samsung.com (KnoxPortal) with ESMTP id
 20201010160527eucas1p2f9e48b635abf1537e9ed0ca181f23bc6~8rSGdTjFp1925919259eucas1p2k;
 Sat, 10 Oct 2020 16:05:27 +0000 (GMT)
Received: from eucas1p2.samsung.com ( [182.198.249.207]) by
 eusmges2new.samsung.com (EUCPMTA) with SMTP id D6.58.05997.7CBD18F5; Sat, 10
 Oct 2020 17:05:27 +0100 (BST)
Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by
 eucas1p2.samsung.com (KnoxPortal) with ESMTPA id
 20201010160527eucas1p2f55cb0fc45bf3647234cdfa251e542fc~8rSGMsFuj0179501795eucas1p2s;
 Sat, 10 Oct 2020 16:05:27 +0000 (GMT)
Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by
 eusmtrp1.samsung.com (KnoxPortal) with ESMTP id
 20201010160527eusmtrp1832ee305a2cd8ca583181821339d4de0~8rSGMFNMA2920229202eusmtrp1v;
 Sat, 10 Oct 2020 16:05:27 +0000 (GMT)
X-AuditID: cbfec7f4-677ff7000000176d-69-5f81dbc7372e
Received: from eusmtip1.samsung.com ( [203.254.199.221]) by
 eusmgms1.samsung.com (EUCPMTA) with SMTP id 94.5A.06314.6CBD18F5; Sat, 10
 Oct 2020 17:05:27 +0100 (BST)
Received: from Padamandas.fritz.box (unknown [106.210.88.70]) by
 eusmtip1.samsung.com (KnoxPortal) with ESMTPA id
 20201010160526eusmtip1f1743b61930a421b73c47ec3a9abbc3f~8rSFiTXqR2442224422eusmtip1z;
 Sat, 10 Oct 2020 16:05:26 +0000 (GMT)
From: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
To: David Hunt <david.hunt@intel.com>, Bruce Richardson
 <bruce.richardson@intel.com>
Cc: dev@dpdk.org, l.wojciechow@partner.samsung.com, stable@dpdk.org
Date: Sat, 10 Oct 2020 18:04:56 +0200
Message-Id: <20201010160508.19709-6-l.wojciechow@partner.samsung.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20201010160508.19709-1-l.wojciechow@partner.samsung.com>
X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCIsWRmVeSWpSXmKPExsWy7djP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UnMyy1CJ9uwS9jKfPjrIUnJWqOLR+E2MD43bRLkZODgkB
 E4kjB38xdjFycQgJLGWU+HFkC1sXIwdQQkbiwyUBiBphiT/Xutggaj4wSkz5c4wRJMEmYCtx
 ZOZXVpB6EYEwiRMr/UHCzALuElsWT2UGsYWB7Jf/ZrCA2CwCqhJNK5rBWnkFXCV+/5rCBDFf
 XmL1hgNg9ZwCbhJnuw5C7WpklDhx+ybbBEa+BYwMqxhFUkuLc9Nziw31ihNzi0vz0vWS83M3
 MQIDcduxn5t3MF7aGHyIUYCDUYmHV+JUY7wQa2JZcWXuIUYJDmYlEV6ns6fjhHhTEiurUovy
 44tKc1KLDzGaAl01kVlKNDkfGCV5JfGGpobmFpaG5sbmxmYWSuK8HQIHY4QE0hNLUrNTUwtS
 i2D6mDg4pRoY21ZvNBU7w5zfqemb6sj2YlJioM9KyfW+p++9151x7nNs/eEJF53mLp/4JZi7
 zNOFrXCrleyH/62GTNpRPRr8F+56Gtd9Osi2uWLTBeme9EfHjPsf7y2KK0mxmsR1w/5f8Ykm
 ht/cJ03uqX46Ucr35/6LyMnJZyep+YvJmDeXshwQiplluVJciaU4I9FQi7moOBEA4MhIU1oC
 AAA=
X-CMS-MailID: 20201010160527eucas1p2f55cb0fc45bf3647234cdfa251e542fc
X-Msg-Generator: CA
Content-Type: text/plain; charset="utf-8"
X-RootMTR: 20201010160527eucas1p2f55cb0fc45bf3647234cdfa251e542fc
X-EPHeader: CA
CMS-TYPE: 201P
X-CMS-RootMailID: 20201010160527eucas1p2f55cb0fc45bf3647234cdfa251e542fc
References: <20201009220202.20834-1-l.wojciechow@partner.samsung.com>
 <20201010160508.19709-1-l.wojciechow@partner.samsung.com>
 <CGME20201010160527eucas1p2f55cb0fc45bf3647234cdfa251e542fc@eucas1p2.samsung.com>
Subject: [dpdk-dev] [PATCH v7 05/16] test/distributor: fix shutdown of busy
	worker
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
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
Sender: "dev" <dev-bounces@dpdk.org>

The sanity test with worker shutdown delegates all bufs
to be processed by a single lcore worker, then it freezes
one of the lcore workers and continues to send more bufs.
The freezed core shuts down first by calling
rte_distributor_return_pkt().

The test intention is to verify if packets assigned to
the shut down lcore will be reassigned to another worker.

However the shutdown core was not always the one, that was
processing packets. The lcore processing mbufs might be different
every time test is launched. This is caused by keeping the value
of wkr static variable in rte_distributor_process() function
between running test cases.

Test freezed always lcore with 0 id. The patch stores the id
of worker that is processing the data in zero_idx global atomic
variable. This way the freezed lcore is always the proper one.

Fixes: c3eabff124e6 ("distributor: add unit tests")
Cc: bruce.richardson@intel.com
Cc: stable@dpdk.org

Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Tested-by: David Hunt <david.hunt@intel.com>
---
 app/test/test_distributor.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/app/test/test_distributor.c b/app/test/test_distributor.c
index 52230d250..6cd7a2edd 100644
--- a/app/test/test_distributor.c
+++ b/app/test/test_distributor.c
@@ -28,6 +28,7 @@ struct worker_params worker_params;
 static volatile int quit;      /**< general quit variable for all threads */
 static volatile int zero_quit; /**< var for when we just want thr0 to quit*/
 static volatile unsigned worker_idx;
+static volatile unsigned zero_idx;
 
 struct worker_stats {
 	volatile unsigned handled_packets;
@@ -340,26 +341,43 @@ handle_work_for_shutdown_test(void *arg)
 	unsigned int total = 0;
 	unsigned int i;
 	unsigned int returned = 0;
+	unsigned int zero_id = 0;
+	unsigned int zero_unset;
 	const unsigned int id = __atomic_fetch_add(&worker_idx, 1,
 			__ATOMIC_RELAXED);
 
 	num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
 
+	if (num > 0) {
+		zero_unset = RTE_MAX_LCORE;
+		__atomic_compare_exchange_n(&zero_idx, &zero_unset, id,
+			false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
+	}
+	zero_id = __atomic_load_n(&zero_idx, __ATOMIC_ACQUIRE);
+
 	/* wait for quit single globally, or for worker zero, wait
 	 * for zero_quit */
-	while (!quit && !(id == 0 && zero_quit)) {
+	while (!quit && !(id == zero_id && zero_quit)) {
 		worker_stats[id].handled_packets += num;
 		count += num;
 		for (i = 0; i < num; i++)
 			rte_pktmbuf_free(buf[i]);
 		num = rte_distributor_get_pkt(d, id, buf, NULL, 0);
+
+		if (num > 0) {
+			zero_unset = RTE_MAX_LCORE;
+			__atomic_compare_exchange_n(&zero_idx, &zero_unset, id,
+				false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE);
+		}
+		zero_id = __atomic_load_n(&zero_idx, __ATOMIC_ACQUIRE);
+
 		total += num;
 	}
 	worker_stats[id].handled_packets += num;
 	count += num;
 	returned = rte_distributor_return_pkt(d, id, buf, num);
 
-	if (id == 0) {
+	if (id == zero_id) {
 		/* for worker zero, allow it to restart to pick up last packet
 		 * when all workers are shutting down.
 		 */
@@ -578,6 +596,7 @@ quit_workers(struct worker_params *wp, struct rte_mempool *p)
 	rte_eal_mp_wait_lcore();
 	quit = 0;
 	worker_idx = 0;
+	zero_idx = RTE_MAX_LCORE;
 }
 
 static int
-- 
2.17.1