[dpdk-dev] [PATCH 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd
> On Wed, 23 Dec 2015 15:03:15 -0500 > Zhihong Wang wrote: > > > +/* When we receive a INT signal, close all ports */ static void > > +sigint_handler(__rte_unused int signum) { > > + unsigned portid, nb_ports; > > + > > + printf("Preparing to exit...\n"); > > + nb_ports = rte_eth_dev_count(); > > + for (portid = 0; portid < nb_ports; portid++) { > > + if ((enabled_port_mask & (1 << portid)) == 0) { > > + continue; > > + } > > + printf("Stopping port %d...", portid); > > + rte_eth_dev_stop(portid); > > + rte_eth_dev_close(portid); > > + printf(" Done\n"); > > + } > > + printf("Bye...\n"); > > + exit(0); > > +} > > Signal handlers should only set a flag, which is then checked by thread loops. > Calling functions in DPDK from signal handlers is not safe. I'll make changes in v2 to address this issue. Thanks for pointing out :) In some cases signal handler have to do the exit though, like when the program is still doing memory initialization and will take some time.
[dpdk-dev] [PATCH 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd
> > +/* When we receive a INT signal, close all ports */ static void > > +sigint_handler(__rte_unused int signum) { > > + unsigned portid, nb_ports; > > + > > + printf("Preparing to exit...\n"); > > + nb_ports = rte_eth_dev_count(); > > + for (portid = 0; portid < nb_ports; portid++) { > > + if ((enabled_port_mask & (1 << portid)) == 0) { > > + continue; > > + } > > + printf("Stopping port %d...", portid); > > + rte_eth_dev_stop(portid); > > + rte_eth_dev_close(portid); > > Hmm, so your interrupt thread invokes dev_stop, while IO lcores keep calling > rx_burst/tx_burst? > For graceful shutdown on SIGINT, I suppose you first have to stop your IO > lcores > first. > Let say have a global var: 'stop' that every lcore has to check from time to > time (or > something similar). Thanks for the advice! This works once the program enters the forwarding phase. Have to go the other way if it's still in initialization phase which can take quite some time. /Zhihong > Konstantin > > > + printf(" Done\n"); > > + } > > + printf("Bye...\n"); > > + exit(0); > > +} > > + > > int > > main(int argc, char **argv) > > { > > @@ -2572,6 +2594,9 @@ main(int argc, char **argv) > > uint32_t n_tx_queue, nb_lcores; > > uint8_t portid, nb_rx_queue, queue, socketid; > > > > + signal(SIGINT, sigint_handler); > > + signal(SIGTERM, sigint_handler); > > + > > /* init EAL */ > > ret = rte_eal_init(argc, argv); > > if (ret < 0) > > -- > > 2.5.0
[dpdk-dev] [PATCH 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd
Hi, > -Original Message- > From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Zhihong Wang > Sent: Wednesday, December 23, 2015 8:03 PM > To: dev at dpdk.org > Subject: [dpdk-dev] [PATCH 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in > l3fwd > > Handle SIGINT and SIGTERM in l3fwd. > > Signed-off-by: Zhihong Wang > --- > examples/l3fwd/main.c | 25 + > 1 file changed, 25 insertions(+) > > diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c > index 5b0c2dd..aae16d2 100644 > --- a/examples/l3fwd/main.c > +++ b/examples/l3fwd/main.c > @@ -41,6 +41,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -2559,6 +2560,27 @@ check_all_ports_link_status(uint8_t port_num, uint32_t > port_mask) > } > } > > +/* When we receive a INT signal, close all ports */ > +static void > +sigint_handler(__rte_unused int signum) > +{ > + unsigned portid, nb_ports; > + > + printf("Preparing to exit...\n"); > + nb_ports = rte_eth_dev_count(); > + for (portid = 0; portid < nb_ports; portid++) { > + if ((enabled_port_mask & (1 << portid)) == 0) { > + continue; > + } > + printf("Stopping port %d...", portid); > + rte_eth_dev_stop(portid); > + rte_eth_dev_close(portid); Hmm, so your interrupt thread invokes dev_stop, while IO lcores keep calling rx_burst/tx_burst? For graceful shutdown on SIGINT, I suppose you first have to stop your IO lcores first. Let say have a global var: 'stop' that every lcore has to check from time to time (or something similar). Konstantin > + printf(" Done\n"); > + } > + printf("Bye...\n"); > + exit(0); > +} > + > int > main(int argc, char **argv) > { > @@ -2572,6 +2594,9 @@ main(int argc, char **argv) > uint32_t n_tx_queue, nb_lcores; > uint8_t portid, nb_rx_queue, queue, socketid; > > + signal(SIGINT, sigint_handler); > + signal(SIGTERM, sigint_handler); > + > /* init EAL */ > ret = rte_eal_init(argc, argv); > if (ret < 0) > -- > 2.5.0
[dpdk-dev] [PATCH 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd
On Wed, 23 Dec 2015 15:03:15 -0500 Zhihong Wang wrote: > +/* When we receive a INT signal, close all ports */ > +static void > +sigint_handler(__rte_unused int signum) > +{ > + unsigned portid, nb_ports; > + > + printf("Preparing to exit...\n"); > + nb_ports = rte_eth_dev_count(); > + for (portid = 0; portid < nb_ports; portid++) { > + if ((enabled_port_mask & (1 << portid)) == 0) { > + continue; > + } > + printf("Stopping port %d...", portid); > + rte_eth_dev_stop(portid); > + rte_eth_dev_close(portid); > + printf(" Done\n"); > + } > + printf("Bye...\n"); > + exit(0); > +} Signal handlers should only set a flag, which is then checked by thread loops. Calling functions in DPDK from signal handlers is not safe.
[dpdk-dev] [PATCH 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd
Handle SIGINT and SIGTERM in l3fwd. Signed-off-by: Zhihong Wang --- examples/l3fwd/main.c | 25 + 1 file changed, 25 insertions(+) diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index 5b0c2dd..aae16d2 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -2559,6 +2560,27 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask) } } +/* When we receive a INT signal, close all ports */ +static void +sigint_handler(__rte_unused int signum) +{ + unsigned portid, nb_ports; + + printf("Preparing to exit...\n"); + nb_ports = rte_eth_dev_count(); + for (portid = 0; portid < nb_ports; portid++) { + if ((enabled_port_mask & (1 << portid)) == 0) { + continue; + } + printf("Stopping port %d...", portid); + rte_eth_dev_stop(portid); + rte_eth_dev_close(portid); + printf(" Done\n"); + } + printf("Bye...\n"); + exit(0); +} + int main(int argc, char **argv) { @@ -2572,6 +2594,9 @@ main(int argc, char **argv) uint32_t n_tx_queue, nb_lcores; uint8_t portid, nb_rx_queue, queue, socketid; + signal(SIGINT, sigint_handler); + signal(SIGTERM, sigint_handler); + /* init EAL */ ret = rte_eal_init(argc, argv); if (ret < 0) -- 2.5.0