|
1 | | -# 00 Overview: F-Stack User-Space Stack + Local Kernel Stack COEXISTENCE (per-fd marker selection + unified events) |
| 1 | +# 00 Overview: F-Stack User-Space Stack + Local Kernel Stack COEXISTENCE (compile-macro gated + per-fd marker selection + unified events) |
2 | 2 |
|
3 | 3 | > **Document ID**: SPEC-KE-00 |
4 | | -> **Version**: v4 (coexistence-paradigm rework) |
5 | | -> **Date**: 2026-06-16 |
| 4 | +> **Version**: v5 (compile-macro gating: `FF_KERNEL_COEXIST` off by default + runtime `kernel_coexist` dual-layer switch) |
| 5 | +> **Date**: 2026-06-17 |
6 | 6 | > **Status**: Drafting |
7 | 7 | > **Scope**: Navigation, terminology, and scope statement for the spec in this directory |
8 | 8 |
|
9 | 9 | --- |
10 | 10 |
|
11 | | -## 0. v4 Rework Background (must read) |
| 11 | +## 0. v5 Compile-Macro Gating Background (must read) |
12 | 12 |
|
13 | | -The v3 implementation routed `ff_socket(SOCK_KERNEL)` to `ff_host_socket()` → a raw host `socket()`, **completely bypassing the F-Stack user-space FreeBSD stack**, and the example was purely kernel-based — effectively running a kernel stack alone inside an F-Stack process and abandoning F-Stack. **This was a fundamental mistake.** |
| 13 | +v4 already landed coexistence (app ON F-Stack + per-fd `SOCK_KERNEL` to the kernel stack + unified events). But all v4 coexistence code in `lib/` is **compiled unconditionally**, so even deployments not using coexistence link it in and cannot guarantee byte-for-byte zero regression vs. upstream F-Stack. |
14 | 14 |
|
15 | | -**The correct v4 paradigm**: within **one F-Stack application process**, business connections use the **F-Stack user-space stack (DPDK + FreeBSD)**, while fds carrying the `SOCK_KERNEL` marker use the **host Linux kernel stack**, and the two **coexist in a single event loop**. This is exactly what F-Stack's two existing implementations do: |
| 15 | +**v5 new requirement**: gate ALL `lib/` coexistence code under a single compile macro `FF_KERNEL_COEXIST`, **commented off by default in `lib/Makefile`**, forming a **compile-time + runtime dual-layer switch**: |
| 16 | + |
| 17 | +- **Compile-time (`FF_KERNEL_COEXIST`)**: undefined → all coexistence code (managed kernel-fd bridge, fd discrimination, `ff_epoll` merge, `ff_socket` kernel branch, per-`ff_*` routing, config `kernel_coexist`, `SOCK_FSTACK/SOCK_KERNEL` macros) is **not compiled**; `libfstack.a` is **byte-for-byte zero regression** vs. upstream. Defined (`make FF_KERNEL_COEXIST=1` or uncomment) → compiled in. |
| 18 | +- **Runtime (config `kernel_coexist`)**: **only when the macro is enabled**, `config.ini [stack] kernel_coexist=1` actually enables per-fd `SOCK_KERNEL` to use the kernel stack; default `=0` stays per-fd F-Stack. |
| 19 | +- **Opt-in impact**: `ff_api.h` `SOCK_FSTACK`/`SOCK_KERNEL` macros are also wrapped by `FF_KERNEL_COEXIST`, so a consumer (APP) must likewise define the macro to see these markers — the reasonable semantics of "off by default, explicitly enabled". |
| 20 | + |
| 21 | +**The correct paradigm**: within **one F-Stack application process**, business connections use the **F-Stack user-space stack (DPDK + FreeBSD)**, while fds carrying the `SOCK_KERNEL` marker use the **host Linux kernel stack**, and the two **coexist in a single event loop**, gated by the compile macro `FF_KERNEL_COEXIST` (off by default). This is exactly what F-Stack's two existing implementations do: |
16 | 22 | - the `FF_KERNEL_EVENT` compile mode of `adapter/syscall` (hook/LD_PRELOAD); |
17 | 23 | - nginx's `kernel_network_stack` config switch. |
18 | 24 |
|
19 | | -This feature = **solidify that coexistence capability as the primary baseline (hook mode)** + **add unified-event coexistence to the native `ff_api` mode**, rather than building a side path that bypasses F-Stack. |
| 25 | +This feature = **solidify that coexistence capability as the primary baseline (hook mode)** + **add unified-event coexistence to the native `ff_api` mode**, gated by the `FF_KERNEL_COEXIST` compile macro, rather than building a side path that bypasses F-Stack. |
| 26 | + |
| 27 | +> **v3 history**: v3 routed `ff_socket(SOCK_KERNEL)` to `ff_host_socket()` → a raw host `socket()`, completely bypassing the F-Stack user-space stack (a fundamental mistake), reverted in v4 and rewritten to the paradigm above. |
20 | 28 |
|
21 | 29 | ## 1. One-Sentence Goal |
22 | 30 |
|
|
0 commit comments