Skip to content

Commit d95ab0e

Browse files
committed
OS/ThreadX: Fix interrupt control ordering and update changelog
Signed-off-by: Huaqi Fang <578567190@qq.com>
1 parent 90e08df commit d95ab0e

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

OS/ThreadX/ports/nuclei/port.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ void PortThreadSwitch(void)
9696
__ASM volatile("csrrw sp, " STRINGIFY(CSR_MSCRATCHCSWL) ", sp");
9797
/* restore timer interrupt to origin kernel interrupt priority */
9898
ECLIC_SetLevelIRQ(SysTimer_IRQn, KERNEL_INTERRUPT_PRIORITY);
99+
__RWMB();
99100
}
100101
/* Determine if the time-slice is active. */
101102
if (_tx_timer_time_slice && _tx_thread_current_ptr) {
@@ -108,6 +109,7 @@ void PortThreadSwitch(void)
108109
_tx_thread_current_ptr -> tx_thread_run_count++;
109110
/* Clear Software IRQ, A MUST */
110111
SysTimer_ClearSWIRQ();
112+
__RWMB();
111113
}
112114

113115
void SetupSysTickInterrupt(void)
@@ -154,10 +156,11 @@ UINT _tx_thread_interrupt_control(UINT new_posture)
154156

155157
if (new_posture == TX_INT_DISABLE) {
156158
// clear interrupt
157-
temp = __RV_CSR_READ_CLEAR(CSR_MSTATUS, MSTATUS_MIE);
159+
temp = __RV_CSR_READ_CLEAR(CSR_MSTATUS, MSTATUS_MIE) & MSTATUS_MIE;
158160
} else {
159-
temp = __RV_CSR_SWAP(CSR_MSTATUS, new_posture);
161+
temp = __RV_CSR_READ_SET(CSR_MSTATUS, MSTATUS_MIE) & MSTATUS_MIE;
160162
}
163+
__RWMB();
161164
return (UINT)temp;
162165
}
163166

doc/source/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ This is release version of ``0.9.0`` of Nuclei SDK.
137137
- Fix ThreadX SMP port ``PortThreadSwitch`` function by adding memory barriers (``__RWMB()``) around ECLIC IRQ priority changes and stack pointer swaps to ensure proper ordering of memory operations on Nuclei 1000 series out-of-order processors, preventing potential race conditions in multi-core task switching
138138
- Fix ThreadX SMP port time-slice processing to run on every tick interrupt, enable trap SP swap setup for the primary hart when ECLICv2 is present, and correct a ``==`` typo in the SMP force-unprotect path ``_tx_thread_smp_force_unprotect``
139139
- Fix ThreadX SMP port by introducing ``_tx_find_ready_thread`` for shared ready-thread selection in GCC/IAR startup and ``PortThreadSwitch``, using ``tx_thread_smp_core_control`` as the ready-thread claim flag
140+
- Fix ThreadX Nuclei port interrupt control and task switch ordering in ``port.c`` by preserving the previous ``MSTATUS.MIE`` state and adding ``__RWMB()`` barriers after interrupt priority restore and software interrupt clear
140141

141142
* Build System
142143

0 commit comments

Comments
 (0)