From 4ac57ffdf75c6b65e6d2de65327e892dd3a7d47e Mon Sep 17 00:00:00 2001 From: fly_1997 Date: Sat, 28 Dec 2024 00:48:47 +0800 Subject: [PATCH] fix some bugs (cherry picked from commit 0361f09ca97a26333b5d898a6d52cc4f9da716d1) --- ...he-method-of-obtaining-cpu-frequency.patch | 262 ++++++++ 0006-update-compilation-options.patch | 614 ++++++++++++++++++ 0007-fix-build-script.patch | 35 + 0008-fix-memory-leak-plugin-type.patch | 279 ++++++++ 0009-every-sdk-process-use-diff-sock.patch | 45 ++ 0010-fix-enable_list-load-error.patch | 34 + 0011-fix-instance-nullptr.patch | 49 ++ oeAware-manager.spec | 17 +- 8 files changed, 1333 insertions(+), 2 deletions(-) create mode 100644 0005-modify-the-method-of-obtaining-cpu-frequency.patch create mode 100644 0006-update-compilation-options.patch create mode 100644 0007-fix-build-script.patch create mode 100644 0008-fix-memory-leak-plugin-type.patch create mode 100644 0009-every-sdk-process-use-diff-sock.patch create mode 100644 0010-fix-enable_list-load-error.patch create mode 100644 0011-fix-instance-nullptr.patch diff --git a/0005-modify-the-method-of-obtaining-cpu-frequency.patch b/0005-modify-the-method-of-obtaining-cpu-frequency.patch new file mode 100644 index 0000000..f86c4d7 --- /dev/null +++ b/0005-modify-the-method-of-obtaining-cpu-frequency.patch @@ -0,0 +1,262 @@ +From 781dccda979b392cb6dc8f9b3e65bbf5f0b99373 Mon Sep 17 00:00:00 2001 +From: zhaolichang +Date: Mon, 9 Dec 2024 11:53:48 +0800 +Subject: [PATCH 1/7] modify the method of obtaining cpu frequency + +1. use dmidecode to obtain cpu frequency when cpufreq file does not exist +2. merge duplicate code in cpu frequency +--- + include/oeaware/utils.h | 2 + + src/common/utils.cpp | 51 +++++++++++++++++++ + src/plugin/scenario/analysis/analysis/env.cpp | 39 ++++++-------- + src/plugin/scenario/analysis/analysis/env.h | 1 + + src/plugin/tune/docker/cpu_burst.cpp | 37 ++++++-------- + src/plugin/tune/docker/cpu_burst.h | 1 + + 6 files changed, 87 insertions(+), 44 deletions(-) + +diff --git a/include/oeaware/utils.h b/include/oeaware/utils.h +index 98e9c5c..48fc7af 100644 +--- a/include/oeaware/utils.h ++++ b/include/oeaware/utils.h +@@ -32,6 +32,8 @@ std::vector SplitString(const std::string &str, const std::string & + bool CreateDir(const std::string &path); + bool SetDataListTopic(DataList *dataList, const std::string &instanceName, const std::string &topicName, + const std::string ¶ms); ++uint64_t GetCpuCycles(int cpu); ++uint64_t GetCpuFreqByDmi(); + } + + #endif +\ No newline at end of file +diff --git a/src/common/utils.cpp b/src/common/utils.cpp +index 8f63a70..79bdc49 100644 +--- a/src/common/utils.cpp ++++ b/src/common/utils.cpp +@@ -17,6 +17,8 @@ + #include + #include + #include ++#include ++#include + + namespace oeaware { + const static int ST_MODE_MASK = 0777; +@@ -201,4 +203,53 @@ bool SetDataListTopic(DataList *dataList, const std::string &instanceName, const + return true; + } + ++uint64_t GetCpuCycles(int cpu) ++{ ++ std::string freqPath = "/sys/devices/system/cpu/cpu" + std::to_string(cpu) + "/cpufreq/scaling_cur_freq"; ++ std::ifstream freqFile(freqPath); ++ ++ if (!freqFile.is_open()) { ++ return 0; ++ } ++ ++ uint64_t freq; ++ freqFile >> freq; ++ freqFile.close(); ++ ++ if (freqFile.fail()) { ++ return 0; ++ } ++ ++ return freq * 1000; // 1000: kHz to Hz ++} ++ ++uint64_t GetCpuFreqByDmi() ++{ ++ FILE *pipe = popen("dmidecode -t processor | grep 'Max Speed' | head -n 1 | awk '{print $3}'", "r"); ++ if (!pipe) { ++ std::cout << "failed to run dmidecode" << std::endl; ++ return 0; ++ } ++ ++ char buffer[128]; ++ if (fgets(buffer, sizeof(buffer), pipe) == nullptr) { ++ std::cout << "failed to get cpufreq by dmidecode" << std::endl; ++ pclose(pipe); ++ return 0; ++ } ++ pclose(pipe); ++ ++ std::string str(buffer); ++ str.erase(str.find_last_not_of(" \t\n\r") + 1); ++ ++ for (char c : str) { ++ if (!std::isdigit(c)) { ++ std::cerr << "invalid CPU frequency format: " << str << std::endl; ++ return 0; ++ } ++ } ++ ++ return std::stoull(buffer) * 1000000; // 1000000: MHz to Hz ++} ++ + } +diff --git a/src/plugin/scenario/analysis/analysis/env.cpp b/src/plugin/scenario/analysis/analysis/env.cpp +index a3a5457..63d352f 100644 +--- a/src/plugin/scenario/analysis/analysis/env.cpp ++++ b/src/plugin/scenario/analysis/analysis/env.cpp +@@ -13,7 +13,10 @@ + #include + #include + #include ++#include ++#include "oeaware/utils.h" + #include "env.h" ++ + unsigned long GetPageMask() + { + static unsigned long pageMask = 0; +@@ -29,32 +32,17 @@ unsigned long GetPageMask() + return pageMask; + } + +-static uint64_t GetCpuCycles(int cpu) +-{ +- std::string freqPath = "/sys/devices/system/cpu/cpu" + std::to_string(cpu) + "/cpufreq/scaling_cur_freq"; +- std::ifstream freqFile(freqPath); +- +- if (!freqFile.is_open()) { +- return 0; +- } +- +- uint64_t freq; +- freqFile >> freq; +- freqFile.close(); +- +- if (freqFile.fail()) { +- return 0; +- } +- +- return freq * 1000; // 1000: kHz to Hz +-} +- +-static void InitCpuCycles(std::vector &maxCycles, uint64_t &sysMaxCycles) ++static void InitCpuCycles(std::vector &maxCycles, uint64_t &sysMaxCycles, uint64_t &maxCpuFreqByDmi) + { + for (int cpu = 0; cpu < maxCycles.size(); cpu++) { +- maxCycles[cpu] = GetCpuCycles(cpu); ++ maxCycles[cpu] = oeaware::GetCpuCycles(cpu); + sysMaxCycles += maxCycles[cpu]; + } ++ ++ if (sysMaxCycles <= 0) { ++ std::cout << "use dmidecode to obtain cpu frequency" << std::endl; ++ sysMaxCycles = maxCpuFreqByDmi * maxCycles.size(); ++ } + } + + bool Env::Init() +@@ -64,6 +52,7 @@ bool Env::Init() + } + numaNum = numa_num_configured_nodes(); + cpuNum = sysconf(_SC_NPROCESSORS_CONF); ++ maxCpuFreqByDmi = oeaware::GetCpuFreqByDmi(); + cpu2Node.resize(cpuNum, -1); + struct bitmask *cpumask = numa_allocate_cpumask(); + for (int nid = 0; nid < numaNum; ++nid) { +@@ -80,7 +69,11 @@ bool Env::Init() + pageMask = GetPageMask(); + InitDistance(); + cpuMaxCycles.resize(cpuNum, 0); +- InitCpuCycles(cpuMaxCycles, sysMaxCycles); ++ InitCpuCycles(cpuMaxCycles, sysMaxCycles, maxCpuFreqByDmi); ++ if (sysMaxCycles <= 0) { ++ std::cout << "failed to get sysMaxCycles" << std::endl; ++ return false; ++ } + initialized = true; + return true; + } +diff --git a/src/plugin/scenario/analysis/analysis/env.h b/src/plugin/scenario/analysis/analysis/env.h +index f75f035..28b21f4 100644 +--- a/src/plugin/scenario/analysis/analysis/env.h ++++ b/src/plugin/scenario/analysis/analysis/env.h +@@ -36,6 +36,7 @@ public: + int cpuNum; + unsigned long pageMask = 0; + uint64_t sysMaxCycles = 0; ++ uint64_t maxCpuFreqByDmi; + std::vector cpu2Node; + std::vector> distance; + std::vector cpuMaxCycles; // per second +diff --git a/src/plugin/tune/docker/cpu_burst.cpp b/src/plugin/tune/docker/cpu_burst.cpp +index 58b41dd..1e60fb9 100644 +--- a/src/plugin/tune/docker/cpu_burst.cpp ++++ b/src/plugin/tune/docker/cpu_burst.cpp +@@ -14,6 +14,7 @@ + #include + #include + #include "oeaware/data/pmu_counting_data.h" ++#include "oeaware/utils.h" + + constexpr double NINETY_PERCENT = 0.9; + constexpr int MILLISECONDS_IN_SECOND = 1000; +@@ -35,34 +36,28 @@ static void SetCfsBurstUs(const std::string &id, int cfsBurstUs) + return; + } + +-static uint64_t GetCpuCycles(int cpu) ++bool CpuBurst::Init() + { +- std::string freq_path = "/sys/devices/system/cpu/cpu" + std::to_string(cpu) + "/cpufreq/scaling_cur_freq"; +- std::ifstream freq_file(freq_path); ++ curSysCycles = 0; ++ maxCpuFreqByDmi = oeaware::GetCpuFreqByDmi(); + +- if (!freq_file.is_open()) { +- return 0; ++ cpuNum = sysconf(_SC_NPROCESSORS_CONF); ++ if (cpuNum <= 0) { ++ std::cout << "can not get cpu num" << std::endl; ++ return false; + } + +- uint64_t freq; +- freq_file >> freq; +- freq_file.close(); +- +- if (freq_file.fail()) { +- return 0; ++ for (unsigned int i = 0; i < cpuNum; i++) { ++ maxSysCycles += oeaware::GetCpuCycles(i); + } + +- return freq * 1000; // 1000: kHz to Hz +-} +- +-bool CpuBurst::Init() +-{ +- curSysCycles = 0; +- cpuNum = sysconf(_SC_NPROCESSORS_CONF); +- for (unsigned int i = 0; i < cpuNum; i++) { +- maxSysCycles += GetCpuCycles(i); ++ if (maxSysCycles <= 0) { ++ std::cout << "use dmidecode to obtain cpu frequency" << std::endl; ++ maxSysCycles = maxCpuFreqByDmi * cpuNum; + } +- if (cpuNum <= 0 || maxSysCycles <= 0) { ++ ++ if (maxSysCycles <= 0) { ++ std::cout << "can not get cpu frequency" << std::endl; + return false; + } + return true; +diff --git a/src/plugin/tune/docker/cpu_burst.h b/src/plugin/tune/docker/cpu_burst.h +index b485747..8ed7fae 100644 +--- a/src/plugin/tune/docker/cpu_burst.h ++++ b/src/plugin/tune/docker/cpu_burst.h +@@ -49,6 +49,7 @@ private: + unsigned int cpuNum = 0; + uint64_t maxSysCycles = 0; // per second + uint64_t curSysCycles = 0; ++ uint64_t maxCpuFreqByDmi; + std::unordered_map containers; + void UpdatePmu(const DataList &dataList); + void UpdateDocker(const DataList &dataList); +-- +2.33.0 + diff --git a/0006-update-compilation-options.patch b/0006-update-compilation-options.patch new file mode 100644 index 0000000..efb0b30 --- /dev/null +++ b/0006-update-compilation-options.patch @@ -0,0 +1,614 @@ +From 48cc5e2163281db23640fa87321b22cadcd69aa0 Mon Sep 17 00:00:00 2001 +From: fly_1997 +Date: Mon, 23 Dec 2024 18:46:18 +0800 +Subject: [PATCH 2/7] update compilation options + +--- + CMakeLists.txt | 20 +++++++++- + build.sh | 40 +++++++++++++++---- + install.sh | 4 +- + src/client/CMakeLists.txt | 8 ++-- + src/common/CMakeLists.txt | 11 ++--- + src/plugin/CMakeLists.txt | 7 ++-- + src/plugin/collect/docker/CMakeLists.txt | 7 ++-- + src/plugin/collect/pmu/CMakeLists.txt | 15 ++----- + src/plugin/collect/system/CMakeLists.txt | 9 +++-- + src/plugin/scenario/analysis/CMakeLists.txt | 9 ++--- + .../scenario/thread_aware/CMakeLists.txt | 8 +++- + src/plugin/tune/docker/CMakeLists.txt | 17 +++----- + src/plugin/tune/system/CMakeLists.txt | 11 ++--- + .../system/cpu/stealtask_tune/CMakeLists.txt | 7 ---- + .../system/network/smc_tune/CMakeLists.txt | 8 ---- + .../network/smc_tune/kprobe/CMakeLists.txt | 2 - + .../system/power/seep_tune/CMakeLists.txt | 8 ---- + src/plugin/tune/system/xcall/CMakeLists.txt | 8 ---- + src/plugin/tune/unixbench/CMakeLists.txt | 13 +++--- + src/plugin_mgr/CMakeLists.txt | 12 +++--- + src/sdk/CMakeLists.txt | 7 +++- + tests/CMakeLists.txt | 4 +- + 22 files changed, 114 insertions(+), 121 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c6a435e..162ff58 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -2,15 +2,33 @@ cmake_minimum_required(VERSION 3.16) + + project(oeAware-manager) + ++set(CMAKE_CXX_STANDARD 14) ++set(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -fPIC") + set(SDK_OUTPUT_LIBRARY_DIRECTORY ${CMAKE_BINARY_DIR}/output/sdk) + set(SDK_INC_PATH ${CMAKE_CURRENT_LIST_DIR}/src/sdk) + ++if (WITH_ASAN) ++ message(STATUS "enable asan") ++ function(enable_asan target) ++ add_compile_options(-fsanitize=address) ++ target_link_libraries(${target} asan) ++ endfunction() ++endif() ++ ++if (WITH_OPTIMIZATION) ++ message(STATUS "add_compile_options(-O2)") ++ add_compile_options(-O2) ++endif() ++ ++message(STATUS "C Flags: ${CMAKE_C_FLAGS}") ++message(STATUS "CXX Flags: ${CMAKE_CXX_FLAGS}") ++ + add_subdirectory(src/common) + add_subdirectory(src/plugin) + add_subdirectory(src/plugin_mgr) + add_subdirectory(src/client) + add_subdirectory(src/sdk) +-if (BUILD_TEST) ++if (WITH_TEST) + add_subdirectory(tests) + endif() + +diff --git a/build.sh b/build.sh +index c405645..bd99758 100644 +--- a/build.sh ++++ b/build.sh +@@ -7,18 +7,25 @@ os_arch=$(uname -m) + libkperf_version="v1.2.1" # only for build_kperf_by_src=ON + build_kperf_by_src="ON" + build_test="OFF" +- ++with_debug="OFF" ++with_asan="OFF" ++with_optimization="OFF" ++params="kperfrpm,help,test,with_asan,with_optimization,debug,release" + function usage() { + echo "" + echo "usage: build.sh [OPTIONS] [ARGS]" + echo "" + echo "The most commonly used build.sh options are:" +- echo " -k |--kperfrpm not build with libkperf by source code" +- echo " -t |--test build tests case" +- echo " -h |--help show usage" ++ echo " -k |--kperfrpm not build with libkperf by source code" ++ echo " -t |--test build tests case" ++ echo " --with_asan open AddressSanitizer compilation option" ++ echo " --with_optimization open optimization compilation option" ++ echo " --debug compile the debug version" ++ echo " --release compile the release version" ++ echo " -h |--help show usage" + } + +-options=$(getopt -o kht --long kperfrpm,help,test -- "$@") ++options=$(getopt -o kht --long ${params} -- "$@") + eval set -- "$options" + while true; do + case "$1" in +@@ -27,7 +34,25 @@ while true; do + shift + ;; + -t|--test) +- build_test="ON" ++ with_test="ON" ++ shift ++ ;; ++ --debug) ++ with_test="ON" ++ with_debug="ON" ++ with_optimization="OFF" ++ shift ++ ;; ++ --release) ++ with_optimization="ON" ++ shift ++ ;; ++ --with_asan) ++ with_asan="ON" ++ shift ++ ;; ++ --with_optimization) ++ with_optimization="ON" + shift + ;; + -h|--help) +@@ -69,5 +94,6 @@ fi + + + cmake .. -DLIB_KPERF_LIBPATH=${libkperf_lib} -DLIB_KPERF_INCPATH=${script_dir}/include/oeaware/data \ +- -DBUILD_TEST=${build_test} ++ -DWITH_TEST=${build_test} -DWITH_DEBUG=${with_debug} -DWITH_ASAN=${with_asan} \ ++ -DWITH_OPTIMIZATION=${with_optimization} + make -j$(nproc) +\ No newline at end of file +diff --git a/install.sh b/install.sh +index afa01f2..55cca48 100644 +--- a/install.sh ++++ b/install.sh +@@ -1,8 +1,8 @@ + mkdir -p /usr/include/oeaware + cp -r build/output/include/* /usr/include/ + cp -r build/output/bin/* /bin/ +-mkdir -p /etc/oeaware +-cp config.yaml /etc/oeaware ++mkdir -p /etc/oeAware ++cp config.yaml /etc/oeAware + cp build/output/sdk/liboeaware-sdk.so /lib64 + + mkdir -p /lib64/oeAware-plugin +diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt +index f16bde1..72c2cce 100644 +--- a/src/client/CMakeLists.txt ++++ b/src/client/CMakeLists.txt +@@ -1,8 +1,5 @@ +-cmake_minimum_required (VERSION 3.16) + project(oeAware-client) + +-SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -O2 -Wall -Wextra") +- + add_subdirectory(analysis) + + aux_source_directory(. SOURCE) +@@ -11,5 +8,10 @@ target_include_directories(oeawarectl PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/analysis + ${CMAKE_CURRENT_SOURCE_DIR}/../common + ) ++ ++if (WITH_ASAN) ++ enable_asan(oeawarectl) ++endif() ++ + target_link_libraries(oeawarectl analysis_cli common boundscheck) + set_target_properties(oeawarectl PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/output/bin") +diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt +index d6bbd58..a1741bc 100644 +--- a/src/common/CMakeLists.txt ++++ b/src/common/CMakeLists.txt +@@ -1,18 +1,11 @@ +-cmake_minimum_required (VERSION 3.16) + project(common) + + aux_source_directory(. SOURCE) +-SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -fPIC -O2") + +- +-include_directories(/usr/include/yaml-cpp) + include_directories(/usr/include/log4cplus) + include_directories(../plugin/collect/include) + include_directories(../plugin/scenario/include) + include_directories(${LIB_KPERF_INCPATH}) +-include_directories(/usr/include/curl) +- +-link_directories(/usr/lib64) + + add_library(${PROJECT_NAME} + ${SOURCE} +@@ -22,6 +15,10 @@ target_link_libraries(${PROJECT_NAME} log4cplus) + target_link_libraries(${PROJECT_NAME} yaml-cpp) + target_link_libraries(${PROJECT_NAME} curl boundscheck) + ++if (WITH_ASAN) ++ enable_asan(${PROJECT_NAME}) ++endif() ++ + if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") + target_link_directories(${PROJECT_NAME} PUBLIC + ${LIB_KPERF_LIBPATH} +diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt +index 450c933..a4ee240 100644 +--- a/src/plugin/CMakeLists.txt ++++ b/src/plugin/CMakeLists.txt +@@ -1,4 +1,3 @@ +- + include_directories( + ${CMAKE_SOURCE_DIR}/include + ) +@@ -15,9 +14,9 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") + endif() + add_subdirectory(collect/system) + +- if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") +- add_subdirectory(scenario/analysis) +- endif() ++if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") ++ add_subdirectory(scenario/analysis) ++endif() + add_subdirectory(scenario/thread_aware) + + add_subdirectory(tune/system) +diff --git a/src/plugin/collect/docker/CMakeLists.txt b/src/plugin/collect/docker/CMakeLists.txt +index cdde00f..5e1760d 100644 +--- a/src/plugin/collect/docker/CMakeLists.txt ++++ b/src/plugin/collect/docker/CMakeLists.txt +@@ -1,9 +1,10 @@ +-cmake_minimum_required(VERSION 3.11) + project(docker_collector) +-add_compile_options(-O2 -fPIC -Wall -Wextra) + add_library(docker_collector SHARED + docker_adapt.cpp + docker_collector.cpp + ) ++if (WITH_ASAN) ++ enable_asan(docker_collector) ++endif() + set_target_properties(docker_collector PROPERTIES +- LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +\ No newline at end of file ++ LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +diff --git a/src/plugin/collect/pmu/CMakeLists.txt b/src/plugin/collect/pmu/CMakeLists.txt +index 000e26e..cb2870b 100644 +--- a/src/plugin/collect/pmu/CMakeLists.txt ++++ b/src/plugin/collect/pmu/CMakeLists.txt +@@ -1,16 +1,5 @@ +-cmake_minimum_required(VERSION 3.15) + project(pmu_plugin) + +-set(CMAKE_CXX_STANDARD 14) +- +-option(WITH_DEBUG "debug mode" OFF) +- +-if (WITH_DEBUG) +- message("-- Note:pmu debug mode") +- add_compile_options(-g) +-endif() +-add_compile_options(-O2 -fPIC -Wall -Wextra -g) +- + # libkperf + message("-- libkperf library path: ${LIB_KPERF_LIBPATH}") + message("-- libkperf include path: ${LIB_KPERF_INCPATH}") +@@ -35,6 +24,10 @@ target_link_directories(pmu PUBLIC + ${LIB_KPERF_LIBPATH} + ) + ++if (WITH_ASAN) ++ enable_asan(pmu) ++endif() ++ + target_link_libraries(pmu boundscheck kperf) + set_target_properties(pmu PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +diff --git a/src/plugin/collect/system/CMakeLists.txt b/src/plugin/collect/system/CMakeLists.txt +index 3ec2358..7f832e5 100644 +--- a/src/plugin/collect/system/CMakeLists.txt ++++ b/src/plugin/collect/system/CMakeLists.txt +@@ -1,7 +1,5 @@ +-cmake_minimum_required(VERSION 3.11) + project(system_collector) + include_directories(command) +-add_compile_options(-O2 -fPIC -Wall -Wextra) + add_library(system_collector SHARED + thread_collector.cpp + system_collector.cpp +@@ -12,6 +10,11 @@ add_library(system_collector SHARED + ) + target_include_directories(system_collector PUBLIC ${CMAKE_SOURCE_DIR}/include) + target_include_directories(system_collector PRIVATE ${CMAKE_SOURCE_DIR}/src/common) ++ ++if (WITH_ASAN) ++ enable_asan(system_collector) ++endif() ++ + target_link_libraries(system_collector common) + set_target_properties(system_collector PROPERTIES +- LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +\ No newline at end of file ++ LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +diff --git a/src/plugin/scenario/analysis/CMakeLists.txt b/src/plugin/scenario/analysis/CMakeLists.txt +index 4cfe525..46fff34 100644 +--- a/src/plugin/scenario/analysis/CMakeLists.txt ++++ b/src/plugin/scenario/analysis/CMakeLists.txt +@@ -1,5 +1,3 @@ +-cmake_minimum_required(VERSION 3.15) +- + project(analysis) + message("-- libkperf library path: ${LIB_KPERF_LIBPATH}") + message("-- libkperf include path: ${LIB_KPERF_INCPATH}") +@@ -11,19 +9,20 @@ set(analysis_src + + set(oeaware_src adapt/analysis_aware.cpp) + +-add_compile_options(-g -fPIC -Wall -Wextra -O2) +- + add_library(analysis_base OBJECT ${analysis_src}) + target_include_directories(analysis_base PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/analysis + ${LIB_KPERF_INCPATH} + ) + +- + target_link_libraries(analysis_base numa boundscheck) + + add_library(analysis_oeaware SHARED ${oeaware_src}) + ++if (WITH_ASAN) ++ enable_asan(analysis_oeaware) ++endif() ++ + target_link_libraries(analysis_oeaware analysis_base) + set_target_properties(analysis_oeaware PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +\ No newline at end of file +diff --git a/src/plugin/scenario/thread_aware/CMakeLists.txt b/src/plugin/scenario/thread_aware/CMakeLists.txt +index 01395e5..7e91f20 100644 +--- a/src/plugin/scenario/thread_aware/CMakeLists.txt ++++ b/src/plugin/scenario/thread_aware/CMakeLists.txt +@@ -1,10 +1,14 @@ +-cmake_minimum_required(VERSION 3.11) + project(thread_scenario) +-add_compile_options(-O2 -fPIC -Wall -Wextra) ++ + add_library(thread_scenario SHARED + thread_aware.cpp + ) + target_include_directories(thread_scenario PUBLIC ${CMAKE_SOURCE_DIR}/include) ++ ++if (WITH_ASAN) ++ enable_asan(thread_scenario) ++endif() ++ + set_target_properties(thread_scenario PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/thread_scenario.conf" +diff --git a/src/plugin/tune/docker/CMakeLists.txt b/src/plugin/tune/docker/CMakeLists.txt +index a41465a..27115dc 100644 +--- a/src/plugin/tune/docker/CMakeLists.txt ++++ b/src/plugin/tune/docker/CMakeLists.txt +@@ -1,16 +1,5 @@ +-cmake_minimum_required(VERSION 3.11) +- + project(docker_tune) + +-if (WITH_DEBUG) +- add_compile_options(-g) +-else() +- add_compile_options(-O2) +-endif() +-add_compile_options(-fPIC -Wall -Wextra) +- +-message("-- libkperf include path: ${LIB_KPERF_INCPATH}") +- + add_library(docker_tune SHARED + cpu_burst.cpp + cpu_burst_adapt.cpp +@@ -21,5 +10,9 @@ include_directories(docker_tune PUBLIC + ${LIB_KPERF_INCPATH} + ) + ++if (WITH_ASAN) ++ enable_asan(docker_tune) ++endif() ++ + set_target_properties(docker_tune PROPERTIES +- LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +\ No newline at end of file ++ LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) +diff --git a/src/plugin/tune/system/CMakeLists.txt b/src/plugin/tune/system/CMakeLists.txt +index 8beeb4d..8f8d0a2 100644 +--- a/src/plugin/tune/system/CMakeLists.txt ++++ b/src/plugin/tune/system/CMakeLists.txt +@@ -1,13 +1,5 @@ +-cmake_minimum_required(VERSION 3.11) + project(system_tune) + +-if (WITH_DEBUG) +- add_compile_options(-g) +-else() +- add_compile_options(-O2) +-endif() +-add_compile_options(-fPIC -Wall -Wextra) +- + add_subdirectory(cpu/stealtask_tune) + add_subdirectory(network/smc_tune) + add_subdirectory(xcall) +@@ -16,6 +8,9 @@ add_subdirectory(power/seep_tune) + add_library(system_tune SHARED + system_tune.cpp) + ++if (WITH_ASAN) ++ enable_asan(system_tune) ++endif() + target_link_libraries(system_tune stealtask_tune smc_tune xcall_tune seep_tune) + + set_target_properties(system_tune PROPERTIES +diff --git a/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt b/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt +index c311a01..9413716 100644 +--- a/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt ++++ b/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt +@@ -1,13 +1,6 @@ + cmake_minimum_required(VERSION 3.11) + project(stealtask_tune) + +-if (WITH_DEBUG) +- add_compile_options(-g) +-else() +- add_compile_options(-O2) +-endif() +-add_compile_options(-fPIC -Wall -Wextra) +- + add_library(stealtask_tune STATIC + stealtask_tune.cpp + ) +diff --git a/src/plugin/tune/system/network/smc_tune/CMakeLists.txt b/src/plugin/tune/system/network/smc_tune/CMakeLists.txt +index 29bd449..6c81aff 100644 +--- a/src/plugin/tune/system/network/smc_tune/CMakeLists.txt ++++ b/src/plugin/tune/system/network/smc_tune/CMakeLists.txt +@@ -1,13 +1,5 @@ +-cmake_minimum_required(VERSION 3.11) + project(smc_tune) + +-if (WITH_DEBUG) +- add_compile_options(-g) +-else() +- add_compile_options(-O2) +-endif() +-add_compile_options(-fPIC -Wall -Wextra -Wno-unused-value -Wno-missing-field-initializers) +- + include_directories(/usr/include/libnl3) + + add_subdirectory(kprobe) +diff --git a/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt b/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt +index 5eb787a..e737eb6 100644 +--- a/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt ++++ b/src/plugin/tune/system/network/smc_tune/kprobe/CMakeLists.txt +@@ -1,5 +1,3 @@ +-cmake_minimum_required(VERSION 3.10) +- + # set module name + project(smc_acc) + +diff --git a/src/plugin/tune/system/power/seep_tune/CMakeLists.txt b/src/plugin/tune/system/power/seep_tune/CMakeLists.txt +index 92fb91b..080ff6a 100644 +--- a/src/plugin/tune/system/power/seep_tune/CMakeLists.txt ++++ b/src/plugin/tune/system/power/seep_tune/CMakeLists.txt +@@ -1,13 +1,5 @@ +-cmake_minimum_required(VERSION 3.11) + project(seep_tune) + +-if (WITH_DEBUG) +- add_compile_options(-g) +-else() +- add_compile_options(-O2) +-endif() +-add_compile_options(-fPIC -Wall -Wextra) +- + add_library(seep_tune STATIC + seep_tune.cpp + ) +diff --git a/src/plugin/tune/system/xcall/CMakeLists.txt b/src/plugin/tune/system/xcall/CMakeLists.txt +index 815a96e..d00f7c2 100644 +--- a/src/plugin/tune/system/xcall/CMakeLists.txt ++++ b/src/plugin/tune/system/xcall/CMakeLists.txt +@@ -1,13 +1,5 @@ +-cmake_minimum_required(VERSION 3.11) + project(xcall_tune) + +-if (WITH_DEBUG) +- add_compile_options(-g) +-else() +- add_compile_options(-O2) +-endif() +-add_compile_options(-fPIC -Wall -Wextra -Wno-unused-value -Wno-missing-field-initializers) +- + add_library(xcall_tune STATIC + xcall_tune.cpp + ) +diff --git a/src/plugin/tune/unixbench/CMakeLists.txt b/src/plugin/tune/unixbench/CMakeLists.txt +index dd6e934..55c34dd 100644 +--- a/src/plugin/tune/unixbench/CMakeLists.txt ++++ b/src/plugin/tune/unixbench/CMakeLists.txt +@@ -1,18 +1,15 @@ +-cmake_minimum_required(VERSION 3.11) + project(ub_tune) + +-if (WITH_DEBUG) +- add_compile_options(-g) +-else() +- add_compile_options(-O2) +-endif() +-add_compile_options(-fPIC -Wall -Wextra) +- + add_library(ub_tune SHARED + ub_tune.cpp + ) + + target_link_libraries(ub_tune numa) ++ ++if (WITH_ASAN) ++ enable_asan(ub_tune) ++endif() ++ + set_target_properties(ub_tune PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_OUTPUT_LIBRARY_DIRECTORY}) + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/ub_tune.conf" +diff --git a/src/plugin_mgr/CMakeLists.txt b/src/plugin_mgr/CMakeLists.txt +index a3f9dd1..90e410b 100644 +--- a/src/plugin_mgr/CMakeLists.txt ++++ b/src/plugin_mgr/CMakeLists.txt +@@ -1,12 +1,5 @@ +-cmake_minimum_required (VERSION 3.16) + project(oeAware-server) + +-SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -O2") +- +-if("${OEAWARE_DEBUG}" EQUAL 1) +-add_definitions(-DOEAWARE_DEBUG) +-endif() +- + aux_source_directory(. SOURCE) + aux_source_directory(event EVENT_SOURCE) + include_directories(/usr/include) +@@ -20,6 +13,11 @@ add_executable (oeaware + ${EVENT_SOURCE} + ) + target_link_libraries(oeaware common) ++ ++if (WITH_ASAN) ++ enable_asan(oeaware) ++endif() ++ + if (${CMAKE_CXX_COMPILER_VERSION} LESS "10.3.1") + target_link_libraries(oeaware -lpthread -ldl) + endif() +diff --git a/src/sdk/CMakeLists.txt b/src/sdk/CMakeLists.txt +index e362a1a..a6385aa 100644 +--- a/src/sdk/CMakeLists.txt ++++ b/src/sdk/CMakeLists.txt +@@ -1,12 +1,15 @@ +-cmake_minimum_required (VERSION 3.16) + project(oeaware-sdk) + + aux_source_directory(. SOURCE) +-SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now -Wall -Wextra -fPIC -O2") + + add_library(${PROJECT_NAME} SHARED + oe_client.cpp + ) ++ ++if (WITH_ASAN) ++ enable_asan(${PROJECT_NAME}) ++endif() ++ + target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include) + target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/common) + target_link_libraries(${PROJECT_NAME} common) +diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt +index 2a6afcd..11aa06d 100644 +--- a/tests/CMakeLists.txt ++++ b/tests/CMakeLists.txt +@@ -1,7 +1,5 @@ +-cmake_minimum_required(VERSION 3.16) + project(test) + set(SRC_DIR ../src) +-SET(CMAKE_CXX_FLAGS "-rdynamic -std=c++14 -g -Wl,-z,relro,-z,now") + + find_package(GTest CONFIG REQUIRED) + +@@ -30,7 +28,7 @@ add_executable(utils_test + ) + + add_executable(data_register_test +- data_register_test ++ data_register_test.cpp + ) + + target_link_libraries(serialize_test PRIVATE common GTest::gtest_main) +-- +2.33.0 + diff --git a/0007-fix-build-script.patch b/0007-fix-build-script.patch new file mode 100644 index 0000000..a6e1703 --- /dev/null +++ b/0007-fix-build-script.patch @@ -0,0 +1,35 @@ +From 7db535b57513318b0f9cb5d2bd844c0e636c42f1 Mon Sep 17 00:00:00 2001 +From: fly_1997 +Date: Mon, 23 Dec 2024 19:44:40 +0800 +Subject: [PATCH 3/7] fix build script + +--- + build.sh | 2 +- + src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt | 1 - + 2 files changed, 1 insertion(+), 2 deletions(-) + +diff --git a/build.sh b/build.sh +index bd99758..c47cdf8 100644 +--- a/build.sh ++++ b/build.sh +@@ -6,7 +6,7 @@ cd $script_dir/ + os_arch=$(uname -m) + libkperf_version="v1.2.1" # only for build_kperf_by_src=ON + build_kperf_by_src="ON" +-build_test="OFF" ++with_test="OFF" + with_debug="OFF" + with_asan="OFF" + with_optimization="OFF" +diff --git a/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt b/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt +index 9413716..10b6d9b 100644 +--- a/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt ++++ b/src/plugin/tune/system/cpu/stealtask_tune/CMakeLists.txt +@@ -1,4 +1,3 @@ +-cmake_minimum_required(VERSION 3.11) + project(stealtask_tune) + + add_library(stealtask_tune STATIC +-- +2.33.0 + diff --git a/0008-fix-memory-leak-plugin-type.patch b/0008-fix-memory-leak-plugin-type.patch new file mode 100644 index 0000000..0ba137a --- /dev/null +++ b/0008-fix-memory-leak-plugin-type.patch @@ -0,0 +1,279 @@ +From 5a961d309e0286d23f196e7afeab486a74bd09da Mon Sep 17 00:00:00 2001 +From: fly_1997 +Date: Wed, 25 Dec 2024 15:19:15 +0800 +Subject: [PATCH 4/7] fix memory leak, plugin type + +--- + src/common/data_register.cpp | 1 + + src/common/data_register.h | 2 +- + src/plugin/collect/docker/docker_adapt.cpp | 15 +++++++-------- + src/plugin/collect/docker/docker_adapt.h | 2 +- + src/plugin/collect/pmu/pmu_common.cpp | 2 ++ + src/plugin/collect/pmu/pmu_counting_collector.cpp | 3 ++- + src/plugin/collect/pmu/pmu_sampling_collector.cpp | 3 ++- + src/plugin/collect/pmu/pmu_uncore.cpp | 2 +- + src/plugin/collect/pmu/pmu_uncore_collector.cpp | 1 + + src/plugin/collect/system/thread_collector.cpp | 5 +++++ + src/plugin/tune/docker/cpu_burst.cpp | 12 ++++++------ + src/plugin/tune/docker/cpu_burst_adapt.cpp | 2 +- + src/plugin/tune/unixbench/ub_tune.cpp | 1 + + 13 files changed, 31 insertions(+), 20 deletions(-) + +diff --git a/src/common/data_register.cpp b/src/common/data_register.cpp +index df64ba5..f93556a 100644 +--- a/src/common/data_register.cpp ++++ b/src/common/data_register.cpp +@@ -152,6 +152,7 @@ void PmuBaseDataFree(void *data) + PmuDataFree(tmpData->pmuData); + tmpData->pmuData = nullptr; + tmpData->len = 0; ++ delete tmpData; + } + + int PmuCountingDataSerialize(const void *data, OutStream &out) +diff --git a/src/common/data_register.h b/src/common/data_register.h +index 2804ef5..477811e 100644 +--- a/src/common/data_register.h ++++ b/src/common/data_register.h +@@ -21,7 +21,7 @@ using SerializeFunc = int(*)(const void*, OutStream &out); + using DataFreeFunc = void(*)(void *); + + struct RegisterEntry { +- RegisterEntry() { } ++ RegisterEntry() : se(nullptr), de(nullptr), free(nullptr) { } + RegisterEntry(const SerializeFunc &se, const DeserializeFunc &de) : se(se), de(de), free(nullptr) { } + RegisterEntry(const SerializeFunc &se, const DeserializeFunc &de, const DataFreeFunc &free) : se(se), + de(de), free(free) { } +diff --git a/src/plugin/collect/docker/docker_adapt.cpp b/src/plugin/collect/docker/docker_adapt.cpp +index eab3270..1105db2 100644 +--- a/src/plugin/collect/docker/docker_adapt.cpp ++++ b/src/plugin/collect/docker/docker_adapt.cpp +@@ -45,6 +45,7 @@ DockerAdapt::DockerAdapt() + version = "1.0.0"; + period = PERIOD; + priority = PRIORITY; ++ type = 0; + + oeaware::Topic topic; + topic.instanceName = this->name; +@@ -97,7 +98,7 @@ void DockerAdapt::Run() + dataList.data = new void* [containers.size()]; + uint64_t i = 0; + for (auto &it : containers) { +- dataList.data[i++] = it.second; ++ dataList.data[i++] = &it.second; + } + dataList.len = i; + Publish(dataList); +@@ -108,8 +109,6 @@ void DockerAdapt::DockerUpdate(const std::unordered_set &directorie + // delete non-existent container + for (auto it = containers.begin(); it != containers.end();) { + if (directories.find(it->first) == directories.end()) { +- delete it->second; +- it->second = nullptr; + it = containers.erase(it); + } else { + ++it; +@@ -123,11 +122,11 @@ void DockerAdapt::DockerUpdate(const std::unordered_set &directorie + read_success &= GetContainersInfo(tmp.cfs_quota_us, dir, "cpu.cfs_quota_us"); + read_success &= GetContainersInfo(tmp.cfs_burst_us, dir, "cpu.cfs_burst_us"); + if (read_success) { +- Container* container = new Container(); +- container->cfs_period_us = tmp.cfs_period_us; +- container->cfs_quota_us = tmp.cfs_quota_us; +- container->cfs_burst_us = tmp.cfs_burst_us; +- container->id = dir; ++ Container container; ++ container.cfs_period_us = tmp.cfs_period_us; ++ container.cfs_quota_us = tmp.cfs_quota_us; ++ container.cfs_burst_us = tmp.cfs_burst_us; ++ container.id = dir; + containers[dir] = container; + } + } +diff --git a/src/plugin/collect/docker/docker_adapt.h b/src/plugin/collect/docker/docker_adapt.h +index 570a2a7..9db9c00 100644 +--- a/src/plugin/collect/docker/docker_adapt.h ++++ b/src/plugin/collect/docker/docker_adapt.h +@@ -33,6 +33,6 @@ private: + void DockerUpdate(const std::unordered_set &sub_dir); + void DockerCollect(); + bool openStatus = false; +- std::unordered_map containers; ++ std::unordered_map containers; + }; + #endif // OEAWARE_MANAGER_DOCKER_ADAPT_H +\ No newline at end of file +diff --git a/src/plugin/collect/pmu/pmu_common.cpp b/src/plugin/collect/pmu/pmu_common.cpp +index caf453a..28c71f0 100644 +--- a/src/plugin/collect/pmu/pmu_common.cpp ++++ b/src/plugin/collect/pmu/pmu_common.cpp +@@ -26,8 +26,10 @@ bool IsSupportPmu() + while (dent = readdir(dir)) { + std::string armPmuPath = DEVICES_PATH + dent->d_name + "/cpus"; + if (oeaware::FileExist(armPmuPath)) { ++ closedir(dir); + return true; + } + } ++ closedir(dir); + return false; + } +diff --git a/src/plugin/collect/pmu/pmu_counting_collector.cpp b/src/plugin/collect/pmu/pmu_counting_collector.cpp +index 281c61d..2b6c0b5 100644 +--- a/src/plugin/collect/pmu/pmu_counting_collector.cpp ++++ b/src/plugin/collect/pmu/pmu_counting_collector.cpp +@@ -62,6 +62,7 @@ int PmuCountingCollector::OpenCounting(const oeaware::Topic &topic) + errno_t ret = strcpy_s(evtList[0], topic.topicName.length() + 1, topic.topicName.c_str()); + if (ret != EOK) { + std::cout << topic.topicName << " open failed, reason: strcpy_s failed" << std::endl; ++ delete[] evtList[0]; + return -1; + } + attr.evtList = evtList; +@@ -71,7 +72,7 @@ int PmuCountingCollector::OpenCounting(const oeaware::Topic &topic) + if (pd == -1) { + std::cout << topic.topicName << " open failed" << std::endl; + } +- ++ delete[] evtList[0]; + return pd; + } + +diff --git a/src/plugin/collect/pmu/pmu_sampling_collector.cpp b/src/plugin/collect/pmu/pmu_sampling_collector.cpp +index b4cf037..6d4712e 100644 +--- a/src/plugin/collect/pmu/pmu_sampling_collector.cpp ++++ b/src/plugin/collect/pmu/pmu_sampling_collector.cpp +@@ -60,6 +60,7 @@ int PmuSamplingCollector::OpenSampling(const oeaware::Topic &topic) + errno_t ret = strcpy_s(evtList[0], topic.topicName.length() + 1, topic.topicName.c_str()); + if (ret != EOK) { + std::cout << topic.topicName << " open failed, reason: strcpy_s failed" << std::endl; ++ delete[] evtList[0]; + return -1; + } + attr.evtList = evtList; +@@ -75,7 +76,7 @@ int PmuSamplingCollector::OpenSampling(const oeaware::Topic &topic) + if (pd == -1) { + std::cout << topic.topicName << " open failed" << std::endl; + } +- ++ delete[] evtList[0]; + return pd; + } + +diff --git a/src/plugin/collect/pmu/pmu_uncore.cpp b/src/plugin/collect/pmu/pmu_uncore.cpp +index cf46121..66a6bf3 100644 +--- a/src/plugin/collect/pmu/pmu_uncore.cpp ++++ b/src/plugin/collect/pmu/pmu_uncore.cpp +@@ -128,7 +128,7 @@ int HhaUncoreConfigInit(void) + static void UncoreConfigFree(UncoreConfig *config) + { + if (config != nullptr) { +- delete config; ++ delete[] config; + config = nullptr; + } + } +diff --git a/src/plugin/collect/pmu/pmu_uncore_collector.cpp b/src/plugin/collect/pmu/pmu_uncore_collector.cpp +index 74c2901..3a2571f 100644 +--- a/src/plugin/collect/pmu/pmu_uncore_collector.cpp ++++ b/src/plugin/collect/pmu/pmu_uncore_collector.cpp +@@ -145,6 +145,7 @@ void PmuUncoreCollector::CloseTopic(const oeaware::Topic &topic) + } + PmuDisable(pmuId); + PmuClose(pmuId); ++ UncoreConfigFini(); + pmuId = -1; + } + +diff --git a/src/plugin/collect/system/thread_collector.cpp b/src/plugin/collect/system/thread_collector.cpp +index 10dfd27..f3439b6 100644 +--- a/src/plugin/collect/system/thread_collector.cpp ++++ b/src/plugin/collect/system/thread_collector.cpp +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include "data_register.h" + + ThreadCollector::ThreadCollector() + { +@@ -28,6 +29,7 @@ ThreadCollector::ThreadCollector() + version = "1.0.0"; + period = 500; + priority = 0; ++ type = 0; + oeaware::Topic topic; + topic.instanceName = this->name; + topic.topicName = this->name; +@@ -61,6 +63,9 @@ oeaware::Result ThreadCollector::Enable(const std::string ¶m) + void ThreadCollector::Disable() + { + openStatus = false; ++ for (auto &item : threads) { ++ oeaware::Register::GetInstance().GetDataFreeFunc(OE_THREAD_COLLECTOR)(item.second); ++ } + } + + void ThreadCollector::Run() +diff --git a/src/plugin/tune/docker/cpu_burst.cpp b/src/plugin/tune/docker/cpu_burst.cpp +index c351684..6c100b7 100644 +--- a/src/plugin/tune/docker/cpu_burst.cpp ++++ b/src/plugin/tune/docker/cpu_burst.cpp +@@ -91,10 +91,10 @@ void CpuBurst::UpdatePmu(const DataList &dataList) + + void CpuBurst::UpdateDocker(const DataList &dataList) + { +- std::unordered_map collector; ++ std::unordered_map collector; + for (uint64_t i = 0; i < dataList.len; i++) { + auto *tmp = (Container*)dataList.data[i]; +- collector[tmp->id] = tmp; ++ collector[tmp->id] = *tmp; + } + + for (const auto &container : collector) { +@@ -102,11 +102,11 @@ void CpuBurst::UpdateDocker(const DataList &dataList) + const auto &container_info = container.second; + if (containers.find(id) == containers.end()) { + containers[id].id = id; +- containers[id].cfs_burst_us_ori = container_info->cfs_burst_us; ++ containers[id].cfs_burst_us_ori = container_info.cfs_burst_us; + } +- containers[id].cfs_period_us = container_info->cfs_period_us; +- containers[id].cfs_quota_us = container_info->cfs_quota_us; +- containers[id].cfs_burst_us = container_info->cfs_burst_us; ++ containers[id].cfs_period_us = container_info.cfs_period_us; ++ containers[id].cfs_quota_us = container_info.cfs_quota_us; ++ containers[id].cfs_burst_us = container_info.cfs_burst_us; + } + + // remove containers +diff --git a/src/plugin/tune/docker/cpu_burst_adapt.cpp b/src/plugin/tune/docker/cpu_burst_adapt.cpp +index 822e0c5..0454b00 100644 +--- a/src/plugin/tune/docker/cpu_burst_adapt.cpp ++++ b/src/plugin/tune/docker/cpu_burst_adapt.cpp +@@ -27,7 +27,7 @@ CpuBurstAdapt::CpuBurstAdapt() + version = "1.0.0"; + period = PERIOD; + priority = PRIORITY; +- ++ type = oeaware::TUNE; + oeaware::Topic topic; + topic.instanceName = this->name; + topic.topicName = this->name; +diff --git a/src/plugin/tune/unixbench/ub_tune.cpp b/src/plugin/tune/unixbench/ub_tune.cpp +index a72e8e9..f71f226 100644 +--- a/src/plugin/tune/unixbench/ub_tune.cpp ++++ b/src/plugin/tune/unixbench/ub_tune.cpp +@@ -28,6 +28,7 @@ UnixBenchTune::UnixBenchTune() { + version = "1.0.0"; + period = 500; + priority = 2; ++ type = TUNE; + depTopic.instanceName = "thread_collector"; + depTopic.topicName = "thread_collector"; + } +-- +2.33.0 + diff --git a/0009-every-sdk-process-use-diff-sock.patch b/0009-every-sdk-process-use-diff-sock.patch new file mode 100644 index 0000000..6e1aeeb --- /dev/null +++ b/0009-every-sdk-process-use-diff-sock.patch @@ -0,0 +1,45 @@ +From b09067a9ecc9e9dea32244b99a5e65eb666f3567 Mon Sep 17 00:00:00 2001 +From: LHesperus <2639350497@qq.com> +Date: Thu, 26 Dec 2024 17:31:47 +0800 +Subject: [PATCH 5/7] every sdk process use diff sock + +--- + src/common/domain_socket.cpp | 1 + + src/sdk/oe_client.cpp | 3 ++- + 2 files changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/common/domain_socket.cpp b/src/common/domain_socket.cpp +index 57d8a55..8610cad 100644 +--- a/src/common/domain_socket.cpp ++++ b/src/common/domain_socket.cpp +@@ -78,5 +78,6 @@ void DomainSocket::Close() + { + close(sock); + sock = 0; ++ unlink(localPath.c_str()); + } + } +diff --git a/src/sdk/oe_client.cpp b/src/sdk/oe_client.cpp +index 9f24b27..55c9750 100644 +--- a/src/sdk/oe_client.cpp ++++ b/src/sdk/oe_client.cpp +@@ -88,6 +88,7 @@ void Impl::HandleRecv() + } + int Impl::Init() + { ++ pid_t pid = getpid(); + auto home = getenv("HOME"); + std::string homeDir; + if (home == nullptr) { +@@ -100,7 +101,7 @@ int Impl::Init() + CreateDir(homeDir); + isQuit = false; + finished = false; +- domainSocket = std::make_shared(homeDir + "/oeaware-sdk.sock"); ++ domainSocket = std::make_shared(homeDir + "/oeaware-sdk-" + std::to_string(pid) + ".sock"); + domainSocket->SetRemotePath(DEFAULT_SERVER_LISTEN_PATH); + resultQueue = std::make_shared>(); + int sock = domainSocket->Socket(); +-- +2.33.0 + diff --git a/0010-fix-enable_list-load-error.patch b/0010-fix-enable_list-load-error.patch new file mode 100644 index 0000000..7ad0f07 --- /dev/null +++ b/0010-fix-enable_list-load-error.patch @@ -0,0 +1,34 @@ +From b31b9d602bba1f43f3f6137a4e2707bd425bf2e5 Mon Sep 17 00:00:00 2001 +From: fly_1997 +Date: Fri, 27 Dec 2024 23:17:08 +0800 +Subject: [PATCH 6/7] fix enable_list load error + +--- + src/plugin_mgr/config.cpp | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/plugin_mgr/config.cpp b/src/plugin_mgr/config.cpp +index 0ac1fb0..4553c93 100644 +--- a/src/plugin_mgr/config.cpp ++++ b/src/plugin_mgr/config.cpp +@@ -61,13 +61,13 @@ void Config::SetEnableList(const YAML::Node &node) + std::string pluginName = enableList[i]["name"].as(); + YAML::Node instances = enableList[i]["instances"]; + EnableItem enableItem(pluginName); +- if (!instances.IsSequence()) { +- WARN(logger, "the format of the enable list is incorrect."); +- continue; +- } + if (!instances.IsDefined() || instances.IsNull()) { + enableItem.SetEnabled(true); + } else { ++ if (!instances.IsSequence()) { ++ WARN(logger, "the format of the enable list{" << pluginName << "} is incorrect."); ++ continue; ++ } + for (size_t j = 0; j < instances.size(); ++j) { + std::string instanceName = instances[j].as(); + enableItem.AddInstance(instanceName); +-- +2.33.0 + diff --git a/0011-fix-instance-nullptr.patch b/0011-fix-instance-nullptr.patch new file mode 100644 index 0000000..9e7765d --- /dev/null +++ b/0011-fix-instance-nullptr.patch @@ -0,0 +1,49 @@ +From b1aac403051ca84e8e083359f981dec887805b6c Mon Sep 17 00:00:00 2001 +From: fly_1997 +Date: Sat, 28 Dec 2024 00:34:14 +0800 +Subject: [PATCH 7/7] fix instance nullptr + +--- + src/plugin_mgr/instance_run_handler.cpp | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp +index c38e9ea..a253119 100644 +--- a/src/plugin_mgr/instance_run_handler.cpp ++++ b/src/plugin_mgr/instance_run_handler.cpp +@@ -19,6 +19,10 @@ constexpr int INSTANCE_RUN_ALWAYS = 1; + + Result InstanceRunHandler::EnableInstance(const std::string &name) + { ++ if (!memoryStore->IsInstanceExist(name)) { ++ WARN(logger, "instance {" << name << "} does not exist."); ++ return Result(FAILED, "instance {" + name + "} does not exist."); ++ } + auto instance = memoryStore->GetInstance(name); + auto result = instance->interface->Enable(); + if (result.code < 0) { +@@ -40,6 +44,10 @@ Result InstanceRunHandler::EnableInstance(const std::string &name) + + void InstanceRunHandler::DisableInstance(const std::string &name) + { ++ if (!memoryStore->IsInstanceExist(name)) { ++ WARN(logger, "instance {" << name << "} does not exist."); ++ return; ++ } + auto instance = memoryStore->GetInstance(name); + instance->enabled = false; + instance->interface->Disable(); +@@ -49,6 +57,10 @@ void InstanceRunHandler::DisableInstance(const std::string &name) + Result InstanceRunHandler::Subscribe(const std::vector &payload) + { + Topic topic = Topic::GetTopicFromType(payload[0]); ++ if (!memoryStore->IsInstanceExist(topic.instanceName)) { ++ WARN(logger, "instance {" << topic.instanceName << "} does not exist."); ++ return Result(FAILED, "instance {" + topic.instanceName + "} does not exist."); ++ } + Result result; + constexpr int subscriberIndex = 1; + auto instance = memoryStore->GetInstance(topic.instanceName); +-- +2.33.0 + diff --git a/oeAware-manager.spec b/oeAware-manager.spec index bcf45b8..01d009d 100644 --- a/oeAware-manager.spec +++ b/oeAware-manager.spec @@ -1,6 +1,6 @@ Name: oeAware-manager Version: v2.0.1 -Release: 2 +Release: 3 Summary: OeAware is a framework for implementing low-load collection, sensing, and tuning on openEuler. License: MulanPSL2 URL: https://gitee.com/openeuler/%{name} @@ -9,6 +9,13 @@ Patch1: 0001-change-the-folder-permission-to-755-add-oeaware-grou.patch Patch2: 0002-docker_cpu_burst-instance-add-unsubscribe-topics.patch Patch3: 0003-add-pmu-check.patch Patch4: 0004-fix-smc_tune-type.patch +Patch5: 0005-modify-the-method-of-obtaining-cpu-frequency.patch +Patch6: 0006-update-compilation-options.patch +Patch7: 0007-fix-build-script.patch +Patch8: 0008-fix-memory-leak-plugin-type.patch +Patch9: 0009-every-sdk-process-use-diff-sock.patch +Patch10: 0010-fix-enable_list-load-error.patch +Patch11: 0011-fix-instance-nullptr.patch BuildRequires: cmake make gcc-c++ BuildRequires: boost-devel @@ -45,7 +52,7 @@ Development files for plugin of oeaware %autosetup -n %{name}-%{version} -p1 %build -sh build.sh -k +sh build.sh -k --release %install #install server @@ -103,6 +110,12 @@ fi %attr(0644, root, root) %{_includedir}/oeaware/data/*.h %changelog +* Mon Dec 30 2024 fly_1997 -v2.0.1-3 +- fix config load error +- fix memory leak +- fix access nullptr instance +- update build.sh + * Wed Dec 18 2024 fly_1997 -v2.0.1-2 - fix smc type error - fix cpu burst unsubscribe problem -- Gitee