examples/multi_process: fix cleanup on exit
PATCH 1/1 examples/multi_process: fix cleanup on exit
Device was started but not stopped on exit signal. Added port stop and close on exit.
--- examples/multi_process/symmetric_mp/main.c | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-)
examples/multi_process/symmetric_mp/main.c +22 -5
@@ -92,6 +92,25 @@ smp_usage(const char *prgname, const char *errmsg)exit (1 ); } +static void +exit_cleanup (void ) +{ +unsigned int i; + +RTE_LOG (INFO ,APP ,"Close ports.\n" ); +for (i =0 ; i < num_ports; i++) { +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +if (rte_eth_dev_stop (ports[i])) +rte_exit (EXIT_FAILURE ,"Error stopping ports\n" ); +if (rte_eth_dev_close (ports[i])) +rte_exit (EXIT_FAILURE ,"Error closing ports\n" ); + } + } + +/* clean up the EAL */ +rte_eal_cleanup (); +exit (0 ); +}/* signal handler configured for SIGTERM and SIGINT to print stats on exit */ static void
@@ -104,9 +123,10 @@ print_stats(int signum)printf ("Port %u: RX - %u, TX - %u, Drop - %u\n" , (unsigned )p_num, pstats[p_num].rx, pstats[p_num].tx, pstats[p_num].drop); } -exit (0 ); +exit_cleanup (); } +/* Parse the argument given in the command line of the application */ static int smp_parse_args (int argc,char **argv)
@@ -486,8 +506,5 @@ main(int argc, char **argv)rte_eal_mp_remote_launch (lcore_main,NULL ,CALL_MAIN ); -/* clean up the EAL */ -rte_eal_cleanup (); - -return 0 ; +exit_cleanup (); }
Signature · 1 line
2.21.0
Quoted 8 lines · Maayan Kashani
Device was started but not stopped on exit signal. Added port stop and close on exit.
Fixes af75078fece3 ("first public release")Signed-off-by Maayan Kashani <[email protected]>---
Signature · 2 lines
Thanks, Anatoly
Thomas Monjalon
Applied09/07/2025 15:30, Burakov, Anatoly:
Quoted 11 lines · Maayan Kashani
Quoted 8 lines
Device was started but not stopped on exit signal. Added port stop and close on exit.
Fixes af75078fece3 ("first public release")Signed-off-by Maayan Kashani <[email protected]>---
Acked-by Anatoly Burakov <[email protected]>
There's always more cleanup and error handling we can do in examples. As they are just code examples, I assume it does not have to be production-ready.
Applied, thanks.
Quoted 4 lines · On Tue, 8 Jul 2025 10:09:54 +0300 Maayan Kashani <[email protected]> wrote:
examples/multi_process/symmetric_mp/main.c +4
-0+static void +exit_cleanup (void ) +{ +unsigned int i;
examples/multi_process/symmetric_mp/main.c smp_usage(const char *prgname, const char *errmsg) · line 108
Quoted 10 lines
examples/multi_process/symmetric_mp/main.c +10
-0+ +RTE_LOG (INFO ,APP ,"Close ports.\n" ); +for (i =0 ; i < num_ports; i++) { +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +if (rte_eth_dev_stop (ports[i])) +rte_exit (EXIT_FAILURE ,"Error stopping ports\n" ); +if (rte_eth_dev_close (ports[i])) +rte_exit (EXIT_FAILURE ,"Error closing ports\n" ); + } + }
Could the ethdev cleanup be integrated into eal_cleanup() so applications don't have to care?
09/07/2025 17:01, Stephen Hemminger:
Quoted 12 lines
Quoted 9 lines · On Tue, 8 Jul 2025 10:09:54 +0300 Maayan Kashani <[email protected]> wrote:
examples/multi_process/symmetric_mp/main.c +9
-0+static void +exit_cleanup (void ) +{ +unsigned int i; + +RTE_LOG (INFO ,APP ,"Close ports.\n" ); +for (i =0 ; i < num_ports; i++) { +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +if (rte_eth_dev_stop (ports[i]))
Quoted 8 lines
examples/multi_process/symmetric_mp/main.c smp_usage(const char *prgname, const char *errmsg) · line 108
Quoted 5 lines
examples/multi_process/symmetric_mp/main.c +5
-0+rte_exit (EXIT_FAILURE ,"Error stopping ports\n" ); +if (rte_eth_dev_close (ports[i])) +rte_exit (EXIT_FAILURE ,"Error closing ports\n" ); + } + }Could the ethdev cleanup be integrated into
eal_cleanup()so applications don't have to care?
It would be a layer violation.
We could have a list of callbacks maybe.