From: AceVest Date: Tue, 3 Jun 2014 16:30:07 +0000 (+0800) Subject: sched X-Git-Tag: 0.3.0~55 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=83b0970850730998376b9fe4d626d58f3d9b0c0d;p=kernel.git sched --- diff --git a/drivers/keyboard.c b/drivers/keyboard.c index c77ef68..c75b181 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -33,10 +33,11 @@ static struct -extern void reboot(); -extern void poweroff(); -extern void ide_debug(); -extern void ide_status(); +void reboot(); +void poweroff(); +void ide_debug(); +void ide_status(); +void debug_sched(); void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) { unsigned char scan_code; @@ -50,9 +51,14 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) if(scan_code == 0x13) // r ide_debug(); - if(scan_code == 0x1F) + if(scan_code == 0x1F) // s ide_status(); + if(scan_code == 0x14) // t + debug_sched(); + +// if(scan_code + if(count < KBD_BUF_SIZE) { count++; diff --git a/include/sched.h b/include/sched.h index 618f499..4073ba2 100644 --- a/include/sched.h +++ b/include/sched.h @@ -31,8 +31,8 @@ pid_t get_next_pid(); void init_tsk_cr3(task_union *); -inline void wake_up(pWaitQueue wq); -inline void sleep_on(pWaitQueue wq); +inline void wake_up(wait_queue_t * wq); +inline void sleep_on(wait_queue_t * wq); #define TASK_CNT 64 diff --git a/include/task.h b/include/task.h index d1b8cae..6a20e8f 100644 --- a/include/task.h +++ b/include/task.h @@ -58,7 +58,7 @@ typedef union task_union list_head_t list; - WaitQueue wait; + wait_queue_t wait; pFile fps[NR_OPENS]; diff --git a/include/wait.h b/include/wait.h index a23111c..a7b32cd 100644 --- a/include/wait.h +++ b/include/wait.h @@ -10,19 +10,16 @@ *-------------------------------------------------------------------------- */ -#ifndef _WAIT_H -#define _WAIT_H +#pragma once #include -typedef struct +typedef struct { - ListHead wait; -} WaitQueueHead, *pWaitQueueHead; + list_head_t wait; -typedef ListHead WaitQueue, *pWaitQueue; +} wait_queue_head_t; -void init_wait_queue(pWaitQueueHead wqh); +typedef list_head_t wait_queue_t; - -#endif //_WAIT_H +void init_wait_queue(wait_queue_head_t * wqh); diff --git a/kernel/fork.c b/kernel/fork.c index d044361..61bc292 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -91,6 +91,7 @@ int do_fork(pt_regs_t *regs, unsigned long flags) INIT_LIST_HEAD(&tsk->list); + // TODO Lock list_add(&tsk->list, &root_task.list); return (int)tsk->pid; diff --git a/kernel/sched.c b/kernel/sched.c index 0a5ea9c..0ac9746 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -25,15 +25,12 @@ pid_t get_next_pid() { static pid_t g_pid = ROOT_TSK_PID; - pid_t pid = g_pid; - g_pid += 123; - return pid; } -inline void load_cr3(task_union * tsk) +inline void load_cr3(task_union *tsk) { LOAD_CR3(tsk->cr3); } @@ -61,7 +58,8 @@ void init_root_tsk() root_task.preempt_cnt = 0; root_task.pid = get_next_pid(); - root_task.ppid = 0; + root_task.ppid = 0; + root_task.state = TASK_RUNNING; INIT_LIST_HEAD(&root_task.list); for(i=0; iesp0; } -inline void switch_to() +inline void switch_to() { load_cr3(current); set_esp0(current); @@ -143,29 +141,44 @@ inline void context_switch(task_union * prev, task_union * next) ); } -unsigned long schedule() +unsigned long schedule() { - static task_union *p = &root_task; + static task_union *last_sel = &root_task; + task_union *sel = &root_task; + task_union *p = 0; + list_head_t *pos = 0; - if(p == &root_task) - p = list_entry(root_task.list.next, task_union, list); - else - p = &root_task; + list_for_each(pos, &(last_sel->list)) + { + p = list_entry(pos, task_union, list); + + if(p->state == TASK_RUNNING) + { + sel = p; + last_sel = sel; + break; + } + } - task_union *prev, *next; - prev = current; - next = p; + task_union *prev = current; + task_union *next = sel; context_switch(prev, next); } +void debug_sched() +{ + task_union *p = list_entry(root_task.list.next, task_union, list); + p->state = (p->state == TASK_RUNNING) ? TASK_INTERRUPTIBLE : TASK_RUNNING; +} + -inline void wake_up(pWaitQueue wq) +inline void wake_up(wait_queue_t * wq) { } -inline void sleep_on(pWaitQueue wq) +inline void sleep_on(wait_queue_t * wq) { } diff --git a/kernel/wait.c b/kernel/wait.c index 5ad1fb2..209631a 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -11,17 +11,17 @@ */ #include -void init_wait_queue(pWaitQueueHead wqh) +void init_wait_queue(wait_queue_head_t * wqh) { INIT_LIST_HEAD(&wqh->wait); } -void add_wait_queue(pWaitQueueHead wqh, pWaitQueue wq) +void add_wait_queue(wait_queue_head_t * wqh, wait_queue_t * wq) { list_add_tail(wq, &wqh->wait); } -void del_wait_queue(pWaitQueueHead wqh, pWaitQueue old) +void del_wait_queue(wait_queue_head_t * wqh, wait_queue_t * old) { //list_del_init(); } diff --git a/setup/system.c b/setup/system.c index f68902e..77540f3 100644 --- a/setup/system.c +++ b/setup/system.c @@ -123,7 +123,7 @@ void setup_irqs() request_irq(i, default_irq_handler, "default", "default"); } - for(i=1; i<16; i++) + for(i=0; i<16; i++) enable_irq(i); asm("sti"); }