kernel: align thread stack size declaration

When thread stack is defined as an array, K_THREAD_STACK_LEN()
is used to calculate the size for each stack in the array.
However, standalone thread stack has its size calculated by
Z_THREAD_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_THREAD_STACK_LEN().

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

View file

@ -132,7 +132,7 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
size_t stack_aligned_size; size_t stack_aligned_size;
stack_start = POINTER_TO_UINT(_current->stack_obj); stack_start = POINTER_TO_UINT(_current->stack_obj);
stack_size = Z_THREAD_STACK_SIZE_ADJUST(_current->stack_info.size); stack_size = K_THREAD_STACK_LEN(_current->stack_info.size);
#if defined(CONFIG_HW_STACK_PROTECTION) #if defined(CONFIG_HW_STACK_PROTECTION)
/* With hardware stack protection, the first page of stack /* With hardware stack protection, the first page of stack

View file

@ -404,7 +404,7 @@ static inline char *K_KERNEL_STACK_BUFFER(k_thread_stack_t *sym)
*/ */
#define K_THREAD_STACK_DECLARE(sym, size) \ #define K_THREAD_STACK_DECLARE(sym, size) \
extern struct z_thread_stack_element \ extern struct z_thread_stack_element \
sym[Z_THREAD_STACK_SIZE_ADJUST(size)] sym[K_THREAD_STACK_LEN(size)]
/** /**
* @brief Declare a reference to a thread stack array * @brief Declare a reference to a thread stack array
@ -467,7 +467,7 @@ static inline char *K_KERNEL_STACK_BUFFER(k_thread_stack_t *sym)
#define Z_THREAD_STACK_DEFINE_IN(sym, size, lsect) \ #define Z_THREAD_STACK_DEFINE_IN(sym, size, lsect) \
struct z_thread_stack_element lsect \ struct z_thread_stack_element lsect \
__aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \ __aligned(Z_THREAD_STACK_OBJ_ALIGN(size)) \
sym[Z_THREAD_STACK_SIZE_ADJUST(size)] sym[K_THREAD_STACK_LEN(size)]
/** /**
* @brief Define a toplevel array of thread stack memory regions in specified region * @brief Define a toplevel array of thread stack memory regions in specified region

View file

@ -384,7 +384,7 @@ static char *setup_thread_stack(struct k_thread *new_thread,
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
if (z_stack_is_user_capable(stack)) { if (z_stack_is_user_capable(stack)) {
stack_obj_size = Z_THREAD_STACK_SIZE_ADJUST(stack_size); stack_obj_size = K_THREAD_STACK_LEN(stack_size);
stack_buf_start = K_THREAD_STACK_BUFFER(stack); stack_buf_start = K_THREAD_STACK_BUFFER(stack);
stack_buf_size = stack_obj_size - K_THREAD_STACK_RESERVED; stack_buf_size = stack_obj_size - K_THREAD_STACK_RESERVED;
} else } else

View file

@ -59,13 +59,13 @@ static struct k_spinlock objfree_lock; /* k_object_free */
#if defined(CONFIG_ARM_MPU) || defined(CONFIG_ARC_MPU) #if defined(CONFIG_ARM_MPU) || defined(CONFIG_ARC_MPU)
#define STACK_ELEMENT_DATA_SIZE(size) \ #define STACK_ELEMENT_DATA_SIZE(size) \
(sizeof(struct z_stack_data) + CONFIG_PRIVILEGED_STACK_SIZE + \ (sizeof(struct z_stack_data) + CONFIG_PRIVILEGED_STACK_SIZE + \
Z_THREAD_STACK_OBJ_ALIGN(size) + Z_THREAD_STACK_SIZE_ADJUST(size)) Z_THREAD_STACK_OBJ_ALIGN(size) + K_THREAD_STACK_LEN(size))
#else #else
#define STACK_ELEMENT_DATA_SIZE(size) (sizeof(struct z_stack_data) + \ #define STACK_ELEMENT_DATA_SIZE(size) (sizeof(struct z_stack_data) + \
Z_THREAD_STACK_SIZE_ADJUST(size)) K_THREAD_STACK_LEN(size))
#endif /* CONFIG_ARM_MPU || CONFIG_ARC_MPU */ #endif /* CONFIG_ARM_MPU || CONFIG_ARC_MPU */
#else #else
#define STACK_ELEMENT_DATA_SIZE(size) Z_THREAD_STACK_SIZE_ADJUST(size) #define STACK_ELEMENT_DATA_SIZE(size) K_THREAD_STACK_LEN(size)
#endif /* CONFIG_GEN_PRIV_STACKS */ #endif /* CONFIG_GEN_PRIV_STACKS */
#endif /* CONFIG_DYNAMIC_OBJECTS */ #endif /* CONFIG_DYNAMIC_OBJECTS */

View file

@ -465,7 +465,7 @@ static void *fatal_setup(void)
obj_size = K_THREAD_STACK_SIZEOF(overflow_stack); obj_size = K_THREAD_STACK_SIZEOF(overflow_stack);
#if defined(CONFIG_USERSPACE) #if defined(CONFIG_USERSPACE)
obj_size = Z_THREAD_STACK_SIZE_ADJUST(obj_size); obj_size = K_THREAD_STACK_LEN(obj_size);
#endif #endif
k_mem_region_align(&pin_addr, &pin_size, k_mem_region_align(&pin_addr, &pin_size,
@ -477,7 +477,7 @@ static void *fatal_setup(void)
obj_size = K_THREAD_STACK_SIZEOF(alt_stack); obj_size = K_THREAD_STACK_SIZEOF(alt_stack);
#if defined(CONFIG_USERSPACE) #if defined(CONFIG_USERSPACE)
obj_size = Z_THREAD_STACK_SIZE_ADJUST(obj_size); obj_size = K_THREAD_STACK_LEN(obj_size);
#endif #endif
k_mem_region_align(&pin_addr, &pin_size, k_mem_region_align(&pin_addr, &pin_size,

View file

@ -12,7 +12,7 @@
#define POOL_SIZE 20480 #define POOL_SIZE 20480
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
#define STACK_OBJ_SIZE Z_THREAD_STACK_SIZE_ADJUST(CONFIG_DYNAMIC_THREAD_STACK_SIZE) #define STACK_OBJ_SIZE K_THREAD_STACK_LEN(CONFIG_DYNAMIC_THREAD_STACK_SIZE)
#else #else
#define STACK_OBJ_SIZE K_KERNEL_STACK_LEN(CONFIG_DYNAMIC_THREAD_STACK_SIZE) #define STACK_OBJ_SIZE K_KERNEL_STACK_LEN(CONFIG_DYNAMIC_THREAD_STACK_SIZE)
#endif #endif

View file

@ -231,7 +231,7 @@ void stack_buffer_scenarios(void)
* For some stack declared with: * For some stack declared with:
* *
* K_THREAD_STACK_DEFINE(my_stack, X); * K_THREAD_STACK_DEFINE(my_stack, X);
* Z_THREAD_STACK_SIZE_ADJUST(X) - K_THREAD_STACK_RESERVED == * K_THREAD_STACK_LEN(X) - K_THREAD_STACK_RESERVED ==
* K_THREAD_STACK_SIZEOF(my_stack) * K_THREAD_STACK_SIZEOF(my_stack)
* *
* K_KERNEL_STACK_DEFINE(my_kern_stack, Y): * K_KERNEL_STACK_DEFINE(my_kern_stack, Y):
@ -241,7 +241,7 @@ void stack_buffer_scenarios(void)
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
/* Not defined if user mode disabled, all stacks are kernel stacks */ /* Not defined if user mode disabled, all stacks are kernel stacks */
if (scenario_data.is_user) { if (scenario_data.is_user) {
adjusted = Z_THREAD_STACK_SIZE_ADJUST(scenario_data.declared_size); adjusted = K_THREAD_STACK_LEN(scenario_data.declared_size);
} else } else
#endif #endif
{ {