Skip to content

Commit

Permalink
Feat: Support cgroupv2 (#327)
Browse files Browse the repository at this point in the history
* 完成CgroupV2除devices的支持

* 完成对CgroupV2的支持(devices除外)

* fix bug

* check name

* recover config.yaml

* get master config.yaml

* fix undefined func

* solve comments

* complete devices support in cgroupV2 by using bpf

complete devices support in cgroupV2 by using bpf

complete devices support in cgroupV2 by using bpf

* rm cmake order

* fix bug in bpf dev_map

* resolve comment and test  multitask

resolve comment

* refactor Cgroup and reslove comment

reslove comment

reslove comment

reslove comment

reslove commit

reslove comment

reslove comment

reslove comment

reslove comment

reslove comment

modify bpf cmake

* check and set compile for project

* reslove comment of checking compiler version and handling device run_time error in V2

format

* resolve comment and modify device access logic on V1 and V2

resolve comment

resolve commit

* check name

* add dynamic load log level in bpf.o,modify bpf_obj load logic(one or more cgroups load bpf_obj once)

reslove comment

reslove comment

reslove comment

fix bug

delete BPF_DEBUG compile option

resolve comment

comment

* comment

* resolve comment

* 完成CgroupV2除devices的支持

* 完成对CgroupV2的支持(devices除外)

* fix bug

* recover config.yaml

* get master config.yaml

* fix undefined func

* solve comments

* complete devices support in cgroupV2 by using bpf

complete devices support in cgroupV2 by using bpf

complete devices support in cgroupV2 by using bpf

* rm cmake order

* fix bug in bpf dev_map

* resolve comment and test  multitask

resolve comment

* refactor Cgroup and reslove comment

reslove comment

reslove comment

reslove comment

reslove commit

reslove comment

reslove comment

reslove comment

reslove comment

reslove comment

modify bpf cmake

* check and set compile for project

* reslove comment of checking compiler version and handling device run_time error in V2

format

* resolve comment and modify device access logic on V1 and V2

resolve comment

resolve commit

* check name

* add dynamic load log level in bpf.o,modify bpf_obj load logic(one or more cgroups load bpf_obj once)

reslove comment

reslove comment

reslove comment

fix bug

delete BPF_DEBUG compile option

resolve comment

comment

* comment

* resolve comment

* add v2 option CRANE_ENABLE_CGROUP_V2 and communicate with CRANE_USE_SYSTEM_LIBCGROUP

* comment

commit

 comment

 comment

* rm pkg check libcgroup

* comment

* comment

* add memory.move_charge_at_immigrate todo
  • Loading branch information
wtr0504 authored Nov 13, 2024
1 parent 7b55661 commit 9ee70b9
Show file tree
Hide file tree
Showing 12 changed files with 1,296 additions and 418 deletions.
47 changes: 47 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,47 @@ if(VERSION_CONTENT STREQUAL "")
endif()

project(Crane VERSION ${CMAKE_PROJECT_VERSION} LANGUAGES C CXX)
# check and set compiler
set(REQUIRED_GNU_VERSION 13.0.0)
set(REQUIRED_CLANG_VERSION 19.0.0)
set(REQUIRED_BPF_CLANG_VERSION 17.0.0)

set(CLANG_VERSION "0.0.0")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL REQUIRED_GNU_VERSION)
if(CRANE_ENABLE_CGROUP_V2)
message(STATUS "Enabling Cgroup V2 will build cgroup_dev_bpf_object, which requires Clang ${REQUIRED_BPF_CLANG_VERSION}+. Use GNU ${CMAKE_CXX_COMPILER_VERSION} for other modules. ")
find_program(CLANG_EXECUTABLE NAMES clang)
if(CLANG_EXECUTABLE)
execute_process(
COMMAND ${CLANG_EXECUTABLE} --version
OUTPUT_VARIABLE CLANG_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CLANG_VERSION ${CLANG_VERSION_OUTPUT})
if(CLANG_VERSION VERSION_GREATER_EQUAL REQUIRED_BPF_CLANG_VERSION)
set(ENABLE_BPF ON)
message(STATUS "Found Clang at ${CLANG_EXECUTABLE} with version ${CLANG_VERSION}; using this version for the cgroup_dev_bpf_object module.")
else()
message(FATAL_ERROR "Clang found at ${CLANG_EXECUTABLE} is version ${CLANG_VERSION}, but version ${REQUIRED_BPF_CLANG_VERSION} or higher is required for device management on Cgroup V2. You may use Cgroup V1 instead.")
endif()
else()
message(FATAL_ERROR "Clang ${REQUIRED_BPF_CLANG_VERSION} or higher is required for device management on Cgroup V2. You can use Cgroup V1.")
endif()
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL REQUIRED_CLANG_VERSION)
if(CRANE_ENABLE_CGROUP_V2)
set(ENABLE_BPF ON)
endif()
message(STATUS "Using Clang for all module.")
else()
message(FATAL_ERROR "Clang ${REQUIRED_CLANG_VERSION} or higher is required.")
endif()
else()
message(FATAL_ERROR "Neither GNU ${REQUIRED_GNU_VERSION}+ nor Clang ${REQUIRED_CLANG_VERSION}+ found. Stop compiling crane")
endif()


# Options start here ----------------------------------------------------------------------------

Expand All @@ -61,6 +102,8 @@ option(CRANE_USE_GITEE_SOURCE "Enable the Gitee repository as the download sourc

option(CRANE_USE_SYSTEM_LIBCGROUP "Use libcgroup from system instead of building from source" OFF)

option(CRANE_ENABLE_CGROUP_V2 "Enable Cgroup V2 support" OFF)

option(CRANE_FULL_DYNAMIC "Enable dynamic libs" OFF)

option(CRANE_ADDRESS_SANITIZER "Enable address sanitizer" OFF)
Expand Down Expand Up @@ -289,6 +332,10 @@ set(_PROTOBUF_PROTOC $<TARGET_FILE:protoc>)
set(_GRPC_GRPCPP grpc++)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:grpc_cpp_plugin>)

if(ENABLE_BPF)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libbpf REQUIRED IMPORTED_TARGET libbpf>=1.4.6)
endif()
# @formatter:off
add_definitions(-DCRANE_BUILD_DIRECTORY=\("${CMAKE_BINARY_DIR}"\))
# @formatter:on
Expand Down
3 changes: 3 additions & 0 deletions dependencies/cmake/libcgroup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if (${CRANE_USE_SYSTEM_LIBCGROUP})

if (libcgroup_FOUND)
message(STATUS "Found libcgroup ${libcgroup_VERSION} in system using pkg-config.")
if(CRANE_ENABLE_CGROUP_V2 AND libcgroup_VERSION VERSION_LESS "3.1.0")
message(FATAL_ERROR "libcgroup version must be higher than 3.1.0 when CRANE_ENABLE_CGROUP_V2 is set.")
endif()
else()
message(FATAL_ERROR "libcgroup in system is not found using pkg-config.")
endif()
Expand Down
9 changes: 9 additions & 0 deletions src/Craned/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ add_dependencies(craned libcgroup)
target_include_directories(
craned PRIVATE ${LIBCGROUP_PATH}/include/
)



if(ENABLE_BPF)
add_dependencies(craned cgroup_dev_bpf_object)
target_compile_definitions(craned PRIVATE CRANE_ENABLE_BPF)
endif()
target_link_libraries(craned
concurrentqueue

Expand Down Expand Up @@ -49,6 +56,8 @@ target_link_libraries(craned
result

Backward::Interface

$<$<BOOL:${ENABLE_BPF}>:bpf>
)

# Linker flag for c++ 17 filesystem library
Expand Down
Loading

0 comments on commit 9ee70b9

Please sign in to comment.