]> git.corax.cc Git - corax/commitdiff
Issue the EOI at the beginning of the interrupt handler in order to avoid deadlocks
authorMatthias Kruk <m@m10k.eu>
Tue, 1 Oct 2019 12:53:28 +0000 (21:53 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 1 Oct 2019 12:53:28 +0000 (21:53 +0900)
kernel/arch/interrupt.c

index 8649a4ad75bcfb53470746829d831ac22e5493bf..b0db93c5372f6d68944df5da8f02298993d9f183 100644 (file)
@@ -50,6 +50,27 @@ int _int_handle(stack_frame_t ctx)
        default:
                break;
     }
+
+       /*
+        * Issue the EOI before invoking the scheduler since it might reschedule
+        * tasks, and the remainder of the function would not be executed until
+        * this task gets scheduled again. Since the interrupt controller (whether
+        * it be the i8259 or the APIC) will not issue further interrupts until
+        * an EOI is issued, the next task would effectively not get preempted
+        * until it makes a syscall or causes an exception (or an NMI or IPI
+        * occurs).
+        *
+        * TLDR: Issue the EOI first to avoid deadlocks.
+        */
+
+#if CONFIG_APIC == 1
+    /* FIXME: Make sure this is NOT done for NMI, SMI, INIT, ExtInt,
+     * SIPI or INIT-deassert mode interrupts */
+    _apic_eoi(ctx.intn);
+#else
+    _i8259_eoi(ctx.intn);
+#endif /* CONFIG_APIC */
+
 /*
     if(ctx.intn == 32) {
         unsigned *apic_esr;
@@ -95,14 +116,6 @@ int _int_handle(stack_frame_t ctx)
                break;
        }
 
-    #if CONFIG_APIC == 1
-    /* FIXME: Make sure this is NOT done for NMI, SMI, INIT, ExtInt,
-     * SIPI or INIT-deassert mode interrupts */
-    _apic_eoi(ctx.intn);
-    #else
-    _i8259_eoi(ctx.intn);
-    #endif /* CONFIG_APIC */
-
     return(0);
 }