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
20 changes: 20 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ DEFINES = [
}) + select({
"//bazel/config:brpc_with_rdma": ["BRPC_WITH_RDMA=1"],
"//conditions:default": [],
}) + 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 @@ -94,6 +97,11 @@ LINKOPTS = [
"-libverbs",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_iouring": [
"-luring",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_asan": ["-fsanitize=address"],
"//conditions:default": [],
Expand Down Expand Up @@ -530,12 +538,19 @@ cc_library(
"src/brpc/policy/thrift_protocol.cpp",
"src/brpc/event_dispatcher_epoll.cpp",
"src/brpc/event_dispatcher_kqueue.cpp",
"src/brpc/iouring/iouring_endpoint.cpp",
"src/brpc/iouring/iouring_helper.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": [],
}),
hdrs = glob([
"src/brpc/*.h",
Expand All @@ -562,6 +577,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")

if(WITH_GLOG)
Expand Down
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ http_archive(
urls = ["https://archive.apache.org/dist/thrift/0.15.0/thrift-0.15.0.tar.gz"],
)

# io_uring support via local liburing source tree.
# Enable with: --define=BRPC_WITH_IOURING=true
# Requires liburing checked out at /docker/root/projects/liburing
new_local_repository(
name = "com_github_axboe_liburing",
path = "/docker/root/projects/liburing",
build_file = "//bazel/third_party/liburing:liburing.BUILD",
)

#
# 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
43 changes: 43 additions & 0 deletions bazel/third_party/liburing/liburing.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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).
# Used via new_local_repository pointing to a local liburing source tree.

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

cc_library(
name = "liburing",
srcs = [
"src/queue.c",
"src/register.c",
"src/setup.c",
"src/syscall.c",
],
hdrs = glob([
"src/include/**/*.h",
"src/include/*.h",
]),
includes = [
"src/include",
],
copts = [
"-D_GNU_SOURCE",
# Suppress warnings from third-party code
"-Wno-unused-variable",
"-Wno-implicit-function-declaration",
],
visibility = ["//visibility:public"],
)
Loading
Loading