From 90b9053c56bced9e1d479ad9047fcb33792d7097 Mon Sep 17 00:00:00 2001 From: renzibei <31380016+renzibei@users.noreply.github.com> Date: Sat, 30 Mar 2024 05:10:03 +0000 Subject: [PATCH] Add ff_stop_run to stop the poll loop --- doc/F-Stack_API_Reference.md | 6 ++++++ lib/ff_api.h | 2 ++ lib/ff_dpdk_if.c | 12 ++++++++++++ lib/ff_dpdk_if.h | 1 + lib/ff_init.c | 6 ++++++ 5 files changed, 27 insertions(+) diff --git a/doc/F-Stack_API_Reference.md b/doc/F-Stack_API_Reference.md index 637b12042..03c3d8a77 100644 --- a/doc/F-Stack_API_Reference.md +++ b/doc/F-Stack_API_Reference.md @@ -49,6 +49,12 @@ However, it is supported only before F-Stack is started. The ioctl() function manipulates the underlying device parameters of special files. more info see man ioctl. +#### ff_stop_run + + void ff_stop_run(); + + Stop the infinite poll loop started by `ff_run`. + ### Network API #### ff_socket diff --git a/lib/ff_api.h b/lib/ff_api.h index ab3cc86d1..c5c4bb293 100644 --- a/lib/ff_api.h +++ b/lib/ff_api.h @@ -55,6 +55,8 @@ int ff_init(int argc, char * const argv[]); void ff_run(loop_func_t loop, void *arg); +void ff_stop_run(void); + /* POSIX-LIKE api begin */ int ff_fcntl(int fd, int cmd, ...); diff --git a/lib/ff_dpdk_if.c b/lib/ff_dpdk_if.c index 808cd0945..702a472f6 100644 --- a/lib/ff_dpdk_if.c +++ b/lib/ff_dpdk_if.c @@ -80,6 +80,7 @@ static int numa_on; static unsigned idle_sleep; static unsigned pkt_tx_delay; static uint64_t usr_cb_tsc; +static int stop_loop; static struct rte_timer freebsd_clock; @@ -2005,6 +2006,11 @@ main_loop(void *arg) qconf = &lcore_conf; while (1) { + + if (unlikely(stop_loop)) { + break; + } + cur_tsc = rte_rdtsc(); if (unlikely(freebsd_clock.expire < cur_tsc)) { rte_timer_manage(); @@ -2136,6 +2142,7 @@ void ff_dpdk_run(loop_func_t loop, void *arg) { struct loop_routine *lr = rte_malloc(NULL, sizeof(struct loop_routine), 0); + stop_loop = 0; lr->loop = loop; lr->arg = arg; rte_eal_mp_remote_launch(main_loop, lr, CALL_MAIN); @@ -2143,6 +2150,11 @@ ff_dpdk_run(loop_func_t loop, void *arg) { rte_free(lr); } +void +ff_dpdk_stop(void) { + stop_loop = 1; +} + void ff_dpdk_pktmbuf_free(void *m) { diff --git a/lib/ff_dpdk_if.h b/lib/ff_dpdk_if.h index d930b8dde..ab332a0ac 100644 --- a/lib/ff_dpdk_if.h +++ b/lib/ff_dpdk_if.h @@ -39,6 +39,7 @@ struct loop_routine { int ff_dpdk_init(int argc, char **argv); int ff_dpdk_if_up(void); void ff_dpdk_run(loop_func_t loop, void *arg); +void ff_dpdk_stop(void); struct ff_dpdk_if_context; struct ff_port_cfg; diff --git a/lib/ff_init.c b/lib/ff_init.c index 5ffbfe37c..74d344341 100644 --- a/lib/ff_init.c +++ b/lib/ff_init.c @@ -61,3 +61,9 @@ ff_run(loop_func_t loop, void *arg) ff_dpdk_run(loop, arg); } +void +ff_stop_run(void) +{ + ff_dpdk_stop(); +} +