Skip to content

Commit 8679c58

Browse files
Flavio Ceolincarlescufi
authored andcommitted
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>
1 parent 1247f84 commit 8679c58

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

include/zephyr/kernel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ __syscall k_tid_t k_sched_current_thread_query(void);
596596
__attribute_const__
597597
static inline k_tid_t k_current_get(void)
598598
{
599-
#ifdef CONFIG_THREAD_LOCAL_STORAGE
599+
#ifdef CONFIG_CURRENT_THREAD_USE_TLS
600+
600601
/* Thread-local cache of current thread ID, set in z_thread_entry() */
601602
extern __thread k_tid_t z_tls_current;
602603

kernel/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,20 @@ config ERRNO_IN_TLS
288288
Use thread local storage to store errno instead of storing it in
289289
the kernel thread struct. This avoids a syscall if userspace is enabled.
290290

291+
config CURRENT_THREAD_USE_NO_TLS
292+
bool
293+
help
294+
Hidden symbol to not use thread local storage to store current
295+
thread.
296+
297+
config CURRENT_THREAD_USE_TLS
298+
bool "Store current thread in thread local storage (TLS)"
299+
depends on THREAD_LOCAL_STORAGE && !CURRENT_THREAD_USE_NO_TLS
300+
default y
301+
help
302+
Use thread local storage to store the current thread. This avoids a
303+
syscall if userspace is enabled.
304+
291305
choice SCHED_ALGORITHM
292306
prompt "Scheduler priority queue algorithm"
293307
default SCHED_DUMB

lib/os/thread_entry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
#include <zephyr/kernel.h>
15-
#ifdef CONFIG_THREAD_LOCAL_STORAGE
15+
#ifdef CONFIG_CURRENT_THREAD_USE_TLS
1616
#include <zephyr/random/random.h>
1717

1818
__thread k_tid_t z_tls_current;
@@ -35,7 +35,7 @@ extern __thread volatile uintptr_t __stack_chk_guard;
3535
FUNC_NORETURN void z_thread_entry(k_thread_entry_t entry,
3636
void *p1, void *p2, void *p3)
3737
{
38-
#ifdef CONFIG_THREAD_LOCAL_STORAGE
38+
#ifdef CONFIG_CURRENT_THREAD_USE_TLS
3939
z_tls_current = k_sched_current_thread_query();
4040
#endif
4141
#ifdef CONFIG_STACK_CANARIES_TLS

0 commit comments

Comments
 (0)