Repository navigation
CPU engines: check the sigaction probe and validate the assigned interval - #1014
Conversation
|
@DataDog review |
Scan-Build Report
Bug Summary
Filter Results by FileReports
|
|||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
The new signal-restoration assertion fails on glibc x86_64 because sigaction adds SA_RESTORER to the installed flags. Comparing against the queried installed disposition avoids falsely failing the gtest suite.
🤖 Bits Code Review · Commit 1bb7828
CI Test ResultsRun: #44499064029 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Failed Jobs
Summary: Total: 32 | Passed: 31 | Failed: 1 Updated: 2026-11-19 10:48:50 UTC |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae607c407a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
On glibc x86-64, sigaction() injects the internal SA_RESTORER flag when installing a custom SIGPROF handler, so any assertion that compares the originally-requested struct sigaction against the read-back disposition will fail even when the handler is correctly restored. The fix is to snapshot the installed disposition (post-sigaction) before the probe and compare two read-backs, as the neighboring tests already do.
🤖 Bits Code Review · Commit ae607c4
There was a problem hiding this comment.
More details
The PR guards failed SIGPROF probes, validates resolved CPU intervals, and documents engine lifecycle behavior. The follow-up fixes the glibc x86_64 restoration-test failure by masking SA_RESTORER; no findings remain open, with full gtests unrun and production telemetry excluded.
🤖 Bits Code Review · Commit 90225b2
…rval ITimerJvmti::check() restored an uninitialized sigaction as the SIGPROF disposition when the probe failed; return an Error instead. ITimerJvmti, ITimer and CTimer validated args._interval but assigned cpuSamplerInterval(); validate the assigned value so a caller setting only cpu is accepted and a non-CPU event reaching a CPU engine fails instead of arming a disarmed timer.
itimer_ut covers the ITimer/ITimerJvmti cases with a forwarding sigaction interposer for the probe-failure path; ctimer_ut covers the CTimer twin.
The non-CPU-event rejection tests now use the default _interval=0, which the pre-fix validation accepted, so they fail on unfixed code. Replace stale itimer.cpp line references in ProfilingEngines.md with symbol references.
Restore SIG_IGN before the saved SIGPROF disposition in itimer_ut teardown, drop the remaining itimer.cpp line citation from ProfilingEngines.md, and phrase the test comments in current-behavior terms.
sameDisposition ignores libc-internal SA_RESTORER in the read-back flags (musl keeps it set; glibc strips it), which unblocks the musl container. Cover cpuSamplerInterval()'s _interval fallback branch, pin the stop() SIG_IGN asymmetry and the untouched _interval on rejected starts, drop the vacuous enginesReady asserts, and cite both engines for the setitimer mechanism in ProfilingEngines.md.
Seed the engines' static _interval through test accessors instead of relying on state leaked by earlier tests, and pin ITimer::stop() to the exact engine handler. Extend the SA_RESTORER comment to cover glibc.
x86-64 glibc leaves SA_RESTORER (0x04000000) in the read-back sa_flags without exporting the macro, so the header-guarded mask never engaged there and the disposition roundtrip test failed on the amd64 CI.
90225b2 to
cb6ce9a
Compare
There was a problem hiding this comment.
On Linux with CTimer available, check,event=wall,cpu=1ms reports OK even though the same options now fail to start a recording. The PR describes this preflight mismatch as a follow-up.
🤖 Bits Code Review · Commit cb6ce9a
|
🐶 babysit-pr is watching this PR — CI breakages and mechanical findings are fixed and pushed automatically; design decisions are always brought to you. This run
👀 watching · since 14:27 UTC · gitlab red (retry access denied) · 3 findings answered · Bits FAIL on cb6ce9a — awaiting operator on fix placement |
Profiler::check() now rejects cpu/event combinations that start() would reject with the same error, before JVM capability probing; engine check() stays pure capability probing, so engine selection and the event=wall/alloc/noop without cpu surface are unchanged. isCpuEvent is public for the preflight gate.
There was a problem hiding this comment.
The preflight guard in profiler.cpp rejects configurations with a zero/missing CPU interval before the CPU engine is selected, causing false negatives for engines (OpenJ9 JVMTI wall-clock, PerfEvents cycles) that supply their own default interval at startup. The fix requires moving the interval validation to after engine selection and scoping it only to timer engines that enforce it.
🤖 Bits Code Review · Commit 80e717b
perf_events and the J9 JVMTI sampler accept a zero resolved interval at start (hardware default period / wall interval), so the uniform preflight rule over-rejected on OpenJ9 and perf-only hosts. Gate the rule on the selected engine via Engine::enforcesCpuSamplerInterval(), true only for the timer family.
There was a problem hiding this comment.
The PR handles failed SIGPROF probes safely and validates the effective CPU timer interval. Engine-specific preflight now preserves CTimer’s rejection without blocking OpenJ9 or PerfEvents, but selecting the engine before the JVM capability check can expose a previously skipped process-wide timer probe on a JVM that preflight would reject.
🤖 Bits Code Review · Commit 1fb2b34
|
@DataDog review |
There was a problem hiding this comment.
The new preflight rejects mixed CPU and wall-clock configurations that can still start a wall-clock recording. It also probes CPU engines before validating the JVM, so a rejected check can disarm an existing process-wide profiling timer.
🤖 Bits Code Review · Commit 1fb2b34
…overable CPU failure Engine selection moves back behind checkJvmCapabilities(): the probes (ITimerJvmti's setitimer clobber, CTimer's timer_create) must not run on JVMs the gate would reject. A CPU engine rejected for its interval is skipped like startCpuEngine() skips it on failure, and the preflight fails only when no other requested mode validates; preflight tests move to CheckCommandTest on a live JVM.
There was a problem hiding this comment.
The most critical production-correctness issue is in profiler.cpp: the no-op allocation engine's check passes and causes check to report OK for configurations where start would not actually activate allocation sampling. Separately, the new timer-rejection assertion in CheckCommandTest.java is not guarded by engine type, so it produces false failures on OpenJ9/JVMTI-backed configurations where the command correctly returns OK.
🤖 Bits Code Review · Commit 504b9c7
…penJ9 rejection test The no-op allocation and wall engines validate but start() skips them, so they cannot carry a recording; the preflight must not treat them as a viable alternative. checkPreflightRejectsNonCpuEventWithCpu skips OpenJ9, whose JVMTI sampler accepts a zero resolved CPU interval.
There was a problem hiding this comment.
More details
The PR fixes unsafe SIGPROF restoration and validates resolved CPU intervals while preserving backend defaults and viable mixed-mode recordings. The OpenJ9 preflight and test issues are resolved, and no-op engines no longer count as viable fallbacks; no review findings remain open.
🤖 Bits Code Review · Commit eb789ac
004eae2
into
main
What does this PR do?:
Fixes three correctness issues in the CPU-time engines, found during review of PR #537 (PROF-14755):
ITimerJvmti::check()restores an uninitializedsigactionas the process-wideSIGPROFdisposition when the probingsigaction()call fails. It now returns anErrorbefore arming thesetitimerprobe.ITimerJvmti::start(),ITimer::start()andCTimer::startWithTableSize()validatedargs._intervalbut assignedargs.cpuSamplerInterval(). A caller setting onlycpuwith a non-positive_intervalwas rejected although the assigned value is valid. They now validate the value they actually assign; a non-CPU event reaching a CPU engine (cpuSamplerInterval() == 0) is rejected instead of silently arming a disarmed timer.ITimerJvmti::stop()does not clear_enabled— verified as correct:Profiler::stop()callsdisableEngines()before any engine teardown, so no stale window exists. The lifecycle is now documented at the two points that rely on it; no behavior change.Motivation:
Three review findings on PR #537 were filed as PROF-14755. Investigation confirmed bug 1 as a real defect (stack-garbage handler installation on a failed syscall), bug 2 as a latent validation/assignment mismatch (not reachable through argument parsing, which rejects
interval <= 0, but reachable for programmatically builtArguments), and bug 3's premise as disproven by the currentProfiler::stop()ordering — the ticket's suggestedenableEvents(false)fix would have introduced a new inconsistency, since no engine writes_enabledfromstop(). TheSIG_IGNasymmetry betweenITimerJvmti::stop()andITimer::stop()is documented and pinned by tests rather than changed; both behaviors are safe.Additional Notes:
event=wall cpu=N(a CPU engine is selected becauseargs._cpu >= 0precedes theEVENT_WALLbranch inselectCpuEngine), the CPU engine previously started silently with a zero interval — a disarmed timer producing no samples. It now fails to start with a logged, recoverable error.cpuSamplerInterval()substitutesDEFAULT_CPU_INTERVALfor CPU events, so no legitimate CPU configuration is newly rejected. Counterpart flip, accepted:event=cpu interval=-1(rejected before) now resolves toDEFAULT_CPU_INTERVAL— consistent withITimer's pre-existing behavior and withArguments::parse, which rejectsinterval <= 0.checkpreflight now mirrors the start()-time interval validation for the configurations that run a real CPU engine (cpuset, or a CPU event) and rejects with the same error, socheckno longer reportsOKfor optionsstart()rejects. Enginecheck()remains pure capability probing: engine selection, fallback order, and theevent=wall/alloc/noop-without-cpusurface are unchanged.origin/main.SKIP_IF_CALLOC_OVERFLOW_ABORTS; the reject branch covers CTimer's validation there), andStartValidatesCpuSamplerIntervalleavesCTimer::_interval/_signalset after the forced allocation failure, matching the neighboring pre-existing test.event=wall cpu=Nbehavior change touches engine selection paths. (human_review:recommended)How to test the change?:
New gtests pin all changed behavior; each discriminating test fails against the pre-fix code (verified by running with the production fix reverted):
ITimerTest.JvmtiCheckFailsWhenSigactionProbeFails— a forwardingsigactioninterposer (bound statically in the test binary) fails the probe; asserts theErrorreturn and an unchangedSIGPROFdisposition.ITimerTest.JvmtiStartAcceptsCpuOnlyArguments/JvmtiStartUsesIntervalFallback— the value actually assigned is accepted in bothcpuSamplerInterval()branches; rejected by pre-fix code.ITimerTest.StartRejectsNonCpuEvent/JvmtiStartRejectsNonCpuEvent(_event=wall,_cpu>0) — rejected now; pre-fix code silently armed a disarmed engine. The static_intervalis seeded before the call, so "untouched" is asserted deterministically.CTimerNativeMemTest.StartValidatesCpuSamplerInterval/StartRejectsNonCpuEvent— the CTimer twin.ITimerTest.JvmtiCheckRestoresPreviousDisposition— the probe/restore roundtrip leaves the disposition untouched (masking libc-internalSA_RESTORERbookkeeping that musl reports on read-back).Verification (candidate: ae607c4):
:ddprof-lib:gtestDebug(macOS arm64, debug):ddprof-lib:gtestDebug_itimer_ut(macOS arm64):ddprof-lib:gtestDebug_ctimer_utgtestAsan_itimer_ut,gtestAsan_ctimer_ut,gtestTsan_itimer_ut,gtestTsan_ctimer_ut(final candidate):ddprof-lib:gtestDebug_itimer_ut(final candidate):ddprof-lib:qualityChecks:ddprof-test:testDebug -Ptests=SmokeCpuTest(macOS, JDK 25)itimer_ut,ctimer_utwith the production fix reverted)Known unrelated failure:
:ddprof-test:testAsanin the glibc aarch64 container fails inCollapsingSleepTest.testSleep(timing assertion). It fails identically on bareorigin/mainwithout this diff; it passed on the pre-rebase candidate. Recorded as pre-existing, not caused by this change.Note: gtest runs in CI on Linux only; the macOS and musl results above cover the platform where
ITimerJvmtiis actually selected and the alternate libc.For Datadog employees:
credentials of any kind, I've requested a security review (run the
dd:platform-security-reviewskill, or file a request via the PSEC review form).
bewairealso runs automatically on every PR.