diff --git a/.gitignore b/.gitignore index 47f23e00..655b3fcd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ /tools/bin /dist /internal/script/resources/x86_64 -/test -/__debug_bin*.log \ No newline at end of file +/internal/script/resources/arm64 +//test +/__debug_bin*.log diff --git a/Makefile b/Makefile index 1496972b..c2341597 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,24 @@ 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" +ARCH := $(shell uname -m) + +# Check for x86_64 (common for amd64) +ifeq ($(ARCH), x86_64) + ARCH := amd64 + TOOLS_ARCH := x86_64 +endif + +ifeq ($(ARCH), aarch64) + ARCH := arm64 +endif + +ifeq ($(ARCH), amd64) + GOFLAGS_EXTRA := -gcflags="all=-spectre=all -N -l" -asmflags="all=-spectre=all" +endif + +GO=CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go +GOFLAGS=-trimpath -mod=readonly $(GOFLAGS_EXTRA) -ldflags="-X perfspect/cmd.gVersion=$(VERSION) -s -w" # Build the perfspect binary .PHONY: perfspect @@ -23,12 +39,12 @@ perfspect: # Copy prebuilt tools to script resources .PHONY: resources resources: - mkdir -p internal/script/resources/x86_64 + mkdir -p internal/script/resources/$(TOOLS_ARCH) 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/* internal/script/resources/$(TOOLS_ARCH) 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/* internal/script/resources/$(TOOLS_ARCH) else # no prebuilt tools found @echo "No prebuilt tools found in /prebuilt/tools or tools/bin" endif @@ -39,7 +55,7 @@ endif .PHONY: dist dist: resources check perfspect rm -rf dist/perfspect - mkdir -p dist/perfspect/tools/x86_64 + mkdir -p dist/perfspect/tools/$(TOOLS_ARCH) cp LICENSE dist/perfspect/ cp THIRD_PARTY_PROGRAMS dist/perfspect/ cp NOTICE dist/perfspect/ @@ -149,4 +165,4 @@ clean: sweep @echo "Cleaning up..." rm -f perfspect sudo rm -rf dist - rm -rf internal/script/resources/x86_64/* + rm -rf internal/script/resources/$(TOOLS_ARCH)/* diff --git a/tools/Makefile b/tools/Makefile index 3a392fa9..07b3e76d 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,17 +1,31 @@ + #!make # # Copyright (C) 2021-2025 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause # +ARCH := $(shell uname -m) + +# Check for x86_64 (common for amd64) +ifeq ($(ARCH), x86_64) + ARCH := amd64 + ARCH_SPECIFIC_TOOLS := avx-turbo cpuid msr-tools pcm turbostat + ASYNC_PROFILER_ARCH := x64 +endif + +ifeq ($(ARCH), aarch64) + ARCH := arm64 + ARCH_SPECIFIC_TOOLS := + ASYNC_PROFILER_ARCH := arm64 +endif + default: tools .PHONY: default tools async-profiler avx-turbo cpuid dmidecode ethtool fio ipmitool lshw lspci msr-tools pcm perf processwatch spectre-meltdown-checker sshpass stackcollapse-perf stress-ng sysstat tsc turbostat -tools: async-profiler avx-turbo cpuid dmidecode ethtool fio ipmitool lshw lspci msr-tools pcm spectre-meltdown-checker sshpass stackcollapse-perf stress-ng sysstat tsc turbostat +tools: async-profiler dmidecode ethtool fio ipmitool lshw lspci spectre-meltdown-checker sshpass stackcollapse-perf stress-ng sysstat tsc $(ARCH_SPECIFIC_TOOLS) mkdir -p bin cp -R async-profiler bin/ - cp avx-turbo/avx-turbo bin/ - cp cpuid/cpuid bin/ cp dmidecode/dmidecode bin/ cp ethtool/ethtool bin/ cp fio/fio bin/ @@ -20,10 +34,6 @@ tools: async-profiler avx-turbo cpuid dmidecode ethtool fio ipmitool lshw lspci cp lshw/src/lshw-static bin/lshw cp lspci/lspci bin/ cp lspci/pci.ids.gz bin/ - cp msr-tools/rdmsr bin/ - cp msr-tools/wrmsr bin/ - cp pcm/build/bin/pcm-tpmi bin/ - cp pcm/scripts/bhs-power-mode.sh bin/ cp spectre-meltdown-checker/spectre-meltdown-checker.sh bin/ cp sshpass/sshpass bin/ cp stress-ng/stress-ng bin/ @@ -32,16 +42,24 @@ tools: async-profiler avx-turbo cpuid dmidecode ethtool fio ipmitool lshw lspci cp sysstat/sar bin/ cp sysstat/sadc bin/ cp tsc/tsc bin/ +ifeq ($(ARCH),amd64) + cp avx-turbo/avx-turbo bin/ + cp cpuid/cpuid bin/ + cp msr-tools/rdmsr bin/ + cp msr-tools/wrmsr bin/ + cp pcm/build/bin/pcm-tpmi bin/ + cp pcm/scripts/bhs-power-mode.sh bin/ cp linux_turbostat/tools/power/x86/turbostat/turbostat bin/ +endif -cd bin && strip --strip-unneeded * ASYNC_PROFILER_VERSION := "4.0" async-profiler: ifeq ("$(wildcard async-profiler)","") -ifeq ("$(wildcard async-profiler-$(ASYNC_PROFILER_VERSION)-linux-x64.tar.gz)","") - wget https://github.com/jvm-profiling-tools/async-profiler/releases/download/v$(ASYNC_PROFILER_VERSION)/async-profiler-$(ASYNC_PROFILER_VERSION)-linux-x64.tar.gz +ifeq ("$(wildcard async-profiler-$(ASYNC_PROFILER_VERSION)-linux-$(ASYNC_PROFILER_ARCH).tar.gz)","") + wget https://github.com/jvm-profiling-tools/async-profiler/releases/download/v$(ASYNC_PROFILER_VERSION)/async-profiler-$(ASYNC_PROFILER_VERSION)-linux-$(ASYNC_PROFILER_ARCH).tar.gz endif - tar -xf async-profiler-$(ASYNC_PROFILER_VERSION)-linux-x64.tar.gz && mv async-profiler-$(ASYNC_PROFILER_VERSION)-linux-x64 async-profiler + tar -xf async-profiler-$(ASYNC_PROFILER_VERSION)-linux-$(ASYNC_PROFILER_ARCH).tar.gz && mv async-profiler-$(ASYNC_PROFILER_VERSION)-linux-$(ASYNC_PROFILER_ARCH) async-profiler endif AVX_TURBO_VERSION := "threadcpuid" @@ -161,7 +179,7 @@ endif cd pcm/build && cmake -DNO_ASAN=1 .. cd pcm/build && cmake --build . -PERF_VERSION := "6.8.12" +PERF_VERSION := "6.15" perf: wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$(PERF_VERSION).tar.xz tar -xf linux-$(PERF_VERSION).tar.xz && mv linux-$(PERF_VERSION)/ linux_perf/ @@ -206,7 +224,7 @@ endif cd sshpass && make stackcollapse-perf: - cd stackcollapse-perf && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build + cd stackcollapse-perf && CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build STRESS_NG_VERSION := "V0.13.08" stress-ng: @@ -216,7 +234,7 @@ else cd stress-ng && git checkout master && git pull endif cd stress-ng && git checkout $(STRESS_NG_VERSION) - cd stress-ng && STATIC=1 make + cd stress-ng && STATIC=1 make -j$(nproc) SYSSTAT_VERSION := "v12.7.6" sysstat: @@ -232,7 +250,7 @@ endif cd sysstat && make tsc: - cd tsc && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build + cd tsc && CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build TURBOSTAT_VERSION := "6.9.12" turbostat: @@ -243,21 +261,23 @@ turbostat: reset: cd async-profiler - cd cpuid && make clean cd dmidecode && git clean -fdx && git reset --hard cd ethtool && git clean -fdx && git reset --hard cd fio && git clean -fdx && git reset --hard cd ipmitool && git clean -fdx && git reset --hard cd lshw && git clean -fdx && git reset --hard cd lspci && git clean -fdx && git reset --hard - cd pcm && git clean -fdx && git reset --hard - cd msr-tools && git clean -fdx && git reset --hard cd spectre-meltdown-checker cd sshpass && make clean cd stress-ng && git clean -fdx && git reset --hard cd sysstat && git clean -fdx && git reset --hard cd tsc && rm -f tsc +ifeq ($(GOARCH),amd64) + cd cpuid && make clean + cd pcm && git clean -fdx && git reset --hard + cd msr-tools && git clean -fdx && git reset --hard cd linux_turbostat/tools/power/x86/turbostat && make clean +endif # not used in build but required in oss archive file because some of the tools are statically linked glibc-2.19.tar.bz2: @@ -268,6 +288,10 @@ libcrypt.tar.gz: wget https://github.com/gpg/libgcrypt/archive/refs/heads/master.tar.gz -O libcrypt.tar.gz libs: glibc-2.19.tar.bz2 zlib.tar.gz libcrypt.tar.gz +OSS_SOURCE_FILES := async-profiler/ dmidecode/ ethtool/ fio/ ipmitool/ lshw/ lspci/ spectre-meltdown-checker/ sshpass/ stress-ng/ sysstat/ tsc/ glibc-2.19.tar.bz2 zlib.tar.gz libcrypt.tar.gz +ifeq ($(ARCH),amd64) + OSS_SOURCE_FILES += cpuid/ msr-tools/ pcm/ linux_turbostat/tools/power/x86/turbostat +endif oss-source: reset libs - tar --exclude-vcs -czf oss_source.tgz async-profiler/ cpuid/ dmidecode/ ethtool/ fio/ ipmitool/ lshw/ lspci/ msr-tools/ pcm/ spectre-meltdown-checker/ sshpass/ stress-ng/ sysstat/ linux_turbostat/tools/power/x86/turbostat glibc-2.19.tar.bz2 zlib.tar.gz libcrypt.tar.gz + tar --exclude-vcs -czf oss_source.tgz $(OSS_SOURCE_FILES) md5sum oss_source.tgz > oss_source.tgz.md5 diff --git a/tools/build.Dockerfile b/tools/build.Dockerfile index c25c1940..bfe45749 100644 --- a/tools/build.Dockerfile +++ b/tools/build.Dockerfile @@ -28,18 +28,27 @@ RUN for i in {1..5}; do \ libreadline-dev default-jre default-jdk cmake flex bison libssl-dev && break; \ echo "Retrying in 5 seconds... ($i/5)" && sleep 5; \ done -ENV JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 -# need golang to build go tools -RUN rm -rf /usr/local/go && wget -qO- https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz | tar -C /usr/local -xz -ENV PATH="${PATH}:/usr/local/go/bin" -# need up-to-date zlib (used by stress-ng static build) to fix security vulnerabilities -RUN git clone https://github.com/madler/zlib.git && cd zlib && ./configure && make install -RUN cp /usr/local/lib/libz.a /usr/lib/x86_64-linux-gnu/libz.a -# Build third-party components + + RUN mkdir workdir ADD . /workdir -WORKDIR /workdir -RUN make tools && make oss-source + +RUN ARCH=$(uname -m); \ +if [ "$ARCH" = "x86_64" ]; then \ + PKG_ARCH="amd64"; \ +elif [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then \ + PKG_ARCH="arm64"; \ +fi; \ +echo PKG_ARCH=$PKG_ARCH; \ +JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-${PKG_ARCH}" ; export JAVA_HOME; \ +rm -rf /usr/local/go && wget -qO- https://go.dev/dl/go${GO_VERSION}.linux-${PKG_ARCH}.tar.gz | tar -C /usr/local -xz && \ +PATH="${PATH}:/usr/local/go/bin" && \ +git clone https://github.com/madler/zlib.git && cd zlib && ./configure && make install && \ +cp /usr/local/lib/libz.a /usr/lib/${ARCH}-linux-gnu/libz.a && \ +cd /workdir && \ +make tools && make oss-source + +ENV PATH="${PATH}:/usr/local/go/bin" FROM ubuntu:22.04 AS perf-builder # Define default values for proxy environment variables