Update: [PATCH v2] mmc: core: Optimize polling delay in __mmc_poll_for_busy()
Hi Shawn,
I have updated the code and verified it based on your suggestions. The specific changes and test data are provided further down in this email.
Quoted 50 lines
On the "quite a few places" concern: it is smaller than it looks. Of the call sites you listed, 9 go through the
mmc_poll_for_busy()wrapper (__mmc_switch,mmc_send_hpi_cmd,mmc_blk_fix_state,sd_flush_cache,sd_enable_cache,sd_poweroff_notify,mmc_cqe_recovery,mmc_do_erase), so they do not change at all - the wrapper keeps passing the current default. Only the ~6 direct callers of__mmc_poll_for_busy()need a one-line mechanical change (mmc_ops.cCMD1 and the wrapper itself,block.cx2,sd.c,mmc.c).Also note that the hardcoded 32768 is itself a policy choice that only suits the long-running commands (CMD6, erase, ...). The
OP_CONDstyle polling wants a different maximum - CMD1 as you measured, and ACMD41 insd_ops.cstarts at 10ms and has the same tail-latency issue - so making it an explicit parameter is exactly the point. The core helper should not know which caller it is serving, which is what thebusy_cbpointer comparison effectively does.1) extend the prototype in
mmc_ops.h:int __mmc_poll_for_busy(struct
mmc_host*host, unsigned intperiod_us,unsigned int udelay_max_us, unsigned int timeout_ms, int (*busy_cb)(void *cb_data, bool *busy), void *cb_data);2) in
__mmc_poll_for_busy(), only the throttling changes:- unsigned int udelay =
period_us?period_us: 32,udelay_max=
32768;(quoted diff) +2
-3+ unsigned int udelay = period_us ? period_us : 32; /* Throttle the polling rate to avoid hogging the CPU. */ if (busy) { - usleep_range(udelay, udelay * 2); - if (udelay < udelay_max) - udelay *= 2; + unsigned int sleep_max = min(udelay * 2,
udelay_max_us);(quoted diff) +4
-0+ + usleep_range(min(udelay, udelay_max_us), sleep_max); + if (udelay < udelay_max_us) + udelay *= 2; }3) add the new value next to the existing ones in
mmc_ops.c:#define
MMC_OP_COND_MAX_DELAY_US(8 * 1000) /* 8ms, justify with
data */4) in
mmc_send_op_cond():err = __mmc_poll_for_busy(host,
MMC_OP_COND_PERIOD_US,
+MMC_OP_COND_MAX_DELAY_US,MMC_OP_COND_TIMEOUT_MS, &__mmc_send_op_cond_cb, &cb_data);5) every other caller passes the current default, e.g. the wrapper in
mmc_ops.c:- return __mmc_poll_for_busy(host, 0,
timeout_ms,&__mmc_busy_cb,&cb_data);(quoted diff) +2
-0+ return __mmc_poll_for_busy(host, 0, 32768, timeout_ms, + &__mmc_busy_cb, &cb_data);
Quoted 8 lines
and the same one-line change for the direct callers in
block.c(__mmc_blk_ioctl_cmd(),mmc_blk_card_busy()),sd.c
(sd_poweroff_notify()) andmmc.c(mmc_sleep()). Withperiod_us= 4ms andudelay_max_us= 8ms, the sleeps become 4-8ms, then 8ms, 8ms, ... so the tail bound is 8ms instead of today's 32-64ms, and no caller behaviour changes except CMD1.no, the backoff step stays doubling. What Imeant is: first try this bounded version for CMD1 (8ms maximum) and compare it against your linear +2ms schedule on the same slow cards. If the boot-time results are the same, the linear step is unnecessary and the change stays simple and generic.
eMMC device information:
mmc0: manfid= 0x00009b, name= Y0S128, prv= 0x0, sn= 0xe4145921, mdt= 2022-10
mmc0: pre_eol_info=0x01, life_time= 0x01 0x01
The measurement data, code changes, and CMD1 sleep step are described as follows:
###Note:
The prints " pr_err("%s %s:[*2]usleep1=%d, usleep2=%d\n", mmc_hostname(host), __func__, min(udelay, period_max_us), sleep_max);" are retained only for debugging and were not used in the final timing statistics, so they do not affect the overall timing
(a) Linear step (+2ms) data (max=10ms)
==================================================================
[OPTION A] Linear step (+2ms), cap = 10ms
==================================================================
Step print:
mmc0 __mmc_poll_for_busy:[*2]usleep1=4000, usleep2=6000 mmc0 __mmc_poll_for_busy:[*2]usleep1=6000, usleep2=8000 mmc0 __mmc_poll_for_busy:[*2]usleep1=8000, usleep2=10000 mmc0 __mmc_poll_for_busy:[*2]usleep1=10000, usleep2=10000 mmc0 __mmc_poll_for_busy:[*2]usleep1=10000, usleep2=10000 CODE:
#define MMC_OP_COND_POLL_STEP_US (2 * 1000) /* 2ms */
if (busy) {
unsigned int sleep_max = min(udelay + MMC_OP_COND_POLL_STEP_US,
period_max_us);
usleep_range(min(udelay, period_max_us), sleep_max);
pr_err("%s %s:[*2]usleep1=%d, usleep2=%d\n",
mmc_hostname(host), __func__,
min(udelay, period_max_us), sleep_max);
udelay = min(udelay + MMC_OP_COND_POLL_STEP_US, period_max_us);
}
-----------------------------------------------------------------------------
File Name | SDHCI Ctrl |FFU Chardev | CID Info |HS400 Ready | d(FFU->CID) CMD1 (s) | Total Init (s) | Wait Part (ms)
-----------------------------------------------------------------------------
001-1112_025609_poweron | 0.490393 | 0.491444 | 1.362249 | 1.365776 | 0.870805 | 0.875383 | 770 |
002-1112_025659_poweron | 0.494135 | 0.495246 | 1.331355 | 1.334950 | 0.836109 | 0.840815 | 738 |
003-1112_025805_poweron | 0.475962 | 0.476544 | 1.349468 | 1.353174 | 0.872924 | 0.877212 | 772 |
004-1112_025852_poweron | 0.502249 | 0.503006 | 0.920649 | 0.924152 | 0.417643 | 0.421903 | 310 |
005-1112_025953_poweron | 0.500047 | 0.500528 | 1.308234 | 1.311497 | 0.807706 | 0.811450 | 712 |
006-1112_030335_poweron | 0.511979 | 0.513092 | 1.320862 | 1.324587 | 0.807770 | 0.812608 | 698 |
007-1112_030438_poweron | 0.505778 | 0.506793 | 1.308963 | 1.311342 | 0.802170 | 0.805564 | 703 |
008-1112_030610_poweron | 0.503976 | 0.504420 | 1.331788 | 1.335489 | 0.827368 | 0.831513 | 725 |
009-1112_030654_poweron | 0.485227 | 0.485993 | 1.292487 | 1.296197 | 0.806494 | 0.810970 | 703 |
010-1112_030737_poweron | 0.504113 | 0.504920 | 1.310241 | 1.314424 | 0.805321 | 0.810311 | 705 |
011-1112_030822_poweron | 0.508555 | 0.509154 | 0.649386 | 0.652987 | 0.140232 | 0.144432 | 40 | ---------------------------------------------------------------------------------
* The table above records the timestamps of the key emmc initialization points.
* d(FFU->CID) CMD1 (s)--- Includes the overall duration of CMD1
* Total Init (s) --- The total duration of the eMMC probe and initialization
(b) Exponential growth with a factor of 2, capped at an 8ms CMD1 wait interval.
==================================================================
[OPTION B] Exponential backoff (x2), cap = 8ms << RECOMMENDED >>
==================================================================
Step print:
mmc0 __mmc_poll_for_busy:usleep1=4000, usleep2=8000
mmc0 __mmc_poll_for_busy:usleep1=8000, usleep2=8000
mmc0 __mmc_poll_for_busy:usleep1=8000, usleep2=8000
CODE:
#define MMC_OP_COND_PERIOD_MAX_US (8 * 1000) /* 8ms */
if (busy) {
unsigned int sleep_max = min(udelay * 2,
period_max_us);
usleep_range(min(udelay, period_max_us), sleep_max);
if (udelay < period_max_us)
udelay = sleep_max;
}
---------------------------------------------------------------------------------
File Name | SDHCI Ctrl |FFU Chardev | CID Info |HS400 Ready | d(FFU->CID) CMD1 (s) | Total Init (s) | Wait Part (ms)
---------------------------------------------------------------------------------
002-1112_025708_poweron | 0.504376 | 0.504713 | 0.633348 | 0.636205 | 0.128635 | 0.131829 | 19 |
003-1112_025752_poweron | 0.501886 | 0.502807 | 0.640128 | 0.643734 | 0.137321 | 0.141848 | 29 |
004-1112_025833_poweron | 0.479628 | 0.480447 | 0.613336 | 0.616808 | 0.132889 | 0.137180 | 17 |
005-1112_030007_poweron | 0.519822 | 0.520575 | 1.317490 | 1.321023 | 0.796915 | 0.801201 | 676 |
006-1112_030049_poweron | 0.505749 | 0.506661 | 1.307391 | 1.311126 | 0.800730 | 0.805377 | 689 |
007-1112_030131_poweron | 0.508087 | 0.508486 | 1.349139 | 1.352838 | 0.840653 | 0.844751 | 746 |
008-1112_030214_poweron | 0.481862 | 0.482442 | 1.317015 | 1.320525 | 0.834573 | 0.838663 | 734 |
009-1112_030254_poweron | 0.500581 | 0.501060 | 1.331095 | 1.334623 | 0.830035 | 0.834042 | 735 |
010-1112_030334_poweron | 0.483933 | 0.484527 | 1.281619 | 1.285141 | 0.797092 | 0.801208 | 702 |
011-1112_030427_poweron | 0.503995 | 0.504426 | 1.332000 | 1.335899 | 0.827574 | 0.831904 | 724 |
012-1112_030623_poweron | 0.511335 | 0.511907 | 1.313210 | 1.316951 | 0.801303 | 0.805616 | 696 |
013-1112_030704_poweron | 0.513948 | 0.514431 | 1.316726 | 1.320453 | 0.802295 | 0.806505 | 696 |
014-1112_030745_poweron | 0.502228 | 0.503244 | 1.303244 | 1.306927 | 0.800000 | 0.804699 | 699 | ---------------------------------------------------------------------------------
* The table above records the timestamps of the key emmc initialization points.
* d(FFU->CID) CMD1 (s)--- Includes the overall duration of CMD1
* Total Init (s) --- The total duration of the eMMC probe and initialization
[Conclusion]
Based on the experimental data (the overall duration of CMD1 and initialization), the backoff strategy with an 8ms cap (OPTION B) yields better results, making it the more suitable approach.
[Final Diff]
The changes for the exponential backoff (x2, max=8ms) are listed below:
drivers/mmc/core/block.c +4 -2
@@ -654,7 +654,8 @@ .card = card, }; - err =__mmc_poll_for_busy (card->host,0 , busy_timeout_ms, + err =__mmc_poll_for_busy (card->host,0 ,MMC_BUSY_POLL_MAX_PERIOD_US , + busy_timeout_ms, &mmc_blk_busy_cb, &cb_data); idata->ic.response[0 ] = cb_data.status;
@@ -2048,7 +2049,8 @@ cb_data.card = card; cb_data.status =0 ; - err =__mmc_poll_for_busy (card->host,0 ,MMC_BLK_TIMEOUT_MS , + err =__mmc_poll_for_busy (card->host,0 ,MMC_BUSY_POLL_MAX_PERIOD_US , +MMC_BLK_TIMEOUT_MS , &mmc_blk_busy_cb, &cb_data);/*
drivers/mmc/core/mmc.c +2 -1
@@ -2007,7 +2007,8 @@ goto out_release; } - err =__mmc_poll_for_busy (host,0 , timeout_ms, &mmc_sleep_busy_cb, host); + err =__mmc_poll_for_busy (host,0 ,MMC_BUSY_POLL_MAX_PERIOD_US , + timeout_ms, &mmc_sleep_busy_cb, host); out_release:mmc_retune_release (host);
drivers/mmc/core/mmc_ops.c +12 -6
@@ -22,6 +22,7 @@#define MMC_BKOPS_TIMEOUT_MS (120 * 1000)/* 120s */ #define MMC_SANITIZE_TIMEOUT_MS (240 * 1000)/* 240s */ #define MMC_OP_COND_PERIOD_US (4 * 1000)/* 4ms */ +#define MMC_OP_COND_PERIOD_MAX_US (8 * 1000)/* 8ms */ #define MMC_OP_COND_TIMEOUT_MS 1000/* 1s */ static const u8 tuning_blk_pattern_4bit[] = {
@@ -243,6 +244,7 @@ cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R3 |MMC_CMD_BCR ; err =__mmc_poll_for_busy (host,MMC_OP_COND_PERIOD_US , +MMC_OP_COND_PERIOD_MAX_US ,MMC_OP_COND_TIMEOUT_MS , &__mmc_send_op_cond_cb, &cb_data);if (err)
@@ -508,13 +510,13 @@ }int __mmc_poll_for_busy (struct mmc_host *host,unsigned int period_us, -unsigned int timeout_ms, +unsigned int period_max_us,unsigned int timeout_ms,int (*busy_cb)(void *cb_data,bool *busy),void *cb_data) {int err;unsigned long timeout; -unsigned int udelay = period_us ? period_us :32 , udelay_max =32768 ; +unsigned int udelay = period_us ? period_us :32 ;bool expired = false;bool busy = false;
@@ -539,9 +541,12 @@/* Throttle the polling rate to avoid hogging the CPU. */ if (busy) { -usleep_range (udelay, udelay *2 ); -if (udelay < udelay_max) - udelay *=2 ; +unsigned int sleep_max =min (udelay *2 , + period_max_us); + +usleep_range (min (udelay, period_max_us), sleep_max); +if (udelay < period_max_us) + udelay = sleep_max; } }while (busy);
@@ -559,7 +564,8 @@ cb_data.retry_crc_err = retry_crc_err; cb_data.busy_cmd = busy_cmd; -return __mmc_poll_for_busy (host,0 , timeout_ms, &mmc_busy_cb, &cb_data); +return __mmc_poll_for_busy (host,0 ,MMC_BUSY_POLL_MAX_PERIOD_US , + timeout_ms, &mmc_busy_cb, &cb_data); }EXPORT_SYMBOL_GPL (mmc_poll_for_busy);
drivers/mmc/core/mmc_ops.h +4 -0
@@ -10,6 +10,9 @@#include <linux/types.h> +/* Default upper bound of the throttled busy polling period. */ +#define MMC_BUSY_POLL_MAX_PERIOD_US 32768/* ~32ms */ +enum mmc_busy_cmd {MMC_BUSY_CMD6 ,MMC_BUSY_ERASE ,
@@ -42,6 +45,7 @@bool mmc_prepare_busy_cmd (struct mmc_host *host,struct mmc_command *cmd,unsigned int timeout_ms);int __mmc_poll_for_busy (struct mmc_host *host,unsigned int period_us, +unsigned int period_max_us,unsigned int timeout_ms,int (*busy_cb)(void *cb_data,bool *busy),void *cb_data);
drivers/mmc/core/sd.c +2 -1
@@ -1705,7 +1705,8 @@ cb_data.card = card; cb_data.reg_buf = reg_buf; - err =__mmc_poll_for_busy (card->host,0 ,SD_POWEROFF_NOTIFY_TIMEOUT_MS , + err =__mmc_poll_for_busy (card->host,0 ,MMC_BUSY_POLL_MAX_PERIOD_US , +SD_POWEROFF_NOTIFY_TIMEOUT_MS , &sd_busy_poweroff_notify_cb, &cb_data); out:
drivers/mmc/core/sd_ops.c +1 -0
@@ -187,6 +187,7 @@ cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R3 |MMC_CMD_BCR ; err =__mmc_poll_for_busy (host,SD_APP_OP_COND_PERIOD_US , +MMC_BUSY_POLL_MAX_PERIOD_US ,SD_APP_OP_COND_TIMEOUT_MS , &sd_app_op_cond_cb, &cb_data);if (err)
drivers/mmc/core/sd_uhs2.c +1 -0
@@ -788,6 +788,7 @@sd_uhs2_cmd_assemble (&cmd, &uhs2_cmd,0 ,0 ); err =__mmc_poll_for_busy (host,UHS2_WAIT_CFG_COMPLETE_PERIOD_US , +MMC_BUSY_POLL_MAX_PERIOD_US ,UHS2_WAIT_CFG_COMPLETE_TIMEOUT_MS , &sd_uhs2_wait_active_state_cb, &cb_data);if (err) {
Best regards,
Xiaojie.Li
--------------------------------------------------------------------------------------邮件原件-----
发件人: Shawn Lin <[email protected]>
发送时间: 2026年9月21日 17:04
收件人: 李晓洁 (Xiaojie Li/13233) <[email protected]>
抄送: [email protected]; Ulf Hansson <[email protected]>; [email protected]; [email protected]; 陈文超 (Wenchao Chen) <[email protected]>; 张如泉 (Rain Zhang) <[email protected]>; 唐月林 (Yuelin Tang) <[email protected]>; [email protected]; Ulf Hansson <[email protected]> 主题: Re: [PATCH v2] mmc: core: Optimize polling delay in __mmc_poll_for_busy()
注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 4 lines · On 2026/09/21 Mon 16:31, 李晓洁 (Xiaojie Li/13233) wrote:
Quoted 3 lines
I think the CMD1-specific branch can be avoided altogether. The reason CMD1's tail latency is high is that
__mmc_poll_for_busy()limits udelay to a maximum of 32768 and, more importantly, the sleep upper bound is udelay * 2.Would it be possible to parameterize the maximum delay instead? E.g.
Quoted 8 lines
Quoted 1 line
int __mmc_poll_for_busy(host,
period_us,udelay_max_us,
timeout_ms, cb,cb_data)Hi shawn,
The__mmc_poll_for_busyfunction is invoked, either directly or indirectly, in numerous locations throughout the codebase. That's why I used if (busy_cb==__mmc_send_op_cond_cb) to check for the special CMD1 handling.
As mentioned in my previous email, passing it directly as a function parameter would require modifying quite a few places. The call sites identified so far are listed below:
On the "quite a few places" concern: it is smaller than it looks. Of the call sites you listed, 9 go through the mmc_poll_for_busy() wrapper (__mmc_switch, mmc_send_hpi_cmd, mmc_blk_fix_state, sd_flush_cache, sd_enable_cache, sd_poweroff_notify, mmc_cqe_recovery, mmc_do_erase), so they do not change at all - the wrapper keeps passing the current default. Only the ~6 direct callers of __mmc_poll_for_busy() need a one-line mechanical change (mmc_ops.c CMD1 and the wrapper itself, block.c x2, sd.c, mmc.c).
Also note that the hardcoded 32768 is itself a policy choice that only suits the long-running commands (CMD6, erase, ...). The OP_COND style polling wants a different maximum - CMD1 as you measured, and ACMD41 in sd_ops.c starts at 10ms and has the same tail-latency issue - so making it an explicit parameter is exactly the point. The core helper should not know which caller it is serving, which is what the busy_cb pointer comparison effectively does.
Quoted 35 lines
(1)mmc_ops.c
(1.1) 238 err = __mmc_poll_for_busy(host,MMC_OP_COND_PERIOD_US, inmmc_send_op_cond()
(1.2)555 return__mmc_poll_for_busy(host, 0, timeout_ms, &mmc_busy_cb, &cb_data); inmmc_poll_for_busy()
(1.3)641 err =mmc_poll_for_busy(card, timeout_ms, retry_crc_err, MMC_BUSY_CMD6); in__mmc_switch()
(1.4)889 returnmmc_poll_for_busy(card, busy_timeout_ms, false, MMC_BUSY_HPI); inmmc_send_hpi_cmd()
(2)block.c
(2.1)649 err = __mmc_poll_for_busy(card->host, 0,busy_timeout_ms, in__mmc_blk_ioctl_cmd()
(2.2)err = __mmc_poll_for_busy(card->host, 0,MMC_BLK_TIMEOUT_MS, inmmc_blk_card_busy()
(2.3)1746 err =mmc_poll_for_busy(card, timeout, false, MMC_BUSY_IO); inmmc_blk_fix_state()
(3)sd.c
(3.1)1711 err = __mmc_poll_for_busy(card->host, 0,SD_POWEROFF_NOTIFY_TIMEOUT_MS, insd_poweroff_notify()(3.2)1358 err = mmc_poll_for_busy(card,SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, insd_flush_cache()(3.3)1404 err = mmc_poll_for_busy(card,SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, insd_enable_cache()(3.4)1704 err = mmc_poll_for_busy(card,SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, insd_poweroff_notify()(4)mmc.c
(4.1)2011 err =__mmc_poll_for_busy(host, 0, timeout_ms, &mmc_sleep_busy_cb, host); inmmc_sleep()
(5)core.c
(5.1)556mmc_poll_for_busy(host->card, MMC_CQE_RECOVERY_TIMEOUT, true, MMC_BUSY_IO); inmmc_cqe_recovery()
(5.2)1701 err =mmc_poll_for_busy(card, busy_timeout, false, MMC_BUSY_ERASE); inmmc_do_erase()
Quoted 7 lines
Quoted 5 lines
and limit both the backoff step and the sleep upper bound to
udelay_max_us:unsigned int sleep_max = min(udelay * 2, udelay_max_us); usleep_range(min(udelay, udelay_max_us), sleep_max);I'm not entirely sure about your suggested changes here. Could you provide more detailed modifications?
1) extend the prototype in mmc_ops.h:
int __mmc_poll_for_busy(struct mmc_host *host, unsigned int period_us,
unsigned int udelay_max_us, unsigned int timeout_ms,
int (*busy_cb)(void *cb_data, bool *busy),
void *cb_data);2) in __mmc_poll_for_busy(), only the throttling changes:
- unsigned int udelay = period_us ? period_us : 32, udelay_max =
32768;
+ unsigned int udelay = period_us ? period_us : 32;
...
/* Throttle the polling rate to avoid hogging the CPU. */
if (busy) {- usleep_range(udelay, udelay * 2);
- if (udelay < udelay_max)
- udelay *= 2;
+ unsigned int sleep_max = min(udelay * 2,udelay_max_us);
+
+ usleep_range(min(udelay, udelay_max_us), sleep_max);
+ if (udelay < udelay_max_us)
+ udelay *= 2;
}3) add the new value next to the existing ones in mmc_ops.c:
#define MMC_OP_COND_MAX_DELAY_US (8 * 1000) /* 8ms, justify with
data */
4) in mmc_send_op_cond():
err = __mmc_poll_for_busy(host, MMC_OP_COND_PERIOD_US,
+ MMC_OP_COND_MAX_DELAY_US,
MMC_OP_COND_TIMEOUT_MS,
&__mmc_send_op_cond_cb, &cb_data);5) every other caller passes the current default, e.g. the wrapper in mmc_ops.c:
- return __mmc_poll_for_busy(host, 0, timeout_ms, &__mmc_busy_cb,&cb_data);
+ return __mmc_poll_for_busy(host, 0, 32768, timeout_ms,
+ &__mmc_busy_cb, &cb_data);
and the same one-line change for the direct callers in block.c (__mmc_blk_ioctl_cmd(), mmc_blk_card_busy()), sd.c
(sd_poweroff_notify()) and mmc.c (mmc_sleep()). With period_us = 4ms and udelay_max_us = 8ms, the sleeps become 4-8ms, then 8ms, 8ms, ... so the tail bound is 8ms instead of today's 32-64ms, and no caller behaviour changes except CMD1.
Quoted 7 lines
Quoted 6 lines
Then
mmc_send_op_cond()passes its own maximum delay (8ms), while all other callers keep passing 32768 so their behaviour is unchanged. That is two lines of code, nobusy_cbpointer comparison, and the tail bound
(8ms) is actually tighter than the linear +2ms schedule (10ms).
Quoted 8 lines
Quoted 1 line
Could you try to see if the linear step is still needed once the sleep upper bound is limited to the maximum delay?
Do you mean that I should verify this by changing the original:
usleep_range(udelay, udelay * 2);
if (udelay <udelay_max)
udelay *= 2;
to:usleep_range(min(udelay, udelay_max_us), sleep_max);?
no, the backoff step stays doubling. What Imeant is: first try this bounded version for CMD1 (8ms maximum) and compare it against your linear +2ms schedule on the same slow cards. If the boot-time results are the same, the linear step is unnecessary and the change stays simple and generic.
Quoted 130 lines
Best regards,
Xiaojie.Li
-----邮件原件-----
发件人: Shawn Lin <[email protected]>
发送时间: 2026年9月21日 15:53
收件人: 李晓洁 (Xiaojie Li/13233) <[email protected]>
抄送: [email protected]; Ulf Hansson <[email protected]>; [email protected]; [email protected]; 陈文超 (Wenchao Chen) <[email protected]>; 张如泉 (Rain Zhang) <[email protected]>; 唐月林 (Yuelin Tang) <[email protected]>; [email protected]; Ulf Hansson <[email protected]> 主题: Re: [PATCH v2] mmc: core: Optimize polling delay in__mmc_poll_for_busy()注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.drivers/mmc/core/mmc_ops.c
Quoted 14 lines · On 2026/09/20 Sun 13:40, 李晓洁 (Xiaojie Li/13233) wrote:
Quoted 3 lines
No, that's the whole point. We don't want open coded polling loops, it's just a nightmare to maintain. Please try to extend the existing
__mmc_poll_for_busy()instead.Hi Uffe,
Following your suggestion to extend
__mmc_poll_for_busy()instead of using open-coded polling loops, here is the proposed optimization.In our actual testing, we found that setting
udelay_max= 8000 (8ms) is more time-efficient thanudelay_max= 10000 (10ms). For CMD1 (SEND_OP_COND), the polling intervals are 4ms, 6ms, and 8ms, capped at a maximum of 8ms.
Attached are the recorded per-boot phase latencies for udelay_max=8000 (8ms) and udelay_max=10000 (10ms), with timestamps in seconds. Please let me know if you cannot open the attachment, and I will resend it.drivers/mmc/core/mmc_ops.c +0
-0I think the CMD1-specific branch can be avoided altogether. The reason CMD1's tail latency is high is that
__mmc_poll_for_busy()limits udelay to a maximum of 32768 and, more importantly, the sleep upper bound is udelay * 2.Would it be possible to parameterize the maximum delay instead? E.g.
int __mmc_poll_for_busy(host,
period_us,udelay_max_us,timeout_ms, cb,cb_data)and limit both the backoff step and the sleep upper bound to
udelay_max_us:unsigned int sleep_max = min(udelay * 2, udelay_max_us); usleep_range(min(udelay, udelay_max_us), sleep_max);Then
mmc_send_op_cond()passes its own maximum delay (8ms), while all other callers keep passing 32768 so their behaviour is unchanged. That is two lines of code, nobusy_cbpointer comparison, and the tail bound
(8ms) is actually tighter than the linear +2ms schedule (10ms).Could you try to see if the linear step is still needed once the sleep upper bound is limited to the maximum delay?
Quoted 70 lines
index a952cc8..9c4762c 100644
drivers/mmc/core/mmc_ops.c +17
-3@@ -539,9 +539,23 @@/* Throttle the polling rate to avoid hogging the CPU. */ if (busy) { -usleep_range (udelay, udelay *2 ); -if (udelay < udelay_max) - udelay *=2 ; +/* +* Special delay handling is required for mmc_send_op_cond; +* otherwise, for slower memory particles, the time required to +* wait for the status change will increase. +*/ +if (busy_cb == __mmc_send_op_cond_cb) { + udelay_max =8000 ; +usleep_range (udelay, udelay +2000 ); +if (udelay < udelay_max) + udelay +=2000 ; +else + udelay = udelay_max; + }else { +usleep_range (udelay, udelay *2 ); +if (udelay < udelay_max) + udelay *=2 ; + } } }while (busy);Best regards,
Xiaojie.Li-----邮件原件-----
发件人: Ulf Hansson <[email protected]>
发送时间: 2026年9月11日 23:47
收件人: 李晓洁 (Xiaojie Li/13233) <[email protected]>
抄送: Ulf Hansson <[email protected]>; [email protected]; [email protected]; 陈文超 (Wenchao Chen) <[email protected]>; 张如泉 (Rain Zhang) <[email protected]>; 唐月林 (Yuelin Tang) <[email protected]>; [email protected] 主题: Re: [PATCH] mmc: core: Modify the CMD1 transmission interval注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 8 lines · On Fri, Sep 11, 2026 at 4:45 AM 李晓洁 (Xiaojie Li/13233)…
Hi Uffe:
Thank you for your reply.
However, I noticed that__mmc_poll_for_busy()andmmc_poll_for_busy()are invoked either directly or indirectly by many other functions within the MMC driver.
Modifying them directly could potentially introduce unintended side effects.Would it be acceptable to implement a dedicated function specifically for CMD1? We could create a CMD1-specific variant based on the existing
__mmc_poll_for_busy().
This approach would significantly minimize the potential impact on the rest of the codebase.No, that's the whole point. We don't want open coded polling loops, it's just a nightmare to maintain. Please try to extend the existing
__mmc_poll_for_busy()instead.And next time, please don't top post.
[...]
Kind regards
Uffe