From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v4 6/8] Documentation: devel: background-execution: update bthread docs
Date: Tue, 22 Jun 2021 10:26:15 +0200 [thread overview]
Message-ID: <20210622082617.18011-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210622082617.18011-1-a.fatoum@pengutronix.de>
Using bthreads throughout means we'll need finer grained locking across
the code base, which is too big a commitment for now. Previous commit
limited bthread_reschedule to only happen in command context, like
how it is for workqueues. Adjust the docs appropriately.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Documentation/devel/background-execution.rst | 34 +++++++-------------
1 file changed, 11 insertions(+), 23 deletions(-)
diff --git a/Documentation/devel/background-execution.rst b/Documentation/devel/background-execution.rst
index fa4d23e6d271..d379593efb23 100644
--- a/Documentation/devel/background-execution.rst
+++ b/Documentation/devel/background-execution.rst
@@ -10,9 +10,9 @@ Pollers
-------
Pollers are a way in barebox to frequently execute code in the background.
-barebox is single-threaded, so a poller is not executed as a separate thread,
-but instead pollers are executed whenever ``is_timeout()`` is called. This has
-a few implications. First of all, pollers are not executed when
+They don't run within their own threads, but instead they are executed
+whenever ``is_timeout()`` is called.
+This has a few implications. First of all, pollers are not executed when
``is_timeout()`` is not called. For this and other reasons, loops polling for
hardware events should always use a timeout, which is best implemented with
``is_timeout()``. Another thing to remember is that pollers can be executed
@@ -74,31 +74,19 @@ code. Usually a work item is allocated by the poller and then freed either in
bthreads
--------
-barebox threads are co-operative green threads, which are scheduled whenever
-``is_timeout()`` is called. This has a few implications. First of all,
-bthreads are not scheduled when ``is_timeout()`` is not called.
-For this and other reasons, loops polling for hardware events should always
-use a timeout, which is best implemented with ``is_timeout()``.
-Another thing to remember is that bthreads can be scheduled anywhere
-in the middle of other device accesses whenever ``is_timeout()`` is
-called. Care must be taken that a green thread doesn't access the very same device
-again itself. See "slices" below on how devices can safely be accessed from
-bthreads.
+barebox threads are co-operative green threads, which are scheduled for the
+same context as workqueues: Before the shell executes the next command.
+This means that bthreads can be used to implement workqueues, but not pollers.
The bthread interface is declared in ``include/bthread.h``.
``bthread_create()`` is used to allocate a bthread control block along with
its stack. ``bthread_wake()`` can be used to add it into the run queue.
From this moment on and until the thread terminates, the thread will be
-switched to regularly as long as someone calls ``is_timeout()``.
-bthreads are allowed to call ``is_timeout()``, which will arrange for
-other threads to execute.
-
-barebox threads are planned to replace previous infrastructure, pollers
-and workqueues. Poller like behavior can be easily achieved by looping
-and yielding on every iteration. There's ``bthread_should_stop()``, which
-can be used as condition for continuing the loop. Workqueues could be
-replaced along the same line, but with mutexes protecting underlying device
-access.
+switched to regularly as long as the shell processes commands.
+
+bthreads are allowed to call ``is_timeout()``, which will eventually
+arrange for other threads to execute. This allowed implementing a Linux-like
+completion API on top, which can be useful for porting threaded kernel code.
Slices
------
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-06-22 8:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 8:26 [PATCH v4 0/8] usbgadget: add support for USB mass storage gadget Ahmad Fatoum
2021-06-22 8:26 ` [PATCH v4 1/8] input: virtio: poll from poller, not bthread Ahmad Fatoum
2021-06-22 8:26 ` [PATCH v4 2/8] bthread: add debug print for scheduler context switches Ahmad Fatoum
2021-06-22 8:26 ` [PATCH v4 3/8] common: move workqueue handling from poller_call() to sched() Ahmad Fatoum
2021-06-22 8:26 ` [PATCH v4 4/8] common: bthread: schedule only in command context Ahmad Fatoum
2021-06-22 9:08 ` Ahmad Fatoum
2021-06-22 8:26 ` [PATCH v4 5/8] bthread: implement basic Linux-like completion API Ahmad Fatoum
2021-06-22 8:26 ` Ahmad Fatoum [this message]
2021-06-22 8:26 ` [PATCH v4 7/8] usbgadget: refactor usbgadget_register to accept array Ahmad Fatoum
2021-06-22 8:26 ` [PATCH v4 8/8] usbgadget: add support for USB mass storage gadget Ahmad Fatoum
2021-06-25 7:34 ` [PATCH v4 0/8] " Sascha Hauer
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=20210622082617.18011-7-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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