18c2ecf20Sopenharmony_ci======================== 28c2ecf20Sopenharmony_ciMMC Asynchronous Request 38c2ecf20Sopenharmony_ci======================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciRationale 68c2ecf20Sopenharmony_ci========= 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciHow significant is the cache maintenance overhead? 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciIt depends. Fast eMMC and multiple cache levels with speculative cache 118c2ecf20Sopenharmony_cipre-fetch makes the cache overhead relatively significant. If the DMA 128c2ecf20Sopenharmony_cipreparations for the next request are done in parallel with the current 138c2ecf20Sopenharmony_citransfer, the DMA preparation overhead would not affect the MMC performance. 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciThe intention of non-blocking (asynchronous) MMC requests is to minimize the 168c2ecf20Sopenharmony_citime between when an MMC request ends and another MMC request begins. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciUsing mmc_wait_for_req(), the MMC controller is idle while dma_map_sg and 198c2ecf20Sopenharmony_cidma_unmap_sg are processing. Using non-blocking MMC requests makes it 208c2ecf20Sopenharmony_cipossible to prepare the caches for next job in parallel with an active 218c2ecf20Sopenharmony_ciMMC request. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciMMC block driver 248c2ecf20Sopenharmony_ci================ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciThe mmc_blk_issue_rw_rq() in the MMC block driver is made non-blocking. 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ciThe increase in throughput is proportional to the time it takes to 298c2ecf20Sopenharmony_ciprepare (major part of preparations are dma_map_sg() and dma_unmap_sg()) 308c2ecf20Sopenharmony_cia request and how fast the memory is. The faster the MMC/SD is the 318c2ecf20Sopenharmony_cimore significant the prepare request time becomes. Roughly the expected 328c2ecf20Sopenharmony_ciperformance gain is 5% for large writes and 10% on large reads on a L2 cache 338c2ecf20Sopenharmony_ciplatform. In power save mode, when clocks run on a lower frequency, the DMA 348c2ecf20Sopenharmony_cipreparation may cost even more. As long as these slower preparations are run 358c2ecf20Sopenharmony_ciin parallel with the transfer performance won't be affected. 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ciDetails on measurements from IOZone and mmc_test 388c2ecf20Sopenharmony_ci================================================ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cihttps://wiki.linaro.org/WorkingGroups/Kernel/Specs/StoragePerfMMC-async-req 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciMMC core API extension 438c2ecf20Sopenharmony_ci====================== 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ciThere is one new public function mmc_start_req(). 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciIt starts a new MMC command request for a host. The function isn't 488c2ecf20Sopenharmony_citruly non-blocking. If there is an ongoing async request it waits 498c2ecf20Sopenharmony_cifor completion of that request and starts the new one and returns. It 508c2ecf20Sopenharmony_cidoesn't wait for the new request to complete. If there is no ongoing 518c2ecf20Sopenharmony_cirequest it starts the new request and returns immediately. 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciMMC host extensions 548c2ecf20Sopenharmony_ci=================== 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciThere are two optional members in the mmc_host_ops -- pre_req() and 578c2ecf20Sopenharmony_cipost_req() -- that the host driver may implement in order to move work 588c2ecf20Sopenharmony_cito before and after the actual mmc_host_ops.request() function is called. 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciIn the DMA case pre_req() may do dma_map_sg() and prepare the DMA 618c2ecf20Sopenharmony_cidescriptor, and post_req() runs the dma_unmap_sg(). 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciOptimize for the first request 648c2ecf20Sopenharmony_ci============================== 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciThe first request in a series of requests can't be prepared in parallel 678c2ecf20Sopenharmony_ciwith the previous transfer, since there is no previous request. 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciThe argument is_first_req in pre_req() indicates that there is no previous 708c2ecf20Sopenharmony_cirequest. The host driver may optimize for this scenario to minimize 718c2ecf20Sopenharmony_cithe performance loss. A way to optimize for this is to split the current 728c2ecf20Sopenharmony_cirequest in two chunks, prepare the first chunk and start the request, 738c2ecf20Sopenharmony_ciand finally prepare the second chunk and start the transfer. 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ciPseudocode to handle is_first_req scenario with minimal prepare overhead:: 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci if (is_first_req && req->size > threshold) 788c2ecf20Sopenharmony_ci /* start MMC transfer for the complete transfer size */ 798c2ecf20Sopenharmony_ci mmc_start_command(MMC_CMD_TRANSFER_FULL_SIZE); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci /* 828c2ecf20Sopenharmony_ci * Begin to prepare DMA while cmd is being processed by MMC. 838c2ecf20Sopenharmony_ci * The first chunk of the request should take the same time 848c2ecf20Sopenharmony_ci * to prepare as the "MMC process command time". 858c2ecf20Sopenharmony_ci * If prepare time exceeds MMC cmd time 868c2ecf20Sopenharmony_ci * the transfer is delayed, guesstimate max 4k as first chunk size. 878c2ecf20Sopenharmony_ci */ 888c2ecf20Sopenharmony_ci prepare_1st_chunk_for_dma(req); 898c2ecf20Sopenharmony_ci /* flush pending desc to the DMAC (dmaengine.h) */ 908c2ecf20Sopenharmony_ci dma_issue_pending(req->dma_desc); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci prepare_2nd_chunk_for_dma(req); 938c2ecf20Sopenharmony_ci /* 948c2ecf20Sopenharmony_ci * The second issue_pending should be called before MMC runs out 958c2ecf20Sopenharmony_ci * of the first chunk. If the MMC runs out of the first data chunk 968c2ecf20Sopenharmony_ci * before this call, the transfer is delayed. 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_ci dma_issue_pending(req->dma_desc); 99