From: acevest Date: Sat, 11 May 2024 01:40:36 +0000 (+0800) Subject: 观察ticks减为负数的情况 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=52fee5d4642b3873928c4df69b20a3bbedeeac08;p=kernel.git 观察ticks减为负数的情况 --- diff --git a/kernel/clock.c b/kernel/clock.c index 6c7ac63..f992557 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -25,6 +25,9 @@ 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); @@ -40,11 +43,23 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { // 同时其下半部分处理时间过长,直到这个时钟中断还没处理完 // 那么这个时钟中断是完全可以打断它,且在这里把这个ticks从0减到负数 // 而这个是uint32_t型,因此会溢出成0xFFFFFFFF - if (current->ticks > 0) { - current->ticks--; + // if (current->ticks > 0) { + // current->ticks--; + // } + if (0 == --current->ticks) { + current->need_resched = 1; + } + + int value = (int)(current->ticks); + + if (min_ticks_value > value) { + min_ticks_value = value; + min_ticks_name = current->name; } - 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 <= TASK_MAX_PRIORITY); // 防止ticks被减到0后再减溢出 add_irq_bh_handler(clk_bh_handler, NULL); } diff --git a/kernel/irq.c b/kernel/irq.c index b6f6a5b..b25f382 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -136,7 +136,7 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { reenter--; // 考察如果不需要调度程序,直接退出 - if (current->ticks != 0) { + if (current->need_resched == 0) { return; } diff --git a/kernel/sched.c b/kernel/sched.c index b2af86e..cc0d6d0 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 <= TASK_MAX_PRIORITY); assert(current->priority <= TASK_MAX_PRIORITY); unsigned long iflags; @@ -235,6 +235,8 @@ void schedule() { next->state = TASK_RUNNING; next->reason = ""; + next->ticks = 5; + prev->need_resched = 0; if (prev != next) { next->sched_cnt++;