add memory usage

This commit is contained in:
TXuian
2024-10-29 16:17:43 +08:00
parent 968d66e5a9
commit 7b6c93d391
37 changed files with 654 additions and 115 deletions
+3 -4
View File
@@ -35,7 +35,7 @@ Modification:
#include "kalloc.h"
#include "memspace.h"
#include "multicores.h"
#include "scheduler.h"
#include "schedule_algo.h"
#include "syscall.h"
#include "task.h"
#include "trap_common.h"
@@ -176,7 +176,7 @@ static void _dealloc_task_cb(struct Thread* task)
/* free thread's kernel stack */
if (task->thread_context.kern_stack_addr) {
kfree((char*)task->thread_context.kern_stack_addr);
kfree_by_ownership(task->memspace->mem_usage.tag, (char*)task->thread_context.kern_stack_addr);
}
/* free memspace if needed to */
@@ -235,7 +235,7 @@ static struct Thread* _new_task_cb(struct MemSpace* pmemspace)
/* init main thread of task */
task->thread_context.task = task;
// alloc stack page for task
if ((void*)(task->thread_context.kern_stack_addr = (uintptr_t)kalloc(USER_STACK_SIZE)) == NULL) {
if ((void*)(task->thread_context.kern_stack_addr = (uintptr_t)kalloc_by_ownership(pmemspace->mem_usage.tag, USER_STACK_SIZE)) == NULL) {
/* here inside, will no free memspace */
_dealloc_task_cb(task);
return NULL;
@@ -288,7 +288,6 @@ extern void context_switch(struct context**, struct context*);
static void _scheduler(struct SchedulerRightGroup right_group)
{
struct MmuCommonDone* p_mmu_driver = AchieveResource(&right_group.mmu_driver_tag);
struct XiziTrapDriver* p_intr_driver = AchieveResource(&right_group.intr_driver_tag);
struct Thread* next_task;
struct CPU* cpu = cur_cpu();