summaryrefslogtreecommitdiff
path: root/lib/time.c
diff options
context:
space:
mode:
authorJerome Forissier <jerome.forissier@linaro.org>2025-04-18 16:09:37 +0200
committerTom Rini <trini@konsulko.com>2025-04-23 13:19:44 -0600
commit2325621fff219ee3b80641f714545f8b33013c0c (patch)
treeac412db17bc7a6e4bf1d823cd8e384d5b7bf812e /lib/time.c
parente831370af5102d8059d4f20d3317e2c39565e9af (diff)
lib: time: hook uthread_schedule() into udelay()
Introduce a uthread scheduling loop into udelay() when CONFIG_UTHREAD is enabled. This means that any uthread calling into udelay() may yield to uthread and be scheduled again later. There is no delay in the scheduling loop because tests have shown that such a delay can have a detrimental effect on the console (input drops characters). Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'lib/time.c')
-rw-r--r--lib/time.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/time.c b/lib/time.c
index d88edafb196..0e9b079f9cf 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -17,6 +17,7 @@
#include <asm/global_data.h>
#include <asm/io.h>
#include <linux/delay.h>
+#include <uthread.h>
#ifndef CFG_WD_PERIOD
# define CFG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default */
@@ -197,7 +198,13 @@ void udelay(unsigned long usec)
do {
schedule();
kv = usec > CFG_WD_PERIOD ? CFG_WD_PERIOD : usec;
- __udelay(kv);
+ if (CONFIG_IS_ENABLED(UTHREAD)) {
+ ulong t0 = timer_get_us();
+ while (timer_get_us() - t0 < kv)
+ uthread_schedule();
+ } else {
+ __udelay(kv);
+ }
usec -= kv;
} while(usec);
}