X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fl2fwd-keepalive%2Fmain.c;h=37453483b9d43f163718cfe8585366c018534a0a;hb=dce8a093de6b70219287be3e4ed59628d19770fe;hp=84a59eb683ba7c70535cc6c9b2b1c57362aeee92;hpb=7b2a704c4e84dcc11ffa381293d2c3d686a999b8;p=dpdk.git diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c index 84a59eb683..37453483b9 100644 --- a/examples/l2fwd-keepalive/main.c +++ b/examples/l2fwd-keepalive/main.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -66,7 +67,6 @@ #include #include #include -#include #include #include #include @@ -117,7 +117,7 @@ static const struct rte_eth_conf port_conf = { .hw_ip_checksum = 0, /**< IP checksum offload disabled */ .hw_vlan_filter = 0, /**< VLAN filtering disabled */ .jumbo_frame = 0, /**< Jumbo Frame Support disabled */ - .hw_strip_crc = 0, /**< CRC stripped by hardware */ + .hw_strip_crc = 1, /**< CRC stripped by hardware */ }, .txmode = { .mq_mode = ETH_MQ_TX_NONE, @@ -143,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, @@ -252,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); @@ -465,7 +474,7 @@ l2fwd_parse_args(int argc, char **argv) argv[optind-1] = prgname; ret = optind-1; - optind = 0; /* reset getopt lib */ + optind = 1; /* reset getopt lib */ return ret; } @@ -527,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); @@ -555,6 +566,16 @@ 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; + struct rte_keepalive_shm *ka_shm; + + 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); @@ -731,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, @@ -783,7 +803,7 @@ main(int argc, char **argv) lcore_id); } } - for (;;) { + while (!terminate_signal_received) { rte_timer_manage(); rte_delay_ms(5); } @@ -793,5 +813,7 @@ main(int argc, char **argv) return -1; } + if (ka_shm != NULL) + rte_keepalive_shm_cleanup(ka_shm); return 0; }