Skip to content

Commit

Permalink
Merge pull request #3 from solarwinds/arm64
Browse files Browse the repository at this point in the history
NH-76482 Support for ARM64
  • Loading branch information
jaroslav-fedor-swi authored Oct 17, 2024
2 parents 3df67b0 + f598fb5 commit c66bee2
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 8 deletions.
34 changes: 30 additions & 4 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ on:
default: false

env:
BENV_IMAGE: public.ecr.aws/u7d6c4a3/solarwinds-opentelemetry-network:benv-exp
BENV_IMAGE: public.ecr.aws/u7d6c4a3/solarwinds-opentelemetry-network:buil-env-buildx
DOCKER_REGISTRY: docker.io
DOCKER_NAMESPACE: solarwinds
IMAGE_PREFIX: "opentelemetry-ebpf-"
Expand Down Expand Up @@ -88,6 +88,10 @@ jobs:
echo "full_version_number = ${full_version_number}"
echo "github_tag = ${github_tag}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Fetch build environment
run: |
Expand All @@ -100,6 +104,7 @@ jobs:
--mount "type=bind,source=$GITHUB_WORKSPACE/src,destination=/root/src,readonly" \
--mount "type=bind,source=$GITHUB_WORKSPACE/out,destination=/root/out" \
--env EBPF_NET_SRC_ROOT=/root/src \
--env ENABLE_ARM64_BUILD=TRUE \
$BENV_IMAGE \
./build.sh pipeline-docker
- name: Build packages
Expand All @@ -108,6 +113,7 @@ jobs:
--mount "type=bind,source=$GITHUB_WORKSPACE/src,destination=/root/src,readonly" \
--mount "type=bind,source=$GITHUB_WORKSPACE/out,destination=/root/out" \
--env EBPF_NET_SRC_ROOT=/root/src \
--env ENABLE_ARM64_BUILD=TRUE \
--workdir /root/out \
$BENV_IMAGE \
cpack -G 'RPM;DEB'
Expand Down Expand Up @@ -170,12 +176,32 @@ jobs:
image_name="${IMAGE_PREFIX}${image}"
image_path="${docker_registry}/${DOCKER_NAMESPACE}/${image_name}"
docker tag "${image}" ${image_path}:v${full_version_number}-amd64
docker tag "${image}-arm64" ${image_path}:v${full_version_number}-arm64
if [[ "${{ inputs.dry_run }}" == "false" ]];
then
docker push ${image_path}:v${full_version_number}-arm64
docker push ${image_path}:v${full_version_number}-amd64
else
echo "Would run: docker push ${image_path}:v${full_version_number}-{arm64,amd64}"
fi
for tag in ${tags[@]}; do
docker tag $image ${image_path}:${tag}
manifest_cmd="docker manifest create ${image_path}:${tag}"
manifest_cmd="${manifest_cmd} --amend ${image_path}:v${full_version_number}-arm64"
manifest_cmd="${manifest_cmd} --amend ${image_path}:v${full_version_number}-amd64"
if [[ "${{ inputs.dry_run }}" == "false" ]]; then
docker push ${image_path}:${tag}
eval $manifest_cmd
docker manifest push ${image_path}:${tag}
else
echo "Would run: $manifest_cmd"
echo "Would run: docker manifest push ${image_path}:${tag}"
fi
done
done
docker images --no-trunc
docker images --no-trunc
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:

env:
BENV_IMAGE: public.ecr.aws/u7d6c4a3/solarwinds-opentelemetry-network:benv-exp
BENV_IMAGE: public.ecr.aws/u7d6c4a3/solarwinds-opentelemetry-network:buil-env-buildx

concurrency:
group: build-and-test-${{ github.event.pull_request_number || github.ref }}
Expand Down
22 changes: 21 additions & 1 deletion cmake/docker-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,37 @@ function(build_custom_docker_image IMAGE_NAME)
)
endforeach()

# Get the value of the environment variable ENABLE_ARM64_BUILD
if (DEFINED ENV{ENABLE_ARM64_BUILD} AND "$ENV{ENABLE_ARM64_BUILD}" STREQUAL "TRUE")
set(ENABLE_ARM64_BUILD TRUE)
else()
set(ENABLE_ARM64_BUILD FALSE)
endif()


if (RUN_DOCKER_COMMANDS)
add_custom_command(
TARGET
"${IMAGE_NAME}-docker"
WORKING_DIRECTORY
"${out_path}"
COMMAND
docker build -t "${IMAGE_NAME}" ${DOCKER_ARGS} .
docker buildx build --platform linux/amd64 -t "${IMAGE_NAME}" ${DOCKER_ARGS} .
)
if (ENABLE_ARM64_BUILD)
add_custom_command(
TARGET
"${IMAGE_NAME}-docker"
WORKING_DIRECTORY
"${out_path}"
COMMAND
docker buildx build --platform linux/arm64 -t "${IMAGE_NAME}-arm64" ${DOCKER_ARGS} .
)
endif()
endif()



###########################
# push to docker registry #
###########################
Expand Down
8 changes: 8 additions & 0 deletions platform/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,17 @@ typedef FILE fp_outfile;
/* compiler-gcc.h */
#ifdef __GNUC__
#define barrier() __asm__ __volatile__("" : : : "memory")

#ifdef __aarch64__
#define mb() asm volatile("dmb ish" : : : "memory")
#define rmb() asm volatile("dmb ishld" : : : "memory")
#define wmb() asm volatile("dmb ishst" : : : "memory")
#else
#define mb() asm volatile("mfence" : : : "memory")
#define rmb() asm volatile("lfence" : : : "memory")
#define wmb() asm volatile("sfence" : : : "memory")
#endif

#define read_barrier_depends() \
do { \
} while (0)
Expand Down
14 changes: 12 additions & 2 deletions platform/userspace-time.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,21 @@ static inline __attribute__((always_inline)) u64 monotonic()
return (u64)ts.tv_sec * (1000 * 1000 * 1000) + ts.tv_nsec;
}

// For ARM64
#ifdef __aarch64__
static inline __attribute__((always_inline)) uint64_t fp_monotonic_time_ns(void) {
uint64_t cntvct;
asm volatile("mrs %0, cntvct_el0" : "=r" (cntvct));
return cntvct;
}

// For x86
#else
#include <x86intrin.h>
static inline __attribute__((always_inline)) u64 fp_monotonic_time_ns(void)
{
static inline __attribute__((always_inline)) uint64_t fp_monotonic_time_ns(void) {
return __rdtsc();
}
#endif

#ifdef __cplusplus
}
Expand Down
10 changes: 10 additions & 0 deletions util/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ struct monotonic_clock {
}
};

#ifndef __aarch64__
#include <x86intrin.h>
#endif
/**
* Monotonic, std::chrono compatible clock using `__rdtsc()` as the backend.
*/
Expand All @@ -159,5 +161,13 @@ struct rdtsc_clock {
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<monotonic_clock>;

#ifdef __aarch64__
static inline __attribute__((always_inline)) time_point now() {
uint64_t cntvct;
asm volatile ("mrs %0, cntvct_el0; " : "=r"(cntvct) :: "memory");
return time_point{duration{cntvct}};
}
#else
static inline __attribute__((always_inline)) time_point now() { return time_point{duration{__rdtsc()}}; }
#endif
};

0 comments on commit c66bee2

Please sign in to comment.