Skip to content

feat(api): add ff_set_auto_cleanup() and ff_cleanup() for deferred EA… - #1103

Open
code-agree wants to merge 1 commit into
F-Stack:devfrom
code-agree:feat/deferred-cleanup
Open

code-agree wants to merge 1 commit into
F-Stack:devfrom
code-agree:feat/deferred-cleanup

Conversation

@code-agree

@code-agree code-agree commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Add ff_set_auto_cleanup(int enable) and idempotent ff_cleanup(void) so applications can close BSD sockets and epoll fds after ff_run() returns before tearing down config and DPDK EAL, while keeping the default ff_run()
behavior 100% backward-compatible.

Motivation

In F-Stack 2.0, ff_dpdk_run() runs ff_unload_config(), rte_eal_cleanup(), and ff_log_close() before returning. In default mode, DPDK queues and EAL are already released before the caller can invoke ff_close() on its
sockets/epoll fds (for example, in C++ RAII destructors).

Changes

  • lib/ff_api.h / lib/ff_init.c / lib/ff_dpdk_if.h: Expose ff_set_auto_cleanup(int enable) and ff_cleanup(void) following the existing ff_init / ff_run / ff_stop_run layering.
  • lib/ff_dpdk_if.c:
    • Default ff_auto_cleanup = 1 (zero behavioral change for existing callers).
    • Extract teardown into idempotent ff_dpdk_cleanup(), preserving the existing primary_slim && RTE_PROC_PRIMARY guard and returning rte_eal_cleanup()'s status.

Verification

Built libfstack.a cleanly with GCC 15.1.0 (-Wall -Wextra -Werror), verified exported symbols via nm, and ran a live AWS ENA reproducer (ff_init -> ff_epoll_create + ff_socket -> ff_run/ff_stop_run -> ff_close -> ff_cleanup):

  • Default (auto_cleanup=1) — DPDK queues are released before ff_run() returns:
[mode=default] created epfd=0 sock=1, entering ff_run
ENA_DRIVER: ena_rx_queue_release(): Rx queue 0:0 released
ENA_DRIVER: ena_tx_queue_release(): Tx queue 0:0 released
[mode=default] ff_run returned, closing sock=1 and epfd=0

• Deferred (ff_set_auto_cleanup(0)) — sockets/epoll close before DPDK teardown, and ff_cleanup() is idempotent (rc1=0 rc2=0, exit code 0):

[mode=deferred] created epfd=0 sock=1, entering ff_run
[mode=deferred] ff_run returned, closing sock=1 and epfd=0
ENA_DRIVER: ena_rx_queue_release(): Rx queue 0:0 released
ENA_DRIVER: ena_tx_queue_release(): Tx queue 0:0 released
[mode=deferred] ff_close(sock)=0 ff_close(epfd)=0
[mode=deferred] ff_cleanup() rc1=0 rc2=0


---

…L teardown

ff_dpdk_run() currently tears down config and DPDK EAL before returning
to the caller, which can invalidate resources if the application closes
BSD sockets or epoll fds after ff_run() returns (e.g., C++ RAII).

Keep the default behavior unchanged (auto-cleanup enabled), and expose
ff_set_auto_cleanup(int) plus an idempotent ff_cleanup() so applications
can explicitly control teardown ordering while preserving primary_slim
semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant