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: 11850733 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2128514B2 for ; Thu, 22 Oct 2020 09:54:57 +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 A4EF7223FB for ; Thu, 22 Oct 2020 09:54:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gWrEttkE"; 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 A4EF7223FB 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-mediatek-bounces+patchwork-linux-mediatek=patchwork.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=wBxmGh/yjsMwa0lX72OBLFAfwyMGAj4hyn9bPJOAGco=; b=gWrEttkEhxmwi+YTNt860lmDJP vZ+NGWmfEx5XjZhHzZegCNu2cAOrbuhVy88/T6exGbxQYc+V+P/eTkUsl6U6eVWxeXWZ04V3V3tZr e85ejVgLYXJakDZOKkshCrUSoOMqZEWJZIxRDMtQcgdSTklv8sVW6LBCW2V9SdX/15hDv64TBnT7s pF7JsVB6ZKQm6PMp3LHNDWD8lwUYPSDvT/y6HC6GlvZtLfL3OxsUP8eOeH7UX04wpL7WdmcN/psTa kpyDCCPnrbXClNIk7p4Z3crqVDKeUNutN07wO1OSKQXWfxb26VcV3yyMaCzvVeVFl/bgXk950mybG /nkY9enA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVXJ9-0007g8-Cz; Thu, 22 Oct 2020 09:54:55 +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-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 MIME_BASE64_TEXT RAW: Message text disguised using base64 encoding -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-mediatek@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, 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-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.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);