From e560ff7af04c60895a83a7d0bdf8de0d9fc8c462 Mon Sep 17 00:00:00 2001 From: queyanwen Date: Wed, 26 Jul 2023 21:54:15 +0800 Subject: [PATCH] eagle: Arch2.0 --- .gitignore | 6 +++- eagle/CMakeLists.txt | 4 ++- eagle/build.sh | 1 + eagle/inc/common.h | 2 ++ eagle/install.sh | 2 +- eagle/src/CMakeLists.txt | 8 +++++ eagle/src/eaglecore.c | 17 ++++++++++ eagle/src/pwrapi_adaptor/CMakeLists.txt | 35 +++++++++++++++++++ eagle/src/pwrapi_adaptor/pwrapi/readme | 7 ++++ eagle/src/pwrapi_adaptor/pwrapiadpt.c | 45 +++++++++++++++++++++++++ eagle/src/pwrapi_adaptor/pwrapiadpt.h | 33 ++++++++++++++++++ eagle/src/sched_service/CMakeLists.txt | 1 + eagle/src/servicemgr.c | 1 + eagle/uninstall.sh | 10 ++++++ 14 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 eagle/src/pwrapi_adaptor/CMakeLists.txt create mode 100644 eagle/src/pwrapi_adaptor/pwrapi/readme create mode 100644 eagle/src/pwrapi_adaptor/pwrapiadpt.c create mode 100644 eagle/src/pwrapi_adaptor/pwrapiadpt.h diff --git a/.gitignore b/.gitignore index 8660c18..439a1b2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,8 @@ install build release -debug \ No newline at end of file +debug +./eagle/src/pwrapi_adaptor/pwrapi/libpwrapi.so +./eagle/src/pwrapi_adaptor/pwrapi/powerapi.h +./eagle/src/pwrapi_adaptor/pwrapi/pwrdata.h +./eagle/src/pwrapi_adaptor/pwrapi/pwrerr.h \ No newline at end of file diff --git a/eagle/CMakeLists.txt b/eagle/CMakeLists.txt index cf96a22..8349c23 100644 --- a/eagle/CMakeLists.txt +++ b/eagle/CMakeLists.txt @@ -2,5 +2,7 @@ cmake_minimum_required (VERSION 3.16) project (eagle_entrance C) set(CMAKE_VERBOSE_MAKEFILE on) -add_subdirectory(src) +add_subdirectory(src/pwrapi_adaptor) add_subdirectory(src/sched_service) +add_subdirectory(src) + diff --git a/eagle/build.sh b/eagle/build.sh index 25227a1..1112c80 100644 --- a/eagle/build.sh +++ b/eagle/build.sh @@ -20,5 +20,6 @@ mkdir ./release/eagle/lib cp ./build/src/eagle ./release/eagle/ cp -r ./conf ./release/eagle/ cp ./build/src/sched_service/libsched_service.so ./release/eagle/lib +cp ./build/src/pwrapi_adaptor/libpwrapi_adaptor.so ./release/eagle/lib exit 0 \ No newline at end of file diff --git a/eagle/inc/common.h b/eagle/inc/common.h index f88e003..dda6cf3 100644 --- a/eagle/inc/common.h +++ b/eagle/inc/common.h @@ -55,6 +55,7 @@ #define MD_NM_DCOLL "DATA_COLL" #define MD_NM_SVR "SERVICE" #define MD_NM_PCY "POLICY" +#define MD_NM_PWRAPI "PWRAPI" // Define configuration section name #define CFG_NM_LOG "log" @@ -258,6 +259,7 @@ enum RtnCode { ERR_NOT_REGISTED = 100, ERR_OVER_MAX_CONNECTION, ERR_DISCONNECTED = 300, + ERR_INVOKE_PWRAPI_FAILED, ERR_FILE_NOT_EXIST = 400, ERR_FILE_CONTENT_ERROR, diff --git a/eagle/install.sh b/eagle/install.sh index 14c8517..a0db142 100644 --- a/eagle/install.sh +++ b/eagle/install.sh @@ -2,4 +2,4 @@ cd build sudo make install -sudo systemctl start eagle.service \ No newline at end of file +sudo systemctl start eagle.service --now \ No newline at end of file diff --git a/eagle/src/CMakeLists.txt b/eagle/src/CMakeLists.txt index 7452ca4..0c1f045 100644 --- a/eagle/src/CMakeLists.txt +++ b/eagle/src/CMakeLists.txt @@ -3,6 +3,13 @@ project (eagle C) set ( CMAKE_INCLUDE_CURRENT_DIR ON) # Add head file directory include_directories ("${PROJECT_SOURCE_DIR}/../inc") +include_directories ("${PROJECT_SOURCE_DIR}/pwrapi_adaptor") +include_directories ("${PROJECT_SOURCE_DIR}/pwrapi_adaptor/pwrapi") +# Add library directory +link_directories ( + "${PROJECT_SOURCE_DIR}/pwrapi_adaptor/pwrapi" + "${CMAKE_CURRENT_BINARY_DIR}/pwrapi_adaptor" +) # Load source file aux_source_directory(${PROJECT_SOURCE_DIR} EAGLE_SRC_DIR) @@ -10,6 +17,7 @@ aux_source_directory(${PROJECT_SOURCE_DIR} EAGLE_SRC_DIR) # Set compiling policy set (PG_NAME ${PROJECT_NAME}) add_executable (${PG_NAME} ${EAGLE_SRC_DIR}) +target_link_libraries(${PG_NAME} -lpwrapi_adaptor -lpwrapi -lpthread) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) # Set installaltion path diff --git a/eagle/src/eaglecore.c b/eagle/src/eaglecore.c index 03f03fd..cfaac8a 100644 --- a/eagle/src/eaglecore.c +++ b/eagle/src/eaglecore.c @@ -21,13 +21,29 @@ #include "servicemgr.h" #include "policymgr.h" #include "datacollect.h" +#include "pwrapiadpt.h" static int g_hasRegistedToPapis = FALSE; +static void PwrapiLogCallback(int level, const char *fmt, va_list vl) +{ + char message[MAX_LINE_NUM] = {0}; + + if (vsnprintf(message, sizeof(message) - 1, fmt, vl) < 0) { + return; + } + Logger(level, MD_NM_PWRAPI, message); +} + static int RegisterToPapis(void) { // todo. register via powerapi.so + PwrapiSetLogCallback(PwrapiLogCallback); + int ret = PwrapiRegister(); + if (ret != SUCCESS) { + return ret; + } g_hasRegistedToPapis = TRUE; return SUCCESS; } @@ -35,6 +51,7 @@ static int RegisterToPapis(void) static void UnRegisterFromPapis(void) { // todo. + PWR_UnRegister(); g_hasRegistedToPapis = FALSE; } diff --git a/eagle/src/pwrapi_adaptor/CMakeLists.txt b/eagle/src/pwrapi_adaptor/CMakeLists.txt new file mode 100644 index 0000000..e09d323 --- /dev/null +++ b/eagle/src/pwrapi_adaptor/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required (VERSION 3.16) +project (pwrapi_adaptor C) +set ( CMAKE_INCLUDE_CURRENT_DIR ON) + +# Add head directory +include_directories ("${PROJECT_SOURCE_DIR}") +include_directories ("${PROJECT_SOURCE_DIR}/pwrapi") +include_directories ("${PROJECT_SOURCE_DIR}/../../inc") + + +# Load source file +set(SCHED_SRC ${PROJECT_SOURCE_DIR}/pwrapiadpt.c) + +# Set compile policy +set (PG_NAME ${PROJECT_NAME}) +add_library(${PG_NAME} SHARED ${SCHED_SRC}) +set_target_properties(${PG_NAME} PROPERTIES LINKER_LANGUAGE C) +set (CMAKE_EXPORT_COMPILE_COMMANDS ON) + +if(BUILD_LLT) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") +endif(BUILD_LLT) + +# set installation path +set ( CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install path prefix" FORCE) +install (TARGETS ${PG_NAME} DESTINATION lib) + +# Release compile mode +#set(CMAKE_BUILD_TYPE "Release") +#set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") + +# Debug compile mode +set(CMAKE_BUILD_TYPE "Debug") +set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") + diff --git a/eagle/src/pwrapi_adaptor/pwrapi/readme b/eagle/src/pwrapi_adaptor/pwrapi/readme new file mode 100644 index 0000000..4d38932 --- /dev/null +++ b/eagle/src/pwrapi_adaptor/pwrapi/readme @@ -0,0 +1,7 @@ +The pwrapi_adaptor module depends on powerapi development kits. +Before building eagle, you should the powerapi development kits to this directory, including: + +libpwrapi.so +powerapi.h +pwrdata.h +pwrerr.h \ No newline at end of file diff --git a/eagle/src/pwrapi_adaptor/pwrapiadpt.c b/eagle/src/pwrapi_adaptor/pwrapiadpt.c new file mode 100644 index 0000000..6fe7acc --- /dev/null +++ b/eagle/src/pwrapi_adaptor/pwrapiadpt.c @@ -0,0 +1,45 @@ +/* ***************************************************************************** + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023 All rights reserved. + * eagle licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: queyanwen + * Create: 2023-06-28 + * Description: adaptor the powerapi + * **************************************************************************** */ + +#include "pwrapiadpt.h" +#include "log.h" + + +int PwrapiSetLogCallback(void(LogCallback)(int level, const char *fmt, va_list vl)) +{ + int ret = PWR_SetLogCallback(LogCallback); + if (ret != PWR_SUCCESS) { + Logger(ERROR, MD_NM_PWRAPI, "Invoke PWR_SetLogCallback failed. ret:%d", ret); + return ERR_INVOKE_PWRAPI_FAILED; + } + return SUCCESS; +} + +int PwrapiRegister() +{ + int ret = PWR_Register(); + Logger(ERROR, MD_NM_PWRAPI, "Invoke PWR_Register failed. ret:%d", ret); + if (ret != PWR_SUCCESS) { + + return ERR_INVOKE_PWRAPI_FAILED; + } + return SUCCESS; +} + +int PwrapiUnRegister() +{ + (void)PWR_UnRegister(); + return SUCCESS; +} diff --git a/eagle/src/pwrapi_adaptor/pwrapiadpt.h b/eagle/src/pwrapi_adaptor/pwrapiadpt.h new file mode 100644 index 0000000..f1555d9 --- /dev/null +++ b/eagle/src/pwrapi_adaptor/pwrapiadpt.h @@ -0,0 +1,33 @@ +/* ***************************************************************************** + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * eagle licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: queyanwen + * Create: 2023-06-28 + * Description: adaptor the powerapi + * **************************************************************************** */ +#ifndef EAGLE_PWRAPI_ADAPTOR_H__ +#define EAGLE_PWRAPI_ADAPTOR_H__ + +#include +#include "powerapi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int PwrapiSetLogCallback(void(LogCallback)(int level, const char *fmt, va_list vl)); +int PwrapiRegister(); +int PwrapiUnRegister(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/eagle/src/sched_service/CMakeLists.txt b/eagle/src/sched_service/CMakeLists.txt index abd69ee..5d0254e 100644 --- a/eagle/src/sched_service/CMakeLists.txt +++ b/eagle/src/sched_service/CMakeLists.txt @@ -5,6 +5,7 @@ set ( CMAKE_INCLUDE_CURRENT_DIR ON) # Add head directory include_directories ("${PROJECT_SOURCE_DIR}") include_directories ("${PROJECT_SOURCE_DIR}/../../inc") +include_directories ("${PROJECT_SOURCE_DIR}/../pwrapi_adaptor") # Load source file set(SCHED_SRC ${PROJECT_SOURCE_DIR}/sched_service.c) diff --git a/eagle/src/servicemgr.c b/eagle/src/servicemgr.c index 8da2bb2..c3a76f5 100644 --- a/eagle/src/servicemgr.c +++ b/eagle/src/servicemgr.c @@ -15,6 +15,7 @@ #include "servicemgr.h" #include "common.h" +#include "policymgr.h" int InitServiceMgr(void) { diff --git a/eagle/uninstall.sh b/eagle/uninstall.sh index 737053e..230d098 100644 --- a/eagle/uninstall.sh +++ b/eagle/uninstall.sh @@ -2,4 +2,14 @@ #cd build sudo systemctl stop eagle.service +sudo systemctl disable eagle.service #sudo make uninstall +if [ -f "./build/install_manifest.txt" ];then + cd build + xargs rm < install_manifest.txt + else + rm /usr/lib/libpwrapi_adaptor.so + rm /usr/sbin/eagle + rm /etc/sysconfig/eagle_config.ini + rm /usr/lib/systemd/system/eagle.service +fi \ No newline at end of file -- Gitee