Skip to content

Commit

Permalink
arch: arm: update thread options flag and CONTROL atomically
Browse files Browse the repository at this point in the history
Under FP shared registers mode (CONFIG_FP_SHARING=y),
a thread's user_options flag is checked during swap and
during stack fail check. Therefore, in k_float_disable()
we want to ensure that a thread won't be swapped-out with
K_FP_REGS flag cleared but still FP-active (CONTROL.FPCA
being not zero). To ensure that we temporarily disable
interrupts.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
  • Loading branch information
ioannisg authored and andrewboie committed Jun 28, 2019
1 parent f70093a commit 171272c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions arch/arm/core/thread.c
Expand Up @@ -351,9 +351,23 @@ int z_arch_float_disable(struct k_thread *thread)

/* Disable all floating point capabilities for the thread */

/* K_FP_REG flag is used in SWAP and stack check fail. Locking
* interrupts here prevents a possible context-switch or MPU
* fault to take an outdated thread user_options flag into
* account.
*/
int key = z_arch_irq_lock();

thread->base.user_options &= ~K_FP_REGS;

__set_CONTROL(__get_CONTROL() & (~CONTROL_FPCA_Msk));

/* No need to add an ISB barrier after setting the CONTROL
* register; z_arch_irq_unlock() already adds one.
*/

z_arch_irq_unlock(key);

return 0;
}
#endif /* CONFIG_FLOAT && CONFIG_FP_SHARING */

0 comments on commit 171272c

Please sign in to comment.