From 05abfac89b9da68243770c80052e880af0da31c7 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 8 Mar 2021 21:59:32 +0800 Subject: [PATCH] mm/heap: Move semaphore related declaration to private header since other subsystem doesn't need call these function anymore Signed-off-by: Xiang Xiao Change-Id: Idfb217c412db62d9f17f427310b75bb78785dc50 --- arch/misoc/src/lm32/lm32_idle.c | 13 --- arch/misoc/src/minerva/minerva_idle.c | 11 --- arch/risc-v/src/common/riscv_idle.c | 9 -- .../imxrt/imxrt1050-evk/scripts/user-space.ld | 2 - .../imxrt/imxrt1060-evk/scripts/user-space.ld | 2 - .../same70-xplained/scripts/user-space.ld | 2 - .../samv7/samv71-xult/scripts/user-space.ld | 2 - .../arm/stm32/axoloti/scripts/user-space.ld | 2 - .../stm32/nucleo-f429zi/scripts/user-space.ld | 2 - .../olimex-stm32-p407/scripts/user-space.ld | 2 - .../stm32f429i-disco/scripts/user-space.ld | 2 - include/nuttx/kmalloc.h | 4 - include/nuttx/mm/mm.h | 21 ----- mm/kmm_heap/Make.defs | 2 +- mm/kmm_heap/kmm_sem.c | 88 ------------------ mm/mm_heap/mm.h | 11 ++- mm/umm_heap/Make.defs | 2 +- mm/umm_heap/umm_sem.c | 90 ------------------- sched/init/nx_start.c | 13 --- 19 files changed, 11 insertions(+), 269 deletions(-) delete mode 100644 mm/kmm_heap/kmm_sem.c delete mode 100644 mm/umm_heap/umm_sem.c diff --git a/arch/misoc/src/lm32/lm32_idle.c b/arch/misoc/src/lm32/lm32_idle.c index be163032ede..1f18dea3d52 100644 --- a/arch/misoc/src/lm32/lm32_idle.c +++ b/arch/misoc/src/lm32/lm32_idle.c @@ -75,19 +75,6 @@ void up_idle(void) * sleep in a reduced power mode until an interrupt occurs to save power */ - /* This is a kludge that I still don't understand. The call to kmm_trysemaphore() - * in the nx_start.c IDLE loop seems necessary for the good health of the IDLE - * loop. When the work queue is enabled, this logic is removed from the IDLE - * loop and it appears that we are somehow left idling with interrupts non- - * functional. The following should be no-op, it just disables then re-enables - * interrupts. But it fixes the problem and will stay here until I understand - * the problem/fix better. - * - * And no, the contents of the CP0 status register are not incorrect. But for - * some reason the status register needs to be re-written again on this thread - * for it to take effect. This might be a PIC32-only issue? - */ - #ifdef CONFIG_SCHED_WORKQUEUE irqstate_t flags = enter_critical_section(); leave_critical_section(flags); diff --git a/arch/misoc/src/minerva/minerva_idle.c b/arch/misoc/src/minerva/minerva_idle.c index 1b2d6a3efdb..dfb3bc2603a 100644 --- a/arch/misoc/src/minerva/minerva_idle.c +++ b/arch/misoc/src/minerva/minerva_idle.c @@ -73,17 +73,6 @@ void up_idle(void) /* This would be an appropriate place to put some MCU-specific logic to * sleep in a reduced power mode until an interrupt occurs to save power - * - * This is a kludge that I still don't understand. The call to - * kmm_trysemaphore() in the nx_start.c IDLE loop seems necessary for the - * good health of the IDLE loop. When the work queue is enabled, this logic - * is removed from the IDLE loop and it appears that we are somehow left - * idling with interrupts non- functional. The following should be no-op, - * it just disables then re-enables interrupts. But it fixes the problem - * and will stay here until I understand the problem/fix better. And no, - * the contents of the CP0 status register are not incorrect. But for some - * reason the status register needs to be re-written again on this thread - * for it to take effect. */ #ifdef CONFIG_SCHED_WORKQUEUE diff --git a/arch/risc-v/src/common/riscv_idle.c b/arch/risc-v/src/common/riscv_idle.c index d1857de68ac..051c245cb4d 100644 --- a/arch/risc-v/src/common/riscv_idle.c +++ b/arch/risc-v/src/common/riscv_idle.c @@ -74,15 +74,6 @@ void up_idle(void) * sleep in a reduced power mode until an interrupt occurs to save power */ - /* This is a kludge that I still don't understand. The call to - * kmm_trysemaphore() in the nx_start.c IDLE loop seems necessary for the - * good health of the IDLE loop. When the work queue is enabled, this - * logic is removed from the IDLE loop and it appears that we are somehow - * left idling with interrupts non-functional. The following should be - * no-op, it just disables then re-enables interrupts. But it fixes the - * problem and will stay here until I understand the problem/fix better. - */ - #ifdef CONFIG_SCHED_WORKQUEUE irqstate_t flags = enter_critical_section(); leave_critical_section(flags); diff --git a/boards/arm/imxrt/imxrt1050-evk/scripts/user-space.ld b/boards/arm/imxrt/imxrt1050-evk/scripts/user-space.ld index df7ef101c17..efec7723629 100644 --- a/boards/arm/imxrt/imxrt1050-evk/scripts/user-space.ld +++ b/boards/arm/imxrt/imxrt1050-evk/scripts/user-space.ld @@ -44,8 +44,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/boards/arm/imxrt/imxrt1060-evk/scripts/user-space.ld b/boards/arm/imxrt/imxrt1060-evk/scripts/user-space.ld index daf3f4bcd11..05ad8e9e134 100644 --- a/boards/arm/imxrt/imxrt1060-evk/scripts/user-space.ld +++ b/boards/arm/imxrt/imxrt1060-evk/scripts/user-space.ld @@ -45,8 +45,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/boards/arm/samv7/same70-xplained/scripts/user-space.ld b/boards/arm/samv7/same70-xplained/scripts/user-space.ld index 18eb9b56e04..0bb34e8db3f 100644 --- a/boards/arm/samv7/same70-xplained/scripts/user-space.ld +++ b/boards/arm/samv7/same70-xplained/scripts/user-space.ld @@ -44,8 +44,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/boards/arm/samv7/samv71-xult/scripts/user-space.ld b/boards/arm/samv7/samv71-xult/scripts/user-space.ld index 80d8872c9c7..f5042dee82e 100644 --- a/boards/arm/samv7/samv71-xult/scripts/user-space.ld +++ b/boards/arm/samv7/samv71-xult/scripts/user-space.ld @@ -44,8 +44,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/boards/arm/stm32/axoloti/scripts/user-space.ld b/boards/arm/stm32/axoloti/scripts/user-space.ld index 69aecb0a3c6..af5b6d8e968 100644 --- a/boards/arm/stm32/axoloti/scripts/user-space.ld +++ b/boards/arm/stm32/axoloti/scripts/user-space.ld @@ -44,8 +44,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/boards/arm/stm32/nucleo-f429zi/scripts/user-space.ld b/boards/arm/stm32/nucleo-f429zi/scripts/user-space.ld index 1c07afc5622..edc904f8f2a 100644 --- a/boards/arm/stm32/nucleo-f429zi/scripts/user-space.ld +++ b/boards/arm/stm32/nucleo-f429zi/scripts/user-space.ld @@ -29,8 +29,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/boards/arm/stm32/olimex-stm32-p407/scripts/user-space.ld b/boards/arm/stm32/olimex-stm32-p407/scripts/user-space.ld index 669b428d1f8..d4c826124b5 100644 --- a/boards/arm/stm32/olimex-stm32-p407/scripts/user-space.ld +++ b/boards/arm/stm32/olimex-stm32-p407/scripts/user-space.ld @@ -44,8 +44,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/boards/arm/stm32/stm32f429i-disco/scripts/user-space.ld b/boards/arm/stm32/stm32f429i-disco/scripts/user-space.ld index acc955975d2..3fd3780fce9 100644 --- a/boards/arm/stm32/stm32f429i-disco/scripts/user-space.ld +++ b/boards/arm/stm32/stm32f429i-disco/scripts/user-space.ld @@ -44,8 +44,6 @@ EXTERN(umm_initialize) EXTERN(umm_addregion) -EXTERN(umm_trysemaphore) -EXTERN(umm_givesemaphore) EXTERN(malloc) EXTERN(realloc) diff --git a/include/nuttx/kmalloc.h b/include/nuttx/kmalloc.h index 89e8e08ba29..d75e8457ff0 100644 --- a/include/nuttx/kmalloc.h +++ b/include/nuttx/kmalloc.h @@ -70,8 +70,6 @@ extern "C" #define kumm_initialize(h,s) umm_initialize(h,s) #define kumm_addregion(h,s) umm_addregion(h,s) -#define kumm_trysemaphore() umm_trysemaphore() -#define kumm_givesemaphore() umm_givesemaphore() #define kumm_calloc(n,s) calloc(n,s); #define kumm_malloc(s) malloc(s) @@ -91,8 +89,6 @@ extern "C" # define kmm_initialize(h,s) /* Initialization done by kumm_initialize */ # define kmm_addregion(h,s) umm_addregion(h,s) -# define kmm_trysemaphore() umm_trysemaphore() -# define kmm_givesemaphore() umm_givesemaphore() # define kmm_calloc(n,s) calloc(n,s); # define kmm_malloc(s) malloc(s) diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 4235090669e..c0cf54f3975 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -29,8 +29,6 @@ #include #include -#include -#include /**************************************************************************** * Pre-processor Definitions @@ -185,25 +183,6 @@ void umm_addregion(FAR void *heapstart, size_t heapsize); void kmm_addregion(FAR void *heapstart, size_t heapsize); #endif -/* Functions contained in mm_sem.c ******************************************/ - -void mm_seminitialize(FAR struct mm_heap_s *heap); -void mm_takesemaphore(FAR struct mm_heap_s *heap); -int mm_trysemaphore(FAR struct mm_heap_s *heap); -void mm_givesemaphore(FAR struct mm_heap_s *heap); - -/* Functions contained in umm_sem.c *****************************************/ - -int umm_trysemaphore(void); -void umm_givesemaphore(void); - -/* Functions contained in kmm_sem.c *****************************************/ - -#ifdef CONFIG_MM_KERNEL_HEAP -int kmm_trysemaphore(void); -void kmm_givesemaphore(void); -#endif - /* Functions contained in mm_malloc.c ***************************************/ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size); diff --git a/mm/kmm_heap/Make.defs b/mm/kmm_heap/Make.defs index 881f3076151..57741820cec 100644 --- a/mm/kmm_heap/Make.defs +++ b/mm/kmm_heap/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_MM_KERNEL_HEAP),y) -CSRCS += kmm_initialize.c kmm_addregion.c kmm_sem.c +CSRCS += kmm_initialize.c kmm_addregion.c CSRCS += kmm_brkaddr.c kmm_calloc.c kmm_extend.c kmm_free.c kmm_mallinfo.c CSRCS += kmm_malloc.c kmm_memalign.c kmm_realloc.c kmm_zalloc.c kmm_heapmember.c diff --git a/mm/kmm_heap/kmm_sem.c b/mm/kmm_heap/kmm_sem.c deleted file mode 100644 index bef246858bb..00000000000 --- a/mm/kmm_heap/kmm_sem.c +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * mm/kmm_heap/kmm_sem.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kmm_trysemaphore - * - * Description: - * Try to take the kernel heap semaphore. - * - * Input Parameters: - * None - * - * Returned Value: - * OK on success; a negated errno on failure - * - ****************************************************************************/ - -int kmm_trysemaphore(void) -{ - return mm_trysemaphore(&g_kmmheap); -} - -/**************************************************************************** - * Name: kmm_givesemaphore - * - * Description: - * Give the kernel heap semaphore. - * - * Input Parameters: - * None - * - * Returned Value: - * OK on success; a negated errno on failure - * - ****************************************************************************/ - -void kmm_givesemaphore(void) -{ - return mm_givesemaphore(&g_kmmheap); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 80d5c52d4d7..752108c62ec 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -111,6 +111,8 @@ * Public Types ****************************************************************************/ +struct mm_heap_s; + /* Determines the size of the chunk size/offset type */ #ifdef CONFIG_MM_SMALL @@ -203,9 +205,14 @@ struct mm_heap_impl_s struct mm_delaynode_s *mm_delaylist; }; -/* Functions contained in mm_shrinkchunk.c **********************************/ +/* Functions contained in mm_sem.c ******************************************/ -struct mm_heap_s; +void mm_seminitialize(FAR struct mm_heap_s *heap); +void mm_takesemaphore(FAR struct mm_heap_s *heap); +int mm_trysemaphore(FAR struct mm_heap_s *heap); +void mm_givesemaphore(FAR struct mm_heap_s *heap); + +/* Functions contained in mm_shrinkchunk.c **********************************/ void mm_shrinkchunk(FAR struct mm_heap_s *heap, FAR struct mm_allocnode_s *node, size_t size); diff --git a/mm/umm_heap/Make.defs b/mm/umm_heap/Make.defs index 703211bc5c6..45140026579 100644 --- a/mm/umm_heap/Make.defs +++ b/mm/umm_heap/Make.defs @@ -35,7 +35,7 @@ # User heap allocator -CSRCS += umm_initialize.c umm_addregion.c umm_sem.c +CSRCS += umm_initialize.c umm_addregion.c CSRCS += umm_brkaddr.c umm_calloc.c umm_extend.c umm_free.c umm_mallinfo.c CSRCS += umm_malloc.c umm_memalign.c umm_realloc.c umm_zalloc.c umm_heapmember.c CSRCS += umm_globals.c umm_posix_memalign.c umm_aligned_alloc.c umm_valloc.c diff --git a/mm/umm_heap/umm_sem.c b/mm/umm_heap/umm_sem.c deleted file mode 100644 index 2a1f6e854f8..00000000000 --- a/mm/umm_heap/umm_sem.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * mm/umm_heap/umm_sem.c - * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include "umm_heap/umm_heap.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: umm_trysemaphore - * - * Description: - * This is a simple wrapper for the mm_trysemaphore() function. This - * function is exported from the user-space blob so that the kernel - * can manage the user-mode allocator. - * - * Input Parameters: - * None - * - * Returned Value: - * OK on success; a negated errno on failure - * - ****************************************************************************/ - -int umm_trysemaphore(void) -{ - return mm_trysemaphore(USR_HEAP); -} - -/**************************************************************************** - * Name: umm_givesemaphore - * - * Description: - * This is a simple wrapper for the mm_givesemaphore() function. This - * function is exported from the user-space blob so that the kernel - * can manage the user-mode allocator. - * - * Input Parameters: - * None - * - * Returned Value: - * OK on success; a negated errno on failure - * - ****************************************************************************/ - -void umm_givesemaphore(void) -{ - mm_givesemaphore(USR_HEAP); -} diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index 00cc6acabf6..76869e67c39 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -792,12 +792,6 @@ void nx_start(void) DEBUGASSERT(this_cpu() == 0 && CONFIG_MAX_TASKS > CONFIG_SMP_NCPUS); - /* Take the memory manager semaphore on this CPU so that it will not be - * available on the other CPUs until we have finished initialization. - */ - - DEBUGVERIFY(kmm_trysemaphore()); - /* Then start the other CPUs */ DEBUGVERIFY(nx_smp_start()); @@ -814,13 +808,6 @@ void nx_start(void) DEBUGVERIFY(nx_bringup()); -#ifdef CONFIG_SMP - /* Let other threads have access to the memory manager */ - - kmm_givesemaphore(); - -#endif /* CONFIG_SMP */ - /* The IDLE Loop **********************************************************/ /* When control is return to this point, the system is idle. */