Skip to content

Commit fa2df40

Browse files
committed
draft
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
1 parent 180b1c4 commit fa2df40

70 files changed

Lines changed: 8561 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/services/ebpf/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
API Reference
2+
#############
3+
4+
The public eBPF API is documented through the ``ebpf`` Doxygen group.
5+
6+
.. doxygengroup:: ebpf

doc/services/ebpf/architecture.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Architecture
2+
############
3+
4+
The subsystem is easiest to understand as two paths that meet in the runtime:
5+
6+
* the control path prepares programs to run,
7+
* the event path executes enabled programs when a backend target fires.
8+
9+
The short mental model is:
10+
11+
* :zephyr_file:`subsys/ebpf/ebpf_prog.c` is the program lifecycle orchestrator,
12+
* :zephyr_file:`subsys/ebpf/ebpf_attach_target.c` is the common attach-target
13+
runtime for all backends,
14+
* :zephyr_file:`subsys/ebpf/ebpf_verifier.c` is the safety gate,
15+
* :zephyr_file:`subsys/ebpf/backends/ebpf_tracing.c` and
16+
:zephyr_file:`subsys/ebpf/backends/ebpf_pm.c` are backend bridges,
17+
* :zephyr_file:`subsys/ebpf/ebpf_vm.c` is the execution engine,
18+
* :zephyr_file:`subsys/ebpf/ebpf_helpers.c` is the helper switchboard,
19+
* :zephyr_file:`subsys/ebpf/ebpf_maps.c` is the shared state store.
20+
21+
Subsystem Diagram
22+
*****************
23+
24+
.. figure:: images/ebpf_architecture.svg
25+
:alt: Zephyr eBPF subsystem architecture
26+
:width: 100%
27+
28+
Zephyr eBPF subsystem architecture.
29+
30+
Control Path
31+
************
32+
33+
The control path is entered when application code manages a program. The
34+
responsibilities are intentionally concentrated away from the hot event path.
35+
36+
1. A program descriptor and any maps are registered statically.
37+
2. :zephyr_file:`subsys/ebpf/ebpf_prog.c` accepts an attach request.
38+
3. :zephyr_file:`subsys/ebpf/ebpf_attach_target.c` checks whether the concrete
39+
:c:type:`ebpf_attach_target` is valid and whether the current program type
40+
can attach to it.
41+
4. A new attachment begins. The program enters the ``loaded`` state and
42+
current-attachment statistics are reset.
43+
5. When the program is enabled, :zephyr_file:`subsys/ebpf/ebpf_verifier.c`
44+
validates the bytecode for the current attachment.
45+
6. After verification succeeds, the program enters the ``enabled`` state and is
46+
eligible to run when its target fires.
47+
48+
Event Path
49+
**********
50+
51+
The event path is entered when a backend observes a real system event.
52+
53+
1. A backend bridge such as :zephyr_file:`subsys/ebpf/backends/ebpf_tracing.c`
54+
or :zephyr_file:`subsys/ebpf/backends/ebpf_pm.c` translates the native event into
55+
:c:type:`ebpf_attach_target` plus a backend-specific context object.
56+
2. :zephyr_file:`subsys/ebpf/ebpf_attach_target.c` finds every enabled program bound
57+
to that target.
58+
3. For each matching program, :zephyr_file:`subsys/ebpf/ebpf_vm.c` creates a
59+
fresh VM invocation with a clean register file and private stack.
60+
4. The VM exposes the event context through register ``R1``.
61+
5. Helper calls are resolved by :zephyr_file:`subsys/ebpf/ebpf_helpers.c`.
62+
6. Map operations are serviced by :zephyr_file:`subsys/ebpf/ebpf_maps.c`.
63+
7. Optional runtime statistics are accumulated in the program's current
64+
attachment.
65+
66+
Core Runtime Model
67+
******************
68+
69+
Several architectural choices explain the current subsystem shape:
70+
71+
* A program owns one current attachment at a time.
72+
* A target may fan out to multiple enabled programs.
73+
* Verification is scoped to the current attachment, not to the
74+
lifetime of the program descriptor.
75+
* Execution statistics are also current-attachment state.
76+
* Backends own event capture; :zephyr_file:`subsys/ebpf/ebpf_attach_target.c`
77+
is the shared attach-target runtime for all backends and owns validity
78+
checks, naming, active checks, fan-out dispatch, and program-to-target
79+
compatibility policy.
80+
81+
This split keeps program lifecycle decisions out of the hot path and keeps
82+
backend glue out of the generic runtime.

0 commit comments

Comments
 (0)