Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/actions/build-capstone/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build Capstone (cycle-estimation decoder)
description: >-
Build the static Capstone that Callgrind cycle estimation links against, and
export its install prefix as CAPSTONE_DIR for later steps.

runs:
using: composite
steps:
- shell: bash
run: |
CS_SRC="$GITHUB_WORKSPACE/third_party/capstone"
CS_PREFIX="$GITHUB_WORKSPACE/.capstone"
cmake -S "$CS_SRC" -B "$CS_SRC/build" \
-DCMAKE_BUILD_TYPE=Release \
-DCAPSTONE_ARCHITECTURE_DEFAULT=OFF \
-DCAPSTONE_X86_SUPPORT=ON \
-DCAPSTONE_ARM64_SUPPORT=ON \
-DCAPSTONE_BUILD_SHARED_LIBS=OFF \
-DCAPSTONE_BUILD_CSTOOL=OFF \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_PREFIX="$CS_PREFIX" \
-DCMAKE_C_FLAGS="-fno-stack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fPIC"
cmake --build "$CS_SRC/build" -j"$(nproc)"
cmake --install "$CS_SRC/build"
echo "CAPSTONE_DIR=$CS_PREFIX" >> "$GITHUB_ENV"
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

# Skip installing package docs to avoid wasting time when installing valgrind
# See: https://github.com/actions/runner-images/issues/10977#issuecomment-2810713336
Expand All @@ -42,20 +44,25 @@ jobs:
build-essential \
automake \
autoconf \
cmake \
libc6-dev \
gcc-multilib \
libc6-dev-i386 \
gdb \
docbook \
docbook-xsl \
docbook-xml \
xsltproc

- name: Build Capstone (cycle-estimation decoder)
uses: ./.github/actions/build-capstone

- name: Run autogen
run: ./autogen.sh

# CodSpeed only runs the 64-bit tool, and cycle estimation needs a
# 64-bit Capstone, so skip the 32-bit secondary build entirely. This
# halves build time and avoids compiling cycledecode.c without Capstone.
- name: Configure
run: ./configure
run: ./configure --enable-only64bit

- name: Build Valgrind
run: make -j$(nproc)
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- uses: actions/checkout@v4
with:
lfs: true
submodules: recursive
- uses: extractions/setup-just@v3

# Skip installing package docs to avoid wasting time when installing build dependencies
Expand Down Expand Up @@ -58,12 +59,17 @@ jobs:
build-essential \
automake \
autoconf \
cmake \
gdb \
docbook \
docbook-xsl \
docbook-xml \
xsltproc

- name: Build Capstone (cycle-estimation decoder)
if: steps.valgrind-cache.outputs.cache-hit != 'true' && matrix.valgrind == 'local'
uses: ./.github/actions/build-capstone

- name: Build Valgrind (${{ matrix.valgrind }})
if: steps.valgrind-cache.outputs.cache-hit != 'true'
run: just build ${{ matrix.valgrind }}
Expand Down Expand Up @@ -97,3 +103,4 @@ jobs:
with:
mode: walltime
config: bench/codspeed.yml
runner-version: 4.17.7-alpha.1
13 changes: 9 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ jobs:
- architecture: amd64
platform: ubuntu-22.04
ubuntu-version: 22.04
additional-deps: gcc-multilib libc6-dev-i386
- architecture: amd64
platform: ubuntu-24.04
ubuntu-version: 24.04
additional-deps: gcc-multilib libc6-dev-i386
- architecture: arm64
platform: codspeedhq-arm64-ubuntu-22.04
ubuntu-version: 22.04
Expand All @@ -31,20 +29,27 @@ jobs:
runs-on: ${{ matrix.runner.platform }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Update apt-get cache
run: sudo apt-get update
- name: Install packaging deps
run: sudo apt-get install -y build-essential devscripts debhelper dh-make
- name: Install build deps
run: sudo apt-get install -y debhelper-compat gdb mpi-default-dev pkgconf docbook docbook-xsl docbook-xml xsltproc ${{ matrix.runner.additional-deps }}
run: sudo apt-get install -y debhelper-compat gdb mpi-default-dev pkgconf cmake docbook docbook-xsl docbook-xml xsltproc
- name: Configure GPG Key
run: echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --import
env:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}

# debian/rules forwards $CAPSTONE_DIR to configure via --with-capstone.
- name: Build Capstone (cycle-estimation decoder)
uses: ./.github/actions/build-capstone

- name: Build the deb package
id: build_deb
run: |
debuild --no-tgz-check -nc
debuild -e CAPSTONE_DIR --no-tgz-check -nc
echo "asset-path=$(find .. -name 'valgrind_*.deb')" >> "$GITHUB_OUTPUT"
env:
DEBEMAIL: ${{ vars.MAINTAINER_EMAIL }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2565,3 +2565,6 @@ test-suite.log

# autoconf backup
/configure~

# Capstone build install prefix (built from the third_party/capstone submodule)
/.capstone
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "third_party/capstone"]
path = third_party/capstone
url = https://github.com/capstone-engine/capstone.git
shallow = true
5 changes: 4 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ build-in dir:
./autogen.sh
fi

./configure
# 64-bit only: CodSpeed runs the 64-bit tool, and cycle estimation needs a
# 64-bit Capstone, so the 32-bit secondary build (which has no Capstone) is
# skipped.
./configure --enable-only64bit
make include/vgversion.h
make -j$(nproc) -C VEX
make -j$(nproc) -C coregrind
Expand Down
42 changes: 36 additions & 6 deletions bench/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
"stress-ng --cpu 4 --cpu-ops 10",
]

# Callgrind configurations: (extra args, config name). The config name is the
# last segment of the benchmark id, e.g. `test_valgrind[<version>, <cmd>, no-inline]`.
# Callgrind configurations: (extra args, config name, requires_codspeed). The
# config name is the last segment of the benchmark id, e.g.
# `test_valgrind[<version>, <cmd>, no-inline]`. `requires_codspeed` marks configs
# that rely on CodSpeed-only options (e.g. `--cycle-estimation`); they are skipped
# for upstream Valgrind builds, which would otherwise abort with "Unknown option".
CONFIGS = [
(["--read-inline-info=no"], "no-inline"),
(["--read-inline-info=yes"], "inline"),
(["--read-inline-info=no"], "no-inline", False),
(["--read-inline-info=yes"], "inline", False),
(
[
"--trace-children=yes",
Expand All @@ -45,6 +48,7 @@
"--read-inline-info=yes",
],
"full-with-inline",
False,
),
(
[
Expand All @@ -59,9 +63,31 @@
"--dump-line=no",
],
"full-no-inline",
False,
),
(
[
"--trace-children=yes",
"--cache-sim=yes",
"--I1=32768,8,64",
"--D1=32768,8,64",
"--LL=8388608,16,64",
"--collect-systime=nsec",
"--compress-strings=no",
"--combine-dumps=yes",
"--dump-line=no",
"--read-inline-info=yes",
"--cycle-estimation=yes"
],
"full-with-inline-with-cycle-estimation",
True,
),
(["--cycle-estimation=yes"], "cycle-estimation", True),
]

# Label produced by `valgrind_version` for CodSpeed's custom build.
CODSPEED_VERSION = "valgrind.codspeed"


def valgrind_version(valgrind_path: str) -> str:
"""Return the normalized version label used in benchmark ids.
Expand All @@ -80,7 +106,7 @@ def valgrind_version(valgrind_path: str) -> str:

version = result.stdout.strip()
if "codspeed" in version:
return "valgrind.codspeed"
return CODSPEED_VERSION
return version


Expand All @@ -89,8 +115,12 @@ def build_config(valgrind_paths: list) -> dict:
benchmarks = []
for valgrind_path in valgrind_paths:
version = valgrind_version(valgrind_path)
is_codspeed = version == CODSPEED_VERSION
for cmd in COMMANDS:
for args, config_name in CONFIGS:
for args, config_name, requires_codspeed in CONFIGS:
should_skip = requires_codspeed and not is_codspeed
if should_skip:
continue
name = f"test_valgrind[{version}, {cmd}, {config_name}]"
exec_cmd = " ".join(
[valgrind_path, "--tool=callgrind", "--log-file=/dev/null", *args, cmd]
Expand Down
14 changes: 12 additions & 2 deletions callgrind/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ bin_SCRIPTS = \

noinst_HEADERS = \
costs.h \
cycledecode.h \
cycledecode_capstone.h \
sigkey.h \
events.h \
global.h

# Generated cost tables (#included by cycledecode.c under CLG_WITH_CAPSTONE;
# the arch is selected at compile time).
EXTRA_DIST += x86_caps_lut.inc arm64_caps_lut.inc

#----------------------------------------------------------------------------
# callgrind-<platform>
#----------------------------------------------------------------------------
Expand All @@ -37,6 +44,8 @@ CALLGRIND_SOURCES_COMMON = \
clo.c \
context.c \
costs.c \
cycledecode.c \
cycledecode_capstone.c \
debug.c \
dump.c \
events.c \
Expand All @@ -54,11 +63,12 @@ callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_SOURCES = \
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CPPFLAGS = \
$(AM_CPPFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_CFLAGS = $(LTO_CFLAGS) \
$(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) $(CALLGRIND_CFLAGS_COMMON)
$(AM_CFLAGS_@VGCONF_PLATFORM_PRI_CAPS@) $(CALLGRIND_CFLAGS_COMMON) \
@CAPSTONE_CFLAGS@
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_DEPENDENCIES = \
$(TOOL_DEPENDENCIES_@VGCONF_PLATFORM_PRI_CAPS@)
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDADD = \
$(TOOL_LDADD_@VGCONF_PLATFORM_PRI_CAPS@)
$(TOOL_LDADD_@VGCONF_PLATFORM_PRI_CAPS@) @CAPSTONE_LIBS@
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LDFLAGS = \
$(TOOL_LDFLAGS_@VGCONF_PLATFORM_PRI_CAPS@)
callgrind_@VGCONF_ARCH_PRI@_@VGCONF_OS@_LINK = \
Expand Down
Loading
Loading