From ed240f27968beffdf7e9d68f2a17db6272c29357 Mon Sep 17 00:00:00 2001 From: Benjamin Walsh Date: Sun, 22 Jan 2017 13:05:08 -0500 Subject: [PATCH] kernel/arch: streamline thread user options The K_ flags/options avaialble to users were hidden in the kernel private header files: move them to include/kernel.h to publicize them. Also, to avoid any future confusion, rename the k_thread.execution_flags field to user_options. Change-Id: I65a6fd5e9e78d4ccf783f3304b607a1e6956aeac Signed-off-by: Benjamin Walsh --- arch/x86/core/float.c | 10 +++---- arch/x86/core/swap.S | 8 ++--- arch/x86/include/kernel_arch_data.h | 11 +------ include/kernel.h | 29 +++++++++++++++++++ kernel/include/kernel_offsets.h | 2 +- kernel/include/kernel_structs.h | 17 ++--------- kernel/include/offsets_short.h | 4 +-- kernel/init.c | 4 +-- kernel/thread.c | 8 ++--- subsys/shell/modules/kernel_service.c | 4 +-- .../microkernel/src/object_monitor.c | 8 ++--- .../nanokernel/src/object_monitor.c | 8 ++--- 12 files changed, 61 insertions(+), 52 deletions(-) diff --git a/arch/x86/core/float.c b/arch/x86/core/float.c index 13039d991dd..b03d9604689 100644 --- a/arch/x86/core/float.c +++ b/arch/x86/core/float.c @@ -60,7 +60,7 @@ extern uint32_t _sse_mxcsr_default_value; static void _FpCtxSave(struct tcs *tcs) { #ifdef CONFIG_SSE - if (tcs->base.execution_flags & K_SSE_REGS) { + if (tcs->base.user_options & K_SSE_REGS) { _do_fp_and_sse_regs_save(&tcs->arch.preempFloatReg); return; } @@ -78,7 +78,7 @@ static inline void _FpCtxInit(struct tcs *tcs) { _do_fp_regs_init(); #ifdef CONFIG_SSE - if (tcs->base.execution_flags & K_SSE_REGS) { + if (tcs->base.user_options & K_SSE_REGS) { _do_sse_regs_init(); } #endif @@ -104,7 +104,7 @@ void k_float_enable(struct tcs *tcs, unsigned int options) /* Indicate thread requires floating point context saving */ - tcs->base.execution_flags |= (uint8_t)options; + tcs->base.user_options |= (uint8_t)options; /* * The current thread might not allow FP instructions, so clear CR0[TS] @@ -148,7 +148,7 @@ void k_float_enable(struct tcs *tcs, unsigned int options) * of the FPU to them (unless we need it ourselves). */ - if ((_current->base.execution_flags & _FP_USER_MASK) == 0) { + if ((_current->base.user_options & _FP_USER_MASK) == 0) { /* * We are not FP-capable, so mark FPU as owned by the * thread we've just enabled FP support for, then @@ -202,7 +202,7 @@ void k_float_disable(struct tcs *tcs) /* Disable all floating point capabilities for the thread */ - tcs->base.execution_flags &= ~_FP_USER_MASK; + tcs->base.user_options &= ~_FP_USER_MASK; if (tcs == _current) { _FpAccessDisable(); diff --git a/arch/x86/core/swap.S b/arch/x86/core/swap.S index 98f2d61a678..8286c8c736b 100644 --- a/arch/x86/core/swap.S +++ b/arch/x86/core/swap.S @@ -151,7 +151,7 @@ SECTION_FUNC(TEXT, _Swap) * _and_ whether the thread was context switched out preemptively. */ - testb $_FP_USER_MASK, _thread_offset_to_execution_flags(%eax) + testb $_FP_USER_MASK, _thread_offset_to_user_options(%eax) je restoreContext_NoFloatSwap @@ -192,7 +192,7 @@ SECTION_FUNC(TEXT, _Swap) #ifdef CONFIG_SSE - testb $K_SSE_REGS, _thread_offset_to_execution_flags(%ebx) + testb $K_SSE_REGS, _thread_offset_to_user_options(%ebx) je x87FloatSave /* @@ -231,7 +231,7 @@ restoreContext_NoFloatSave: je restoreContext_NoFloatRestore #ifdef CONFIG_SSE - testb $K_SSE_REGS, _thread_offset_to_execution_flags(%eax) + testb $K_SSE_REGS, _thread_offset_to_user_options(%eax) je x87FloatRestore fxrstor _thread_offset_to_preempFloatReg(%eax) @@ -266,7 +266,7 @@ restoreContext_NoFloatSwap: * registers */ - testb $_FP_USER_MASK, _thread_offset_to_execution_flags(%eax) + testb $_FP_USER_MASK, _thread_offset_to_user_options(%eax) jne CROHandlingDone /* diff --git a/arch/x86/include/kernel_arch_data.h b/arch/x86/include/kernel_arch_data.h index 36888448ee9..98fff9063d3 100644 --- a/arch/x86/include/kernel_arch_data.h +++ b/arch/x86/include/kernel_arch_data.h @@ -42,7 +42,7 @@ #define STACK_ALIGN_SIZE 4 -/* x86 Bitmask definitions for struct k_thread->thread_state */ +/* x86 Bitmask definitions for struct k_thread.thread_state */ /* executing context is interrupt handler */ #define _INT_ACTIVE (1 << 7) @@ -54,15 +54,6 @@ /* end - states */ -/* x86 Bitmask definitions for struct k_thread->execution_flags */ - -#if defined(CONFIG_FP_SHARING) && defined(CONFIG_SSE) -/* thread uses SSEx (and also FP) registers */ -#define K_SSE_REGS (1 << 7) -#endif - -/* end - execution flags */ - #if defined(CONFIG_FP_SHARING) && defined(CONFIG_SSE) #define _FP_USER_MASK (K_FP_REGS | K_SSE_REGS) #elif defined(CONFIG_FP_SHARING) diff --git a/include/kernel.h b/include/kernel.h index 59c57a82642..0f969820b80 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -173,6 +173,35 @@ extern void k_call_stacks_analyze(void); */ typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3); +#endif /* !_ASMLANGUAGE */ + + +/* + * Thread user options. May be needed by assembly code. Common part uses low + * bits, arch-specific use high bits. + */ + +/* system thread that must not abort */ +#define K_ESSENTIAL (1 << 0) + +#if defined(CONFIG_FP_SHARING) +/* thread uses floating point registers */ +#define K_FP_REGS (1 << 1) +#endif + +#ifdef CONFIG_X86 +/* x86 Bitmask definitions for threads user options */ + +#if defined(CONFIG_FP_SHARING) && defined(CONFIG_SSE) +/* thread uses SSEx (and also FP) registers */ +#define K_SSE_REGS (1 << 7) +#endif +#endif + +/* end - thread options */ + +#if !defined(_ASMLANGUAGE) + /** * @brief Spawn a thread. * diff --git a/kernel/include/kernel_offsets.h b/kernel/include/kernel_offsets.h index 18651d0545c..7513aa64dfd 100644 --- a/kernel/include/kernel_offsets.h +++ b/kernel/include/kernel_offsets.h @@ -38,7 +38,7 @@ GEN_OFFSET_SYM(_kernel_t, current_fp); GEN_ABSOLUTE_SYM(_STRUCT_KERNEL_SIZE, sizeof(struct _kernel)); -GEN_OFFSET_SYM(_thread_base_t, execution_flags); +GEN_OFFSET_SYM(_thread_base_t, user_options); GEN_OFFSET_SYM(_thread_base_t, thread_state); GEN_OFFSET_SYM(_thread_base_t, prio); GEN_OFFSET_SYM(_thread_base_t, sched_locked); diff --git a/kernel/include/kernel_structs.h b/kernel/include/kernel_structs.h index e391af09eb8..174bac84565 100644 --- a/kernel/include/kernel_structs.h +++ b/kernel/include/kernel_structs.h @@ -15,7 +15,7 @@ #endif /* - * bitmask definitions for the execution_flags and state + * Bitmask definitions for the struct k_thread.thread_state field. * * Must be before kerneL_arch_data.h because it might need them to be already * defined. @@ -42,17 +42,6 @@ /* end - states */ -/* execution flags: common uses low bits, arch-specific use high bits */ - -/* system thread that must not abort */ -#define K_ESSENTIAL (1 << 0) - -#if defined(CONFIG_FP_SHARING) -/* thread uses floating point registers */ -#define K_FP_REGS (1 << 1) -#endif -/* end - execution flags */ - /* lowest value of _thread_base.preempt at which a thread is non-preemptible */ #define _NON_PREEMPT_THRESHOLD 0x0080 @@ -78,8 +67,8 @@ struct _thread_base { /* this thread's entry in a ready/wait queue */ sys_dnode_t k_q_node; - /* execution flags */ - uint8_t execution_flags; + /* user facing 'thread options'; values defined in include/kernel.h */ + uint8_t user_options; /* thread state */ uint8_t thread_state; diff --git a/kernel/include/offsets_short.h b/kernel/include/offsets_short.h index 38716fff66b..ac73d154750 100644 --- a/kernel/include/offsets_short.h +++ b/kernel/include/offsets_short.h @@ -46,8 +46,8 @@ #define _thread_offset_to_thread_state \ (___thread_t_base_OFFSET + ___thread_base_t_thread_state_OFFSET) -#define _thread_offset_to_execution_flags \ - (___thread_t_base_OFFSET + ___thread_base_t_execution_flags_OFFSET) +#define _thread_offset_to_user_options \ + (___thread_t_base_OFFSET + ___thread_base_t_user_options_OFFSET) #define _thread_offset_to_prio \ (___thread_t_base_OFFSET + ___thread_base_t_prio_OFFSET) diff --git a/kernel/init.c b/kernel/init.c index 58f2c899200..49763c4566a 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -216,7 +216,7 @@ static void _main(void *unused1, void *unused2, void *unused3) main(); /* Terminate thread normally since it has no more work to do */ - _main_thread->base.execution_flags &= ~K_ESSENTIAL; + _main_thread->base.user_options &= ~K_ESSENTIAL; } void __weak main(void) @@ -251,7 +251,7 @@ static void prepare_multithreading(struct k_thread *dummy_thread) _current = dummy_thread; - dummy_thread->base.execution_flags = K_ESSENTIAL; + dummy_thread->base.user_options = K_ESSENTIAL; #endif /* _kernel.ready_q is all zeroes */ diff --git a/kernel/thread.c b/kernel/thread.c index a40b44902f4..d70820291f3 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -77,7 +77,7 @@ int k_is_in_isr(void) */ void _thread_essential_set(void) { - _current->base.execution_flags |= K_ESSENTIAL; + _current->base.user_options |= K_ESSENTIAL; } /* @@ -87,7 +87,7 @@ void _thread_essential_set(void) */ void _thread_essential_clear(void) { - _current->base.execution_flags &= ~K_ESSENTIAL; + _current->base.user_options &= ~K_ESSENTIAL; } /* @@ -97,7 +97,7 @@ void _thread_essential_clear(void) */ int _is_thread_essential(void) { - return _current->base.execution_flags & K_ESSENTIAL; + return _current->base.user_options & K_ESSENTIAL; } void k_busy_wait(uint32_t usec_to_wait) @@ -430,7 +430,7 @@ void _init_thread_base(struct _thread_base *thread_base, int priority, { /* k_q_node is initialized upon first insertion in a list */ - thread_base->execution_flags = (uint8_t)options; + thread_base->user_options = (uint8_t)options; thread_base->thread_state = (uint8_t)initial_state; thread_base->prio = priority; diff --git a/subsys/shell/modules/kernel_service.c b/subsys/shell/modules/kernel_service.c index 9685146751d..b9ac4145e1b 100644 --- a/subsys/shell/modules/kernel_service.c +++ b/subsys/shell/modules/kernel_service.c @@ -56,10 +56,10 @@ static int shell_cmd_tasks(int argc, char *argv[]) thread_list = (struct k_thread *)SYS_THREAD_MONITOR_HEAD; while (thread_list != NULL) { - printk("%s%p: flags: 0x%x priority: %d\n", + printk("%s%p: options: 0x%x priority: %d\n", (thread_list == k_current_get()) ? "*" : " ", thread_list, - thread_list->base.execution_flags, + thread_list->base.user_options, k_thread_priority_get(thread_list)); thread_list = (struct k_thread *)SYS_THREAD_MONITOR_NEXT(thread_list); } diff --git a/tests/legacy/kernel/test_obj_tracing/microkernel/src/object_monitor.c b/tests/legacy/kernel/test_obj_tracing/microkernel/src/object_monitor.c index 0fa4ed51040..5529138d418 100644 --- a/tests/legacy/kernel/test_obj_tracing/microkernel/src/object_monitor.c +++ b/tests/legacy/kernel/test_obj_tracing/microkernel/src/object_monitor.c @@ -54,14 +54,14 @@ static inline int test_thread_monitor(void) thread_list = (struct k_thread *)SYS_THREAD_MONITOR_HEAD; while (thread_list != NULL) { if (thread_list->base.prio == -1) { - TC_PRINT("TASK: %p FLAGS: 0x%02x, STATE: 0x%02x\n", + TC_PRINT("TASK: %p OPTIONS: 0x%02x, STATE: 0x%02x\n", thread_list, - thread_list->base.execution_flags, + thread_list->base.user_options, thread_list->base.thread_state); } else { - TC_PRINT("FIBER: %p FLAGS: 0x%02x, STATE: 0x%02x\n", + TC_PRINT("FIBER: %p OPTIONS: 0x%02x, STATE: 0x%02x\n", thread_list, - thread_list->base.execution_flags, + thread_list->base.user_options, thread_list->base.thread_state); } thread_list = diff --git a/tests/legacy/kernel/test_obj_tracing/nanokernel/src/object_monitor.c b/tests/legacy/kernel/test_obj_tracing/nanokernel/src/object_monitor.c index 901b0798ac5..562d2c8df2e 100644 --- a/tests/legacy/kernel/test_obj_tracing/nanokernel/src/object_monitor.c +++ b/tests/legacy/kernel/test_obj_tracing/nanokernel/src/object_monitor.c @@ -54,14 +54,14 @@ static inline int test_thread_monitor(void) thread_list = (struct k_thread *)SYS_THREAD_MONITOR_HEAD; while (thread_list != NULL) { if (thread_list->base.prio == -1) { - TC_PRINT("TASK: %p FLAGS: 0x%02x, STATE: 0x%02x\n", + TC_PRINT("TASK: %p OPTIONS: 0x%02x, STATE: 0x%02x\n", thread_list, - thread_list->base.execution_flags, + thread_list->base.user_options, thread_list->base.thread_state); } else { - TC_PRINT("FIBER: %p FLAGS: 0x%02x, STATE: 0x%02x\n", + TC_PRINT("FIBER: %p OPTIONS: 0x%02x, STATE: 0x%02x\n", thread_list, - thread_list->base.execution_flags, + thread_list->base.user_options, thread_list->base.thread_state); } thread_list =