Skip to content

Commit

Permalink
Add vectorscan (same abi as hyperscan) for arm 64 (#29881)
Browse files Browse the repository at this point in the history
Fix #29276

Use Vectorscan for Arm 64 CPUs

Risk Level: Low
Testing: Covered by original commit
Platform Specific Features: aarch64

Signed-off-by: Samuel Bercovici <samuelb@radware.com>
  • Loading branch information
sambercovici authored Nov 28, 2023
1 parent bc2fdb7 commit dcf8850
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bazel/foreign_cc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ configure_make(
# Workaround for the issue with statically linked libstdc++
# using -l:libstdc++.a.
env = {
"CXXFLAGS": "-lstdc++ -Wno-unused-command-line-argument",
"CXXFLAGS": "--static -lstdc++ -Wno-unused-command-line-argument",
},
lib_source = "@net_colm_open_source_colm//:all",
out_binaries = ["colm"],
Expand All @@ -141,7 +141,7 @@ configure_make(
# Workaround for the issue with statically linked libstdc++
# using -l:libstdc++.a.
env = {
"CXXFLAGS": "-lstdc++ -Wno-unused-command-line-argument",
"CXXFLAGS": "--static -lstdc++ -Wno-unused-command-line-argument",
},
lib_source = "@net_colm_open_source_ragel//:all",
out_binaries = ["ragel"],
Expand Down
33 changes: 33 additions & 0 deletions bazel/foreign_cc/vectorscan.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1db128b..ee3b4a9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,7 +27,7 @@ include (${CMAKE_MODULE_PATH}/platform.cmake)
include (${CMAKE_MODULE_PATH}/boost.cmake)
include (${CMAKE_MODULE_PATH}/ragel.cmake)

-find_package(PkgConfig REQUIRED)
+find_package(PkgConfig QUIET)

find_program(RAGEL ragel)

diff --git a/cmake/sqlite3.cmake b/cmake/sqlite3.cmake
index 92b18ce..5291726 100644
--- a/cmake/sqlite3.cmake
+++ b/cmake/sqlite3.cmake
@@ -2,6 +2,8 @@
# a lot of noise to find sqlite
#

+if(NOT SQLITE_SKIP_CHECK)
+
option(SQLITE_PREFER_STATIC "Build sqlite3 statically instead of using an installed lib" OFF)

if(NOT SQLITE_PREFER_STATIC)
@@ -33,4 +35,6 @@ else()
endif()
endif()

+endif()
+
# that's enough about sqlite
14 changes: 12 additions & 2 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load(":dev_binding.bzl", "envoy_dev_binding")
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
load("@envoy_api//bazel:envoy_http_archive.bzl", "envoy_http_archive")
load("@envoy_api//bazel:external_deps.bzl", "load_repository_locations")
load(":dev_binding.bzl", "envoy_dev_binding")
load(":repository_locations.bzl", "PROTOC_VERSIONS", "REPOSITORY_LOCATIONS_SPEC")
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")

PPC_SKIP_TARGETS = ["envoy.filters.http.lua"]

Expand Down Expand Up @@ -311,6 +311,7 @@ def envoy_dependencies(skip_targets = []):
_com_github_google_quiche()
_com_googlesource_googleurl()
_io_hyperscan()
_io_vectorscan()
_io_opentracing_cpp()
_net_colm_open_source_colm()
_net_colm_open_source_ragel()
Expand Down Expand Up @@ -710,6 +711,15 @@ def _io_hyperscan():
patches = ["@envoy//bazel/foreign_cc:hyperscan.patch"],
)

def _io_vectorscan():
external_http_archive(
name = "io_vectorscan",
build_file_content = BUILD_ALL_CONTENT,
type = "tar.gz",
patch_args = ["-p1"],
patches = ["@envoy//bazel/foreign_cc:vectorscan.patch"],
)

def _io_opentracing_cpp():
external_http_archive(
name = "io_opentracing_cpp",
Expand Down
18 changes: 18 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,24 @@ REPOSITORY_LOCATIONS_SPEC = dict(
license = "BSD-3-Clause",
license_url = "https://github.com/intel/hyperscan/blob/v{version}/LICENSE",
),
io_vectorscan = dict(
project_name = "Vectorscan",
project_desc = "Hyperscan port for additional CPU architectures",
project_url = "https://www.vectorcamp.gr/vectorscan/",
version = "5.4.11",
sha256 = "905f76ad1fa9e4ae0eb28232cac98afdb96c479666202c5a4c27871fb30a2711",
strip_prefix = "vectorscan-vectorscan-{version}",
urls = ["https://codeload.github.com/VectorCamp/vectorscan/tar.gz/refs/tags/vectorscan/{version}"],
use_category = ["dataplane_ext"],
extensions = [
"envoy.matching.input_matchers.hyperscan",
"envoy.regex_engines.hyperscan",
],
release_date = "2023-11-20",
cpe = "N/A",
license = "BSD-3-Clause",
license_url = "https://github.com/VectorCamp/vectorscan/blob/vectorscan/{version}/LICENSE",
),
io_opentracing_cpp = dict(
project_name = "OpenTracing",
project_desc = "Vendor-neutral APIs and instrumentation for distributed tracing",
Expand Down
8 changes: 6 additions & 2 deletions contrib/all_contrib_extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ def envoy_contrib_linux_x86_64_constraints():
"@platforms//cpu:x86_64",
]

def envoy_contrib_linux_aarch64_constraints():
return [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
]

ARM64_SKIP_CONTRIB_TARGETS = [
"envoy.tls.key_providers.cryptomb",
"envoy.tls.key_providers.qat",
"envoy.matching.input_matchers.hyperscan",
"envoy.network.connection_balance.dlb",
"envoy.regex_engines.hyperscan",
]
PPC_SKIP_CONTRIB_TARGETS = [
"envoy.tls.key_providers.cryptomb",
Expand Down
47 changes: 45 additions & 2 deletions contrib/hyperscan/matching/input_matchers/source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ load(
)
load(
"//contrib:all_contrib_extensions.bzl",
"envoy_contrib_linux_aarch64_constraints",
"envoy_contrib_linux_x86_64_constraints",
)

Expand Down Expand Up @@ -41,8 +42,34 @@ envoy_cmake(
],
)

envoy_cmake(
name = "vectorscan",
build_data = ["@org_boost//:header"],
cache_entries = {
"BOOST_ROOT": "$EXT_BUILD_ROOT/external/org_boost",
# "BUILD_SVE2_BITPERM": "on",
# "BUILD_SVE2": "on",
# "BUILD_SVE": "on",
"BUILD_EXAMPLES": "off",
"BUILD_SHARED_LIBS": "off",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_LIBDIR": "lib",
"FAT_RUNTIME": "off",
"SQLITE_SKIP_CHECK": "on",
"RAGEL": "$EXT_BUILD_DEPS/ragel/bin/ragel",
},
default_cache_entries = {},
lib_source = "@io_vectorscan//:all",
out_static_libs = ["libhs.a"],
tags = ["skip_on_windows"],
target_compatible_with = envoy_contrib_linux_aarch64_constraints(),
deps = [
envoy_external_dep_path("ragel"),
],
)

envoy_cc_library(
name = "matcher_lib",
name = "hyperscan_matcher_lib",
srcs = ["matcher.cc"],
hdrs = ["matcher.h"],
deps = [
Expand All @@ -53,12 +80,25 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "vectorscan_matcher_lib",
srcs = ["matcher.cc"],
hdrs = ["matcher.h"],
deps = [
":vectorscan",
"//envoy/common:regex_interface",
"//envoy/matcher:matcher_interface",
"//envoy/thread_local:thread_local_interface",
],
)

envoy_cc_contrib_extension(
name = "config",
srcs = ["config.cc"],
hdrs = ["config.h"],
defines = select({
"//bazel:linux_x86_64": [],
"//bazel:linux_aarch64": [],
"//conditions:default": [
"HYPERSCAN_DISABLED=1",
],
Expand All @@ -71,7 +111,10 @@ envoy_cc_contrib_extension(
"@envoy_api//contrib/envoy/extensions/matching/input_matchers/hyperscan/v3alpha:pkg_cc_proto",
] + select({
"//bazel:linux_x86_64": [
":matcher_lib",
":hyperscan_matcher_lib",
],
"//bazel:linux_aarch64": [
":vectorscan_matcher_lib",
],
"//conditions:default": [
],
Expand Down
30 changes: 24 additions & 6 deletions contrib/hyperscan/matching/input_matchers/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,54 @@ envoy_cc_test(
name = "matcher_test",
srcs = ["matcher_test.cc"],
deps = [
"//contrib/hyperscan/matching/input_matchers/source:matcher_lib",
"//source/common/thread_local:thread_local_lib",
"//test/mocks/event:event_mocks",
"//test/mocks/thread_local:thread_local_mocks",
"//test/test_common:utility_lib",
],
] + select({
"//bazel:linux_x86_64": [
"//contrib/hyperscan/matching/input_matchers/source:hyperscan_matcher_lib",
],
"//bazel:linux_aarch64": [
"//contrib/hyperscan/matching/input_matchers/source:vectorscan_matcher_lib",
],
}),
)

envoy_cc_benchmark_binary(
name = "hyperscan_speed_test",
srcs = ["hyperscan_speed_test.cc"],
external_deps = ["benchmark"],
deps = [
"//contrib/hyperscan/matching/input_matchers/source:hyperscan",
"//source/common/common:assert_lib",
"//source/common/common:utility_lib",
"@com_googlesource_code_re2//:re2",
],
] + select({
"//bazel:linux_x86_64": [
"//contrib/hyperscan/matching/input_matchers/source:hyperscan",
],
"//bazel:linux_aarch64": [
"//contrib/hyperscan/matching/input_matchers/source:vectorscan",
],
}),
)

envoy_cc_benchmark_binary(
name = "matcher_speed_test",
srcs = ["matcher_speed_test.cc"],
external_deps = ["benchmark"],
deps = [
"//contrib/hyperscan/matching/input_matchers/source:matcher_lib",
"//source/common/common:assert_lib",
"//source/common/common:regex_lib",
"//source/common/common:utility_lib",
"//source/common/thread_local:thread_local_lib",
"//test/mocks/event:event_mocks",
],
] + select({
"//bazel:linux_x86_64": [
"//contrib/hyperscan/matching/input_matchers/source:hyperscan_matcher_lib",
],
"//bazel:linux_aarch64": [
"//contrib/hyperscan/matching/input_matchers/source:vectorscan_matcher_lib",
],
}),
)
14 changes: 12 additions & 2 deletions contrib/hyperscan/regex_engines/source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ envoy_cc_library(
srcs = ["regex.cc"],
hdrs = ["regex.h"],
deps = [
"//contrib/hyperscan/matching/input_matchers/source:matcher_lib",
"//envoy/common:regex_interface",
],
] + select({
"//bazel:linux_x86_64": [
"//contrib/hyperscan/matching/input_matchers/source:hyperscan_matcher_lib",
],
"//bazel:linux_aarch64": [
"//contrib/hyperscan/matching/input_matchers/source:vectorscan_matcher_lib",
],
}),
)

envoy_cc_contrib_extension(
Expand All @@ -25,6 +31,7 @@ envoy_cc_contrib_extension(
hdrs = ["config.h"],
defines = select({
"//bazel:linux_x86_64": [],
"//bazel:linux_aarch64": [],
"//conditions:default": [
"HYPERSCAN_DISABLED=1",
],
Expand All @@ -36,6 +43,9 @@ envoy_cc_contrib_extension(
"//bazel:linux_x86_64": [
":regex_lib",
],
"//bazel:linux_aarch64": [
":regex_lib",
],
"//conditions:default": [
],
}),
Expand Down

0 comments on commit dcf8850

Please sign in to comment.