[tracing] Add kernel tracing subsystem and integration validation#401
[tracing] Add kernel tracing subsystem and integration validation#401xuchang-vivo wants to merge 4 commits intovivoblueos:mainfrom
Conversation
|
build_prs |
|
Job is started, see https://github.com/vivoblueos/kernel/actions/runs/24561455116. |
|
❌ Job failed. Failed jobs: check_format (failure), build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/24561455116. |
|
build_prs |
|
Job is started, see https://github.com/vivoblueos/kernel/actions/runs/24561980464. |
|
❌ Job failed. Failed jobs: build_and_check_boards (failure), see https://github.com/vivoblueos/kernel/actions/runs/24561980464. |
|
build_prs |
|
Job is started, see https://github.com/vivoblueos/kernel/actions/runs/24562282519. |
|
✅ All jobs completed successfully, see https://github.com/vivoblueos/kernel/actions/runs/24562282519. |
|
build_prs |
|
Job is started, see https://github.com/vivoblueos/kernel/actions/runs/24562749518. |
|
✅ All jobs completed successfully, see https://github.com/vivoblueos/kernel/actions/runs/24562749518. |
nooopslol
left a comment
There was a problem hiding this comment.
Please add instructions for using the tracing tool, including how to capture traces and how to parse them.
The use cases can be found in test_tracing.rs. Currently, it does not support being triggered from shell commands and needs to be explicitly called in the firmware. Additionally, it has not been connected to an output backend yet. I will add shell commands and the output backend in a subsequent PR. This will need to wait until I have refactored the serial output module. This PR will serve as a buildblock, with additional tracing features to be added later. |
Summary
This PR introduces the first usable kernel tracing subsystem for BlueOS and validates it on
qemu_mps2_an385debug configuration.Included in this PR
kernel/src/tracing/{mod,control,event,buffer,dump}.rskconfig/config/qemu_mps2_an385/debug/defconfig(CONFIG_TRACING=y)kernel/tests/test_tracing.rskernel/tests/integration_test.rstracing::buffer::inittracing::control::initEmbedded Tracing (Brief Introduction)
In embedded systems, tracing is a low-overhead way to record runtime behavior as structured events, especially for timing-sensitive and concurrency issues that are hard to debug with logs.
Compared with plain
printfdebugging:event_id, timestamp, cpu/thread context, payload), easier to correlate and visualize.Typical architecture:
This PR implements the kernel-side foundation (probe + control + buffer + dump + tests) as step 1.
Validation
qemu_mps2_an385.debug:ninja -C out/qemu_mps2_an385.debug run_integration_testTraceStart,MmAlloc,MmFreeNotes
traceplaceholder command is intentionally removed in a separate app-level change and is not part of this kernel PR.Reference Links (Embedded Tracing)
Lock-Free Ring Buffer Strategy
To avoid deadlock risks in IRQ/SMP contexts, tracing write path now uses a lock-free per-CPU ring-buffer design:
fetch_addonwrite_seq.commit_seqwithReleaseordering.commit_seqwithAcquireordering and only consumes entries wherecommit_seq == seq.Why this strategy:
Current tradeoff:
Recorded Events Matrix
0x0001TraceStarttracing::start()0x0002TraceStoptracing::stop()0x0003TraceDropped0x0101SchedSwitchscheduler::switch_current_thread()0x0102ThreadCreatethread::Builder::build()0x0103ThreadExitschedulerretire path0x0104ThreadWakeup0x0105ThreadBlockscheduler::suspend_me_until()0x0201IrqEnterIrqTrace::enter()0x0202IrqExitIrqTrace::leave()0x0301SysEnterarm/riscv/aarch64)0x0302SysExitarm/riscv/aarch64)0x0401LockWaitBeginsync::mutexwait path0x0402LockWaitEndsync::mutexwait completion/timeout0x0403LockHoldBeginsync::mutexlock acquisition0x0404LockHoldEndsync::mutexunlock path0x0501MmAllocallocator::{malloc,realloc,malloc_align}0x0502MmFreeallocator::{free,realloc,free_align}0x0503MmAllocFail0x0601CounterMemUsedBytes