summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/Kconfig5
-rw-r--r--common/Makefile1
-rw-r--r--common/poller.c23
-rw-r--r--common/sched.c26
-rw-r--r--include/poller.h8
-rw-r--r--include/sched.h10
-rw-r--r--include/slice.h6
7 files changed, 52 insertions, 27 deletions
diff --git a/common/Kconfig b/common/Kconfig
index 8b8f80bbb..77fdf6d1c 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 382a4f661..16582534e 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 61da5698d..0409d3cf8 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 000000000..dcf6522ac
--- /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();
+}
diff --git a/include/poller.h b/include/poller.h
index 371dafc6f..6e51a0613 100644
--- a/include/poller.h
+++ b/include/poller.h
@@ -7,6 +7,7 @@
#define POLLER_H
#include <linux/list.h>
+#include <linux/types.h>
struct poller_struct {
void (*func)(struct poller_struct *poller);
@@ -39,11 +40,14 @@ static inline bool poller_async_active(struct poller_async *pa)
return pa->active;
}
-extern int poller_active;
-
#ifdef CONFIG_POLLER
+bool poller_active(void);
void poller_call(void);
#else
+static inline bool poller_active(void)
+{
+ return false;
+}
static inline void poller_call(void)
{
}
diff --git a/include/sched.h b/include/sched.h
index 57be1678f..4dadff206 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -2,14 +2,12 @@
#ifndef __BAREBOX_SCHED_H_
#define __BAREBOX_SCHED_H_
-#include <bthread.h>
-#include <poller.h>
-
+#ifdef CONFIG_HAS_SCHED
+void resched(void);
+#else
static inline void resched(void)
{
- poller_call();
- if (!IS_ENABLED(CONFIG_POLLER) || !poller_active)
- bthread_reschedule();
}
+#endif
#endif
diff --git a/include/slice.h b/include/slice.h
index cf684300a..67d47b908 100644
--- a/include/slice.h
+++ b/include/slice.h
@@ -2,6 +2,7 @@
#define __SLICE_H
#include <bthread.h>
+#include <poller.h>
enum slice_action {
SLICE_ACQUIRE = 1,
@@ -35,11 +36,8 @@ extern struct slice command_slice;
void command_slice_acquire(void);
void command_slice_release(void);
-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(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__); \
} while (0)