summaryrefslogtreecommitdiff
path: root/nuttx/mm
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-11 20:33:58 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-11 20:33:58 +0000
commit63240531781806cb440108ebd5ad0c3dc62510d3 (patch)
tree386d184c161ad982f82fe673bdf69319f84cca6b /nuttx/mm
parent205242a575697630d073edc02a6341e6d9be22a6 (diff)
downloadpx4-nuttx-63240531781806cb440108ebd5ad0c3dc62510d3.tar.gz
px4-nuttx-63240531781806cb440108ebd5ad0c3dc62510d3.tar.bz2
px4-nuttx-63240531781806cb440108ebd5ad0c3dc62510d3.zip
Update to granule allocator; Update to ENC28j60 driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5130 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/mm')
-rw-r--r--nuttx/mm/Kconfig30
-rw-r--r--nuttx/mm/Makefile7
-rw-r--r--nuttx/mm/mm_gran.h26
-rw-r--r--nuttx/mm/mm_granalloc.c20
-rw-r--r--nuttx/mm/mm_granfree.c35
-rw-r--r--nuttx/mm/mm_graninit.c11
6 files changed, 112 insertions, 17 deletions
diff --git a/nuttx/mm/Kconfig b/nuttx/mm/Kconfig
index bf3540138..2e5bc95db 100644
--- a/nuttx/mm/Kconfig
+++ b/nuttx/mm/Kconfig
@@ -42,3 +42,33 @@ config HEAP2_SIZE
---help---
The size of the second heap region.
+config GRAN
+ bool "Enable Granule Allocator"
+ default n
+ ---help---
+ Enable granual allocator support. Allocations will be aligned to the
+ granule size; allocations will be in units of the granule size.
+ Larger granules will give better performance and less overhead but
+ more losses of memory due to alignment and quantization waste.
+
+ NOTE: The current implementation also restricts the maximum
+ allocation size to 32 granaules. That restriction could be
+ eliminated with some additional coding effort.
+
+config GRAN_SINGLE
+ bool "Single Granule Allocator"
+ default n
+ depends on GRAN
+ ---help---
+ Select if there is only one instance of the granule allocator (i.e.,
+ gran_initialize will be called only once. In this case, (1) there
+ are a few optimizations that can can be done and (2) the GRAN_HANDLE
+ is not needed.
+
+config DEBUG_GRAN
+ bool "Granule Allocator Debug"
+ default n
+ depends on GRAN && DEBUG
+ ---help---
+ Just like CONFIG_DEBUG_MM, but only generates ouput from the gran
+ allocation logic.
diff --git a/nuttx/mm/Makefile b/nuttx/mm/Makefile
index 7e6eb68a7..ef168f0db 100644
--- a/nuttx/mm/Makefile
+++ b/nuttx/mm/Makefile
@@ -36,10 +36,15 @@
-include $(TOPDIR)/Make.defs
ASRCS =
-AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \
mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \
mm_memalign.c mm_free.c mm_mallinfo.c
+
+ifeq ($(CONFIG_GRAN),y)
+CSRCS = mm_graninit.c mm_granalloc.c mm_granfree.c
+endif
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
diff --git a/nuttx/mm/mm_gran.h b/nuttx/mm/mm_gran.h
index 6f5f890ed..d8a334e29 100644
--- a/nuttx/mm/mm_gran.h
+++ b/nuttx/mm/mm_gran.h
@@ -42,17 +42,41 @@
#include <nuttx/config.h>
+#include <stdint.h>
+
#include <nuttx/gran.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* Sizes of things */
+
#define SIZEOF_GAT(n) \
((n + 31) >> 5)
#define SIZEOF_GRAN_S(n) \
(sizeof(struct gran_s) + sizeof(uint32_t) * (SIZEOF_GAT(n) - 1))
+/* Debug */
+
+#ifdef CONFIG_CPP_HAVE_VARARGS
+# ifdef CONFIG_DEBUG_GRAM
+# define gramdbg(format, arg...) dbg(format, ##arg)
+# define gramvdbg(format, arg...) vdbg(format, ##arg)
+# else
+# define gramdbg(format, arg...) mdbg(format, ##arg)
+# define gramvdbg(format, arg...) mvdbg(format, ##arg)
+# endif
+#else
+# ifdef CONFIG_DEBUG_GRAM
+# define gramdbg dbg
+# define gramvdbg vdbg
+# else
+# define gramdbg (void)
+# define gramvdbg (void)
+# endif
+#endif
+
/****************************************************************************
* Public Types
****************************************************************************/
@@ -64,7 +88,7 @@ struct gran_s
uint8_t log2gran; /* Log base 2 of the size of one granule */
uint16_t ngranules; /* The total number of (aligned) granules in the heap */
uintptr_t heapstart; /* The aligned start of the granule heap */
- uint32_t gat[i]; /* Start of the granule allocation table */
+ uint32_t gat[1]; /* Start of the granule allocation table */
};
/****************************************************************************
diff --git a/nuttx/mm/mm_granalloc.c b/nuttx/mm/mm_granalloc.c
index f94f447e3..a8802a6c5 100644
--- a/nuttx/mm/mm_granalloc.c
+++ b/nuttx/mm/mm_granalloc.c
@@ -39,8 +39,14 @@
#include <nuttx/config.h>
+#include <assert.h>
+
#include <nuttx/gran.h>
+#include "mm_gran.h"
+
+#ifdef CONFIG_GRAN
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -61,7 +67,7 @@
*
****************************************************************************/
-static inline FAR void *gran_mark_allocated(FAR struct gran_s *priv, uintptr_t alloc, unsigned int ngranules)
+static inline void gran_mark_allocated(FAR struct gran_s *priv, uintptr_t alloc, unsigned int ngranules)
{
unsigned int granno;
unsigned int gatidx;
@@ -128,13 +134,13 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
int i;
int j;
- DEBUGASSERT(priv);
+ DEBUGASSERT(priv && size <= 32 * (1 << priv->log2gran));
if (priv && size > 0)
{
/* How many contiguous granules we we need to find? */
- tmpmask = (1 << log2gran) - 1;
- ngranules = (size + tmpmask) >> log2gran;
+ tmpmask = (1 << priv->log2gran) - 1;
+ ngranules = (size + tmpmask) >> priv->log2gran;
/* Then create mask for that number of granules */
@@ -188,11 +194,11 @@ static inline FAR void *gran_common_alloc(FAR struct gran_s *priv, size_t size)
*/
curr >>= 1;
- if (next & 1)
+ if ((next & 1) != 0)
{
curr |= 0x80000000;
}
- next >> 1;
+ next >>= 1;
/* Increment the next candidate allocation address */
@@ -239,3 +245,5 @@ FAR void *gran_alloc(GRAN_HANDLE handle, size_t size)
return gran_common_alloc((FAR struct gran_s *)handle, size);
}
#endif
+
+#endif /* CONFIG_GRAN */
diff --git a/nuttx/mm/mm_granfree.c b/nuttx/mm/mm_granfree.c
index 4679ae62b..e359cded8 100644
--- a/nuttx/mm/mm_granfree.c
+++ b/nuttx/mm/mm_granfree.c
@@ -39,8 +39,14 @@
#include <nuttx/config.h>
+#include <assert.h>
+
#include <nuttx/gran.h>
+#include "mm_gran.h"
+
+#ifdef CONFIG_GRAN
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -66,18 +72,29 @@ static inline void gran_common_free(FAR struct gran_s *priv,
unsigned int granno;
unsigned int gatidx;
unsigned int gatbit;
+ unsigned int granmask;
+ unsigned int ngranules;
unsigned int avail;
- uint32_t mask;
+ uint32_t gatmask;
+
+ DEBUGASSERT(priv && memory && size <= 32 * (1 << priv->log2gran));
- /* Determine the granule number of the allocation */
+ /* Determine the granule number of the first granule in the allocation */
- granno = (alloc - priv->heapstart) >> priv->log2gran;
+ granno = ((uintptr_t)memory - priv->heapstart) >> priv->log2gran;
- /* Determine the GAT table index associated with the allocation */
+ /* Determine the GAT table index and bit number associated with the
+ * allocation.
+ */
gatidx = granno >> 5;
gatbit = granno & 31;
+ /* Determine the number of granules in the allocation */
+
+ granmask = (1 << priv->log2gran) - 1;
+ ngranules = (size + granmask) >> priv->log2gran;
+
/* Clear bits in the first GAT entry */
avail = 32 - gatbit;
@@ -91,15 +108,15 @@ static inline void gran_common_free(FAR struct gran_s *priv,
else
{
- mask = 0xffffffff >> (32 - ngranules);
- priv->gat[gatidx] &= ~(mask << gatbit);
+ gatmask = 0xffffffff >> (32 - ngranules);
+ priv->gat[gatidx] &= ~(gatmask << gatbit);
return;
}
/* Clear bits in the second GAT entry */
- mask = 0xffffffff >> (32 - ngranules);
- priv->gat[gatidx+1] &= ~(mask << gatbit);
+ gatmask = 0xffffffff >> (32 - ngranules);
+ priv->gat[gatidx+1] &= ~(gatmask << gatbit);
}
/****************************************************************************
@@ -132,3 +149,5 @@ void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size)
return gran_common_free((FAR struct gran_s *)handle, memory, size);
}
#endif
+
+#endif /* CONFIG_GRAN */
diff --git a/nuttx/mm/mm_graninit.c b/nuttx/mm/mm_graninit.c
index 99b499155..46b5f5ff1 100644
--- a/nuttx/mm/mm_graninit.c
+++ b/nuttx/mm/mm_graninit.c
@@ -39,8 +39,14 @@
#include <nuttx/config.h>
+#include <stdlib.h>
+
#include <nuttx/gran.h>
+#include "mm_gran.h"
+
+#ifdef CONFIG_GRAN
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -108,7 +114,7 @@ static inline FAR struct gran_s *gran_common_initialize(FAR void *heapstart,
priv->log2gran = log2gran;
priv->ngranules = ngranules;
- priv->heapstart = alignedstart
+ priv->heapstart = alignedstart;
}
return priv;
@@ -161,3 +167,6 @@ GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gr
}
#endif
+#endif /* CONFIG_GRAN */
+
+