xiaoxiang781216 commented on code in PR #9103: URL: https://github.com/apache/nuttx/pull/9103#discussion_r1186454071
########## arch/risc-v/src/common/riscv_macros.S: ########## @@ -227,8 +222,15 @@ REGLOAD t0, REG_INT_CTX(\out) li t1, MSTATUS_FS and t2, t0, t1 - li t1, MSTATUS_FS_INIT - ble t2, t1, 1f + li t1, MSTATUS_FS_DIRTY + bne t2, t1, 1f + + /* Reset FS bit to MSTATUS_FS_CLEAN */ + li t1, MSTATUS_FS_CLEAN Review Comment: but this change makes the thread fail to restore the FPU context in the following case: 1. Thread 1 use FPU and then switch out(FPU save with dirty flag) 2. Thread 1 switch in some time later(FPU restore with clean flag) 3. Thread 1 doesn't use FPU in this time and switch out(skip FPU saving) 4. Thread 2 swith in use FPU and thread 1 FPU context is destroyed 5. Thread 1 switch in again, but can't restore the FPU context So, the root cause is that https://github.com/apache/nuttx/pull/5731 move the storage of context from tcb to stack, and then we can't save FPU one time but restore FPU multiple time because the stack(FPU saved here) may be modified after the thread resume the execution. To fix this problem, we need save/restore FPU context every time if MSTATUS_FS doesn't equal MSTATUS_FS_INIT. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
