From: acevest Date: Tue, 24 Jun 2014 00:38:45 +0000 (+0800) Subject: add debug wait queue code X-Git-Url: http://zhaoyanbai.com/repos/%22http:/static/doc/zpipe.c?a=commitdiff_plain;h=27115e60eb2dcc87e92a8997ad00202c600811b2;p=kernel.git add debug wait queue code --- diff --git a/drivers/keyboard.c b/drivers/keyboard.c index f3cf6a9..6336bfe 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -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; diff --git a/include/task.h b/include/task.h index 0ab883a..80a2470 100644 --- a/include/task.h +++ b/include/task.h @@ -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 diff --git a/kernel/init.c b/kernel/init.c index 20a4317..577ef42 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -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;"); } } diff --git a/kernel/wait.c b/kernel/wait.c index b06b537..66daa6c 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -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 +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); +}