Event tracing system v1
Summary
As described in #25, Linmo currently lacks an event tracing system, which makes it difficult to debug asynchronous and preemptive kernel behavior.
This PR introduces the first scheduler-focused stage of the event tracing work, together with validation and profiling support for evaluating the implementation.
Functional scope
This PR includes:
- a tracing core with a fixed-size ring buffer
- scheduler event tracing for the current V1 scope
- deterministic scheduler trace validation
- QEMU-based profiling support for
debug_trace_event() - reproduction notes for the profiling workflow
Test Plan
| Area | Coverage |
|---|---|
| Scheduler tracing build | make clean && make trace_sched |
| Disabled tracing build | make clean && CFLAGS='-DCONFIG_DEBUG_TRACE=0' make trace_sched |
| Enabled runtime validation | trace_sched reports Overall: PASS |
| Disabled runtime validation | trace_sched reports Tracing disabled build: PASS |
| Ring buffer overwrite validation | verified by trace_sched wraparound test |
| QEMU plugin build | make -C tools/qemu QEMU_PLUGIN_INC=/path/to/qemu/include |
| QEMU plugin workflow | documented in tools/qemu/README.md |
Evaluation Setup / Reproduction
The profiling setup and reproduction steps included in this PR are documented in:
tools/qemu/README.md
| Item | Value |
|---|---|
| Toolchain path | PATH=/path/to/riscv/bin:$PATH |
| Cross compiler prefix | CROSS_COMPILE=<your-riscv-tool-prefix> |
| QEMU binary | qemu-system-riscv32 |
| QEMU plugin build compiler | cc |
| Plugin header path | QEMU_PLUGIN_INC=/path/to/qemu/include |
| Plugin build dependency | pkg-config with glib-2.0 |
Performance Notes
This PR keeps tracing under compile-time control and is intended to compile out tracing-related scheduler work when tracing is disabled.
Enabled and disabled trace_sched builds were revalidated locally after the latest changes.
This PR also includes QEMU-based profiling support for first-round tracing cost characterization.
The profiling workflow is documented in tools/qemu/README.md. Since the tracing path changed during the
latest review updates, the previously collected profiling numbers should be treated as provisional and refreshed in a follow-up measurement pass.
This PR does not claim that the final performance target in #25 has been met.
Notes
| Topic | Status |
|---|---|
| Scheduler-focused tracing milestone | included |
| Validation app | included |
| QEMU profiling support | included |
| Reproduction guide | included |
| Full issue #25 completion | not claimed in this PR |
| Performance target in #25 | not yet met / not claimed as met |
Future Work
- optimize the tracing hot path toward the performance target discussed in #25
- extend tracing coverage to IPC events
- extend tracing coverage to ISR / exception events
Summary by cubic
Adds v1 of the kernel event tracing system focused on the scheduler to improve debugging of async/preemptive behavior. Includes a ring-buffer trace core, scheduler event hooks, a validation app, QEMU-based profiling for debug_trace_event(), and a small hot-path optimization.
-
New Features
- Trace core: fixed-size ring buffer with
debug_trace_*API; 16-byte event records (timestamp + task ID); lock-free writes, interrupt-safe reads; defaultsCONFIG_DEBUG_TRACE=1,DEBUG_EVENT_BUFFER_SIZE=256; no-op stubs when disabled. - Scheduler instrumentation: emits
CREATE(id, prio),DESTROY(id, prev_state),SWITCH(prev_id, next_id),SUSPEND/RESUME,DELAY(ticks), and explicitYIELD(API only). trace_schedapp: deterministic checks for event presence/order, wraparound overwrite reporting, and monotonic timestamps; prints totals; dumps events on failure; added to app targets.- QEMU tooling: TCG plugin and docs to profile
debug_trace_event(); counts instructions and stores within a symbol PC range; includestools/qemuMakefile and-icountsteps.
- Trace core: fixed-size ring buffer with
-
Refactors
- Reduced trace hot-path footprint by inlining current task ID read in
debug_trace_event()(removesmo_task_id()call).
- Reduced trace hot-path footprint by inlining current task ID read in