mmc-async-req.txt 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Rationale
  2. =========
  3. How significant is the cache maintenance overhead?
  4. It depends. Fast eMMC and multiple cache levels with speculative cache
  5. pre-fetch makes the cache overhead relatively significant. If the DMA
  6. preparations for the next request are done in parallel with the current
  7. transfer, the DMA preparation overhead would not affect the MMC performance.
  8. The intention of non-blocking (asynchronous) MMC requests is to minimize the
  9. time between when an MMC request ends and another MMC request begins.
  10. Using mmc_wait_for_req(), the MMC controller is idle while dma_map_sg and
  11. dma_unmap_sg are processing. Using non-blocking MMC requests makes it
  12. possible to prepare the caches for next job in parallel with an active
  13. MMC request.
  14. MMC block driver
  15. ================
  16. The mmc_blk_issue_rw_rq() in the MMC block driver is made non-blocking.
  17. The increase in throughput is proportional to the time it takes to
  18. prepare (major part of preparations are dma_map_sg() and dma_unmap_sg())
  19. a request and how fast the memory is. The faster the MMC/SD is the
  20. more significant the prepare request time becomes. Roughly the expected
  21. performance gain is 5% for large writes and 10% on large reads on a L2 cache
  22. platform. In power save mode, when clocks run on a lower frequency, the DMA
  23. preparation may cost even more. As long as these slower preparations are run
  24. in parallel with the transfer performance won't be affected.
  25. Details on measurements from IOZone and mmc_test
  26. ================================================
  27. https://wiki.linaro.org/WorkingGroups/Kernel/Specs/StoragePerfMMC-async-req
  28. MMC core API extension
  29. ======================
  30. There is one new public function mmc_start_req().
  31. It starts a new MMC command request for a host. The function isn't
  32. truly non-blocking. If there is an ongoing async request it waits
  33. for completion of that request and starts the new one and returns. It
  34. doesn't wait for the new request to complete. If there is no ongoing
  35. request it starts the new request and returns immediately.
  36. MMC host extensions
  37. ===================
  38. There are two optional members in the mmc_host_ops -- pre_req() and
  39. post_req() -- that the host driver may implement in order to move work
  40. to before and after the actual mmc_host_ops.request() function is called.
  41. In the DMA case pre_req() may do dma_map_sg() and prepare the DMA
  42. descriptor, and post_req() runs the dma_unmap_sg().
  43. Optimize for the first request
  44. ==============================
  45. The first request in a series of requests can't be prepared in parallel
  46. with the previous transfer, since there is no previous request.
  47. The argument is_first_req in pre_req() indicates that there is no previous
  48. request. The host driver may optimize for this scenario to minimize
  49. the performance loss. A way to optimize for this is to split the current
  50. request in two chunks, prepare the first chunk and start the request,
  51. and finally prepare the second chunk and start the transfer.
  52. Pseudocode to handle is_first_req scenario with minimal prepare overhead:
  53. if (is_first_req && req->size > threshold)
  54. /* start MMC transfer for the complete transfer size */
  55. mmc_start_command(MMC_CMD_TRANSFER_FULL_SIZE);
  56. /*
  57. * Begin to prepare DMA while cmd is being processed by MMC.
  58. * The first chunk of the request should take the same time
  59. * to prepare as the "MMC process command time".
  60. * If prepare time exceeds MMC cmd time
  61. * the transfer is delayed, guesstimate max 4k as first chunk size.
  62. */
  63. prepare_1st_chunk_for_dma(req);
  64. /* flush pending desc to the DMAC (dmaengine.h) */
  65. dma_issue_pending(req->dma_desc);
  66. prepare_2nd_chunk_for_dma(req);
  67. /*
  68. * The second issue_pending should be called before MMC runs out
  69. * of the first chunk. If the MMC runs out of the first data chunk
  70. * before this call, the transfer is delayed.
  71. */
  72. dma_issue_pending(req->dma_desc);