refactor(rocprofiler-sdk): migrate PC sampling off the per-queue callback registry#8895
refactor(rocprofiler-sdk): migrate PC sampling off the per-queue callback registry#8895amd-vkale wants to merge 1 commit into
Conversation
✅ All Policy Checks Passed
📖 Need help? See the Policy FAQ for details on every check and how to fix failures. |
|
🚫 Please fix the failed policies before requesting reviews. The following policy checks failed:
The |
54f04db to
c3d0f74
Compare
c3d0f74 to
923ac10
Compare
…back registry Isolates the PC-sampling slice of the callback-removal effort (reference PRs ROCm#8730 / ROCm#8586) into a small, single-service change, per review guidance to land callback removal one service at a time. Independent of kernel replay. PC sampling no longer registers a queue_callbacks_t with the HSA queue controller in pc_sampling_service_finish_configuration. Instead: - pc_sampling::signal_completion_hook (new pc_sampling/queue_hooks.{hpp,cpp}) delivers kernel completion to the CID manager; it is called explicitly from the HSA async signal handler in hsa/queue.cpp. kernel_completion_cb is moved out of the anonymous namespace and declared in hsa_adapter.hpp. - pc_sampling::is_configured_on_agent replaces the queue.get_notifiers() signal the old registration used to provide, so the write interceptor still injects the marker packet for PC-only runs. It is always linkable (guarded by ROCPROFILER_SDK_HSA_PC_SAMPLING) and compiled before the pc_sampling CMake early-return so it links even without HSA PC sampling support. The marker packet injection in the write interceptor is unchanged (it was never registry-based). Removes the now-unused intercept_cb_id from PCSAgentSession and adds a queue_hooks unit test. The per-queue callback registry is retained for the remaining service (thread-trace/spm/counters migrate in their own PRs). Co-authored-by: Cursor <cursoragent@cursor.com>
923ac10 to
ec87a2f
Compare
vlaindic
left a comment
There was a problem hiding this comment.
Overall, the PR LGTM, thanks! I added a few comments and basically I propose to think about a master hook that will forward the calls down the chain based on available services. If you think that this kind of implementation is not optimal, then please disregard the comment.
Also, I'd recommend you to run the existing PC sampling tests on MI300A machine to ensure that there's no regressions introduced by this PR. Thanks in advance.
Also adding AI review comments:
PR #8895 Review — refactor(rocprofiler-sdk): migrate PC sampling off the per-queue callback registry
Files changed: 9 | +205 / -31 | Branch: users/vkale/remove-callbacks-pc-sampling → develop
Overall Assessment
This is a clean, well-scoped refactor. The approach (explicit hook call in the signal handler instead of a registry-based callback) is sound, the #if ROCPROFILER_SDK_HSA_PC_SAMPLING gating is consistent, and the unit test for the no-runtime path is a good addition. A few concrete issues below, none of them blockers if addressed.
Findings
⚠️ IMPORTANT (1) — [hygiene] Missing JIRA ID and empty Test Plan / Test Result
Issues Detected
- The
## Issue Trackingsection contains only the template placeholder comments; no actual JIRA ID or GitHub issue number is present. ## Test Planand## Test Resultare both empty (only template comments remain).
Suggested Actions
- Add a JIRA ID in the format
ABC-1234to the Issue Tracking section, or if none exists, add a one-liner explaining why (e.g., pure refactor tracked only via parent PR #8730). - Fill in the Test Plan section: at minimum state which existing test suite was run (
pcs-testunit tests, any end-to-end PC sampling test), and what the pass/fail outcome was.
Risk / Impact Assessment
- Low in isolation — the description body is self-contained enough for reviewers familiar with the callback refactor. But the empty Test Plan is concerning for anyone approving a GPU signal-path change without knowing if the existing PC sampling test suite was exercised.
⚠️ IMPORTANT (2) — [clarity] Copyright headers on new files still read 2025
Issues Detected
queue_hooks.cppline 3:Copyright (c) 2025 Advanced Micro Devices, Inc.queue_hooks.hppline 3:Copyright (c) 2025 Advanced Micro Devices, Inc.tests/queue_hooks_test.cppline 3:Copyright (c) 2025 Advanced Micro Devices, Inc.
All three are newly added files in this PR.
Suggested Actions
- Update copyright header in
queue_hooks.cppfrom2025to2026— file is newly added in this PR. - Update copyright header in
queue_hooks.hppfrom2025to2026— file is newly added in this PR. - Update copyright header in
tests/queue_hooks_test.cppfrom2025to2026— file is newly added in this PR.
Risk / Impact Assessment
- Low — legal / compliance housekeeping, not runtime impact.
⚠️ IMPORTANT (3) — [generic] Mutable-reference copy in signal_completion_hook is a workaround that should be documented more prominently
Issues Detected
In queue_hooks.cpp:57-59:
// kernel_completion_cb takes a mutable reference to the kernel packet even
// though it does not modify it; copy to bind a non-const lvalue.
auto kern_pkt = kernel_packet;
hsa::kernel_completion_cb(queue.get_agent().get_rocp_agent(), kern_pkt, *session);The comment explains the workaround, but the root issue (the kernel_completion_cb signature takes rocprofiler_packet& despite not modifying the argument) is in hsa_adapter.cpp and hsa_adapter.hpp, not here. This cross-file mismatch is easy to miss in a future signature cleanup.
Suggested Actions
- Add a
// TODO:or// FIXME:comment at thekernel_completion_cbdeclaration inhsa_adapter.hpp:62noting that the parameter should beconst rocprofiler_packet&— this makes the mismatch visible at the definition site, not just at the sole callsite inqueue_hooks.cpp. - Alternatively, fix the
kernel_completion_cbsignature to takeconst rocprofiler::hsa::rocprofiler_packet&now (it is already marked/* kernel_pkt *// unused in the function body), removing the need for the copy entirely.
Risk / Impact Assessment
- Low — no runtime risk, but the defensive copy adds unnecessary overhead on every kernel completion when PC sampling is active.
💡 SUGGESTION (1) — [generic] Typo in PR description
Issues Detected
- "to isolatesthe" in the Motivation section — missing space and stray "s": should be "to isolate the".
Suggested Actions
- Fix before marking ready to review.
💡 SUGGESTION (2) — [hygiene] Test adequacy: only the #else branch is exercised
Issues Detected
queue_hooks_test.cpp tests is_configured_on_agent when ROCPROFILER_SDK_HSA_PC_SAMPLING is not set (or the service is unconfigured). The #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 path (delegating to is_pc_sample_service_configured) has no unit-test coverage at all.
Suggested Actions
- This is acceptable for a no-GPU unit test. Note it explicitly in the test comment so a future contributor knows the HSA path is only covered by integration tests (e.g., in the existing PC sampling end-to-end suite).
- Consider adding a second test case:
is_configured_on_agentreturnsfalsefor an unrecognized agent even when HSA PC sampling is compiled in, using an existing mock or stub foris_pc_sample_service_configured.
Risk / Impact Assessment
- Low — the no-runtime path is thoroughly guarded. The real risk would be a regression in the HSA path, which is only caught by end-to-end tests.
💡 SUGGESTION (3) — [clarity] PR is marked "Not ready to Review" — confirm before requesting full review
The label Not ready to Review is still set. If the PR is ready for review, remove it; otherwise ping when ready.
Summary Table
| # | Severity | Tag | File | Issue |
|---|---|---|---|---|
| 1 | [hygiene] | PR description | Missing JIRA ID + empty Test Plan/Result | |
| 2 | [clarity] | 3 new files | Copyright year 2025 → should be 2026 | |
| 3 | [generic] | queue_hooks.cpp, hsa_adapter.hpp |
Unnecessary defensive copy / stale mutable signature | |
| 4 | 💡 SUGGESTION | [generic] | PR description | Typo "isolatesthe" |
| 5 | 💡 SUGGESTION | [hygiene] | queue_hooks_test.cpp |
Test only covers #else branch |
| 6 | 💡 SUGGESTION | [clarity] | PR labels | "Not ready to Review" label still set |
| // PC sampling completion is no longer routed through the per-queue | ||
| // callback registry; invoke its hook explicitly. | ||
| pc_sampling::signal_completion_hook(queue_info_session.queue, | ||
| packet.kernel_packet, | ||
| _session, | ||
| packet, | ||
| packet.instrumentation_packets, | ||
| dispatch_time); | ||
|
|
There was a problem hiding this comment.
I'm wondering whether we should have a master hook that will be invoked here. Then a master hook would check what service is enabled, and then invoke a specific hook.
| TEST(pc_sampling_queue_hooks, is_configured_on_agent_unconfigured) | ||
| { | ||
| rocprofiler_agent_id_t agent_id; | ||
| agent_id.handle = 123456; | ||
| EXPECT_FALSE(rocprofiler::pc_sampling::is_configured_on_agent(agent_id)); | ||
| } |
There was a problem hiding this comment.
Should we have a similar test for the case when PC sampling is configured?
| namespace pc_sampling | ||
| { | ||
| bool | ||
| is_configured_on_agent(rocprofiler_agent_id_t agent_id) |
There was a problem hiding this comment.
Don't mind having this function, but maybe seems similar to place #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 inside the is_pc_sample_service_configured as that function is called by multiple places and already has a guard whether HSA is loaded.
Motivation
The purpose of this PR is to isolatesthe PC-sampling slice of the callback-removal effort (reference PRs #8730 / #8586) into a small, single-service change, per review guidance to land callback removal one service at a time. Helps toward but independent of kernel replay feature in #7960.
Technical Details
PC sampling no longer registers a queue_callbacks_t with the HSA queue controller in pc_sampling_service_finish_configuration. Instead:
The marker packet injection in the write interceptor is unchanged (it was never registry-based). Removes the now-unused intercept_cb_id from PCSAgentSession and adds a queue_hooks unit test. The per-queue callback registry is retained for the remaining service (thread-trace/spm/counters migrate in their own PRs).
Issue Tracking
Test Plan
Test Result
Submission Checklist