From patchwork Thu Oct 22 09:41:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "houlong.wei" X-Patchwork-Id: 11850735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81998C4363A for ; Thu, 22 Oct 2020 09:56:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F223F223FB for ; Thu, 22 Oct 2020 09:56:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cgorp/Mo"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="aHofETMC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F223F223FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=KdS0wajFSQl8GkvahuUfrHuvVtoykrnrtcSTpFkx2dY=; b=cgorp/MoZmDCEaEqGUyfY0zVhY BXMEqSjt2vP35TUnhe3+dv7As3Hvs4tIqJheEzZOxtbkgkEjf1pwMI85AmnEUbZApDrQWlwqFiAH4 +4xsQc6zgxg6EeklORSrJzNXqkeLIACjczbHKZq+4AqKS4xFZS0e43H7aJ1UT7koId6Wm+lVFVjJJ cYDZqaIugv5pB4LP7HANBLutXiX196cOnSlSQQJs1xZ3PNJ5N39nErTbusUFAd5N8tpcRwN92PVy1 cRG83tcsHFgLZt2QczJ31n6ee96LbHCKVjzneuafPKyVS18T/6H56KVc6Is/aRGO08NN3g0iM3hcr OUaDrdGQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVXJ7-0007eb-49; Thu, 22 Oct 2020 09:54:53 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVXJ5-0007c9-1A; Thu, 22 Oct 2020 09:54:52 +0000 X-UUID: 1447803fd8b64e178a5e1dcdbc1e8fd1-20201022 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=4h6hAq7l0V4rS9t709EExfcDsTlXaMuAC530Tl9I3lE=; b=aHofETMCPK01JrxMeZoldwr40Y5X+PCDLPMw/laQrLcXcZ6OlVKBFs/gi/y7vZtRxhEuIY+8c8Vjhp5cxY/Jo4ncD9Jzxc4Rhmr3nx2hmD0xVAH5xF6gyy64QR1/i1s3G5iyJKL+3/iI5oEhUbxCXFcZs8BDVP8Og+rqmCzRabE=; X-UUID: 1447803fd8b64e178a5e1dcdbc1e8fd1-20201022 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1309757871; Thu, 22 Oct 2020 01:54:31 -0800 Received: from MTKMBS02N1.mediatek.inc (172.21.101.77) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 22 Oct 2020 02:44:29 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 22 Oct 2020 17:44:21 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 22 Oct 2020 17:44:20 +0800 From: Houlong Wei To: Matthias Brugger , Jassi Brar Subject: [PATCH] soc: mediatek: cmdq: fixup possible timeout issue Date: Thu, 22 Oct 2020 17:41:53 +0800 Message-ID: <20201022094152.17662-1-houlong.wei@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201022_055451_261568_734E552B X-CRM114-Status: GOOD ( 13.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicolas Boichat , yongqiang.niu@mediatek.com, srv_heupstream@mediatek.com, Daoyuan Huang , linux-kernel@vger.kernel.org, Daniel Kurtz , Dennis-YC Hsieh , linux-mediatek@lists.infradead.org, Houlong Wei , Bibby Hsieh , CK HU , linux-arm-kernel@lists.infradead.org, ginny.chen@mediatek.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fixes: 576f1b4bc802 ("soc: mediatek: Add Mediatek CMDQ helper") There may be possible timeout issue when lots of cmdq packets are flushed to the same cmdq client. The necessary modifications are as below. 1.Adjust the timer timeout period as client->timeout_ms * client->pkt_cnt. 2.Optimize the time to start the timer. Signed-off-by: Houlong Wei Reviewed-by: Nicolas Boichat --- drivers/soc/mediatek/mtk-cmdq-helper.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c index dc644cfb6419..31142c193527 100644 --- a/drivers/soc/mediatek/mtk-cmdq-helper.c +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c @@ -350,7 +350,8 @@ static void cmdq_pkt_flush_async_cb(struct cmdq_cb_data data) del_timer(&client->timer); else mod_timer(&client->timer, jiffies + - msecs_to_jiffies(client->timeout_ms)); + msecs_to_jiffies(client->timeout_ms * + client->pkt_cnt)); spin_unlock_irqrestore(&client->lock, flags); } @@ -379,9 +380,7 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb, if (client->timeout_ms != CMDQ_NO_TIMEOUT) { spin_lock_irqsave(&client->lock, flags); - if (client->pkt_cnt++ == 0) - mod_timer(&client->timer, jiffies + - msecs_to_jiffies(client->timeout_ms)); + client->pkt_cnt++; spin_unlock_irqrestore(&client->lock, flags); } @@ -391,6 +390,21 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb, /* We can send next packet immediately, so just call txdone. */ mbox_client_txdone(client->chan, 0); + if (client->timeout_ms != CMDQ_NO_TIMEOUT) { + spin_lock_irqsave(&client->lock, flags); + /* + * GCE HW maybe execute too quickly and the callback function + * may be invoked earlier. If this happens, pkt_cnt is reduced + * by 1 in cmdq_pkt_flush_async_cb(). The timer is set only if + * pkt_cnt is greater than 0. + */ + if (client->pkt_cnt > 0) + mod_timer(&client->timer, jiffies + + msecs_to_jiffies(client->timeout_ms * + client->pkt_cnt)); + spin_unlock_irqrestore(&client->lock, flags); + } + return 0; } EXPORT_SYMBOL(cmdq_pkt_flush_async);