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/nuttx.git

commit 0c805ca0a907fad87074276a693d0b1f7a5332ad
Author: Xiang Xiao <xiaoxi...@xiaomi.com>
AuthorDate: Mon Oct 30 01:01:37 2023 +0800

    mm: Change global spinlock to per heap
    
    Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com>
---
 mm/mm_heap/mm.h        |  1 +
 mm/mm_heap/mm_free.c   |  4 ++--
 mm/mm_heap/mm_malloc.c |  4 ++--
 mm/tlsf/mm_tlsf.c      | 13 +++++--------
 4 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index f7c5549939..163aa46818 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -250,6 +250,7 @@ struct mm_heap_s
    * immdiately.
    */
 
+  spinlock_t mm_spinlock;
   FAR struct mm_delaynode_s *mm_delaylist[CONFIG_SMP_NCPUS];
 
   /* The is a multiple mempool of the heap */
diff --git a/mm/mm_heap/mm_free.c b/mm/mm_heap/mm_free.c
index 7716c720ce..b41464da9f 100644
--- a/mm/mm_heap/mm_free.c
+++ b/mm/mm_heap/mm_free.c
@@ -45,12 +45,12 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR 
void *mem)
 
   /* Delay the deallocation until a more appropriate time. */
 
-  flags = spin_lock_irqsave(NULL);
+  flags = spin_lock_irqsave(&heap->mm_spinlock);
 
   tmp->flink = heap->mm_delaylist[up_cpu_index()];
   heap->mm_delaylist[up_cpu_index()] = tmp;
 
-  spin_unlock_irqrestore(NULL, flags);
+  spin_unlock_irqrestore(&heap->mm_spinlock, flags);
 #endif
 }
 
diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c
index c8c12a974d..df2624aba0 100644
--- a/mm/mm_heap/mm_malloc.c
+++ b/mm/mm_heap/mm_malloc.c
@@ -47,12 +47,12 @@ static void free_delaylist(FAR struct mm_heap_s *heap)
 
   /* Move the delay list to local */
 
-  flags = spin_lock_irqsave(NULL);
+  flags = spin_lock_irqsave(&heap->mm_spinlock);
 
   tmp = heap->mm_delaylist[up_cpu_index()];
   heap->mm_delaylist[up_cpu_index()] = NULL;
 
-  spin_unlock_irqrestore(NULL, flags);
+  spin_unlock_irqrestore(&heap->mm_spinlock, flags);
 
   /* Test if the delayed is empty */
 
diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c
index 5d221a8e3d..0f93c2229f 100644
--- a/mm/tlsf/mm_tlsf.c
+++ b/mm/tlsf/mm_tlsf.c
@@ -97,11 +97,8 @@ struct mm_heap_s
 
   /* Free delay list, for some situation can't do free immdiately */
 
-#ifdef CONFIG_SMP
+  spinlock_t mm_spinlock;
   struct mm_delaynode_s *mm_delaylist[CONFIG_SMP_NCPUS];
-#else
-  struct mm_delaynode_s *mm_delaylist[1];
-#endif
 
 #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
   struct procfs_meminfo_entry_s mm_procfs;
@@ -173,12 +170,12 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR 
void *mem)
 
   /* Delay the deallocation until a more appropriate time. */
 
-  flags = spin_lock_irqsave(NULL);
+  flags = spin_lock_irqsave(&heap->mm_spinlock);
 
   tmp->flink = heap->mm_delaylist[up_cpu_index()];
   heap->mm_delaylist[up_cpu_index()] = tmp;
 
-  spin_unlock_irqrestore(NULL, flags);
+  spin_unlock_irqrestore(&heap->mm_spinlock, flags);
 #endif
 }
 
@@ -194,12 +191,12 @@ static void free_delaylist(FAR struct mm_heap_s *heap)
 
   /* Move the delay list to local */
 
-  flags = spin_lock_irqsave(NULL);
+  flags = spin_lock_irqsave(&heap->mm_spinlock);
 
   tmp = heap->mm_delaylist[up_cpu_index()];
   heap->mm_delaylist[up_cpu_index()] = NULL;
 
-  spin_unlock_irqrestore(NULL, flags);
+  spin_unlock_irqrestore(&heap->mm_spinlock, flags);
 
   /* Test if the delayed is empty */
 

Reply via email to