mm/mempool: support backtrace function for mempool

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
dongjiuzhu1
2022-11-06 23:27:44 +08:00
committed by Xiang Xiao
parent af3978c1fa
commit c386a1a2d9
6 changed files with 388 additions and 33 deletions
+82
View File
@@ -25,6 +25,7 @@
* Included Files
****************************************************************************/
#include <malloc.h>
#include <sys/types.h>
#include <nuttx/list.h>
@@ -47,6 +48,14 @@ struct mempool_procfs_entry_s
{
FAR const char *name;
FAR struct mempool_procfs_entry_s *next;
#if CONFIG_MM_BACKTRACE >= 0
/* This is dynamic control flag whether to turn on backtrace in the heap,
* you can set it by /proc/mempool.
*/
bool backtrace;
#endif
};
#endif
@@ -67,6 +76,9 @@ struct mempool_s
struct list_node list; /* The free block list in normal mempool */
struct list_node ilist; /* The free block list in interrupt mempool */
struct list_node elist; /* The expand block list for normal mempool */
#if CONFIG_MM_BACKTRACE >= 0
struct list_node alist; /* The used block list in mempool */
#endif
size_t nused; /* The number of used block in mempool */
spinlock_t lock; /* The protect lock to mempool */
sem_t waitsem; /* The semaphore of waiter get free block */
@@ -102,6 +114,8 @@ struct mempoolinfo_s
unsigned long nwaiter; /* This is the number of waiter for mempool */
};
#define mempoolinfo_task mallinfo_task
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@@ -182,6 +196,27 @@ void mempool_free(FAR struct mempool_s *pool, FAR void *blk);
int mempool_info(FAR struct mempool_s *pool, FAR struct mempoolinfo_s *info);
/****************************************************************************
* Name: mempool_memdump
*
* Description:
* mempool_memdump returns a memory info about specified pid of
* task/thread. if pid equals -1, this function will dump all allocated
* node and output backtrace for every allocated node for this mempool,
* if pid equals -2, this function will dump all free node for this
* mempool, and if pid is greater than or equal to 0, will dump pid
* allocated node and output backtrace.
*
* Input Parameters:
* pool - Address of the memory pool to be used.
* info - The pointer of mempoolinfo.
*
* Returned Value:
* OK on success; A negated errno value on any failure.
****************************************************************************/
void mempool_memdump(FAR struct mempool_s *pool, pid_t pid);
/****************************************************************************
* Name: mempool_deinit
*
@@ -194,6 +229,20 @@ int mempool_info(FAR struct mempool_s *pool, FAR struct mempoolinfo_s *info);
int mempool_deinit(FAR struct mempool_s *pool);
/****************************************************************************
* Name: mempool_info_task
*
* Description:
* Get memory pool's memory used info.
*
* Input Parameters:
* pool - Address of the memory pool to be used.
* info - Memory info.
****************************************************************************/
int mempool_info_task(FAR struct mempool_s *pool,
FAR struct mempoolinfo_task *info);
/****************************************************************************
* Name: mempool_procfs_register
*
@@ -352,6 +401,26 @@ size_t mempool_multiple_alloc_size(FAR void *blk);
FAR void *mempool_multiple_memalign(FAR struct mempool_multiple_s *mpool,
size_t alignment, size_t size);
/****************************************************************************
* Name: mempool_multiple_memdump
*
* Description:
* mempool_multiple_memdump returns a memory info about specified pid of
* task/thread. if pid equals -1, this function will dump all allocated
* node and output backtrace for every allocated node for this multiple
* mempool, if pid equals -2, this function will dump all free node for
* this multiple mempool, and if pid is greater than or equal to 0, will
* dump pid allocated node and output backtrace.
*
* Input Parameters:
* mpool - The handle of multiple memory pool to be used.
* pid - The pid of task.
*
****************************************************************************/
void mempool_multiple_memdump(FAR struct mempool_multiple_s *mpool,
pid_t pid);
/****************************************************************************
* Name: mempool_multiple_fixed_alloc
*
@@ -426,6 +495,19 @@ void mempool_multiple_fixed_free(FAR struct mempool_multiple_s *mpool,
int mempool_multiple_deinit(FAR struct mempool_multiple_s *mpool);
/****************************************************************************
* Name: mempool_multiple_info_task
* Description:
* Get multiple memory pool's memory used info.
*
* Input Parameters:
* mpool - The handle of multiple memory pool to be used.
* info - Memory info.
****************************************************************************/
void mempool_multiple_info_task(FAR struct mempool_multiple_s *mpool,
FAR struct mempoolinfo_task *info);
#undef EXTERN
#if defined(__cplusplus)
}