kernel: rename main/idle thread/stacks
The main and idle threads, and their associated stacks, were being referenced in various parts of the kernel with no central definition. Expose these in kernel_internal.h and namespace with z_ appropriately. The main and idle threads were being defined statically, with another variable exposed to contain their pointer value. This wastes a bit of memory and isn't accessible to user threads anyway, just expose the actual thread objects. Redundance MAIN_STACK_SIZE and IDLE_STACK_SIZE defines in init.c removed, just use the Kconfigs they derive from. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
e6654103ba
commit
fe031611fd
13 changed files with 52 additions and 72 deletions
|
@ -17,7 +17,7 @@
|
|||
#include <swap_macros.h>
|
||||
|
||||
GDATA(_interrupt_stack)
|
||||
GDATA(_main_stack)
|
||||
GDATA(z_main_stack)
|
||||
GDATA(_VectorTable)
|
||||
|
||||
/* use one of the available interrupt stacks during init */
|
||||
|
@ -154,7 +154,7 @@ _master_core_startup:
|
|||
* FIRQ stack when CONFIG_INIT_STACKS is enabled before switching to
|
||||
* one of them for the rest of the early boot
|
||||
*/
|
||||
mov_s sp, _main_stack
|
||||
mov_s sp, z_main_stack
|
||||
add sp, sp, CONFIG_MAIN_STACK_SIZE
|
||||
|
||||
mov_s r0, _interrupt_stack
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
_ASM_FILE_PROLOGUE
|
||||
|
||||
GDATA(_main_stack)
|
||||
GDATA(z_main_stack)
|
||||
|
||||
SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table)
|
||||
|
||||
|
@ -31,7 +31,7 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table)
|
|||
* on the interrupt stack when CONFIG_INIT_STACKS is enabled before
|
||||
* switching to the interrupt stack for the rest of the early boot
|
||||
*/
|
||||
.word _main_stack + CONFIG_MAIN_STACK_SIZE
|
||||
.word z_main_stack + CONFIG_MAIN_STACK_SIZE
|
||||
|
||||
.word __reset
|
||||
.word __nmi
|
||||
|
|
|
@ -29,7 +29,7 @@ _ASM_FILE_PROLOGUE
|
|||
#if defined(CONFIG_SW_VECTOR_RELAY)
|
||||
|
||||
GDATA(_vector_table_pointer)
|
||||
GDATA(_main_stack)
|
||||
GDATA(z_main_stack)
|
||||
|
||||
SECTION_FUNC(vector_relay_handler, __vector_relay_handler)
|
||||
mrs r0, ipsr;
|
||||
|
@ -52,7 +52,7 @@ SECTION_FUNC(vector_relay_handler, __vector_relay_handler)
|
|||
GTEXT(__vector_relay_handler)
|
||||
|
||||
SECTION_FUNC(vector_relay_table, __vector_relay_table)
|
||||
.word _main_stack + CONFIG_MAIN_STACK_SIZE
|
||||
.word z_main_stack + CONFIG_MAIN_STACK_SIZE
|
||||
|
||||
.word __reset
|
||||
|
||||
|
|
|
@ -300,6 +300,11 @@ extern u32_t z_timestamp_main; /* timestamp when main task starts */
|
|||
extern u32_t z_timestamp_idle; /* timestamp when CPU goes idle */
|
||||
#endif
|
||||
|
||||
extern struct k_thread z_main_thread;
|
||||
extern struct k_thread z_idle_thread;
|
||||
extern K_THREAD_STACK_DEFINE(z_main_stack, CONFIG_MAIN_STACK_SIZE);
|
||||
extern K_THREAD_STACK_DEFINE(z_idle_stack, CONFIG_IDLE_STACK_SIZE);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -71,18 +71,11 @@ u32_t __noinit z_timestamp_idle; /* timestamp when CPU goes idle */
|
|||
#endif
|
||||
|
||||
/* init/main and idle threads */
|
||||
K_THREAD_STACK_DEFINE(z_main_stack, CONFIG_MAIN_STACK_SIZE);
|
||||
K_THREAD_STACK_DEFINE(z_idle_stack, CONFIG_IDLE_STACK_SIZE);
|
||||
|
||||
#define IDLE_STACK_SIZE CONFIG_IDLE_STACK_SIZE
|
||||
#define MAIN_STACK_SIZE CONFIG_MAIN_STACK_SIZE
|
||||
|
||||
K_THREAD_STACK_DEFINE(_main_stack, MAIN_STACK_SIZE);
|
||||
K_THREAD_STACK_DEFINE(_idle_stack, IDLE_STACK_SIZE);
|
||||
|
||||
static struct k_thread _main_thread_s;
|
||||
static struct k_thread _idle_thread_s;
|
||||
|
||||
k_tid_t const _main_thread = (k_tid_t)&_main_thread_s;
|
||||
k_tid_t const _idle_thread = (k_tid_t)&_idle_thread_s;
|
||||
struct k_thread z_main_thread;
|
||||
struct k_thread z_idle_thread;
|
||||
|
||||
/*
|
||||
* storage space for the interrupt stack
|
||||
|
@ -101,21 +94,21 @@ K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);
|
|||
* clean this up in the future.
|
||||
*/
|
||||
#if defined(CONFIG_SMP) && CONFIG_MP_NUM_CPUS > 1
|
||||
K_THREAD_STACK_DEFINE(_idle_stack1, IDLE_STACK_SIZE);
|
||||
K_THREAD_STACK_DEFINE(_idle_stack1, CONFIG_IDLE_STACK_SIZE);
|
||||
static struct k_thread _idle_thread1_s;
|
||||
k_tid_t const _idle_thread1 = (k_tid_t)&_idle_thread1_s;
|
||||
K_THREAD_STACK_DEFINE(_interrupt_stack1, CONFIG_ISR_STACK_SIZE);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SMP) && CONFIG_MP_NUM_CPUS > 2
|
||||
K_THREAD_STACK_DEFINE(_idle_stack2, IDLE_STACK_SIZE);
|
||||
K_THREAD_STACK_DEFINE(_idle_stack2, CONFIG_IDLE_STACK_SIZE);
|
||||
static struct k_thread _idle_thread2_s;
|
||||
k_tid_t const _idle_thread2 = (k_tid_t)&_idle_thread2_s;
|
||||
K_THREAD_STACK_DEFINE(_interrupt_stack2, CONFIG_ISR_STACK_SIZE);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SMP) && CONFIG_MP_NUM_CPUS > 3
|
||||
K_THREAD_STACK_DEFINE(_idle_stack3, IDLE_STACK_SIZE);
|
||||
K_THREAD_STACK_DEFINE(_idle_stack3, CONFIG_IDLE_STACK_SIZE);
|
||||
static struct k_thread _idle_thread3_s;
|
||||
k_tid_t const _idle_thread3 = (k_tid_t)&_idle_thread3_s;
|
||||
K_THREAD_STACK_DEFINE(_interrupt_stack3, CONFIG_ISR_STACK_SIZE);
|
||||
|
@ -291,7 +284,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3)
|
|||
main();
|
||||
|
||||
/* Mark nonessenrial since main() has no more work to do */
|
||||
_main_thread->base.user_options &= ~K_ESSENTIAL;
|
||||
z_main_thread.base.user_options &= ~K_ESSENTIAL;
|
||||
|
||||
/* Dump coverage data once the main() has exited. */
|
||||
gcov_coverage_dump();
|
||||
|
@ -311,7 +304,7 @@ void __weak main(void)
|
|||
static void init_idle_thread(struct k_thread *thr, k_thread_stack_t *stack)
|
||||
{
|
||||
z_setup_new_thread(thr, stack,
|
||||
IDLE_STACK_SIZE, idle, NULL, NULL, NULL,
|
||||
CONFIG_IDLE_STACK_SIZE, idle, NULL, NULL, NULL,
|
||||
K_LOWEST_THREAD_PRIO, K_ESSENTIAL, IDLE_THREAD_NAME);
|
||||
z_mark_thread_as_started(thr);
|
||||
|
||||
|
@ -371,21 +364,21 @@ static void prepare_multithreading(struct k_thread *dummy_thread)
|
|||
* contain garbage, which would prevent the cache loading algorithm
|
||||
* to work as intended
|
||||
*/
|
||||
_kernel.ready_q.cache = _main_thread;
|
||||
_kernel.ready_q.cache = &z_main_thread;
|
||||
#endif
|
||||
|
||||
z_setup_new_thread(_main_thread, _main_stack,
|
||||
MAIN_STACK_SIZE, bg_thread_main,
|
||||
NULL, NULL, NULL,
|
||||
CONFIG_MAIN_THREAD_PRIORITY, K_ESSENTIAL, "main");
|
||||
sys_trace_thread_create(_main_thread);
|
||||
z_setup_new_thread(&z_main_thread, z_main_stack,
|
||||
CONFIG_MAIN_STACK_SIZE, bg_thread_main,
|
||||
NULL, NULL, NULL,
|
||||
CONFIG_MAIN_THREAD_PRIORITY, K_ESSENTIAL, "main");
|
||||
sys_trace_thread_create(&z_main_thread);
|
||||
|
||||
z_mark_thread_as_started(_main_thread);
|
||||
z_ready_thread(_main_thread);
|
||||
z_mark_thread_as_started(&z_main_thread);
|
||||
z_ready_thread(&z_main_thread);
|
||||
|
||||
init_idle_thread(_idle_thread, _idle_stack);
|
||||
_kernel.cpus[0].idle_thread = _idle_thread;
|
||||
sys_trace_thread_create(_idle_thread);
|
||||
init_idle_thread(&z_idle_thread, z_idle_stack);
|
||||
_kernel.cpus[0].idle_thread = &z_idle_thread;
|
||||
sys_trace_thread_create(&z_idle_thread);
|
||||
|
||||
#if defined(CONFIG_SMP) && CONFIG_MP_NUM_CPUS > 1
|
||||
init_idle_thread(_idle_thread1, _idle_stack1);
|
||||
|
@ -418,9 +411,9 @@ static void prepare_multithreading(struct k_thread *dummy_thread)
|
|||
static FUNC_NORETURN void switch_to_main_thread(void)
|
||||
{
|
||||
#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN
|
||||
z_arch_switch_to_main_thread(_main_thread, _main_stack,
|
||||
K_THREAD_STACK_SIZEOF(_main_stack),
|
||||
bg_thread_main);
|
||||
z_arch_switch_to_main_thread(&z_main_thread, z_main_stack,
|
||||
K_THREAD_STACK_SIZEOF(z_main_stack),
|
||||
bg_thread_main);
|
||||
#else
|
||||
/*
|
||||
* Context switch to main task (entry function is _main()): the
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <syscall_handler.h>
|
||||
#include <drivers/timer/system_timer.h>
|
||||
#include <stdbool.h>
|
||||
#include <kernel_internal.h>
|
||||
|
||||
#if defined(CONFIG_SCHED_DUMB)
|
||||
#define _priq_run_add z_priq_dumb_add
|
||||
|
@ -84,9 +85,7 @@ static inline bool is_idle(struct k_thread *thread)
|
|||
#ifdef CONFIG_SMP
|
||||
return thread->base.is_idle;
|
||||
#else
|
||||
extern k_tid_t const _idle_thread;
|
||||
|
||||
return thread == _idle_thread;
|
||||
return thread == &z_idle_thread;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
#include <kernel_structs.h>
|
||||
#include <cmsis_os.h>
|
||||
#include <ksched.h>
|
||||
|
||||
extern const k_tid_t _main_thread;
|
||||
#include <kernel_internal.h>
|
||||
|
||||
/**
|
||||
* @brief Get the RTOS kernel system timer counter
|
||||
|
@ -42,5 +41,5 @@ osStatus osKernelStart(void)
|
|||
*/
|
||||
int32_t osKernelRunning(void)
|
||||
{
|
||||
return z_has_thread_started(_main_thread);
|
||||
return z_has_thread_started(&z_main_thread);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <tracing_cpu_stats.h>
|
||||
#include <sys/printk.h>
|
||||
#include <kernel_internal.h>
|
||||
|
||||
enum cpu_state {
|
||||
CPU_STATE_IDLE,
|
||||
|
@ -21,16 +22,12 @@ static struct cpu_stats stats_hw_tick;
|
|||
static int nested_interrupts;
|
||||
static struct k_thread *current_thread;
|
||||
|
||||
#ifndef CONFIG_SMP
|
||||
extern k_tid_t const _idle_thread;
|
||||
#endif
|
||||
|
||||
static int is_idle_thread(struct k_thread *thread)
|
||||
{
|
||||
#ifdef CONFIG_SMP
|
||||
return thread->base.is_idle;
|
||||
#else
|
||||
return thread == _idle_thread;
|
||||
return thread == &z_idle_thread;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -7,19 +7,15 @@
|
|||
#include <zephyr.h>
|
||||
#include <kernel_structs.h>
|
||||
#include <init.h>
|
||||
#include <kernel_internal.h>
|
||||
#include "ctf_top.h"
|
||||
|
||||
|
||||
#ifndef CONFIG_SMP
|
||||
extern k_tid_t const _idle_thread;
|
||||
#endif
|
||||
|
||||
static inline int is_idle_thread(struct k_thread *thread)
|
||||
{
|
||||
#ifdef CONFIG_SMP
|
||||
return thread->base.is_idle;
|
||||
#else
|
||||
return thread == _idle_thread;
|
||||
return thread == &z_idle_thread;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -7,21 +7,18 @@
|
|||
#define _TRACE_SYSVIEW_H
|
||||
#include <kernel.h>
|
||||
#include <init.h>
|
||||
#include <kernel_internal.h>
|
||||
|
||||
#include <SEGGER_SYSVIEW.h>
|
||||
#include <Global.h>
|
||||
#include "SEGGER_SYSVIEW_Zephyr.h"
|
||||
|
||||
#ifndef CONFIG_SMP
|
||||
extern k_tid_t const _idle_thread;
|
||||
#endif
|
||||
|
||||
static inline int is_idle_thread(struct k_thread *thread)
|
||||
{
|
||||
#ifdef CONFIG_SMP
|
||||
return thread->base.is_idle;
|
||||
#else
|
||||
return thread == _idle_thread;
|
||||
return thread == &z_idle_thread;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
LOG_MODULE_REGISTER(net_shell, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <kernel_internal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <shell/shell.h>
|
||||
|
@ -3248,7 +3249,6 @@ static int cmd_net_route(const struct shell *shell, size_t argc, char *argv[])
|
|||
}
|
||||
|
||||
#if defined(CONFIG_INIT_STACKS)
|
||||
extern K_THREAD_STACK_DEFINE(_main_stack, CONFIG_MAIN_STACK_SIZE);
|
||||
extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE);
|
||||
extern K_THREAD_STACK_DEFINE(sys_work_q_stack,
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE);
|
||||
|
@ -3294,11 +3294,11 @@ static int cmd_net_stacks(const struct shell *shell, size_t argc,
|
|||
}
|
||||
|
||||
#if defined(CONFIG_INIT_STACKS)
|
||||
net_analyze_stack_get_values(Z_THREAD_STACK_BUFFER(_main_stack),
|
||||
K_THREAD_STACK_SIZEOF(_main_stack),
|
||||
net_analyze_stack_get_values(Z_THREAD_STACK_BUFFER(z_main_stack),
|
||||
K_THREAD_STACK_SIZEOF(z_main_stack),
|
||||
&pcnt, &unused);
|
||||
PR("%s [%s] stack size %d/%d bytes unused %u usage %d/%d (%u %%)\n",
|
||||
"main", "_main_stack", CONFIG_MAIN_STACK_SIZE,
|
||||
"main", "z_main_stack", CONFIG_MAIN_STACK_SIZE,
|
||||
CONFIG_MAIN_STACK_SIZE, unused,
|
||||
CONFIG_MAIN_STACK_SIZE - unused, CONFIG_MAIN_STACK_SIZE, pcnt);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <zephyr.h>
|
||||
#include <syscall_handler.h>
|
||||
#include <ztest.h>
|
||||
#include <kernel_internal.h>
|
||||
|
||||
#define SEM_ARRAY_SIZE 16
|
||||
|
||||
|
@ -65,8 +66,6 @@ void object_permission_checks(struct k_sem *sem, bool skip_init)
|
|||
"object should have had sufficient permissions");
|
||||
}
|
||||
|
||||
extern const k_tid_t _main_thread;
|
||||
|
||||
/**
|
||||
* @brief Tests to verify object permission
|
||||
*
|
||||
|
@ -93,7 +92,7 @@ void test_generic_object(void)
|
|||
/* Give an extra reference to another thread so the object
|
||||
* doesn't disappear if we revoke our own
|
||||
*/
|
||||
k_object_access_grant(dyn_sem[i], _main_thread);
|
||||
k_object_access_grant(dyn_sem[i], &z_main_thread);
|
||||
}
|
||||
|
||||
/* dynamic object table well-populated with semaphores at this point */
|
||||
|
|
|
@ -146,7 +146,6 @@ void test_thread_name_get_set(void)
|
|||
#ifdef CONFIG_USERSPACE
|
||||
static char unreadable_string[64];
|
||||
static char not_my_buffer[CONFIG_THREAD_MAX_NAME_LEN];
|
||||
ZTEST_BMEM struct k_thread *main_thread_ptr;
|
||||
struct k_sem sem;
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
|
@ -169,7 +168,7 @@ void test_thread_name_user_get_set(void)
|
|||
zassert_equal(ret, -EFAULT, "accepted unreadable string");
|
||||
ret = k_thread_name_set((struct k_thread *)&sem, "some name");
|
||||
zassert_equal(ret, -EINVAL, "accepted non-thread object");
|
||||
ret = k_thread_name_set(main_thread_ptr, "some name");
|
||||
ret = k_thread_name_set(&z_main_thread, "some name");
|
||||
zassert_equal(ret, -EINVAL, "no permission on thread object");
|
||||
|
||||
/* Set and get current thread's name */
|
||||
|
@ -191,7 +190,7 @@ void test_thread_name_user_get_set(void)
|
|||
ret = k_thread_name_copy((struct k_thread *)&sem, thread_name,
|
||||
sizeof(thread_name));
|
||||
zassert_equal(ret, -EINVAL, "not a thread object");
|
||||
ret = k_thread_name_copy(main_thread_ptr, thread_name,
|
||||
ret = k_thread_name_copy(&z_main_thread, thread_name,
|
||||
sizeof(thread_name));
|
||||
zassert_equal(ret, 0, "couldn't get main thread name");
|
||||
printk("Main thread name is '%s'\n", thread_name);
|
||||
|
@ -270,8 +269,6 @@ void test_user_mode(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
extern const k_tid_t _main_thread;
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
k_thread_access_grant(k_current_get(), &tdata, tstack);
|
||||
|
@ -281,8 +278,6 @@ void test_main(void)
|
|||
#ifdef CONFIG_USERSPACE
|
||||
strncpy(unreadable_string, "unreadable string",
|
||||
sizeof(unreadable_string));
|
||||
/* Copy so user mode can get at it */
|
||||
main_thread_ptr = _main_thread;
|
||||
#endif
|
||||
|
||||
ztest_test_suite(threads_lifecycle,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue