From 989e4335c825dff7f3d4cb82a5103ddab1e6d0c8 Mon Sep 17 00:00:00 2001 From: queyanwen Date: Fri, 4 Nov 2022 16:39:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=87=87=E9=9B=86=E4=BB=BB=E5=8A=A1=E5=92=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/inc/pwrdata.h | 26 +++++++++++++- common/inc/pwrerr.h | 1 + common/inc/pwrmsg.h | 3 ++ pwrapic/inc/powerapi.h | 3 ++ pwrapic/inc/pwrcpu.h | 3 +- pwrapic/inc/pwrdisk.h | 4 +-- pwrapic/inc/pwrnet.h | 4 +-- pwrapic/inc/pwrtask.h | 23 +++++++++++++ pwrapic/inc/pwrusb.h | 4 +-- pwrapic/inc/sockclient.h | 4 ++- pwrapic/src/powerapi.c | 34 +++++++++++++++++++ pwrapic/src/pwrtask.c | 60 +++++++++++++++++++++++++++++++++ pwrapic/src/sockclient.c | 33 ++++++++++++++++-- pwrapis/conf/pwrapis_config.ini | 16 ++++----- 14 files changed, 197 insertions(+), 21 deletions(-) create mode 100644 pwrapic/inc/pwrtask.h create mode 100644 pwrapic/src/pwrtask.c diff --git a/common/inc/pwrdata.h b/common/inc/pwrdata.h index dd7e0bf..8e7d8e8 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 0a659fa..692b3f4 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 3b39179..b7e3486 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 87aec98..de748d4 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 7d253a3..3d21ece 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 314c00f..3f1342b 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 ffda8fe..d303423 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 0000000..54aec7d --- /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 87e3eb1..32e5837 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 a6e1aa3..621a36c 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 0bd30ed..c8aea67 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 0000000..8cfd9d5 --- /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 7329769..b50b5c2 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 a95677e..ec44486 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 -- Gitee