]> Zhao Yanbai Git Server - kernel.git/commitdiff
add debug wait queue code
authoracevest <zhaoyanbai@126.com>
Tue, 24 Jun 2014 00:38:45 +0000 (08:38 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 3 Nov 2021 02:42:42 +0000 (10:42 +0800)
drivers/keyboard.c
include/task.h
kernel/init.c
kernel/wait.c

index f3cf6a9bc2638bd49831abfeaca02b210340e757..6336bfe632b08680575b90fff96d60902214ce73 100644 (file)
@@ -26,7 +26,7 @@ void ide_debug();
 void ide_status();
 void debug_sched();
 void vga_toggle();
-
+int debug_wait_queue_put(unsigned int v);
 void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id)
 {
     unsigned char scan_code;
@@ -49,6 +49,13 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id)
     if(scan_code == 0x3B)   // F1
         vga_toggle();
 
+    if(scan_code == 0x3C)   // F2
+        debug_wait_queue_put(0);
+    if(scan_code == 0x3D)   // F3
+        debug_wait_queue_put(1);
+    if(scan_code == 0x3E)   // F4
+        debug_wait_queue_put(2);
+
     if((cnsl_rd_q.head+1) == cnsl_rd_q.tail)
         goto end;
 
index 0ab883af25cba62f68f8ce2b7b4504f2d7ef7f67..80a2470f9e00c4ff36efd95a2361f80e440e6541 100644 (file)
@@ -77,7 +77,13 @@ static inline task_union *get_current()
 
 #define current get_current()
 
-#define ROOT_TSK_PID    (7)
+static inline pid_t sysc_getpid()
+{
+    return current->pid;
+}
+
+
+#define ROOT_TSK_PID    (0)
 
 #define TASK_INIT_WEIGHT 10
 
index 20a4317c7be8532921fe74855e91eec3328adf4a..577ef42ef0a2fa81b49122edaf4aadb7fdecb2d3 100644 (file)
@@ -21,8 +21,9 @@ Desc    gdt[NGDT];
 
 char __initdata kernel_init_stack[KRNL_INIT_STACK_SIZE] __attribute__ ((__aligned__(PAGE_SIZE)));
 
-static unsigned int eid = 2;
+static unsigned int eid = 1;
 void debug_sem();
+int debug_wait_queue_get();
 void init_task_entry()
 {
     printk("hahahha %s\n", __func__);
@@ -38,7 +39,9 @@ void init_task_entry()
             debug_sem();
             printk("---END----%d\n", id);
         }
-        printd(id, "task:%d cnt:%d", id, i);
+        printd(id+1, "task:%d cnt:%d", id, i);
+        int v = debug_wait_queue_get();
+        printk("task:%d wait queue get %d\n", id, v);
         //asm("sti;");
     }
 }
index b06b537388ea6e31749db01d3f302f10f9253647..66daa6cef928f466ca237e99ce447976b7a68694 100644 (file)
@@ -18,18 +18,18 @@ void init_wait_queue(wait_queue_head_t *wqh)
 
 void add_wait_queue(wait_queue_head_t *wqh, wait_queue_t *wq)
 {
-    unsigned long iflags;
-    irq_save(iflags);
+    unsigned long flags;
+    irq_save(flags);
     list_add_tail(&wq->task_list, &wqh->task_list);
-    irq_restore(iflags);
+    irq_restore(flags);
 }
 
 void del_wait_queue(wait_queue_head_t *wqh, wait_queue_t *wq)
 {
-    unsigned long iflags;
-    irq_save(iflags);
+    unsigned long flags;
+    irq_save(flags);
     list_del(&wq->task_list);
-    irq_restore(iflags);
+    irq_restore(flags);
 }
 
 void wake_up(wait_queue_head_t *wqh)
@@ -45,3 +45,45 @@ void wake_up(wait_queue_head_t *wqh)
 
     // no schedule() here.
 }
+
+
+#include<irq.h>
+DECLARE_WAIT_QUEUE_HEAD(debug_wq);
+unsigned int debug_global_var = 0;
+int debug_wait_queue_get()
+{
+    unsigned int v = 0;
+    task_union * task = current;
+    DECLARE_WAIT_QUEUE(wait, task);
+    add_wait_queue(&debug_wq, &wait);
+
+    while(1)
+    {
+        printk("pid %d is going to wait\n", sysc_getpid());
+        task->state = TASK_WAIT;
+
+        disable_irq();
+        v = debug_global_var;
+        if(debug_global_var != 0)
+            debug_global_var--;
+        enable_irq();
+
+        if(v != 0)
+            break;
+
+        schedule();
+        printk("pid %d is running\n", sysc_getpid());
+    }
+
+    printk("pid %d is really running\n", sysc_getpid());
+    task->state = TASK_RUNNING;
+    del_wait_queue(&debug_wq, &wait);
+
+    return v;
+}
+
+int debug_wait_queue_put(unsigned int v)
+{
+    debug_global_var = v;
+    wake_up(&debug_wq);
+}