summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-05 17:33:50 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-05 17:33:50 +0000
commit3607bf2b4b1f2087cfb52ab4591f2ac347698a9c (patch)
tree0c034fe7e16b4d77846b1c3dea995474238da4f0 /nuttx/sched
parent9f054efd67930f2dd6ef2a2f4e28eea3d8b10431 (diff)
downloadpx4-nuttx-3607bf2b4b1f2087cfb52ab4591f2ac347698a9c.tar.gz
px4-nuttx-3607bf2b4b1f2087cfb52ab4591f2ac347698a9c.tar.bz2
px4-nuttx-3607bf2b4b1f2087cfb52ab4591f2ac347698a9c.zip
More separation of kernel- and user-memory management
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3468 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/Makefile3
-rw-r--r--nuttx/sched/kmm_addregion.c113
-rw-r--r--nuttx/sched/kmm_initialize.c113
-rw-r--r--nuttx/sched/kmm_kfree.c2
-rw-r--r--nuttx/sched/kmm_kmalloc.c2
-rw-r--r--nuttx/sched/kmm_krealloc.c3
-rw-r--r--nuttx/sched/kmm_kzalloc.c2
-rw-r--r--nuttx/sched/kmm_semaphore.c140
-rw-r--r--nuttx/sched/os_start.c11
-rw-r--r--nuttx/sched/sched_free.c6
-rwxr-xr-xnuttx/sched/sched_garbage.c4
11 files changed, 383 insertions, 16 deletions
diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile
index f164630bf..93807b695 100644
--- a/nuttx/sched/Makefile
+++ b/nuttx/sched/Makefile
@@ -134,7 +134,8 @@ endif
IRQ_SRCS = irq_initialize.c irq_attach.c irq_dispatch.c irq_unexpectedisr.c
-KMM_SRCS = kmm_kmalloc.c kmm_kzalloc.c kmm_krealloc.c kmm_kfree.c
+KMM_SRCS = kmm_initialize.c kmm_addregion.c kmm_semaphore.c \
+ kmm_kmalloc.c kmm_kzalloc.c kmm_krealloc.c kmm_kfree.c
CSRCS = $(MISC_SRCS) $(TSK_SRCS) $(SCHED_SRCS) $(WDOG_SRCS) $(TIME_SRCS) \
$(SEM_SRCS) $(TIMER_SRCS) $(WORK_SRCS) $(PGFILL_SRCS) $(IRQ_SRCS)
diff --git a/nuttx/sched/kmm_addregion.c b/nuttx/sched/kmm_addregion.c
new file mode 100644
index 000000000..ed923a56f
--- /dev/null
+++ b/nuttx/sched/kmm_addregion.c
@@ -0,0 +1,113 @@
+/************************************************************************
+ * sched/kmm_addregion.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+
+#ifdef CONFIG_NUTTX_KERNEL
+
+/* This logic is all tentatively and, hopefully, will grow in usability.
+ * For now, the kernel-mode build uses the memory manager that is
+ * provided in the user-space build. That is awkward but reasonable for
+ * the current level of support: At present, only memory protection is
+ * provided. Kernel-mode code may call into user-mode code, but not
+ * vice-versa. So hosting the memory manager in user-space allows the
+ * memory manager to be shared in both kernel- and user-mode spaces.
+ *
+ * In the longer run, if an MMU is support that can provide virtualized
+ * memory, then some SLAB memory manager will be required in kernel-space
+ * with some kind of brk() system call to obtain mapped heap space.
+ *
+ * In the current build model, the user-space module is built first. The
+ * file user_map.h is generated in the first pass and contains the
+ * addresses of the memory manager needed in this file:
+ */
+
+#include <arch/board/user_map.h>
+
+/************************************************************************
+ * Pre-processor definition
+ ************************************************************************/
+
+/* This value is obtained from user_map.h */
+
+#define KADDREGION(h,s) ((kmaddregion_t)CONFIG_USER_MMADDREGION)(h,s)
+
+/************************************************************************
+ * Private Types
+ ************************************************************************/
+
+typedef void (*kmaddregion_t)(FAR void*, size_t);
+
+/************************************************************************
+ * Private Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Function: kmm_addregion
+ *
+ * Description:
+ * This is a simple redirection to the user-space mm_addregion()
+ * function.
+ *
+ * Parameters:
+ * heap_start - Address of the beginning of the memory region
+ * heap_size - The size (in bytes) if the memory region.
+ *
+ * Return Value:
+ * None
+ *
+ * Assumptions:
+ * 1. mm_addregion() resides in user-space
+ * 2. The address of the user space mm_addregion() is provided in
+ * user_map.h
+ * 3. The user-space mm_addregion() is callable from kernel-space.
+ *
+ ************************************************************************/
+
+void kmm_addregion(FAR void *heap_start, size_t heap_size)
+{
+ return KADDREGION(heap_start, heap_size);
+}
+
+#endif /* CONFIG_NUTTX_KERNEL */
diff --git a/nuttx/sched/kmm_initialize.c b/nuttx/sched/kmm_initialize.c
new file mode 100644
index 000000000..59a554adc
--- /dev/null
+++ b/nuttx/sched/kmm_initialize.c
@@ -0,0 +1,113 @@
+/************************************************************************
+ * sched/kmm_initialize.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+
+#ifdef CONFIG_NUTTX_KERNEL
+
+/* This logic is all tentatively and, hopefully, will grow in usability.
+ * For now, the kernel-mode build uses the memory manager that is
+ * provided in the user-space build. That is awkward but reasonable for
+ * the current level of support: At present, only memory protection is
+ * provided. Kernel-mode code may call into user-mode code, but not
+ * vice-versa. So hosting the memory manager in user-space allows the
+ * memory manager to be shared in both kernel- and user-mode spaces.
+ *
+ * In the longer run, if an MMU is support that can provide virtualized
+ * memory, then some SLAB memory manager will be required in kernel-space
+ * with some kind of brk() system call to obtain mapped heap space.
+ *
+ * In the current build model, the user-space module is built first. The
+ * file user_map.h is generated in the first pass and contains the
+ * addresses of the memory manager needed in this file:
+ */
+
+#include <arch/board/user_map.h>
+
+/************************************************************************
+ * Pre-processor definition
+ ************************************************************************/
+
+/* This value is obtained from user_map.h */
+
+#define KINITIALIZE(h,s) ((kminitialize_t)CONFIG_USER_MMINIT)(h,s)
+
+/************************************************************************
+ * Private Types
+ ************************************************************************/
+
+typedef void (*kminitialize_t)(FAR void*, size_t);
+
+/************************************************************************
+ * Private Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Function: kmm_initialize
+ *
+ * Description:
+ * This is a simple redirection to the user-space mm_initialize()
+ * function.
+ *
+ * Parameters:
+ * heap_start - Address of the beginning of the (initial) memory region
+ * heap_size - The size (in bytes) if the (initial) memory region.
+ *
+ * Return Value:
+ * None
+ *
+ * Assumptions:
+ * 1. mm_initialize() resides in user-space
+ * 2. The address of the user space mm_initialize() is provided in
+ * user_map.h
+ * 3. The user-space mm_initialize() is callable from kernel-space.
+ *
+ ************************************************************************/
+
+void kmm_initialize(FAR void *heap_start, size_t heap_size)
+{
+ return KINITIALIZE(heap_start, heap_size);
+}
+
+#endif /* CONFIG_NUTTX_KERNEL */
diff --git a/nuttx/sched/kmm_kfree.c b/nuttx/sched/kmm_kfree.c
index 0370ce8ee..2e64be4bc 100644
--- a/nuttx/sched/kmm_kfree.c
+++ b/nuttx/sched/kmm_kfree.c
@@ -102,7 +102,7 @@ typedef void (*kfree_t)(FAR void *);
*
************************************************************************/
-void free(FAR void *mem)
+void kfree(FAR void *mem)
{
return KFREE(mem);
}
diff --git a/nuttx/sched/kmm_kmalloc.c b/nuttx/sched/kmm_kmalloc.c
index 01267ab48..aee5306f2 100644
--- a/nuttx/sched/kmm_kmalloc.c
+++ b/nuttx/sched/kmm_kmalloc.c
@@ -90,7 +90,7 @@ typedef FAR void *(*kmalloc_t)(size_t);
* This is a simple redirection to the user-space malloc() function.
*
* Parameters:
- * None
+ * size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
diff --git a/nuttx/sched/kmm_krealloc.c b/nuttx/sched/kmm_krealloc.c
index b52d86499..91b3448b8 100644
--- a/nuttx/sched/kmm_krealloc.c
+++ b/nuttx/sched/kmm_krealloc.c
@@ -90,7 +90,8 @@ typedef FAR void *(*krealloc_t)(FAR void*, size_t);
* This is a simple redirection to the user-space realloc() function.
*
* Parameters:
- * None
+ * oldmem - The old memory allocated
+ * size - Size (in bytes) of the new memory region to be re-allocated.
*
* Return Value:
* The address of the re-allocated memory (NULL on failure to re-allocate)
diff --git a/nuttx/sched/kmm_kzalloc.c b/nuttx/sched/kmm_kzalloc.c
index 567cd37d4..aba3cf26f 100644
--- a/nuttx/sched/kmm_kzalloc.c
+++ b/nuttx/sched/kmm_kzalloc.c
@@ -90,7 +90,7 @@ typedef FAR void *(*kzalloc_t)(size_t);
* This is a simple redirection to the user-space zalloc() function.
*
* Parameters:
- * None
+ * size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
diff --git a/nuttx/sched/kmm_semaphore.c b/nuttx/sched/kmm_semaphore.c
new file mode 100644
index 000000000..a78a0bed7
--- /dev/null
+++ b/nuttx/sched/kmm_semaphore.c
@@ -0,0 +1,140 @@
+/************************************************************************
+ * sched/kmm_semaphore.c
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 <nuttx/config.h>
+#include <nuttx/kmalloc.h>
+
+#ifdef CONFIG_NUTTX_KERNEL
+
+/* This logic is all tentatively and, hopefully, will grow in usability.
+ * For now, the kernel-mode build uses the memory manager that is
+ * provided in the user-space build. That is awkward but reasonable for
+ * the current level of support: At present, only memory protection is
+ * provided. Kernel-mode code may call into user-mode code, but not
+ * vice-versa. So hosting the memory manager in user-space allows the
+ * memory manager to be shared in both kernel- and user-mode spaces.
+ *
+ * In the longer run, if an MMU is support that can provide virtualized
+ * memory, then some SLAB memory manager will be required in kernel-space
+ * with some kind of brk() system call to obtain mapped heap space.
+ *
+ * In the current build model, the user-space module is built first. The
+ * file user_map.h is generated in the first pass and contains the
+ * addresses of the memory manager needed in this file:
+ */
+
+#include <arch/board/user_map.h>
+
+/************************************************************************
+ * Pre-processor definition
+ ************************************************************************/
+
+/* These values are obtained from user_map.h */
+
+#define KTRYSEMAPHORE() ((kmtrysemaphore_t) CONFIG_USER_MMTRYSEM )()
+#define KGIVESEMAPHORE() ((kmgivesemaphore_t)CONFIG_USER_MMGIVESEM)()
+
+/************************************************************************
+ * Private Types
+ ************************************************************************/
+
+typedef int (*kmtrysemaphore_t)(void);
+typedef void (*kmgivesemaphore_t)(void);
+
+/************************************************************************
+ * Private Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Function: kmm_trysemaphore
+ *
+ * Description:
+ * This is a simple redirection to the user-space mm_trysemaphore()
+ * function.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * OK on success; a negated errno on failure
+ *
+ * Assumptions:
+ * 1. mm_trysemaphore() resides in user-space
+ * 2. The address of the user space mm_trysemaphore() is provided in
+ * user_map.h
+ * 3. The user-space mm_semaphore() is callable from kernel-space.
+ *
+ ************************************************************************/
+
+int kmm_trysemaphore(void)
+{
+ return KTRYSEMAPHORE();
+}
+
+/************************************************************************
+ * Function: kmm_givesemaphore
+ *
+ * Description:
+ * This is a simple redirection to the user-space mm_givesemaphore()
+ * function.
+ *
+ * Parameters:
+ * None
+ *
+ * Return Value:
+ * OK on success; a negated errno on failure
+ *
+ * Assumptions:
+ * 1. mm_givesemaphore() resides in user-space
+ * 2. The address of the user space mm_givesemaphore() is provided in
+ * user_map.h
+ * 3. The user-space mm_semaphore() is callable from kernel-space.
+ *
+ ************************************************************************/
+
+void kmm_givesemaphore(void)
+{
+ KGIVESEMAPHORE();
+}
+
+#endif /* CONFIG_NUTTX_KERNEL */
diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c
index 5b5e659e7..0e44099c8 100644
--- a/nuttx/sched/os_start.c
+++ b/nuttx/sched/os_start.c
@@ -47,8 +47,9 @@
#include <nuttx/fs.h>
#include <nuttx/net.h>
#include <nuttx/lib.h>
-#include <nuttx/mm.h>
+#include <nuttx/kmalloc.h>
#include <nuttx/init.h>
+
#include "os_internal.h"
#include "sig_internal.h"
#include "wd_internal.h"
@@ -295,10 +296,10 @@ void os_start(void)
FAR void *heap_start;
size_t heap_size;
up_allocate_heap(&heap_start, &heap_size);
- mm_initialize(heap_start, heap_size);
+ kmm_initialize(heap_start, heap_size);
}
#else
- mm_initialize((void*)CONFIG_HEAP_BASE, CONFIG_HEAP_SIZE);
+ kmm_initialize((void*)CONFIG_HEAP_BASE, CONFIG_HEAP_SIZE);
#endif
/* Initialize the interrupt handling subsystem (if included) */
@@ -460,10 +461,10 @@ void os_start(void)
* possible because if the IDLE thread is running, no other task is!
*/
- if (mm_trysemaphore() == 0)
+ if (kmm_trysemaphore() == 0)
{
sched_garbagecollection();
- mm_givesemaphore();
+ kmm_givesemaphore();
}
#endif
diff --git a/nuttx/sched/sched_free.c b/nuttx/sched/sched_free.c
index 998f5458c..2bdf9670e 100644
--- a/nuttx/sched/sched_free.c
+++ b/nuttx/sched/sched_free.c
@@ -45,8 +45,6 @@
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
-#include <nuttx/mm.h>
-
#include "os_internal.h"
/************************************************************************
@@ -92,7 +90,7 @@ void sched_free(FAR void *address)
* manager to do this.
*/
- if (up_interrupt_context() || mm_trysemaphore() != 0)
+ if (up_interrupt_context() || kmm_trysemaphore() != 0)
{
/* Yes.. Delay the deallocation until a more appropriate time. */
@@ -111,7 +109,7 @@ void sched_free(FAR void *address)
/* No.. just deallocate the memory now. */
kfree(address);
- mm_givesemaphore();
+ kmm_givesemaphore();
}
}
diff --git a/nuttx/sched/sched_garbage.c b/nuttx/sched/sched_garbage.c
index 946198ede..714422bd6 100755
--- a/nuttx/sched/sched_garbage.c
+++ b/nuttx/sched/sched_garbage.c
@@ -1,7 +1,7 @@
/****************************************************************************
- * sched/work_garbage.c
+ * sched/sched_garbage.c
*
- * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without