From 9f40e134859b527297531e6e978e09230f531414 Mon Sep 17 00:00:00 2001 From: heppen Date: Tue, 18 Jun 2024 10:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(msg=5Fbuffer):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dmsg=E9=98=9F=E5=88=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug_fix: 1. msg缓存队列判满逻辑有误; 2. GetProcWattAttrs日志打印错误; 3. pwrapis服务端消息队列满时,丢弃消息返错 --- .gitignore | 2 ++ common/inc/pwrbuffer.h | 6 +++--- pwrapic/gtest/CMakeLists.txt | 1 + pwrapic/src/pwrproc.c | 4 ++-- pwrapis/src/server.c | 9 +++++++++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2a96d98..7e4e261 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ cscope.* tags pwrapic/gtest/lib pwrapic/gtest/include/gtest +.cache +compile_commands.json \ No newline at end of file diff --git a/common/inc/pwrbuffer.h b/common/inc/pwrbuffer.h index 06cff03..d40339d 100644 --- a/common/inc/pwrbuffer.h +++ b/common/inc/pwrbuffer.h @@ -18,7 +18,7 @@ #include #include "pwrmsg.h" -#define PWR_BUFFER_SIZE 128 +#define PWR_BUFFER_SIZE 256 // Ring Queue, FIFO typedef struct PwrMsgBuffer { int head; @@ -60,8 +60,8 @@ static inline int IsFullBuffer(const PwrMsgBuffer *smb) if (!smb) { return 0; } - int t = (smb->head + 1) % PWR_BUFFER_SIZE; - return t == smb->tail; + int t = (smb->tail + 1) % PWR_BUFFER_SIZE; + return t == smb->head; } ResultWaitingMsgNode *CreateResultWaitingMsgNode(void); diff --git a/pwrapic/gtest/CMakeLists.txt b/pwrapic/gtest/CMakeLists.txt index d2bd3f6..9847864 100644 --- a/pwrapic/gtest/CMakeLists.txt +++ b/pwrapic/gtest/CMakeLists.txt @@ -31,6 +31,7 @@ target_link_libraries(gtest_test PRIVATE -lpwrapi -lgtest -lgtest_main + -lpthread ) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/pwrapic/src/pwrproc.c b/pwrapic/src/pwrproc.c index a3b92cf..2e90e6b 100644 --- a/pwrapic/src/pwrproc.c +++ b/pwrapic/src/pwrproc.c @@ -117,9 +117,9 @@ int GetProcWattAttrs(PWR_PROC_WattAttrs *wattAttrs) int ret = SendReqAndWaitForRsp(input, output); if (ret != PWR_SUCCESS) { - PwrLog(ERROR, "GetProcWattState failed. ret:%d", ret); + PwrLog(ERROR, "GetProcWattAttrs failed. ret:%d", ret); } else { - PwrLog(DEBUG, "GetProcWattState succeed."); + PwrLog(DEBUG, "GetProcWattAttrs succeed."); } return ret; } diff --git a/pwrapis/src/server.c b/pwrapis/src/server.c index b5dd8e5..93a29d6 100644 --- a/pwrapis/src/server.c +++ b/pwrapis/src/server.c @@ -313,6 +313,15 @@ static void ProcessRecvMsgFromClient(int clientIdx) return; } + if (IsFullBuffer(&g_recvBuff)) { + Logger(WARNING, MD_NM_SVR, + "Receive buffer is full, opt:%d, sysId:%d, seqId:%d", + msg->head.optType, msg->head.sysId, msg->head.seqId); + SendRspToClient(msg, PWR_ERR_MSG_BUFFER_FULL, NULL, 0); + ReleasePwrMsg(&msg); + return; + } + if (msg->head.sysId != (uint32_t)g_pwrClients[clientIdx].sysId) { ReleasePwrMsg(&msg); return; -- Gitee