From 8a41f3e0fa58596fe1592dd820b1f8825a86bd6c Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Thu, 26 Mar 2026 15:55:32 +0100 Subject: [PATCH] small cleanuo to smp asm files --- port/threadx_smp/src/tx_thread_schedule.S | 17 ++++++----------- port/threadx_smp/src/tx_thread_smp_protect.S | 9 +-------- port/threadx_smp/src/tx_thread_smp_unprotect.S | 1 - 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/port/threadx_smp/src/tx_thread_schedule.S b/port/threadx_smp/src/tx_thread_schedule.S index eb3fa53..736e261 100644 --- a/port/threadx_smp/src/tx_thread_schedule.S +++ b/port/threadx_smp/src/tx_thread_schedule.S @@ -80,20 +80,15 @@ _tx_thread_schedule: la t0, _tx_thread_execute_ptr // Pickup address of execute ptr add t0, t0, t4 // Select this hart's execute slot _tx_thread_schedule_loop: + csrci mstatus, 0x08 // Lockout interrupts + LOAD t1, 0(t0) // Pickup next thread to execute + bnez t1, _tx_thread_schedule_thread // If non-NULL, continue + csrsi mstatus, 0x08 // Enable interrupts #ifdef TX_ENABLE_WFI - csrci mstatus, 0x08 // Lockout interrupts - LOAD t1, 0(t0) // Pickup next thread to execute - bnez t1, _tx_thread_schedule_thread // If non-NULL, continue - csrsi mstatus, 0x08 // Enable interrupts wfi // Wait for interrupt - j _tx_thread_schedule_loop // Keep looking for a thread -#else - csrci mstatus, 0x08 // Lockout interrupts - LOAD t1, 0(t0) // Pickup next thread to execute - bnez t1, _tx_thread_schedule_thread // If non-NULL, continue - csrsi mstatus, 0x08 // Enable interrupts - j _tx_thread_schedule_loop // Keep looking for a thread #endif + j _tx_thread_schedule_loop // Keep looking for a thread + _tx_thread_schedule_thread: /* Atomically claim the thread's ready token so only one hart can diff --git a/port/threadx_smp/src/tx_thread_smp_protect.S b/port/threadx_smp/src/tx_thread_smp_protect.S index 4618e3c..7762057 100644 --- a/port/threadx_smp/src/tx_thread_smp_protect.S +++ b/port/threadx_smp/src/tx_thread_smp_protect.S @@ -23,18 +23,11 @@ _tx_thread_smp_protect: /* Try to get the protection. */ LWU t4, 0(t1) // Pickup protection flag - beqz t4, _get_protection // If clear, try to claim it - - /* Protection is busy. Restore interrupts and retry. */ - csrw mstatus, a0 // Restore interrupts - j _tx_thread_smp_protect // Restart the protection attempt - -_get_protection: + bnez t4, _protection_busy // If set, protection is busy li t4, 1 // Build lock value amoswap.w.aq t5, t4, (t1) // Attempt to get protection bnez t5, _protection_busy // If old value != 0, retry -_got_protection: fence rw, rw // Ensure lock acquisition is visible sw t2, 4(t1) // Save owning hart diff --git a/port/threadx_smp/src/tx_thread_smp_unprotect.S b/port/threadx_smp/src/tx_thread_smp_unprotect.S index 431898b..eaa6be8 100644 --- a/port/threadx_smp/src/tx_thread_smp_unprotect.S +++ b/port/threadx_smp/src/tx_thread_smp_unprotect.S @@ -35,7 +35,6 @@ _tx_thread_smp_unprotect: /* Release the protection. */ li t3, -1 // Invalid owner value sw t3, 4(t2) // Mark owning hart invalid - fence rw, rw // Ensure shared accesses complete amoswap.w.rl x0, x0, (t2) // Release protection flag _still_protected: