finish exec4.10-11

This commit is contained in:
KAAAsS 2021-05-18 12:35:43 +08:00
parent 64e90d6037
commit 339f843bae
Signed by: KAAAsS
GPG Key ID: D56625F3E671882F
5 changed files with 27 additions and 7 deletions

View File

@ -13,4 +13,4 @@ define add-symbol-file-auto
end end
add-symbol-file-auto ./build/kernel.img add-symbol-file-auto ./build/kernel.img
add-symbol-file-auto ./user/build/ramdisk/yield_single.bin add-symbol-file-auto ./user/build/ramdisk/yield_spin.bin

View File

@ -32,7 +32,7 @@ void exception_init_per_cpu(void)
* Uncomment the timer_init() when you are handling preemptive * Uncomment the timer_init() when you are handling preemptive
* shceduling * shceduling
*/ */
// timer_init(); timer_init();
/** /**
* Lab3: Your code here * Lab3: Your code here

View File

@ -50,6 +50,8 @@ void handle_irq(int type)
* Lab4 * Lab4
* Do you miss something? * Do you miss something?
*/ */
sched();
eret_to_thread(switch_context());
} }
void plat_handle_irq(void) void plat_handle_irq(void)

View File

@ -106,6 +106,7 @@ int rr_sched_dequeue(struct thread *thread)
// 出队 // 出队
list_del(&thread->ready_queue_node); list_del(&thread->ready_queue_node);
thread->thread_ctx->state = TS_INTER; thread->thread_ctx->state = TS_INTER;
thread->thread_ctx->sc->budget = DEFAULT_BUDGET;
return 0; return 0;
} }
@ -164,11 +165,18 @@ int rr_sched(void)
{ {
struct thread *dest_thread; struct thread *dest_thread;
// 若当前有运行进程,放入队列 // 若当前有运行进程
if (current_thread != NULL && current_thread->thread_ctx != NULL if (current_thread != NULL && current_thread->thread_ctx != NULL) {
&& current_thread->thread_ctx->type != TYPE_IDLE) { // 预算非 0
rr_sched_enqueue(current_thread); if (current_thread->thread_ctx->sc->budget != 0) {
kdebug("[RR] Cpu #%d yield thread %lx to queue\n", smp_get_cpu_id(), current_thread->thread_ctx); return 0;
}
// 若非空闲线程,放入队列
if (current_thread->thread_ctx->type != TYPE_IDLE) {
rr_sched_enqueue(current_thread);
kdebug("[RR] Cpu #%d yield thread %lx to queue\n", smp_get_cpu_id(), current_thread->thread_ctx);
}
} }
// 选择新线程 // 选择新线程
@ -221,6 +229,12 @@ int rr_sched_init(void)
*/ */
void rr_sched_handle_timer_irq(void) void rr_sched_handle_timer_irq(void)
{ {
// 预算
if (current_thread != NULL && current_thread->thread_ctx != NULL) {
if (current_thread->thread_ctx->sc->budget > 0) {
current_thread->thread_ctx->sc->budget--;
}
}
} }
struct sched_ops rr = { struct sched_ops rr = {

View File

@ -140,6 +140,10 @@ u64 switch_context(void)
*/ */
void sys_yield(void) void sys_yield(void)
{ {
// 重置预算
current_thread->thread_ctx->sc->budget = 0;
// 调度
sched(); sched();
eret_to_thread(switch_context()); eret_to_thread(switch_context());
} }