diff --git a/eagle/conf/eagle.policy b/eagle/conf/eagle.policy index 44df5414b82133c6a4b5ffac2c7ed09a1d802d11..58993bc9aca13d1b33d5db241351a1fef51b98c8 100644 --- a/eagle/conf/eagle.policy +++ b/eagle/conf/eagle.policy @@ -5,26 +5,31 @@ name=default desc=optimaze for high energy efficiency [sched_service] +enable=1 sched_lib = libsched_service.so enable_watt_sched = 1 -watt_th = 70 +watt_th = 85 [freq_service] +enable=1 freq_lib = libfreq_service.so cpufreq_gov = seep perf_loss_rate = 5 sampling_rate = 1000 [idle_service] +enable=1 idle_lib = libidle_service.so cpuidle_gov = menu [pcap_service] +enable=1 pcap_lib = libpcap_service.so enable_pcap = 1 cap_target = 500 [mpc_service] +enable=1 mpc_lib = libmpc_service.so enable_mpc = 1 diff --git a/eagle/inc/common.h b/eagle/inc/common.h index dda6cf3f1073e97889814d21d1cd716e84f65d43..a53dc02f8653f5612ba09b47eebbac0c0b0fde15 100644 --- a/eagle/inc/common.h +++ b/eagle/inc/common.h @@ -14,35 +14,8 @@ * **************************************************************************** */ #ifndef EAGLE_COMMON_H__ #define EAGLE_COMMON_H__ -#define FOUND 0 -#define NOT_FOUND (-1) -#define FAILED (-1) -#define DEFAULT_VAL 0 -#define EMPTY_FD (-1) -#define MAX_PEDDING_SOCKS 5 -#define MS_TO_SEC 1000 -#define ONE_HUNDRED 100 -// Status code defination -#define INTERACT_SUCCEED 2003 -#define INTERACT_FAIL 2002 -#define NO_PROCESS 2000 -#define PROCESS_EXISTED 2001 -#define GET_UNKNOWN_TYPE 2005 -#define GET_NO_DATA 2006 -#define WRONG_TIME_RANGE 1303 -#define IMPORT_WRONG_DIR_DATA 2007 -#define IMPORT_WRONG_FORMAT_DATA 2008 -#define CRC_FAIL 1202 -#define UNKNOWN_CMD 2009 -#define WRONG_BODY_LEN 2010 -#define WRONG_PATH 1300 -#define WRONG_FORMAT 1301 -#define WRONG_VALUE 1302 -#define LACK_PARAM 1304 -#define UNKNOWN_PARAM 1305 -#define NO_PERMISSION 1201 -#define OVER_GET_DT_LEN 2010 +#include "public.h" // Define module name #define MD_NM_MAN "MAIN" @@ -79,190 +52,5 @@ #define CFG_IT_CFG_UPD_INTVL "config_update_interval" #define CFG_IT_PCY_UPD_INTVL "policy_update_interval" -// Max filename length -#define MAX_NAME_LEN 128 -// Max MD5 length -#define MD5_LEN 33 - - -// Max line length -#define MAX_LINE_LENGTH 256 -// Max type collect items -#define MAX_TYPE_ITEM_CNT 500 -// Max section name length -#define MAX_SECTION 23 -// Max config name length -#define MAX_NAME 256 -// Max config value length -#define MAX_VALUE 129 -// Max key value length -#define MAX_KEY_LEN 32 -// Max config param value -#define MAX_PARAM_VAL 128 -// Max config data name -#define MAX_DT_NAME 60 -// Max section name length -#define MAX_SEC_NAME 17 -// Max section name length -#define MAX_FILE_NAME 178 -#define MAX_PATH_NAME 128 -#define MAX_FULL_NAME (MAX_FILE_NAME + MAX_PATH_NAME) -// Comment char -#define COMMENT_PREFIXES "#" -// Max config line length -#define MAX_LINE_NUM 3000 -// Max log head length -#define MAX_LOG_LINE (MAX_LINE_NUM + MAX_STD_TIME) -// MAX time length -#define MAX_STD_TIME 32 -#define MAX_FULL_TIME 25 -// Gather -#define MAX_PERIOD 3600 -// Sockt connetion closed -#define CONN_CLOSED (-753462) -#define READ_DONE 1 -// Total number of items collected -#define TOTAL_COLL_ITEM_NUM 400 -// The maximum length of the collected value -#define MAX_COLL_DATA 120 -// Time value length -#define TIME_SEC_LEN 20 -#define FILE_TIME_LEN 13 -#define MAX_REGEX 64 -#define MAX_FILE_LINE 256 -// Maximum persistent data length -#define UNIT_FACTOR 1048576 -#define NEED_SWITCH 1 -#define NO_NEED_SWITCH 0 -#define OPENED 1 -#define CLOSED 0 -#define READ_END "nonono" -// Data read buffer length -#define MAX_READ_BUFF 1024 -#define MAX_CP_BUF 1024 -#define CRT_DIR_MODE 0700 -#define CURRENT_DIR "." -#define PARENT_DIR ".." -#define K_TO_M 1024 -// Collected data name separator -#define DATA_NM_SEP '.' -#define DT_NM_SEP_STR "." -#define JIFF_FACTOR 100 -// Cpu node name prefix length -#define CPU_NM_PX_LEN 7 -#define CPU_USG_LINE_NUM 1 -#define CPU_TOTAL_SECS_FIELD_NUM 1 -#define CPU_IDLE_SECS_FIELD_NUM 2 -#define SIGLE_CPU_IDLE_SECS_NUM 5 -#define CPU_LOAD_LINE_NUM 1 -#define CPU_ONE_MIN_LOAD_FIELD_NUM 1 -#define CPU_FIVE_MIN_LOAD_FIELD_NUM 2 -#define CPU_FIFTEEN_MIN_LOAD_FIELD_NUM 3 - -// Memery data location define -#define FIRST_MATCH_LINE 1 -#define MEMINFO_DATA_FIELD_NUM 2 -#define NUMA_MEM_DATA_FIELD_NUM 4 - -// Numa node name perfix length -#define NUMA_NM_PX_LEN 13 -#define ZERO_USAGE "0" -#define ST_CHANGE "2" -#define FLOAT_ZERO_USAGE "0.00" -#define DAY_SECS 86400 -#define FAILED_EXIT (-1) -#define EMPTY_STR "" - -// Persistence module initialization state definition -#define PST_INIT_DONE 1 -#define PST_NOT_INIT 0 -#define TYPE_FIELD_NUM 1 -#define TIME_FIELD_NUM 2 -#define DT_NAME_FIELD_NUM 3 -#define DT_TIME_FIELD_NUM 2 -#define TAIL_LEN_FACTOR 2 -#define BUF_WARN_RATE 2 -#define ERR_CFG_NAME "ERR_CFG_NAME" - -// Message related definition -#define MAX_HEAD_LEN 256 -#define PATH_SEP_STR "/" -#define PATH_SEP_CHAR '/' -#define CPU_NM_PRX "cpu" -#define CPU_NM_LEN 8 -#define CRC_TB_LEN 256 -#define CRC_FACTOR 0xFFFFFFFF -#define CRC_ERROR (-489) -#define CRC_FILE_BUF_LEN 102400 -#define SEC_TO_USEC 1000000 - -#define APP_ARGC 2 -#define CRC_RIGHT_SHIFT_BIT 8 - -#define MIN_DT_FILE_SIZE 1 -#define MAX_DT_FILE_SIZE 1024 -#define MIN_SPACE_SIZE 1 -#define MAX_SPACE_SIZE 10240 -#define MIN_DEL_RATIO 1 -#define MAX_DEL_RATIO 50 -#define MIN_DT_FILE_DURATION 1 -#define MAX_DT_FILE_DURATION 100 - -#define MIN_LOG_FILE_SIZE 1 -#define MAX_LOG_FILE_SIZE 100 -#define MIN_LOG_CMP_CNT 1 -#define MAX_LOG_CMP_CNT 1000 -#define MAX_LOG_FILE_SIZE 100 -#define MAX_LOG_TOTAL_SIZE 10000 -#define MIN_LOG_LEVEL 0 -#define MAX_LOG_LEVEL 3 -#define MIN_SV_PORT 1025 -#define MAX_SV_PORT 65535 -#define MAX_FS_TYPE_CNT 64 - -#define MIN_GTH_ITV 1 -#define MAX_GTH_ITV 5 -#define MAX_CT_LEN 104857600 - -#define MIN_COLL_DURATION 1 -#define MAX_COLL_DURATION MAX_PERIOD - -#define STR_LEN_FOR_LONG 22 -#define WRONG_OBJ "coll_item_not_existed" - -#define NO_MAP "NO_MAP" -#define ERR_VAL "-1" - -enum RunStatus { - EXIT = 0, - KEEP_RUN -}; - -#define INVALID_FD (-1) -#define INVALID_INDEX (-1) -#define MAX_LICENT_NUM 3 -#define THREAD_LOOP_INTERVAL 2000 // us -#define MAX_SYSID_LEN 20 -#define TRUE 1 -#define FALSE 0 - -enum RtnCode { - SUCCESS = 0, - ERR_COMMON = 1, - ERR_TIMEOUT, - ERR_SYS_EXCEPTION, - ERR_NULL_POINTER, - ERR_INVALIDE_PARAM, - ERR_MODIFY_BAN_UPDATE_ATTR_CURRENTLY, - ERR_PATH_NORMALIZE, - ERR_PATH_VERIFY, - ERR_NOT_REGISTED = 100, - ERR_OVER_MAX_CONNECTION, - ERR_DISCONNECTED = 300, - ERR_INVOKE_PWRAPI_FAILED, - - ERR_FILE_NOT_EXIST = 400, - ERR_FILE_CONTENT_ERROR, -}; #endif diff --git a/eagle/inc/config.h b/eagle/inc/config.h index 17057f81caabba2a4734579cab632beadee5e0cd..408516874e4a42d9fb3a431e6677770be596aa59 100644 --- a/eagle/inc/config.h +++ b/eagle/inc/config.h @@ -35,12 +35,6 @@ #define MAX_CMP_CNT 10 // LogCfg -enum LogLevel { - DEBUG = 0, - INFO, - WARNING, - ERROR -}; enum CnfItemType { E_CFG_IT_FLS, diff --git a/eagle/inc/policy.h b/eagle/inc/policy.h index 849c2fea1dba9b3885d81525c171885f229350c2..73d1b4c7e0e1497a9010da3153e93d336df63250 100644 --- a/eagle/inc/policy.h +++ b/eagle/inc/policy.h @@ -16,50 +16,9 @@ #define EAGLE_POLICY_H__ #include "common.h" +#include "policydt.h" -enum PcyState { - PCY_DISABLE = 0, - PCY_ENABLE = 1 -}; -typedef struct SchedServicePcy { - char schedLib[MAX_KEY_LEN]; - int enableWattSched; - int WattTh; // [0,100] -} SchedServicePcy; - -typedef struct FreqServicePcy { - char freqLib[MAX_KEY_LEN]; - char freqGov[MAX_KEY_LEN]; - int perfLossRate; // [0.100] - int samplingRate; // ms -} FreqServicePcy; - -typedef struct IdleServicePcy { - char idleLib[MAX_KEY_LEN]; - char idleGov[MAX_KEY_LEN]; -} IdleServicePcy; - -typedef struct PcapServicePcy { - char pcapLib[MAX_KEY_LEN]; - int enablePcap; - int capTarget; -} PcapServicePcy; - -typedef struct MpcServicePcy { - char mpcLib[MAX_KEY_LEN]; - int enableMpc; -} MpcServicePcy; - -typedef struct Policy { - char pcyName[MAX_KEY_LEN]; - char pcyDesc[MAX_LINE_LENGTH]; - SchedServicePcy schedPcy; - FreqServicePcy freqPcy; - IdleServicePcy idlePcy; - PcapServicePcy pcapPcy; - MpcServicePcy mpcPcy; -} Policy; int InitPolicy(const char policyFilePath[], Policy *pcy); diff --git a/eagle/inc/servicemgr.h b/eagle/inc/servicemgr.h index 006173257c77f2dd306a494ecf791dc631b2c364..939b5804ee40e19e2214cf27ad24eb98660a16ea 100644 --- a/eagle/inc/servicemgr.h +++ b/eagle/inc/servicemgr.h @@ -18,4 +18,5 @@ int InitServiceMgr(void); int StartServices(void); void StopServices(void); +void UninitServiceMgr(void); #endif diff --git a/eagle/inc/shared/policydt.h b/eagle/inc/shared/policydt.h new file mode 100644 index 0000000000000000000000000000000000000000..6ac111bd4ccb1bc2c8e943c9418bd34b8467a9b2 --- /dev/null +++ b/eagle/inc/shared/policydt.h @@ -0,0 +1,69 @@ +/* ***************************************************************************** + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. 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: 2022-06-23 + * Description: Policy data structure + * **************************************************************************** */ +#ifndef EAGLE_POLICY_DT_H__ +#define EAGLE_POLICY_DT_H__ + +#include "public.h" + +enum PcyState { + PCY_DISABLE = 0, + PCY_ENABLE = 1 +}; + +typedef struct PcyBase { + int enable; + char lib[MAX_KEY_LEN]; +} PcyBase; + +typedef struct SchedServicePcy { + PcyBase base; + int enableWattSched; + int WattTh; // [0,100] +} SchedServicePcy; + +typedef struct FreqServicePcy { + PcyBase base; + char freqGov[MAX_KEY_LEN]; + int perfLossRate; // [0.100] + int samplingRate; // ms +} FreqServicePcy; + +typedef struct IdleServicePcy { + PcyBase base; + char idleGov[MAX_KEY_LEN]; +} IdleServicePcy; + +typedef struct PcapServicePcy { + PcyBase base; + int enablePcap; + int capTarget; +} PcapServicePcy; + +typedef struct MpcServicePcy { + PcyBase base; + int enableMpc; +} MpcServicePcy; + +typedef struct Policy { + char pcyName[MAX_KEY_LEN]; + char pcyDesc[MAX_LINE_LENGTH]; + SchedServicePcy schedPcy; + FreqServicePcy freqPcy; + IdleServicePcy idlePcy; + PcapServicePcy pcapPcy; + MpcServicePcy mpcPcy; +} Policy; + +#endif diff --git a/eagle/inc/shared/public.h b/eagle/inc/shared/public.h new file mode 100644 index 0000000000000000000000000000000000000000..8234ec3aae1e88ceee5711819d4763fceedcb486 --- /dev/null +++ b/eagle/inc/shared/public.h @@ -0,0 +1,242 @@ +/* ***************************************************************************** + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. 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: luocaimin + * Create: 2022-03-29 + * Description: provide const value defination + * **************************************************************************** */ +#ifndef EAGLE_PUBLIC_H__ +#define EAGLE_PUBLIC_H__ + +#define FOUND 0 +#define NOT_FOUND (-1) +#define FAILED (-1) +#define DEFAULT_VAL 0 +#define EMPTY_FD (-1) +#define MAX_PEDDING_SOCKS 5 +#define MS_TO_SEC 1000 +#define ONE_HUNDRED 100 + +// Status code defination +#define INTERACT_SUCCEED 2003 +#define INTERACT_FAIL 2002 +#define NO_PROCESS 2000 +#define PROCESS_EXISTED 2001 +#define GET_UNKNOWN_TYPE 2005 +#define GET_NO_DATA 2006 +#define WRONG_TIME_RANGE 1303 +#define IMPORT_WRONG_DIR_DATA 2007 +#define IMPORT_WRONG_FORMAT_DATA 2008 +#define CRC_FAIL 1202 +#define UNKNOWN_CMD 2009 +#define WRONG_BODY_LEN 2010 +#define WRONG_PATH 1300 +#define WRONG_FORMAT 1301 +#define WRONG_VALUE 1302 +#define LACK_PARAM 1304 +#define UNKNOWN_PARAM 1305 +#define NO_PERMISSION 1201 +#define OVER_GET_DT_LEN 2010 + + +// Max filename length +#define MAX_NAME_LEN 128 +// Max MD5 length +#define MD5_LEN 33 + + +// Max line length +#define MAX_LINE_LENGTH 256 +// Max type collect items +#define MAX_TYPE_ITEM_CNT 500 +// Max section name length +#define MAX_SECTION 23 +// Max config name length +#define MAX_NAME 256 +// Max config value length +#define MAX_VALUE 129 +// Max key value length +#define MAX_KEY_LEN 32 +// Max config param value +#define MAX_PARAM_VAL 128 +// Max config data name +#define MAX_DT_NAME 60 +// Max section name length +#define MAX_SEC_NAME 17 +// Max section name length +#define MAX_FILE_NAME 178 +#define MAX_PATH_NAME 128 +#define MAX_FULL_NAME (MAX_FILE_NAME + MAX_PATH_NAME) +// Comment char +#define COMMENT_PREFIXES "#" +// Max config line length +#define MAX_LINE_NUM 3000 +// Max log head length +#define MAX_LOG_LINE (MAX_LINE_NUM + MAX_STD_TIME) +// MAX time length +#define MAX_STD_TIME 32 +#define MAX_FULL_TIME 25 +// Gather +#define MAX_PERIOD 3600 +// Sockt connetion closed +#define CONN_CLOSED (-753462) +#define READ_DONE 1 +// Total number of items collected +#define TOTAL_COLL_ITEM_NUM 400 +// The maximum length of the collected value +#define MAX_COLL_DATA 120 +// Time value length +#define TIME_SEC_LEN 20 +#define FILE_TIME_LEN 13 +#define MAX_REGEX 64 +#define MAX_FILE_LINE 256 +// Maximum persistent data length +#define UNIT_FACTOR 1048576 +#define NEED_SWITCH 1 +#define NO_NEED_SWITCH 0 +#define OPENED 1 +#define CLOSED 0 +#define READ_END "nonono" +// Data read buffer length +#define MAX_READ_BUFF 1024 +#define MAX_CP_BUF 1024 +#define CRT_DIR_MODE 0700 +#define CURRENT_DIR "." +#define PARENT_DIR ".." +#define K_TO_M 1024 +// Collected data name separator +#define DATA_NM_SEP '.' +#define DT_NM_SEP_STR "." +#define JIFF_FACTOR 100 +// Cpu node name prefix length +#define CPU_NM_PX_LEN 7 +#define CPU_USG_LINE_NUM 1 +#define CPU_TOTAL_SECS_FIELD_NUM 1 +#define CPU_IDLE_SECS_FIELD_NUM 2 +#define SIGLE_CPU_IDLE_SECS_NUM 5 +#define CPU_LOAD_LINE_NUM 1 +#define CPU_ONE_MIN_LOAD_FIELD_NUM 1 +#define CPU_FIVE_MIN_LOAD_FIELD_NUM 2 +#define CPU_FIFTEEN_MIN_LOAD_FIELD_NUM 3 + +// Memery data location define +#define FIRST_MATCH_LINE 1 +#define MEMINFO_DATA_FIELD_NUM 2 +#define NUMA_MEM_DATA_FIELD_NUM 4 + +// Numa node name perfix length +#define NUMA_NM_PX_LEN 13 +#define ZERO_USAGE "0" +#define ST_CHANGE "2" +#define FLOAT_ZERO_USAGE "0.00" +#define DAY_SECS 86400 +#define FAILED_EXIT (-1) +#define EMPTY_STR "" + +// Persistence module initialization state definition +#define PST_INIT_DONE 1 +#define PST_NOT_INIT 0 +#define TYPE_FIELD_NUM 1 +#define TIME_FIELD_NUM 2 +#define DT_NAME_FIELD_NUM 3 +#define DT_TIME_FIELD_NUM 2 +#define TAIL_LEN_FACTOR 2 +#define BUF_WARN_RATE 2 +#define ERR_CFG_NAME "ERR_CFG_NAME" + +// Message related definition +#define MAX_HEAD_LEN 256 +#define PATH_SEP_STR "/" +#define PATH_SEP_CHAR '/' +#define CPU_NM_PRX "cpu" +#define CPU_NM_LEN 8 +#define CRC_TB_LEN 256 +#define CRC_FACTOR 0xFFFFFFFF +#define CRC_ERROR (-489) +#define CRC_FILE_BUF_LEN 102400 +#define SEC_TO_USEC 1000000 + +#define APP_ARGC 2 +#define CRC_RIGHT_SHIFT_BIT 8 + +#define MIN_DT_FILE_SIZE 1 +#define MAX_DT_FILE_SIZE 1024 +#define MIN_SPACE_SIZE 1 +#define MAX_SPACE_SIZE 10240 +#define MIN_DEL_RATIO 1 +#define MAX_DEL_RATIO 50 +#define MIN_DT_FILE_DURATION 1 +#define MAX_DT_FILE_DURATION 100 + +#define MIN_LOG_FILE_SIZE 1 +#define MAX_LOG_FILE_SIZE 100 +#define MIN_LOG_CMP_CNT 1 +#define MAX_LOG_CMP_CNT 1000 +#define MAX_LOG_FILE_SIZE 100 +#define MAX_LOG_TOTAL_SIZE 10000 +#define MIN_LOG_LEVEL 0 +#define MAX_LOG_LEVEL 3 +#define MIN_SV_PORT 1025 +#define MAX_SV_PORT 65535 +#define MAX_FS_TYPE_CNT 64 + +#define MIN_GTH_ITV 1 +#define MAX_GTH_ITV 5 +#define MAX_CT_LEN 104857600 + +#define MIN_COLL_DURATION 1 +#define MAX_COLL_DURATION MAX_PERIOD + +#define STR_LEN_FOR_LONG 22 +#define WRONG_OBJ "coll_item_not_existed" + +#define NO_MAP "NO_MAP" +#define ERR_VAL "-1" + +enum RunStatus { + EXIT = 0, + KEEP_RUN +}; + +#define INVALID_FD (-1) +#define INVALID_INDEX (-1) +#define MAX_LICENT_NUM 3 +#define THREAD_LOOP_INTERVAL 2000 // us +#define MAX_SYSID_LEN 20 +#define TRUE 1 +#define FALSE 0 + +enum RtnCode { + SUCCESS = 0, + ERR_COMMON = 1, + ERR_TIMEOUT, + ERR_SYS_EXCEPTION, + ERR_NULL_POINTER, + ERR_INVALIDE_PARAM, + ERR_MODIFY_BAN_UPDATE_ATTR_CURRENTLY, + ERR_PATH_NORMALIZE, + ERR_PATH_VERIFY, + ERR_NOT_REGISTED = 100, + ERR_OVER_MAX_CONNECTION, + ERR_DISCONNECTED = 300, + ERR_INVOKE_PWRAPI_FAILED, + + ERR_FILE_NOT_EXIST = 400, + ERR_FILE_CONTENT_ERROR, + ERR_DL_OPEN_FAILED, +}; + +enum LogLevel { + DEBUG = 0, + INFO, + WARNING, + ERROR +}; +#endif diff --git a/eagle/src/CMakeLists.txt b/eagle/src/CMakeLists.txt index 0c1f0450b65948462e2042a492f43e6929855a2a..777dda6365fb643d534804309ade30eb0f15313b 100644 --- a/eagle/src/CMakeLists.txt +++ b/eagle/src/CMakeLists.txt @@ -2,9 +2,14 @@ cmake_minimum_required (VERSION 3.16) 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") +include_directories ( + "${PROJECT_SOURCE_DIR}/../inc" + "${PROJECT_SOURCE_DIR}/../inc/shared" + "${PROJECT_SOURCE_DIR}/pwrapi_adaptor" + "${PROJECT_SOURCE_DIR}/pwrapi_adaptor/pwrapi" + #"${PROJECT_SOURCE_DIR}/sched_service" + ) + # Add library directory link_directories ( "${PROJECT_SOURCE_DIR}/pwrapi_adaptor/pwrapi" @@ -13,22 +18,24 @@ link_directories ( # Load source file aux_source_directory(${PROJECT_SOURCE_DIR} EAGLE_SRC_DIR) +#aux_source_directory(${PROJECT_SOURCE_DIR}/sched_service 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) +target_link_libraries(${PG_NAME} -lpwrapi_adaptor -lpwrapi -ldl -lpthread) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) # Set installaltion path #set ( CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}") set ( CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE) -#install (TARGETS ${PG_NAME} DESTINATION bin) install (TARGETS ${PG_NAME} DESTINATION sbin) # Install default config files install (FILES "${PROJECT_SOURCE_DIR}/../conf/eagle_config.ini" DESTINATION /etc/sysconfig) install (FILES "${PROJECT_SOURCE_DIR}/../eagle.service" DESTINATION /usr/lib/systemd/system) +install (FILES "${CMAKE_CURRENT_BINARY_DIR}/pwrapi_adaptor/libpwrapi_adaptor.so" DESTINATION /usr/lib) +install (FILES "${CMAKE_CURRENT_BINARY_DIR}/sched_service/libsched_service.so" DESTINATION /usr/lib) # release complile mode #set(CMAKE_BUILD_TYPE "Release") diff --git a/eagle/src/policy.c b/eagle/src/policy.c index 67cfc8f8abe148670a2275cd60e89819e143dc58..021f7f2e5f4930cdad34d1b9cbe934bf60800e96 100644 --- a/eagle/src/policy.c +++ b/eagle/src/policy.c @@ -31,6 +31,7 @@ // Policy item name #define PCY_ITEM_PCY_NAME "name" #define PCY_ITEM_PCY_DESC "desc" +#define PCY_ITEM_BASE_EN "enable" #define PCY_ITEM_SCHED_LIB "sched_lib" #define PCY_ITEM_SCHED_EWS "enable_watt_sched" #define PCY_ITEM_SCHED_WTH "watt_th" @@ -127,8 +128,18 @@ static int FullfillPcyItem(Policy *pcy, const char *name, const char *value) static int FullfillSchedItem(Policy *pcy, const char *name, const char *value) { + if (strcmp(name, PCY_ITEM_BASE_EN) == 0) { + if (strcmp(value, PCY_STATE_ENABLE) == 0) { + pcy->schedPcy.base.enable = PCY_ENABLE; + } else if (strcmp(value, PCY_STATE_DISABLE) == 0) { + pcy->schedPcy.base.enable = PCY_DISABLE; + } else { + return ERR_FILE_CONTENT_ERROR; + } + return SUCCESS; + } if (strcmp(name, PCY_ITEM_SCHED_LIB) == 0) { - strncpy(pcy->schedPcy.schedLib, value, sizeof(pcy->schedPcy.schedLib) - 1); + strncpy(pcy->schedPcy.base.lib, value, sizeof(pcy->schedPcy.base.lib) - 1); return SUCCESS; } if (strcmp(name, PCY_ITEM_SCHED_EWS) == 0) { @@ -153,8 +164,18 @@ static int FullfillSchedItem(Policy *pcy, const char *name, const char *value) static int FullfillFreqItem(Policy *pcy, const char *name, const char *value) { + if (strcmp(name, PCY_ITEM_BASE_EN) == 0) { + if (strcmp(value, PCY_STATE_ENABLE) == 0) { + pcy->freqPcy.base.enable = PCY_ENABLE; + } else if (strcmp(value, PCY_STATE_DISABLE) == 0) { + pcy->freqPcy.base.enable = PCY_DISABLE; + } else { + return ERR_FILE_CONTENT_ERROR; + } + return SUCCESS; + } if (strcmp(name, PCY_ITEM_FREQ_LIB) == 0) { - strncpy(pcy->freqPcy.freqLib, value, sizeof(pcy->freqPcy.freqLib) - 1); + strncpy(pcy->freqPcy.base.lib, value, sizeof(pcy->freqPcy.base.lib) - 1); return SUCCESS; } if (strcmp(name, PCY_ITEM_FREQ_GOV) == 0) { @@ -183,8 +204,18 @@ static int FullfillFreqItem(Policy *pcy, const char *name, const char *value) static int FullfillIdleItem(Policy *pcy, const char *name, const char *value) { + if (strcmp(name, PCY_ITEM_BASE_EN) == 0) { + if (strcmp(value, PCY_STATE_ENABLE) == 0) { + pcy->idlePcy.base.enable = PCY_ENABLE; + } else if (strcmp(value, PCY_STATE_DISABLE) == 0) { + pcy->idlePcy.base.enable = PCY_DISABLE; + } else { + return ERR_FILE_CONTENT_ERROR; + } + return SUCCESS; + } if (strcmp(name, PCY_ITEM_IDLE_LIB) == 0) { - strncpy(pcy->idlePcy.idleLib, value, sizeof(pcy->idlePcy.idleLib) - 1); + strncpy(pcy->idlePcy.base.lib, value, sizeof(pcy->idlePcy.base.lib) - 1); return SUCCESS; } if (strcmp(name, PCY_ITEM_IDLE_GOV) == 0) { @@ -199,8 +230,18 @@ static int FullfillIdleItem(Policy *pcy, const char *name, const char *value) static int FullfillPcapItem(Policy *pcy, const char *name, const char *value) { + if (strcmp(name, PCY_ITEM_BASE_EN) == 0) { + if (strcmp(value, PCY_STATE_ENABLE) == 0) { + pcy->pcapPcy.base.enable = PCY_ENABLE; + } else if (strcmp(value, PCY_STATE_DISABLE) == 0) { + pcy->pcapPcy.base.enable = PCY_DISABLE; + } else { + return ERR_FILE_CONTENT_ERROR; + } + return SUCCESS; + } if (strcmp(name, PCY_ITEM_PCAP_LIB) == 0) { - strncpy(pcy->pcapPcy.pcapLib, value, sizeof(pcy->pcapPcy.pcapLib) - 1); + strncpy(pcy->pcapPcy.base.lib, value, sizeof(pcy->pcapPcy.base.lib) - 1); return SUCCESS; } if (strcmp(name, PCY_ITEM_PCAP_ENPCAP) == 0) { @@ -225,8 +266,18 @@ static int FullfillPcapItem(Policy *pcy, const char *name, const char *value) static int FullfillMpcItem(Policy *pcy, const char *name, const char *value) { + if (strcmp(name, PCY_ITEM_BASE_EN) == 0) { + if (strcmp(value, PCY_STATE_ENABLE) == 0) { + pcy->mpcPcy.base.enable = PCY_ENABLE; + } else if (strcmp(value, PCY_STATE_DISABLE) == 0) { + pcy->mpcPcy.base.enable = PCY_DISABLE; + } else { + return ERR_FILE_CONTENT_ERROR; + } + return SUCCESS; + } if (strcmp(name, PCY_ITEM_MPC_LIB) == 0) { - strncpy(pcy->mpcPcy.mpcLib, value, sizeof(pcy->mpcPcy.mpcLib) - 1); + strncpy(pcy->mpcPcy.base.lib, value, sizeof(pcy->mpcPcy.base.lib) - 1); return SUCCESS; } if (strcmp(name, PCY_ITEM_MPC_ENMPC) == 0) { @@ -244,6 +295,7 @@ static int FullfillMpcItem(Policy *pcy, const char *name, const char *value) static int FullfillPolicyItem(Policy *pcy, const char *section, const char *name, const char *value) { + // code to be optimized. if (strcmp(section, PCY_SEC_PCY) == 0) { return FullfillPcyItem(pcy, name, value); } diff --git a/eagle/src/policymgr.c b/eagle/src/policymgr.c index 193e20818c4ea7df602354488d9b9d4050825879..48cd59632823cf3f6d2e86a33a4a5c58a0bda641 100644 --- a/eagle/src/policymgr.c +++ b/eagle/src/policymgr.c @@ -14,7 +14,6 @@ * **************************************************************************** */ #include "policymgr.h" - #include #include "log.h" #include "config.h" @@ -22,7 +21,6 @@ static struct Policy g_curPolicy; static struct Policy g_lastPolicy; - int InitPolicyMgr(void) { bzero(&g_curPolicy, sizeof(Policy)); diff --git a/eagle/src/pwrapi_adaptor/CMakeLists.txt b/eagle/src/pwrapi_adaptor/CMakeLists.txt index e09d32309911398fa32875cb61f54102c91e7ede..61679559776aaa0f97a096c3396499130c09a37d 100644 --- a/eagle/src/pwrapi_adaptor/CMakeLists.txt +++ b/eagle/src/pwrapi_adaptor/CMakeLists.txt @@ -5,7 +5,7 @@ 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") +include_directories ("${PROJECT_SOURCE_DIR}/../../inc/shared") # Load source file diff --git a/eagle/src/pwrapi_adaptor/pwrapi/readme b/eagle/src/pwrapi_adaptor/pwrapi/readme index 4d38932a3bc912848a7b726abb394d2de6224b8a..9d260b47cb9432e338d21625584cdddc8632b087 100644 --- a/eagle/src/pwrapi_adaptor/pwrapi/readme +++ b/eagle/src/pwrapi_adaptor/pwrapi/readme @@ -1,5 +1,5 @@ The pwrapi_adaptor module depends on powerapi development kits. -Before building eagle, you should the powerapi development kits to this directory, including: +Before building eagle, you should copy the powerapi development kits to this directory, including: libpwrapi.so powerapi.h diff --git a/eagle/src/pwrapi_adaptor/pwrapiadpt.c b/eagle/src/pwrapi_adaptor/pwrapiadpt.c index 4bcfca8a2d5115280d9c4d45d622d60110dd81e0..b1ae29acfbf37040eeb77db0c8d9f6b18a8238bb 100644 --- a/eagle/src/pwrapi_adaptor/pwrapiadpt.c +++ b/eagle/src/pwrapi_adaptor/pwrapiadpt.c @@ -14,14 +14,12 @@ * **************************************************************************** */ #include "pwrapiadpt.h" -#include "log.h" - +#include "public.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; @@ -30,7 +28,6 @@ int PwrapiSetLogCallback(void(LogCallback)(int level, const char *fmt, va_list v int PwrapiRegister(void) { 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; } diff --git a/eagle/src/sched_service/CMakeLists.txt b/eagle/src/sched_service/CMakeLists.txt index 5d0254eeabb23f395f42076540e0390e17c4f8e4..7ae754bbc3fca3cec0d203edb687ed3d53ffe702 100644 --- a/eagle/src/sched_service/CMakeLists.txt +++ b/eagle/src/sched_service/CMakeLists.txt @@ -4,7 +4,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}/../../inc/shared") include_directories ("${PROJECT_SOURCE_DIR}/../pwrapi_adaptor") # Load source file diff --git a/eagle/src/sched_service/sched_service.c b/eagle/src/sched_service/sched_service.c index 8c0acb3191327a0b8db8668e378d5b090162fd7b..cd82c6faea65bc2f1c1b7286c1e3ce7e1cee7e39 100644 --- a/eagle/src/sched_service/sched_service.c +++ b/eagle/src/sched_service/sched_service.c @@ -14,21 +14,34 @@ * **************************************************************************** */ #include "sched_service.h" - #include -#include "common.h" +#include "public.h" -static void DefaultLogCallback(int level, const char *fmt, va_list vl) +static void DefaultLogCallback(int level, const char *usInfo, const char *fmt, va_list vl) { printf(fmt); } -void (*g_log_callback)(int level, const char *fmt, va_list vl) = DefaultLogCallback; +static void (*g_log_callback)(int level, const char *usInfo, const char *fmt, va_list vl) + = DefaultLogCallback; +static const char *g_id = NULL; + +static inline void SrvLog(int level, const char *fmt, ...) +{ + if (g_log_callback) { + va_list vl; + va_start(vl, fmt); + g_log_callback(level, g_id, fmt, vl); + va_end(vl); + } +} -int SRV_SetLogCallback(void(LogCallback)(int, const char *, va_list)) +int SRV_SetLogCallback(void(LogCallback)(int, const char *, const char *, va_list), + const char *usrInfo) { if (LogCallback) { g_log_callback = LogCallback; + g_id = usrInfo; return SUCCESS; } return ERR_NULL_POINTER; @@ -37,4 +50,29 @@ int SRV_SetLogCallback(void(LogCallback)(int, const char *, va_list)) int SRV_Init(void) { // todo + SrvLog(ERROR, "SRV_Init called. d:%d", 0); +} + +int SRV_Start(void* pcy) +{ + // todo + SrvLog(ERROR, "SRV_Start called. d:%d", 1); +} + +int SRV_Update(void* pcy) +{ + // todo + SrvLog(ERROR, "SRV_Update called. d:%d", 2); +} + +int SRV_Stop(void) +{ + // todo + SrvLog(ERROR, "SRV_Stop called. d:%d", 3); +} + +int SRV_Uninit(void) +{ + // todo + SrvLog(ERROR, "SRV_Uninit called. d:%d", 4); } \ No newline at end of file diff --git a/eagle/src/sched_service/sched_service.h b/eagle/src/sched_service/sched_service.h index 3de8576e63ebda88980ddff76443d0a63b0f53d4..21089b6b0a0cc02b34e7b7e6286c38c481d5fb24 100644 --- a/eagle/src/sched_service/sched_service.h +++ b/eagle/src/sched_service/sched_service.h @@ -23,13 +23,13 @@ extern "C" { #define SRV_API - -/** -Init the service -**/ -SRV_API int SRV_SetLogCallback(void(LogCallback)(int level, const char *fmt, va_list vl)); +SRV_API int SRV_SetLogCallback(void(LogCallback)(int level, const char *, const char *, va_list), + const char *usrInfo); SRV_API int SRV_Init(void); - +SRV_API int SRV_Start(void* pcy); +SRV_API int SRV_Update(void* pcy); +SRV_API int SRV_Stop(void); +SRV_API int SRV_Uninit(void); #ifdef __cplusplus } diff --git a/eagle/src/servicemgr.c b/eagle/src/servicemgr.c index c3a76f5ec5ff1bf5bf39acf5cc4f8623f72aafc0..dc35c16ebb794daaefad275c2034a08e7d821d16 100644 --- a/eagle/src/servicemgr.c +++ b/eagle/src/servicemgr.c @@ -14,21 +14,159 @@ * **************************************************************************** */ #include "servicemgr.h" +#include +#include +#include +#include #include "common.h" #include "policymgr.h" +#include "log.h" + +#define MAX_SERVICE_NUM 6 + +typedef int (*SrvFpSetLogCallback)(void(LogCallback)(int, const char *, const char *, va_list), + const char *usrInfo); +typedef int (*SrvFpInit)(void); +typedef int (*SrvFpStart)(void* pcy); +typedef int (*SrvFpUpdate)(void* pcy); +typedef int (*SrvFpStop)(void); +typedef int (*SrvFpUninit)(void); + +enum ServiceState { + ST_OFFLOAD = 0, + ST_LOADED = 1, + ST_RUNNING = 2, +}; + +typedef struct Service { + int status; + void *handle; + SrvFpSetLogCallback setLogCallback; + SrvFpInit init; + SrvFpStart start; + SrvFpUpdate update; + SrvFpStop stop; + SrvFpUninit uninit; +} Service; + +static struct Service services[MAX_SERVICE_NUM] = {0}; + +struct ServicePolicyMap { + int idx; + Service* service; + PcyBase* subPcy; +}; + +static struct ServicePolicyMap srvPcyMap[MAX_SERVICE_NUM] = {0}; +static void InitSrvPcyMap(void) +{ + for (int i = 0; i < MAX_SERVICE_NUM; i++) { + srvPcyMap[i].idx = i; + srvPcyMap[i].service = &services[i]; + } + srvPcyMap[0].subPcy = (PcyBase*)&(GetCurPolicy()->schedPcy); + srvPcyMap[1].subPcy = (PcyBase*)&(GetCurPolicy()->freqPcy); + srvPcyMap[2].subPcy = (PcyBase*)&(GetCurPolicy()->idlePcy); + srvPcyMap[3].subPcy = (PcyBase*)&(GetCurPolicy()->pcapPcy); + srvPcyMap[4].subPcy = (PcyBase*)&(GetCurPolicy()->mpcPcy); + srvPcyMap[5].subPcy = NULL; +} + +static void SrvLogCallback(int level, const char *usrInfo, 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_SVRMGR, "[%s] %s",usrInfo, message); +} + +#define LoadFunction(func, funcType, symName) \ + func = (funcType)dlsym(services[idx].handle, symName); \ + if (!func) { \ + successful = FALSE; \ + Logger(ERROR, MD_NM_SVRMGR, "Load function failed. err:%s", dlerror()); \ + } + +static int LoadService(int idx) +{ + services[idx].handle = dlopen(srvPcyMap[idx].subPcy->lib, RTLD_LAZY | RTLD_GLOBAL); + if (!services[idx].handle) { + Logger(ERROR, MD_NM_SVRMGR, "dlopen failed. %s", dlerror()); + return ERR_DL_OPEN_FAILED; + } + int successful = TRUE; + LoadFunction(services[idx].setLogCallback, SrvFpSetLogCallback, "SRV_SetLogCallback") + LoadFunction(services[idx].init, SrvFpInit, "SRV_Init") + LoadFunction(services[idx].start, SrvFpStart, "SRV_Start") + LoadFunction(services[idx].update, SrvFpUpdate, "SRV_Update") + LoadFunction(services[idx].stop, SrvFpStop, "SRV_Stop") + LoadFunction(services[idx].uninit, SrvFpUninit, "SRV_Uninit") + if (!successful) { + bzero(&services[idx], sizeof(services[idx])); + return ERR_DL_OPEN_FAILED; + } + return SUCCESS; +} + +static void OffloadService(int idx) +{ + if (services[idx].handle) { + dlclose(services[idx].handle); + } + bzero(&services[idx], sizeof(services[idx])); +} int InitServiceMgr(void) { - // todo + InitSrvPcyMap(); + for (int i = 0; i < MAX_SERVICE_NUM; i++) { + if (!srvPcyMap[i].subPcy || srvPcyMap[i].subPcy->enable != PCY_ENABLE) { + continue; + } + if (LoadService(i) != SUCCESS) { + continue; + } + services[i].setLogCallback(SrvLogCallback, srvPcyMap[i].subPcy->lib); + if (services[i].init() == SUCCESS) { + services[i].status = ST_LOADED; + } + } + return SUCCESS; } int StartServices(void) { - // todo + for (int i = 0; i < MAX_SERVICE_NUM; i++) { + if (services[i].status != ST_LOADED || services[i].start == NULL) { + continue; + } + if (services[i].start(srvPcyMap[i].subPcy) == SUCCESS) { + services[i].status = ST_RUNNING; + } + } return SUCCESS; } void StopServices(void) { - // todo + for (int i = 0; i < MAX_SERVICE_NUM; i++) { + if (services[i].stop) { + services[i].stop(); + services[i].status = ST_LOADED; + } + } +} + +void UninitServiceMgr(void) +{ + for (int i = 0; i < MAX_SERVICE_NUM; i++) { + if (services[i].status == ST_RUNNING && services[i].stop) { + services[i].stop(); + } + if (services[i].uninit) { + services[i].uninit(); + } + OffloadService(i); + } } diff --git a/eagle/uninstall.sh b/eagle/uninstall.sh index 230d098867b53c72f177ee411b3a21b07eead0a7..80767b3839803a39b47f010f52bfa7ab6942ad8e 100644 --- a/eagle/uninstall.sh +++ b/eagle/uninstall.sh @@ -9,6 +9,7 @@ if [ -f "./build/install_manifest.txt" ];then xargs rm < install_manifest.txt else rm /usr/lib/libpwrapi_adaptor.so + rm /usr/lib/libsched_service.so rm /usr/sbin/eagle rm /etc/sysconfig/eagle_config.ini rm /usr/lib/systemd/system/eagle.service