Skip to content

Commit 00ba29b

Browse files
committed
doc(arch): sync L1/L2 architecture docs with adapter/syscall LD_PRELOAD changes
Update the Layer 1 (System Overview) and Layer 2 (Interface Spec) docs, in both English (docs/) and Simplified Chinese (docs/zh_cn/), so they match the current state of adapter/syscall/ described in adapter/syscall/README.md. L1 changes - docs/01-LAYER1-ARCHITECTURE.md, docs/zh_cn/01-LAYER1-ARCHITECTURE.md: expand the source-tree comment for adapter/syscall/ to spell out that it builds libff_syscall.so + a standalone fstack instance and communicates over Hugepage shared memory (sem path or FF_USE_RING_IPC lock-free ring path). - docs/F-Stack_Architecture_Layer1_System_Overview.md and the zh_cn counterpart: rewrite Section 7.1 'Method 2: LD_PRELOAD Interception' to describe the two-process model (the fstack instance must be started before the preloaded application), enumerate the full set of hooked POSIX entries (socket/bind/connect/accept/accept4/listen/ close/read/write/send*/recv*/__read_chk/__recv_chk/__recvfrom_chk/ ioctl/epoll_*/fork) and the FF_KERNEL_EVENT / FF_MULTI_SC / FF_USE_RING_IPC switches. L2 changes - docs/F-Stack_Architecture_Layer2_Interface_Specification.md and the zh_cn counterpart: fix the library-name error in Section 6.2 (was 'LD_PRELOAD=libfstack.so', now 'libff_syscall.so'), describe the two-process model, list the hooked POSIX entries and the three runtime/compile switches in a small table. All cross references point to adapter/syscall/README.md as the single source of truth. Line endings normalized to LF.
1 parent bc7c380 commit 00ba29b

6 files changed

Lines changed: 133 additions & 44 deletions

docs/01-LAYER1-ARCHITECTURE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ NIC Hardware
9292
├── tools/ # Tool scripts
9393
├── adapter/ # Network adapters
9494
│ ├── micro_thread/ # Micro-thread interface for stateful applications using F-Stack
95-
│ └── syscall/ # Intercept Linux syscalls as F-Stack APIs via LD_PRELOAD
95+
│ └── syscall/ # Builds libff_syscall.so + an fstack instance binary; intercepts
96+
│ # Linux syscalls (socket/bind/connect/read/write/send/recv/
97+
│ # epoll/accept4/__recv_chk/fork/ioctl ...) via LD_PRELOAD and
98+
│ # forwards them to the fstack instance through Hugepage-backed
99+
│ # shared memory (sem path or FF_USE_RING_IPC lock-free ring path)
96100
├── doc/ # Original English documentation
97101
├── docs/ # Three-layer architecture knowledge base docs
98102
└── config.ini # Default configuration file

docs/F-Stack_Architecture_Layer1_System_Overview.md

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ Actual data on 10GbE link:
140140
141141
├── adapter/ # Network adapters
142142
│ ├── micro_thread/ # Micro-thread interface for stateful applications using F-Stack
143-
│ └── syscall/ # Intercept Linux syscalls as F-Stack APIs via LD_PRELOAD
143+
│ └── syscall/ # Builds libff_syscall.so + fstack instance binary; intercepts
144+
│ # Linux syscalls via LD_PRELOAD and forwards them to the fstack
145+
│ # instance through Hugepage shared memory (sem path or
146+
│ # FF_USE_RING_IPC lock-free ring path). See adapter/syscall/README.md
144147
├── doc/ # Original English documentation
145148
├── docs/ # Three-layer architecture knowledge base docs
146149
├── config.ini # Default configuration file
@@ -775,25 +778,43 @@ int main() {
775778
```
776779

777780
**Method 2: LD_PRELOAD Interception (e.g., Nginx)**
781+
782+
In LD_PRELOAD mode the application runs in two separate processes: a standalone `fstack`
783+
instance (links libfstack.a, polls DPDK) plus the user application (e.g. nginx) preloaded
784+
with `libff_syscall.so`. The two processes communicate over Hugepage shared memory — the
785+
default is a semaphore-based path; setting `FF_USE_RING_IPC=1` switches the data plane to
786+
a lock-free DPDK SPSC `rte_ring`. The `fstack` instance must be started before the
787+
LD_PRELOAD application.
788+
778789
```bash
779-
# Enable F-Stack support for Nginx
780-
LD_PRELOAD=libff_syscall.so nginx
781-
782-
# LD_PRELOAD hooks intercept:
783-
socket() → ff_socket()
784-
bind() → ff_bind()
785-
connect() → ff_connect()
786-
read() → ff_read()
787-
write() → ff_write()
788-
send() → ff_send()
789-
sendto() → ff_sendto()
790-
sendmsg() → ff_sendmsg()
791-
recv() → ff_recv()
792-
recvfrom() → ff_recvfrom()
793-
recvmsg() → ff_recvmsg()
790+
# 1) Start the fstack instance first (one or more instances)
791+
./fstack --conf config.ini --proc-type=primary --proc-id=0 &
792+
793+
# 2) Then enable F-Stack support for Nginx via LD_PRELOAD
794+
LD_PRELOAD=/path/to/libff_syscall.so nginx
795+
796+
# Hooked POSIX entries forwarded to ff_* / kqueue:
797+
socket() → ff_socket() accept() → ff_accept()
798+
bind() → ff_bind() accept4() → ff_accept() + SOCK_CLOEXEC/NONBLOCK
799+
connect() → ff_connect() listen() → ff_listen()
800+
read() → ff_read() close() → ff_close()
801+
write() → ff_write() ioctl() → ff_ioctl()
802+
send/sendto/sendmsg() → ff_send/sendto/sendmsg()
803+
recv/recvfrom/recvmsg() → ff_recv/recvfrom/recvmsg()
804+
__read_chk / __recv_chk / __recvfrom_chk (glibc _FORTIFY_SOURCE wrappers)
805+
epoll_create/ctl/wait() → kqueue-backed events (optional polling mode)
806+
fork() → per-process FreeBSD struct thread (Linux-kernel-like semantics)
794807
...
808+
809+
# Key environment variables / compile switches:
810+
# FF_KERNEL_EVENT=1 Forward kernel-only fds to host epoll in parallel
811+
# FF_MULTI_SC=1 SO_REUSEPORT-style multi-sc, one sc per worker fd
812+
# FF_USE_RING_IPC=1 Switch IPC to lock-free DPDK SPSC ring (default v3.4 opts)
795813
```
796814

815+
See `adapter/syscall/README.md` for the full feature list, compile flags, known
816+
limitations, and acknowledgements.
817+
797818
### 7.2 Tool Support
798819

799820
Operations tools communicate with F-Stack processes via IPC:

docs/F-Stack_Architecture_Layer2_Interface_Specification.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,21 +1026,43 @@ symmetric_rss = 1 # Bidirectional connections to same queue
10261026

10271027
### 6.2 Application Integration Interfaces
10281028

1029-
**Direct Call Mode**: Application directly links `libfstack.a` and calls `ff_*` APIs
1029+
**Direct Call Mode**: Application directly links `libfstack.a` and calls `ff_*` APIs.
10301030

1031-
**LD_PRELOAD Mode**: Use `LD_PRELOAD=libfstack.so` to intercept system calls
1031+
**LD_PRELOAD Mode**: Application is preloaded with `libff_syscall.so` (built from
1032+
`adapter/syscall/`); it runs as a **separate process** from the `fstack` instance
1033+
binary and the two communicate over Hugepage shared memory. The default IPC path is
1034+
semaphore-based; setting `FF_USE_RING_IPC=1` switches to a lock-free DPDK SPSC ring.
1035+
The `fstack` instance must be started before the LD_PRELOAD application.
10321036

10331037
```bash
1038+
# Start the fstack instance(s) first
1039+
./fstack --conf config.ini --proc-type=primary --proc-id=0 &
1040+
10341041
# Nginx integration
1035-
LD_PRELOAD=/path/to/libfstack.so /usr/sbin/nginx -g "daemon off;"
1042+
LD_PRELOAD=/path/to/libff_syscall.so /usr/sbin/nginx -g "daemon off;"
10361043

10371044
# Redis integration
1038-
LD_PRELOAD=/path/to/libfstack.so /usr/bin/redis-server /etc/redis.conf
1045+
LD_PRELOAD=/path/to/libff_syscall.so /usr/bin/redis-server /etc/redis.conf
10391046

10401047
# Custom application
1041-
LD_PRELOAD=/path/to/libfstack.so ./my_app
1048+
LD_PRELOAD=/path/to/libff_syscall.so ./my_app
10421049
```
10431050

1051+
Hooked POSIX entries include `socket / bind / connect / accept / accept4 / listen /
1052+
close / read / write / send / sendto / sendmsg / recv / recvfrom / recvmsg /
1053+
__read_chk / __recv_chk / __recvfrom_chk / ioctl / epoll_create|ctl|wait / fork`.
1054+
1055+
Common runtime / compile switches:
1056+
1057+
| Switch | Default | Effect |
1058+
|---|---|---|
1059+
| `FF_KERNEL_EVENT` | off | Forward kernel-only fds to host epoll in parallel |
1060+
| `FF_MULTI_SC` | off | SO_REUSEPORT-style multi-sc, one sc per worker fd |
1061+
| `FF_USE_RING_IPC` | off | Switch IPC to lock-free DPDK SPSC ring (v3.4 opts on by default) |
1062+
1063+
For the full design, supported modes, environment variables, performance notes and
1064+
known limitations, see `adapter/syscall/README.md`.
1065+
10441066
---
10451067

10461068
## Summary

docs/zh_cn/01-LAYER1-ARCHITECTURE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ NIC 驱动 (igb_uio / vfio-pci)
9292
├── tools/ # 工具脚本
9393
├── adapter/ # 网络适配器
9494
│ ├── micro_thread/ # 微线程接口,方便有状态应用使用 F-Stack
95-
│ └── syscall/ # 通过 LD_PRELOAD 劫持 Linux syscall 为 F-Stack API
95+
│ └── syscall/ # 编译产物为 libff_syscall.so 与独立 fstack 实例二进制;通过
96+
│ # LD_PRELOAD 劫持 Linux syscall(socket/bind/connect/read/write/
97+
│ # send/recv/epoll/accept4/__recv_chk/fork/ioctl 等)转发给
98+
│ # fstack 实例,IPC 走 Hugepage 共享内存(sem 路径或开关
99+
│ # FF_USE_RING_IPC 后的 lock-free ring 路径)
96100
├── doc/ # 原始英文文档
97101
├── docs/ # 三层架构知识库文档
98102
└── config.ini # 默认配置文件

docs/zh_cn/F-Stack_Architecture_Layer1_System_Overview.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ F-Stack 模式 (用户态网络)
138138
139139
├── adapter/ # 网络适配器
140140
│ ├── micro_thread/ # 微线程接口,方便有状态应用使用 F-Stack
141-
│ └── syscall/ # 通过 LD_PRELOAD 劫持 Linux syscall 为 F-Stack API
141+
│ └── syscall/ # 编译产物为 libff_syscall.so 与独立 fstack 实例二进制;通过
142+
│ # LD_PRELOAD 劫持 Linux syscall 转发给 fstack 实例,IPC 走
143+
│ # Hugepage 共享内存(默认 sem 路径,或开关 FF_USE_RING_IPC 后
144+
│ # 切到 lock-free ring 路径),详见 adapter/syscall/README.md
142145
├── doc/ # 原始英文文档
143146
├── docs/ # 三层架构知识库文档
144147
├── config.ini # 默认配置文件
@@ -770,25 +773,40 @@ int main() {
770773
```
771774

772775
**方式 2:LD_PRELOAD 拦截 (如 Nginx)**
776+
777+
LD_PRELOAD 模式下应用以两个进程方式运行:独立的 `fstack` 实例(链接 libfstack.a,跑
778+
DPDK 轮询),以及预加载 `libff_syscall.so` 的用户应用(如 nginx)。两者通过 Hugepage
779+
共享内存通信——默认走信号量路径,置 `FF_USE_RING_IPC=1` 后切换为基于 DPDK SPSC
780+
`rte_ring` 的 lock-free 路径。**`fstack` 实例必须在 LD_PRELOAD 应用之前启动**
781+
773782
```bash
774-
# Nginx 启用 F-Stack 支持
775-
LD_PRELOAD=libff_syscall.so nginx
776-
777-
# LD_PRELOAD 钩子拦截:
778-
socket() → ff_socket()
779-
bind() → ff_bind()
780-
connect() → ff_connect()
781-
read() → ff_read()
782-
write() → ff_write()
783-
send() → ff_send()
784-
sendto() → ff_sendto()
785-
sendmsg() → ff_sendmsg()
786-
recv() → ff_recv()
787-
recvfrom() → ff_recvfrom()
788-
recvmsg() → ff_recvmsg()
783+
# 1) 先启动 fstack 实例(可启动多个)
784+
./fstack --conf config.ini --proc-type=primary --proc-id=0 &
785+
786+
# 2) 再使用 LD_PRELOAD 启用 Nginx 的 F-Stack 支持
787+
LD_PRELOAD=/path/to/libff_syscall.so nginx
788+
789+
# LD_PRELOAD 钩子拦截(转发至 ff_* / kqueue):
790+
socket() → ff_socket() accept() → ff_accept()
791+
bind() → ff_bind() accept4() → ff_accept() + SOCK_CLOEXEC/NONBLOCK
792+
connect() → ff_connect() listen() → ff_listen()
793+
read() → ff_read() close() → ff_close()
794+
write() → ff_write() ioctl() → ff_ioctl()
795+
send/sendto/sendmsg() → ff_send/sendto/sendmsg()
796+
recv/recvfrom/recvmsg() → ff_recv/recvfrom/recvmsg()
797+
__read_chk / __recv_chk / __recvfrom_chk (glibc _FORTIFY_SOURCE 包装)
798+
epoll_create/ctl/wait() → kqueue 事件(可选 polling 模式)
799+
fork() → 每进程独立 FreeBSD struct thread(贴近 Linux kernel 语义)
789800
...
801+
802+
# 关键环境变量 / 编译开关:
803+
# FF_KERNEL_EVENT=1 并行转发内核 fd 给宿主 epoll
804+
# FF_MULTI_SC=1 SO_REUSEPORT 风格的多 sc,每 worker fd 一个 sc
805+
# FF_USE_RING_IPC=1 将 IPC 切到 lock-free DPDK SPSC ring(默认含 v3.4 优化)
790806
```
791807

808+
完整功能列表、编译开关、已知限制及致谢请参考 `adapter/syscall/README.md`
809+
792810
### 7.2 工具支持
793811

794812
运维工具通过 IPC 与 F-Stack 进程通信:

docs/zh_cn/F-Stack_Architecture_Layer2_Interface_Specification.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,21 +1181,41 @@ symmetric_rss = 1 # 双向连接到同一队列
11811181

11821182
### 6.2 应用集成接口
11831183

1184-
**直接调用模式**:应用直接链接 libfstack.a 并调用 ff_* API
1184+
**直接调用模式**:应用直接链接 libfstack.a 并调用 ff_* API
11851185

1186-
**LD_PRELOAD 模式**:使用 LD_PRELOAD=libfstack.so 拦截系统调用
1186+
**LD_PRELOAD 模式**:应用预加载 `libff_syscall.so`(由 `adapter/syscall/` 构建),与
1187+
独立的 `fstack` 实例**以两个进程方式运行**,两者通过 Hugepage 共享内存通信;默认走
1188+
信号量路径,置 `FF_USE_RING_IPC=1` 后切换为基于 DPDK SPSC `rte_ring` 的 lock-free
1189+
路径。**`fstack` 实例必须在 LD_PRELOAD 应用之前启动**
11871190

11881191
```bash
1192+
# 先启动 fstack 实例(可启动多个)
1193+
./fstack --conf config.ini --proc-type=primary --proc-id=0 &
1194+
11891195
# Nginx 集成
1190-
LD_PRELOAD=/path/to/libfstack.so /usr/sbin/nginx -g "daemon off;"
1196+
LD_PRELOAD=/path/to/libff_syscall.so /usr/sbin/nginx -g "daemon off;"
11911197

11921198
# Redis 集成
1193-
LD_PRELOAD=/path/to/libfstack.so /usr/bin/redis-server /etc/redis.conf
1199+
LD_PRELOAD=/path/to/libff_syscall.so /usr/bin/redis-server /etc/redis.conf
11941200

11951201
# 自定义应用
1196-
LD_PRELOAD=/path/to/libfstack.so ./my_app
1202+
LD_PRELOAD=/path/to/libff_syscall.so ./my_app
11971203
```
11981204

1205+
被劫持的 POSIX 入口包括:`socket / bind / connect / accept / accept4 / listen /
1206+
close / read / write / send / sendto / sendmsg / recv / recvfrom / recvmsg /
1207+
__read_chk / __recv_chk / __recvfrom_chk / ioctl / epoll_create|ctl|wait / fork`。
1208+
1209+
常用运行时 / 编译开关:
1210+
1211+
| 开关 | 默认 | 作用 |
1212+
|---|---|---|
1213+
| `FF_KERNEL_EVENT` || 并行转发内核 fd 给宿主 epoll |
1214+
| `FF_MULTI_SC` || SO_REUSEPORT 风格的多 sc,每 worker fd 一个 sc |
1215+
| `FF_USE_RING_IPC` || 将 IPC 切到 lock-free DPDK SPSC ring(默认含 v3.4 优化) |
1216+
1217+
完整设计、支持模式、环境变量、性能数据与已知限制详见 `adapter/syscall/README.md`
1218+
11991219
---
12001220

12011221
## 总结

0 commit comments

Comments
 (0)