diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-06-22 10:26:12 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-25 09:30:33 +0200 |
commit | 6ed59a76a0d1250059b8cdd61e0c3cf0f25b5a69 (patch) | |
tree | 248965d7519753bb0e23105a277166416e569398 /common | |
parent | f866f471337e3249e0946764f09841baf73d6c9d (diff) | |
download | barebox-6ed59a76a0d1250059b8cdd61e0c3cf0f25b5a69.tar.gz barebox-6ed59a76a0d1250059b8cdd61e0c3cf0f25b5a69.tar.xz |
common: move workqueue handling from poller_call() to sched()
Workqueues are run out of poller_call, not because of a dependency, but
because when they were added, poller_call was directly called from
is_timeout.
With the addition of bthreads, there is now a general resched() function
that runs pollers and switches between bthreads. It makes sense to move
workqueue handling there as well to keep scheduling matter contained in
a single function. Do so.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20210622082617.18011-4-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 5 | ||||
-rw-r--r-- | common/Makefile | 1 | ||||
-rw-r--r-- | common/poller.c | 23 | ||||
-rw-r--r-- | common/sched.c | 26 |
4 files changed, 40 insertions, 15 deletions
diff --git a/common/Kconfig b/common/Kconfig index 8b8f80bbb3..77fdf6d1c6 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -997,11 +997,16 @@ config BAREBOXCRC32_TARGET 'bareboxcrc32' is a userspacetool to generate the crc32 checksums the same way barebox does. Say yes here to build it for the target. +config HAS_SCHED + bool + config POLLER bool "generic polling infrastructure" + select HAS_SCHED config BTHREAD bool "barebox co-operative (green) thread infrastructure" + select HAS_SCHED depends on HAS_ARCH_SJLJ help barebox threads are lightweight cooperative (green) threads that are diff --git a/common/Makefile b/common/Makefile index 382a4f661f..16582534ec 100644 --- a/common/Makefile +++ b/common/Makefile @@ -50,6 +50,7 @@ extra-$(CONFIG_MODULES) += module.lds obj-$(CONFIG_OFTREE) += oftree.o obj-$(CONFIG_PARTITION_DISK) += partitions.o partitions/ obj-$(CONFIG_PASSWORD) += password.o +obj-$(CONFIG_HAS_SCHED) += sched.o obj-$(CONFIG_POLLER) += poller.o obj-$(CONFIG_BTHREAD) += bthread.o obj-$(CONFIG_RESET_SOURCE) += reset_source.o diff --git a/common/poller.c b/common/poller.c index 61da5698d2..0409d3cf81 100644 --- a/common/poller.c +++ b/common/poller.c @@ -10,11 +10,14 @@ #include <param.h> #include <poller.h> #include <clock.h> -#include <work.h> -#include <slice.h> static LIST_HEAD(poller_list); -int poller_active; +static int __poller_active; + +bool poller_active(void) +{ + return __poller_active; +} int poller_register(struct poller_struct *poller, const char *name) { @@ -110,23 +113,13 @@ int poller_async_unregister(struct poller_async *pa) void poller_call(void) { struct poller_struct *poller, *tmp; - bool run_workqueues = !slice_acquired(&command_slice); - - if (poller_active) - return; - - command_slice_acquire(); - - if (run_workqueues) - wq_do_all_works(); - poller_active = 1; + __poller_active = 1; list_for_each_entry_safe(poller, tmp, &poller_list, list) poller->func(poller); - command_slice_release(); - poller_active = 0; + __poller_active = 0; } #if defined CONFIG_CMD_POLLER diff --git a/common/sched.c b/common/sched.c new file mode 100644 index 0000000000..dcf6522ac0 --- /dev/null +++ b/common/sched.c @@ -0,0 +1,26 @@ +/* SPDX License Identifier: GPL-2.0 */ + +#include <bthread.h> +#include <poller.h> +#include <work.h> +#include <slice.h> +#include <sched.h> + +void resched(void) +{ + bool run_workqueues = !slice_acquired(&command_slice); + + if (poller_active()) + return; + + command_slice_acquire(); + + if (run_workqueues) + wq_do_all_works(); + + poller_call(); + + command_slice_release(); + + bthread_reschedule(); +} |