From 6826a5ce6ec9f6c5b8047f0bb68f6fc20c960281 Mon Sep 17 00:00:00 2001 From: "jc_.kim" Date: Fri, 7 Jul 2017 15:00:21 +0900 Subject: [PATCH] Modify heapinfo for excluding child stacksize from parent heapsize --- apps/system/utils/kdbg_heapinfo.c | 22 +++++++++++++++------- os/arch/arm/src/common/up_createstack.c | 4 +++- os/include/tinyara/mm/mm.h | 1 + os/mm/mm_heap/mm_heapinfo.c | 25 ++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/apps/system/utils/kdbg_heapinfo.c b/apps/system/utils/kdbg_heapinfo.c index 1ec6f48..0fda46b 100644 --- a/apps/system/utils/kdbg_heapinfo.c +++ b/apps/system/utils/kdbg_heapinfo.c @@ -34,18 +34,23 @@ static void kdbg_heapinfo_init(FAR struct tcb_s *tcb, FAR void *arg) static void kdbg_heapinfo_task(FAR struct tcb_s *tcb, FAR void *arg) { - if (tcb->pid == 0) { - tcb->adj_stack_size = CONFIG_IDLETHREAD_STACKSIZE; - } - printf("%3d | ", tcb->pid); + struct mm_allocnode_s *node; + node = (struct mm_allocnode_s *)(tcb->stack_alloc_ptr - SIZEOF_MM_ALLOCNODE); + + printf("%3d", tcb->pid); #if defined(CONFIG_SCHED_HAVE_PARENT) && !defined(HAVE_GROUP_MEMBERS) - printf("%5d | ", tcb->ppid); + printf(" | %5d", tcb->ppid); #endif - printf("%5d | %9d | %9d | ", tcb->adj_stack_size, tcb->curr_alloc_size, tcb->peak_alloc_size); + if (tcb->pid == 0) { + printf(" | %5d", CONFIG_IDLETHREAD_STACKSIZE); + } else { + printf(" | %5d", node->size); + } + printf(" | %9d | %9d", tcb->curr_alloc_size, tcb->peak_alloc_size); /* Show task name and arguments */ #if CONFIG_TASK_NAME_SIZE > 0 - printf("%s(", tcb->name); + printf(" | %s(", tcb->name); #else printf("("); #endif @@ -102,6 +107,9 @@ int kdbg_heapinfo(int argc, char **args) printf("-------|-----------|-----------|----------\n"); sched_foreach(kdbg_heapinfo_task, NULL); + printf("\n** NOTED **\n"); + printf("* Idle Task's stack is not allocated in heap region\n"); + printf("* And another stack size is allocated stack size + alloc node size(task:32/pthread:20)\n\n"); return OK; usage: diff --git a/os/arch/arm/src/common/up_createstack.c b/os/arch/arm/src/common/up_createstack.c index 1ff752d..7dff9db 100644 --- a/os/arch/arm/src/common/up_createstack.c +++ b/os/arch/arm/src/common/up_createstack.c @@ -236,7 +236,9 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) #ifdef CONFIG_STACK_COLORATION up_stack_color(tcb->stack_alloc_ptr, tcb->adj_stack_size); #endif - +#ifdef CONFIG_DEBUG_MM_HEAPINFO + heapinfo_exclude_stacksize(tcb->stack_alloc_ptr); +#endif board_led_on(LED_STACKCREATED); return OK; } diff --git a/os/include/tinyara/mm/mm.h b/os/include/tinyara/mm/mm.h index 7f71c8a..63f9c35 100644 --- a/os/include/tinyara/mm/mm.h +++ b/os/include/tinyara/mm/mm.h @@ -608,6 +608,7 @@ void heapinfo_update_node(FAR struct mm_allocnode_s *node, mmaddress_t caller_re void heapinfo_add_size(pid_t pid, mmsize_t size); void heapinfo_subtract_size(pid_t pid, mmsize_t size); void heapinfo_update_total_size(struct mm_heap_s *heap, mmsize_t size); +void heapinfo_exclude_stacksize(void *stack_ptr); #endif #ifdef CONFIG_DEBUG_MM_HEAPINFO diff --git a/os/mm/mm_heap/mm_heapinfo.c b/os/mm/mm_heap/mm_heapinfo.c index 1b8e5a7..caa545c 100644 --- a/os/mm/mm_heap/mm_heapinfo.c +++ b/os/mm/mm_heap/mm_heapinfo.c @@ -81,6 +81,7 @@ void heapinfo_parse(FAR struct mm_heap_s *heap, int mode, pid_t pid) size_t mxordblk = 0; int ordblks = 0; /* Number of non-inuse chunks */ size_t fordblks = 0; /* Total non-inuse space */ + int stack_resource; int nonsched_resource; int nonsched_idx; @@ -93,8 +94,9 @@ void heapinfo_parse(FAR struct mm_heap_s *heap, int mode, pid_t pid) #else #define region 0 #endif - /* initialize the nonsched */ + /* initialize the nonsched and stack resource */ nonsched_resource = 0; + stack_resource = 0; for (nonsched_idx = 0; nonsched_idx < CONFIG_MAX_TASKS; nonsched_idx++) { nonsched_list[nonsched_idx] = -1; nonsched_size[nonsched_idx] = 0; @@ -137,6 +139,8 @@ void heapinfo_parse(FAR struct mm_heap_s *heap, int mode, pid_t pid) #if CONFIG_TASK_NAME_SIZE > 0 if (node->pid == -1 && mode != HEAPINFO_SIMPLE) { printf("INT Context\n"); + } else if (node->pid == -2) { + stack_resource += node->size; } else if (sched_gettcb(node->pid) == NULL) { nonsched_list[MM_PIDHASH(node->pid)] = node->pid; nonsched_size[MM_PIDHASH(node->pid)] += node->size; @@ -170,6 +174,7 @@ void heapinfo_parse(FAR struct mm_heap_s *heap, int mode, pid_t pid) printf("Free Size : %d\n", fordblks); printf("Largest Free Node Size : %d\n", mxordblk); printf("Number of Free Node : %d\n", ordblks); + printf("\nStack Resources : %d", stack_resource); printf("\nNon Scheduled Task Resources : %d\n", nonsched_resource); if (mode != HEAPINFO_SIMPLE) { @@ -251,4 +256,22 @@ void heapinfo_update_node(FAR struct mm_allocnode_s *node, mmaddress_t caller_re } return; } + +/**************************************************************************** + * Name: heapinfo_exclude_stacksize + * + * Description: + * when create a stack, subtract the stacksize from parent + ****************************************************************************/ +void heapinfo_exclude_stacksize(void *stack_ptr) +{ + struct mm_allocnode_s *node; + struct tcb_s *rtcb; + + node = (struct mm_allocnode_s *)(stack_ptr - SIZEOF_MM_ALLOCNODE); + rtcb = sched_gettcb(node->pid); + + rtcb->curr_alloc_size -= node->size; + node->pid = -2; +} #endif -- 2.7.4