Skip to contentSkip to conversation

Add MMC software queue support

PATCH In review Baolin Wang 3 participants 14 messages Feb 12, 2020 – Jun 15, 2020

Subsystems (6)
lore
Share & tools
lore

Baolin Wang

author maintainer
#0 lore raw

v9 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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, 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=1G --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 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Any comments are welcome. Thanks a lot.

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the CQE can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Changes from v6:
- Change the patch order and set host->always_defer_done = true for the Spreadtrum host driver.

Changes from v5:
- Modify the condition of defering to complete request suggested by Adrian.

Changes from v4:
- Add a seperate patch to introduce a variable to defer to complete data requests for some host drivers, when using host software queue.

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct cqhci_slot', instead adding 'struct sqhci_host', which is only used by software queue.

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343 +++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)
 create mode 100644 drivers/mmc/host/mmc_hsq.c
 create mode 100644 drivers/mmc/host/mmc_hsq.h
Signature · 1 line
1.7.9.5
author maintainer
#1 lore raw

PATCH v9 1/5 mmc: Add MMC host software queue support

From: Baolin Wang <[email protected]>

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 and spend some extra time to poll the card for busy completion for I/O writes via sending CMD13, 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 default queue depth as 64 for software queue, which allows more requests to be prepared, merged and inserted into IO scheduler to improve performance, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as well as avoiding a long latency.

Moreover the host controller should support HW busy detection for I/O operations when enabling the host software queue. That means, the host controller must not complete a data transfer request, until after the card stops signals busy.

From the fio testing data in cover letter, we can see the software queue can improve some performance with 4K block size, increasing about 16% for random read, increasing about 90% for random write, though no obvious improvement for sequential read and 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     |   18 ++-
 drivers/mmc/core/queue.c   |   22 ++-
 drivers/mmc/host/Kconfig   |    7 +
 drivers/mmc/host/Makefile  |    1 +
 drivers/mmc/host/cqhci.c   |    8 +-
 drivers/mmc/host/mmc_hsq.c |  343 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/mmc_hsq.h |   30 ++++
 include/linux/mmc/host.h   |    3 +
 9 files changed, 481 insertions(+), 12 deletions(-)
 create mode 100644 drivers/mmc/host/mmc_hsq.c
 create mode 100644 drivers/mmc/host/mmc_hsq.h
drivers/mmc/core/block.c +61 -0
index 663d879..55d52fc 100644
@@ -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_hsq_req_done(struct mmc_request *mrq);
 
 static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
 {
@@ -1532,9 +1537,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_hsq_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_hsq_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->hsq_enabled)
+		return mmc_blk_hsq_issue_rw_rq(mq, req);
 
 	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
 
@@ -1920,6 +1946,41 @@ static void mmc_blk_urgent_bkops(struct mmc_queue *mq,
 		mmc_run_bkops(mq->card);
 }
 
+static void mmc_blk_hsq_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 +11 -7
index f6912de..693921e 100644
@@ -1851,15 +1851,19 @@ 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 {
+		if (!err) {
 			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->hsq_enabled = true;
+				pr_info("%s: Host Software Queue enabled\n",
+					mmc_hostname(host));
+			}
 		}
 	}
 
drivers/mmc/core/queue.c +18 -4
index 9edc086..25bee3d 100644
@@ -62,7 +62,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->hsq_enabled)
 		return mmc_cqe_issue_type(host, req);
 
 	if (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE)
@@ -124,12 +124,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->hsq_enabled)
 		ret = BLK_EH_RESET_TIMER;
 	else
 		ret = mmc_cqe_timed_out(req);
@@ -144,12 +146,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->hsq_enabled)
 		mmc_blk_cqe_recovery(mq);
 	else
 		mmc_blk_mq_recovery(mq);
@@ -160,6 +163,9 @@ static void mmc_mq_recovery_handler(struct work_struct *work)
 	mq->recovery_needed = false;
 	spin_unlock_irq(&mq->lock);
 
+	if (host->hsq_enabled)
+		host->cqe_ops->cqe_recovery_finish(host);
+
 	mmc_put_card(mq->card, &mq->ctx);
 
 	blk_mq_run_hw_queues(q, true);
@@ -279,6 +285,14 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *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) {
+			spin_unlock_irq(&mq->lock);
+			return BLK_STS_RESOURCE;
+		}
 		break;
 	default:
 		/*
@@ -430,7 +444,7 @@ 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)
+	if (mq->use_cqe && !host->hsq_enabled)
 		mq->tag_set.queue_depth =
 			min_t(int, card->ext_csd.cmdq_depth, host->cqe_qdepth);
 	else
drivers/mmc/host/Kconfig +7 -0
index 3a5089f..65d3966 100644
@@ -949,6 +949,13 @@ config MMC_CQHCI
 
 	  If unsure, say N.
 
+config MMC_HSQ
+	tristate "MMC Host Software Queue support"
+	help
+	  This selects the Software Queue 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
index 21d9089..b929ef9 100644
@@ -100,6 +100,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_HSQ)			+= mmc_hsq.o
 
 ifeq ($(CONFIG_CB710_DEBUG),y)
 	CFLAGS-cb710-mmc	+= -DDEBUG
drivers/mmc/host/cqhci.c +7 -1
index 5047f73..e2ea2c4 100644
@@ -321,14 +321,20 @@ static int cqhci_enable(struct mmc_host *mmc, struct mmc_card *card)
 	struct cqhci_host *cq_host = mmc->cqe_private;
 	int err;
 
+	if (!card->ext_csd.cmdq_en)
+		return -EINVAL;
+
 	if (cq_host->enabled)
 		return 0;
 
 	cq_host->rca = card->rca;
 
 	err = cqhci_host_alloc_tdl(cq_host);
-	if (err)
+	if (err) {
+		pr_err("%s: Failed to enable CQE, error %d\n",
+		       mmc_hostname(mmc), err);
 		return err;
+	}
 
 	__cqhci_enable(cq_host);
 
drivers/mmc/host/mmc_hsq.c new file +343 -0

343 lines not on this page · raw message

drivers/mmc/host/mmc_hsq.h new file +30 -0
new file mode 100644
index 0000000..d51beb7
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef LINUX_MMC_HSQ_H
+#define LINUX_MMC_HSQ_H
+
+struct hsq_slot {
+	struct mmc_request *mrq;
+};
+
+struct mmc_hsq {
+	struct mmc_host *mmc;
+	struct mmc_request *mrq;
+	wait_queue_head_t wait_queue;
+	struct hsq_slot *slot;
+	spinlock_t lock;
+
+	int next_tag;
+	int num_slots;
+	int qcnt;
+
+	bool enabled;
+	bool waiting_for_idle;
+	bool recovery_halt;
+};
+
+int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc);
+void mmc_hsq_suspend(struct mmc_host *mmc);
+int mmc_hsq_resume(struct mmc_host *mmc);
+bool mmc_hsq_finalize_request(struct mmc_host *mmc, struct mmc_request *mrq);
+
+#endif
include/linux/mmc/host.h +3 -0
index ba70338..562ed06 100644
@@ -462,6 +462,9 @@ struct mmc_host {
 	bool			cqe_enabled;
 	bool			cqe_on;
 
+	/* Host Software Queue support */
+	bool			hsq_enabled;
+
 	unsigned long		private[0] ____cacheline_aligned;
 };
 
Signature · 1 line
1.7.9.5
author maintainer
#2 lore raw

PATCH v9 2/5 mmc: core: Enable the MMC host software queue for the SD card

In reply to Baolin Wang

From: Baolin Wang <[email protected]>

Enable the MMC host software queue for the SD card if the host controller supports the MMC host software queue.

On my Spreadtrum platform, I did not see any obvious performance changes in 4K block size when changing to use hsq for the SD cards, I think the reason is the SD card works at a low speed on my platform, and most of time is spent in the hardware. But we can see some obvious improvements when enabling the packed request based on hsq, that's why we still add hsq support for the SD cards.

---
 drivers/mmc/core/sd.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mmc/core/sd.c +10 -0
index fe914ff..76c7add 100644
@@ -1082,6 +1082,16 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 		}
 	}
 
+	if (host->cqe_ops && !host->cqe_enabled) {
+		err = host->cqe_ops->cqe_enable(host, card);
+		if (!err) {
+			host->cqe_enabled = true;
+			host->hsq_enabled = true;
+			pr_info("%s: Host Software Queue enabled\n",
+				mmc_hostname(host));
+		}
+	}
+
 	if (host->caps2 & MMC_CAP2_AVOID_3_3V &&
 	    host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) {
 		pr_err("%s: Host failed to negotiate down from 3.3V\n",
Signature · 1 line
1.7.9.5
author maintainer
#3 lore raw

PATCH v9 3/5 mmc: host: sdhci: Add request_done ops for struct sdhci_ops

In reply to Baolin Wang

From: Baolin Wang <[email protected]>

Add 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
index 63db844..9761981 100644
@@ -2944,7 +2944,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;
 }
@@ -3372,7 +3375,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
index a6a3ddc..3e95f74 100644
@@ -654,6 +654,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
author maintainer
#4 lore raw

PATCH v9 4/5 mmc: host: sdhci: Add a variable to defer to complete requests if needed

In reply to Baolin Wang

From: Baolin Wang <[email protected]>

When using the host software queue, it will trigger the next request in irq handler without a context switch. But the sdhci_request() can not be called in interrupt context when using host software queue for some host drivers, due to the get_cd() ops can be sleepable.

But for some host drivers, such as Spreadtrum host driver, the card is nonremovable, so the get_cd() ops is not sleepable, which means we can complete the data request and trigger the next request in irq handler to remove the context switch for the Spreadtrum host driver.

As suggested by Adrian, we should introduce a request_atomic() API to indicate that a request can be called in interrupt context to remove the context switch when using mmc host software queue. But this should be done in another thread to convert the users of mmc host software queue. Thus we can introduce a variable in struct sdhci_host to indicate that we will always to defer to complete requests when using the host software queue.

---
 drivers/mmc/host/sdhci.c |    2 +-
 drivers/mmc/host/sdhci.h |    1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +1 -1
index 9761981..9c37451 100644
@@ -3250,7 +3250,7 @@ static inline bool sdhci_defer_done(struct sdhci_host *host,
 {
 	struct mmc_data *data = mrq->data;
 
-	return host->pending_reset ||
+	return host->pending_reset || host->always_defer_done ||
 	       ((host->flags & SDHCI_REQ_USE_DMA) && data &&
 		data->host_cookie == COOKIE_MAPPED);
 }
drivers/mmc/host/sdhci.h +1 -0
index 3e95f74..cac2d97 100644
@@ -537,6 +537,7 @@ struct sdhci_host {
 	bool irq_wake_enabled;	/* IRQ wakeup is enabled */
 	bool v4_mode;		/* Host Version 4 Enable */
 	bool use_external_dma;	/* Host selects to use external DMA */
+	bool always_defer_done;	/* Always defer to complete requests */
 
 	struct mmc_request *mrqs_done[SDHCI_MAX_MRQS];	/* Requests done */
 	struct mmc_command *cmd;	/* Current command */
Signature · 1 line
1.7.9.5
author maintainer
#5 lore raw

PATCH v9 5/5 mmc: host: sdhci-sprd: Add software queue support

In reply to Baolin Wang

From: Baolin Wang <[email protected]>

Add software queue support to improve the performance.

---
 drivers/mmc/host/Kconfig      |    1 +
 drivers/mmc/host/sdhci-sprd.c |   28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
drivers/mmc/host/Kconfig +1 -0
index 65d3966..3ea45be 100644
@@ -645,6 +645,7 @@ config MMC_SDHCI_SPRD
 	depends on ARCH_SPRD
 	depends on MMC_SDHCI_PLTFM
 	select MMC_SDHCI_IO_ACCESSORS
+	select MMC_HSQ
 	help
 	  This selects the SDIO Host Controller in Spreadtrum
 	  SoCs, this driver supports R11(IP version: R11P0).
drivers/mmc/host/sdhci-sprd.c +28 -0
index d07b979..d346223 100644
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 
 #include "sdhci-pltfm.h"
+#include "mmc_hsq.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 (mmc_hsq_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 mmc_hsq *hsq;
 	struct clk *clk;
 	int ret = 0;
 
@@ -631,6 +644,18 @@ static int sdhci_sprd_probe(struct platform_device *pdev)
 
 	sprd_host->flags = host->flags;
 
+	hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq), GFP_KERNEL);
+	if (!hsq) {
+		ret = -ENOMEM;
+		goto err_cleanup_host;
+	}
+
+	ret = mmc_hsq_init(hsq, host->mmc);
+	if (ret)
+		goto err_cleanup_host;
+
+	host->always_defer_done = true;
+
 	ret = __sdhci_add_host(host);
 	if (ret)
 		goto err_cleanup_host;
@@ -689,6 +714,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);
 
+	mmc_hsq_suspend(host->mmc);
 	sdhci_runtime_suspend_host(host);
 
 	clk_disable_unprepare(sprd_host->clk_sdio);
@@ -717,6 +743,8 @@ static int sdhci_sprd_runtime_resume(struct device *dev)
 		goto clk_disable;
 
 	sdhci_runtime_resume_host(host, 1);
+	mmc_hsq_resume(host->mmc);
+
 	return 0;
 
 clk_disable:
Signature · 1 line
1.7.9.5
#6 lore raw
In reply to Baolin Wang
Quoted 141 lines · Baolin Wang

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, 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=1G --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 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Any comments are welcome. Thanks a lot.

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the CQE can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Changes from v6:
- Change the patch order and set host->always_defer_done = true for the Spreadtrum host driver.

Changes from v5:
- Modify the condition of defering to complete request suggested by Adrian.

Changes from v4:
- Add a seperate patch to introduce a variable to defer to complete data requests for some host drivers, when using host software queue.

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct cqhci_slot', instead adding 'struct sqhci_host', which is only used by software queue.

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343 +++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)
 create mode 100644 drivers/mmc/host/mmc_hsq.c
 create mode 100644 drivers/mmc/host/mmc_hsq.h
Quoted 3 lines

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look good.

Kind regards
Uffe

author maintainer
#7 lore raw
Quoted 143 lines · Ulf Hansson
Quoted 141 lines · Baolin Wang

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, 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=1G --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 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Any comments are welcome. Thanks a lot.

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the CQE can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Changes from v6:
- Change the patch order and set host->always_defer_done = true for the Spreadtrum host driver.

Changes from v5:
- Modify the condition of defering to complete request suggested by Adrian.

Changes from v4:
- Add a seperate patch to introduce a variable to defer to complete data requests for some host drivers, when using host software queue.

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct cqhci_slot', instead adding 'struct sqhci_host', which is only used by software queue.

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343 +++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)
 create mode 100644 drivers/mmc/host/mmc_hsq.c
 create mode 100644 drivers/mmc/host/mmc_hsq.h
Quoted 6 lines
Quoted 3 lines

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

I am very appreciated for you and Arnd's good sugestion when introducing the hsq.

Quoted 4 lines

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look good.

Thanks for your help and looks good to me.

maintainer
#8 lore raw
Quoted 46 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Baolin Wang
Sent: 2020年2月19日 9:35
To: Ulf Hansson <[email protected]>
Cc: Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>; Chunyan Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Quoted 2 lines · Ulf Hansson

On Wed, 12 Feb 2020 at 05:14, Baolin Wang <[email protected]>

Quoted 16 lines · wrote:
Quoted 16 lines

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as well as avoiding a long latency.

Quoted 7 lines
Quoted 7 lines

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.

Quoted 4 lines
Quoted 4 lines

./fio --filename=/dev/mmcblk0p30 --direct=1 --iodepth=20 --rw=read --bs=4K --size=1G --group_reporting --numjobs=20 --name=test_read

Quoted 53 lines
Quoted 2 lines
Quoted 2 lines

My eMMC card working at HS400 Enhanced strobe mode:

[    2.229856] mmc0: new HS400 Enhanced strobe MMC card at address

0001

Quoted 4 lines
Quoted 4 lines
[    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)

Quoted 45 lines
Quoted 45 lines

1. Without MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average
speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average
speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average
speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average
speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average
speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average
speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average
speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average
speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Any comments are welcome. Thanks a lot.

Hi Baolin,

I refer to your code, and add the software queue support on i.MX based on the Linux next-20200602, but unfortunately, I see an obvious performance drop when change to use software queue. I test on our imx850-evk board, with eMMC soldered.
From the result listing below, only random write has a little performance improve, for others, seems performance drop a lot.
I noticed that, this software queue need no-removable card, any other limitation? For host?
From the code logic, software queue complete the request in irq handler, seems no other change, I do not figure out why this will trigger a performance drop on my platform. Any comment would be appreciate!

Without software queue, normal read/write method:
Sequential read: 56MB/s
Random read: 23.5MB/s
Sequential write: 43.7MB/s
Random write: 19MB/s

With mmc software queue:
Sequential read: 33.5MB/s
Random read: 18.7 MB/s
Sequential write: 37.7MB/s
Random write: 19.8MB/s

Here, I also list my change code to support software queue

drivers/mmc/host/Kconfig +1 -0
index eb85237bf2d6..996b8cc5c381 100644
@@ -254,6 +254,7 @@ config MMC_SDHCI_ESDHC_IMX
        depends on MMC_SDHCI_PLTFM
        select MMC_SDHCI_IO_ACCESSORS
        select MMC_CQHCI
+       select MMC_HSQ
        help
          This selects the Freescale eSDHC/uSDHC controller support
          found on i.MX25, i.MX35 i.MX5x and i.MX6x.
drivers/mmc/host/sdhci-esdhc-imx.c +54 -5

139 lines not on this page · raw message

Quoted 82 lines
Quoted 12 lines
Quoted 12 lines

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the CQE
can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Quoted 6 lines
Quoted 6 lines

Changes from v6:
- Change the patch order and set host->always_defer_done = true for
the Spreadtrum host driver.

Changes from v5:
- Modify the condition of defering to complete request suggested by

Adrian.

Quoted 29 lines
Quoted 29 lines

Changes from v4:
- Add a seperate patch to introduce a variable to defer to complete
data requests for some host drivers, when using host software queue.

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct cqhci_slot',
instead adding 'struct sqhci_host', which is only used by software queue.

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

Quoted 8 lines
Quoted 8 lines
 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343

+++++++++++++++++++++++++++++++++++++++++

Quoted 9 lines
Quoted 9 lines
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)  create mode

100644 drivers/mmc/host/mmc_hsq.c create mode 100644 drivers/mmc/host/mmc_hsq.h

Quoted 6 lines
Quoted 3 lines

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

I am very appreciated for you and Arnd's good sugestion when introducing the hsq.

Quoted 4 lines

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look good.

Thanks for your help and looks good to me.

author maintainer
#9 lore raw

Hi Haibo.

Quoted 101 lines · BOUGH CHEN
Quoted 47 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Baolin Wang
Sent: 2020年2月19日 9:35
To: Ulf Hansson <[email protected]>
Cc: Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>; Chunyan Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Quoted 2 lines · Ulf Hansson

On Wed, 12 Feb 2020 at 05:14, Baolin Wang <[email protected]>

Quoted 16 lines · wrote:
Quoted 16 lines

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as well as avoiding a long latency.

Quoted 7 lines
Quoted 7 lines

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.

Quoted 4 lines
Quoted 4 lines

./fio --filename=/dev/mmcblk0p30 --direct=1 --iodepth=20 --rw=read --bs=4K --size=1G --group_reporting --numjobs=20 --name=test_read

Quoted 53 lines
Quoted 2 lines
Quoted 2 lines

My eMMC card working at HS400 Enhanced strobe mode:

[    2.229856] mmc0: new HS400 Enhanced strobe MMC card at address

0001

Quoted 4 lines
Quoted 4 lines
[    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)

Quoted 45 lines
Quoted 45 lines

1. Without MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average
speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average
speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average
speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average
speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average
speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average
speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average
speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average
speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Any comments are welcome. Thanks a lot.

Quoted 7 lines

Hi Baolin,

I refer to your code, and add the software queue support on i.MX based on the Linux next-20200602, but unfortunately, I see an obvious performance drop when change to use software queue. I test on our imx850-evk board, with eMMC soldered.
From the result listing below, only random write has a little performance improve, for others, seems performance drop a lot.
I noticed that, this software queue need no-removable card, any other limitation? For host?
From the code logic, software queue complete the request in irq handler, seems no other change, I do not figure out why this will trigger a performance drop on my platform. Any comment would be appreciate!

Have you tested with below patches, which introduce an atomic_request host ops to submit next request in the irq hard handler context to reduce latency?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ed6330330276cba39058e8dbdb28ab8d013d926e
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a374a72baa817388a04825118b7c1ba13064c8c6
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=98a2642f91a47dcd1215d037c14e0e5de33a247d
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e872f1e22ea5f678ae42812949477387fda6725b
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=845c939ee22943786a6eb1d13d03c77b19fcc2c8
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6db96e5810e0a6a345b7d78549de7676ae5b2662
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=48ef8a2a1e5e6a2a189009e880e341ddb452971d
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=61ab64e2f54f4c607428667f83f411cb659843a3

Quoted 267 lines

Without software queue, normal read/write method:
Sequential read: 56MB/s
Random read: 23.5MB/s
Sequential write: 43.7MB/s
Random write: 19MB/s

With mmc software queue:
Sequential read: 33.5MB/s
Random read: 18.7 MB/s
Sequential write: 37.7MB/s
Random write: 19.8MB/s

Here, I also list my change code to support software queue

drivers/mmc/host/Kconfig +1 -0
index eb85237bf2d6..996b8cc5c381 100644
@@ -254,6 +254,7 @@ config MMC_SDHCI_ESDHC_IMX
        depends on MMC_SDHCI_PLTFM
        select MMC_SDHCI_IO_ACCESSORS
        select MMC_CQHCI
+       select MMC_HSQ
        help
          This selects the Freescale eSDHC/uSDHC controller support
          found on i.MX25, i.MX35 i.MX5x and i.MX6x.
drivers/mmc/host/sdhci-esdhc-imx.c +54 -5
index 1d7f84b23a22..6f163695b08d 100644
@@ -29,6 +29,7 @@
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
 #include "cqhci.h"
+#include "mmc_hsq.h"
 
 #define ESDHC_SYS_CTRL_DTOCV_MASK      0x0f
 #define        ESDHC_CTRL_D3CD                 0x08
@@ -1220,6 +1221,15 @@ static u32 esdhc_cqhci_irq(struct sdhci_host *host, u32 intmask)
        return 0;
 }
 
+static void esdhc_request_done(struct sdhci_host *host, struct mmc_request *mrq)
+{
+       /* Validate if the request was from software queue firstly. */
+       if (mmc_hsq_finalize_request(host->mmc, mrq))
+               return;
+
+       mmc_request_done(host->mmc, mrq);
+}
+
 static struct sdhci_ops sdhci_esdhc_ops = {
        .read_l = esdhc_readl_le,
        .read_w = esdhc_readw_le,
@@ -1237,6 +1247,7 @@ static struct sdhci_ops sdhci_esdhc_ops = {
        .set_uhs_signaling = esdhc_set_uhs_signaling,
        .reset = esdhc_reset,
        .irq = esdhc_cqhci_irq,
+       .request_done = esdhc_request_done,
 };
 
 static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
@@ -1301,6 +1312,19 @@ static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)
                        writel(tmp, host->ioaddr + ESDHC_VEND_SPEC2);
 
                        host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ;
+
+                       /*
+                        * On i.MX8MM, we are running Dual Linux OS, with 1st Linux using SD Card
+                        * as rootfs storage, 2nd Linux using eMMC as rootfs storage. We let the
+                        * the 1st linux configure power/clock for the 2nd Linux.
+                        *
+                        * When the 2nd Linux is booting into rootfs stage, we let the 1st Linux
+                        * to destroy the 2nd linux, then restart the 2nd linux, we met SDHCI dump.
+                        * After we clear the pending interrupt and halt CQCTL, issue gone.
+                        */
+                       tmp = cqhci_readl(cq_host, CQHCI_IS);
+                       cqhci_writel(cq_host, tmp, CQHCI_IS);
+                       cqhci_writel(cq_host, CQHCI_HALT, CQHCI_CTL);
                }
 
                if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
@@ -1351,9 +1375,6 @@ static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)
                 * After we clear the pending interrupt and halt CQCTL, issue gone.
                 */
                if (cq_host) {
-                       tmp = cqhci_readl(cq_host, CQHCI_IS);
-                       cqhci_writel(cq_host, tmp, CQHCI_IS);
-                       cqhci_writel(cq_host, CQHCI_HALT, CQHCI_CTL);
                }
        }
 }
@@ -1555,6 +1576,7 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
        struct sdhci_pltfm_host *pltfm_host;
        struct sdhci_host *host;
        struct cqhci_host *cq_host;
+       struct mmc_hsq *hsq;
        int err;
        struct pltfm_imx_data *imx_data;
 
@@ -1664,6 +1686,16 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
                err = cqhci_init(cq_host, host->mmc, false);
                if (err)
                        goto disable_ahb_clk;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq), GFP_KERNEL);
+               if (!hsq) {
+                       err = -ENOMEM;
+                       goto disable_ahb_clk;
+               }
+
+               err = mmc_hsq_init(hsq, host->mmc);
+               if (err)
+                       goto disable_ahb_clk;
        }
 
        if (of_id)
@@ -1673,6 +1705,11 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
        if (err)
                goto disable_ahb_clk;
 
+       if (!mmc_card_is_removable(host->mmc))
+               host->mmc_host_ops.request_atomic = sdhci_request_atomic;
+       else
+               host->always_defer_done = true;
+
        sdhci_esdhc_imx_hwinit(host);
 
        err = sdhci_add_host(host);
@@ -1737,6 +1774,8 @@ static int sdhci_esdhc_suspend(struct device *dev)
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        if ((imx_data->socdata->flags & ESDHC_FLAG_STATE_LOST_IN_LPMODE) &&
@@ -1764,6 +1803,8 @@ static int sdhci_esdhc_suspend(struct device *dev)
 static int sdhci_esdhc_resume(struct device *dev)
 {
        struct sdhci_host *host = dev_get_drvdata(dev);
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
        int ret;
 
        ret = pinctrl_pm_select_default_state(dev);
@@ -1777,8 +1818,11 @@ static int sdhci_esdhc_resume(struct device *dev)
        if (ret)
                return ret;
 
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                ret = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        if (!ret)
                ret = mmc_gpio_set_cd_wake(host->mmc, false);
@@ -1799,6 +1843,8 @@ static int sdhci_esdhc_runtime_suspend(struct device *dev)
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        ret = sdhci_runtime_suspend_host(host);
@@ -1851,8 +1897,11 @@ static int sdhci_esdhc_runtime_resume(struct device *dev)
        if (err)
                goto disable_ipg_clk;
 
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                err = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        return err;
 
Quoted 84 lines
Quoted 14 lines
Quoted 14 lines

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the CQE
can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Quoted 6 lines
Quoted 6 lines

Changes from v6:
- Change the patch order and set host->always_defer_done = true for
the Spreadtrum host driver.

Changes from v5:
- Modify the condition of defering to complete request suggested by

Adrian.

Quoted 29 lines
Quoted 29 lines

Changes from v4:
- Add a seperate patch to introduce a variable to defer to complete
data requests for some host drivers, when using host software queue.

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct cqhci_slot',
instead adding 'struct sqhci_host', which is only used by software queue.

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

Quoted 8 lines
Quoted 8 lines
 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343

+++++++++++++++++++++++++++++++++++++++++

Quoted 9 lines
Quoted 9 lines
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)  create mode

100644 drivers/mmc/host/mmc_hsq.c create mode 100644 drivers/mmc/host/mmc_hsq.h

Quoted 6 lines
Quoted 3 lines

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

I am very appreciated for you and Arnd's good sugestion when introducing the hsq.

Quoted 4 lines

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look good.

Thanks for your help and looks good to me.

Signature · 1 line
Baolin Wang
maintainer
#10 lore raw
Quoted 139 lines

-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: 2020年6月8日 19:54
To: BOUGH CHEN <[email protected]>
Cc: Ulf Hansson <[email protected]>; Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>; Chunyan Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>; dl-linux-imx <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Hi Haibo.

Quoted 8 lines · BOUGH CHEN
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Baolin Wang
Sent: 2020年2月19日 9:35
To: Ulf Hansson <[email protected]>
Cc: Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>;

Chunyan

Quoted 20 lines
Quoted 20 lines

Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Quoted 2 lines · Ulf Hansson

On Wed, 12 Feb 2020 at 05:14, Baolin Wang <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

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.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as

well as avoiding a long latency.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

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

Quoted 8 lines
Quoted 8 lines

size.

Quoted 7 lines
Quoted 7 lines

./fio --filename=/dev/mmcblk0p30 --direct=1 --iodepth=20 --rw=read --bs=4K --size=1G --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

Quoted 3 lines
Quoted 3 lines

0001

Quoted 2 lines
Quoted 2 lines
[    2.237566] mmcblk0: mmc0:0001 HBG4a2 29.1 GiB
[    2.242621] mmcblk0boot0: mmc0:0001 HBG4a2 partition 1 4.00

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.249110] mmcblk0boot1: mmc0:0001 HBG4a2 partition 2 4.00

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.255307] mmcblk0rpmb: mmc0:0001 HBG4a2 partition 3 4.00

MiB,

Quoted 51 lines
Quoted 51 lines

chardev (248:0)

Quoted 50 lines
Quoted 50 lines

1. Without MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average
speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average
speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average
speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average
speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average
speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average
speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average
speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average
speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Any comments are welcome. Thanks a lot.

Hi Baolin,

I refer to your code, and add the software queue support on i.MX based on

the Linux next-20200602, but unfortunately, I see an obvious performance drop when change to use software queue.

Quoted 2 lines

I test on our imx850-evk board, with eMMC soldered.
From the result listing below, only random write has a little performance

improve, for others, seems performance drop a lot.

Quoted 8 lines
Quoted 1 line

I noticed that, this software queue need no-removable card, any other

limitation? For host?

Quoted 1 line

From the code logic, software queue complete the request in irq handler,

seems no other change, I do not figure out why this will trigger a performance drop on my platform. Any comment would be appreciate!

Have you tested with below patches, which introduce an atomic_request host ops to submit next request in the irq hard handler context to reduce latency?

Hi Baolin,

The Linux code base I use is Linux-next-20200602, which already contain all the patch you listed, including the atomic_request.
I do not test the atomic_request alone. I just enable software queue, and this software queue use the atomic request.
So, do you mean, I need to first disable software queue, and just enable the atomic_request, to confirm whether the atomic_request has some performance impact on my platform?

Best Regards
Haibo Chen

Quoted 359 lines

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3Ded6330330276cba39058e8dbdb28ab8d013d926e&amp;dat a=02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2 c447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C6372721409928 90127&amp;sdata=JJVYXczOXYUdpdNkcJhGMaO6a6EeZkQ72hF090BMAHY%3 D&amp;reserved=0
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3Da374a72baa817388a04825118b7c1ba13064c8c6&amp;dat a=02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2 c447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C6372721409928 90127&amp;sdata=RaL685%2FtijHmnmr%2B9wOyr6bN53gLLXpEBgS9wwBqIi8 %3D&amp;reserved=0
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3D98a2642f91a47dcd1215d037c14e0e5de33a247d&amp;dat a=02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2 c447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C6372721409928 90127&amp;sdata=%2B3TBD1lyYOA7D6gvhw0mikvoALMMlyaf9xPGra%2FCnU I%3D&amp;reserved=0
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3De872f1e22ea5f678ae42812949477387fda6725b&amp;data =02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2c 447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C63727214099289 0127&amp;sdata=7kByREznCyEUzibneJB1JMlXdaW%2FZs0FN1MWSzDAPAg% 3D&amp;reserved=0
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3D845c939ee22943786a6eb1d13d03c77b19fcc2c8&amp;data =02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2c 447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C63727214099289 0127&amp;sdata=zxV8REvhSnBTFeyi9HHjFEPcYYrPJGJpNj%2FcOORY0%2BE%3 D&amp;reserved=0
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3D6db96e5810e0a6a345b7d78549de7676ae5b2662&amp;da ta=02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2 c447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C6372721409928 90127&amp;sdata=5J26bs7%2FmJbhcU2%2FJRAdvY6BLd2QIJLafjq37sVKfYA%3 D&amp;reserved=0
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3D48ef8a2a1e5e6a2a189009e880e341ddb452971d&amp;dat a=02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2 c447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C6372721409928 90127&amp;sdata=yM6znnt3BDaLR0G1%2FtWyx1OogCKP2cxErZvvZxDDzbQ% 3D&amp;reserved=0
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kern
el.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fco mmit%2F%3Fid%3D61ab64e2f54f4c607428667f83f411cb659843a3&amp;data =02%7C01%7Chaibo.chen%40nxp.com%7C8618eba906ad4fdb4e1708d80ba2c 447%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C63727214099289 0127&amp;sdata=GZfSBBYZ9eOJfxLPEKCfVUJTcvc6oci6AmeSUCWD8Dc%3D& amp;reserved=0

drivers/mmc/host/sdhci-esdhc-imx.c static u32 esdhc_cqhci_irq(struct sdhci_host

Quoted 41 lines

Without software queue, normal read/write method:
Sequential read: 56MB/s
Random read: 23.5MB/s
Sequential write: 43.7MB/s
Random write: 19MB/s

With mmc software queue:
Sequential read: 33.5MB/s
Random read: 18.7 MB/s
Sequential write: 37.7MB/s
Random write: 19.8MB/s

Here, I also list my change code to support software queue

drivers/mmc/host/Kconfig index renamed from drivers/mmc/host/Kconfig +0 -0

eb85237bf2d6..996b8cc5c381 100644

drivers/mmc/host/Kconfig +1 -0
@@ -254,6 +254,7 @@ config MMC_SDHCI_ESDHC_IMX
        depends on MMC_SDHCI_PLTFM
        select MMC_SDHCI_IO_ACCESSORS
        select MMC_CQHCI
+       select MMC_HSQ
        help
          This selects the Freescale eSDHC/uSDHC controller support
          found on i.MX25, i.MX35 i.MX5x and i.MX6x.
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
index 1d7f84b23a22..6f163695b08d 100644
@@ -29,6 +29,7 @@
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
 #include "cqhci.h"
+#include "mmc_hsq.h"
 
 #define ESDHC_SYS_CTRL_DTOCV_MASK      0x0f
 #define        ESDHC_CTRL_D3CD                 0x08
@@ -1220,6 +1221,15 @@ static u32 esdhc_cqhci_irq(struct sdhci_host

*host, u32 intmask)

Quoted 15 lines
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
        return 0;
 }
 
+static void esdhc_request_done(struct sdhci_host *host, struct
+mmc_request *mrq) {
+       /* Validate if the request was from software queue firstly. */
+       if (mmc_hsq_finalize_request(host->mmc, mrq))
+               return;
+
+       mmc_request_done(host->mmc, mrq); }
+
 static struct sdhci_ops sdhci_esdhc_ops = {
        .read_l = esdhc_readl_le,
        .read_w = esdhc_readw_le,

drivers/mmc/host/sdhci-esdhc-imx.c static struct sdhci_ops sdhci_esdhc_ops = {

Quoted 8 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -1
@@ -1237,6 +1247,7 @@ static struct sdhci_ops sdhci_esdhc_ops = {
        .set_uhs_signaling = esdhc_set_uhs_signaling,
        .reset = esdhc_reset,
        .irq = esdhc_cqhci_irq,
+       .request_done = esdhc_request_done,
 };
 
 static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { @@
-1301,6 +1312,19 @@ static void sdhci_esdhc_imx_hwinit(struct sdhci_host

*host)

Quoted 1 line
                        writel(tmp, host->ioaddr +

ESDHC_VEND_SPEC2);

Quoted 2 lines
                        host->quirks &=

~SDHCI_QUIRK_NO_BUSY_IRQ;

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 3 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+
+                       /*
+                        * On i.MX8MM, we are running Dual Linux OS,

with 1st Linux using SD Card

Quoted 1 line

+ * as rootfs storage, 2nd Linux using eMMC as

rootfs storage. We let the

Quoted 1 line

+ * the 1st linux configure power/clock for the

2nd Linux.

drivers/mmc/host/sdhci-esdhc-imx.c

Quoted 2 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
+                        *
+                        * When the 2nd Linux is booting into rootfs

stage, we let the 1st Linux

Quoted 1 line

+ * to destroy the 2nd linux, then restart the

2nd linux, we met SDHCI dump.

Quoted 1 line

+ * After we clear the pending interrupt and halt

CQCTL, issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 4 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -0
+                        */
+                       tmp = cqhci_readl(cq_host, CQHCI_IS);
+                       cqhci_writel(cq_host, tmp, CQHCI_IS);
+                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

Quoted 3 lines
                }

                if (imx_data->socdata->flags &

ESDHC_FLAG_STD_TUNING)

Quoted 1 line

{ @@ -1351,9 +1375,6 @@ static void sdhci_esdhc_imx_hwinit(struct

sdhci_host *host)

Quoted 1 line

* After we clear the pending interrupt and halt CQCTL,

issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 5 lines
                 */
                if (cq_host) {
drivers/mmc/host/sdhci-esdhc-imx.c +0 -3
-                       tmp = cqhci_readl(cq_host, CQHCI_IS);
-                       cqhci_writel(cq_host, tmp, CQHCI_IS);
-                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 4 lines
                }
        }

}

drivers/mmc/host/sdhci-esdhc-imx.c +0 -0
@@ -1555,6 +1576,7 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 8 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
        struct sdhci_pltfm_host *pltfm_host;
        struct sdhci_host *host;
        struct cqhci_host *cq_host;
+       struct mmc_hsq *hsq;
        int err;
        struct pltfm_imx_data *imx_data;
 
@@ -1664,6 +1686,16 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
                err = cqhci_init(cq_host, host->mmc, false);
                if (err)
                        goto disable_ahb_clk;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq),

GFP_KERNEL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 12 lines
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
+               if (!hsq) {
+                       err = -ENOMEM;
+                       goto disable_ahb_clk;
+               }
+
+               err = mmc_hsq_init(hsq, host->mmc);
+               if (err)
+                       goto disable_ahb_clk;
        }
 
        if (of_id)
@@ -1673,6 +1705,11 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
        if (err)
                goto disable_ahb_clk;
 
+       if (!mmc_card_is_removable(host->mmc))
+               host->mmc_host_ops.request_atomic =

sdhci_request_atomic;

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device

Quoted 7 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       else
+               host->always_defer_done = true;
+
        sdhci_esdhc_imx_hwinit(host);
 
        err = sdhci_add_host(host);
@@ -1737,6 +1774,8 @@ static int sdhci_esdhc_suspend(struct device

*dev)

Quoted 9 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        if ((imx_data->socdata->flags &

ESDHC_FLAG_STATE_LOST_IN_LPMODE) && @@ -1764,6 +1803,8 @@

static int

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_resume(struct device

Quoted 10 lines

sdhci_esdhc_suspend(struct device *dev) static int

sdhci_esdhc_resume(struct device *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data =
+ sdhci_pltfm_priv(pltfm_host);
        int ret;
 
        ret = pinctrl_pm_select_default_state(dev);
@@ -1777,8 +1818,11 @@ static int sdhci_esdhc_resume(struct device

*dev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_resume(struct device *dev)

Quoted 13 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -2
        if (ret)
                return ret;
 
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                ret = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        if (!ret)
                ret = mmc_gpio_set_cd_wake(host->mmc, false); @@
-1799,6 +1843,8 @@ static int sdhci_esdhc_runtime_suspend(struct device

*dev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device *dev)

Quoted 8 lines
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        ret = sdhci_runtime_suspend_host(host); @@ -1851,8 +1897,11

@@

Quoted 31 lines

static int sdhci_esdhc_runtime_resume(struct device *dev)

        if (err)
                goto disable_ipg_clk;
drivers/mmc/host/sdhci-esdhc-imx.c +4 -1
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                err = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        return err;
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the
CQE can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Changes from v6:
- Change the patch order and set host->always_defer_done = true
for the Spreadtrum host driver.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Changes from v5:
- Modify the condition of defering to complete request
suggested by

Adrian.

Quoted 4 lines
Quoted 4 lines

Changes from v4:
- Add a seperate patch to introduce a variable to defer to
complete data requests for some host drivers, when using host

software queue.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct
cqhci_slot', instead adding 'struct sqhci_host', which is only used by

software queue.

Quoted 45 lines
Quoted 45 lines
Quoted 15 lines
Quoted 15 lines

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

Quoted 8 lines
Quoted 8 lines
 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343

+++++++++++++++++++++++++++++++++++++++++

Quoted 10 lines
Quoted 10 lines
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)  create

mode
100644 drivers/mmc/host/mmc_hsq.c create mode 100644 drivers/mmc/host/mmc_hsq.h

Quoted 6 lines
Quoted 3 lines

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

I am very appreciated for you and Arnd's good sugestion when introducing the hsq.

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look good.

Thanks for your help and looks good to me.

--
Baolin Wang

author maintainer
#11 lore raw
Quoted 146 lines · BOUGH CHEN
Quoted 146 lines

-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: 2020年6月8日 19:54
To: BOUGH CHEN <[email protected]>
Cc: Ulf Hansson <[email protected]>; Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>; Chunyan Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>; dl-linux-imx <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Hi Haibo.

Quoted 8 lines · BOUGH CHEN
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Baolin Wang
Sent: 2020年2月19日 9:35
To: Ulf Hansson <[email protected]>
Cc: Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>;

Chunyan

Quoted 20 lines
Quoted 20 lines

Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Quoted 2 lines · Ulf Hansson

On Wed, 12 Feb 2020 at 05:14, Baolin Wang <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

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.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as

well as avoiding a long latency.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

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

Quoted 8 lines
Quoted 8 lines

size.

Quoted 7 lines
Quoted 7 lines

./fio --filename=/dev/mmcblk0p30 --direct=1 --iodepth=20 --rw=read --bs=4K --size=1G --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

Quoted 3 lines
Quoted 3 lines

0001

Quoted 2 lines
Quoted 2 lines
[    2.237566] mmcblk0: mmc0:0001 HBG4a2 29.1 GiB
[    2.242621] mmcblk0boot0: mmc0:0001 HBG4a2 partition 1 4.00

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.249110] mmcblk0boot1: mmc0:0001 HBG4a2 partition 2 4.00

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.255307] mmcblk0rpmb: mmc0:0001 HBG4a2 partition 3 4.00

MiB,

Quoted 51 lines
Quoted 51 lines

chardev (248:0)

Quoted 50 lines
Quoted 50 lines

1. Without MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average
speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average
speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average
speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average
speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average
speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average
speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average
speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average
speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Any comments are welcome. Thanks a lot.

Hi Baolin,

I refer to your code, and add the software queue support on i.MX based on

the Linux next-20200602, but unfortunately, I see an obvious performance drop when change to use software queue.

Quoted 2 lines

I test on our imx850-evk board, with eMMC soldered.
From the result listing below, only random write has a little performance

improve, for others, seems performance drop a lot.

Quoted 1 line

I noticed that, this software queue need no-removable card, any other

limitation? For host?

Quoted 1 line

From the code logic, software queue complete the request in irq handler,

seems no other change, I do not figure out why this will trigger a performance drop on my platform. Any comment would be appreciate!

Quoted 8 lines
Quoted 2 lines

Have you tested with below patches, which introduce an atomic_request host ops to submit next request in the irq hard handler context to reduce latency?

Hi Baolin,

The Linux code base I use is Linux-next-20200602, which already contain all the patch you listed, including the atomic_request.
I do not test the atomic_request alone. I just enable software queue, and this software queue use the atomic request.
So, do you mean, I need to first disable software queue, and just enable the atomic_request, to confirm whether the atomic_request has some performance impact on my platform?

NO, the HSQ will support atomic_request ops, and I think you should implement the atomic_request ops in your driver if possible, like below patch:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=61ab64e2f54f4c607428667f83f411cb659843a3

Quoted 302 lines
Quoted 302 lines

drivers/mmc/host/sdhci-esdhc-imx.c static u32 esdhc_cqhci_irq(struct sdhci_host

Quoted 41 lines

Without software queue, normal read/write method:
Sequential read: 56MB/s
Random read: 23.5MB/s
Sequential write: 43.7MB/s
Random write: 19MB/s

With mmc software queue:
Sequential read: 33.5MB/s
Random read: 18.7 MB/s
Sequential write: 37.7MB/s
Random write: 19.8MB/s

Here, I also list my change code to support software queue

drivers/mmc/host/Kconfig index renamed from drivers/mmc/host/Kconfig +0 -0

eb85237bf2d6..996b8cc5c381 100644

drivers/mmc/host/Kconfig +1 -0
@@ -254,6 +254,7 @@ config MMC_SDHCI_ESDHC_IMX
        depends on MMC_SDHCI_PLTFM
        select MMC_SDHCI_IO_ACCESSORS
        select MMC_CQHCI
+       select MMC_HSQ
        help
          This selects the Freescale eSDHC/uSDHC controller support
          found on i.MX25, i.MX35 i.MX5x and i.MX6x.
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
index 1d7f84b23a22..6f163695b08d 100644
@@ -29,6 +29,7 @@
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
 #include "cqhci.h"
+#include "mmc_hsq.h"
 
 #define ESDHC_SYS_CTRL_DTOCV_MASK      0x0f
 #define        ESDHC_CTRL_D3CD                 0x08
@@ -1220,6 +1221,15 @@ static u32 esdhc_cqhci_irq(struct sdhci_host

*host, u32 intmask)

Quoted 15 lines
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
        return 0;
 }
 
+static void esdhc_request_done(struct sdhci_host *host, struct
+mmc_request *mrq) {
+       /* Validate if the request was from software queue firstly. */
+       if (mmc_hsq_finalize_request(host->mmc, mrq))
+               return;
+
+       mmc_request_done(host->mmc, mrq); }
+
 static struct sdhci_ops sdhci_esdhc_ops = {
        .read_l = esdhc_readl_le,
        .read_w = esdhc_readw_le,

drivers/mmc/host/sdhci-esdhc-imx.c static struct sdhci_ops sdhci_esdhc_ops = {

Quoted 8 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -1
@@ -1237,6 +1247,7 @@ static struct sdhci_ops sdhci_esdhc_ops = {
        .set_uhs_signaling = esdhc_set_uhs_signaling,
        .reset = esdhc_reset,
        .irq = esdhc_cqhci_irq,
+       .request_done = esdhc_request_done,
 };
 
 static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { @@
-1301,6 +1312,19 @@ static void sdhci_esdhc_imx_hwinit(struct sdhci_host

*host)

Quoted 1 line
                        writel(tmp, host->ioaddr +

ESDHC_VEND_SPEC2);

Quoted 2 lines
                        host->quirks &=

~SDHCI_QUIRK_NO_BUSY_IRQ;

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 3 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+
+                       /*
+                        * On i.MX8MM, we are running Dual Linux OS,

with 1st Linux using SD Card

Quoted 1 line

+ * as rootfs storage, 2nd Linux using eMMC as

rootfs storage. We let the

Quoted 1 line

+ * the 1st linux configure power/clock for the

2nd Linux.

drivers/mmc/host/sdhci-esdhc-imx.c

Quoted 2 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
+                        *
+                        * When the 2nd Linux is booting into rootfs

stage, we let the 1st Linux

Quoted 1 line

+ * to destroy the 2nd linux, then restart the

2nd linux, we met SDHCI dump.

Quoted 1 line

+ * After we clear the pending interrupt and halt

CQCTL, issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 4 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -0
+                        */
+                       tmp = cqhci_readl(cq_host, CQHCI_IS);
+                       cqhci_writel(cq_host, tmp, CQHCI_IS);
+                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

Quoted 3 lines
                }

                if (imx_data->socdata->flags &

ESDHC_FLAG_STD_TUNING)

Quoted 1 line

{ @@ -1351,9 +1375,6 @@ static void sdhci_esdhc_imx_hwinit(struct

sdhci_host *host)

Quoted 1 line

* After we clear the pending interrupt and halt CQCTL,

issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 5 lines
                 */
                if (cq_host) {
drivers/mmc/host/sdhci-esdhc-imx.c +0 -3
-                       tmp = cqhci_readl(cq_host, CQHCI_IS);
-                       cqhci_writel(cq_host, tmp, CQHCI_IS);
-                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 4 lines
                }
        }

}

drivers/mmc/host/sdhci-esdhc-imx.c +0 -0
@@ -1555,6 +1576,7 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 8 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
        struct sdhci_pltfm_host *pltfm_host;
        struct sdhci_host *host;
        struct cqhci_host *cq_host;
+       struct mmc_hsq *hsq;
        int err;
        struct pltfm_imx_data *imx_data;
 
@@ -1664,6 +1686,16 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
                err = cqhci_init(cq_host, host->mmc, false);
                if (err)
                        goto disable_ahb_clk;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq),

GFP_KERNEL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 12 lines
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
+               if (!hsq) {
+                       err = -ENOMEM;
+                       goto disable_ahb_clk;
+               }
+
+               err = mmc_hsq_init(hsq, host->mmc);
+               if (err)
+                       goto disable_ahb_clk;
        }
 
        if (of_id)
@@ -1673,6 +1705,11 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
        if (err)
                goto disable_ahb_clk;
 
+       if (!mmc_card_is_removable(host->mmc))
+               host->mmc_host_ops.request_atomic =

sdhci_request_atomic;

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device

Quoted 7 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       else
+               host->always_defer_done = true;
+
        sdhci_esdhc_imx_hwinit(host);
 
        err = sdhci_add_host(host);
@@ -1737,6 +1774,8 @@ static int sdhci_esdhc_suspend(struct device

*dev)

Quoted 9 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        if ((imx_data->socdata->flags &

ESDHC_FLAG_STATE_LOST_IN_LPMODE) && @@ -1764,6 +1803,8 @@

static int

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_resume(struct device

Quoted 10 lines

sdhci_esdhc_suspend(struct device *dev) static int

sdhci_esdhc_resume(struct device *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data =
+ sdhci_pltfm_priv(pltfm_host);
        int ret;
 
        ret = pinctrl_pm_select_default_state(dev);
@@ -1777,8 +1818,11 @@ static int sdhci_esdhc_resume(struct device

*dev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_resume(struct device *dev)

Quoted 13 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -2
        if (ret)
                return ret;
 
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                ret = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        if (!ret)
                ret = mmc_gpio_set_cd_wake(host->mmc, false); @@
-1799,6 +1843,8 @@ static int sdhci_esdhc_runtime_suspend(struct device

*dev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device *dev)

Quoted 8 lines
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        ret = sdhci_runtime_suspend_host(host); @@ -1851,8 +1897,11

@@

Quoted 31 lines

static int sdhci_esdhc_runtime_resume(struct device *dev)

        if (err)
                goto disable_ipg_clk;
drivers/mmc/host/sdhci-esdhc-imx.c +4 -1
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                err = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        return err;
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the
CQE can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Changes from v6:
- Change the patch order and set host->always_defer_done = true
for the Spreadtrum host driver.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Changes from v5:
- Modify the condition of defering to complete request
suggested by

Adrian.

Quoted 4 lines
Quoted 4 lines

Changes from v4:
- Add a seperate patch to introduce a variable to defer to
complete data requests for some host drivers, when using host

software queue.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct
cqhci_slot', instead adding 'struct sqhci_host', which is only used by

software queue.

Quoted 45 lines
Quoted 45 lines
Quoted 15 lines
Quoted 15 lines

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

Quoted 8 lines
Quoted 8 lines
 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343

+++++++++++++++++++++++++++++++++++++++++

Quoted 10 lines
Quoted 10 lines
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)  create

mode
100644 drivers/mmc/host/mmc_hsq.c create mode 100644 drivers/mmc/host/mmc_hsq.h

Quoted 6 lines
Quoted 3 lines

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

I am very appreciated for you and Arnd's good sugestion when introducing the hsq.

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look good.

Thanks for your help and looks good to me.

--
Baolin Wang

Signature · 1 line
Baolin Wang
author maintainer
#12 lore raw
Quoted 153 lines · Baolin Wang
Quoted 151 lines · BOUGH CHEN
Quoted 140 lines

-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: 2020年6月8日 19:54
To: BOUGH CHEN <[email protected]>
Cc: Ulf Hansson <[email protected]>; Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>; Chunyan Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>; dl-linux-imx <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Hi Haibo.

Quoted 8 lines · BOUGH CHEN
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Baolin Wang
Sent: 2020年2月19日 9:35
To: Ulf Hansson <[email protected]>
Cc: Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>;

Chunyan

Quoted 20 lines
Quoted 20 lines

Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Quoted 2 lines · Ulf Hansson

On Wed, 12 Feb 2020 at 05:14, Baolin Wang <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines

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.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as

well as avoiding a long latency.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

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

Quoted 8 lines
Quoted 8 lines

size.

Quoted 7 lines
Quoted 7 lines

./fio --filename=/dev/mmcblk0p30 --direct=1 --iodepth=20 --rw=read --bs=4K --size=1G --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

Quoted 3 lines
Quoted 3 lines

0001

Quoted 2 lines
Quoted 2 lines
[    2.237566] mmcblk0: mmc0:0001 HBG4a2 29.1 GiB
[    2.242621] mmcblk0boot0: mmc0:0001 HBG4a2 partition 1 4.00

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.249110] mmcblk0boot1: mmc0:0001 HBG4a2 partition 2 4.00

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.255307] mmcblk0rpmb: mmc0:0001 HBG4a2 partition 3 4.00

MiB,

Quoted 51 lines
Quoted 51 lines

chardev (248:0)

Quoted 50 lines
Quoted 50 lines

1. Without MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average
speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average
speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average
speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average
speed: 35.96MiB/s

2. With MMC software queue
I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average
speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average
speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average
speed: 71.66MiB/s

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average
speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and write.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Any comments are welcome. Thanks a lot.

Hi Baolin,

I refer to your code, and add the software queue support on i.MX based on

the Linux next-20200602, but unfortunately, I see an obvious performance drop when change to use software queue.

Quoted 2 lines

I test on our imx850-evk board, with eMMC soldered.
From the result listing below, only random write has a little performance

improve, for others, seems performance drop a lot.

Quoted 8 lines
Quoted 1 line

I noticed that, this software queue need no-removable card, any other

limitation? For host?

Quoted 1 line

From the code logic, software queue complete the request in irq handler,

seems no other change, I do not figure out why this will trigger a performance drop on my platform. Any comment would be appreciate!

Have you tested with below patches, which introduce an atomic_request host ops to submit next request in the irq hard handler context to reduce latency?

Hi Baolin,

Quoted 8 lines
Quoted 3 lines

The Linux code base I use is Linux-next-20200602, which already contain all the patch you listed, including the atomic_request.
I do not test the atomic_request alone. I just enable software queue, and this software queue use the atomic request.
So, do you mean, I need to first disable software queue, and just enable the atomic_request, to confirm whether the atomic_request has some performance impact on my platform?

NO, the HSQ will support atomic_request ops, and I think you should implement the atomic_request ops in your driver if possible, like below patch:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=61ab64e2f54f4c607428667f83f411cb659843a3

Ah, sorry, I saw you've implemented the atomic_request ops. Moreover I've tested the mainline, and I still got some performance improvement.

What's the IO scheduler you selected?

Quoted 308 lines
Quoted 297 lines
Quoted 297 lines

drivers/mmc/host/sdhci-esdhc-imx.c static u32 esdhc_cqhci_irq(struct sdhci_host

Quoted 42 lines

Without software queue, normal read/write method:
Sequential read: 56MB/s
Random read: 23.5MB/s
Sequential write: 43.7MB/s
Random write: 19MB/s

With mmc software queue:
Sequential read: 33.5MB/s
Random read: 18.7 MB/s
Sequential write: 37.7MB/s
Random write: 19.8MB/s

Here, I also list my change code to support software queue

drivers/mmc/host/Kconfig index renamed from drivers/mmc/host/Kconfig +0 -0

eb85237bf2d6..996b8cc5c381 100644

drivers/mmc/host/Kconfig +1 -0
@@ -254,6 +254,7 @@ config MMC_SDHCI_ESDHC_IMX
        depends on MMC_SDHCI_PLTFM
        select MMC_SDHCI_IO_ACCESSORS
        select MMC_CQHCI
+       select MMC_HSQ
        help
          This selects the Freescale eSDHC/uSDHC controller support
          found on i.MX25, i.MX35 i.MX5x and i.MX6x.
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
index 1d7f84b23a22..6f163695b08d 100644
@@ -29,6 +29,7 @@
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
 #include "cqhci.h"
+#include "mmc_hsq.h"
 
 #define ESDHC_SYS_CTRL_DTOCV_MASK      0x0f
 #define        ESDHC_CTRL_D3CD                 0x08
@@ -1220,6 +1221,15 @@ static u32 esdhc_cqhci_irq(struct sdhci_host

*host, u32 intmask)

Quoted 15 lines
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
        return 0;
 }
 
+static void esdhc_request_done(struct sdhci_host *host, struct
+mmc_request *mrq) {
+       /* Validate if the request was from software queue firstly. */
+       if (mmc_hsq_finalize_request(host->mmc, mrq))
+               return;
+
+       mmc_request_done(host->mmc, mrq); }
+
 static struct sdhci_ops sdhci_esdhc_ops = {
        .read_l = esdhc_readl_le,
        .read_w = esdhc_readw_le,

drivers/mmc/host/sdhci-esdhc-imx.c static struct sdhci_ops sdhci_esdhc_ops = {

Quoted 8 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -1
@@ -1237,6 +1247,7 @@ static struct sdhci_ops sdhci_esdhc_ops = {
        .set_uhs_signaling = esdhc_set_uhs_signaling,
        .reset = esdhc_reset,
        .irq = esdhc_cqhci_irq,
+       .request_done = esdhc_request_done,
 };
 
 static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { @@
-1301,6 +1312,19 @@ static void sdhci_esdhc_imx_hwinit(struct sdhci_host

*host)

Quoted 1 line
                        writel(tmp, host->ioaddr +

ESDHC_VEND_SPEC2);

Quoted 2 lines
                        host->quirks &=

~SDHCI_QUIRK_NO_BUSY_IRQ;

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 3 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+
+                       /*
+                        * On i.MX8MM, we are running Dual Linux OS,

with 1st Linux using SD Card

Quoted 1 line

+ * as rootfs storage, 2nd Linux using eMMC as

rootfs storage. We let the

Quoted 1 line

+ * the 1st linux configure power/clock for the

2nd Linux.

drivers/mmc/host/sdhci-esdhc-imx.c

Quoted 2 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
+                        *
+                        * When the 2nd Linux is booting into rootfs

stage, we let the 1st Linux

Quoted 1 line

+ * to destroy the 2nd linux, then restart the

2nd linux, we met SDHCI dump.

Quoted 1 line

+ * After we clear the pending interrupt and halt

CQCTL, issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 4 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -0
+                        */
+                       tmp = cqhci_readl(cq_host, CQHCI_IS);
+                       cqhci_writel(cq_host, tmp, CQHCI_IS);
+                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

Quoted 3 lines
                }

                if (imx_data->socdata->flags &

ESDHC_FLAG_STD_TUNING)

Quoted 1 line

{ @@ -1351,9 +1375,6 @@ static void sdhci_esdhc_imx_hwinit(struct

sdhci_host *host)

Quoted 1 line

* After we clear the pending interrupt and halt CQCTL,

issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 5 lines
                 */
                if (cq_host) {
drivers/mmc/host/sdhci-esdhc-imx.c +0 -3
-                       tmp = cqhci_readl(cq_host, CQHCI_IS);
-                       cqhci_writel(cq_host, tmp, CQHCI_IS);
-                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 4 lines
                }
        }

}

drivers/mmc/host/sdhci-esdhc-imx.c +0 -0
@@ -1555,6 +1576,7 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 8 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
        struct sdhci_pltfm_host *pltfm_host;
        struct sdhci_host *host;
        struct cqhci_host *cq_host;
+       struct mmc_hsq *hsq;
        int err;
        struct pltfm_imx_data *imx_data;
 
@@ -1664,6 +1686,16 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
                err = cqhci_init(cq_host, host->mmc, false);
                if (err)
                        goto disable_ahb_clk;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq),

GFP_KERNEL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 12 lines
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
+               if (!hsq) {
+                       err = -ENOMEM;
+                       goto disable_ahb_clk;
+               }
+
+               err = mmc_hsq_init(hsq, host->mmc);
+               if (err)
+                       goto disable_ahb_clk;
        }
 
        if (of_id)
@@ -1673,6 +1705,11 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
        if (err)
                goto disable_ahb_clk;
 
+       if (!mmc_card_is_removable(host->mmc))
+               host->mmc_host_ops.request_atomic =

sdhci_request_atomic;

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device

Quoted 7 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       else
+               host->always_defer_done = true;
+
        sdhci_esdhc_imx_hwinit(host);
 
        err = sdhci_add_host(host);
@@ -1737,6 +1774,8 @@ static int sdhci_esdhc_suspend(struct device

*dev)

Quoted 9 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        if ((imx_data->socdata->flags &

ESDHC_FLAG_STATE_LOST_IN_LPMODE) && @@ -1764,6 +1803,8 @@

static int

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_resume(struct device

Quoted 10 lines

sdhci_esdhc_suspend(struct device *dev) static int

sdhci_esdhc_resume(struct device *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data =
+ sdhci_pltfm_priv(pltfm_host);
        int ret;
 
        ret = pinctrl_pm_select_default_state(dev);
@@ -1777,8 +1818,11 @@ static int sdhci_esdhc_resume(struct device

*dev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_resume(struct device *dev)

Quoted 13 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -2
        if (ret)
                return ret;
 
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                ret = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        if (!ret)
                ret = mmc_gpio_set_cd_wake(host->mmc, false); @@
-1799,6 +1843,8 @@ static int sdhci_esdhc_runtime_suspend(struct device

*dev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device *dev)

Quoted 8 lines
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        ret = sdhci_runtime_suspend_host(host); @@ -1851,8 +1897,11

@@

Quoted 31 lines

static int sdhci_esdhc_runtime_resume(struct device *dev)

        if (err)
                goto disable_ipg_clk;
drivers/mmc/host/sdhci-esdhc-imx.c +4 -1
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                err = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        return err;
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core layer.
- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make sure the
CQE can work normally.
- Add a new patch to enable the host software queue for the SD card.
- Use the default MMC queue depth for host software queue.

Changes from v6:
- Change the patch order and set host->always_defer_done = true
for the Spreadtrum host driver.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Changes from v5:
- Modify the condition of defering to complete request
suggested by

Adrian.

Quoted 4 lines
Quoted 4 lines

Changes from v4:
- Add a seperate patch to introduce a variable to defer to
complete data requests for some host drivers, when using host

software queue.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in flight.
- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct
cqhci_slot', instead adding 'struct sqhci_host', which is only used by

software queue.

Quoted 49 lines
Quoted 49 lines
Quoted 15 lines
Quoted 15 lines

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 (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD card
mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests if
needed
mmc: host: sdhci-sprd: Add software queue support

Quoted 8 lines
Quoted 8 lines
 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343

+++++++++++++++++++++++++++++++++++++++++

Quoted 10 lines
Quoted 10 lines
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)  create

mode
100644 drivers/mmc/host/mmc_hsq.c create mode 100644 drivers/mmc/host/mmc_hsq.h

Quoted 6 lines
Quoted 3 lines

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

I am very appreciated for you and Arnd's good sugestion when introducing the hsq.

Quoted 4 lines

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look good.

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Thanks for your help and looks good to me.

--
Baolin Wang

--
Baolin Wang

Signature · 1 line
Baolin Wang
maintainer
#13 lore raw
Quoted 207 lines

-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: 2020年6月15日 7:26
To: BOUGH CHEN <[email protected]>
Cc: Ulf Hansson <[email protected]>; Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>; Chunyan Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>; dl-linux-imx <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Quoted 2 lines · Baolin Wang

On Wed, Jun 10, 2020 at 10:26 AM BOUGH CHEN <[email protected]>

Quoted 18 lines · wrote:
Quoted 18 lines
Quoted 18 lines

-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: 2020年6月8日 19:54
To: BOUGH CHEN <[email protected]>
Cc: Ulf Hansson <[email protected]>; Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>; Chunyan Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>; dl-linux-imx <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Hi Haibo.

On Mon, Jun 8, 2020 at 2:35 PM BOUGH CHEN <[email protected]>

Quoted 24 lines · wrote:
Quoted 24 lines
Quoted 24 lines
Quoted 9 lines
Quoted 9 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Baolin Wang
Sent: 2020年2月19日 9:35
To: Ulf Hansson <[email protected]>
Cc: Adrian Hunter <[email protected]>; Asutosh Das <[email protected]>; Orson Zhai <[email protected]>;

Chunyan

Quoted 14 lines
Quoted 14 lines

Zhang <[email protected]>; Arnd Bergmann <[email protected]>; Linus Walleij <[email protected]>; Baolin Wang <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH v9 0/5] Add MMC software queue support

Quoted 3 lines · Ulf Hansson

On Wed, 12 Feb 2020 at 05:14, Baolin Wang
<[email protected]>

Quoted 1 line · wrote:
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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.

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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 64 to allow more requests can be be prepared, merged and inserted into IO scheduler, but we only allow 2 requests in flight, that is enough to let the irq handler always trigger the next request without a context switch, as

well as avoiding a long latency.

Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines

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.

Quoted 5 lines
Quoted 5 lines

./fio --filename=/dev/mmcblk0p30 --direct=1 --iodepth=20 --rw=read --bs=4K --size=1G --group_reporting --numjobs=20 --name=test_read

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

My eMMC card working at HS400 Enhanced strobe mode:

[    2.229856] mmc0: new HS400 Enhanced strobe MMC card at

address

Quoted 3 lines
Quoted 3 lines

0001

Quoted 2 lines
Quoted 2 lines
[    2.237566] mmcblk0: mmc0:0001 HBG4a2 29.1 GiB
[    2.242621] mmcblk0boot0: mmc0:0001 HBG4a2 partition 1

4.00

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.249110] mmcblk0boot1: mmc0:0001 HBG4a2 partition 2

4.00

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

MiB

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[    2.255307] mmcblk0rpmb: mmc0:0001 HBG4a2 partition 3

4.00

Quoted 44 lines
Quoted 44 lines
Quoted 44 lines

MiB,

Quoted 43 lines
Quoted 43 lines

chardev (248:0)

Quoted 42 lines
Quoted 42 lines

1. Without MMC software queue I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.4MiB/s, 63.4MiB/s, 57.5MiB/s, 57.2MiB/s, 60.8MiB/s Average
speed: 59.66MiB/s

2) Random read:
Speed: 26.9MiB/s, 26.9MiB/s, 27.1MiB/s, 27.1MiB/s, 27.2MiB/s Average
speed: 27.04MiB/s

3) Sequential write:
Speed: 71.6MiB/s, 72.5MiB/s, 72.2MiB/s, 64.6MiB/s, 67.5MiB/s Average
speed: 69.68MiB/s

4) Random write:
Speed: 36.3MiB/s, 35.4MiB/s, 38.6MiB/s, 34MiB/s, 35.5MiB/s Average
speed: 35.96MiB/s

2. With MMC software queue I tested 5 times for each case and output a average speed.

1) Sequential read:
Speed: 59.2MiB/s, 60.4MiB/s, 63.6MiB/s, 60.3MiB/s, 59.9MiB/s Average
speed: 60.68MiB/s

2) Random read:
Speed: 31.3MiB/s, 31.4MiB/s, 31.5MiB/s, 31.3MiB/s, 31.3MiB/s Average
speed: 31.36MiB/s

3) Sequential write:
Speed: 71MiB/s, 71.8MiB/s, 72.3MiB/s, 72.2MiB/s, 71MiB/s Average
speed: 71.66MiB/s

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

4) Random write:
Speed: 68.9MiB/s, 68.7MiB/s, 68.8MiB/s, 68.6MiB/s, 68.8MiB/s Average
speed: 68.76MiB/s

Form above data, we can see the MMC software queue can help to improve some performance obviously for random read and write, though no obvious improvement for sequential read and

write.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Any comments are welcome. Thanks a lot.

Hi Baolin,

I refer to your code, and add the software queue support on i.MX based on

the Linux next-20200602, but unfortunately, I see an obvious performance drop when change to use software queue.

Quoted 3 lines

I test on our imx850-evk board, with eMMC soldered. From the result listing below, only random write has a little performance

improve, for others, seems performance drop a lot.

Quoted 2 lines

I noticed that, this software queue need no-removable card, any other

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

limitation? For host?

Quoted 2 lines

From the code logic, software queue complete the request in irq handler,

seems no other change, I do not figure out why this will trigger a performance drop on my platform. Any comment would be appreciate!

Have you tested with below patches, which introduce an atomic_request host ops to submit next request in the irq hard handler

context to reduce latency?

Quoted 4 lines
Quoted 4 lines

Hi Baolin,

The Linux code base I use is Linux-next-20200602, which already contain all

the patch you listed, including the atomic_request.

Quoted 1 line
Quoted 1 line

I do not test the atomic_request alone. I just enable software queue, and

this software queue use the atomic request.

Quoted 1 line
Quoted 1 line

So, do you mean, I need to first disable software queue, and just enable the

atomic_request, to confirm whether the atomic_request has some performance impact on my platform?

Quoted 6 lines

NO, the HSQ will support atomic_request ops, and I think you should implement the atomic_request ops in your driver if possible, like below patch:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.

kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2

Quoted 1 line

Fcommit%2F%3Fid%3D61ab64e2f54f4c607428667f83f411cb659843a3&amp;d ata=02

Quoted 1 line

%7C01%7Chaibo.chen%40nxp.com%7C500e3b7d66954c14d2f208d810ba488

3%7C686e

Quoted 1 line
Quoted 9 lines

a1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7C637277739547832756&amp;s data=0j

Quoted 1 line

RbAi8gvllPKc0IPjdQfK7nTGQ9piefGu80lWQIG5Y%3D&amp;reserved=0

Ah, sorry, I saw you've implemented the atomic_request ops. Moreover I've tested the mainline, and I still got some performance improvement.

What's the IO scheduler you selected?

Hi Baolin,

I do not change the setting of IO scheduler, so should be the default IO scheduler.
One thing I find when I go through your patch set, is that you said the HSQ need host side to has the flag MMC_CAP_WAIT_WHILE_BUSY. But for i.MX usdhc host, it do not support this flag, not sure whether it caused the performance difference.

Best Regards
Haibo Chen

Quoted 339 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

Without software queue, normal read/write method:
Sequential read: 56MB/s
Random read: 23.5MB/s
Sequential write: 43.7MB/s
Random write: 19MB/s

With mmc software queue:
Sequential read: 33.5MB/s
Random read: 18.7 MB/s
Sequential write: 37.7MB/s
Random write: 19.8MB/s

Here, I also list my change code to support software queue

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/Kconfig +0 -0

index
eb85237bf2d6..996b8cc5c381 100644
--- a/drivers/mmc/host/Kconfig

Quoted 8 lines
Quoted 8 lines

drivers/mmc/host/Kconfig config MMC_SDHCI_ESDHC_IMX · line 259

Quoted 8 lines

+++ b/drivers/mmc/host/Kconfig

drivers/mmc/host/Kconfig +1 -0
@@ -254,6 +254,7 @@ config MMC_SDHCI_ESDHC_IMX
        depends on MMC_SDHCI_PLTFM
        select MMC_SDHCI_IO_ACCESSORS
        select MMC_CQHCI
+       select MMC_HSQ
        help
          This selects the Freescale eSDHC/uSDHC controller

support

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 15 lines
drivers/mmc/host/Kconfig +0 -0
          found on i.MX25, i.MX35 i.MX5x and i.MX6x.
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
index 1d7f84b23a22..6f163695b08d 100644
@@ -29,6 +29,7 @@
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
 #include "cqhci.h"
+#include "mmc_hsq.h"
 
 #define ESDHC_SYS_CTRL_DTOCV_MASK      0x0f
 #define        ESDHC_CTRL_D3CD                 0x08
@@ -1220,6 +1221,15 @@ static u32 esdhc_cqhci_irq(struct
Quoted 1 line

sdhci_host

*host, u32 intmask)

Quoted 21 lines
        return 0;

}

drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
+static void esdhc_request_done(struct sdhci_host *host, struct
+mmc_request *mrq) {
+       /* Validate if the request was from software queue firstly. */
+       if (mmc_hsq_finalize_request(host->mmc, mrq))
+               return;
+
+       mmc_request_done(host->mmc, mrq); }
+
 static struct sdhci_ops sdhci_esdhc_ops = {
        .read_l = esdhc_readl_le,
        .read_w = esdhc_readw_le, @@ -1237,6 +1247,7 @@ static

struct sdhci_ops sdhci_esdhc_ops = {
.set_uhs_signaling = esdhc_set_uhs_signaling, .reset = esdhc_reset,
.irq = esdhc_cqhci_irq,
+ .request_done = esdhc_request_done,
};

Quoted 4 lines

static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
@@
-1301,6 +1312,19 @@ static void sdhci_esdhc_imx_hwinit(struct sdhci_host

*host)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
                        writel(tmp, host->ioaddr +

ESDHC_VEND_SPEC2);

Quoted 2 lines
                        host->quirks &=

~SDHCI_QUIRK_NO_BUSY_IRQ;

Quoted 3 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+
+                       /*
+                        * On i.MX8MM, we are running Dual

Linux

Quoted 118 lines
Quoted 118 lines
Quoted 118 lines
Quoted 1 line

+ OS,

with 1st Linux using SD Card

Quoted 2 lines

+ * as rootfs storage, 2nd Linux using
+ eMMC as

rootfs storage. We let the

Quoted 2 lines

+ * the 1st linux configure power/clock
+ for the

2nd Linux.

drivers/mmc/host/sdhci-esdhc-imx.c

Quoted 3 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+                        *
+                        * When the 2nd Linux is booting into
+ rootfs

stage, we let the 1st Linux

Quoted 2 lines

+ * to destroy the 2nd linux, then
+ restart the

2nd linux, we met SDHCI dump.

Quoted 2 lines

+ * After we clear the pending interrupt
+ and halt

CQCTL, issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 4 lines
drivers/mmc/host/sdhci-esdhc-imx.c +4 -0
+                        */
+                       tmp = cqhci_readl(cq_host, CQHCI_IS);
+                       cqhci_writel(cq_host, tmp, CQHCI_IS);
+                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

Quoted 3 lines
                }

                if (imx_data->socdata->flags &

ESDHC_FLAG_STD_TUNING)

Quoted 2 lines

{ @@ -1351,9 +1375,6 @@ static void
sdhci_esdhc_imx_hwinit(struct

sdhci_host *host)

Quoted 2 lines

* After we clear the pending interrupt and halt
CQCTL,

issue gone.

drivers/mmc/host/sdhci-esdhc-imx.c static void sdhci_esdhc_imx_hwinit(struct sdhci_host *host)

Quoted 5 lines
                 */
                if (cq_host) {
drivers/mmc/host/sdhci-esdhc-imx.c +0 -3
-                       tmp = cqhci_readl(cq_host, CQHCI_IS);
-                       cqhci_writel(cq_host, tmp, CQHCI_IS);
-                       cqhci_writel(cq_host, CQHCI_HALT,

CQHCI_CTL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 4 lines
                }
        }

}

drivers/mmc/host/sdhci-esdhc-imx.c +0 -0
@@ -1555,6 +1576,7 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 8 lines
drivers/mmc/host/sdhci-esdhc-imx.c +1 -0
        struct sdhci_pltfm_host *pltfm_host;
        struct sdhci_host *host;
        struct cqhci_host *cq_host;
+       struct mmc_hsq *hsq;
        int err;
        struct pltfm_imx_data *imx_data;
 
@@ -1664,6 +1686,16 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
                err = cqhci_init(cq_host, host->mmc, false);
                if (err)
                        goto disable_ahb_clk;
+       } else if (esdhc_is_usdhc(imx_data)) {
+               hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq),

GFP_KERNEL);

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct

Quoted 12 lines
drivers/mmc/host/sdhci-esdhc-imx.c +8 -0
+               if (!hsq) {
+                       err = -ENOMEM;
+                       goto disable_ahb_clk;
+               }
+
+               err = mmc_hsq_init(hsq, host->mmc);
+               if (err)
+                       goto disable_ahb_clk;
        }
 
        if (of_id)
@@ -1673,6 +1705,11 @@ static int sdhci_esdhc_imx_probe(struct

platform_device *pdev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_imx_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
        if (err)
                goto disable_ahb_clk;
 
+       if (!mmc_card_is_removable(host->mmc))
+               host->mmc_host_ops.request_atomic =

sdhci_request_atomic;

Quoted 7 lines
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       else
+               host->always_defer_done = true;
+
        sdhci_esdhc_imx_hwinit(host);
 
        err = sdhci_add_host(host); @@ -1737,6 +1774,8 @@ static

int sdhci_esdhc_suspend(struct device

*dev)

Quoted 9 lines
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
drivers/mmc/host/sdhci-esdhc-imx.c +2 -0
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        if ((imx_data->socdata->flags &

ESDHC_FLAG_STATE_LOST_IN_LPMODE) && @@ -1764,6 +1803,8 @@

static int

Quoted 11 lines

sdhci_esdhc_suspend(struct device *dev) static int

sdhci_esdhc_resume(struct device *dev)  {
        struct sdhci_host *host = dev_get_drvdata(dev);
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data =
+ sdhci_pltfm_priv(pltfm_host);
        int ret;
 
        ret = pinctrl_pm_select_default_state(dev);
@@ -1777,8 +1818,11 @@ static int sdhci_esdhc_resume(struct

device

*dev)

Quoted 10 lines
        if (ret)
                return ret;
drivers/mmc/host/sdhci-esdhc-imx.c +4 -1
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                ret = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
        if (!ret)
                ret = mmc_gpio_set_cd_wake(host->mmc, false);

@@

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 2 lines

-1799,6 +1843,8 @@ static int sdhci_esdhc_runtime_suspend(struct device

*dev)

drivers/mmc/host/sdhci-esdhc-imx.c static int sdhci_esdhc_suspend(struct device *dev)

Quoted 9 lines
                ret = cqhci_suspend(host->mmc);
                if (ret)
                        return ret;
drivers/mmc/host/sdhci-esdhc-imx.c +3 -0
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_suspend(host->mmc);
        }
 
        ret = sdhci_runtime_suspend_host(host); @@ -1851,8
+1897,11

@@

Quoted 15 lines

static int sdhci_esdhc_runtime_resume(struct device *dev)

        if (err)
                goto disable_ipg_clk;
drivers/mmc/host/sdhci-esdhc-imx.c +4 -1
-       if (host->mmc->caps2 & MMC_CAP2_CQE)
+       if (host->mmc->caps2 & MMC_CAP2_CQE) {
                err = cqhci_resume(host->mmc);
+       } else if (esdhc_is_usdhc(imx_data)) {
+               mmc_hsq_resume(host->mmc);
+       }
 
        return err;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Changes from v8:
- Add more description in the commit message.
- Optimize the failure log when calling cqe_enable().

Changes from v7:
- Add reviewed tag from Arnd.
- Use the 'hsq' acronym for varibles and functions in the core

layer.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- Check the 'card->ext_csd.cmdq_en' in cqhci.c to make
sure the CQE can work normally.
- Add a new patch to enable the host software queue for the SD

card.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines

- Use the default MMC queue depth for host software queue.

Changes from v6:
- Change the patch order and set host->always_defer_done
= true for the Spreadtrum host driver.

Changes from v5:
- Modify the condition of defering to complete request
suggested by

Adrian.

Quoted 5 lines
Quoted 5 lines

Changes from v4:
- Add a seperate patch to introduce a variable to defer
to complete data requests for some host drivers, when using host

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

software queue.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Changes from v3:
- Use host software queue instead of sqhci.
- Fix random config building issue.
- Change queue depth to 32, but still only allow 2 requests in

flight.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

- Update the testing data.

Changes from v2:
- Remove reference to 'struct cqhci_host' and 'struct
cqhci_slot', instead adding 'struct sqhci_host', which is only used by

software queue.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

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.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Baolin Wang (5):
mmc: Add MMC host software queue support
mmc: core: Enable the MMC host software queue for the SD

card

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

mmc: host: sdhci: Add request_done ops for struct sdhci_ops
mmc: host: sdhci: Add a variable to defer to complete requests

if

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 11 lines
Quoted 11 lines

needed
mmc: host: sdhci-sprd: Add software queue support

 drivers/mmc/core/block.c      |   61 ++++++++
 drivers/mmc/core/mmc.c        |   18 ++-
 drivers/mmc/core/queue.c      |   22 ++-
 drivers/mmc/core/sd.c         |   10 ++
 drivers/mmc/host/Kconfig      |    8 +
 drivers/mmc/host/Makefile     |    1 +
 drivers/mmc/host/cqhci.c      |    8 +-
 drivers/mmc/host/mmc_hsq.c    |  343

+++++++++++++++++++++++++++++++++++++++++

Quoted 16 lines
Quoted 6 lines
 drivers/mmc/host/mmc_hsq.h    |   30 ++++
 drivers/mmc/host/sdhci-sprd.c |   28 ++++
 drivers/mmc/host/sdhci.c      |   14 +-
 drivers/mmc/host/sdhci.h      |    3 +
 include/linux/mmc/host.h      |    3 +
 13 files changed, 534 insertions(+), 15 deletions(-)
Quoted 7 lines

create mode
100644 drivers/mmc/host/mmc_hsq.c create mode 100644 drivers/mmc/host/mmc_hsq.h

--
1.7.9.5

Applied for next, thanks! Also, thanks for your patience while moving forward during the reviews!

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I am very appreciated for you and Arnd's good sugestion when introducing the hsq.

Quoted 4 lines

Note, I did some amending of patch1 to resolve some checkpatch warnings. SPDX licence and Kconfig help texts, please have a look and tell if there are something that doesn't look

good.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Thanks for your help and looks good to me.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

--
Baolin Wang

--
Baolin Wang

--
Baolin Wang