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
10 changes: 9 additions & 1 deletion .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ on:
jobs:
qoder-review:
runs-on: ubuntu-latest
env:
QODER_PERSONAL_ACCESS_TOKEN: ${{ secrets.QODER_PERSONAL_ACCESS_TOKEN }}
permissions:
contents: read
pull-requests: write
id-token: write

steps:
- name: Checkout repository
if: ${{ env.QODER_PERSONAL_ACCESS_TOKEN != '' }}
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run Qoder Code Review
if: ${{ env.QODER_PERSONAL_ACCESS_TOKEN != '' }}
uses: QoderAI/qoder-action@v0
with:
qoder_personal_access_token: ${{ secrets.QODER_PERSONAL_ACCESS_TOKEN }}
qoder_personal_access_token: ${{ env.QODER_PERSONAL_ACCESS_TOKEN }}
prompt: |
/review-pr
REPO:${{ github.repository }} PR_NUMBER:${{ github.event.pull_request.number }}

- name: Skip Qoder Code Review
if: ${{ env.QODER_PERSONAL_ACCESS_TOKEN == '' }}
run: echo "Qoder review skipped because QODER_PERSONAL_ACCESS_TOKEN is unavailable."
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
path = extern/yalantinglibs
url = https://github.com/alibaba/yalantinglibs.git
branch = v0.5.7
[submodule "extern/ubdiag"]
path = extern/ubdiag
url = https://atomgit.com/liusiyu60/ubdiag
branch = fix/shm-probe-fastpath
1 change: 1 addition & 0 deletions extern/ubdiag
Submodule ubdiag added at 7deea5
277 changes: 277 additions & 0 deletions mooncake-common/FindUbDiag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
# FindUbDiag.cmake Resolves UbDiag::ubdiag_lib with a three-layer fallback: 1.
# Submodule (extern/ubdiag) — add_subdirectory if present 2. System package —
# find_package(UbDiag QUIET) 3. Mock header — mooncake-common/ubdiag-mock/
# (no-op PerfPoint)
#
# Usage: include(${CMAKE_SOURCE_DIR}/mooncake-common/FindUbDiag.cmake)
# target_link_libraries(your_target PRIVATE UbDiag::ubdiag_lib)

if(TARGET UbDiag::ubdiag_lib)
return()
endif()

option(MOONCAKE_UBDIAG_BUILD_CLI
"Enable UbDiag CLI integration for vendored or system UbDiag" ON)
option(MOONCAKE_UBDIAG_L1_SHARED
"Build vendored UbDiag as libubdiag.so so Mooncake and the CLI use one SDK" ON)
option(MOONCAKE_UBDIAG_ENABLE_PERCENTILE
"Enable vendored UbDiag P99/P999/P9999 percentile calculation for Mooncake PerfPoint" ON)
option(MOONCAKE_UBDIAG_ENABLE_PERFLOG
"Enable vendored UbDiag PerfLog timestamp logging for Mooncake PerfPoint" ON)
option(MOONCAKE_UBDIAG_PERFPOINT_ONLY
"Disable vendored UbDiag OB/MemPoint/CachePoint extensions; keep Mooncake PerfPoint/P99/PerfLog/CSV" ON)
option(MOONCAKE_UBDIAG_DISABLE_SYSTEM
"Skip Layer 2 system-package lookup, used only for forced mock verification" OFF)

function(_mooncake_ubdiag_write_rpm_manifest layer cli_path library_path config_path)
set(_manifest "${CMAKE_BINARY_DIR}/mooncake_ubdiag_rpm.env")
file(WRITE "${_manifest}" "MOONCAKE_UBDIAG_LAYER=${layer}\n")
file(APPEND "${_manifest}" "MOONCAKE_UBDIAG_CLI_PATH=${cli_path}\n")
file(APPEND "${_manifest}" "MOONCAKE_UBDIAG_LIBRARY_PATH=${library_path}\n")
file(APPEND "${_manifest}" "MOONCAKE_UBDIAG_CONFIG_PATH=${config_path}\n")
set(MOONCAKE_UBDIAG_RPM_MANIFEST "${_manifest}"
CACHE FILEPATH "UbDiag RPM packaging manifest generated by Mooncake" FORCE)
set(MOONCAKE_UBDIAG_ACTIVE_LAYER "${layer}"
CACHE STRING "Active UbDiag integration layer: submodule, system, or mock" FORCE)
endfunction()

function(_mooncake_ubdiag_get_imported_location target out_var)
set(_location_props IMPORTED_LOCATION IMPORTED_LOCATION_NOCONFIG)
get_target_property(_configs ${target} IMPORTED_CONFIGURATIONS)
if(NOT _configs OR _configs MATCHES "-NOTFOUND$")
set(_configs)
endif()
foreach(_config IN LISTS _configs)
string(TOUPPER "${_config}" _config_upper)
list(APPEND _location_props "IMPORTED_LOCATION_${_config_upper}")
endforeach()
list(APPEND _location_props
IMPORTED_LOCATION_RELEASE
IMPORTED_LOCATION_RELWITHDEBINFO
IMPORTED_LOCATION_MINSIZEREL
IMPORTED_LOCATION_DEBUG)

foreach(_prop IN LISTS _location_props)
get_target_property(_location ${target} ${_prop})
if(_location AND NOT _location MATCHES "-NOTFOUND$")
set(${out_var} "${_location}" PARENT_SCOPE)
return()
endif()
endforeach()

set(${out_var} "" PARENT_SCOPE)
endfunction()

function(_mooncake_ubdiag_require_submodule_file source_dir relative_path)
set(_required_file "${source_dir}/${relative_path}")
if(EXISTS "${_required_file}")
return()
endif()

# A pull updates the parent gitlink but does not repair deleted files in an
# already checked-out submodule. Restore only the required tracked file and
# leave every other local UbDiag change untouched.
find_program(_MOONCAKE_UBDIAG_GIT_EXECUTABLE NAMES git)
if(_MOONCAKE_UBDIAG_GIT_EXECUTABLE AND EXISTS "${source_dir}/.git")
execute_process(
COMMAND "${_MOONCAKE_UBDIAG_GIT_EXECUTABLE}"
-C "${source_dir}" checkout -- "${relative_path}"
RESULT_VARIABLE _restore_result
OUTPUT_QUIET
ERROR_QUIET)
if(_restore_result EQUAL 0 AND EXISTS "${_required_file}")
message(STATUS "UbDiag: restored missing tracked file ${relative_path}")
return()
endif()
endif()

message(FATAL_ERROR
"UbDiag L1 submodule is incomplete: ${_required_file} is missing.\n"
"Restore the recorded submodule contents with:\n"
" git submodule sync --recursive\n"
" git submodule update --init --checkout extern/ubdiag")
endfunction()

# Layer 1: Submodule (same pattern as extern/pybind11). UbDiag's generic
# BUILD_TESTS / BUILD_EXAMPLES default to ON and collide with Mooncake option
# names, so temporarily narrow them only while adding the submodule.
if(EXISTS "${CMAKE_SOURCE_DIR}/extern/ubdiag/CMakeLists.txt")
file(STRINGS "${CMAKE_SOURCE_DIR}/extern/ubdiag/CMakeLists.txt"
_MOONCAKE_UBDIAG_PACKAGE_CONFIG_REFS
REGEX "UbDiagConfig\\.cmake\\.in")
if(_MOONCAKE_UBDIAG_PACKAGE_CONFIG_REFS)
_mooncake_ubdiag_require_submodule_file(
"${CMAKE_SOURCE_DIR}/extern/ubdiag" "cmake/UbDiagConfig.cmake.in")
endif()

set(_MOONCAKE_UBDIAG_SAVED_BUILD_EXAMPLES "${BUILD_EXAMPLES}")
set(_MOONCAKE_UBDIAG_HAD_BUILD_EXAMPLES_CACHE FALSE)
if(DEFINED CACHE{BUILD_EXAMPLES})
set(_MOONCAKE_UBDIAG_HAD_BUILD_EXAMPLES_CACHE TRUE)
get_property(_MOONCAKE_UBDIAG_BUILD_EXAMPLES_HELP CACHE BUILD_EXAMPLES PROPERTY HELPSTRING)
endif()
set(_MOONCAKE_UBDIAG_SAVED_BUILD_TESTS "${BUILD_TESTS}")
set(_MOONCAKE_UBDIAG_HAD_BUILD_TESTS_CACHE FALSE)
if(DEFINED CACHE{BUILD_TESTS})
set(_MOONCAKE_UBDIAG_HAD_BUILD_TESTS_CACHE TRUE)
get_property(_MOONCAKE_UBDIAG_BUILD_TESTS_HELP CACHE BUILD_TESTS PROPERTY HELPSTRING)
endif()
set(BUILD_EXAMPLES OFF)
set(BUILD_EXAMPLES OFF CACHE BOOL "Disable UbDiag examples when vendored by Mooncake" FORCE)
set(BUILD_TESTS OFF)
set(BUILD_TESTS OFF CACHE BOOL "Disable UbDiag tests when vendored by Mooncake" FORCE)
if(MOONCAKE_UBDIAG_L1_SHARED)
set(UBDIAG_BUILD_SHARED ON CACHE BOOL "Build vendored UbDiag as a shared library" FORCE)
endif()
if(MOONCAKE_UBDIAG_ENABLE_PERCENTILE)
set(ENABLE_PERCENTILE ON CACHE BOOL "Enable vendored UbDiag percentile calculation" FORCE)
endif()
if(MOONCAKE_UBDIAG_ENABLE_PERFLOG)
set(ENABLE_PERFLOG ON CACHE BOOL "Enable vendored UbDiag PerfLog support" FORCE)
endif()
if(MOONCAKE_UBDIAG_PERFPOINT_ONLY)
set(ENABLE_OB_MEMORY OFF CACHE BOOL "Disable vendored UbDiag eBPF memory observation" FORCE)
set(ENABLE_OB_CACHE OFF CACHE BOOL "Disable vendored UbDiag cache observation" FORCE)
set(ENABLE_MEMPOINT OFF CACHE BOOL "Disable vendored UbDiag MemPoint observation" FORCE)
set(UBDIAG_ENABLE_CACHEPOINT OFF CACHE BOOL "Disable vendored UbDiag CachePoint observation" FORCE)
endif()

add_subdirectory(${CMAKE_SOURCE_DIR}/extern/ubdiag
${CMAKE_BINARY_DIR}/extern/ubdiag_build EXCLUDE_FROM_ALL)

if(_MOONCAKE_UBDIAG_HAD_BUILD_EXAMPLES_CACHE)
set(BUILD_EXAMPLES "${_MOONCAKE_UBDIAG_SAVED_BUILD_EXAMPLES}"
CACHE BOOL "${_MOONCAKE_UBDIAG_BUILD_EXAMPLES_HELP}" FORCE)
else()
unset(BUILD_EXAMPLES CACHE)
endif()
set(BUILD_EXAMPLES "${_MOONCAKE_UBDIAG_SAVED_BUILD_EXAMPLES}")
if(_MOONCAKE_UBDIAG_HAD_BUILD_TESTS_CACHE)
set(BUILD_TESTS "${_MOONCAKE_UBDIAG_SAVED_BUILD_TESTS}"
CACHE BOOL "${_MOONCAKE_UBDIAG_BUILD_TESTS_HELP}" FORCE)
else()
unset(BUILD_TESTS CACHE)
endif()
set(BUILD_TESTS "${_MOONCAKE_UBDIAG_SAVED_BUILD_TESTS}")

if(TARGET ubdiag_lib)
set(_MOONCAKE_UBDIAG_SOURCE_DIR "${CMAKE_SOURCE_DIR}/extern/ubdiag")
# ubdiag's CMake uses CMAKE_SOURCE_DIR instead of CMAKE_CURRENT_SOURCE_DIR
# for its include paths. When consumed via add_subdirectory from Mooncake,
# CMAKE_SOURCE_DIR points to Mooncake's root, not ubdiag's. Fix it here.
target_include_directories(ubdiag_lib PUBLIC
$<BUILD_INTERFACE:${_MOONCAKE_UBDIAG_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

foreach(_MOONCAKE_UBDIAG_LIB_TARGET
ubdiag_logger ubdiag_manager_lib ubdiag_runtime_lib ubdiag_bpf_loader)
if(TARGET ${_MOONCAKE_UBDIAG_LIB_TARGET})
target_include_directories(${_MOONCAKE_UBDIAG_LIB_TARGET} PUBLIC
$<BUILD_INTERFACE:${_MOONCAKE_UBDIAG_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${_MOONCAKE_UBDIAG_SOURCE_DIR}/src>)
endif()
endforeach()

if(TARGET ubdiag)
target_include_directories(ubdiag PRIVATE
${_MOONCAKE_UBDIAG_SOURCE_DIR}/include
${_MOONCAKE_UBDIAG_SOURCE_DIR}/src
${_MOONCAKE_UBDIAG_SOURCE_DIR}/src/cli)
if(MOONCAKE_UBDIAG_BUILD_CLI AND NOT TARGET mooncake_ubdiag_cli)
add_custom_target(mooncake_ubdiag_cli ALL DEPENDS ubdiag)
endif()
elseif(MOONCAKE_UBDIAG_BUILD_CLI)
message(WARNING "UbDiag: extern/ubdiag does not define the ubdiag CLI target")
endif()

add_library(UbDiag::ubdiag_lib ALIAS ubdiag_lib)
_mooncake_ubdiag_write_rpm_manifest(
"submodule"
"${CMAKE_BINARY_DIR}/extern/ubdiag_build/src/cli/ubdiag"
"${CMAKE_BINARY_DIR}/extern/ubdiag_build/src/sdk/libubdiag.so"
"${CMAKE_SOURCE_DIR}/extern/ubdiag/config/ubdiag.conf.example")
message(STATUS "UbDiag: using submodule (extern/ubdiag, CLI=${MOONCAKE_UBDIAG_BUILD_CLI})")
return()
endif()
endif()

# Layer 2: System package — only search standard system library paths
# Using NO_DEFAULT_PATH + explicit PATHS to prevent cmake from recursively
# searching CMAKE_SYSTEM_PREFIX_PATH subdirectories (e.g., UbDiag_bak, build artifacts)
if(NOT MOONCAKE_UBDIAG_DISABLE_SYSTEM)
find_package(UbDiag QUIET
NO_DEFAULT_PATH
PATHS
/usr/lib64/cmake
/usr/local/lib64/cmake
/usr/lib/cmake
/usr/local/lib/cmake)
if(TARGET UbDiag::ubdiag_lib)
_mooncake_ubdiag_get_imported_location(UbDiag::ubdiag_lib _MOONCAKE_UBDIAG_SYSTEM_LIBRARY)

set(_MOONCAKE_UBDIAG_CLI_HINTS)
set(_MOONCAKE_UBDIAG_CONFIG_HINTS)
if(_MOONCAKE_UBDIAG_SYSTEM_LIBRARY)
get_filename_component(_MOONCAKE_UBDIAG_SYSTEM_LIB_DIR
"${_MOONCAKE_UBDIAG_SYSTEM_LIBRARY}" DIRECTORY)
get_filename_component(_MOONCAKE_UBDIAG_SYSTEM_PREFIX
"${_MOONCAKE_UBDIAG_SYSTEM_LIB_DIR}/.." ABSOLUTE)
list(APPEND _MOONCAKE_UBDIAG_CLI_HINTS
"${_MOONCAKE_UBDIAG_SYSTEM_PREFIX}/bin")
list(APPEND _MOONCAKE_UBDIAG_CONFIG_HINTS
"${_MOONCAKE_UBDIAG_SYSTEM_PREFIX}/etc/ubdiag")
endif()

find_program(MOONCAKE_UBDIAG_SYSTEM_CLI
NAMES ubdiag
HINTS ${_MOONCAKE_UBDIAG_CLI_HINTS}
PATHS /usr/bin /usr/local/bin
NO_DEFAULT_PATH)
if(MOONCAKE_UBDIAG_SYSTEM_CLI
AND NOT MOONCAKE_UBDIAG_SYSTEM_CLI MATCHES "-NOTFOUND$")
set(_MOONCAKE_UBDIAG_SYSTEM_CLI "${MOONCAKE_UBDIAG_SYSTEM_CLI}")
if(MOONCAKE_UBDIAG_BUILD_CLI AND NOT TARGET UbDiag::ubdiag_cli)
add_executable(UbDiag::ubdiag_cli IMPORTED GLOBAL)
set_target_properties(UbDiag::ubdiag_cli PROPERTIES
IMPORTED_LOCATION "${_MOONCAKE_UBDIAG_SYSTEM_CLI}")
endif()
if(MOONCAKE_UBDIAG_BUILD_CLI AND NOT TARGET mooncake_ubdiag_cli)
add_custom_target(mooncake_ubdiag_cli ALL
DEPENDS "${_MOONCAKE_UBDIAG_SYSTEM_CLI}")
endif()
else()
set(_MOONCAKE_UBDIAG_SYSTEM_CLI "")
if(MOONCAKE_UBDIAG_BUILD_CLI)
message(WARNING "UbDiag: system package found, but ubdiag CLI was not found under standard system paths")
endif()
endif()

find_file(MOONCAKE_UBDIAG_SYSTEM_CONFIG
NAMES ubdiag.conf
HINTS ${_MOONCAKE_UBDIAG_CONFIG_HINTS}
PATHS /etc/ubdiag /usr/local/etc/ubdiag
NO_DEFAULT_PATH)
if(MOONCAKE_UBDIAG_SYSTEM_CONFIG
AND NOT MOONCAKE_UBDIAG_SYSTEM_CONFIG MATCHES "-NOTFOUND$")
set(_MOONCAKE_UBDIAG_SYSTEM_CONFIG "${MOONCAKE_UBDIAG_SYSTEM_CONFIG}")
else()
set(_MOONCAKE_UBDIAG_SYSTEM_CONFIG "")
endif()

_mooncake_ubdiag_write_rpm_manifest(
"system"
"${_MOONCAKE_UBDIAG_SYSTEM_CLI}"
"${_MOONCAKE_UBDIAG_SYSTEM_LIBRARY}"
"${_MOONCAKE_UBDIAG_SYSTEM_CONFIG}")
message(STATUS "UbDiag: using system package (CLI=${_MOONCAKE_UBDIAG_SYSTEM_CLI})")
return()
endif()
endif()

# Layer 3: Mock fallback (no-op PerfPoint, guarantees compilation)
add_library(ubdiag_mock INTERFACE)
target_include_directories(
ubdiag_mock INTERFACE ${CMAKE_SOURCE_DIR}/mooncake-common/ubdiag-mock)
add_library(UbDiag::ubdiag_lib ALIAS ubdiag_mock)
_mooncake_ubdiag_write_rpm_manifest("mock" "" "" "")
message(STATUS "UbDiag: using mock (no-op PerfPoint)")
1 change: 0 additions & 1 deletion mooncake-common/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ option(USE_UB "option for using UB protocol transport" OFF)
option(USE_SUNRISE "option for enabling gpu features for Sunrise GPU with Tang runtime" OFF)

if (USE_UB)
add_compile_definitions(USE_UB)
message(STATUS "ub transport is enabled")
include(${CMAKE_CURRENT_LIST_DIR}/FindUrma.cmake)
endif()
Expand Down
Loading
Loading