Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/ff_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ void ff_run(loop_func_t loop, void *arg);

void ff_stop_run(void);

/*
* Control whether ff_run() automatically tears down config, DPDK EAL, and log
* before returning (default: 1). Set to 0 when the application needs to close
* BSD sockets or epoll fds after ff_run() returns, then call ff_cleanup().
*/
void ff_set_auto_cleanup(int enable);

/* Idempotent teardown of config, DPDK EAL, and F-Stack log. */
int ff_cleanup(void);

/*
* Resident slim primary helpers (graceful_reload=1).
* ff_primary_conf_digest: digest of the config items the primary applies
Expand Down
26 changes: 25 additions & 1 deletion lib/ff_dpdk_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -4153,6 +4153,8 @@ ff_dpdk_if_up(void) {
return 0;
}

static int ff_auto_cleanup = 1;

void
ff_dpdk_run(loop_func_t loop, void *arg) {
struct loop_routine *lr = rte_malloc(NULL,
Expand All @@ -4165,16 +4167,38 @@ ff_dpdk_run(loop_func_t loop, void *arg) {
stop_clock();
rte_free(lr);

if (ff_auto_cleanup) {
ff_dpdk_cleanup();
}
}

void
ff_dpdk_set_auto_cleanup(int enable)
{
ff_auto_cleanup = enable ? 1 : 0;
}

int
ff_dpdk_cleanup(void)
{
static int cleaned = 0;
if (cleaned) {
return 0;
}
cleaned = 1;

int ret = 0;
/* FU-S2-2-CFG-UNLOAD: free ff_global_cfg before EAL cleanup so any
* cfg.* allocations made via DPDK helpers (none today, but defensive)
* are released while the EAL is still up. Mirrors the comment block
* that previously read "FIXME: Cleanup ff_config, freebsd etc." */
if (!(ff_global_cfg.dpdk.primary_slim &&
rte_eal_process_type() == RTE_PROC_PRIMARY)) {
ff_unload_config();
rte_eal_cleanup();
ret = rte_eal_cleanup();
}
ff_log_close();
return ret;
}

void
Expand Down
2 changes: 2 additions & 0 deletions lib/ff_dpdk_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ 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);
void ff_dpdk_set_auto_cleanup(int enable);
int ff_dpdk_cleanup(void);

struct ff_dpdk_if_context;
struct ff_port_cfg;
Expand Down
12 changes: 12 additions & 0 deletions lib/ff_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ ff_stop_run(void)
ff_dpdk_stop();
}

void
ff_set_auto_cleanup(int enable)
{
ff_dpdk_set_auto_cleanup(enable);
}

int
ff_cleanup(void)
{
return ff_dpdk_cleanup();
}

const char *
ff_eal_runtime_dir(void)
{
Expand Down