Objective
- to understand how eBPF-events are being handled in userspace in various open-source projects
- to learn their approach for handling massive amount of events
Currently only tetragon project is covered.
Reasoning
Once eBPF-events are written by the kernel-space hook in ringBuffer or perfBuffer, they become available for consumption from user-space.
Following steps are usually performed in user-space code;
- Preparation of ringBuffer / perfBuffer reader
- Reading of records from buffer
- Processing of raw-samples
Tetragon
Preparation
PerfEvent reader is prepared from pinned perf-map. [Source]
Reading
A goroutine is launched;
- to read records from perfReader that adds them to eventsQueue (a buffered-channel).
Another goroutine is launched;
- for reading records from eventsQueue, where they are passed to receiveEvent() for processing
Processing
On calling receiveEvent()
- it converts raw-bytes to events by passing data to HandlePerfData()
- send events to various listeners
On calling HandlePerfData();
- it tries to find event-specific handler using first-byte
- calls the handler for parsing raw-bytes
.png)
