This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new c4901d6f4b arch: risc-v: Introduce g_percpu_spin in riscv_percpu.c
c4901d6f4b is described below

commit c4901d6f4b7a2faa03a9a22ec3559a2cc249e5bd
Author: Masayuki Ishikawa <masayuki.ishik...@gmail.com>
AuthorDate: Wed Oct 5 07:16:01 2022 +0900

    arch: risc-v: Introduce g_percpu_spin in riscv_percpu.c
    
    Summary:
    - This commit introduces g_percpu_spin to avoid deadlock
      in riscv_percpu.c instead of using the global spinlock.
    
    Impact:
    - None
    
    Testing:
    - Tested with rv-virt:knsh64 and rv-virt:ksmp64 (will be added later)
    
    Signed-off-by: Masayuki Ishikawa <masayuki.ishik...@jp.sony.com>
---
 arch/risc-v/src/common/riscv_percpu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/risc-v/src/common/riscv_percpu.c 
b/arch/risc-v/src/common/riscv_percpu.c
index 6b55e54c76..d80c3d8efa 100644
--- a/arch/risc-v/src/common/riscv_percpu.c
+++ b/arch/risc-v/src/common/riscv_percpu.c
@@ -55,6 +55,7 @@ static_assert(RISCV_PERCPU_IRQSTACK == 
offsetof(riscv_percpu_t, irq_stack),
 static riscv_percpu_t   g_percpu[HART_CNT];
 static sq_queue_t       g_freelist;
 static uintptr_t        g_initialized;
+static spinlock_t       g_percpu_spin;
 
 /****************************************************************************
  * Private Functions
@@ -76,7 +77,7 @@ static void riscv_percpu_init(void)
 
   /* Need to lock access during configuration */
 
-  flags = spin_lock_irqsave(NULL);
+  flags = spin_lock_irqsave(&g_percpu_spin);
 
   /* Initialize if not done so already */
 
@@ -102,7 +103,7 @@ static void riscv_percpu_init(void)
     }
 
 out_with_lock:
-  spin_unlock_irqrestore(NULL, flags);
+  spin_unlock_irqrestore(&g_percpu_spin, flags);
 }
 
 /****************************************************************************
@@ -131,9 +132,9 @@ void riscv_percpu_add_hart(uintptr_t hartid)
 
   /* Get free entry for this hart, this must not fail */
 
-  flags = spin_lock_irqsave(NULL);
+  flags = spin_lock_irqsave(&g_percpu_spin);
   percpu = (riscv_percpu_t *)sq_remfirst(&g_freelist);
-  spin_unlock_irqrestore(NULL, flags);
+  spin_unlock_irqrestore(&g_percpu_spin, flags);
   DEBUGASSERT(percpu);
 
   /* Assign hartid, stack has already been assigned */

Reply via email to