summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-06-22 10:26:13 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-25 09:30:53 +0200
commita921a60f4d6f4df5637c835f1d5492f6c77e0a56 (patch)
tree9e330e66cd73ea518a9544b8a24917b6d924b15f /common
parent6ed59a76a0d1250059b8cdd61e0c3cf0f25b5a69 (diff)
downloadbarebox-a921a60f4d6f4df5637c835f1d5492f6c77e0a56.tar.gz
barebox-a921a60f4d6f4df5637c835f1d5492f6c77e0a56.tar.xz
common: bthread: schedule only in command context
Originally, I envisioned bthreads as replacement for pollers and workqueues. But even without preemption, having functions you call possibly accessing structures you are iterating over can corrupt memory. This problem exists with pollers as well, but because of their limited scope, it's harder to shoot your foot with them, as you don't keep implicit state between poller activations unlike bthreads, which maintain their stack across context switches. Limit bthread scope instead to be a replacement for workqueues. This still allows us to port some classes of state-machine-in-kthread kernel code, while avoding the aforementioned pitfalls. Cc: Jan Luebbe <j.luebbe@pengutronix.de> Cc: Sascha Hauer <s.hauer@pengutronix.de> Cc: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210622082617.18011-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/sched.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/common/sched.c b/common/sched.c
index dcf6522ac0..02582b2c5e 100644
--- a/common/sched.c
+++ b/common/sched.c
@@ -15,12 +15,12 @@ void resched(void)
command_slice_acquire();
- if (run_workqueues)
+ if (run_workqueues) {
wq_do_all_works();
+ bthread_reschedule();
+ }
poller_call();
command_slice_release();
-
- bthread_reschedule();
}