Repository navigation
feat(ktrace): recorded scheduler, syscall and page fault events and streamed sessions into a file - #348
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ktrace start -o FILEorktrace record -o FILEin place ofktrace dump. The ring size then bounds only how far the recorder may fall behind, not how long a session runs, and the file counts any records a full ring dropped.Note
Medium Risk
Adds optional hot-path tracing on every context switch, wakeup, syscall, and user page fault, and replaces ktrace I/O with a concurrent ring-drain/streaming model where reader/session lifecycle bugs could drop or mis-order data.
Overview
ktrace moves from post-stop snapshot dumps to live streaming while a session records:
/dev/ktrace/tracemust be open first, only one reader is allowed, and closing the reader stops the session. The on-disk layout switches from a CPU table to chunked records (CHUNK_RECORDS/CHUNK_END), with anevent_maskin the file header and per-chunk lost counts when rings fill before the reader drains them.Sessions now take
start(uint64_t event_mask); controlstartrecords all events. Rings track drained vs head so full buffers drop new events instead of wrapping silently. Status reports records/lost per CPU and bytes_streamed.Kernel instrumentation (when the matching bit is set): scheduler context switches (with reason), wakeups, syscall duration/result (excluding
SYS_ELEVATE), and user page-fault handling time/result. Helpers live inktrace_events.{h,cpp}withis_recording()fast paths.Userland
ktracereplacesdumpwithrecord -o FILE(open trace → start → stream) andstart -o FILE(detached recorder viaproc_create).fs::ERR_PIPEsurfaces start-without-reader; file provider mapsERR_INTR/ERR_PIPE.Kernel tests were rewritten around the streaming protocol, masks, ring loss, and reader lifecycle.
Reviewed by Cursor Bugbot for commit e8abe5d. Bugbot is set up for automated code reviews on this repo. Configure here.