From: acevest Date: Sat, 11 May 2024 11:05:29 +0000 (+0800) Subject: 时钟中断打断了下半部逻辑的情况下不再添加下半部处理程序 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=205a80455296cb90dea06c23bebedeedd63bb3a2;p=kernel.git 时钟中断打断了下半部逻辑的情况下不再添加下半部处理程序 --- diff --git a/kernel/clock.c b/kernel/clock.c index e78622f..66b6764 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -42,6 +42,7 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { // 打断后该时钟中断不应该继续减少该进程的时间片,因为这会造成该进程在后续的调底中少了实际的运行时间 if (1 == current->need_resched) { // 这种情况必然已经发生了该时钟中断打断了下半部处理程序 + // 反之时钟中断打断了下半部处理程序不一定need_resched就为1 return; } @@ -55,7 +56,9 @@ void clk_handler(unsigned int irq, pt_regs_t *regs, void *dev_id) { assert(current->ticks >= 0); // 防止ticks被减到0后再减溢出 - add_irq_bh_handler(clk_bh_handler, NULL); + if (reenter == 0) { + add_irq_bh_handler(clk_bh_handler, NULL); + } } // 开中断执行这个函数 diff --git a/kernel/irq.c b/kernel/irq.c index b25f382..2b03adb 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -77,6 +77,8 @@ void dump_irq_nr_stack() { void irq_bh_handler(); void schedule(); +volatile int reenter_count = 0; + __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { unsigned int irq = regs->irq; if (irq >= NR_IRQS) { @@ -86,8 +88,11 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { irq_desc_t *p = irq_desc + irq; irq_action_t *action = p->action; - assert(irq_disabled()); reenter++; + reenter_count += reenter == 0 ? 0 : 1; + assert(irq_disabled()); + assert(reenter >= 0); + assert(reenter <= 1); // 屏蔽当前中断 p->chip->disable(irq); @@ -100,8 +105,8 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { #if 1 unsigned long esp; asm("movl %%esp, %%eax" : "=a"(esp)); - printl(MPL_CURRENT, "current %08x %-6s cr3 %08x reenter %d esp %08x ticks %u", current, current->name, current->cr3, - reenter, esp, current->ticks); + printl(MPL_CURRENT, "current %08x %-6s cr3 %08x reenter %d:%u esp %08x ticks %u", current, current->name, + current->cr3, reenter, reenter_count, esp, current->ticks); #endif while (action && action->handler) {