]> Zhao Yanbai Git Server - kernel.git/commitdiff
sched
authorAceVest <zhaoyanbai@126.com>
Tue, 3 Jun 2014 16:30:07 +0000 (00:30 +0800)
committerAceVest <zhaoyanbai@126.com>
Tue, 3 Jun 2014 16:30:07 +0000 (00:30 +0800)
drivers/keyboard.c
include/sched.h
include/task.h
include/wait.h
kernel/fork.c
kernel/sched.c
kernel/wait.c
setup/system.c

index c77ef68c81a238fd4ece201d77cbde25810b987d..c75b1819de80b05d12176dab0e022d3d4f1a807b 100644 (file)
@@ -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++;
index 618f499d2670977fee146bc024237ed850c7d43e..4073ba259370feb12f3cc100437d8ff50967ac00 100644 (file)
@@ -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
 
index d1b8cae12d00ee0be1b211c08764eb9d9121af33..6a20e8f856a5ab36e16b190d4a5c78b13b368da6 100644 (file)
@@ -58,7 +58,7 @@ typedef union task_union
 
         list_head_t list;
 
-        WaitQueue    wait;
+        wait_queue_t    wait;
 
         pFile        fps[NR_OPENS];
 
index a23111c5d649ec9e35e2ad24797d5a9bb0d5f6af..a7b32cd34554cafa5e5eecd063764b3a9db23c15 100644 (file)
  *--------------------------------------------------------------------------
  */
 
-#ifndef    _WAIT_H
-#define _WAIT_H
+#pragma once
 
 #include <list.h>
 
-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);
index d044361187f1b66b658de9680d9a64c5b9c80815..61bc2927f3a08656227b0f3bf07b415a0b00d247 100644 (file)
@@ -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;
index 0a5ea9c3c547c81589e7352ee0f6de5432ea557a..0ac9746a60de2642cc4ff263a48ce33c87d28c22 100644 (file)
@@ -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; i<NR_OPENS; i++)
@@ -101,7 +99,7 @@ task_union *get_unused_task_pcb()
     }
 }
 
-inline    task_union * get_next_tsk()
+inline task_union *get_next_tsk()
 {
     return 0;
 }
@@ -111,7 +109,7 @@ inline void set_esp0(task_union * tsk)
     tss.esp0 = tsk->esp0;
 }
 
-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)
 {
 
 }
index 5ad1fb2f173850f0f6be8b2fa2c8c17b494b8f2b..209631a51182a0aee1102169994d9bebbabb732b 100644 (file)
  */
 #include <wait.h>
 
-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();
 }
index f68902e58602eaab524ac435b44d3aa3f452932d..77540f3ca98526b3cf8469fc1d5842591f6fef23 100644 (file)
@@ -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");
 }