]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
lib: time: hook uthread_schedule() into udelay()
authorJerome Forissier <jerome.forissier@linaro.org>
Fri, 18 Apr 2025 14:09:37 +0000 (16:09 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 23 Apr 2025 19:19:44 +0000 (13:19 -0600)
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>
lib/time.c

index d88edafb1962d70653dff76e18b4c52f8aba07f1..0e9b079f9cf46fb363d1c2c0bab535cf4b723bc1 100644 (file)
@@ -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);
 }