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 8FF96A046B
	for <public@inbox.dpdk.org>; Wed, 26 Jun 2019 18:31:51 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 22E802E8F;
	Wed, 26 Jun 2019 18:31:06 +0200 (CEST)
Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com
 [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id A87EB2BB5
 for <dev@dpdk.org>; Wed, 26 Jun 2019 18:30:52 +0200 (CEST)
Received: by mail-wm1-f67.google.com with SMTP id v19so2744640wmj.5
 for <dev@dpdk.org>; Wed, 26 Jun 2019 09:30:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:subject:date:message-id:in-reply-to:references;
 bh=vJmq5DaP1Wt8GCjaDZEZhPlf5UC13Z3m+XChLBtGZXk=;
 b=qNCCq9CuKXMM3VNSmQ06HZRe4RsrAVnFw6SXGGhjm460T5uAgiWu3FtpLPTl8XVoGT
 Yy2wKz1ifyPPYPB5oGTpluVlnnKYbJfOzC5Sg3Y6Z2aXLnAmmcVxsJMRx0DjnqVNTMwV
 QTr3XoNuMvlW3MSOQUuo08EivHV1vUmnHaa0iFkW/IRkG/7XC049Pen59ReIQUBAhooM
 0YmNwlutyEPTw3GSb16B/vV5ObebNcrJAel8ppGJpwMN2g9IXdvXLoRu99B/02qYTSlJ
 oGV7/Brr+8qiIX1fTVwI5zJ1q5+Et0dwUeMbIQn78BXT/054VzU7BT287YyWhi26s0a9
 fCeQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
 :references;
 bh=vJmq5DaP1Wt8GCjaDZEZhPlf5UC13Z3m+XChLBtGZXk=;
 b=N4xabFyC4n6I9BXh5lMmt8IM888xWz1VnCAWakKvMtyQXml/4UFUXXMufe5LzSg2mZ
 3DL8g7mZGKifCVy5ri6/IyGWUTENWkBXfsmjnGOZFnM3Dbto75rrIJVkvvp7hLI7NEx7
 kY9PH0ErBqPK/NznQIgZF6Jq/12xXngRhwKwqEvybWpmzSA694IlWB3wVCBuWLQkUUtx
 1Q0pM4C6zDK79A/LUhPTjIhCOHiASX0tYDmWkP9JuSKQyH4c7Ta2M5b2O5mD9q/PcN9d
 shKk9x7bbz2OA5Yp/KOfl88bx0ZtxisqxJk93OoICdbXFOZ4hStFotDL0DWIZq0BRfdL
 7A9w==
X-Gm-Message-State: APjAAAVQlIMRbTevWbOijKOUp7ONoHH1oiS3y7k0AyZCSeInYmR2cDSn
 defxWMSOlXSOfI573zZEf0PwDOc/SbR9VA==
X-Google-Smtp-Source: APXvYqwWNKhnbmlTenROTBr8OsA2sjVPfLQWb1cj6Cp6K6EdkcMho3IPWvEP4lO0WSrFZs4Om4e5EA==
X-Received: by 2002:a1c:ab06:: with SMTP id u6mr3254104wme.125.1561566652141; 
 Wed, 26 Jun 2019 09:30:52 -0700 (PDT)
Received: from localhost.localdomain (178.43.130.103.ipv4.supernova.orange.pl.
 [178.43.130.103])
 by smtp.gmail.com with ESMTPSA id n10sm16989663wrw.83.2019.06.26.09.30.50
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Wed, 26 Jun 2019 09:30:51 -0700 (PDT)
From: Tomasz Jozwiak <tjozwiakgm@gmail.com>
To: dev@dpdk.org, fiona.trahe@intel.com, tjozwiakgm@gmail.com,
 shallyv@marvell.com, arturx.trybula@intel.com
Date: Wed, 26 Jun 2019 18:30:32 +0200
Message-Id: <1561566633-12329-7-git-send-email-tjozwiakgm@gmail.com>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1561566633-12329-1-git-send-email-tjozwiakgm@gmail.com>
References: <1560032553-15528-1-git-send-email-tjozwiakgm@gmail.com>
 <1561566633-12329-1-git-send-email-tjozwiakgm@gmail.com>
Subject: [dpdk-dev] [PATCH v3 6/7] app/test-compress-perf: add force process
	termination
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>

From: Tomasz Jozwiak <tomaszx.jozwiak@intel.com>

This patch adds a possibility to force controlled process termination
as a result of two signals: SIGTERM and SIGINT

Signed-off-by: Tomasz Jozwiak <tomaszx.jozwiak@intel.com>
---
 app/test-compress-perf/comp_perf_options.h        |  1 +
 app/test-compress-perf/comp_perf_test_benchmark.c | 13 ++++++++++++
 app/test-compress-perf/comp_perf_test_verify.c    | 14 ++++++++++++
 app/test-compress-perf/main.c                     | 26 +++++++++++++++++++++--
 4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h
index 79e63d5..534212d 100644
--- a/app/test-compress-perf/comp_perf_options.h
+++ b/app/test-compress-perf/comp_perf_options.h
@@ -68,6 +68,7 @@ struct comp_test_data {
 
 	double ratio;
 	enum cleanup_st cleanup;
+	int perf_comp_force_stop;
 };
 
 int
diff --git a/app/test-compress-perf/comp_perf_test_benchmark.c b/app/test-compress-perf/comp_perf_test_benchmark.c
index 5f27bae..9effccc 100644
--- a/app/test-compress-perf/comp_perf_test_benchmark.c
+++ b/app/test-compress-perf/comp_perf_test_benchmark.c
@@ -183,6 +183,9 @@ main_loop(struct cperf_benchmark_ctx *ctx, enum rte_comp_xform_type type)
 				ops[op_id]->private_xform = priv_xform;
 			}
 
+			if (unlikely(test_data->perf_comp_force_stop))
+				goto end;
+
 			num_enq = rte_compressdev_enqueue_burst(dev_id,
 								mem->qp_id, ops,
 								num_ops);
@@ -241,6 +244,9 @@ main_loop(struct cperf_benchmark_ctx *ctx, enum rte_comp_xform_type type)
 
 		/* Dequeue the last operations */
 		while (total_deq_ops < total_ops) {
+			if (unlikely(test_data->perf_comp_force_stop))
+				goto end;
+
 			num_deq = rte_compressdev_dequeue_burst(dev_id,
 							   mem->qp_id,
 							   deq_ops,
@@ -305,6 +311,13 @@ main_loop(struct cperf_benchmark_ctx *ctx, enum rte_comp_xform_type type)
 	rte_mempool_put_bulk(mem->op_pool, (void **)ops, allocated);
 	rte_compressdev_private_xform_free(dev_id, priv_xform);
 	rte_free(ops);
+
+	if (test_data->perf_comp_force_stop) {
+		RTE_LOG(ERR, USER1,
+		      "lcore: %d Perf. test has been aborted by user\n",
+			mem->lcore_id);
+		res = -1;
+	}
 	return res;
 }
 
diff --git a/app/test-compress-perf/comp_perf_test_verify.c b/app/test-compress-perf/comp_perf_test_verify.c
index c2aab70..b2cd7a0 100644
--- a/app/test-compress-perf/comp_perf_test_verify.c
+++ b/app/test-compress-perf/comp_perf_test_verify.c
@@ -187,6 +187,9 @@ main_loop(struct cperf_verify_ctx *ctx, enum rte_comp_xform_type type)
 				ops[op_id]->private_xform = priv_xform;
 			}
 
+			if (unlikely(test_data->perf_comp_force_stop))
+				goto end;
+
 			num_enq = rte_compressdev_enqueue_burst(dev_id,
 								mem->qp_id, ops,
 								num_ops);
@@ -267,6 +270,9 @@ main_loop(struct cperf_verify_ctx *ctx, enum rte_comp_xform_type type)
 
 		/* Dequeue the last operations */
 		while (total_deq_ops < total_ops) {
+			if (unlikely(test_data->perf_comp_force_stop))
+				goto end;
+
 			num_deq = rte_compressdev_dequeue_burst(dev_id,
 							mem->qp_id,
 							deq_ops,
@@ -345,6 +351,14 @@ main_loop(struct cperf_verify_ctx *ctx, enum rte_comp_xform_type type)
 	rte_mempool_put_bulk(mem->op_pool, (void **)ops, allocated);
 	rte_compressdev_private_xform_free(dev_id, priv_xform);
 	rte_free(ops);
+
+	if (test_data->perf_comp_force_stop) {
+		RTE_LOG(ERR, USER1,
+		      "lcore: %d Perf. test has been aborted by user\n",
+			mem->lcore_id);
+		res = -1;
+	}
+
 	return res;
 }
 
diff --git a/app/test-compress-perf/main.c b/app/test-compress-perf/main.c
index 1044532..77b279b 100644
--- a/app/test-compress-perf/main.c
+++ b/app/test-compress-perf/main.c
@@ -2,6 +2,10 @@
  * Copyright(c) 2018 Intel Corporation
  */
 
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+
 #include <rte_malloc.h>
 #include <rte_eal.h>
 #include <rte_log.h>
@@ -42,6 +46,8 @@ static const struct cperf_test cperf_testmap[] = {
 	}
 };
 
+static struct comp_test_data *test_data;
+
 static int
 comp_perf_check_capabilities(struct comp_test_data *test_data, uint8_t cdev_id)
 {
@@ -283,12 +289,24 @@ comp_perf_dump_input_data(struct comp_test_data *test_data)
 	return ret;
 }
 
+static void
+comp_perf_cleanup_on_signal(int signalNumber __rte_unused)
+{
+	test_data->perf_comp_force_stop = 1;
+}
+
+static void
+comp_perf_register_cleanup_on_signal(void)
+{
+	signal(SIGTERM, comp_perf_cleanup_on_signal);
+	signal(SIGINT, comp_perf_cleanup_on_signal);
+}
+
 int
 main(int argc, char **argv)
 {
 	uint8_t level_idx = 0;
 	int ret, i;
-	struct comp_test_data *test_data;
 	void *ctx[RTE_MAX_LCORE] = {};
 	uint8_t enabled_cdevs[RTE_COMPRESS_MAX_DEVS];
 	int nb_compressdevs = 0;
@@ -310,6 +328,8 @@ main(int argc, char **argv)
 		rte_exit(EXIT_FAILURE, "Cannot reserve memory in socket %d\n",
 				rte_socket_id());
 
+	comp_perf_register_cleanup_on_signal();
+
 	ret = EXIT_SUCCESS;
 	test_data->cleanup = ST_TEST_DATA;
 	comp_perf_options_default(test_data);
@@ -430,8 +450,10 @@ main(int argc, char **argv)
 		/* fallthrough */
 	case ST_COMPDEV:
 		for (i = 0; i < nb_compressdevs &&
-				i < RTE_COMPRESS_MAX_DEVS; i++)
+		     i < RTE_COMPRESS_MAX_DEVS; i++) {
 			rte_compressdev_stop(enabled_cdevs[i]);
+			rte_compressdev_close(enabled_cdevs[i]);
+		}
 		/* fallthrough */
 	case ST_TEST_DATA:
 		rte_free(test_data);
-- 
2.7.4