[v7,6/6] app/test-compress-perf: add force process termination

Message ID 1562325340-3891-7-git-send-email-fiona.trahe@intel.com
State Superseded, archived
Delegated to: akhil goyal
Headers show
Series
  • Untitled series #5366
Related show

Checks

Context Check Description
ci/Intel-compilation fail apply issues
ci/checkpatch success coding style OK

Commit Message

Trahe, Fiona July 5, 2019, 11:15 a.m.
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>
Acked-by: Artur Trybula <arturx.trybula@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(-)

Patch

diff --git a/app/test-compress-perf/comp_perf_options.h b/app/test-compress-perf/comp_perf_options.h
index 0aa29a599..532fb964e 100644
--- a/app/test-compress-perf/comp_perf_options.h
+++ b/app/test-compress-perf/comp_perf_options.h
@@ -67,6 +67,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 e0f852bf0..aa1f8eea2 100644
--- a/app/test-compress-perf/comp_perf_test_benchmark.c
+++ b/app/test-compress-perf/comp_perf_test_benchmark.c
@@ -184,6 +184,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);
@@ -242,6 +245,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,
@@ -306,6 +312,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 7be30ee13..37ac38da6 100644
--- a/app/test-compress-perf/comp_perf_test_verify.c
+++ b/app/test-compress-perf/comp_perf_test_verify.c
@@ -188,6 +188,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);
@@ -268,6 +271,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,
@@ -346,6 +352,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 dd6ef9a6d..e746e4708 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>
@@ -36,6 +40,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)
 {
@@ -277,12 +283,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;
@@ -304,6 +322,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);
@@ -424,8 +444,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);