From 59d50e1f1c23d7263baf2ce08d139554ffb8f8ef Mon Sep 17 00:00:00 2001 From: Alexey Marchuk Date: Mon, 11 Jan 2021 18:58:49 +0300 Subject: [PATCH] perf: Add signal handlers Perf tool doesn't have handlers for SIGINT and SIGTERM signals, so when the tool is killed with e.g. ctrl-c all SPDK and transport resources are destroyed ungracefully. In the case of RDMA we may have IO requests inflight and if the request is processed by the driver when the corresponding MR is destroyed by the kernel, it may cause an error on the target side. Such errors are not harmful but it is better to have a graceful shutdown procedure. Fixes issue #1549 Signed-off-by: Alexey Marchuk Change-Id: I7818a4705d2b5cf4a5f3ca4745c62392312d22d2 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5869 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Reviewed-by: Michael Haeuptle Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- examples/nvme/perf/perf.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index fb3eed4a4..59c9f62bd 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -4,7 +4,7 @@ * Copyright (c) Intel Corporation. * All rights reserved. * - * Copyright (c) 2019-2020 Mellanox Technologies LTD. All rights reserved. + * Copyright (c) 2019-2021 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -2464,6 +2464,35 @@ nvme_poll_ctrlrs(void *arg) return NULL; } +static void +sig_handler(int signo) +{ + g_exit = true; +} + +static int +setup_sig_handlers(void) +{ + struct sigaction sigact = {}; + int rc; + + sigemptyset(&sigact.sa_mask); + sigact.sa_handler = sig_handler; + rc = sigaction(SIGINT, &sigact, NULL); + if (rc < 0) { + fprintf(stderr, "sigaction(SIGINT) failed, errno %d (%s)\n", errno, strerror(errno)); + return -1; + } + + rc = sigaction(SIGTERM, &sigact, NULL); + if (rc < 0) { + fprintf(stderr, "sigaction(SIGTERM) failed, errno %d (%s)\n", errno, strerror(errno)); + return -1; + } + + return 0; +} + int main(int argc, char **argv) { int rc; @@ -2501,6 +2530,12 @@ int main(int argc, char **argv) goto cleanup; } + rc = setup_sig_handlers(); + if (rc != 0) { + rc = -1; + goto cleanup; + } + g_tsc_rate = spdk_get_ticks_hz(); if (register_workers() != 0) {