mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 2/4] slice: reschedule bthreads doing File I/O in command context
Date: Fri, 30 Apr 2021 15:40:59 +0200	[thread overview]
Message-ID: <20210430134101.20580-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210430134101.20580-1-a.fatoum@pengutronix.de>

Currently, without locks, it's unsafe to do file I/O outside of
the main thread, be it in pollers or secondary bthreads.

Pollers side step this issue by deferring file I/O to workqueues
that run in command context: the time when the shell is waiting
for input.

For bthreads, we can do something similar without involving
workqueues: We just suspend threads until they are scheduled in
command context.

This is not a full solution: Not everything that should
assert_command_context() does so, so you still can't do absolutely
everything in a secondary bthread. To get there, we will need
to distribute locks across the code base, but that's a patchset
for another time.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/slice.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/slice.h b/include/slice.h
index cf684300a809..abe819163d32 100644
--- a/include/slice.h
+++ b/include/slice.h
@@ -40,8 +40,10 @@ extern int poller_active;
 #define assert_command_context() do { \
 	WARN_ONCE(IS_ENABLED(CONFIG_POLLER) && poller_active, \
 		  "%s called in poller\n", __func__); \
-	WARN_ONCE(IS_ENABLED(CONFIG_BTHREAD) && !bthread_is_main(current), \
-		  "%s called in secondary bthread\n", __func__); \
+	if (IS_ENABLED(CONFIG_BTHREAD) && !bthread_is_main(current)) { \
+		while (slice_acquired(&command_slice)) \
+			bthread_reschedule(); \
+	} \
 } while (0)
 
 #endif
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-04-30 13:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30 13:40 [PATCH v2 0/4] usbgadget: add support for USB mass storage gadget Ahmad Fatoum
2021-04-30 13:40 ` [PATCH v2 1/4] bthread: implement basic Linux-like completion API Ahmad Fatoum
2021-04-30 13:40 ` Ahmad Fatoum [this message]
2021-04-30 13:41 ` [PATCH v2 3/4] usbgadget: refactor usbgadget_register to accept array Ahmad Fatoum
2021-04-30 13:41 ` [PATCH v2 4/4] usbgadget: add support for USB mass storage gadget Ahmad Fatoum

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=20210430134101.20580-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH v2 2/4] slice: reschedule bthreads doing File I/O in command context' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox