From 5c8adefc6766dfe6f68b04cb6f733bf5ecdb9501 Mon Sep 17 00:00:00 2001 From: Windrow14 Date: Mon, 19 Aug 2024 16:26:53 +0800 Subject: [PATCH] drivers/mmcsd/Kconfig|mmcsd_sdio.c: check ready without sleep If per tick is set to 10ms, it will cause nxsig_usleep(1000) in the sdio driver to sleep for 19ms, which is much longer than the expected 1ms, resulting in very low write performance. Add option to reduce CPU hogging by using sched_yield(), though it may also affect write performance when the CPU is busy. Signed-off-by: Yinzhe Wu Reviewed-by: Yuezhang Mo Reviewed-by: Jacky Cao Tested-by: Yinzhe Wu --- drivers/mmcsd/Kconfig | 13 +++++++++++++ drivers/mmcsd/mmcsd_sdio.c | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/mmcsd/Kconfig b/drivers/mmcsd/Kconfig index 8a663eb113..7ace74ea7e 100644 --- a/drivers/mmcsd/Kconfig +++ b/drivers/mmcsd/Kconfig @@ -177,6 +177,19 @@ config MMCSD_BLOCK_WDATADELAY Some hardware needs to configure this delay to write one data block, because the hardware needs more time for wear leveling and bad block management. +config MMCSD_CHECK_READY_STATUS_WITHOUT_SLEEP + bool "No sleep in ready-check function." + default n + ---help--- + Since nxsig_usleep returns at the tick after the next tick, when + CONFIG_USEC_PER_TICK is big, the real sleep time is much more than + desired in mmcsd_transferready(). As a result, write speed is + affected seriously. + + When this configuration is enabled, the sleep in mmcsd_transferready + will be skipped. However, CPU will be hogged by the process during + this period of writing time. + endif endif # MMCSD diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index 3ee7eb2680..debb7d9c12 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -1251,7 +1251,13 @@ static int mmcsd_transferready(FAR struct mmcsd_state_s *priv) /* Do not hog the CPU */ +#ifdef CONFIG_MMCSD_CHECK_READY_STATUS_WITHOUT_SLEEP + /* Use sched_yield when tick is big to avoid low writing speed */ + + sched_yield(); +#else nxsig_usleep(1000); +#endif /* We are still in the programming state. Calculate the elapsed * time... we can't stay in this loop forever!