kernel: align kernel stack size declaration

When kernel stack is defined as an array, K_KERNEL_STACK_LEN()
is used to calculate the size for each stack in the array.
However, standalone kernel stack has its size calculated by
Z_KERNEL_STACK_SIZE_ADJUST() instead. Depending on the arch
alignment requirement, they may not be the same... which
could cause some confusions. So align them both to use
K_KERNEL_STACK_LEN().

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2024-03-22 14:03:37 -07:00 committed by Anas Nashif
parent b9f66b26f8
commit 6cd7936f57
8 changed files with 11 additions and 11 deletions

View file

@ -107,9 +107,9 @@ struct x86_cpuboot x86_cpuboot[] = {
.tr = X86_KERNEL_CPU0_TR,
.gs_base = &tss0,
.sp = (uint64_t) z_interrupt_stacks[0] +
Z_KERNEL_STACK_SIZE_ADJUST(CONFIG_ISR_STACK_SIZE),
K_KERNEL_STACK_LEN(CONFIG_ISR_STACK_SIZE),
.stack_size =
Z_KERNEL_STACK_SIZE_ADJUST(CONFIG_ISR_STACK_SIZE),
K_KERNEL_STACK_LEN(CONFIG_ISR_STACK_SIZE),
.fn = z_prep_c,
.arg = &x86_cpu_boot_arg,
},

View file

@ -123,7 +123,7 @@ static inline char *z_stack_ptr_align(char *ptr)
*/
#define K_KERNEL_STACK_DECLARE(sym, size) \
extern struct z_thread_stack_element \
sym[Z_KERNEL_STACK_SIZE_ADJUST(size)]
sym[K_KERNEL_STACK_LEN(size)]
/**
* @brief Declare a reference to a thread stack array
@ -175,7 +175,7 @@ static inline char *z_stack_ptr_align(char *ptr)
#define Z_KERNEL_STACK_DEFINE_IN(sym, size, lsect) \
struct z_thread_stack_element lsect \
__aligned(Z_KERNEL_STACK_OBJ_ALIGN) \
sym[Z_KERNEL_STACK_SIZE_ADJUST(size)]
sym[K_KERNEL_STACK_LEN(size)]
/**
* @brief Define a toplevel array of kernel stack memory regions in specified section

View file

@ -49,7 +49,7 @@ extern "C" {
#define PTHREAD_ONCE_INIT {0}
/* The minimum allowable stack size */
#define PTHREAD_STACK_MIN Z_KERNEL_STACK_SIZE_ADJUST(0)
#define PTHREAD_STACK_MIN K_KERNEL_STACK_LEN(0)
/**
* @brief Declare a condition variable as initialized

View file

@ -75,7 +75,7 @@ static k_thread_stack_t *stack_alloc_dyn(size_t size, int flags)
}
return z_thread_stack_alloc_dyn(Z_KERNEL_STACK_OBJ_ALIGN,
Z_KERNEL_STACK_SIZE_ADJUST(size));
K_KERNEL_STACK_LEN(size));
}
k_thread_stack_t *z_impl_k_thread_stack_alloc(size_t size, int flags)

View file

@ -391,7 +391,7 @@ static char *setup_thread_stack(struct k_thread *new_thread,
#endif /* CONFIG_USERSPACE */
{
/* Object cannot host a user mode thread */
stack_obj_size = Z_KERNEL_STACK_SIZE_ADJUST(stack_size);
stack_obj_size = K_KERNEL_STACK_LEN(stack_size);
stack_buf_start = K_KERNEL_STACK_BUFFER(stack);
stack_buf_size = stack_obj_size - K_KERNEL_STACK_RESERVED;

View file

@ -122,7 +122,7 @@ cy_rslt_t cy_rtos_create_thread(cy_thread_t *thread, cy_thread_entry_fn_t entry_
/* Allocate stack if NULL was passed */
if ((uint32_t *)stack == NULL) {
stack_alloc = k_aligned_alloc(Z_KERNEL_STACK_OBJ_ALIGN,
Z_KERNEL_STACK_SIZE_ADJUST(stack_size));
K_KERNEL_STACK_LEN(stack_size));
/* Store pointer to allocated stack,
* NULL if not allocated by cy_rtos_thread_create (passed by application).

View file

@ -14,7 +14,7 @@
#ifdef CONFIG_USERSPACE
#define STACK_OBJ_SIZE Z_THREAD_STACK_SIZE_ADJUST(CONFIG_DYNAMIC_THREAD_STACK_SIZE)
#else
#define STACK_OBJ_SIZE Z_KERNEL_STACK_SIZE_ADJUST(CONFIG_DYNAMIC_THREAD_STACK_SIZE)
#define STACK_OBJ_SIZE K_KERNEL_STACK_LEN(CONFIG_DYNAMIC_THREAD_STACK_SIZE)
#endif
#define MAX_HEAP_STACKS (POOL_SIZE / STACK_OBJ_SIZE)

View file

@ -235,7 +235,7 @@ void stack_buffer_scenarios(void)
* K_THREAD_STACK_SIZEOF(my_stack)
*
* K_KERNEL_STACK_DEFINE(my_kern_stack, Y):
* Z_KERNEL_STACK_SIZE_ADJUST(Y) - K_KERNEL_STACK_RESERVED ==
* K_KERNEL_STACK_LEN(Y) - K_KERNEL_STACK_RESERVED ==
* K_KERNEL_STACK_SIZEOF(my_stack)
*/
#ifdef CONFIG_USERSPACE
@ -245,7 +245,7 @@ void stack_buffer_scenarios(void)
} else
#endif
{
adjusted = Z_KERNEL_STACK_SIZE_ADJUST(scenario_data.declared_size);
adjusted = K_KERNEL_STACK_LEN(scenario_data.declared_size);
}
adjusted -= reserved;