Skip to content

Add native support for ARM builds - #59

Merged
Xenofon Foukas (xfoukas) merged 49 commits into
microsoft:devfrom
anita-tenjarla:anita/add-arm-support
May 30, 2025
Merged

Xenofon Foukas (xfoukas) merged 49 commits into
microsoft:devfrom
anita-tenjarla:anita/add-arm-support

Conversation

@anita-tenjarla

Copy link
Copy Markdown
Contributor
  • Update Dockerfiles to conditionally install gcc-multilib, which is not available on ARM
  • Update examples Makefiles to include {platform}-linux-gnu
  • Update approved libraries for ARM .so
  • Call jbpf_measure_{start|end}_time which only conditionally executes x86 asm based on detected platform
  • Remove sudo from run_app.sh since we're already running as root in container

closes #58

* Update Dockerfiles to conditionally install gcc-multilib, which is not available on ARM
* Update examples Makefiles to include {platform}-linux-gnu
* Update approved libraries for ARM so
* Call jbpf_measure_{start|end}_time which only conditionally executes x86 asm based on detected platform
@anita-tenjarla

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree [company="Cloudflare"]

@anita-tenjarla

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Cloudflare"

@xfoukas Xenofon Foukas (xfoukas) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Anita Tenjarla (@anita-tenjarla), thanks again for creating this PR. This is really helpful¬

I went over it and I have a few comments:

  • [Issue with atomics]: The ARM version of ubpf (used for running the userspace eBPF code) does not support atomic operations. As such, two of the tests fail when building for ARM (concurrency/atomic_concurrency_test and concurrency/codelet_control_input_concurrency_atomic_test). Given that this is not a jbpf limitation, but rather a ubpf limitation, I think we should give out a warning for users compiling on ARM, that atomics are not supported and we should disable those tests when running for arm builds. A clean way to do this would be to modify the cmake file to check the arch (e.g., with CMAKE_SYSTEM_PROCESSOR() calls) and emit the warning and disable the tests, if the arch is aarch64.
  • [asm timers]: The reason for relying on asm code for getting the time instead of clock_gettime() is to avoid making OS calls that can lead to context switches. This is critical for some real-time use cases that we need to support. As such, I would propose a different way of fixing the timer issue. We could extend the implementation of jbpf_start_time() and jbpf_end_time() in jbpf_utils.h with an aarch64 based asm implementation of counting time to match the x86 one (using the cntvct_el0 and cntfrq_el0 registers). This way, we don't need to make any modifications to jbpf_perf.c and we avoid introducing unwanted OS calls.
  • The README.md file should be updated with a new section Supported architectures which explains that both x86_64 and aarch64 are supported, stating the limitations of the aarch64 version in terms of the atomics operation.

We are also working on adding aarch64 VMs in our pipelines so that we can test against ARM once this PR is merged.

@@ -1,3 +1,3 @@
#!/bin/sh

sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JBPF_PATH/out/lib ./example_app

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is used when running without docker containers, so it should not be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed the sudo call here because the other instances of run_app.sh (in first_example_standalone_json_udp and first_example_ipc folders) don't invoke root. I don't really mind either way, but just noting that in Docker (which already runs as root) running the script as-is will return an error.

@anita-tenjarla

Copy link
Copy Markdown
Contributor Author

Anita Tenjarla (@anita-tenjarla), thanks again for creating this PR. This is really helpful¬

I went over it and I have a few comments:

  • [Issue with atomics]: The ARM version of ubpf (used for running the userspace eBPF code) does not support atomic operations. As such, two of the tests fail when building for ARM (concurrency/atomic_concurrency_test and concurrency/codelet_control_input_concurrency_atomic_test). Given that this is not a jbpf limitation, but rather a ubpf limitation, I think we should give out a warning for users compiling on ARM, that atomics are not supported and we should disable those tests when running for arm builds. A clean way to do this would be to modify the cmake file to check the arch (e.g., with CMAKE_SYSTEM_PROCESSOR() calls) and emit the warning and disable the tests, if the arch is aarch64.
  • [asm timers]: The reason for relying on asm code for getting the time instead of clock_gettime() is to avoid making OS calls that can lead to context switches. This is critical for some real-time use cases that we need to support. As such, I would propose a different way of fixing the timer issue. We could extend the implementation of jbpf_start_time() and jbpf_end_time() in jbpf_utils.h with an aarch64 based asm implementation of counting time to match the x86 one (using the cntvct_el0 and cntfrq_el0 registers). This way, we don't need to make any modifications to jbpf_perf.c and we avoid introducing unwanted OS calls.
  • The README.md file should be updated with a new section Supported architectures which explains that both x86_64 and aarch64 are supported, stating the limitations of the aarch64 version in terms of the atomics operation.

We are also working on adding aarch64 VMs in our pipelines so that we can test against ARM once this PR is merged.

Thank you for the quick review! I'm happy to add a commit and make the requested changes outlined in "issue with atomics" and "readme", but I don't feel equipped to make the changes in "asm timers." I'm not familiar with writing and testing asm. Is that something you might be able to help me out with?

* Add section to README about supported architectures
* Exclude atomic tests on aarch64 and emit log about skipped tests. Test will fail because ubpf does not support atomics for aarch64.
@xfoukas

Copy link
Copy Markdown
Collaborator

Anita Tenjarla (@anita-tenjarla), thanks again for creating this PR. This is really helpful¬
I went over it and I have a few comments:

  • [Issue with atomics]: The ARM version of ubpf (used for running the userspace eBPF code) does not support atomic operations. As such, two of the tests fail when building for ARM (concurrency/atomic_concurrency_test and concurrency/codelet_control_input_concurrency_atomic_test). Given that this is not a jbpf limitation, but rather a ubpf limitation, I think we should give out a warning for users compiling on ARM, that atomics are not supported and we should disable those tests when running for arm builds. A clean way to do this would be to modify the cmake file to check the arch (e.g., with CMAKE_SYSTEM_PROCESSOR() calls) and emit the warning and disable the tests, if the arch is aarch64.
  • [asm timers]: The reason for relying on asm code for getting the time instead of clock_gettime() is to avoid making OS calls that can lead to context switches. This is critical for some real-time use cases that we need to support. As such, I would propose a different way of fixing the timer issue. We could extend the implementation of jbpf_start_time() and jbpf_end_time() in jbpf_utils.h with an aarch64 based asm implementation of counting time to match the x86 one (using the cntvct_el0 and cntfrq_el0 registers). This way, we don't need to make any modifications to jbpf_perf.c and we avoid introducing unwanted OS calls.
  • The README.md file should be updated with a new section Supported architectures which explains that both x86_64 and aarch64 are supported, stating the limitations of the aarch64 version in terms of the atomics operation.

We are also working on adding aarch64 VMs in our pipelines so that we can test against ARM once this PR is merged.

Thank you for the quick review! I'm happy to add a commit and make the requested changes outlined in "issue with atomics" and "readme", but I don't feel equipped to make the changes in "asm timers." I'm not familiar with writing and testing asm. Is that something you might be able to help me out with?

Certainly, I can take over the pending task regarding the ARM timers and complete the PR.

@anita-tenjarla

Copy link
Copy Markdown
Contributor Author

Thank you! Please let me know if there's anything you'd like me to add or test in the meantime.

@xfoukas

Copy link
Copy Markdown
Collaborator

Thanks for updating the PR! I am currently working on adding the code for the timers and should have something pushed soon.

@xfoukas Xenofon Foukas (xfoukas) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Anita Tenjarla (@anita-tenjarla) I have pushed some changes to the PR as discussed, for measuring the time. What remains now is to test everything. We are currently working on adding new arm pipelines for this purpose.

In the meantime, can you please point your PR to dev instead of main, according to the latest contribution guidelines found here. Thanks!

@anita-tenjarla

Copy link
Copy Markdown
Contributor Author

Hey, not sure if this is the right place to bring this up. I originally raised this issue when I was building the jbpf shared object file on ARM. Since then, I've also been building jbpf on ARM as a static library, but I got the following error:

  = note: /usr/bin/ld: /jbpf/out/lib/libjbpf.a(jbpf_io_ipc.c.o): in function `dipc_ctrl_thread':
          jbpf_io_ipc.c:(.text+0x6b98): undefined reference to `__aarch64_swp1_sync'
__aarch64_swp1_sync

I had to add the following to the CMakeLists.txt in order to compile:

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
add_compile_options(-mno-outline-atomics)
endif()

Should I add a commit here with that change? Or would you prefer I open a separate issue or PR?

@xfoukas

Copy link
Copy Markdown
Collaborator

Anita Tenjarla (@anita-tenjarla), please add the change in this PR. Thanks!

@anita-tenjarla

Copy link
Copy Markdown
Contributor Author

Just updated, thanks!

Add memory barriers to aarch64 code for measuring time, to avoid scenarios where the start and the end time and up being the same.
Fix formatting issues.
Install yaml-cpp-dev from the Ubuntu repo.

@xfoukas Xenofon Foukas (xfoukas) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I made some small changes to fix a time measurement related bug and to clean up some issues related to the installation of packages to the containers.

The PR looks good to me. Thank you for your contribution!

@xfoukas
Xenofon Foukas (xfoukas) enabled auto-merge (squash) May 30, 2025 00:15
@xfoukas
Xenofon Foukas (xfoukas) merged commit 8f2971e into microsoft:dev May 30, 2025
Xenofon Foukas (xfoukas) added a commit that referenced this pull request Jun 2, 2025
* Add branch instructions in CONTRIBUTING.md and Update ADO pipeline triggers (#78)

* Add Github Action Pipeline and Fixed INITIALIZE_SUBMODULES (#64)

* Add Debug build configuration testing to CI pipeline (#57)

---------

Co-authored-by: Zhihua Lai <[email protected]>
Co-authored-by: Xenofon Foukas <[email protected]>

* Add helper function for fixed points (#71) (#85)

Co-authored-by: Zhihua Lai <[email protected]>

* Fixes for tests to pass when cmake build type is Release (#86)

This fixes issue #79. When the cmake build type is not defined it defaults to Release.
Given that the tests rely on assert() to pass, the PR also undefs NDEBUG in the release build flags to prevent the optimizer from removing the assert() calls.

* Improve Validation Error Messages in Linked Map (#82)

* Matt/dev: MAX_NUM_HOOKS to 128 (#91)

* Add helper function for fixed points (#71)

* Increase MAX_NUM_HOOKS from 64 to 128 (#90)

---------

Co-authored-by: Zhihua Lai <[email protected]>

* Refactor run_lcm_subproc by removing memory allocation with new/delete. (#93)

* Fix build/package error in ubuntu22.04 (#96)

* Add native support for ARM builds (#59)

---------

Co-authored-by: Zhihua Lai <[email protected]>
Co-authored-by: Xenofon Foukas <[email protected]>
Co-authored-by: Connor Settle <[email protected]>
Co-authored-by: Zhihua Lai <[email protected]>

* Bugfix: perf time measurement API with invalid times (#102)

* Bump ubpf to the latest version (#103)

* Matt/issue94 (#95)

* Remove ado correctness + move to cloud agents (#100)

* Sync dev with main (#105)

* Add helper function for fixed points (#71)

* Increase MAX_NUM_HOOKS from 64 to 128 (#90)


---------

Co-authored-by: Zhihua Lai <[email protected]>
Co-authored-by: matthewbalkwill <[email protected]>

---------

Co-authored-by: Zhihua Lai <[email protected]>
Co-authored-by: Xiaochuan Ye <[email protected]>
Co-authored-by: matthewbalkwill <[email protected]>
Co-authored-by: Anita Tenjarla <[email protected]>
Co-authored-by: Zhihua Lai <[email protected]>
Co-authored-by: Connor Settle <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jbpf does not build out of the box for ARM machines (Mac M1/M2 chips)

3 participants