U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jerome Forissier <jerome.forissier@linaro.org>
To: u-boot@lists.denx.de
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jerome Forissier <jerome.forissier@linaro.org>
Subject: [PATCH v2 00/14] Uthreads
Date: Tue, 25 Feb 2025 17:34:26 +0100	[thread overview]
Message-ID: <cover.1740499185.git.jerome.forissier@linaro.org> (raw)

This series introduces threads and uses them to improve the performance
of the USB bus scanning code and to implement background jobs in the
shell via two new commands: 'spawn' and 'wait'.

The threading framework is called 'uthread' and is inspired from the
barebox threads [1]. setjmp() and longjmp() are used to save and
restore contexts, as well as a non-standard extension called initjmp().
This new function is added in several patches, one for each
architecture that supports HAVE_SETJMP. A new symbol is defined:
HAVE_INITJMP. Two tests, one for initjmp() and one for the uthread
scheduling, are added to the lib suite. NOTE: the SANDBOX version of
initjmp() appears to have problems and needs to be worked on.

[1] https://github.com/barebox/barebox/blob/master/common/bthread.c

After introducing threads and making schedule() and udelay() a thread
re-scheduling point, the USB stack initialization is modified to benefit
from concurrency when UTHREAD is enabled, where uthreads are used in
usb_init() to initialize and scan multiple busses at the same time.
The code was tested on arm64 and arm QEMU with 4 simulated XHCI buses
and some devices. On this platform the USB scan takes 2.2 s instead of
5.6 s. Tested on i.MX93 EVK with two USB hubs, one ethernet adapter and
one webcam on each, "usb start" takes 2.4 s instead of 4.6 s.

Finally, the spawn and wait commands are introduced, allowing the use of
threads from the shell. Tested on the i.MX93 EVK with a spinning HDD
connected to USB1 and the network connected to ENET1. The USB plus DHCP
init sequence "spawn usb start; spawn dhcp; wait" takes 4.5 seconds
instead of 8 seconds for "usb start; dhcp".

Changes in v2:
- Rewrite the cover letter, do not mention the older coroutines series
- Rebased onto next
- UTHREAD_STACK_SIZE is set to 32768 (32 KiB) instead of 32178
- Remove uthread_free_all() and let threads be freed as they terminate
by uthread_schedule()
- Add function descriptions
- Add documentation (doc/develop/uthread.rst)
- Explain initjmp() in the description of "arch: introduce symbol
HAVE_INITJMP".
- Add thread groups (uthread_grp_new_id() and uthread_grp_done())
- Add the spawn and wait commands

Jerome Forissier (14):
  arch: introduce symbol HAVE_INITJMP
  arm: add initjmp()
  riscv: add initjmp()
  sandbox: add initjmp()
  test: lib: add initjmp() test
  uthread: add cooperative multi-tasking interface
  cyclic: invoke uthread_schedule() from schedule()
  lib: time: hook uthread_schedule() into udelay()
  doc: develop: add documentation for uthreads
  test: lib: add uthread test
  dm: usb: move bus initialization into new static function
    usb_init_bus()
  dm: usb: initialize and scan multiple buses simultaneously with
    uthread
  cmd: add spawn and wait commands
  test: dm: add test for spawn and wait commands

 arch/Kconfig                      |   8 ++
 arch/arm/include/asm/setjmp.h     |   1 +
 arch/arm/lib/setjmp.S             |  11 ++
 arch/arm/lib/setjmp_aarch64.S     |   9 ++
 arch/riscv/include/asm/setjmp.h   |   1 +
 arch/riscv/lib/setjmp.S           |  10 ++
 arch/sandbox/cpu/Makefile         |  11 +-
 arch/sandbox/cpu/initjmp.c        | 172 +++++++++++++++++++++++++++++
 arch/sandbox/include/asm/setjmp.h |   5 +
 cmd/Kconfig                       |  17 +++
 cmd/Makefile                      |   2 +
 cmd/spawn.c                       | 176 +++++++++++++++++++++++++++++
 common/console.c                  |   2 +
 common/cyclic.c                   |   3 +
 doc/develop/index.rst             |   1 +
 doc/develop/uthread.rst           | 136 +++++++++++++++++++++++
 drivers/usb/host/usb-uclass.c     | 168 +++++++++++++++++++---------
 include/u-boot/schedule.h         |   3 +
 include/uthread.h                 |  44 ++++++++
 lib/Kconfig                       |  21 ++++
 lib/Makefile                      |   2 +
 lib/time.c                        |  10 +-
 lib/uthread.c                     | 178 ++++++++++++++++++++++++++++++
 test/boot/bootdev.c               |  14 +--
 test/boot/bootflow.c              |   2 +-
 test/cmd/Makefile                 |   1 +
 test/cmd/spawn.c                  |  33 ++++++
 test/lib/Makefile                 |   2 +
 test/lib/initjmp.c                |  72 ++++++++++++
 test/lib/uthread.c                |  68 ++++++++++++
 30 files changed, 1122 insertions(+), 61 deletions(-)
 create mode 100644 arch/sandbox/cpu/initjmp.c
 create mode 100644 cmd/spawn.c
 create mode 100644 doc/develop/uthread.rst
 create mode 100644 include/uthread.h
 create mode 100644 lib/uthread.c
 create mode 100644 test/cmd/spawn.c
 create mode 100644 test/lib/initjmp.c
 create mode 100644 test/lib/uthread.c

-- 
2.43.0


             reply	other threads:[~2025-02-25 16:35 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25 16:34 Jerome Forissier [this message]
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
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=cover.1740499185.git.jerome.forissier@linaro.org \
    --to=jerome.forissier@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox