Event tracing system v1

Draft
SY
4mo ago
+866-9

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

AreaCoverage
Scheduler tracing buildmake clean && make trace_sched
Disabled tracing buildmake clean && CFLAGS='-DCONFIG_DEBUG_TRACE=0' make trace_sched
Enabled runtime validationtrace_sched reports Overall: PASS
Disabled runtime validationtrace_sched reports Tracing disabled build: PASS
Ring buffer overwrite validationverified by trace_sched wraparound test
QEMU plugin buildmake -C tools/qemu QEMU_PLUGIN_INC=/path/to/qemu/include
QEMU plugin workflowdocumented 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
ItemValue
Toolchain pathPATH=/path/to/riscv/bin:$PATH
Cross compiler prefixCROSS_COMPILE=<your-riscv-tool-prefix>
QEMU binaryqemu-system-riscv32
QEMU plugin build compilercc
Plugin header pathQEMU_PLUGIN_INC=/path/to/qemu/include
Plugin build dependencypkg-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

TopicStatus
Scheduler-focused tracing milestoneincluded
Validation appincluded
QEMU profiling supportincluded
Reproduction guideincluded
Full issue #25 completionnot claimed in this PR
Performance target in #25not 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; defaults CONFIG_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 explicit YIELD (API only).
    • trace_sched app: 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; includes tools/qemu Makefile and -icount steps.
  • Refactors

    • Reduced trace hot-path footprint by inlining current task ID read in debug_trace_event() (removes mo_task_id() call).