Modify CPU context scheduler

This commit is contained in:
songyanguang 2025-01-17 19:23:34 +08:00
parent b03330f0f8
commit 994145bd63
6 changed files with 35 additions and 3 deletions

View File

@ -75,7 +75,7 @@ void kernel_intr_handler(struct trapframe* tf)
panic("Intr at kernel mode should never happen by design.\n");
}
extern void context_switch(struct context**, struct context*);
extern void context_switch(struct context*, struct context*);
void syscall_arch_handler(struct trapframe* tf)
{
uint64_t ec = tf->cause;
@ -97,7 +97,7 @@ void syscall_arch_handler(struct trapframe* tf)
assert(cur_cpu()->task != NULL);
ERROR("Error Task: %s\n", cur_cpu()->task->name);
sys_exit(cur_cpu()->task);
context_switch(&cur_cpu()->task->thread_context.context, cur_cpu()->scheduler);
context_switch(&cur_cpu()->task->thread_context.context, &cur_cpu()->scheduler);
panic("dabort end should never be reashed.\n");
}
}

View File

@ -37,7 +37,11 @@ struct CPU {
int cpuid;
struct Thread* task;
#ifndef __riscv
struct context* scheduler;
#else
struct context scheduler;
#endif
};
extern struct CPU global_cpus[NR_CPU];

View File

@ -292,7 +292,11 @@ static void task_state_set_running(struct Thread* task)
uintptr_t riscv_kernel_satp = 0;
#endif
struct Thread* next_task_emergency = NULL;
#ifndef __riscv
extern void context_switch(struct context**, struct context*);
#else
extern void context_switch(struct context*, struct context*);
#endif
static void _scheduler(struct SchedulerRightGroup right_group)
{
struct MmuCommonDone* p_mmu_driver = AchieveResource(&right_group.mmu_driver_tag);

View File

@ -48,7 +48,11 @@ Modification:
#include "syscall.h"
#include "task.h"
#ifndef __riscv
extern void context_switch(struct context**, struct context*);
#else
extern void context_switch(struct context*, struct context*);
#endif
__attribute__((optimize("O0"))) void dabort_handler(struct trapframe* r)
{
#ifndef __riscv
@ -74,7 +78,11 @@ __attribute__((optimize("O0"))) void dabort_handler(struct trapframe* r)
xizi_enter_kernel();
sys_exit(cur_task);
assert(cur_cpu()->task == NULL);
#ifndef __riscv
context_switch(&cur_task->thread_context.context, cur_cpu()->scheduler);
#else
context_switch(cur_task->thread_context.context, &cur_cpu()->scheduler);
#endif
panic("dabort end should never be reashed.\n");
}
@ -103,6 +111,10 @@ __attribute__((optimize("O0"))) void iabort_handler(struct trapframe* r)
xizi_enter_kernel();
sys_exit(cur_task);
assert(cur_cpu()->task == NULL);
#ifndef __riscv
context_switch(&cur_task->thread_context.context, cur_cpu()->scheduler);
#else
context_switch(cur_task->thread_context.context, &cur_cpu()->scheduler);
#endif
panic("iabort end should never be reashed.\n");
}

View File

@ -53,7 +53,11 @@ void default_interrupt_routine(int irq)
ERROR("Interrupt %d has been asserted\n", irq);
}
#ifndef __riscv
extern void context_switch(struct context**, struct context*);
#else
extern void context_switch(struct context*, struct context*);
#endif
void intr_irq_dispatch(struct trapframe* tf)
{
xizi_enter_kernel();
@ -86,7 +90,11 @@ void intr_irq_dispatch(struct trapframe* tf)
if (cur_cpu()->task == NULL || current_task->state != RUNNING) {
cur_cpu()->task = NULL;
#ifndef __riscv
context_switch(&current_task->thread_context.context, cur_cpu()->scheduler);
#else
context_switch(current_task->thread_context.context, &cur_cpu()->scheduler);
#endif
}
assert(current_task == cur_cpu()->task);

View File

@ -45,7 +45,11 @@ bool swi_distributer_init(struct SwiDispatcherRightGroup* _right_group)
return p_intr_driver != NULL;
}
#ifndef __riscv
extern void context_switch(struct context**, struct context*);
#else
extern void context_switch(struct context*, struct context*);
#endif
void software_irq_dispatch(struct trapframe* tf)
{
xizi_enter_kernel();
@ -68,7 +72,7 @@ void software_irq_dispatch(struct trapframe* tf)
#ifndef __riscv
context_switch(&cur_task->thread_context.context, cur_cpu()->scheduler);
#else
context_switch(&cur_task->thread_context.context, &cpu->scheduler);
context_switch(cur_task->thread_context.context, &cpu->scheduler);
#endif
}
if (syscall_num == SYSCALL_EXIT) {