mm/mm_heap: using LOG2_CEIL to generate MM_MIN_SHIFT at compile time

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2022-10-25 22:24:26 +08:00 committed by Xiang Xiao
parent 6f208524a1
commit 5982cafbe0

View File

@ -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");