Add MMC software queue support
Subsystems (4)
v2 cover Add MMC software queue support
Hi All,
Now the MMC read/write stack will always wait for previous request is completed by mmc_blk_rw_wait(), before sending a new request to hardware, or queue a work to complete request, that will bring context switching overhead, especially for high I/O per second rates, to affect the IO performance.
Thus this patch set will introduce the MMC software command queue support based on command queue engine's interfaces, and set the queue depth as 2, that means we do not need wait for previous request is completed and can queue 2 requests in flight. It is enough to let the irq handler always trigger the next request without a context switch and then ask the blk_mq layer for the next one to get queued, as well as avoiding a long latency.
Moreover we can expand the MMC software queue interface to support MMC packed request or packed command instead of adding new interfaces, according to previosus discussion.
Below are some comparison data with fio tool. The fio command I used is like below with changing the '--rw' parameter and enabling the direct IO flag to measure the actual hardware transfer speed in 4K block size.
./fio --filename=/dev/mmcblk0p30 --direct=1 --iodepth=20 --rw=read --bs=4K --size=512M --group_reporting --numjobs=20 --name=test_read
My eMMC card working at HS400 Enhanced strobe mode:
[ 2.229856] mmc0: new HS400 Enhanced strobe MMC card at address 0001 [ 2.237566] mmcblk0: mmc0:0001 HBG4a2 29.1 GiB [ 2.242621] mmcblk0boot0: mmc0:0001 HBG4a2 partition 1 4.00 MiB [ 2.249110] mmcblk0boot1: mmc0:0001 HBG4a2 partition 2 4.00 MiB [ 2.255307] mmcblk0rpmb: mmc0:0001 HBG4a2 partition 3 4.00 MiB, chardev (248:0)
1. Without MMC software queue
I tested 3 times for each case and output a average speed.
1) Sequential read:
Speed: 28.9MiB/s, 26.4MiB/s, 30.9MiB/s
Average speed: 28.7MiB/s
2) Random read:
Speed: 18.2MiB/s, 8.9MiB/s, 15.8MiB/s
Average speed: 14.3MiB/s
3) Sequential write:
Speed: 21.1MiB/s, 27.9MiB/s, 25MiB/s
Average speed: 24.7MiB/s
4) Random write:
Speed: 21.5MiB/s, 18.1MiB/s, 18.1MiB/s
Average speed: 19.2MiB/s
2. With MMC software queue
I tested 3 times for each case and output a average speed.
1) Sequential read:
Speed: 44.1MiB/s, 42.3MiB/s, 44.4MiB/s
Average speed: 43.6MiB/s
2) Random read:
Speed: 30.6MiB/s, 30.9MiB/s, 30.5MiB/s
Average speed: 30.6MiB/s
3) Sequential write:
Speed: 44.1MiB/s, 45.9MiB/s, 44.2MiB/s
Average speed: 44.7MiB/s
4) Random write:
Speed: 45.1MiB/s, 43.3MiB/s, 42.4MiB/s
Average speed: 43.6MiB/s
Form above data, we can see the MMC software queue can help to improve the performance obviously.
Any comments are welcome. Thanks a lot.
Changes from v1:
- Add request_done ops for sdhci_ops.
- Replace virtual command queue with software queue for functions and variables.
- Rename the software queue file and add sqhci.h header file.
Baolin Wang (4):
mmc: host: cqhci: Move the struct cqhci_slot into header file
mmc: Add MMC software queue support
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci-sprd: Add software queue support
drivers/mmc/core/block.c | 61 ++++++++ drivers/mmc/core/mmc.c | 13 +- drivers/mmc/core/queue.c | 25 ++- drivers/mmc/host/Kconfig | 9 ++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/cqhci.c | 10 -- drivers/mmc/host/cqhci.h | 17 +- drivers/mmc/host/sdhci-sprd.c | 26 ++++ drivers/mmc/host/sdhci.c | 12 +- drivers/mmc/host/sdhci.h | 2 + drivers/mmc/host/sqhci.c | 345 +++++++++++++++++++++++++++++++++++++++++ drivers/mmc/host/sqhci.h | 35 +++++ include/linux/mmc/host.h | 3 + 13 files changed, 536 insertions(+), 23 deletions(-) create mode 100644 drivers/mmc/host/sqhci.c create mode 100644 drivers/mmc/host/sqhci.h
Signature · 1 line
1.7.9.5
PATCH v2 1/4 mmc: host: cqhci: Move the struct cqhci_slot into header file
The struct cqhci_slot will be used by MMC software queue introducing by following patches, thus move it to the header file.
--- drivers/mmc/host/cqhci.c | 10 ---------- drivers/mmc/host/cqhci.h | 11 ++++++++++- 2 files changed, 10 insertions(+), 11 deletions(-)
drivers/mmc/host/cqhci.c +0 -10
@@ -21,16 +21,6 @@#define DCMD_SLOT 31#define NUM_SLOTS 32 -struct cqhci_slot { -struct mmc_request *mrq; -unsigned int flags; -#define CQHCI_EXTERNAL_TIMEOUT BIT(0) -#define CQHCI_COMPLETED BIT(1) -#define CQHCI_HOST_CRC BIT(2) -#define CQHCI_HOST_TIMEOUT BIT(3) -#define CQHCI_HOST_OTHER BIT(4) -}; -static inline u8 *get_desc (struct cqhci_host *cq_host,u8 tag) {return cq_host->desc_base + (tag * cq_host->slot_sz);
drivers/mmc/host/cqhci.h +10 -1
@@ -141,7 +141,16 @@struct cqhci_host_ops ;struct mmc_host ;struct mmc_request ; -struct cqhci_slot ; + +struct cqhci_slot { +struct mmc_request *mrq; +unsigned int flags; +#define CQHCI_EXTERNAL_TIMEOUT BIT(0) +#define CQHCI_COMPLETED BIT(1) +#define CQHCI_HOST_CRC BIT(2) +#define CQHCI_HOST_TIMEOUT BIT(3) +#define CQHCI_HOST_OTHER BIT(4) +};struct cqhci_host {const struct cqhci_host_ops *ops;
Signature · 1 line
1.7.9.5
PATCH v2 2/4 mmc: Add MMC software queue support
In reply to Baolin WangNow the MMC read/write stack will always wait for previous request is completed by mmc_blk_rw_wait(), before sending a new request to hardware, or queue a work to complete request, that will bring context switching overhead, especially for high I/O per second rates, to affect the IO performance.
Thus this patch introduces MMC software queue interface based on the hardware command queue engine's interfaces, which is similar with the hardware command queue engine's idea, that can remove the context switching. Moreover we set the queue depth as 2 for software queue, that is enough to let the irq handler always trigger the next request without a context switch and then ask the blk_mq layer for the next one to get queued, as well as avoiding a long latency.
Quoted 1 line
From the fio testing data in cover letter, we can see the software
queue can improve performance obviously with 4K block size, increasing about 52% for sequential read, increasing about 114% for random read, increasing about 81% for sequential write, and increasing about 127% for random write.
Moreover we can expand the software queue interface to support MMC packed request or packed command in future.
--- drivers/mmc/core/block.c | 61 ++++++++ drivers/mmc/core/mmc.c | 13 +- drivers/mmc/core/queue.c | 25 +++- drivers/mmc/host/Kconfig | 8 ++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/cqhci.h | 6 + drivers/mmc/host/sqhci.c | 345 +++++++++++++++++++++++++++++++++++++++++++++ drivers/mmc/host/sqhci.h | 35 +++++ include/linux/mmc/host.h | 3 + 9 files changed, 487 insertions(+), 10 deletions(-) create mode 100644 drivers/mmc/host/sqhci.c create mode 100644 drivers/mmc/host/sqhci.h
drivers/mmc/core/block.c +61 -0
@@ -168,6 +168,11 @@ struct mmc_rpmb_data {static inline int mmc_blk_part_switch (struct mmc_card *card,unsigned int part_type); +static void mmc_blk_rw_rq_prep (struct mmc_queue_req *mqrq, +struct mmc_card *card, +int disable_multi, +struct mmc_queue *mq); +static void mmc_blk_swq_req_done (struct mmc_request *mrq);static struct mmc_blk_data *mmc_blk_get (struct gendisk *disk) {
@@ -1569,9 +1574,30 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue *mq, struct request *req)return mmc_blk_cqe_start_req (mq->card->host, mrq); } +static int mmc_blk_swq_issue_rw_rq (struct mmc_queue *mq,struct request *req) +{ +struct mmc_queue_req *mqrq =req_to_mmc_queue_req (req); +struct mmc_host *host = mq->card->host; +int err; + +mmc_blk_rw_rq_prep (mqrq, mq->card,0 , mq); + mqrq->brq.mrq.done = mmc_blk_swq_req_done; +mmc_pre_req (host, &mqrq->brq.mrq); + + err =mmc_cqe_start_req (host, &mqrq->brq.mrq); +if (err) +mmc_post_req (host, &mqrq->brq.mrq, err); + +return err; +} +static int mmc_blk_cqe_issue_rw_rq (struct mmc_queue *mq,struct request *req) {struct mmc_queue_req *mqrq =req_to_mmc_queue_req (req); +struct mmc_host *host = mq->card->host; + +if (host->swq_enabled) +return mmc_blk_swq_issue_rw_rq (mq, req);mmc_blk_data_prep (mq, mqrq,0 ,NULL ,NULL );
@@ -1957,6 +1983,41 @@ static void mmc_blk_urgent_bkops(struct mmc_queue *mq,mmc_run_bkops (mq->card); } +static void mmc_blk_swq_req_done (struct mmc_request *mrq) +{ +struct mmc_queue_req *mqrq = + container_of(mrq, struct mmc_queue_req, brq.mrq); +struct request *req =mmc_queue_req_to_req (mqrq); +struct request_queue *q = req->q; +struct mmc_queue *mq = q->queuedata; +struct mmc_host *host = mq->card->host; +unsigned long flags; + +if (mmc_blk_rq_error (&mqrq->brq) || +mmc_blk_urgent_bkops_needed (mq, mqrq)) { +spin_lock_irqsave (&mq->lock, flags); + mq->recovery_needed = true; + mq->recovery_req = req; +spin_unlock_irqrestore (&mq->lock, flags); + + host->cqe_ops->cqe_recovery_start (host); + +schedule_work (&mq->recovery_work); +return ; + } + +mmc_blk_rw_reset_success (mq, req); + +/* +* Block layer timeouts race with completions which means the normal +* completion path cannot be used during recovery. +*/ +if (mq->in_recovery) +mmc_blk_cqe_complete_rq (mq, req); +else +blk_mq_complete_request (req); +} +void mmc_blk_mq_complete (struct request *req) {struct mmc_queue *mq = req->q->queuedata;
drivers/mmc/core/mmc.c +10 -3
@@ -1852,15 +1852,22 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,*/ card->reenable_cmdq = card->ext_csd.cmdq_en; -if (card->ext_csd.cmdq_en && !host->cqe_enabled) { +if (host->cqe_ops && !host->cqe_enabled) { err = host->cqe_ops->cqe_enable (host, card);if (err) {pr_err ("%s: Failed to enable CQE, error %d\n" ,mmc_hostname (host), err); }else { host->cqe_enabled = true; -pr_info ("%s: Command Queue Engine enabled\n" , -mmc_hostname (host)); + +if (card->ext_csd.cmdq_en) { +pr_info ("%s: Command Queue Engine enabled\n" , +mmc_hostname (host)); + }else { + host->swq_enabled = true; +pr_info ("%s: Software Queue enabled\n" , +mmc_hostname (host)); + } } }
drivers/mmc/core/queue.c +18 -7
@@ -60,7 +60,7 @@ enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req) {struct mmc_host *host = mq->card->host; -if (mq->use_cqe) +if (mq->use_cqe && !host->swq_enabled)return mmc_cqe_issue_type (host, req);if (req_op (req) ==REQ_OP_READ ||req_op (req) ==REQ_OP_WRITE )
@@ -122,12 +122,14 @@ static enum blk_eh_timer_return mmc_mq_timed_out(struct request *req, {struct request_queue *q = req->q;struct mmc_queue *mq = q->queuedata; +struct mmc_card *card = mq->card; +struct mmc_host *host = card->host;unsigned long flags;int ret;spin_lock_irqsave (&mq->lock, flags); -if (mq->recovery_needed || !mq->use_cqe) +if (mq->recovery_needed || !mq->use_cqe || host->swq_enabled) ret =BLK_EH_RESET_TIMER ;else ret =mmc_cqe_timed_out (req);
@@ -142,12 +144,13 @@ static void mmc_mq_recovery_handler(struct work_struct *work) struct mmc_queue *mq = container_of(work, struct mmc_queue, recovery_work);struct request_queue *q = mq->queue; +struct mmc_host *host = mq->card->host;mmc_get_card (mq->card, &mq->ctx); mq->in_recovery = true; -if (mq->use_cqe) +if (mq->use_cqe && !host->swq_enabled)mmc_blk_cqe_recovery (mq);else mmc_blk_mq_recovery (mq);
@@ -158,6 +161,9 @@ static void mmc_mq_recovery_handler(struct work_struct *work) mq->recovery_needed = false;spin_unlock_irq (&mq->lock); +if (host->swq_enabled) + host->cqe_ops->cqe_recovery_finish (host); +mmc_put_card (mq->card, &mq->ctx);blk_mq_run_hw_queues (q, true);
@@ -407,11 +413,16 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card)* The queue depth for CQE must match the hardware because the request * tag is used to index the hardware queue. */ -if (mq->use_cqe) - mq->tag_set.queue_depth = -min_t (int, card->ext_csd.cmdq_depth, host->cqe_qdepth); -else +if (mq->use_cqe) { +if (host->swq_enabled) + mq->tag_set.queue_depth = host->cqe_qdepth; +else + mq->tag_set.queue_depth = +min_t (int, card->ext_csd.cmdq_depth, host->cqe_qdepth); + }else { mq->tag_set.queue_depth =MMC_QUEUE_DEPTH ; + } + mq->tag_set.numa_node =NUMA_NO_NODE ; mq->tag_set.flags =BLK_MQ_F_SHOULD_MERGE |BLK_MQ_F_BLOCKING ; mq->tag_set.nr_hw_queues =1 ;
drivers/mmc/host/Kconfig +8 -0
@@ -923,6 +923,14 @@ config MMC_CQHCI If unsure, say N. +config MMC_SQHCI + bool "Software Queue Host Controller Interface support" + help + This selects the Software Queue Host Controller Interface (SQHCI) + support. + + If unsure, say N. + config MMC_TOSHIBA_PCI tristate "Toshiba Type A SD/MMC Card Interface Driver" depends on PCI
drivers/mmc/host/Makefile +1 -0
@@ -97,6 +97,7 @@ obj-$(CONFIG_MMC_SDHCI_BRCMSTB) += sdhci-brcmstb.o obj-$(CONFIG_MMC_SDHCI_OMAP) += sdhci-omap.o obj-$(CONFIG_MMC_SDHCI_SPRD) += sdhci-sprd.o obj-$(CONFIG_MMC_CQHCI) += cqhci.o +obj-$(CONFIG_MMC_SQHCI) += sqhci.o ifeq ($(CONFIG_CB710_DEBUG),y) CFLAGS-cb710-mmc += -DDEBUG
drivers/mmc/host/cqhci.h +6 -0
@@ -205,6 +205,12 @@ struct cqhci_host {struct completion halt_comp;wait_queue_head_t wait_queue;struct cqhci_slot *slot; + +#ifdef CONFIG_MMC_SQHCI +/* Software queue support */ +int next_tag; +struct mmc_request *mrq; +#endif };struct cqhci_host_ops {
drivers/mmc/host/sqhci.c new file +345 -0
345 lines not on this page · raw message
drivers/mmc/host/sqhci.h new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef LINUX_MMC_SQHCI_H +#define LINUX_MMC_SQHCI_H + +#include "cqhci.h" + +#ifdef CONFIG_MMC_SQHCI +int sqhci_init (struct cqhci_host *cqv_host,struct mmc_host *mmc); +void sqhci_suspend (struct mmc_host *mmc); +int sqhci_resume (struct mmc_host *mmc); +bool sqhci_finalize_request (struct mmc_host *mmc,struct mmc_request *mrq); +#else +static inline int sqhci_init (struct cqhci_host *cqv_host,struct mmc_host *mmc) +{ +return -EINVAL ; +} + +static inline void sqhci_suspend (struct mmc_host *mmc) +{ +} + +static inline int sqhci_resume (struct mmc_host *mmc) +{ +return 0 ; +} + +static inline bool sqhci_finalize_request (struct mmc_host *mmc, +struct mmc_request *mrq) +{ +return false; +} + +#endif + +#endif
include/linux/mmc/host.h +3 -0
@@ -459,6 +459,9 @@ struct mmc_host {bool cqe_enabled;bool cqe_on; +/* Software Queue support */ +bool swq_enabled; +unsigned long private[0 ]____cacheline_aligned ; };
Signature · 1 line
1.7.9.5
PATCH v2 3/4 mmc: host: sdhci: Add request_done ops for struct sdhci_ops
In reply to Baolin WangAdd request_done ops for struct sdhci_ops as a preparation in case some host controllers have different method to complete one request, such as supporting request completion of MMC software queue.
--- drivers/mmc/host/sdhci.c | 12 ++++++++++-- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +10 -2
@@ -2710,7 +2710,10 @@ static bool sdhci_request_done(struct sdhci_host *host)spin_unlock_irqrestore (&host->lock, flags); -mmc_request_done (host->mmc, mrq); +if (host->ops->request_done) + host->ops->request_done (host, mrq); +else +mmc_request_done (host->mmc, mrq);return false; }
@@ -3133,7 +3136,12 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)/* Process mrqs ready for immediate completion */ for (i =0 ; i <SDHCI_MAX_MRQS ; i++) { -if (mrqs_done[i]) +if (!mrqs_done[i]) +continue ; + +if (host->ops->request_done) + host->ops->request_done (host, mrqs_done[i]); +else mmc_request_done (host->mmc, mrqs_done[i]); }
drivers/mmc/host/sdhci.h +2 -0
@@ -643,6 +643,8 @@ struct sdhci_ops {void (*voltage_switch)(struct sdhci_host *host);void (*adma_write_desc)(struct sdhci_host *host,void **desc,dma_addr_t addr,int len,unsigned int cmd); +void (*request_done)(struct sdhci_host *host, +struct mmc_request *mrq); };#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
Signature · 1 line
1.7.9.5
PATCH v2 4/4 mmc: host: sdhci-sprd: Add software queue support
In reply to Baolin WangAdd software queue support to improve the performance.
--- drivers/mmc/host/Kconfig | 1 + drivers/mmc/host/sdhci-sprd.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
drivers/mmc/host/Kconfig +1 -0
@@ -619,6 +619,7 @@ config MMC_SDHCI_SPRD depends on ARCH_SPRD depends on MMC_SDHCI_PLTFM select MMC_SDHCI_IO_ACCESSORS + select MMC_SQHCI help This selects the SDIO Host Controller in Spreadtrum SoCs, this driver supports R11(IP version: R11P0).
drivers/mmc/host/sdhci-sprd.c +26 -0
@@ -19,6 +19,7 @@#include <linux/slab.h> #include "sdhci-pltfm.h" +#include "sqhci.h" /* SDHCI_ARGUMENT2 register high 16bit */ #define SDHCI_SPRD_ARG2_STUFF GENMASK(31, 16)
@@ -379,6 +380,16 @@ static unsigned int sdhci_sprd_get_ro(struct sdhci_host *host)return 0 ; } +static void sdhci_sprd_request_done (struct sdhci_host *host, +struct mmc_request *mrq) +{ +/* Validate if the request was from software queue firstly. */ +if (sqhci_finalize_request (host->mmc, mrq)) +return ; + +mmc_request_done (host->mmc, mrq); +} +static struct sdhci_ops sdhci_sprd_ops = { .read_l = sdhci_sprd_readl, .write_l = sdhci_sprd_writel,
@@ -392,6 +403,7 @@ static unsigned int sdhci_sprd_get_ro(struct sdhci_host *host) .hw_reset = sdhci_sprd_hw_reset, .get_max_timeout_count = sdhci_sprd_get_max_timeout_count, .get_ro = sdhci_sprd_get_ro, + .request_done = sdhci_sprd_request_done, };static void sdhci_sprd_request (struct mmc_host *mmc,struct mmc_request *mrq)
@@ -521,6 +533,7 @@ static int sdhci_sprd_probe(struct platform_device *pdev) {struct sdhci_host *host;struct sdhci_sprd_host *sprd_host; +struct cqhci_host *sq_host;struct clk *clk;int ret =0 ;
@@ -631,6 +644,16 @@ static int sdhci_sprd_probe(struct platform_device *pdev) sprd_host->flags = host->flags; + sq_host =devm_kzalloc (&pdev->dev,sizeof (*sq_host),GFP_KERNEL ); +if (!sq_host) { + ret = -ENOMEM ; + goto err_cleanup_host; + } + + ret =sqhci_init (sq_host, host->mmc); +if (ret) + goto err_cleanup_host; + ret =__sdhci_add_host (host);if (ret) goto err_cleanup_host;
@@ -689,6 +712,7 @@ static int sdhci_sprd_runtime_suspend(struct device *dev)struct sdhci_host *host =dev_get_drvdata (dev);struct sdhci_sprd_host *sprd_host =TO_SPRD_HOST (host); +sqhci_suspend (host->mmc);sdhci_runtime_suspend_host (host);clk_disable_unprepare (sprd_host->clk_sdio);
@@ -717,6 +741,8 @@ static int sdhci_sprd_runtime_resume(struct device *dev) goto clk_disable;sdhci_runtime_resume_host (host,1 ); +sqhci_resume (host->mmc); +return 0 ; clk_disable:
Signature · 1 line
1.7.9.5