Skip to content

cross-compile for ARM #365

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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
42 changes: 38 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ jobs:
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: perfspect
path: dist/perfspect*.tgz
- name: upload md5
path: dist/perfspect.tgz
- name: upload perfspect md5
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: md5
path: dist/perfspect*.md5.txt
path: dist/perfspect.tgz.md5.txt
- name: upload perfspect aarch64
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: perfspect-aarch64
path: dist/perfspect-aarch64.tgz
- name: upload perfspect md5 aarch64
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: md5-aarch64
path: dist/perfspect-aarch64.tgz.md5.txt
- name: upload manifest
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
Expand All @@ -51,7 +61,7 @@ jobs:
name: perfspect
- name: run test
run: |
tar -xf perfspect*
tar -xf perfspect.tgz
cp .github/mock_mlc perfspect/tools/x86_64/
cd perfspect
mkdir output
Expand All @@ -63,3 +73,27 @@ jobs:
with:
name: ${{ matrix.runner }} report
path: perfspect/output/

test_aarch64:
needs: [build]
runs-on: ubuntu-24.04-arm
steps:
- name: checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: download perspect
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: perfspect-aarch64
- name: run test
run: |
tar -xf perfspect-aarch64.tgz
cd perfspect
mkdir output
./perfspect report --output output
cp -f perfspect.log output/
- name: upload report
if: ${{ always() }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: ${{ matrix.runner }} report aarch64
path: perfspect/output/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/perfspect
/perfspect-aarch64
/perfspect.log
/perfspect_202*
/debug_out
/tools/bin
/dist
/internal/script/resources/x86_64
/internal/script/resources/aarch64
/test
/__debug_bin*.log
35 changes: 24 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,54 @@ VERSION := $(VERSION_NUMBER)_$(COMMIT_DATE)_$(COMMIT_ID)

default: perfspect

GO=CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go
GOFLAGS=-trimpath -mod=readonly -gcflags="all=-spectre=all -N -l" -asmflags="all=-spectre=all" -ldflags="-X perfspect/cmd.gVersion=$(VERSION) -s -w"
GOFLAGS_COMMON=-trimpath -mod=readonly -ldflags="-X perfspect/cmd.gVersion=$(VERSION) -s -w"

# Build the perfspect binary
# Build the perfspect binary for x86_64
.PHONY: perfspect
perfspect:
$(GO) build $(GOFLAGS) -o $@
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GOFLAGS_COMMON) -gcflags="all=-spectre=all -N -l" -asmflags="all=-spectre=all" -o $@

# Build the perfspect binary for AARCH64
.PHONY: perfspect-aarch64
perfspect-aarch64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(GOFLAGS_COMMON) -o $@

# Copy prebuilt tools to script resources
.PHONY: resources
resources:
mkdir -p internal/script/resources/x86_64
mkdir -p internal/script/resources/aarch64
ifneq ("$(wildcard /prebuilt/tools)","") # /prebuilt/tools is a directory in the container
cp -r /prebuilt/tools/* internal/script/resources/x86_64
cp -r /prebuilt/tools/x86_64/* internal/script/resources/x86_64
cp -r /prebuilt/tools/aarch64/* internal/script/resources/aarch64
else # copy dev system tools to script resources
ifneq ("$(wildcard tools/bin)","")
cp -r tools/bin/* internal/script/resources/x86_64
cp -r tools/bin/x86_64/* internal/script/resources/x86_64
cp -r tools/bin/aarch64/* internal/script/resources/aarch64
else # no prebuilt tools found
@echo "No prebuilt tools found in /prebuilt/tools or tools/bin"
endif
endif


# Build the distribution package
# Build the distribution packages
.PHONY: dist
dist: resources check perfspect
rm -rf dist/perfspect
dist: resources check perfspect perfspect-aarch64
# common across architectures
rm -rf dist
mkdir -p dist/perfspect/tools/x86_64
mkdir -p dist/perfspect/tools/aarch64
cp LICENSE dist/perfspect/
cp THIRD_PARTY_PROGRAMS dist/perfspect/
cp NOTICE dist/perfspect/
cp targets.yaml dist/perfspect/
cp perfspect dist/perfspect/
# x86_64 specific
cp perfspect dist/perfspect/perfspect
cd dist && tar -czf perfspect.tgz perfspect
cd dist && md5sum perfspect.tgz > perfspect.tgz.md5.txt
# aarch64 specific, overwrite the binary
cp perfspect-aarch64 dist/perfspect/perfspect
cd dist && tar -czf perfspect-aarch64.tgz perfspect
cd dist && md5sum perfspect-aarch64.tgz > perfspect-aarch64.tgz.md5.txt
rm -rf dist/perfspect
echo '{"version": "$(VERSION_NUMBER)", "date": "$(COMMIT_DATE)", "time": "$(COMMIT_TIME)", "commit": "$(COMMIT_ID)" }' | jq '.' > dist/manifest.json
ifneq ("$(wildcard /prebuilt)","") # /prebuilt is a directory in the container
Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ perf:
cd linux_perf/tools/perf && make LDFLAGS="-static --static" BUILD_BPF_SKEL=1 NO_JVMTI=1
mkdir -p bin
cp linux_perf/tools/perf/perf bin/
strip --strip-unneeded bin/perf
-strip --strip-unneeded bin/perf || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For aarch64, you can use aarch64-linux-gnu-strip

cp linux_perf/tools/perf/perf-archive.sh bin/perf-archive
chmod +x bin/perf-archive

Expand Down
27 changes: 24 additions & 3 deletions tools/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,28 @@ WORKDIR /workdir
RUN make perf
RUN make processwatch

# --- aarch64 perf build stage ---
FROM ubuntu:22.04 AS perf-builder-arm64
ARG http_proxy=""
ARG https_proxy=""
ENV http_proxy=${http_proxy}
ENV https_proxy=${https_proxy}
ENV LANG=en_US.UTF-8
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y apt-utils locales wget curl git netcat-openbsd \
software-properties-common jq zip unzip gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
make pkgconf flex bison libssl-dev libelf-dev libdw-dev libiberty-dev libzstd-dev \
python3 python3-dev libtraceevent-dev
RUN locale-gen en_US.UTF-8 && echo "LANG=en_US.UTF-8" > /etc/default/locale
RUN mkdir workdir
ADD . /workdir
WORKDIR /workdir
# Build perf for aarch64
RUN make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- NO_LIBELF=1 NO_LIBTRACEEVENT=1 perf

FROM scratch AS output
COPY --from=builder workdir/bin /bin
COPY --from=builder workdir/oss_source* /
COPY --from=perf-builder workdir/bin/ /bin
COPY --from=builder workdir/oss_source.tgz /
COPY --from=builder workdir/oss_source.tgz.md5 /
COPY --from=builder workdir/bin /bin/x86_64
COPY --from=perf-builder workdir/bin /bin/x86_64
COPY --from=perf-builder-arm64 workdir/bin /bin/aarch64