From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 343ED1077 for ; Thu, 27 Apr 2017 14:37:11 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Apr 2017 05:37:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,383,1488873600"; d="scan'208";a="92839332" Received: from rhorton-mobl1.ger.corp.intel.com (HELO FC23.ir.intel.com) ([163.33.230.216]) by orsmga005.jf.intel.com with ESMTP; 27 Apr 2017 05:37:08 -0700 From: Remy Horton To: dev@dpdk.org Cc: John McNamara Date: Thu, 27 Apr 2017 13:37:05 +0100 Message-Id: <1493296626-28128-2-git-send-email-remy.horton@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1493296626-28128-1-git-send-email-remy.horton@intel.com> References: <1493296626-28128-1-git-send-email-remy.horton@intel.com> Subject: [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Apr 2017 12:37:11 -0000 The l2fwd-keepalive example has infinite processing loops and as a result the only way to exit it is via SIGINT/SIGTERM (e.g. Control-C). The resulting shutdown is unclean, which is fixed by adding a signal handler that causes the processing loops to break. Fixes: e64833f2273a ("examples/l2fwd-keepalive: add sample application") Signed-off-by: Remy Horton --- doc/guides/rel_notes/release_17_05.rst | 4 ++++ examples/l2fwd-keepalive/main.c | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/guides/rel_notes/release_17_05.rst b/doc/guides/rel_notes/release_17_05.rst index ad20e86..aefa406 100644 --- a/doc/guides/rel_notes/release_17_05.rst +++ b/doc/guides/rel_notes/release_17_05.rst @@ -334,6 +334,10 @@ Libraries Examples ~~~~~~~~ +* **l2fwd-keepalive: Fixed unclean shutdowns.** + + Added clean shutdown to l2fwd-keepalive so that it can free up + stale resources used for inter-process communication. Other ~~~~~ diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c index 4623d2a..5fdbdef 100644 --- a/examples/l2fwd-keepalive/main.c +++ b/examples/l2fwd-keepalive/main.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -142,6 +143,15 @@ static int64_t check_period = 5; /* default check cycle is 5ms */ /* Keepalive structure */ struct rte_keepalive *rte_global_keepalive_info; +/* Termination signalling */ +static int terminate_signal_received; + +/* Termination signal handler */ +static void handle_sigterm(__rte_unused int value) +{ + terminate_signal_received = 1; +} + /* Print out statistics on packets dropped */ static void print_stats(__attribute__((unused)) struct rte_timer *ptr_timer, @@ -251,7 +261,7 @@ l2fwd_main_loop(void) uint64_t tsc_initial = rte_rdtsc(); uint64_t tsc_lifetime = (rand()&0x07) * rte_get_tsc_hz(); - while (1) { + while (!terminate_signal_received) { /* Keepalive heartbeat */ rte_keepalive_mark_alive(rte_global_keepalive_info); @@ -526,6 +536,8 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask) static void dead_core(__rte_unused void *ptr_data, const int id_core) { + if (terminate_signal_received) + return; printf("Dead core %i - restarting..\n", id_core); if (rte_eal_get_lcore_state(id_core) == FINISHED) { rte_eal_wait_lcore(id_core); @@ -554,6 +566,15 @@ main(int argc, char **argv) uint8_t portid, last_port; unsigned lcore_id, rx_lcore_id; unsigned nb_ports_in_mask = 0; + struct sigaction signal_handler; + + memset(&signal_handler, 0, sizeof(signal_handler)); + terminate_signal_received = 0; + signal_handler.sa_handler = &handle_sigterm; + if (sigaction(SIGINT, &signal_handler, NULL) == -1 || + sigaction(SIGTERM, &signal_handler, NULL) == -1) + rte_exit(EXIT_FAILURE, "SIGNAL\n"); + /* init EAL */ ret = rte_eal_init(argc, argv); @@ -782,7 +803,7 @@ main(int argc, char **argv) lcore_id); } } - for (;;) { + while (!terminate_signal_received) { rte_timer_manage(); rte_delay_ms(5); } -- 2.5.5