You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/28 16:12:09 UTC
[incubator-nuttx] 02/03: mm/mm_heap: using LOG2_CEIL to generate MM_MIN_SHIFT at compile time
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 5982cafbe0e4a5be85edf61a5a8edb411d2f6dee
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Tue Oct 25 22:24:26 2022 +0800
mm/mm_heap: using LOG2_CEIL to generate MM_MIN_SHIFT at compile time
Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
mm/mm_heap/mm.h | 35 +++++------------------------------
1 file changed, 5 insertions(+), 30 deletions(-)
diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index a53b63aa60..65ee07cc56 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -29,6 +29,7 @@
#include <nuttx/mutex.h>
#include <nuttx/fs/procfs.h>
+#include <nuttx/lib/math32.h>
#include <assert.h>
#include <execinfo.h>
@@ -60,38 +61,14 @@
* minor performance losses.
*/
+#define MM_MIN_SHIFT LOG2_CEIL(sizeof(struct mm_freenode_s))
#if defined(CONFIG_MM_SMALL) && UINTPTR_MAX <= UINT32_MAX
-/* Two byte offsets; Pointers may be 2 or 4 bytes;
- * sizeof(struct mm_freenode_s) is 8 or 12 bytes.
- * REVISIT: We could do better on machines with 16-bit addressing.
- */
-
-# define MM_MIN_SHIFT_ ( 4) /* 16 bytes */
# define MM_MAX_SHIFT (15) /* 32 Kb */
-
-#elif defined(CONFIG_HAVE_LONG_LONG)
-/* Four byte offsets; Pointers may be 4 or 8 bytes
- * sizeof(struct mm_freenode_s) is 16 or 24 bytes.
- */
-
-# if UINTPTR_MAX <= UINT32_MAX
-# define MM_MIN_SHIFT_ ( 4) /* 16 bytes */
-# elif UINTPTR_MAX <= UINT64_MAX
-# define MM_MIN_SHIFT_ ( 5) /* 32 bytes */
-# endif
-# define MM_MAX_SHIFT (22) /* 4 Mb */
-
#else
-/* Four byte offsets; Pointers must be 4 bytes.
- * sizeof(struct mm_freenode_s) is 16 bytes.
- */
-
-# define MM_MIN_SHIFT_ ( 4) /* 16 bytes */
# define MM_MAX_SHIFT (22) /* 4 Mb */
#endif
#if CONFIG_MM_BACKTRACE == 0
-# define MM_MIN_SHIFT (MM_MIN_SHIFT_ + 1)
# define MM_ADD_BACKTRACE(heap, ptr) \
do \
{ \
@@ -100,7 +77,6 @@
} \
while (0)
#elif CONFIG_MM_BACKTRACE > 0
-# define MM_MIN_SHIFT (MM_MIN_SHIFT_ + 2)
# define MM_ADD_BACKTRACE(heap, ptr) \
do \
{ \
@@ -121,7 +97,6 @@
while (0)
#else
# define MM_ADD_BACKTRACE(heap, ptr)
-# define MM_MIN_SHIFT MM_MIN_SHIFT_
#endif
/* All other definitions derive from these two */
@@ -185,9 +160,6 @@ struct mm_allocnode_s
mmsize_t preceding; /* Size of the preceding chunk */
};
-static_assert(SIZEOF_MM_ALLOCNODE <= MM_MIN_CHUNK,
- "Error size for struct mm_allocnode_s\n");
-
/* This describes a free chunk */
struct mm_freenode_s
@@ -204,6 +176,9 @@ struct mm_freenode_s
FAR struct mm_freenode_s *blink;
};
+static_assert(SIZEOF_MM_ALLOCNODE <= MM_MIN_CHUNK,
+ "Error size for struct mm_allocnode_s\n");
+
static_assert(SIZEOF_MM_FREENODE <= MM_MIN_CHUNK,
"Error size for struct mm_freenode_s\n");