All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <ziyao@disroot.org>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jerome Forissier <jerome.forissier@linaro.org>
Cc: u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>,
	Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH v2 08/14] lib: time: hook uthread_schedule() into udelay()
Date: Fri, 28 Feb 2025 14:16:38 +0000	[thread overview]
Message-ID: <Z8HFRuCH8TQWC7Pw@pie> (raw)
In-Reply-To: <CAC_iWjLtTzCAqR_aq6Q1kBEn=E3oQoCDuvxWAnfrT6R=KCgSeQ@mail.gmail.com>

On Fri, Feb 28, 2025 at 03:38:22PM +0200, Ilias Apalodimas wrote:
> Hi Jerome,
> 
> On Tue, 25 Feb 2025 at 18:35, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
> >
> > 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.
> >
> > While not strictly necessary since uthread_schedule() is already called
> > by schedule(),
> > tests show that it is desirable to call it in a tight
> > loop instead of calling __usleep(). It gives more opportunities for
> > other threads to make progress and results in better performances.
> 
> Some examples of timing gains would be nice.
> 
> >
> > Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> > ---
> >  lib/time.c | 10 +++++++++-
> >  1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/time.c b/lib/time.c
> > index d88edafb196..d1a1a66f301 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,14 @@ 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)
> 
> Do we make progress by constantly scheduling new tasks? Perhaps we
> should at least leave the task running for some time?

If I get the point, the UTHREAD is a cooperative framework, which means
a task yields the control flow only when it considers nothing else could
be done. And there's no preemption (at least in this revision). Thus I
don't think it's a problem.

> Thanks
> /Ilias

Best regards,
Yao Zi

> > +                               uthread_schedule();
> > +               } else {
> > +                       __udelay(kv);
> > +               }
> >                 usec -= kv;
> >         } while(usec);
> > +
> >  }
> > --
> > 2.43.0
> >

  reply	other threads:[~2025-02-28 14:16 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25 16:34 [PATCH v2 00/14] Uthreads Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 01/14] arch: introduce symbol HAVE_INITJMP Jerome Forissier
2025-02-28 12:01   ` Ilias Apalodimas
2025-02-28 12:38   ` Heinrich Schuchardt
2025-02-28 12:57     ` Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 02/14] arm: add initjmp() Jerome Forissier
2025-02-28 12:01   ` Ilias Apalodimas
2025-02-28 13:05   ` Heinrich Schuchardt
2025-02-28 13:21     ` Jerome Forissier
2025-02-28 13:28       ` Heinrich Schuchardt
2025-02-28 14:16         ` Jerome Forissier
2025-02-28 17:54           ` Tom Rini
2025-02-25 16:34 ` [PATCH v2 03/14] riscv: " Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 04/14] sandbox: " Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 05/14] test: lib: add initjmp() test Jerome Forissier
2025-02-28 12:38   ` Ilias Apalodimas
2025-02-28 13:04   ` Heinrich Schuchardt
2025-02-28 13:09     ` Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 06/14] uthread: add cooperative multi-tasking interface Jerome Forissier
2025-02-28 13:09   ` Ilias Apalodimas
2025-02-28 14:30     ` Jerome Forissier
2025-02-28 13:21   ` Heinrich Schuchardt
2025-02-28 14:39     ` Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 07/14] cyclic: invoke uthread_schedule() from schedule() Jerome Forissier
2025-02-27 12:30   ` Stefan Roese
2025-02-27 17:05     ` Jerome Forissier
2025-02-28 15:43       ` Stefan Roese
2025-02-28 13:22   ` Ilias Apalodimas
2025-02-25 16:34 ` [PATCH v2 08/14] lib: time: hook uthread_schedule() into udelay() Jerome Forissier
2025-02-28 13:38   ` Ilias Apalodimas
2025-02-28 14:16     ` Yao Zi [this message]
2025-02-28 14:45       ` Jerome Forissier
2025-02-28 18:16       ` Ilias Apalodimas
2025-02-25 16:34 ` [PATCH v2 09/14] doc: develop: add documentation for uthreads Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 10/14] test: lib: add uthread test Jerome Forissier
2025-02-28 13:26   ` Ilias Apalodimas
2025-02-25 16:34 ` [PATCH v2 11/14] dm: usb: move bus initialization into new static function usb_init_bus() Jerome Forissier
2025-02-28 13:27   ` Ilias Apalodimas
2025-02-25 16:34 ` [PATCH v2 12/14] dm: usb: initialize and scan multiple buses simultaneously with uthread Jerome Forissier
2025-02-27 16:25   ` Simon Glass
2025-02-27 17:30     ` Jerome Forissier
2025-03-04 13:13       ` Simon Glass
2025-02-25 16:34 ` [PATCH v2 13/14] cmd: add spawn and wait commands Jerome Forissier
2025-02-25 16:34 ` [PATCH v2 14/14] test: dm: add test for " Jerome Forissier
2025-02-27 16:25   ` Simon Glass
2025-02-27 17:12     ` Jerome Forissier
2025-03-04 13:14       ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z8HFRuCH8TQWC7Pw@pie \
    --to=ziyao@disroot.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jerome.forissier@linaro.org \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.