[PATCH v3 2/4] slice: reschedule bthreads doing File I/O in command context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux