aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core/queue.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-09-20 04:56:14 -0400
committerUlf Hansson <ulf.hansson@linaro.org>2017-10-04 04:22:55 -0400
commitde3ee99b097dd51938276e3af388cd4ad0f2750a (patch)
treeedd6f7892e67f61f8e8a26a15d3a50bad1d975dc /drivers/mmc/core/queue.c
parentfb458864d9a78cc433fec7979acbe4078c82d7a8 (diff)
mmc: Delete bounce buffer handling
In may, Steven sent a patch deleting the bounce buffer handling and the CONFIG_MMC_BLOCK_BOUNCE option. I chose the less invasive path of making it a runtime config option, and we merged that successfully for kernel v4.12. The code is however just standing in the way and taking up space for seemingly no gain on any systems in wide use today. Pierre says the code was there to improve speed on TI SDHCI controllers on certain HP laptops and possibly some Ricoh controllers as well. Early SDHCI controllers lacked the scatter-gather feature, which made software bounce buffers a significant speed boost. We are clearly talking about the list of SDHCI PCI-based MMC/SD card readers found in the pci_ids[] list in drivers/mmc/host/sdhci-pci-core.c. The TI SDHCI derivative is not supported by the upstream kernel. This leaves the Ricoh. What we can however notice is that the x86 defconfigs in the kernel did not enable CONFIG_MMC_BLOCK_BOUNCE option, which means that any such laptop would have to have a custom configured kernel to actually take advantage of this bounce buffer speed-up. It simply seems like there was a speed optimization for the Ricoh controllers that noone was using. (I have not checked the distro defconfigs but I am pretty sure the situation is the same there.) Bounce buffers increased performance on the OMAP HSMMC at one point, and was part of the original submission in commit a45c6cb81647 ("[ARM] 5369/1: omap mmc: Add new omap hsmmc controller for 2430 and 34xx, v3") This optimization was removed in commit 0ccd76d4c236 ("omap_hsmmc: Implement scatter-gather emulation") which found that scatter-gather emulation provided even better performance. The same was introduced for SDHCI in commit 2134a922c6e7 ("sdhci: scatter-gather (ADMA) support") I am pretty positively convinced that software scatter-gather emulation will do for any host controller what the bounce buffers were doing. Essentially, the bounce buffer was a reimplementation of software scatter-gather-emulation in the MMC subsystem, and it should be done away with. Cc: Pierre Ossman <pierre@ossman.eu> Cc: Juha Yrjola <juha.yrjola@solidboot.com> Cc: Steven J. Hill <Steven.Hill@cavium.com> Cc: Shawn Lin <shawn.lin@rock-chips.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Suggested-by: Steven J. Hill <Steven.Hill@cavium.com> Suggested-by: Shawn Lin <shawn.lin@rock-chips.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/mmc/core/queue.c')
-rw-r--r--drivers/mmc/core/queue.c125
1 files changed, 9 insertions, 116 deletions
diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
index 74c663b1c0a7..0a4e77a5ba33 100644
--- a/drivers/mmc/core/queue.c
+++ b/drivers/mmc/core/queue.c
@@ -23,8 +23,6 @@
23#include "core.h" 23#include "core.h"
24#include "card.h" 24#include "card.h"
25 25
26#define MMC_QUEUE_BOUNCESZ 65536
27
28/* 26/*
29 * Prepare a MMC request. This just filters out odd stuff. 27 * Prepare a MMC request. This just filters out odd stuff.
30 */ 28 */
@@ -150,26 +148,6 @@ static void mmc_queue_setup_discard(struct request_queue *q,
150 queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q); 148 queue_flag_set_unlocked(QUEUE_FLAG_SECERASE, q);
151} 149}
152 150
153static unsigned int mmc_queue_calc_bouncesz(struct mmc_host *host)
154{
155 unsigned int bouncesz = MMC_QUEUE_BOUNCESZ;
156
157 if (host->max_segs != 1 || (host->caps & MMC_CAP_NO_BOUNCE_BUFF))
158 return 0;
159
160 if (bouncesz > host->max_req_size)
161 bouncesz = host->max_req_size;
162 if (bouncesz > host->max_seg_size)
163 bouncesz = host->max_seg_size;
164 if (bouncesz > host->max_blk_count * 512)
165 bouncesz = host->max_blk_count * 512;
166
167 if (bouncesz <= 512)
168 return 0;
169
170 return bouncesz;
171}
172
173/** 151/**
174 * mmc_init_request() - initialize the MMC-specific per-request data 152 * mmc_init_request() - initialize the MMC-specific per-request data
175 * @q: the request queue 153 * @q: the request queue
@@ -184,26 +162,9 @@ static int mmc_init_request(struct request_queue *q, struct request *req,
184 struct mmc_card *card = mq->card; 162 struct mmc_card *card = mq->card;
185 struct mmc_host *host = card->host; 163 struct mmc_host *host = card->host;
186 164
187 if (card->bouncesz) { 165 mq_rq->sg = mmc_alloc_sg(host->max_segs, gfp);
188 mq_rq->bounce_buf = kmalloc(card->bouncesz, gfp); 166 if (!mq_rq->sg)
189 if (!mq_rq->bounce_buf) 167 return -ENOMEM;
190 return -ENOMEM;
191 if (card->bouncesz > 512) {
192 mq_rq->sg = mmc_alloc_sg(1, gfp);
193 if (!mq_rq->sg)
194 return -ENOMEM;
195 mq_rq->bounce_sg = mmc_alloc_sg(card->bouncesz / 512,
196 gfp);
197 if (!mq_rq->bounce_sg)
198 return -ENOMEM;
199 }
200 } else {
201 mq_rq->bounce_buf = NULL;
202 mq_rq->bounce_sg = NULL;
203 mq_rq->sg = mmc_alloc_sg(host->max_segs, gfp);
204 if (!mq_rq->sg)
205 return -ENOMEM;
206 }
207 168
208 return 0; 169 return 0;
209} 170}
@@ -212,13 +173,6 @@ static void mmc_exit_request(struct request_queue *q, struct request *req)
212{ 173{
213 struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req); 174 struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req);
214 175
215 /* It is OK to kfree(NULL) so this will be smooth */
216 kfree(mq_rq->bounce_sg);
217 mq_rq->bounce_sg = NULL;
218
219 kfree(mq_rq->bounce_buf);
220 mq_rq->bounce_buf = NULL;
221
222 kfree(mq_rq->sg); 176 kfree(mq_rq->sg);
223 mq_rq->sg = NULL; 177 mq_rq->sg = NULL;
224} 178}
@@ -242,12 +196,6 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
242 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask) 196 if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
243 limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT; 197 limit = (u64)dma_max_pfn(mmc_dev(host)) << PAGE_SHIFT;
244 198
245 /*
246 * mmc_init_request() depends on card->bouncesz so it must be calculated
247 * before blk_init_allocated_queue() starts allocating requests.
248 */
249 card->bouncesz = mmc_queue_calc_bouncesz(host);
250
251 mq->card = card; 199 mq->card = card;
252 mq->queue = blk_alloc_queue(GFP_KERNEL); 200 mq->queue = blk_alloc_queue(GFP_KERNEL);
253 if (!mq->queue) 201 if (!mq->queue)
@@ -271,17 +219,11 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
271 if (mmc_can_erase(card)) 219 if (mmc_can_erase(card))
272 mmc_queue_setup_discard(mq->queue, card); 220 mmc_queue_setup_discard(mq->queue, card);
273 221
274 if (card->bouncesz) { 222 blk_queue_bounce_limit(mq->queue, limit);
275 blk_queue_max_hw_sectors(mq->queue, card->bouncesz / 512); 223 blk_queue_max_hw_sectors(mq->queue,
276 blk_queue_max_segments(mq->queue, card->bouncesz / 512); 224 min(host->max_blk_count, host->max_req_size / 512));
277 blk_queue_max_segment_size(mq->queue, card->bouncesz); 225 blk_queue_max_segments(mq->queue, host->max_segs);
278 } else { 226 blk_queue_max_segment_size(mq->queue, host->max_seg_size);
279 blk_queue_bounce_limit(mq->queue, limit);
280 blk_queue_max_hw_sectors(mq->queue,
281 min(host->max_blk_count, host->max_req_size / 512));
282 blk_queue_max_segments(mq->queue, host->max_segs);
283 blk_queue_max_segment_size(mq->queue, host->max_seg_size);
284 }
285 227
286 sema_init(&mq->thread_sem, 1); 228 sema_init(&mq->thread_sem, 1);
287 229
@@ -370,56 +312,7 @@ void mmc_queue_resume(struct mmc_queue *mq)
370 */ 312 */
371unsigned int mmc_queue_map_sg(struct mmc_queue *mq, struct mmc_queue_req *mqrq) 313unsigned int mmc_queue_map_sg(struct mmc_queue *mq, struct mmc_queue_req *mqrq)
372{ 314{
373 unsigned int sg_len;
374 size_t buflen;
375 struct scatterlist *sg;
376 struct request *req = mmc_queue_req_to_req(mqrq); 315 struct request *req = mmc_queue_req_to_req(mqrq);
377 int i;
378
379 if (!mqrq->bounce_buf)
380 return blk_rq_map_sg(mq->queue, req, mqrq->sg);
381
382 sg_len = blk_rq_map_sg(mq->queue, req, mqrq->bounce_sg);
383
384 mqrq->bounce_sg_len = sg_len;
385
386 buflen = 0;
387 for_each_sg(mqrq->bounce_sg, sg, sg_len, i)
388 buflen += sg->length;
389
390 sg_init_one(mqrq->sg, mqrq->bounce_buf, buflen);
391
392 return 1;
393}
394
395/*
396 * If writing, bounce the data to the buffer before the request
397 * is sent to the host driver
398 */
399void mmc_queue_bounce_pre(struct mmc_queue_req *mqrq)
400{
401 if (!mqrq->bounce_buf)
402 return;
403
404 if (rq_data_dir(mmc_queue_req_to_req(mqrq)) != WRITE)
405 return;
406
407 sg_copy_to_buffer(mqrq->bounce_sg, mqrq->bounce_sg_len,
408 mqrq->bounce_buf, mqrq->sg[0].length);
409}
410
411/*
412 * If reading, bounce the data from the buffer after the request
413 * has been handled by the host driver
414 */
415void mmc_queue_bounce_post(struct mmc_queue_req *mqrq)
416{
417 if (!mqrq->bounce_buf)
418 return;
419
420 if (rq_data_dir(mmc_queue_req_to_req(mqrq)) != READ)
421 return;
422 316
423 sg_copy_from_buffer(mqrq->bounce_sg, mqrq->bounce_sg_len, 317 return blk_rq_map_sg(mq->queue, req, mqrq->sg);
424 mqrq->bounce_buf, mqrq->sg[0].length);
425} 318}