kernel: Option to not use tls to get current thread
Add a Kconfig option to tell whether or not using thread local storage to store current thread. The function using it can be called from ISR and using TLS variables in this context may (should ???) not be allowed Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
1247f8465c
commit
8679c58644
3 changed files with 18 additions and 3 deletions
|
|
@ -596,7 +596,8 @@ __syscall k_tid_t k_sched_current_thread_query(void);
|
|||
__attribute_const__
|
||||
static inline k_tid_t k_current_get(void)
|
||||
{
|
||||
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
||||
#ifdef CONFIG_CURRENT_THREAD_USE_TLS
|
||||
|
||||
/* Thread-local cache of current thread ID, set in z_thread_entry() */
|
||||
extern __thread k_tid_t z_tls_current;
|
||||
|
||||
|
|
|
|||
|
|
@ -288,6 +288,20 @@ config ERRNO_IN_TLS
|
|||
Use thread local storage to store errno instead of storing it in
|
||||
the kernel thread struct. This avoids a syscall if userspace is enabled.
|
||||
|
||||
config CURRENT_THREAD_USE_NO_TLS
|
||||
bool
|
||||
help
|
||||
Hidden symbol to not use thread local storage to store current
|
||||
thread.
|
||||
|
||||
config CURRENT_THREAD_USE_TLS
|
||||
bool "Store current thread in thread local storage (TLS)"
|
||||
depends on THREAD_LOCAL_STORAGE && !CURRENT_THREAD_USE_NO_TLS
|
||||
default y
|
||||
help
|
||||
Use thread local storage to store the current thread. This avoids a
|
||||
syscall if userspace is enabled.
|
||||
|
||||
choice SCHED_ALGORITHM
|
||||
prompt "Scheduler priority queue algorithm"
|
||||
default SCHED_DUMB
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
||||
#ifdef CONFIG_CURRENT_THREAD_USE_TLS
|
||||
#include <zephyr/random/random.h>
|
||||
|
||||
__thread k_tid_t z_tls_current;
|
||||
|
|
@ -35,7 +35,7 @@ extern __thread volatile uintptr_t __stack_chk_guard;
|
|||
FUNC_NORETURN void z_thread_entry(k_thread_entry_t entry,
|
||||
void *p1, void *p2, void *p3)
|
||||
{
|
||||
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
||||
#ifdef CONFIG_CURRENT_THREAD_USE_TLS
|
||||
z_tls_current = k_sched_current_thread_query();
|
||||
#endif
|
||||
#ifdef CONFIG_STACK_CANARIES_TLS
|
||||
|
|
|
|||
Loading…
Reference in a new issue