DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup
@ 2017-04-27 12:37 Remy Horton
  2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit Remy Horton
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Remy Horton @ 2017-04-27 12:37 UTC (permalink / raw)
  To: dev; +Cc: John McNamara

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, in particular leaving stale shared
host memory handles. This is fixed by adding a signal handler that
causes the processing loops to break, and adding cleanup code to remove
the stale handles.

Remy Horton (2):
  examples/l2fwd-keepalive: add graceful exit
  examples/l2fwd-keepalive: add SHM cleanup on exit

 doc/guides/rel_notes/release_17_05.rst |  4 ++++
 examples/l2fwd-keepalive/main.c        | 31 +++++++++++++++++++++++++++----
 examples/l2fwd-keepalive/shm.c         | 10 ++++++++++
 examples/l2fwd-keepalive/shm.h         |  9 +++++++++
 4 files changed, 50 insertions(+), 4 deletions(-)

-- 
2.5.5

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit
  2017-04-27 12:37 [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Remy Horton
@ 2017-04-27 12:37 ` Remy Horton
  2017-04-28  8:37   ` Mcnamara, John
  2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit Remy Horton
  2017-05-01 14:42 ` [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Thomas Monjalon
  2 siblings, 1 reply; 6+ messages in thread
From: Remy Horton @ 2017-04-27 12:37 UTC (permalink / raw)
  To: dev; +Cc: John McNamara

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 <remy.horton@intel.com>
---
 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 <ctype.h>
 #include <errno.h>
 #include <getopt.h>
+#include <signal.h>
 
 #include <rte_common.h>
 #include <rte_log.h>
@@ -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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit
  2017-04-27 12:37 [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Remy Horton
  2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit Remy Horton
@ 2017-04-27 12:37 ` Remy Horton
  2017-04-28  8:37   ` Mcnamara, John
  2017-05-01 14:42 ` [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Thomas Monjalon
  2 siblings, 1 reply; 6+ messages in thread
From: Remy Horton @ 2017-04-27 12:37 UTC (permalink / raw)
  To: dev; +Cc: John McNamara

This patch adds the unlinking/unmapping of shared host memory
on termination of l2fwd-keepalive. Previously it was only
cleaned on re-running of the example application.

Fixes: e64833f2273a ("examples/l2fwd-keepalive: add sample application")

Signed-off-by: Remy Horton <remy.horton@intel.com>
---
 examples/l2fwd-keepalive/main.c |  6 ++++--
 examples/l2fwd-keepalive/shm.c  | 10 ++++++++++
 examples/l2fwd-keepalive/shm.h  |  9 +++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c
index 5fdbdef..3745348 100644
--- a/examples/l2fwd-keepalive/main.c
+++ b/examples/l2fwd-keepalive/main.c
@@ -567,6 +567,7 @@ main(int argc, char **argv)
 	unsigned lcore_id, rx_lcore_id;
 	unsigned nb_ports_in_mask = 0;
 	struct sigaction signal_handler;
+	struct rte_keepalive_shm *ka_shm;
 
 	memset(&signal_handler, 0, sizeof(signal_handler));
 	terminate_signal_received = 0;
@@ -751,9 +752,8 @@ main(int argc, char **argv)
 	rte_timer_subsystem_init();
 	rte_timer_init(&stats_timer);
 
+	ka_shm = NULL;
 	if (check_period > 0) {
-		struct rte_keepalive_shm *ka_shm;
-
 		ka_shm = rte_keepalive_shm_create();
 		if (ka_shm == NULL)
 			rte_exit(EXIT_FAILURE,
@@ -813,5 +813,7 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+	if (ka_shm != NULL)
+		rte_keepalive_shm_cleanup(ka_shm);
 	return 0;
 }
diff --git a/examples/l2fwd-keepalive/shm.c b/examples/l2fwd-keepalive/shm.c
index 177aa5b..fbf5bd7 100644
--- a/examples/l2fwd-keepalive/shm.c
+++ b/examples/l2fwd-keepalive/shm.c
@@ -129,3 +129,13 @@ void rte_keepalive_relayed_state(struct rte_keepalive_shm *shm,
 				strerror(errno));
 	}
 }
+
+void rte_keepalive_shm_cleanup(struct rte_keepalive_shm *ka_shm)
+{
+	if (shm_unlink(RTE_KEEPALIVE_SHM_NAME) == -1 && errno != ENOENT)
+		printf("Warning: Error unlinking  %s (%s)\n",
+			RTE_KEEPALIVE_SHM_NAME, strerror(errno));
+
+	if (ka_shm && munmap(ka_shm, sizeof(struct rte_keepalive_shm)) != 0)
+		printf("Warning: munmap() failed\n");
+}
diff --git a/examples/l2fwd-keepalive/shm.h b/examples/l2fwd-keepalive/shm.h
index 25e1b61..66a6060 100644
--- a/examples/l2fwd-keepalive/shm.h
+++ b/examples/l2fwd-keepalive/shm.h
@@ -87,3 +87,12 @@ struct rte_keepalive_shm *rte_keepalive_shm_create(void);
 void rte_keepalive_relayed_state(struct rte_keepalive_shm *shm,
 	const int id_core, const enum rte_keepalive_state core_state,
 	uint64_t last_alive);
+
+/** Shutdown cleanup of shared host memory keepalive object.
+ * @param *shm
+ *  Pointer to SHM keepalive structure. May be NULL.
+ *
+ *  If *shm is NULL, this function will only attempt to remove the
+ *  shared host memory handle and not unmap the underlying memory.
+ */
+void rte_keepalive_shm_cleanup(struct rte_keepalive_shm *ka_shm);
-- 
2.5.5

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit
  2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit Remy Horton
@ 2017-04-28  8:37   ` Mcnamara, John
  0 siblings, 0 replies; 6+ messages in thread
From: Mcnamara, John @ 2017-04-28  8:37 UTC (permalink / raw)
  To: Horton, Remy, dev



> -----Original Message-----
> From: Horton, Remy
> Sent: Thursday, April 27, 2017 1:37 PM
> To: dev@dpdk.org
> Cc: Mcnamara, John <john.mcnamara@intel.com>
> Subject: [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit
> 
> 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 <remy.horton@intel.com>

Tested-by Roman Korynkevych <romanx.korynkevych@intel.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit
  2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit Remy Horton
@ 2017-04-28  8:37   ` Mcnamara, John
  0 siblings, 0 replies; 6+ messages in thread
From: Mcnamara, John @ 2017-04-28  8:37 UTC (permalink / raw)
  To: Horton, Remy, dev



> -----Original Message-----
> From: Horton, Remy
> Sent: Thursday, April 27, 2017 1:37 PM
> To: dev@dpdk.org
> Cc: Mcnamara, John <john.mcnamara@intel.com>
> Subject: [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit
> 
> This patch adds the unlinking/unmapping of shared host memory on
> termination of l2fwd-keepalive. Previously it was only cleaned on re-
> running of the example application.
> 
> Fixes: e64833f2273a ("examples/l2fwd-keepalive: add sample application")
> 
> Signed-off-by: Remy Horton <remy.horton@intel.com>

Tested-by Roman Korynkevych <romanx.korynkevych@intel.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup
  2017-04-27 12:37 [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Remy Horton
  2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit Remy Horton
  2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit Remy Horton
@ 2017-05-01 14:42 ` Thomas Monjalon
  2 siblings, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2017-05-01 14:42 UTC (permalink / raw)
  To: Remy Horton; +Cc: dev, John McNamara

27/04/2017 14:37, Remy Horton:
> 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, in particular leaving stale shared
> host memory handles. This is fixed by adding a signal handler that
> causes the processing loops to break, and adding cleanup code to remove
> the stale handles.
> 
> Remy Horton (2):
>   examples/l2fwd-keepalive: add graceful exit
>   examples/l2fwd-keepalive: add SHM cleanup on exit

Applied, thanks

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-05-01 14:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-27 12:37 [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Remy Horton
2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit Remy Horton
2017-04-28  8:37   ` Mcnamara, John
2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit Remy Horton
2017-04-28  8:37   ` Mcnamara, John
2017-05-01 14:42 ` [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).