From nobody Wed Dec 17 07:36:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC998EE49A0 for ; Wed, 23 Aug 2023 06:18:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232911AbjHWGS2 (ORCPT ); Wed, 23 Aug 2023 02:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232877AbjHWGSV (ORCPT ); Wed, 23 Aug 2023 02:18:21 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC8CCF1; Tue, 22 Aug 2023 23:18:17 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 37N6Hsxh025248; Wed, 23 Aug 2023 14:17:54 +0800 (+08) (envelope-from Wenchao.Chen@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx05.spreadtrum.com [10.29.1.56]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RVwtp70Gjz2QM4RY; Wed, 23 Aug 2023 14:15:30 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx05.spreadtrum.com (10.29.1.56) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 23 Aug 2023 14:17:52 +0800 From: Wenchao Chen To: CC: , , , , , Wenchao Chen Subject: [PATCH V2 1/2] mmc: queue: replace immediate with hsq->depth Date: Wed, 23 Aug 2023 14:17:33 +0800 Message-ID: <20230823061734.27479-2-wenchao.chen@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230823061734.27479-1-wenchao.chen@unisoc.com> References: <20230823061734.27479-1-wenchao.chen@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx05.spreadtrum.com (10.29.1.56) X-MAIL: SHSQR01.spreadtrum.com 37N6Hsxh025248 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hsq is similar to cqe, using hsq->depth to represent the maximum processing capacity of hsq. We can adjust hsq->depth according to the actual situation. Signed-off-by: Wenchao Chen --- drivers/mmc/core/queue.c | 6 +----- drivers/mmc/host/mmc_hsq.c | 1 + drivers/mmc/host/mmc_hsq.h | 6 ++++++ include/linux/mmc/host.h | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c index b396e3900717..a0a2412f62a7 100644 --- a/drivers/mmc/core/queue.c +++ b/drivers/mmc/core/queue.c @@ -260,11 +260,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_c= tx *hctx, } break; case MMC_ISSUE_ASYNC: - /* - * For MMC host software queue, we only allow 2 requests in - * flight to avoid a long latency. - */ - if (host->hsq_enabled && mq->in_flight[issue_type] > 2) { + if (host->hsq_enabled && mq->in_flight[issue_type] > host->hsq_depth) { spin_unlock_irq(&mq->lock); return BLK_STS_RESOURCE; } diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c index 424dc7b07858..8556cacb21a1 100644 --- a/drivers/mmc/host/mmc_hsq.c +++ b/drivers/mmc/host/mmc_hsq.c @@ -337,6 +337,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *= mmc) hsq->mmc =3D mmc; hsq->mmc->cqe_private =3D hsq; mmc->cqe_ops =3D &mmc_hsq_ops; + mmc->hsq_depth =3D HSQ_NORMAL_DEPTH; =20 for (i =3D 0; i < HSQ_NUM_SLOTS; i++) hsq->tag_slot[i] =3D HSQ_INVALID_TAG; diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h index 1808024fc6c5..aa5c4543b55f 100644 --- a/drivers/mmc/host/mmc_hsq.h +++ b/drivers/mmc/host/mmc_hsq.h @@ -5,6 +5,12 @@ #define HSQ_NUM_SLOTS 64 #define HSQ_INVALID_TAG HSQ_NUM_SLOTS =20 +/* + * For MMC host software queue, we only allow 2 requests in + * flight to avoid a long latency. + */ +#define HSQ_NORMAL_DEPTH 2 + struct hsq_slot { struct mmc_request *mrq; }; diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 461d1543893b..1fd8b1dd8698 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -520,6 +520,7 @@ struct mmc_host { =20 /* Host Software Queue support */ bool hsq_enabled; + int hsq_depth; =20 u32 err_stats[MMC_ERR_MAX]; unsigned long private[] ____cacheline_aligned; --=20 2.17.1 From nobody Wed Dec 17 07:36:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7A2FEE49B2 for ; Wed, 23 Aug 2023 06:18:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232895AbjHWGSZ (ORCPT ); Wed, 23 Aug 2023 02:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232180AbjHWGSV (ORCPT ); Wed, 23 Aug 2023 02:18:21 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5085AE40; Tue, 22 Aug 2023 23:18:19 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 37N6Hti6025267; Wed, 23 Aug 2023 14:17:55 +0800 (+08) (envelope-from Wenchao.Chen@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx05.spreadtrum.com [10.29.1.56]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RVwtr1gmsz2QM4RY; Wed, 23 Aug 2023 14:15:32 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx05.spreadtrum.com (10.29.1.56) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 23 Aug 2023 14:17:53 +0800 From: Wenchao Chen To: CC: , , , , , Wenchao Chen Subject: [PATCH V2 2/2] mmc: hsq: dynamic adjustment of hsq->depth Date: Wed, 23 Aug 2023 14:17:34 +0800 Message-ID: <20230823061734.27479-3-wenchao.chen@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230823061734.27479-1-wenchao.chen@unisoc.com> References: <20230823061734.27479-1-wenchao.chen@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx05.spreadtrum.com (10.29.1.56) X-MAIL: SHSQR01.spreadtrum.com 37N6Hti6025267 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Increasing hsq_depth improves random write performance. Signed-off-by: Wenchao Chen --- drivers/mmc/host/mmc_hsq.c | 26 ++++++++++++++++++++++++++ drivers/mmc/host/mmc_hsq.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c index 8556cacb21a1..8682a3d16a76 100644 --- a/drivers/mmc/host/mmc_hsq.c +++ b/drivers/mmc/host/mmc_hsq.c @@ -21,6 +21,30 @@ static void mmc_hsq_retry_handler(struct work_struct *wo= rk) mmc->ops->request(mmc, hsq->mrq); } =20 +static void mmc_hsq_modify_threshold(struct mmc_hsq *hsq) +{ + struct mmc_host *mmc =3D hsq->mmc; + struct mmc_request *mrq; + struct hsq_slot *slot; + int need_change =3D 0; + int tag; + + for (tag =3D 0; tag < HSQ_NUM_SLOTS; tag++) { + slot =3D &hsq->slot[tag]; + mrq =3D slot->mrq; + if (mrq && mrq->data && (mrq->data->blocks =3D=3D HSQ_DATA_IS_4K) + && (mrq->data->flags & MMC_DATA_WRITE)) + need_change++; + else + break; + } + + if (need_change > 1) + mmc->hsq_depth =3D HSQ_PERFORMANCE_DEPTH; + else + mmc->hsq_depth =3D HSQ_NORMAL_DEPTH; +} + static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) { struct mmc_host *mmc =3D hsq->mmc; @@ -42,6 +66,8 @@ static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) return; } =20 + mmc_hsq_modify_threshold(hsq); + slot =3D &hsq->slot[hsq->next_tag]; hsq->mrq =3D slot->mrq; hsq->qcnt--; diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h index aa5c4543b55f..fc031e38f1e0 100644 --- a/drivers/mmc/host/mmc_hsq.h +++ b/drivers/mmc/host/mmc_hsq.h @@ -10,6 +10,8 @@ * flight to avoid a long latency. */ #define HSQ_NORMAL_DEPTH 2 +#define HSQ_PERFORMANCE_DEPTH 5 +#define HSQ_DATA_IS_4K 8 =20 struct hsq_slot { struct mmc_request *mrq; --=20 2.17.1