From patchwork Tue Apr 13 11:50:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 91241 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 78589A0524; Tue, 13 Apr 2021 13:50:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB06D160ECA; Tue, 13 Apr 2021 13:50:14 +0200 (CEST) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id C6E82160E9C for ; Tue, 13 Apr 2021 13:50:05 +0200 (CEST) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FKP3z4GGHzB04h for ; Tue, 13 Apr 2021 19:47:43 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Tue, 13 Apr 2021 19:49:55 +0800 From: "Min Hu (Connor)" To: CC: Date: Tue, 13 Apr 2021 19:50:03 +0800 Message-ID: <1618314611-47978-5-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1618314611-47978-1-git-send-email-humin29@huawei.com> References: <1618314611-47978-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 04/12] net/hns3: fix potentially incorrect timing in MBX X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Chengchang Tang Currently, when processing MBX messages, the system timestamp is obtained to determine whether timeout occurs. However, the gettimeofday function is not monotonically increasing. Therefore, this may lead to incorrect judgment or difficulty exiting the loop. And actually, in this scenario, it is not necessary to obatain the timestamp. This patch deletes the call to the gettimeofday function during MBX message processing. Fixes: 463e748964f5 ("net/hns3: support mailbox") Cc: stable@dpdk.org Signed-off-by: Chengchang Tang Signed-off-by: Min Hu (Connor) --- drivers/net/hns3/hns3_mbx.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/hns3/hns3_mbx.c b/drivers/net/hns3/hns3_mbx.c index c5b0856..eb202dd 100644 --- a/drivers/net/hns3/hns3_mbx.c +++ b/drivers/net/hns3/hns3_mbx.c @@ -61,13 +61,12 @@ static int hns3_get_mbx_resp(struct hns3_hw *hw, uint16_t code, uint16_t subcode, uint8_t *resp_data, uint16_t resp_len) { -#define HNS3_MAX_RETRY_MS 500 +#define HNS3_MAX_RETRY_US 500000 #define HNS3_WAIT_RESP_US 100 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); struct hns3_mbx_resp_status *mbx_resp; + uint32_t wait_time = 0; bool received; - uint64_t now; - uint64_t end; if (resp_len > HNS3_MBX_MAX_RESP_DATA_SIZE) { hns3_err(hw, "VF mbx response len(=%u) exceeds maximum(=%d)", @@ -75,9 +74,7 @@ hns3_get_mbx_resp(struct hns3_hw *hw, uint16_t code, uint16_t subcode, return -EINVAL; } - now = get_timeofday_ms(); - end = now + HNS3_MAX_RETRY_MS; - while (now < end) { + while (wait_time < HNS3_MAX_RETRY_US) { if (__atomic_load_n(&hw->reset.disable_cmd, __ATOMIC_RELAXED)) { hns3_err(hw, "Don't wait for mbx respone because of " "disable_cmd"); @@ -103,10 +100,10 @@ hns3_get_mbx_resp(struct hns3_hw *hw, uint16_t code, uint16_t subcode, if (received) break; - now = get_timeofday_ms(); + wait_time += HNS3_WAIT_RESP_US; } hw->mbx_resp.req_msg_data = 0; - if (now >= end) { + if (wait_time >= HNS3_MAX_RETRY_US) { hns3_mbx_proc_timeout(hw, code, subcode); return -ETIME; }