From: acevest Date: Sat, 11 May 2024 04:51:04 +0000 (+0800) Subject: task_t.ticks从uint32调整为int X-Git-Url: http://zhaoyanbai.com/repos/man.dnssec-keygen.html?a=commitdiff_plain;h=3b491cd5ab86468a1b027590967596e0e1201caa;p=kernel.git task_t.ticks从uint32调整为int --- diff --git a/include/task.h b/include/task.h index d47538e..30f96de 100644 --- a/include/task.h +++ b/include/task.h @@ -48,7 +48,7 @@ typedef union task_union { uint32_t esp; uint32_t eip; - uint32_t ticks; + int ticks; uint32_t turn; // 时间片用完次数 uint32_t priority; uint64_t jiffies; diff --git a/kernel/clock.c b/kernel/clock.c index 5110a43..e78622f 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -25,9 +25,6 @@ void debug_print_all_tasks(); void dump_irq_nr_stack(); void clk_bh_handler(void *arg); -const char *min_ticks_name = 0; -int min_ticks_value = 100; - void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { // if (jiffies % 100 == 0) { // printl(MPL_CLOCK, "clock irq: %d", jiffies); @@ -43,7 +40,6 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { // 而如果其下半部分需要处理的事情很多,处理时间过长,两个时钟中断之间的时间还不足以处理完 // 那么下一个时钟中断是完全可以打断还没处理完的下半部逻辑 // 打断后该时钟中断不应该继续减少该进程的时间片,因为这会造成该进程在后续的调底中少了实际的运行时间 - if (1 == current->need_resched) { // 这种情况必然已经发生了该时钟中断打断了下半部处理程序 return; @@ -51,24 +47,13 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { current->ticks--; -#if 1 - int value = (int)(current->ticks); - - if (min_ticks_value > value) { - min_ticks_value = value; - min_ticks_name = current->name; - } -#endif - if (0 == current->ticks) { current->need_resched = 1; current->ticks = current->priority; current->turn++; } - assert(current->ticks <= TASK_MAX_PRIORITY); // 防止ticks被减到0后再减溢出 - - printl(MPL_TEST, "%20s %10d %20s %10d", min_ticks_name, min_ticks_value, current->name, value); + assert(current->ticks >= 0); // 防止ticks被减到0后再减溢出 add_irq_bh_handler(clk_bh_handler, NULL); } diff --git a/kernel/sched.c b/kernel/sched.c index 471cd2a..86d9105 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -182,7 +182,7 @@ void schedule() { task_t *p = 0; list_head_t *pos = 0, *t = 0; - // assert(current->ticks <= TASK_MAX_PRIORITY); + assert(current->ticks >= 0); assert(current->priority <= TASK_MAX_PRIORITY); unsigned long iflags; diff --git a/kernel/syscall.c b/kernel/syscall.c index 9979ce1..c1f5c01 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -43,20 +43,24 @@ int sysc_none() { extern uint64_t jiffies; -// 特别说明:如果想把这个函数的参数ticks改为uint64_t +// 特别说明:如果想把这个函数的参数ticks改为int64_t // 那么就需要在编写用户级的系统调用库函数的时候注意 // 不仅需要填写 ebx,还要填写 ecx // 不然就可能出现诡异的一直WAIT,不会调度到该任务的问题 -int sysc_wait(uint32_t ticks) { - unsigned long flags; - irq_save(flags); - current->state = TASK_WAIT; - current->reason = "sysc_wait"; - current->delay_jiffies = jiffies + ticks; - list_add(¤t->pend, &delay_tasks); - irq_restore(flags); - +int sysc_wait(int ticks) { + if (ticks < 0) { + return -EINVAL; + } else { + unsigned long flags; + irq_save(flags); + current->state = TASK_WAIT; + current->reason = "sysc_wait"; + current->delay_jiffies = jiffies + ticks; + list_add(¤t->pend, &delay_tasks); + irq_restore(flags); + } schedule(); + return 0; } int sysc_test() {} diff --git a/kernel/task_init.c b/kernel/task_init.c index 30753e7..7064470 100644 --- a/kernel/task_init.c +++ b/kernel/task_init.c @@ -9,7 +9,7 @@ #include #include #include -int sysc_wait(uint32_t ticks); +int sysc_wait(int ticks); void init_task_entry() { current->priority = 10; diff --git a/kernel/task_root.c b/kernel/task_root.c index 9ea4224..528f3a9 100644 --- a/kernel/task_root.c +++ b/kernel/task_root.c @@ -22,7 +22,7 @@ #include int do_fork(pt_regs_t *regs, unsigned long flags); -int sysc_wait(uint32_t ticks); +int sysc_wait(int ticks); #define get_eflags(x) __asm__ __volatile__("pushfl; popl %0;" : "=g"(x)::"memory")