diff --git a/common/inc/pwrdata.h b/common/inc/pwrdata.h index dd7e0bf54ba81be95c82a6f5b5eb7247daaef54f..8e7d8e820116ebd4c9dde7be3d4b76e689998a78 100644 --- a/common/inc/pwrdata.h +++ b/common/inc/pwrdata.h @@ -14,13 +14,17 @@ * **************************************************************************** */ #ifndef __POWERAPI_DATA_H__ #define __POWERAPI_DATA_H__ - +#include #define MAX_ELEMENT_NAME_LEN 32 #define MAX_NAME_LEN 128 #define MAX_CPU_LIST_LEN 248 #define MAX_NUMA_NODE_NUM 16 #define MAX_GOV_NUM 16 #define MAX_STRING_LEN 1000 +#define MAX_TIME_LEN 24 +#define MAX_DC_INTERVAL 100000000 +#define MIN_DC_INTERVAL 500 + #define MAX_CPU_DMA_LATENCY 2000000000 #define MAX_DISK_LIST_LEN 128 @@ -29,6 +33,26 @@ enum Arch { X86_64 = 1, }; +typedef enum PWR_COM_COL_DATATYPE { + PWR_COM_DATATYPE_LLC_MISS = 1, + PWR_COM_DATATYPE_CPU_USAGE, + PWR_COM_DATATYPE_CPU_IPC, + + PWR_COM_DATATYPE_INVALIDE, +} PWR_COM_COL_DATATYPE; + +typedef struct PWR_COM_CallbackData { + char ctime[MAX_TIME_LEN]; + int dataType; + int dataLen; + void *data; +} PWR_COM_CallbackData; + +typedef struct PWR_COM_BasicDcTaskInfo { + PWR_COM_COL_DATATYPE dataType; + int interval; +} PWR_COM_BasicDcTaskInfo; + typedef struct PWR_CPU_NumaInfo { int nodeNo; char cpuList[MAX_CPU_LIST_LEN]; diff --git a/common/inc/pwrerr.h b/common/inc/pwrerr.h index 0a659fafae7843d7cd38692e67250973322472c2..692b3f4d12a7efcd70e108fdf54ef8de03fa1d45 100644 --- a/common/inc/pwrerr.h +++ b/common/inc/pwrerr.h @@ -25,6 +25,7 @@ enum RtnCode { ERR_SYS_EXCEPTION, ERR_NULL_POINTER, ERR_INVALIDE_PARAM, + ERR_CALLBACK_FUNCTION_SHOULD_BE_SET_FIRST, ERR_NOT_REGISTED = 100, ERR_OVER_MAX_CONNECTION, ERR_DISCONNECTED = 300, diff --git a/common/inc/pwrmsg.h b/common/inc/pwrmsg.h index 3b39179a76c837b6c05b0ec88382564fc9fdc63c..b7e34861527544de209c18ce3b2f472aa706deb7 100644 --- a/common/inc/pwrmsg.h +++ b/common/inc/pwrmsg.h @@ -46,6 +46,9 @@ typedef struct PwrMsg { } PwrMsg; enum OperationType { + COM_CREATE_DC_TASK = 10, + COM_DELETE_DC_TASK, + COM_CALLBACK_DATA, CPU_GET_INFO = 100, CPU_GET_USAGE, CPU_GET_CACHE_MISS, diff --git a/pwrapic/inc/powerapi.h b/pwrapic/inc/powerapi.h index 87aec98f99e8e0a647b3f87d603c121680460e08..de748d41f64d69cf063ce13750c3f87fed0091ef 100644 --- a/pwrapic/inc/powerapi.h +++ b/pwrapic/inc/powerapi.h @@ -31,6 +31,9 @@ extern "C" { PWR_API int PWR_SetLogCallback(void(LogCallback)(int level, const char *fmt, va_list vl)); PWR_API int PWR_Register(void); PWR_API int PWR_UnRegister(void); +PWR_API int PWR_SetMetaDataCallback(void(MetaDataCallback)(int taskId, const PWR_COM_CallbackData *callbackData)); +PWR_API int PWR_CreateDcTask(PWR_COM_BasicDcTaskInfo *basicDcTaskInfo, int *taskId); +PWR_API int PWR_DeleteDcTask(int taskId); // CPU PWR_API int PWR_CPU_GetInfo(PWR_CPU_Info *cpuInfo); diff --git a/pwrapic/inc/pwrcpu.h b/pwrapic/inc/pwrcpu.h index 7d253a399b442ab2959a037fe0ac4db4b866f96a..3d21ecee16abd0d289ed8361b637890434dbf752 100644 --- a/pwrapic/inc/pwrcpu.h +++ b/pwrapic/inc/pwrcpu.h @@ -15,7 +15,8 @@ #ifndef __POWERAPI_CPU_H__ #define __POWERAPI_CPU_H__ -#include "powerapi.h" +#include +#include "pwrdata.h" int GetCpuInfo(PWR_CPU_Info *cpuInfo); int GetCpuUsage(PWR_CPU_Usage *usage, uint32_t bufferSize); int GetCpuLlcMissPerIns(double *cacheMiss); diff --git a/pwrapic/inc/pwrdisk.h b/pwrapic/inc/pwrdisk.h index 314c00fb876b6ca058dd8b08c380cf8c71ae2de9..3f1342be990f7ce099eb09d2b34597024931ca16 100644 --- a/pwrapic/inc/pwrdisk.h +++ b/pwrapic/inc/pwrdisk.h @@ -14,8 +14,8 @@ * **************************************************************************** */ #ifndef __POWERAPI_DISK_H__ #define __POWERAPI_DISK_H__ - -#include "powerapi.h" +#include +#include "pwrdata.h" int GetDiskList(char diskList[][MAX_ELEMENT_NAME_LEN], uint32_t *len); int GetDiskLoad(PWR_DISK_Load load[], uint32_t *len, int spec); diff --git a/pwrapic/inc/pwrnet.h b/pwrapic/inc/pwrnet.h index ffda8fe3a26e89016ef2b9d4a3afdbf17c3d3d1e..d303423c497514958510ee7866fdab6cf9202a35 100644 --- a/pwrapic/inc/pwrnet.h +++ b/pwrapic/inc/pwrnet.h @@ -14,8 +14,8 @@ * **************************************************************************** */ #ifndef __POWERAPI_NET_H__ #define __POWERAPI_NET_H__ - -#include "powerapi.h" +#include +#include "pwrdata.h" int GetNetInfo(PWR_NET_Info *netInfo, uint32_t bufferSize); int GetNetThrough(char ethName[], PWR_NET_Through *ethThrough); diff --git a/pwrapic/inc/pwrtask.h b/pwrapic/inc/pwrtask.h new file mode 100644 index 0000000000000000000000000000000000000000..54aec7de2481026d4c491ae52a035b9639b629bf --- /dev/null +++ b/pwrapic/inc/pwrtask.h @@ -0,0 +1,23 @@ +/* ***************************************************************************** + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved. + * PowerAPI 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-11-01 + * Description: Provide service for PowerAPI refer to TASK. + * **************************************************************************** */ +#ifndef POWERAPI_COMM_H__ +#define POWERAPI_COMM_H__ + +#include "pwrdata.h" + +int CreateDcTask(PWR_COM_BasicDcTaskInfo *basicDcTaskInfo, int *taskId); +int DeleteDcTask(int taskId); + +#endif diff --git a/pwrapic/inc/pwrusb.h b/pwrapic/inc/pwrusb.h index 87e3eb1d65a16a7b4a3391590003ae9df32438ff..32e5837e02c861234e7631ec89d0002c41762d54 100644 --- a/pwrapic/inc/pwrusb.h +++ b/pwrapic/inc/pwrusb.h @@ -14,8 +14,8 @@ * **************************************************************************** */ #ifndef __POWERAPI_USB_H__ #define __POWERAPI_USB_H__ - -#include "powerapi.h" +#include +#include "pwrdata.h" int GetUsbAutoSuspend(PWR_USB_AutoSuspend usbAts[], uint32_t *len); int SetUsbAutoSuspend(PWR_USB_AutoSuspend usbAts[], uint32_t len); diff --git a/pwrapic/inc/sockclient.h b/pwrapic/inc/sockclient.h index a6e1aa35d8d37059d416b7500e60b0fa488a6371..621a36cb8c9b48e75a817c120b47714b6bab98da 100644 --- a/pwrapic/inc/sockclient.h +++ b/pwrapic/inc/sockclient.h @@ -15,6 +15,7 @@ #ifndef __POWERAPI_CONNECTION_H__ #define __POWERAPI_CONNECTION_H__ #include "pwrmsg.h" +#include "pwrdata.h" typedef struct ReqInputParam { enum OperationType optType; @@ -30,6 +31,7 @@ typedef struct RspOutputParam { int InitSockClient(void); int FiniSockClient(void); - +int SetMetaDataCallback(void(MetaDataCallback)(int, const PWR_COM_CallbackData *)); +int HasSetDataCallback(void); int SendReqAndWaitForRsp(ReqInputParam input, RspOutputParam output); #endif diff --git a/pwrapic/src/powerapi.c b/pwrapic/src/powerapi.c index 0bd30edf7ff89532176b1ae116edde6390aa84ed..c8aea67cb5f1b8d713eada343bbf1f9cfbee154c 100644 --- a/pwrapic/src/powerapi.c +++ b/pwrapic/src/powerapi.c @@ -18,6 +18,7 @@ #include #include "pwrlog.h" #include "sockclient.h" +#include "pwrtask.h" #include "pwrcpu.h" #include "pwrdisk.h" #include "pwrnet.h" @@ -74,6 +75,39 @@ int PWR_UnRegister(void) return ret; } + +int PWR_SetMetaDataCallback(void(MetaDataCallback)(int, const PWR_COM_CallbackData *)) +{ + if (MetaDataCallback) { + return SetMetaDataCallback(MetaDataCallback); + } + return ERR_NULL_POINTER; +} + +int PWR_CreateDcTask(PWR_COM_BasicDcTaskInfo *basicDcTaskInfo, int *taskId) +{ + CHECK_STATUS(); + CHECK_NULL_POINTER(basicDcTaskInfo); + CHECK_NULL_POINTER(taskId); + + if (basicDcTaskInfo->interval < MIN_DC_INTERVAL || basicDcTaskInfo->interval > MAX_DC_INTERVAL) { + return ERR_INVALIDE_PARAM; + } + + if (!HasSetDataCallback()) { + return ERR_CALLBACK_FUNCTION_SHOULD_BE_SET_FIRST; + } + + return CreateDcTask(basicDcTaskInfo, taskId); +} + +int PWR_DeleteDcTask(int taskId) +{ + CHECK_STATUS(); + + return DeleteDcTask(taskId); +} + int PWR_CPU_GetInfo(PWR_CPU_Info *cpuInfo) { CHECK_STATUS(); diff --git a/pwrapic/src/pwrtask.c b/pwrapic/src/pwrtask.c new file mode 100644 index 0000000000000000000000000000000000000000..8cfd9d53c1266c12b41fe425590e918c322061f2 --- /dev/null +++ b/pwrapic/src/pwrtask.c @@ -0,0 +1,60 @@ +/* ***************************************************************************** + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. + * PowerAPI 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-11-01 + * Description: Provide service for PowerAPI refer to TASK. + * **************************************************************************** */ + +#include "pwrtask.h" +#include +#include "pwrlog.h" +#include "pwrerr.h" +#include "sockclient.h" + +int CreateDcTask(PWR_COM_BasicDcTaskInfo *basicDcTaskInfo, int *taskId) +{ + ReqInputParam input; + input.optType = COM_CREATE_DC_TASK; + input.dataLen = sizeof(PWR_COM_BasicDcTaskInfo); + input.data = (char *)basicDcTaskInfo; + + RspOutputParam output; + uint32_t size = sizeof(int); + output.rspBuffSize = &size; + output.rspData = (void *)taskId; + + int ret = SendReqAndWaitForRsp(input, output); + if (ret != SUCCESS) { + PwrLog(ERROR, "CreateDcTask failed. ret:%d", ret); + } else { + PwrLog(DEBUG, "CreateDcTask Succeed."); + } + return ret; +} + +int DeleteDcTask(int taskId) +{ + ReqInputParam input; + input.optType = COM_DELETE_DC_TASK; + input.dataLen = sizeof(taskId); + input.data = (char *)&taskId; + RspOutputParam output; + output.rspBuffSize = NULL; + output.rspData = NULL; + + int ret = SendReqAndWaitForRsp(input, output); + if (ret != SUCCESS) { + PwrLog(ERROR, "DeleteDcTask failed. ret:%d", ret); + } else { + PwrLog(DEBUG, "DeleteDcTask Succeed."); + } + return ret; +} \ No newline at end of file diff --git a/pwrapic/src/sockclient.c b/pwrapic/src/sockclient.c index 7329769ee591d7443a81c803d706765717fde813..b50b5c2ea8e9e906a05e74e46f6a8d6dcb751283 100644 --- a/pwrapic/src/sockclient.c +++ b/pwrapic/src/sockclient.c @@ -96,6 +96,13 @@ static int WriteMsg(const void *pData, int len) return SUCCESS; } +static void (*g_metadata_callback)(int, const PWR_COM_CallbackData *) = NULL; +static void DoDataCallback(PwrMsg *msg) +{ + g_metadata_callback(msg->head.taskNo, (PWR_COM_CallbackData *)(msg->data)); + ReleasePwrMsg(&msg); +} + static void ProcessRspMsg(PwrMsg *rsp) { ResultWaitingMsgNode *rwm = FindAndMoveWaitingMsg(&g_waitList, rsp->head.seqId); @@ -112,8 +119,16 @@ static void ProcessRspMsg(PwrMsg *rsp) static void ProcessOtherMsg(PwrMsg *msg) { - if (AddToBufferTail(&g_recvBuff, msg) != SUCCESS) { + /* if (AddToBufferTail(&g_recvBuff, msg) != SUCCESS) { ReleasePwrMsg(&msg); + } */ + switch (msg->head.optType) { + case COM_CALLBACK_DATA: + DoDataCallback(msg); + break; + default: + ReleasePwrMsg(&msg); + break; } } @@ -347,6 +362,20 @@ int FiniSockClient(void) return SUCCESS; } +int SetMetaDataCallback(void(MetaDataCallback)(int, const PWR_COM_CallbackData *)) +{ + if (MetaDataCallback) { + g_metadata_callback = MetaDataCallback; + return SUCCESS; + } + return ERR_NULL_POINTER; +} + +int HasSetDataCallback(void) +{ + return g_metadata_callback != NULL; +} + int SendReqAndWaitForRsp(ReqInputParam input, RspOutputParam output) { if ((output.rspData && (!output.rspBuffSize || *output.rspBuffSize == 0))) { @@ -375,7 +404,7 @@ int SendReqAndWaitForRsp(ReqInputParam input, RspOutputParam output) ReleasePwrMsg(&rsp); return ret; } - + if (output.rspData) { uint32_t srcSize = *output.rspBuffSize; if (rsp->data) { diff --git a/pwrapis/conf/pwrapis_config.ini b/pwrapis/conf/pwrapis_config.ini index a95677e63e5a014c7479c2989acf40cd9d527ecd..ec444862ee76d435a5f37521e135295c8cc9ce56 100644 --- a/pwrapis/conf/pwrapis_config.ini +++ b/pwrapis/conf/pwrapis_config.ini @@ -1,17 +1,13 @@ [log] -file_size=1 -cmp_cnt=2 +# MB +file_size=10 +cmp_cnt=3 +# 0-debug 1-info 2-warning 3-error log_level=0 log_path=/opt/os_data/log bak_log_path=/opt/os_data/log/bak log_pfx=papis.log -[server] -#port=3028 -sock_file=pwrserver.sock - -#[gather] -#interval=1 -#mnt_point=/opt/os_data/mnt - +#[server] +#[gather] \ No newline at end of file