Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
--define with_bthread_tracer=true \
--define BRPC_WITH_NO_PTHREAD_MUTEX_HOOK=true \
--define with_babylon_counter=true \
--define BRPC_WITH_IOURING=true \
-- //:brpc
clang-compile-with-make-protobuf:
Expand Down Expand Up @@ -200,6 +201,7 @@ jobs:
--define with_bthread_tracer=true \
--define BRPC_WITH_NO_PTHREAD_MUTEX_HOOK=true \
--define with_babylon_counter=true \
--define BRPC_WITH_IOURING=true \
-- //:brpc
clang-unittest:
Expand Down
16 changes: 15 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ DEFINES = [
"//conditions:default": ["THRIFT_STDCXX=std"],
}) + select({
"//bazel/config:brpc_with_rdma": ["BRPC_WITH_RDMA=1"],
"//conditions:default": [],
"//conditions:default": ["BRPC_WITH_RDMA=0"],
}) + select({
"//bazel/config:brpc_with_iouring": ["BRPC_WITH_IOURING=1"],
"//conditions:default": ["BRPC_WITH_IOURING=0"],
}) + select({
"//bazel/config:brpc_with_debug_bthread_sche_safety": ["BRPC_DEBUG_BTHREAD_SCHE_SAFETY=1"],
"//conditions:default": ["BRPC_DEBUG_BTHREAD_SCHE_SAFETY=0"],
Expand Down Expand Up @@ -531,12 +534,18 @@ cc_library(
"src/brpc/policy/thrift_protocol.cpp",
"src/brpc/event_dispatcher_epoll.cpp",
"src/brpc/event_dispatcher_kqueue.cpp",
"src/brpc/iouring/*.cpp",
]) + select({
"//bazel/config:brpc_with_thrift": glob([
"src/brpc/thrift*.cpp",
"src/brpc/**/thrift*.cpp",
]),
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_iouring": glob([
"src/brpc/iouring/*.cpp",
]),
"//conditions:default": [],
Comment on lines +544 to +548
}),
hdrs = glob([
"src/brpc/*.h",
Expand All @@ -563,6 +572,11 @@ cc_library(
"@org_apache_thrift//:thrift",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_iouring": [
"@com_github_axboe_liburing//:liburing",
],
"//conditions:default": [],
}),
)

Expand Down
48 changes: 47 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(WITH_THRIFT "With thrift framed protocol supported" OFF)
option(WITH_BTHREAD_TRACER "With bthread tracer supported" OFF)
option(WITH_SNAPPY "With snappy" OFF)
option(WITH_RDMA "With RDMA" OFF)
option(WITH_IOURING "With io_uring" OFF)
option(WITH_DEBUG_BTHREAD_SCHE_SAFETY "With debugging bthread sche safety" OFF)
option(WITH_DEBUG_LOCK "With debugging lock" OFF)
option(WITH_ASAN "With AddressSanitizer" OFF)
Expand Down Expand Up @@ -104,6 +105,11 @@ if(WITH_RDMA)
set(WITH_RDMA_VAL "1")
endif()

set(WITH_IOURING_VAL "0")
if(WITH_IOURING)
set(WITH_IOURING_VAL "1")
endif()

set(WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL "0")
if(WITH_DEBUG_BTHREAD_SCHE_SAFETY)
set(WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL "1")
Expand Down Expand Up @@ -136,7 +142,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -Wno-deprecated-declarations -Wno-inconsistent-missing-override")
endif()

set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEFINE_CLOCK_GETTIME} -DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DBRPC_WITH_RDMA=${WITH_RDMA_VAL} -DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=${WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL} -DBRPC_DEBUG_LOCK=${WITH_DEBUG_LOCK_VAL}")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEFINE_CLOCK_GETTIME} -DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DBRPC_WITH_RDMA=${WITH_RDMA_VAL} -DBRPC_WITH_IOURING=${WITH_IOURING_VAL} -DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=${WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL} -DBRPC_DEBUG_LOCK=${WITH_DEBUG_LOCK_VAL}")
if (WITH_ASAN)
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -fsanitize=address")
set(CMAKE_C_FLAGS "${CMAKE_CPP_FLAGS} -fsanitize=address")
Expand Down Expand Up @@ -277,6 +283,41 @@ if(WITH_RDMA)
endif()
endif()

if(WITH_IOURING)
message("brpc compile with io_uring")
# Search for the header in standard paths and common source-tree locations.
find_path(IOURING_INCLUDE_PATH NAMES liburing.h
PATHS
/usr/include
/usr/local/include
/docker/root/projects/liburing/src/include
NO_DEFAULT_PATH)
if(NOT IOURING_INCLUDE_PATH)
find_path(IOURING_INCLUDE_PATH NAMES liburing.h)
endif()

find_library(IOURING_LIB NAMES uring liburing.a
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/docker/root/projects/liburing/src
NO_DEFAULT_PATH)
if(NOT IOURING_LIB)
find_library(IOURING_LIB NAMES uring)
endif()

if((NOT IOURING_INCLUDE_PATH) OR (NOT IOURING_LIB))
message(FATAL_ERROR "Fail to find liburing. "
"Please install liburing-dev / liburing-devel, or "
"build from source at https://github.com/axboe/liburing "
"and set CMAKE_PREFIX_PATH accordingly.")
endif()
include_directories(${IOURING_INCLUDE_PATH})
message(STATUS "Found liburing: include=${IOURING_INCLUDE_PATH} lib=${IOURING_LIB}")
endif()

find_library(PROTOC_LIB NAMES protoc)
if(NOT PROTOC_LIB)
message(FATAL_ERROR "Fail to find protoc lib")
Expand Down Expand Up @@ -329,6 +370,11 @@ if(WITH_RDMA)
list(APPEND DYNAMIC_LIB ${RDMA_LIB})
endif()

if(WITH_IOURING)
list(APPEND DYNAMIC_LIB ${IOURING_LIB})
set(BRPC_PRIVATE_LIBS "${BRPC_PRIVATE_LIBS} -luring")
endif()

set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz")
Comment on lines +373 to 378
Comment on lines +373 to 378

if(WITH_GLOG)
Expand Down
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ bazel_dep(name = "apple_support", version = "1.17.1")
bazel_dep(name = 'rules_cc', version = '0.0.1')
bazel_dep(name = 'rules_proto', version = '4.0.0')
bazel_dep(name = 'zlib', version = '1.3.1.bcr.5', repo_name = 'com_github_madler_zlib')
# io_uring support. Enable with: --define=BRPC_WITH_IOURING=true
bazel_dep(name = 'liburing', version = '2.14', repo_name = 'com_github_axboe_liburing')
bazel_dep(name = 'babylon', version = '1.4.4')
# --registry=https://raw.githubusercontent.com/apache/brpc/master/registry
# `registry/modules/libunwind/` (see the `--registry=https://raw.githubusercontent.com/apache/brpc/master/registry`
Expand Down
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ cc_library(
urls = ["https://github.com/nlohmann/json/archive/refs/tags/v3.12.0.tar.gz"],
)

# io_uring support. Enable with: --define=BRPC_WITH_IOURING=true
# compat.h and other headers are generated by configure (via genrule).
http_archive(
name = "com_github_axboe_liburing",
build_file = "//bazel/third_party/liburing:liburing.BUILD",
sha256 = "5f80964108981c6ad979c735f0b4877d5f49914c2a062f8e88282f26bf61de0c",
strip_prefix = "liburing-liburing-2.14",
urls = ["https://github.com/axboe/liburing/archive/refs/tags/liburing-2.14.tar.gz"],
)

#
# Perl Dependencies
Expand Down
6 changes: 6 additions & 0 deletions bazel/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ config_setting(
visibility = ["//visibility:public"],
)

config_setting(
name = "brpc_with_iouring",
define_values = {"BRPC_WITH_IOURING": "true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "brpc_with_boringssl",
define_values = {"BRPC_WITH_BORINGSSL": "true"},
Expand Down
18 changes: 18 additions & 0 deletions bazel/third_party/liburing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This empty BUILD.bazel makes this directory a Bazel package so that
# //bazel/third_party/liburing:liburing.BUILD is a valid label for the
# build_file attribute of the com_github_axboe_liburing http_archive rule.
87 changes: 87 additions & 0 deletions bazel/third_party/liburing/liburing.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# BUILD file for liburing (io_uring userspace library).
# Mirrors the approach used in the Bazel Central Registry overlay for liburing:
# a genrule runs ./configure (to generate config-host.h, compat.h and
# io_uring_version.h) and a plain cc_library compiles the sources directly,
# avoiding any dependency on rules_foreign_cc.

load("@rules_cc//cc:defs.bzl", "cc_library")

licenses(["notice"]) # MIT / GPL-2.0-only (dual-licensed)

# Run ./configure to produce the three generated headers. We only need the
# headers, not the full make build, so we skip the library compilation step.
genrule(
name = "generate_headers",
srcs = [
"Makefile.common",
"liburing.spec",
],
outs = [
"config-host.h",
"src/include/liburing/compat.h",
"src/include/liburing/io_uring_version.h",
],
cmd = """
export CC=$(CC) CXX=$(CC)++

# switch to the package dir to execute "configure" right there
pushd $$(dirname $(location configure))
mkdir -p src/include/liburing
./configure --use-libc
popd

# collect the outputs
for out in $(OUTS); do
cp $$(realpath --relative-to=$(BINDIR) $$out) $$out
done
""",
toolchains = ["@bazel_tools//tools/cpp:current_cc_toolchain"],
tools = ["configure"],
)

cc_library(
name = "liburing",
srcs = [
"config-host.h",
"src/include/liburing/compat.h",
"src/include/liburing/io_uring_version.h",
"src/queue.c",
"src/register.c",
"src/setup.c",
"src/syscall.c",
"src/version.c",
] + glob([
"src/arch/**/*.h",
"src/*.h",
]),
hdrs = glob(["src/include/**/*.h"]),
# cflags aligned with upstream:
# https://github.com/axboe/liburing/blob/master/src/Makefile#L13
copts = [
"-D_GNU_SOURCE",
"-D_LARGEFILE_SOURCE",
"-D_FILE_OFFSET_BITS=64",
"-DLIBURING_INTERNAL",
"-Wall",
"-Wextra",
"-fno-stack-protector",
"-include config-host.h",
],
includes = ["src/include"],
visibility = ["//visibility:public"],
)
Loading
Loading