mm: Rename PID_MM_INVALID to PID_MM_LEAK

to express the intent more clear

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-05-28 20:09:42 +08:00 committed by Petro Karashchenko
parent b00237ac01
commit 9b6cd96671
6 changed files with 40 additions and 51 deletions

View file

@ -35,7 +35,7 @@
#define PID_MM_FREE ((pid_t)-4) #define PID_MM_FREE ((pid_t)-4)
#define PID_MM_ALLOC ((pid_t)-3) #define PID_MM_ALLOC ((pid_t)-3)
#define PID_MM_INVALID ((pid_t)-2) #define PID_MM_LEAK ((pid_t)-2)
#define PID_MM_MEMPOOL ((pid_t)-1) #define PID_MM_MEMPOOL ((pid_t)-1)
/* For Linux and MacOS compatibility */ /* For Linux and MacOS compatibility */

View file

@ -412,10 +412,8 @@ mempool_info_task(FAR struct mempool_s *pool,
#if CONFIG_MM_BACKTRACE < 0 #if CONFIG_MM_BACKTRACE < 0
else if (task->pid == PID_MM_ALLOC) else if (task->pid == PID_MM_ALLOC)
{ {
size_t count = pool->nalloc; info.aordblks += pool->nalloc;
info.uordblks += pool->nalloc * pool->blocksize;
info.aordblks += count;
info.uordblks += count * pool->blocksize;
} }
#else #else
else else
@ -425,15 +423,12 @@ mempool_info_task(FAR struct mempool_s *pool,
list_for_every_entry(&pool->alist, buf, struct mempool_backtrace_s, list_for_every_entry(&pool->alist, buf, struct mempool_backtrace_s,
node) node)
{ {
if (task->pid == buf->pid || task->pid == PID_MM_ALLOC || if ((task->pid == PID_MM_ALLOC || task->pid == buf->pid ||
(task->pid == PID_MM_INVALID && (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
nxsched_get_tcb(buf->pid) == NULL)) buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
{ {
if (buf->seqno >= task->seqmin && buf->seqno <= task->seqmax) info.aordblks++;
{ info.uordblks += pool->blocksize;
info.aordblks++;
info.uordblks += pool->blocksize;
}
} }
} }
} }
@ -491,7 +486,7 @@ void mempool_memdump(FAR struct mempool_s *pool,
list_for_every_entry(&pool->alist, buf, struct mempool_backtrace_s, list_for_every_entry(&pool->alist, buf, struct mempool_backtrace_s,
node) node)
{ {
if ((buf->pid == dump->pid || dump->pid == PID_MM_ALLOC) && if ((dump->pid == PID_MM_ALLOC || dump->pid == buf->pid) &&
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax) buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
{ {
# if CONFIG_MM_BACKTRACE > 0 # if CONFIG_MM_BACKTRACE > 0

View file

@ -87,7 +87,9 @@ static void mallinfo_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
static void mallinfo_task_handler(FAR struct mm_allocnode_s *node, static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
FAR void *arg) FAR void *arg)
{ {
FAR struct mm_mallinfo_handler_s *handle = arg; FAR struct mm_mallinfo_handler_s *handler = arg;
FAR const struct malltask *task = handler->task;
FAR struct mallinfo_task *info = handler->info;
size_t nodesize = SIZEOF_MM_NODE(node); size_t nodesize = SIZEOF_MM_NODE(node);
/* Check if the node corresponds to an allocated memory chunk */ /* Check if the node corresponds to an allocated memory chunk */
@ -96,30 +98,25 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
{ {
DEBUGASSERT(nodesize >= SIZEOF_MM_ALLOCNODE); DEBUGASSERT(nodesize >= SIZEOF_MM_ALLOCNODE);
#if CONFIG_MM_BACKTRACE < 0 #if CONFIG_MM_BACKTRACE < 0
if (handle->task->pid == PID_MM_ALLOC) if (task->pid == PID_MM_ALLOC)
{ {
handle->info->aordblks++; info->aordblks++;
handle->info->uordblks += nodesize; info->uordblks += nodesize;
} }
#else #else
if (handle->task->pid == PID_MM_ALLOC || if ((task->pid == PID_MM_ALLOC || task->pid == node->pid ||
handle->task->pid == node->pid || (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(node->pid))) &&
(handle->task->pid == PID_MM_INVALID && node->seqno >= task->seqmin && node->seqno <= task->seqmax)
nxsched_get_tcb(node->pid) == NULL))
{ {
if (node->seqno >= handle->task->seqmin && info->aordblks++;
node->seqno <= handle->task->seqmax) info->uordblks += nodesize;
{
handle->info->aordblks++;
handle->info->uordblks += nodesize;
}
} }
#endif #endif
} }
else if (handle->task->pid == PID_MM_FREE) else if (task->pid == PID_MM_FREE)
{ {
handle->info->aordblks++; info->aordblks++;
handle->info->uordblks += nodesize; info->uordblks += nodesize;
} }
} }

View file

@ -80,7 +80,7 @@ void mm_dump_handler(FAR struct tcb_s *tcb, FAR void *arg)
struct mallinfo_task info; struct mallinfo_task info;
struct malltask task; struct malltask task;
task.pid = tcb ? tcb->pid : PID_MM_INVALID; task.pid = tcb ? tcb->pid : PID_MM_LEAK;
task.seqmin = 0; task.seqmin = 0;
task.seqmax = ULONG_MAX; task.seqmax = ULONG_MAX;
info = mm_mallinfo_task(arg, &task); info = mm_mallinfo_task(arg, &task);

View file

@ -61,7 +61,7 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
#if CONFIG_MM_BACKTRACE < 0 #if CONFIG_MM_BACKTRACE < 0
if (dump->pid == PID_MM_ALLOC) if (dump->pid == PID_MM_ALLOC)
#else #else
if ((dump->pid == PID_MM_ALLOC || node->pid == dump->pid) && if ((dump->pid == PID_MM_ALLOC || dump->pid == node->pid) &&
node->seqno >= dump->seqmin && node->seqno <= dump->seqmax) node->seqno >= dump->seqmin && node->seqno <= dump->seqmax)
#endif #endif
{ {

View file

@ -284,6 +284,8 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used,
FAR struct memdump_backtrace_s *buf; FAR struct memdump_backtrace_s *buf;
#endif #endif
FAR struct mm_mallinfo_handler_s *handler = user; FAR struct mm_mallinfo_handler_s *handler = user;
FAR const struct malltask *task = handler->task;
FAR struct mallinfo_task *info = handler->info;
#if CONFIG_MM_BACKTRACE >= 0 #if CONFIG_MM_BACKTRACE >= 0
size -= sizeof(struct memdump_backtrace_s); size -= sizeof(struct memdump_backtrace_s);
@ -292,30 +294,25 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used,
if (used) if (used)
{ {
#if CONFIG_MM_BACKTRACE < 0 #if CONFIG_MM_BACKTRACE < 0
if (handler->task->pid == PID_MM_ALLOC) if (task->pid == PID_MM_ALLOC)
{ {
handler->info->aordblks++; info->aordblks++;
handler->info->uordblks += size; info->uordblks += size;
} }
#else #else
if (handler->task->pid == PID_MM_ALLOC || if ((task->pid == PID_MM_ALLOC || task->pid == buf->pid ||
handler->task->pid == buf->pid || (task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
(handler->task->pid == PID_MM_INVALID && buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
nxsched_get_tcb(buf->pid) == NULL))
{ {
if (buf->seqno >= handler->task->seqmin && info->aordblks++;
buf->seqno <= handler->task->seqmax) info->uordblks += size;
{
handler->info->aordblks++;
handler->info->uordblks += size;
}
} }
#endif #endif
} }
else if (handler->task->pid == PID_MM_FREE) else if (task->pid == PID_MM_FREE)
{ {
handler->info->aordblks++; info->aordblks++;
handler->info->uordblks += size; info->uordblks += size;
} }
#endif #endif
} }
@ -417,9 +414,9 @@ static void memdump_handler(FAR void *ptr, size_t size, int used,
if (used) if (used)
{ {
#if CONFIG_MM_BACKTRACE < 0 #if CONFIG_MM_BACKTRACE < 0
if (pid == PID_MM_ALLOC) if (dump->pid == PID_MM_ALLOC)
#else #else
if ((dump->pid == PID_MM_ALLOC || buf->pid == dump->pid) && if ((dump->pid == PID_MM_ALLOC || dump->pid == buf->pid) &&
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax) buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
#endif #endif
{ {