Hi, Currently, interrupt handlers run with interrupts disabled, preventing servicing further interrupts (even if those interrupts have higher priority) until full completion of current interrupt routine. This patch makes the necessary changes to permit reenabling interrupts during interrupt handlers execution. Greetings, Juan PREVIOUS OPERATION AND BUGS 1. Flag can_tswitch is set to 1 if the interrupt service routine will return to user space, and to zero otherwise. Flag lastirq is set to interrupt number during the execution of interrupt handlers, and set to -1 at other times. 2. Interrupt handlers run with interrupts disabled. Also, handling of flags can_tswitch and lastirq is inadequate for nested interrupts, because they are not properly restored at the end of nested interrupts. 3. Schedule() is called at the end of any interrupt, if the interrupt routine will return to user space. During execution of function schedule() interrupts are reenabled because of a bug in that function. I think this is harmless because by then the EOI command was already sent to the interrupt controller. 4. Calling schedule by interrupt handlers is permitted, but the actual task switch inside schedule() will be skipped. This is controlled by flags can_tswitch and lastirq. 5. However, checking of can_tswitch and lastirq flags to enable task switching is flawed: it permits task switches if (can_tswitch == 1) and (lastirq != -1), clearly an error. Nothing happens now because the only two interrupt handlers presently used (timer and keyboard) do not call schedule. Other than that, flag can_tswitch is ignored by schedule(). NEW OPERATION 1. Schedule is called at the end of any interrupt, if the interrupt routine will return to user space. 2. Interrupts are reenabled before calling the interrupt handler. Interrupt nesting is permitted. Variable intr_count is a counter to keep track of the nesting level. It is incremented at the beginning of interrupt processing and decremented after issuing the EOI command to the interrupt controller. 3. Flags can_tswitch and lastirg are completely removed from the source tree. 4. In function schedule, task switches are skipped if intr_count > 0. OTHER CHANGES 1. An attempt was made to permit task switching if the interrupt routine will return to a system call. It succeeded up to the point of starting execution of the "init" program, then the system crashed. To get this far some bugs were fixed in files "arch/i86/kernel/process.c", "arch/i86/kernel/system.c" and "init/main.c" 2. In file init/main.c, in function init_task(), before attempting to load "bin/sh", opens console on device "/dev/tty1" and it should be "dev/tty0". Anyway, bin/sh fails to start, but now does not die silently. On the other hand, sash runs fine. 3. The purpose of this patch is to increase the functionality of the kernel and reduce interrupt latency time. Regardless, a side result of this modification is a reduction in code size of 32 bytes. The Image builded without errors. The kernel was tested with QEMU and dioscuri emulators. Also in a PPro pc booting from floppy.
Attachment:
elksG.patch
Description: Binary data