feat(agnocast_kmod): replace do_exit kprobe with sched_process_exit tracepoint#1089
Draft
k1832 wants to merge 2 commits intotier4:mainfrom
Draft
feat(agnocast_kmod): replace do_exit kprobe with sched_process_exit tracepoint#1089k1832 wants to merge 2 commits intotier4:mainfrom
k1832 wants to merge 2 commits intotier4:mainfrom
Conversation
…it tracepoint Replace the kprobe on the internal `do_exit` symbol with the stable `sched_process_exit` tracepoint. This improves portability (do_exit is not a stable kernel API), reduces per-exit overhead (~20x less latency), and provides a formal unload safety guarantee via tracepoint_synchronize_unregister(). Use for_each_kernel_tracepoint() for dynamic lookup since the tracepoint symbol is not exported to modules. Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp>
Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp>
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.
Description
Replace the
do_exitkprobe with asched_process_exittracepoint for process exit detection.Why:
do_exitsched_process_exittracepointdo_exitis an internal symbol — no stability guarantee across kernel versionsint3breakpoint trap (x86) orBRK(arm64)nopwhen disabled,jmpwhen enabled)unregister_kprobe()— no explicit "all callbacks done" guaranteetracepoint_synchronize_unregister()— formal guarantee no callbacks in flightcurrent->pidtask_struct *directly — correct by construction#if LINUX_VERSION_CODEguards (6.2+__noreturn, 6.7+ inlining)The tracepoint symbol (
__tracepoint_sched_process_exit) is not exported to modules, so we use dynamic lookup viafor_each_kernel_tracepoint()+tracepoint_probe_register(), both of which areEXPORT_SYMBOL_GPLand compatible with the module'sMODULE_LICENSE("Dual BSD/GPL").Behavioral equivalence: The kprobe handler and tracepoint callback both call
enqueue_exit_pid(pid). The cleanup logic (process_exit_cleanup,exit_worker_thread, ring buffer) is completely unchanged.task->pidis valid at both hook points — the PID is not freed untilexit_notify()→release_task(), which runs after the tracepoint.Benchmark (50000 ×
/bin/trueon same machine):No measurable throughput difference. This is expected — the ~1 us per-call saving is invisible in a test dominated by fork+exec+exit cost (~3.8 ms per iteration). The real value is portability (stable API), unload safety (
tracepoint_synchronize_unregister), and eliminating preemption-disabled windows.Related links
How was this PR tested?
bash scripts/test/e2e_test_1to1(required)bash scripts/test/e2e_test_2to2(required)KUnit tests do not need changes — they call
enqueue_exit_pid()/process_exit_cleanup()directly and do not exercise the hook mechanism.Notes for reviewers
for_each_kernel_tracepoint()is used for dynamic tracepoint lookup because the static tracepoint symbol is not exported to modules. This is a standard pattern used by other out-of-tree modules.tracepoint_synchronize_unregister()is called during module exit to guarantee no callbacks are in flight before the module is unloaded.