Skip to content
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

ARM support for BESS #1041

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/sse2neon"]
path = deps/sse2neon
url = https://github.com/DLTcollab/sse2neon
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ Please add your name to the end of this file and include this file to the PR, un
* Brent Stephens
* M. Asim Jamshed
* Yan Grunenberger
* Md Ashfaqur Rahaman
18 changes: 13 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import subprocess
import textwrap
import argparse
import platform


def cmd(cmd, quiet=False, shell=False):
Expand Down Expand Up @@ -90,7 +91,14 @@ def cmd(cmd, quiet=False, shell=False):

DPDK_URL = 'https://fast.dpdk.org/rel'
DPDK_VER = 'dpdk-19.11.4'
DPDK_TARGET = 'x86_64-native-linuxapp-gcc'

if platform.uname().machine == 'x86_64':
DPDK_TARGET = 'x86_64-native-linuxapp-gcc'
elif platform.uname().machine == 'aarch64':
DPDK_TARGET = 'arm64-armv8a-linux-gcc'
else:
print("Unsupported platform")
sys.exit(1)

kernel_release = cmd('uname -r', quiet=True).strip()

Expand Down Expand Up @@ -299,10 +307,10 @@ def configure_dpdk():
check_mlx()
generate_dpdk_extra_mk()

arch = os.getenv('CPU')
if arch:
print(' - Building DPDK with -march=%s' % arch)
set_config(DPDK_CONFIG, "CONFIG_RTE_MACHINE", arch)
arch = platform.uname().machine
if arch == 'aarch64':
print(' - Building DPDK with -march=%s' % 'armv8-a')
set_config(DPDK_CONFIG, "CONFIG_RTE_MACHINE", 'armv8-a')


def makeflags():
Expand Down
28 changes: 26 additions & 2 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,18 @@ ifeq "$(CXXCOMPILER)" "g++"
endif

HAS_PKG_CONFIG := $(shell command -v $(PKG_CONFIG) 2>&1 >/dev/null && echo yes || echo no)
ARCH := $(shell uname -m)

RTE_SDK ?= $(abspath ../deps/dpdk-19.11.4)
RTE_TARGET ?= $(shell uname -m)-native-linuxapp-gcc

ifeq ($(ARCH),x86_64)
RTE_TARGET ?= $(shell uname -m)-native-linuxapp-gcc
else ifeq ($(ARCH),aarch64)
RTE_TARGET ?= arm64-armv8a-linux-gcc
else
$(error Unsupported architecture)
endif

DPDK_LIB ?= dpdk

ifneq ($(wildcard $(RTE_SDK)/$(RTE_TARGET)/*),)
Expand All @@ -76,6 +85,10 @@ else ifneq ($(MAKECMDGOALS),clean)
$(error DPDK is not available. Make sure $(abspath $(RTE_SDK)) is available and built)
endif

# Library for translating Intel SSE intrinsics
# to ARM64 NEON
SSE2NEON_DIR ?= $(abspath ../deps/sse2neon)

# We always want these libraries to be dynamically linked even when the
# user requests a static build.
ALWAYS_DYN_LIBS := -lpthread -ldl
Expand Down Expand Up @@ -108,9 +121,16 @@ endif
# these headers. Should fix the warnings. Using -isystem also disables
# -MMD dependency recording (should we use -MD?).
COREDIR := $(abspath .)
CPU ?= native
ifeq ($(ARCH),x86_64)
CPU ?= native
else ifeq ($(ARCH),aarch64)
CPU ?= armv8-a+fp+simd
else
$(error Unsupported architecture)
endif
CXXFLAGS += -std=c++17 -g3 -ggdb3 -march=$(CPU) \
-isystem $(DPDK_INC_DIR) -isystem $(COREDIR) \
-isystem $(SSE2NEON_DIR) \
-isystem $(dir $<).. -isystem $(COREDIR)/modules \
-D_GNU_SOURCE \
-Werror -Wall -Wextra -Wcast-align -Wno-error=deprecated-declarations \
Expand All @@ -133,6 +153,10 @@ ifeq "$(shell expr $(CXXCOMPILER) = g++)" "1"
CXXFLAGS += -fno-gnu-unique
endif

ifeq ($(ARCH),aarch64)
CXXFLAGS += -DRTE_FORCE_INTRINSICS
endif

LDFLAGS += -rdynamic -L$(DPDK_LIB_DIR) -Wl,-rpath=$(DPDK_LIB_DIR) -pthread
ifdef BESS_LINK_DYNAMIC
LIBS_ALL_SHARED = -Wl,-call_shared
Expand Down
13 changes: 12 additions & 1 deletion core/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,16 @@ static bool SkipSymbol(char *symbol) {
// TODO: Only use async-signal-safe operations in the signal handler.
static void TrapHandler(int sig_num, siginfo_t *info, void *ucontext) {
std::ostringstream oops;

#if (__i386 || __x86_64)
auto *uc = static_cast<ucontext_t *>(ucontext);
#elif __aarch64__
// unused parameter
(void)ucontext;
#else
#error Unsupported architecture
#endif

bool is_fatal = (sig_num != SIGUSR1);
static volatile bool already_trapped = false;

Expand All @@ -422,8 +431,10 @@ static void TrapHandler(int sig_num, siginfo_t *info, void *ucontext) {
trap_ip = reinterpret_cast<void *>(uc->uc_mcontext.gregs[REG_EIP]);
#elif __x86_64
trap_ip = reinterpret_cast<void *>(uc->uc_mcontext.gregs[REG_RIP]);
#elif __aarch64__
trap_ip = nullptr;
#else
#error neither x86 or x86-64
#error Unsupported architecture
#endif

if (is_fatal) {
Expand Down
2 changes: 1 addition & 1 deletion core/gate_hooks/pcapng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ T PadSize(T a, T b) {

// Return the single hex digit representing `nibble`. If it cannot be
// represented, return the char 'X'.
char NibbleToHD(char nibble) {
char NibbleToHD(signed char nibble) {
if (nibble >= 0 && nibble <= 9) {
return nibble + '0';
} else if (nibble >= 10 && nibble <= 15) {
Expand Down
6 changes: 6 additions & 0 deletions core/kmod/llring.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ typedef uint64_t phys_addr_t;
#define llring_likely(x) __builtin_expect(!!(x), 1)
#define llring_unlikely(x) __builtin_expect(!!(x), 0)

#if __x86_64
#include <emmintrin.h>
#elif __aarch64__
#include <sse2neon.h>
#else
#error Unsupported architecture
#endif

static inline void llring_pause(void) { _mm_pause(); }

Expand Down
8 changes: 7 additions & 1 deletion core/modules/ip_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
#include "../utils/format.h"
#include "../utils/ip.h"

#if __x86_64
#define VECTOR_OPTIMIZATION 1
#elif __aarch64__
#define VECTOR_OPTIMIZATION 0
#else
#error Unsupported architecture
#endif

static inline int is_valid_gate(gate_idx_t gate) {
return (gate < MAX_GATES || gate == DROP_GATE);
Expand Down Expand Up @@ -84,7 +90,7 @@ void IPLookup::ProcessBatch(Context *ctx, bess::PacketBatch *batch) {
gate_idx_t default_gate = default_gate_;

int cnt = batch->cnt();
int i;
int i = 0;

#if VECTOR_OPTIMIZATION
// Convert endianness for four addresses at the same time
Expand Down
6 changes: 6 additions & 0 deletions core/modules/set_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#if __x86_64
#include <x86intrin.h>
#elif __aarch64__
#include <sse2neon.h>
#else
#error Unsupported architecture
#endif

#include <cmath>

Expand Down
6 changes: 6 additions & 0 deletions core/utils/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
#define BESS_UTILS_BITS_H_

#include <glog/logging.h>
#if __x86_64
#include <x86intrin.h>
#elif __aarch64__
#include <sse2neon.h>
#else
#error Unsupported architecture
#endif

#include <algorithm>

Expand Down
Loading