Skip to content

Commit 511ce37

Browse files
wangbaolin719storulf
authored andcommitted
mmc: Add MMC host software queue support
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. Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Baolin Wang <[email protected]> Signed-off-by: Baolin Wang <[email protected]> Link: https://lore.kernel.org/r/4409c1586a9b3ed20d57ad2faf6c262fc3ccb6e2.1581478568.git.baolin.wang7@gmail.com Signed-off-by: Ulf Hansson <[email protected]>
1 parent 219c02c commit 511ce37

File tree

9 files changed

+486
-12
lines changed

9 files changed

+486
-12
lines changed

drivers/mmc/core/block.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
168168

169169
static inline int mmc_blk_part_switch(struct mmc_card *card,
170170
unsigned int part_type);
171+
static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
172+
struct mmc_card *card,
173+
int disable_multi,
174+
struct mmc_queue *mq);
175+
static void mmc_blk_hsq_req_done(struct mmc_request *mrq);
171176

172177
static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
173178
{
@@ -1532,9 +1537,30 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue *mq, struct request *req)
15321537
return mmc_blk_cqe_start_req(mq->card->host, mrq);
15331538
}
15341539

1540+
static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request *req)
1541+
{
1542+
struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
1543+
struct mmc_host *host = mq->card->host;
1544+
int err;
1545+
1546+
mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
1547+
mqrq->brq.mrq.done = mmc_blk_hsq_req_done;
1548+
mmc_pre_req(host, &mqrq->brq.mrq);
1549+
1550+
err = mmc_cqe_start_req(host, &mqrq->brq.mrq);
1551+
if (err)
1552+
mmc_post_req(host, &mqrq->brq.mrq, err);
1553+
1554+
return err;
1555+
}
1556+
15351557
static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue *mq, struct request *req)
15361558
{
15371559
struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
1560+
struct mmc_host *host = mq->card->host;
1561+
1562+
if (host->hsq_enabled)
1563+
return mmc_blk_hsq_issue_rw_rq(mq, req);
15381564

15391565
mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
15401566

@@ -1920,6 +1946,41 @@ static void mmc_blk_urgent_bkops(struct mmc_queue *mq,
19201946
mmc_run_bkops(mq->card);
19211947
}
19221948

1949+
static void mmc_blk_hsq_req_done(struct mmc_request *mrq)
1950+
{
1951+
struct mmc_queue_req *mqrq =
1952+
container_of(mrq, struct mmc_queue_req, brq.mrq);
1953+
struct request *req = mmc_queue_req_to_req(mqrq);
1954+
struct request_queue *q = req->q;
1955+
struct mmc_queue *mq = q->queuedata;
1956+
struct mmc_host *host = mq->card->host;
1957+
unsigned long flags;
1958+
1959+
if (mmc_blk_rq_error(&mqrq->brq) ||
1960+
mmc_blk_urgent_bkops_needed(mq, mqrq)) {
1961+
spin_lock_irqsave(&mq->lock, flags);
1962+
mq->recovery_needed = true;
1963+
mq->recovery_req = req;
1964+
spin_unlock_irqrestore(&mq->lock, flags);
1965+
1966+
host->cqe_ops->cqe_recovery_start(host);
1967+
1968+
schedule_work(&mq->recovery_work);
1969+
return;
1970+
}
1971+
1972+
mmc_blk_rw_reset_success(mq, req);
1973+
1974+
/*
1975+
* Block layer timeouts race with completions which means the normal
1976+
* completion path cannot be used during recovery.
1977+
*/
1978+
if (mq->in_recovery)
1979+
mmc_blk_cqe_complete_rq(mq, req);
1980+
else
1981+
blk_mq_complete_request(req);
1982+
}
1983+
19231984
void mmc_blk_mq_complete(struct request *req)
19241985
{
19251986
struct mmc_queue *mq = req->q->queuedata;

drivers/mmc/core/mmc.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,15 +1851,19 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
18511851
*/
18521852
card->reenable_cmdq = card->ext_csd.cmdq_en;
18531853

1854-
if (card->ext_csd.cmdq_en && !host->cqe_enabled) {
1854+
if (host->cqe_ops && !host->cqe_enabled) {
18551855
err = host->cqe_ops->cqe_enable(host, card);
1856-
if (err) {
1857-
pr_err("%s: Failed to enable CQE, error %d\n",
1858-
mmc_hostname(host), err);
1859-
} else {
1856+
if (!err) {
18601857
host->cqe_enabled = true;
1861-
pr_info("%s: Command Queue Engine enabled\n",
1862-
mmc_hostname(host));
1858+
1859+
if (card->ext_csd.cmdq_en) {
1860+
pr_info("%s: Command Queue Engine enabled\n",
1861+
mmc_hostname(host));
1862+
} else {
1863+
host->hsq_enabled = true;
1864+
pr_info("%s: Host Software Queue enabled\n",
1865+
mmc_hostname(host));
1866+
}
18631867
}
18641868
}
18651869

drivers/mmc/core/queue.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req)
6262
{
6363
struct mmc_host *host = mq->card->host;
6464

65-
if (mq->use_cqe)
65+
if (mq->use_cqe && !host->hsq_enabled)
6666
return mmc_cqe_issue_type(host, req);
6767

6868
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,
124124
{
125125
struct request_queue *q = req->q;
126126
struct mmc_queue *mq = q->queuedata;
127+
struct mmc_card *card = mq->card;
128+
struct mmc_host *host = card->host;
127129
unsigned long flags;
128130
int ret;
129131

130132
spin_lock_irqsave(&mq->lock, flags);
131133

132-
if (mq->recovery_needed || !mq->use_cqe)
134+
if (mq->recovery_needed || !mq->use_cqe || host->hsq_enabled)
133135
ret = BLK_EH_RESET_TIMER;
134136
else
135137
ret = mmc_cqe_timed_out(req);
@@ -144,12 +146,13 @@ static void mmc_mq_recovery_handler(struct work_struct *work)
144146
struct mmc_queue *mq = container_of(work, struct mmc_queue,
145147
recovery_work);
146148
struct request_queue *q = mq->queue;
149+
struct mmc_host *host = mq->card->host;
147150

148151
mmc_get_card(mq->card, &mq->ctx);
149152

150153
mq->in_recovery = true;
151154

152-
if (mq->use_cqe)
155+
if (mq->use_cqe && !host->hsq_enabled)
153156
mmc_blk_cqe_recovery(mq);
154157
else
155158
mmc_blk_mq_recovery(mq);
@@ -160,6 +163,9 @@ static void mmc_mq_recovery_handler(struct work_struct *work)
160163
mq->recovery_needed = false;
161164
spin_unlock_irq(&mq->lock);
162165

166+
if (host->hsq_enabled)
167+
host->cqe_ops->cqe_recovery_finish(host);
168+
163169
mmc_put_card(mq->card, &mq->ctx);
164170

165171
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,
279285
}
280286
break;
281287
case MMC_ISSUE_ASYNC:
288+
/*
289+
* For MMC host software queue, we only allow 2 requests in
290+
* flight to avoid a long latency.
291+
*/
292+
if (host->hsq_enabled && mq->in_flight[issue_type] > 2) {
293+
spin_unlock_irq(&mq->lock);
294+
return BLK_STS_RESOURCE;
295+
}
282296
break;
283297
default:
284298
/*
@@ -430,7 +444,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card)
430444
* The queue depth for CQE must match the hardware because the request
431445
* tag is used to index the hardware queue.
432446
*/
433-
if (mq->use_cqe)
447+
if (mq->use_cqe && !host->hsq_enabled)
434448
mq->tag_set.queue_depth =
435449
min_t(int, card->ext_csd.cmdq_depth, host->cqe_qdepth);
436450
else

drivers/mmc/host/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,17 @@ config MMC_CQHCI
949949

950950
If unsure, say N.
951951

952+
config MMC_HSQ
953+
tristate "MMC Host Software Queue support"
954+
help
955+
This selects the MMC Host Software Queue support. This may increase
956+
performance, if the host controller and its driver supports it.
957+
958+
If you have a controller/driver supporting this interface, say Y or M
959+
here.
960+
961+
If unsure, say N.
962+
952963
config MMC_TOSHIBA_PCI
953964
tristate "Toshiba Type A SD/MMC Card Interface Driver"
954965
depends on PCI

drivers/mmc/host/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ obj-$(CONFIG_MMC_SDHCI_BRCMSTB) += sdhci-brcmstb.o
100100
obj-$(CONFIG_MMC_SDHCI_OMAP) += sdhci-omap.o
101101
obj-$(CONFIG_MMC_SDHCI_SPRD) += sdhci-sprd.o
102102
obj-$(CONFIG_MMC_CQHCI) += cqhci.o
103+
obj-$(CONFIG_MMC_HSQ) += mmc_hsq.o
103104

104105
ifeq ($(CONFIG_CB710_DEBUG),y)
105106
CFLAGS-cb710-mmc += -DDEBUG

drivers/mmc/host/cqhci.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,20 @@ static int cqhci_enable(struct mmc_host *mmc, struct mmc_card *card)
321321
struct cqhci_host *cq_host = mmc->cqe_private;
322322
int err;
323323

324+
if (!card->ext_csd.cmdq_en)
325+
return -EINVAL;
326+
324327
if (cq_host->enabled)
325328
return 0;
326329

327330
cq_host->rca = card->rca;
328331

329332
err = cqhci_host_alloc_tdl(cq_host);
330-
if (err)
333+
if (err) {
334+
pr_err("%s: Failed to enable CQE, error %d\n",
335+
mmc_hostname(mmc), err);
331336
return err;
337+
}
332338

333339
__cqhci_enable(cq_host);
334340

0 commit comments

Comments
 (0)