-
Notifications
You must be signed in to change notification settings - Fork 1
feat: estimate cycles #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
not-matthias
wants to merge
6
commits into
master
Choose a base branch
from
feat/cycle-estimation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fbab623
chore: add cycle estimation benchmarks
not-matthias baac49f
feat(callgrind): add cycle-LUT toolchain and regenerated cost tables
not-matthias 4259aba
chore: add nix dev-shell flake for valgrind-codspeed
not-matthias 22e0934
feat(callgrind): cycle-estimation runtime (Capstone decode + cost LUT)
not-matthias 641841a
wip(callgrind): make Capstone mandatory for cycle estimation
not-matthias d2d09c3
ci(callgrind): build 64-bit only so cycle estimation works without 32…
not-matthias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## What this is | ||
|
|
||
| CodSpeed's fork of the Valgrind source tree (`github.com/CodSpeedHQ/valgrind-codspeed`, upstream `sourceware.org/git/valgrind.git`). All CodSpeed work is in **Callgrind** (`callgrind/`). CodSpeed-specific changes are tracked in `CODSPEED-CHANGELOG.md`; READMEs/NEWS/AUTHORS are untouched upstream content. | ||
|
|
||
| The headline modification: CodSpeed runs benchmarks with `--instr-atstart=no` and fires `CALLGRIND_START_INSTRUMENTATION` several frames deep (inside libpython, or behind a V8/JIT trampoline). Callgrind's shadow stack starts at 0 while real frames exist, so returns underflow and produce a "phantom root" holding ~all inclusive cost. The fix (`CLG_(reconstruct_call_stack_from_native)` in `callgrind/callstack.c`) seeds the shadow stack from the native stack at the OFF→ON transition. Related: `--obj-skip=<object>` CLI option and `CALLGRIND_ADD_OBJ_SKIP` client request to exclude whole shared libraries. See `.agents/docs/` for the detailed correctness analysis. | ||
|
|
||
| ## Build | ||
|
|
||
| Autotools, but `configure` is checked in — **`./autogen.sh` is only needed if you modify `configure.ac`**. Build order matters: VEX → coregrind → callgrind. | ||
|
|
||
| To develop and use `vg-in-place` (runs the uninstalled binary from the repo root), build **in the repo**. Callgrind cycle estimation requires Capstone, so build from inside `nix develop` (which sets `CAPSTONE_DIR`, picked up by `configure`); otherwise pass `--with-capstone=PATH` to a static, x86+arm64-only, hardening-free Capstone: | ||
|
|
||
| ```bash | ||
| ./configure --enable-only64bit # needs CAPSTONE_DIR (nix develop) or --with-capstone=PATH; only64bit skips the no-Capstone 32-bit secondary build | ||
| make include/vgversion.h | ||
| make -j$(nproc) -C VEX | ||
| make -j$(nproc) -C coregrind | ||
| make -j$(nproc) -C callgrind | ||
| ``` | ||
|
|
||
| `just build local` is a separate flow that copies the tree to `/tmp/valgrind-build/valgrind-local` and builds there (used to test a clean build/install); it does **not** make `./vg-in-place` at the repo root usable. | ||
|
|
||
| Run uninstalled: `./vg-in-place --tool=callgrind [options] <prog>` | ||
|
|
||
| `valgrind` on PATH is symlinked to this repo's `vg-in-place` (`~/.local/bin/valgrind`), so an in-repo build is picked up automatically by `codspeed run` and friends — **no `sudo make install` needed**. | ||
|
|
||
| ## Tests | ||
|
|
||
| Callgrind regression tests live in `callgrind/tests/` (`.vgtest` definitions, `.stderr.exp`/`.stdout.exp`/`.post.exp` expected outputs). Harness is the Perl script `tests/vg_regtest`. | ||
|
|
||
| ```bash | ||
| tests/vg_regtest callgrind # whole callgrind suite | ||
| tests/vg_regtest callgrind/tests/fib # a single test (no extension) | ||
| ``` | ||
|
|
||
| Tests with a `uv`-based workload (e.g. `fib.vgtest`) have a `prereq` guard and silently skip if `uv` is not on PATH. Always use `uv` for Python. | ||
|
|
||
| ## Conventions | ||
|
|
||
| - **Branches:** `cod-<issue-number>-<kebab-description>` (e.g. `cod-2714-investigate-pytest-flamegraph-regression`). Default branch is `master`. | ||
| - **Commits:** conventional commits with a callgrind scope, e.g. `fix(callgrind): ...`, `refactor(callgrind): ...`. | ||
| - **C style:** clang-format via `.clang-format` (LLVM-based, 3-space indent, Linux braces). Format C before committing. | ||
|
|
||
| ## Gotchas | ||
|
|
||
| - The flamegraph validation harness (`.agents/flamegraph-validation/run_all.sh`) calls `../../vg-in-place`, so the repo must be built in place first (not via `just build local`). | ||
| - Debugging sessions leave untracked `vgcore.*` coredumps and `callgrind.out.*` files in `callgrind/tests/` — don't commit them. | ||
| - `obj_skip_checked` on `fn_node` is latched lazily on first BB entry; the shadow-stack seeder mirrors this check so decisions stay consistent. | ||
|
|
||
| ## Notes for agents | ||
|
|
||
| `.agents/docs/` holds dated investigation notes (correctness matrices, bug analyses) — read the relevant one before changing shadow-stack seeding logic. Put new temporary docs/scripts under `.agents/`. |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.