Skip to content
Permalink
Browse files

arch: arm: carve only basic stack frame at thread init

The initial carved stack frame only needs to contain the basic
stack frame (state context), because:
- under No/Unshared FP Services mode no FP context is stacked.
- under FP Sharing mode FP context is cleared upon thread
  creation.
This commit removes the unnecessary stacking of the FP context
during thread initialization. This results in reduced stack
usage under the Shared FP Services mode (CONFIG_FP_SHARING=y).
Also, we do not need to initialize the FPSCR, because there is
no FP stack frame carved.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information...
ioannisg authored and nashif committed Apr 22, 2019
1 parent eecf4b0 commit 929e9ea918a0f8b7a2c03c73046522ed1fcf8b0f
Showing with 7 additions and 5 deletions.
  1. +7 −5 arch/arm/core/thread.c
@@ -101,9 +101,14 @@ void z_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
z_new_thread_init(thread, pStackMem, stackSize, priority,
options);

/* carve the thread entry struct from the "base" of the stack */
/* Carve the thread entry struct from the "base" of the stack
*
* The initial carved stack frame only needs to contain the basic
* stack frame (state context), because no FP operations have been
* performed yet for this thread.
*/
pInitCtx = (struct __esf *)(STACK_ROUND_DOWN(stackEnd -
(char *)top_of_stack_offset - sizeof(struct __esf)));
(char *)top_of_stack_offset - sizeof(struct __basic_sf)));

#if defined(CONFIG_USERSPACE)
if ((options & K_USER) != 0) {
@@ -124,9 +129,6 @@ void z_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
pInitCtx->basic.a4 = (u32_t)parameter3;
pInitCtx->basic.xpsr =
0x01000000UL; /* clear all, thumb bit is 1, even if RO */
#if defined(CONFIG_FLOAT) && defined(CONFIG_FP_SHARING)
pInitCtx->fpscr = (u32_t)0; /* clears FPU status/control register*/
#endif

thread->callee_saved.psp = (u32_t)pInitCtx;
thread->arch.basepri = 0;

0 comments on commit 929e9ea

Please sign in to comment.
You can’t perform that action at this time.