diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/bthread.h | 53 | ||||
-rw-r--r-- | include/glob.h | 6 | ||||
-rw-r--r-- | include/poller.h | 2 | ||||
-rw-r--r-- | include/printk.h | 2 | ||||
-rw-r--r-- | include/sched.h | 15 | ||||
-rw-r--r-- | include/slice.h | 17 | ||||
-rw-r--r-- | include/zero_page.h | 2 |
7 files changed, 86 insertions, 11 deletions
diff --git a/include/bthread.h b/include/bthread.h new file mode 100644 index 0000000000..e3871fb115 --- /dev/null +++ b/include/bthread.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2021 Ahmad Fatoum, Pengutronix + */ + +#ifndef __BTHREAD_H_ +#define __BTHREAD_H_ + +#include <linux/stddef.h> + +struct bthread; + +extern struct bthread *current; + +struct bthread *bthread_create(int (*threadfn)(void *), void *data, const char *namefmt, ...); +void bthread_free(struct bthread *bthread); + +void bthread_schedule(struct bthread *); +void bthread_wake(struct bthread *bthread); +void bthread_suspend(struct bthread *bthread); +int bthread_should_stop(void); +int bthread_stop(struct bthread *bthread); +void bthread_info(void); +const char *bthread_name(struct bthread *bthread); +bool bthread_is_main(struct bthread *bthread); + +/** + * bthread_run - create and wake a thread. + * @threadfn: the function to run for coming reschedule cycles + * @data: data ptr for @threadfn. + * @namefmt: printf-style name for the thread. + * + * Description: Convenient wrapper for bthread_create() followed by + * bthread_wakeup(). Returns the bthread or NULL + */ +#define bthread_run(threadfn, data, namefmt, ...) \ +({ \ + struct bthread *__b \ + = bthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ + if (__b) \ + bthread_wake(__b); \ + __b; \ +}) + +#ifdef CONFIG_BTHREAD +void bthread_reschedule(void); +#else +static inline void bthread_reschedule(void) +{ +} +#endif + +#endif diff --git a/include/glob.h b/include/glob.h index 5f532e6652..ec0ac66f87 100644 --- a/include/glob.h +++ b/include/glob.h @@ -177,6 +177,7 @@ extern int glob __P ((__const char *__restrict __pattern, int __flags, int (*__errfunc) (__const char *, int), glob_t *__restrict __pglob)); +extern void globfree __P ((glob_t *__pglob)); #else static inline int glob __P ((__const char *__restrict __pattern, int __flags, int (*__errfunc) (__const char *, int), @@ -184,9 +185,12 @@ static inline int glob __P ((__const char *__restrict __pattern, int __flags, { return GLOB_ABORTED; } + +static inline void globfree __P ((glob_t *__pglob)) +{ +} #endif /* Free storage allocated in PGLOB by a previous `glob' call. */ -extern void globfree __P ((glob_t *__pglob)); #else extern int glob __P ((__const char *__restrict __pattern, int __flags, int (*__errfunc) (__const char *, int), diff --git a/include/poller.h b/include/poller.h index db773265b2..371dafc6f8 100644 --- a/include/poller.h +++ b/include/poller.h @@ -39,6 +39,8 @@ static inline bool poller_async_active(struct poller_async *pa) return pa->active; } +extern int poller_active; + #ifdef CONFIG_POLLER void poller_call(void); #else diff --git a/include/printk.h b/include/printk.h index f92e477298..94a25ec9eb 100644 --- a/include/printk.h +++ b/include/printk.h @@ -160,7 +160,7 @@ extern void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii); -#if LOGLEVEL <= MSG_DEBUG +#if LOGLEVEL >= MSG_DEBUG #define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ diff --git a/include/sched.h b/include/sched.h new file mode 100644 index 0000000000..57be1678fd --- /dev/null +++ b/include/sched.h @@ -0,0 +1,15 @@ +/* SPDX License Identifier: GPL-2.0 */ +#ifndef __BAREBOX_SCHED_H_ +#define __BAREBOX_SCHED_H_ + +#include <bthread.h> +#include <poller.h> + +static inline void resched(void) +{ + poller_call(); + if (!IS_ENABLED(CONFIG_POLLER) || !poller_active) + bthread_reschedule(); +} + +#endif diff --git a/include/slice.h b/include/slice.h index b2d65b80cd..cf684300a8 100644 --- a/include/slice.h +++ b/include/slice.h @@ -1,6 +1,8 @@ #ifndef __SLICE_H #define __SLICE_H +#include <bthread.h> + enum slice_action { SLICE_ACQUIRE = 1, SLICE_RELEASE = -1, @@ -35,12 +37,11 @@ void command_slice_release(void); extern int poller_active; -#ifdef CONFIG_POLLER -#define assert_command_context() ({ \ - WARN_ONCE(poller_active, "%s called in poller\n", __func__); \ -}) -#else -#define assert_command_context() do { } while (0) -#endif +#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__); \ +} while (0) -#endif /* __SLICE_H */ +#endif diff --git a/include/zero_page.h b/include/zero_page.h index ad6861f240..519e65be76 100644 --- a/include/zero_page.h +++ b/include/zero_page.h @@ -4,7 +4,7 @@ #include <common.h> -#if defined CONFIG_ARCH_HAS_ZERO_PAGE +#if defined CONFIG_ARCH_HAS_ZERO_PAGE && defined CONFIG_MMU /* * zero_page_faulting - fault when accessing the zero page |