diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c index bdbc8de5000..969a5e87466 100644 --- a/arch/sim/src/sim/sim_heap.c +++ b/arch/sim/src/sim/sim_heap.c @@ -397,8 +397,8 @@ struct mallinfo mm_mallinfo(struct mm_heap_s *heap) * ****************************************************************************/ -struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap, - FAR const struct mm_memdump_s *dump) +struct mallinfo_task mm_mallinfo_task(struct mm_heap_s *heap, + const struct malltask *task) { struct mallinfo_task info = { diff --git a/fs/procfs/fs_procfsmeminfo.c b/fs/procfs/fs_procfsmeminfo.c index 882016d6b85..5153d6fe1f1 100644 --- a/fs/procfs/fs_procfsmeminfo.c +++ b/fs/procfs/fs_procfsmeminfo.c @@ -444,8 +444,9 @@ static ssize_t memdump_read(FAR struct file *filep, FAR char *buffer, #if CONFIG_MM_BACKTRACE >= 0 buffer += copysize; buflen -= copysize; - linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN, - "The current sequence number %lu\n", g_mm_seqno); + linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN, + "The current sequence number %lu\n", + g_mm_seqno); totalsize += procfs_memcpy(procfile->line, linesize, buffer, buflen, &offset); diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 44d22932271..8d574c10d9a 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -886,20 +886,20 @@ static ssize_t proc_heap(FAR struct proc_file_s *procfile, size_t copysize; size_t totalsize = 0; struct mallinfo_task info; - struct mm_memdump_s dump; + struct malltask task; - dump.pid = tcb->pid; - dump.seqmin = 0; - dump.seqmax = ULONG_MAX; + task.pid = tcb->pid; + task.seqmin = 0; + task.seqmax = ULONG_MAX; #ifdef CONFIG_MM_KERNEL_HEAP if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL) { - info = kmm_mallinfo_task(&dump); + info = kmm_mallinfo_task(&task); } else #endif { - info = mallinfo_task(&dump); + info = mallinfo_task(&task); } /* Show the heap alloc size */ diff --git a/include/malloc.h b/include/malloc.h index 5760538a0d8..41049c33731 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -52,7 +52,7 @@ struct mallinfo * by free (not in use) chunks. */ }; -struct mm_memdump_s +struct malltask { pid_t pid; /* Process id */ #if CONFIG_MM_BACKTRACE >= 0 @@ -67,14 +67,6 @@ struct mallinfo_task int uordblks; /* This is the total size of memory occupied for task */ }; -/**************************************************************************** - * Public data - ****************************************************************************/ - -#if CONFIG_MM_BACKTRACE >= 0 -extern unsigned long g_mm_seqno; -#endif - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -86,7 +78,7 @@ extern "C" struct mallinfo mallinfo(void); size_t malloc_size(FAR void *ptr); -struct mallinfo_task mallinfo_task(FAR const struct mm_memdump_s *dump); +struct mallinfo_task mallinfo_task(FAR const struct malltask *task); #if defined(__cplusplus) } diff --git a/include/nuttx/mm/mempool.h b/include/nuttx/mm/mempool.h index 14fd11ff92a..f86fea3d74c 100644 --- a/include/nuttx/mm/mempool.h +++ b/include/nuttx/mm/mempool.h @@ -25,11 +25,11 @@ * Included Files ****************************************************************************/ -#include #include #include #include +#include #include #include #include @@ -260,7 +260,7 @@ int mempool_deinit(FAR struct mempool_s *pool); * * Input Parameters: * pool - Address of the memory pool to be used. - * dump - The information of what need dump. + * task - The information of what need retrieve. * * Returned Value: * Statistics of memory information based on dump. @@ -268,7 +268,7 @@ int mempool_deinit(FAR struct mempool_s *pool); struct mallinfo_task mempool_info_task(FAR struct mempool_s *pool, - FAR const struct mm_memdump_s *dump); + FAR const struct malltask *task); /**************************************************************************** * Name: mempool_procfs_register @@ -510,7 +510,7 @@ mempool_multiple_mallinfo(FAR struct mempool_multiple_s *mpool); * * Input Parameters: * mpool - The handle of multiple memory pool to be used. - * dump - The information of what need dump. + * task - The information of what need retrieve. * * Returned Value: * Statistics of memory information based on dump. @@ -518,7 +518,7 @@ mempool_multiple_mallinfo(FAR struct mempool_multiple_s *mpool); struct mallinfo_task mempool_multiple_info_task(FAR struct mempool_multiple_s *mpool, - FAR const struct mm_memdump_s *dump); + FAR const struct malltask *task); #undef EXTERN #if defined(__cplusplus) diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 1c17c035bfb..004c65bbc2c 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -99,6 +99,8 @@ # endif #endif +#define mm_memdump_s malltask + #define MM_BACKTRACE_INVALID_PID ((pid_t)-4) #define MM_BACKTRACE_MEMPOOL_PID ((pid_t)-3) #define MM_BACKTRACE_FREE_PID ((pid_t)-2) @@ -123,6 +125,10 @@ extern "C" #define EXTERN extern #endif +#if CONFIG_MM_BACKTRACE >= 0 +extern unsigned long g_mm_seqno; +#endif + /* User heap structure: * * - Flat build: In the FLAT build, the user heap structure is a globally @@ -316,14 +322,14 @@ void kmm_extend(FAR void *mem, size_t size, int region); struct mallinfo mm_mallinfo(FAR struct mm_heap_s *heap); struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap, - FAR const struct mm_memdump_s *dump); + FAR const struct malltask *task); /* Functions contained in kmm_mallinfo.c ************************************/ #ifdef CONFIG_MM_KERNEL_HEAP struct mallinfo kmm_mallinfo(void); # if CONFIG_MM_BACKTRACE >= 0 -struct mallinfo_task kmm_mallinfo_task(FAR const struct mm_memdump_s *dump); +struct mallinfo_task kmm_mallinfo_task(FAR const struct malltask *task); # endif #endif diff --git a/mm/kmm_heap/kmm_mallinfo.c b/mm/kmm_heap/kmm_mallinfo.c index 6056389e43d..482f338f687 100644 --- a/mm/kmm_heap/kmm_mallinfo.c +++ b/mm/kmm_heap/kmm_mallinfo.c @@ -55,8 +55,8 @@ struct mallinfo kmm_mallinfo(void) * ****************************************************************************/ -struct mallinfo_task kmm_mallinfo_task(FAR const struct mm_memdump_s *dump) +struct mallinfo_task kmm_mallinfo_task(FAR const struct malltask *task) { - return mm_mallinfo_task(g_kmmheap, dump); + return mm_mallinfo_task(g_kmmheap, task); } #endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 6a4e2fc3305..862842354d3 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -393,7 +393,7 @@ int mempool_info(FAR struct mempool_s *pool, FAR struct mempoolinfo_s *info) struct mallinfo_task mempool_info_task(FAR struct mempool_s *pool, - FAR const struct mm_memdump_s *dump) + FAR const struct malltask *task) { irqstate_t flags = spin_lock_irqsave(&pool->lock); struct mallinfo_task info = @@ -401,7 +401,7 @@ mempool_info_task(FAR struct mempool_s *pool, 0, 0 }; - if (dump->pid == MM_BACKTRACE_FREE_PID) + if (task->pid == MM_BACKTRACE_FREE_PID) { size_t count = mempool_queue_lenth(&pool->queue) + mempool_queue_lenth(&pool->iqueue); @@ -410,7 +410,7 @@ mempool_info_task(FAR struct mempool_s *pool, info.uordblks += count * pool->blocksize; } #if CONFIG_MM_BACKTRACE < 0 - else if (dump->pid == MM_BACKTRACE_ALLOC_PID) + else if (task->pid == MM_BACKTRACE_ALLOC_PID) { size_t count = pool->nalloc; @@ -425,11 +425,11 @@ mempool_info_task(FAR struct mempool_s *pool, list_for_every_entry(&pool->alist, buf, struct mempool_backtrace_s, node) { - if (dump->pid == buf->pid || dump->pid == MM_BACKTRACE_ALLOC_PID || - (dump->pid == MM_BACKTRACE_INVALID_PID && + if (task->pid == buf->pid || task->pid == MM_BACKTRACE_ALLOC_PID || + (task->pid == MM_BACKTRACE_INVALID_PID && nxsched_get_tcb(buf->pid) == NULL)) { - if (buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax) + if (buf->seqno >= task->seqmin && buf->seqno <= task->seqmax) { info.aordblks++; info.uordblks += pool->blocksize; diff --git a/mm/mempool/mempool_multiple.c b/mm/mempool/mempool_multiple.c index 038c00e9acc..1885a9b5685 100644 --- a/mm/mempool/mempool_multiple.c +++ b/mm/mempool/mempool_multiple.c @@ -768,7 +768,7 @@ mempool_multiple_mallinfo(FAR struct mempool_multiple_s *mpool) struct mallinfo_task mempool_multiple_info_task(FAR struct mempool_multiple_s *mpool, - FAR const struct mm_memdump_s *dump) + FAR const struct malltask *task) { int i; struct mallinfo_task info; @@ -779,7 +779,7 @@ mempool_multiple_info_task(FAR struct mempool_multiple_s *mpool, for (i = 0; i < mpool->npools; i++) { - info = mempool_info_task(mpool->pools + i, dump); + info = mempool_info_task(mpool->pools + i, task); ret.aordblks += info.aordblks; ret.uordblks += info.uordblks; } diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c index 5c8c5a60a18..83bb4d7168f 100644 --- a/mm/mm_heap/mm_mallinfo.c +++ b/mm/mm_heap/mm_mallinfo.c @@ -37,7 +37,7 @@ struct mm_mallinfo_handler_s { - FAR const struct mm_memdump_s *dump; + FAR const struct malltask *task; FAR struct mallinfo_task *info; }; @@ -96,19 +96,19 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node, { DEBUGASSERT(nodesize >= SIZEOF_MM_ALLOCNODE); #if CONFIG_MM_BACKTRACE < 0 - if (handle->dump->pid == MM_BACKTRACE_ALLOC_PID) + if (handle->task->pid == MM_BACKTRACE_ALLOC_PID) { handle->info->aordblks++; handle->info->uordblks += nodesize; } #else - if (handle->dump->pid == MM_BACKTRACE_ALLOC_PID || - handle->dump->pid == node->pid || - (handle->dump->pid == MM_BACKTRACE_INVALID_PID && + if (handle->task->pid == MM_BACKTRACE_ALLOC_PID || + handle->task->pid == node->pid || + (handle->task->pid == MM_BACKTRACE_INVALID_PID && nxsched_get_tcb(node->pid) == NULL)) { - if (node->seqno >= handle->dump->seqmin && - node->seqno <= handle->dump->seqmax) + if (node->seqno >= handle->task->seqmin && + node->seqno <= handle->task->seqmax) { handle->info->aordblks++; handle->info->uordblks += nodesize; @@ -116,7 +116,7 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node, } #endif } - else if (handle->dump->pid == MM_BACKTRACE_FREE_PID) + else if (handle->task->pid == MM_BACKTRACE_FREE_PID) { handle->info->aordblks++; handle->info->uordblks += nodesize; @@ -170,7 +170,7 @@ struct mallinfo mm_mallinfo(FAR struct mm_heap_s *heap) ****************************************************************************/ struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap, - FAR const struct mm_memdump_s *dump) + FAR const struct malltask *task) { struct mm_mallinfo_handler_s handle; struct mallinfo_task info = @@ -179,11 +179,10 @@ struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap, }; #if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0 - - info = mempool_multiple_info_task(heap->mm_mpool, dump); + info = mempool_multiple_info_task(heap->mm_mpool, task); #endif - handle.dump = dump; + handle.task = task; handle.info = &info; mm_foreach(heap, mallinfo_task_handler, &handle); diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index 9a5f7d44923..ea4f4a0f8d3 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -78,14 +78,14 @@ static void free_delaylist(FAR struct mm_heap_s *heap) void mm_dump_handler(FAR struct tcb_s *tcb, FAR void *arg) { struct mallinfo_task info; - struct mm_memdump_s dump; + struct malltask task; - dump.pid = tcb ? tcb->pid : MM_BACKTRACE_INVALID_PID; - dump.seqmin = 0; - dump.seqmax = ULONG_MAX; - info = mm_mallinfo_task(arg, &dump); + task.pid = tcb ? tcb->pid : MM_BACKTRACE_INVALID_PID; + task.seqmin = 0; + task.seqmax = ULONG_MAX; + info = mm_mallinfo_task(arg, &task); mwarn("pid:%5d, used:%10d, nused:%10d\n", - dump.pid, info.uordblks, info.aordblks); + task.pid, info.uordblks, info.aordblks); } #endif diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index ac3eb689d9e..02711b0780b 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -122,7 +122,7 @@ struct memdump_backtrace_s struct mm_mallinfo_handler_s { - FAR const struct mm_memdump_s *dump; + FAR const struct malltask *task; FAR struct mallinfo_task *info; }; @@ -292,19 +292,19 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used, if (used) { #if CONFIG_MM_BACKTRACE < 0 - if (handler->dump->pid = MM_BACKTRACE_ALLOC_PID) + if (handler->task->pid = MM_BACKTRACE_ALLOC_PID) { handler->info->aordblks++; handler->info->uordblks += size; } #else - if (handler->dump->pid == MM_BACKTRACE_ALLOC_PID || - handler->dump->pid == buf->pid || - (handler->dump->pid == MM_BACKTRACE_INVALID_PID && + if (handler->task->pid == MM_BACKTRACE_ALLOC_PID || + handler->task->pid == buf->pid || + (handler->task->pid == MM_BACKTRACE_INVALID_PID && nxsched_get_tcb(buf->pid) == NULL)) { - if (buf->seqno >= handler->dump->seqmin && - buf->seqno <= handler->dump->seqmax) + if (buf->seqno >= handler->task->seqmin && + buf->seqno <= handler->task->seqmax) { handler->info->aordblks++; handler->info->uordblks += size; @@ -312,7 +312,7 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used, } #endif } - else if (handler->dump->pid == MM_BACKTRACE_FREE_PID) + else if (handler->task->pid == MM_BACKTRACE_FREE_PID) { handler->info->aordblks++; handler->info->uordblks += size; @@ -905,7 +905,7 @@ struct mallinfo mm_mallinfo(FAR struct mm_heap_s *heap) } struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap, - FAR const struct mm_memdump_s *dump) + FAR const struct malltask *task) { struct mm_mallinfo_handler_s handle; struct mallinfo_task info = @@ -920,10 +920,10 @@ struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap, #endif #if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0 - info = mempool_multiple_info_task(heap->mm_mpool, dump); + info = mempool_multiple_info_task(heap->mm_mpool, task); #endif - handle.dump = dump; + handle.task = task; handle.info = &info; #if CONFIG_MM_REGIONS > 1 for (region = 0; region < heap->mm_nregions; region++) diff --git a/mm/umm_heap/umm_mallinfo.c b/mm/umm_heap/umm_mallinfo.c index 15a1aca415c..6c6a144c1fa 100644 --- a/mm/umm_heap/umm_mallinfo.c +++ b/mm/umm_heap/umm_mallinfo.c @@ -57,7 +57,7 @@ struct mallinfo mallinfo(void) * ****************************************************************************/ -struct mallinfo_task mallinfo_task(FAR const struct mm_memdump_s *dump) +struct mallinfo_task mallinfo_task(FAR const struct malltask *task) { - return mm_mallinfo_task(USR_HEAP, dump); + return mm_mallinfo_task(USR_HEAP, task); }