From: acevest Date: Sat, 11 May 2024 05:39:53 +0000 (+0800) Subject: 移除reenter的罗辑,用判断是否在底半处理的方式替代 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/ddns-confgen.html?a=commitdiff_plain;h=refs%2Fheads%2Fdev%2F202405%2Freenter;p=kernel.git 移除reenter的罗辑,用判断是否在底半处理的方式替代 --- diff --git a/include/irq.h b/include/irq.h index bec6002..c72dcdc 100644 --- a/include/irq.h +++ b/include/irq.h @@ -81,4 +81,6 @@ bool irq_disabled(); #define IRQ_CASCADE 0x02 #define IRQ_DISK 0x0E +bool in_bh(); + #endif //_IRQ_H diff --git a/include/system.h b/include/system.h index 9189c40..b4d3f01 100644 --- a/include/system.h +++ b/include/system.h @@ -77,7 +77,7 @@ extern char etext, edata, end; #define disableIRQ() cli() #define enableIRQ() sti() -#define ALIGN(x, a) (((x) + (a)-1) & ~((a)-1)) +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) // 定义最大显存为 16MB #define VRAM_VADDR_SIZE (16 << 20) @@ -264,8 +264,6 @@ void init_task_entry(); void disk_task_entry(); void user_task_entry(); -extern volatile int reenter; - #define DEFAULT_BOOT_DELAY_TICKS 30 void boot_delay(int ticks); diff --git a/kernel/clock.c b/kernel/clock.c index e78622f..b2601f1 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 (!in_bh()) { + add_irq_bh_handler(clk_bh_handler, NULL); + } } // 开中断执行这个函数 diff --git a/kernel/irq.c b/kernel/irq.c index b25f382..1c462e3 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -77,6 +77,12 @@ void dump_irq_nr_stack() { void irq_bh_handler(); void schedule(); +volatile bool in_bh_logic = false; + +volatile uint32_t reenter_count = 0; + +bool in_bh() { return in_bh_logic; } + __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { unsigned int irq = regs->irq; if (irq >= NR_IRQS) { @@ -87,7 +93,6 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { irq_action_t *action = p->action; assert(irq_disabled()); - reenter++; // 屏蔽当前中断 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 esp %08x reenter %u ticks %u", current, current->name, current->cr3, + esp, reenter_count, current->ticks); #endif while (action && action->handler) { @@ -115,25 +120,25 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { // 代表当前中断程序打断了前一个中断程序的“开中断处理的底半部分逻辑” // 即前一个中断处理尚未完全完成 assert(irq_disabled()); - if (reenter != 0) { - reenter--; + if (in_bh_logic) { + reenter_count++; return; } // --以上逻辑CPU处于中断禁止状态-------------------------- // 此处执行中断函数的下半部分逻辑,开中断执行 { + in_bh_logic = true; enable_irq(); irq_bh_handler(); disable_irq(); + in_bh_logic = false; } // --以下逻辑CPU处于中断禁止状态-------------------------- assert(irq_disabled()); - assert(reenter == 0); - reenter--; // 考察如果不需要调度程序,直接退出 if (current->need_resched == 0) { diff --git a/kernel/syscall.S b/kernel/syscall.S index 3b9b27f..9c8f01b 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -26,7 +26,6 @@ .text .global syscall_entry .global ret_from_fork_krnl -.extern reenter //.global syscall_exit syscall_entry: diff --git a/kernel/system.c b/kernel/system.c index 1717762..da11654 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -36,8 +36,6 @@ char idtr[6] __attribute__((__aligned__(4))); extern char _gdtr[6]; extern char _idtr[6]; -volatile int reenter = -1; - void setup_gdt() { pDesc pdesc; // change to new gdt.