finish exec4.10-11
This commit is contained in:
parent
64e90d6037
commit
339f843bae
@ -13,4 +13,4 @@ define add-symbol-file-auto
|
||||
end
|
||||
|
||||
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
|
||||
|
@ -32,7 +32,7 @@ void exception_init_per_cpu(void)
|
||||
* Uncomment the timer_init() when you are handling preemptive
|
||||
* shceduling
|
||||
*/
|
||||
// timer_init();
|
||||
timer_init();
|
||||
|
||||
/**
|
||||
* Lab3: Your code here
|
||||
|
@ -50,6 +50,8 @@ void handle_irq(int type)
|
||||
* Lab4
|
||||
* Do you miss something?
|
||||
*/
|
||||
sched();
|
||||
eret_to_thread(switch_context());
|
||||
}
|
||||
|
||||
void plat_handle_irq(void)
|
||||
|
@ -106,6 +106,7 @@ int rr_sched_dequeue(struct thread *thread)
|
||||
// 出队
|
||||
list_del(&thread->ready_queue_node);
|
||||
thread->thread_ctx->state = TS_INTER;
|
||||
thread->thread_ctx->sc->budget = DEFAULT_BUDGET;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -164,12 +165,19 @@ int rr_sched(void)
|
||||
{
|
||||
struct thread *dest_thread;
|
||||
|
||||
// 若当前有运行进程,放入队列
|
||||
if (current_thread != NULL && current_thread->thread_ctx != NULL
|
||||
&& current_thread->thread_ctx->type != TYPE_IDLE) {
|
||||
// 若当前有运行进程
|
||||
if (current_thread != NULL && current_thread->thread_ctx != NULL) {
|
||||
// 预算非 0
|
||||
if (current_thread->thread_ctx->sc->budget != 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 选择新线程
|
||||
dest_thread = rr_sched_choose_thread();
|
||||
@ -221,6 +229,12 @@ int rr_sched_init(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 = {
|
||||
|
@ -140,6 +140,10 @@ u64 switch_context(void)
|
||||
*/
|
||||
void sys_yield(void)
|
||||
{
|
||||
// 重置预算
|
||||
current_thread->thread_ctx->sc->budget = 0;
|
||||
|
||||
// 调度
|
||||
sched();
|
||||
eret_to_thread(switch_context());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user