diff options
author | Matias Elo <matias.elo@nokia.com> | 2018-11-26 15:57:33 +0200 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2018-11-28 10:31:24 +0300 |
commit | 898d834f8c7164e4ee1a99fbe9115b3c7ca5bd67 (patch) | |
tree | fb37223e0636d453abe54107c7b9d7b70f8e09f4 | |
parent | 42fd89a1ee51a2535192650a8cffc05c32b0da12 (diff) |
example: generator: add signal handler for SIGINT
Free used resources after receiving SIGINT.
Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
-rw-r--r-- | example/generator/odp_generator.c | 13 | ||||
-rwxr-xr-x | test/performance/odp_l2fwd_run.sh | 2 | ||||
-rwxr-xr-x | test/performance/odp_sched_pktio_run.sh | 2 |
3 files changed, 15 insertions, 2 deletions
diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 98a892117..bd6af7955 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -15,6 +15,7 @@ #include <unistd.h> #include <inttypes.h> #include <sys/time.h> +#include <signal.h> #include <example_debug.h> @@ -168,6 +169,14 @@ static void usage(char *progname); static int scan_ip(char *buf, unsigned int *paddr); static void print_global_stats(int num_workers); +static void sig_handler(int signo ODP_UNUSED) +{ + int i; + + for (i = 0; i < args->thread_cnt; i++) + args->thread[i].stop = 1; +} + /** * Scan ip * Parse ip address. @@ -1105,6 +1114,10 @@ int main(int argc, char *argv[]) odp_init_t init_param; odph_odpthread_params_t thr_params; + /* Signal handler has to be registered before global init in case ODP + * implementation creates internal threads/processes. */ + signal(SIGINT, sig_handler); + /* Let helper collect its own arguments (e.g. --odph_proc) */ argc = odph_parse_options(argc, argv); if (odph_options(&helper_options)) { diff --git a/test/performance/odp_l2fwd_run.sh b/test/performance/odp_l2fwd_run.sh index 6166c8b27..5745d3279 100755 --- a/test/performance/odp_l2fwd_run.sh +++ b/test/performance/odp_l2fwd_run.sh @@ -88,7 +88,7 @@ run_l2fwd() $STDBUF odp_l2fwd${EXEEXT} -i $IF1,$IF2 -m 0 -t 30 -c 2 | tee $LOG ret=$? - kill ${GEN_PID} + kill -2 ${GEN_PID} if [ ! -f $LOG ]; then echo "FAIL: $LOG not found" diff --git a/test/performance/odp_sched_pktio_run.sh b/test/performance/odp_sched_pktio_run.sh index db14fb598..1c8d2945b 100755 --- a/test/performance/odp_sched_pktio_run.sh +++ b/test/performance/odp_sched_pktio_run.sh @@ -72,7 +72,7 @@ run_sched_pktio() # Run test for 5 sec sleep 5 - kill ${GEN_PID} + kill -2 ${GEN_PID} wait ${GEN_PID} # Kill with SIGINT to output statistics |