libwd/0050-util-optimize-for-wd_handle_msg_sync.patch

62 lines
1.6 KiB
Diff
Raw Permalink Normal View History

From f36aa5f7e8f82a90aa0cb729bf00cc51f76970d5 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Fri, 29 Mar 2024 17:01:03 +0800
Subject: [PATCH 50/52] util: optimize for wd_handle_msg_sync
1. Separate rx_cnt auto-increment and judgment.
2. Reduce the condition judgment in the case of eagain.
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
Signed-off-by: Qi Tao <taoqi10@huawei.com>
---
wd_util.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/wd_util.c b/wd_util.c
index 2635dc3..0744ff0 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1822,24 +1822,28 @@ int wd_handle_msg_sync(struct wd_alg_driver *drv, struct wd_msg_handle *msg_hand
do {
if (epoll_en) {
ret = wd_ctx_wait(ctx, POLL_TIME);
- if (ret < 0)
+ if (unlikely(ret < 0))
WD_ERR("wd ctx wait timeout(%d)!\n", ret);
}
ret = msg_handle->recv(drv, ctx, msg);
- if (ret == -WD_EAGAIN) {
- if (unlikely(rx_cnt++ >= timeout)) {
- WD_ERR("failed to recv msg: timeout!\n");
- return -WD_ETIMEDOUT;
+ if (ret != -WD_EAGAIN) {
+ if (unlikely(ret < 0)) {
+ WD_ERR("failed to recv msg: error = %d!\n", ret);
+ return ret;
}
+ break;
+ }
- if (balance && *balance > WD_BALANCE_THRHD)
- usleep(1);
- } else if (unlikely(ret < 0)) {
- WD_ERR("failed to recv msg: error = %d!\n", ret);
- return ret;
+ rx_cnt++;
+ if (unlikely(rx_cnt >= timeout)) {
+ WD_ERR("failed to recv msg: timeout!\n");
+ return -WD_ETIMEDOUT;
}
- } while (ret < 0);
+
+ if (balance && *balance > WD_BALANCE_THRHD)
+ usleep(1);
+ } while (1);
if (balance)
*balance = rx_cnt;
--
2.25.1