From 5d8e661a1ae769a1338f2880f508486f2e02247c Mon Sep 17 00:00:00 2001 From: yuchen Date: Thu, 9 Apr 2015 20:26:03 +0800 Subject: [PATCH] update lab6 :: deleting timer --- labcodes/lab6/kern/schedule/sched.c | 76 ------------------- labcodes/lab6/kern/schedule/sched.h | 21 ----- labcodes/lab6/kern/trap/trap.c | 9 +-- labcodes/lab7/kern/trap/trap.c | 12 +-- labcodes/lab8/kern/trap/trap.c | 12 +-- .../lab6_result/kern/schedule/sched.c | 75 ------------------ .../lab6_result/kern/schedule/sched.h | 21 ----- labcodes_answer/lab6_result/kern/trap/trap.c | 1 - 8 files changed, 17 insertions(+), 210 deletions(-) diff --git a/labcodes/lab6/kern/schedule/sched.c b/labcodes/lab6/kern/schedule/sched.c index 0d7e491..f655529 100644 --- a/labcodes/lab6/kern/schedule/sched.c +++ b/labcodes/lab6/kern/schedule/sched.c @@ -98,79 +98,3 @@ schedule(void) { } local_intr_restore(intr_flag); } - -// add timer to timer_list -void -add_timer(timer_t *timer) { - bool intr_flag; - local_intr_save(intr_flag); - { - assert(timer->expires > 0 && timer->proc != NULL); - assert(list_empty(&(timer->timer_link))); - list_entry_t *le = list_next(&timer_list); - while (le != &timer_list) { - timer_t *next = le2timer(le, timer_link); - if (timer->expires < next->expires) { - next->expires -= timer->expires; - break; - } - timer->expires -= next->expires; - le = list_next(le); - } - list_add_before(le, &(timer->timer_link)); - } - local_intr_restore(intr_flag); -} - -// del timer from timer_list -void -del_timer(timer_t *timer) { - bool intr_flag; - local_intr_save(intr_flag); - { - if (!list_empty(&(timer->timer_link))) { - if (timer->expires != 0) { - list_entry_t *le = list_next(&(timer->timer_link)); - if (le != &timer_list) { - timer_t *next = le2timer(le, timer_link); - next->expires += timer->expires; - } - } - list_del_init(&(timer->timer_link)); - } - } - local_intr_restore(intr_flag); -} - -// call scheduler to update tick related info, and check the timer is expired? If expired, then wakup proc -void -run_timer_list(void) { - bool intr_flag; - local_intr_save(intr_flag); - { - list_entry_t *le = list_next(&timer_list); - if (le != &timer_list) { - timer_t *timer = le2timer(le, timer_link); - assert(timer->expires != 0); - timer->expires --; - while (timer->expires == 0) { - le = list_next(le); - struct proc_struct *proc = timer->proc; - if (proc->wait_state != 0) { - assert(proc->wait_state & WT_INTERRUPTED); - } - else { - warn("process %d's wait_state == 0.\n", proc->pid); - } - wakeup_proc(proc); - del_timer(timer); - if (le == &timer_list) { - break; - } - timer = le2timer(le, timer_link); - } - } - sched_class_proc_tick(current); - } - local_intr_restore(intr_flag); -} diff --git a/labcodes/lab6/kern/schedule/sched.h b/labcodes/lab6/kern/schedule/sched.h index 766ac03..2b3230d 100644 --- a/labcodes/lab6/kern/schedule/sched.h +++ b/labcodes/lab6/kern/schedule/sched.h @@ -9,24 +9,6 @@ struct proc_struct; -typedef struct { - unsigned int expires; //the expire time - struct proc_struct *proc; //the proc wait in this timer. If the expire time is end, then this proc will be scheduled - list_entry_t timer_link; //the timer list -} timer_t; - -#define le2timer(le, member) \ -to_struct((le), timer_t, member) - -// init a timer -static inline timer_t * -timer_init(timer_t *timer, struct proc_struct *proc, int expires) { - timer->expires = expires; - timer->proc = proc; - list_init(&(timer->timer_link)); - return timer; -} - struct run_queue; // The introduction of scheduling classes is borrrowed from Linux, and makes the @@ -65,9 +47,6 @@ struct run_queue { void sched_init(void); void wakeup_proc(struct proc_struct *proc); void schedule(void); -void add_timer(timer_t *timer); // add timer to timer_list -void del_timer(timer_t *timer); // del timer from timer_list -void run_timer_list(void); // call scheduler to update tick related info, and check the timer is expired? If expired, then wakup proc #endif /* !__KERN_SCHEDULE_SCHED_H__ */ diff --git a/labcodes/lab6/kern/trap/trap.c b/labcodes/lab6/kern/trap/trap.c index 80f7ecb..91e9873 100644 --- a/labcodes/lab6/kern/trap/trap.c +++ b/labcodes/lab6/kern/trap/trap.c @@ -225,12 +225,9 @@ trap_dispatch(struct trapframe *tf) { * Every TICK_NUM cycle, you should set current process's current->need_resched = 1 */ /* LAB6 YOUR CODE */ - /* IMPORTANT FUNCTIONS: - * run_timer_list - *---------------------- - * you should update your lab5 code (just add ONE or TWO lines of code): - * Every tick, you should update the system time, iterate the timers, and trigger the timers which are end to call scheduler. - * You can use one funcitons to finish all these things. + /* you should upate you lab5 code + * IMPORTANT FUNCTIONS: + * sched_class_proc_tick */ break; case IRQ_OFFSET + IRQ_COM1: diff --git a/labcodes/lab7/kern/trap/trap.c b/labcodes/lab7/kern/trap/trap.c index 80f7ecb..28672a0 100644 --- a/labcodes/lab7/kern/trap/trap.c +++ b/labcodes/lab7/kern/trap/trap.c @@ -225,12 +225,14 @@ trap_dispatch(struct trapframe *tf) { * Every TICK_NUM cycle, you should set current process's current->need_resched = 1 */ /* LAB6 YOUR CODE */ - /* IMPORTANT FUNCTIONS: + /* you should upate you lab5 code + * IMPORTANT FUNCTIONS: + * sched_class_proc_tick + */ + /* LAB7 YOUR CODE */ + /* you should upate you lab6 code + * IMPORTANT FUNCTIONS: * run_timer_list - *---------------------- - * you should update your lab5 code (just add ONE or TWO lines of code): - * Every tick, you should update the system time, iterate the timers, and trigger the timers which are end to call scheduler. - * You can use one funcitons to finish all these things. */ break; case IRQ_OFFSET + IRQ_COM1: diff --git a/labcodes/lab8/kern/trap/trap.c b/labcodes/lab8/kern/trap/trap.c index b063ec6..f25e8c9 100644 --- a/labcodes/lab8/kern/trap/trap.c +++ b/labcodes/lab8/kern/trap/trap.c @@ -225,12 +225,14 @@ trap_dispatch(struct trapframe *tf) { * Every TICK_NUM cycle, you should set current process's current->need_resched = 1 */ /* LAB6 YOUR CODE */ - /* IMPORTANT FUNCTIONS: + /* you should upate you lab5 code + * IMPORTANT FUNCTIONS: + * sched_class_proc_tick + */ + /* LAB7 YOUR CODE */ + /* you should upate you lab6 code + * IMPORTANT FUNCTIONS: * run_timer_list - *---------------------- - * you should update your lab5 code (just add ONE or TWO lines of code): - * Every tick, you should update the system time, iterate the timers, and trigger the timers which are end to call scheduler. - * You can use one funcitons to finish all these things. */ break; case IRQ_OFFSET + IRQ_COM1: diff --git a/labcodes_answer/lab6_result/kern/schedule/sched.c b/labcodes_answer/lab6_result/kern/schedule/sched.c index 0d7e491..9298d89 100644 --- a/labcodes_answer/lab6_result/kern/schedule/sched.c +++ b/labcodes_answer/lab6_result/kern/schedule/sched.c @@ -99,78 +99,3 @@ schedule(void) { local_intr_restore(intr_flag); } -// add timer to timer_list -void -add_timer(timer_t *timer) { - bool intr_flag; - local_intr_save(intr_flag); - { - assert(timer->expires > 0 && timer->proc != NULL); - assert(list_empty(&(timer->timer_link))); - list_entry_t *le = list_next(&timer_list); - while (le != &timer_list) { - timer_t *next = le2timer(le, timer_link); - if (timer->expires < next->expires) { - next->expires -= timer->expires; - break; - } - timer->expires -= next->expires; - le = list_next(le); - } - list_add_before(le, &(timer->timer_link)); - } - local_intr_restore(intr_flag); -} - -// del timer from timer_list -void -del_timer(timer_t *timer) { - bool intr_flag; - local_intr_save(intr_flag); - { - if (!list_empty(&(timer->timer_link))) { - if (timer->expires != 0) { - list_entry_t *le = list_next(&(timer->timer_link)); - if (le != &timer_list) { - timer_t *next = le2timer(le, timer_link); - next->expires += timer->expires; - } - } - list_del_init(&(timer->timer_link)); - } - } - local_intr_restore(intr_flag); -} - -// call scheduler to update tick related info, and check the timer is expired? If expired, then wakup proc -void -run_timer_list(void) { - bool intr_flag; - local_intr_save(intr_flag); - { - list_entry_t *le = list_next(&timer_list); - if (le != &timer_list) { - timer_t *timer = le2timer(le, timer_link); - assert(timer->expires != 0); - timer->expires --; - while (timer->expires == 0) { - le = list_next(le); - struct proc_struct *proc = timer->proc; - if (proc->wait_state != 0) { - assert(proc->wait_state & WT_INTERRUPTED); - } - else { - warn("process %d's wait_state == 0.\n", proc->pid); - } - wakeup_proc(proc); - del_timer(timer); - if (le == &timer_list) { - break; - } - timer = le2timer(le, timer_link); - } - } - sched_class_proc_tick(current); - } - local_intr_restore(intr_flag); -} diff --git a/labcodes_answer/lab6_result/kern/schedule/sched.h b/labcodes_answer/lab6_result/kern/schedule/sched.h index 766ac03..2b3230d 100644 --- a/labcodes_answer/lab6_result/kern/schedule/sched.h +++ b/labcodes_answer/lab6_result/kern/schedule/sched.h @@ -9,24 +9,6 @@ struct proc_struct; -typedef struct { - unsigned int expires; //the expire time - struct proc_struct *proc; //the proc wait in this timer. If the expire time is end, then this proc will be scheduled - list_entry_t timer_link; //the timer list -} timer_t; - -#define le2timer(le, member) \ -to_struct((le), timer_t, member) - -// init a timer -static inline timer_t * -timer_init(timer_t *timer, struct proc_struct *proc, int expires) { - timer->expires = expires; - timer->proc = proc; - list_init(&(timer->timer_link)); - return timer; -} - struct run_queue; // The introduction of scheduling classes is borrrowed from Linux, and makes the @@ -65,9 +47,6 @@ struct run_queue { void sched_init(void); void wakeup_proc(struct proc_struct *proc); void schedule(void); -void add_timer(timer_t *timer); // add timer to timer_list -void del_timer(timer_t *timer); // del timer from timer_list -void run_timer_list(void); // call scheduler to update tick related info, and check the timer is expired? If expired, then wakup proc #endif /* !__KERN_SCHEDULE_SCHED_H__ */ diff --git a/labcodes_answer/lab6_result/kern/trap/trap.c b/labcodes_answer/lab6_result/kern/trap/trap.c index 17569e2..7238a8a 100644 --- a/labcodes_answer/lab6_result/kern/trap/trap.c +++ b/labcodes_answer/lab6_result/kern/trap/trap.c @@ -233,7 +233,6 @@ trap_dispatch(struct trapframe *tf) { */ ticks ++; assert(current != NULL); - run_timer_list(); break; case IRQ_OFFSET + IRQ_COM1: c = cons_getc();