diff --git a/.gitignore b/.gitignore index 8660c18ad11a5cac40c35f079c44aa960e9d2627..439a1b29bb3b323437e549a5aaf5d4ac45951f40 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 cf96a22eb5b33645aaf30ba9eae6db5ca1ceaa6d..8349c23497b0864783d29b8a16f19bb617d2109f 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 25227a19a74fb4021f0813619eadbf2d42b85fd7..1112c8088b4d746c53051056800ce31ee4e13561 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 f88e0038191fb56d52d6ddf36b7cf30829d77d5f..dda6cf3f1073e97889814d21d1cd716e84f65d43 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 14c85173c1aab7d7dcb06d54591b788a19b43822..a0db1425ff2746548325cc2560f7218037ae1715 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 7452ca444e54c425e2a03e73a471a906472c2419..0c1f0450b65948462e2042a492f43e6929855a2a 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 03f03fdbd294e1a1b5474a0fd3aeb7d2a669c3ee..cfaac8a1823254738e9979897a858633bd10a51a 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 0000000000000000000000000000000000000000..e09d32309911398fa32875cb61f54102c91e7ede --- /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 0000000000000000000000000000000000000000..4d38932a3bc912848a7b726abb394d2de6224b8a --- /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 0000000000000000000000000000000000000000..6fe7accb0d83785d7d7eea99d7fdaaae467c9ded --- /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 0000000000000000000000000000000000000000..f1555d93ca2f005df556d8270276d296c190143b --- /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 abd69eee95e7578cbf86b88ed7a14b0ab0801525..5d0254eeabb23f395f42076540e0390e17c4f8e4 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 8da2bb21cabdb2e48f7c401ddc18d7356c81a6ab..c3a76f5ec5ff1bf5bf39acf5cc4f8623f72aafc0 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 737053e488ef5cb60c64b0c3810d7220ff8e9f22..230d098867b53c72f177ee411b3a21b07eead0a7 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