kernel/arch: streamline thread user options

The K_<thread option> 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 <walsh.benj@gmail.com>
This commit is contained in:
Benjamin Walsh 2017-01-22 13:05:08 -05:00 committed by Anas Nashif
commit ed240f2796
12 changed files with 61 additions and 52 deletions

View file

@ -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();

View file

@ -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
/*

View file

@ -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)

View file

@ -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.
*

View file

@ -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);

View file

@ -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;

View file

@ -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)

View file

@ -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 */

View file

@ -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;

View file

@ -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);
}

View file

@ -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 =

View file

@ -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 =