From 0572bc4d031c68a15a0e41d9030d21cd81a4323b Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 28 May 2023 22:01:43 +0800 Subject: [PATCH] mm/mempool: Count the backtrace overhead in mempool_[dump|info[_task]] Signed-off-by: Xiang Xiao --- include/nuttx/mm/mempool.h | 8 ++++---- mm/mempool/mempool.c | 34 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/nuttx/mm/mempool.h b/include/nuttx/mm/mempool.h index f86fea3d74..7989541b40 100644 --- a/include/nuttx/mm/mempool.h +++ b/include/nuttx/mm/mempool.h @@ -39,11 +39,11 @@ ****************************************************************************/ #if CONFIG_MM_BACKTRACE >= 0 -# define MEMPOOL_REALBLOCKSIZE(pool) (ALIGN_UP(pool->blocksize + \ - sizeof(struct mempool_backtrace_s), \ - pool->blockalign)) +# define MEMPOOL_REALBLOCKSIZE(pool) (ALIGN_UP((pool)->blocksize + \ + sizeof(struct mempool_backtrace_s), \ + (pool)->blockalign)) #else -# define MEMPOOL_REALBLOCKSIZE(pool) (pool->blocksize) +# define MEMPOOL_REALBLOCKSIZE(pool) ((pool)->blocksize) #endif /**************************************************************************** diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index af3a92677b..79c370e032 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -143,11 +143,10 @@ int mempool_init(FAR struct mempool_s *pool, FAR const char *name) pool->nalloc = 0; #endif - if (pool->interruptsize > sizeof(sq_entry_t)) + if (pool->interruptsize >= blocksize) { - size_t ninterrupt = (pool->interruptsize - sizeof(sq_entry_t)) / - blocksize; - size_t size = ninterrupt * blocksize + sizeof(sq_entry_t); + size_t ninterrupt = pool->interruptsize / blocksize; + size_t size = ninterrupt * blocksize; pool->ibase = pool->alloc(pool, size); if (pool->ibase == NULL) @@ -356,6 +355,7 @@ void mempool_free(FAR struct mempool_s *pool, FAR void *blk) int mempool_info(FAR struct mempool_s *pool, FAR struct mempoolinfo_s *info) { + size_t blocksize = MEMPOOL_REALBLOCKSIZE(pool); irqstate_t flags; DEBUGASSERT(pool != NULL && info != NULL); @@ -368,10 +368,10 @@ int mempool_info(FAR struct mempool_s *pool, FAR struct mempoolinfo_s *info) #else info->aordblks = pool->nalloc; #endif - info->arena = (info->aordblks + info->ordblks + info->iordblks) * - pool->blocksize; + info->arena = + (info->aordblks + info->ordblks + info->iordblks) * blocksize; spin_unlock_irqrestore(&pool->lock, flags); - info->sizeblks = pool->blocksize; + info->sizeblks = blocksize; if (pool->wait && pool->expandsize == 0) { int semcount; @@ -395,6 +395,7 @@ struct mallinfo_task mempool_info_task(FAR struct mempool_s *pool, FAR const struct malltask *task) { + size_t blocksize = MEMPOOL_REALBLOCKSIZE(pool); irqstate_t flags = spin_lock_irqsave(&pool->lock); struct mallinfo_task info = { @@ -407,13 +408,13 @@ mempool_info_task(FAR struct mempool_s *pool, mempool_queue_lenth(&pool->iqueue); info.aordblks += count; - info.uordblks += count * pool->blocksize; + info.uordblks += count * blocksize; } #if CONFIG_MM_BACKTRACE < 0 else if (task->pid == PID_MM_ALLOC) { info.aordblks += pool->nalloc; - info.uordblks += pool->nalloc * pool->blocksize; + info.uordblks += pool->nalloc * blocksize; } #else else @@ -428,7 +429,7 @@ mempool_info_task(FAR struct mempool_s *pool, buf->seqno >= task->seqmin && buf->seqno <= task->seqmax) { info.aordblks++; - info.uordblks += pool->blocksize; + info.uordblks += blocksize; } } } @@ -460,6 +461,8 @@ mempool_info_task(FAR struct mempool_s *pool, void mempool_memdump(FAR struct mempool_s *pool, FAR const struct mm_memdump_s *dump) { + size_t blocksize = MEMPOOL_REALBLOCKSIZE(pool); + if (dump->pid == PID_MM_FREE) { FAR sq_entry_t *entry; @@ -467,15 +470,13 @@ void mempool_memdump(FAR struct mempool_s *pool, sq_for_every(&pool->queue, entry) { syslog(LOG_INFO, "%12zu%*p\n", - pool->blocksize, MM_PTR_FMT_WIDTH, - (FAR char *)entry); + blocksize, MM_PTR_FMT_WIDTH, (FAR char *)entry); } sq_for_every(&pool->iqueue, entry) { syslog(LOG_INFO, "%12zu%*p\n", - pool->blocksize, MM_PTR_FMT_WIDTH, - (FAR char *)entry); + blocksize, MM_PTR_FMT_WIDTH, (FAR char *)entry); } } #if CONFIG_MM_BACKTRACE >= 0 @@ -506,9 +507,8 @@ void mempool_memdump(FAR struct mempool_s *pool, # endif syslog(LOG_INFO, "%6d%12zu%12lu%*p%s\n", - (int)buf->pid, pool->blocksize, buf->seqno, - MM_PTR_FMT_WIDTH, - ((FAR char *)buf - pool->blocksize), bt); + (int)buf->pid, blocksize, buf->seqno, + MM_PTR_FMT_WIDTH, ((FAR char *)buf - blocksize), bt); } } }