Interrupting the scheduler...
Posted: Sat Oct 30, 2004 1:29 am
I'm revisiting this and this. I'll try to make my question as brief as possible so as not to retread everything...
I don't want nested interrupts. However, I do want "kernel threads", which means that kernel entries can be nested at most two deep (e.g. -- user-thread makes syscall, transitioning to its kernel-mode stack. Resulting kernel-thread is interrupted by the clock, which could invoke the scheduler, preempting the kernel thread with a higher-priority user-thread). I want "kernel threads" so that long-running kernel operations can be preempted (is there a better way to do this...? I can't think of one...)
The question is this -- Assuming that interrupts are enabled while the scheduler is running (but before it does the final stack switch of course), how can I protect the scheduler from itself? Here are some possible answers -- please let me know how insane they are:
Once I get this design decision out of my hair, maybe I can actually get something done.
I don't want nested interrupts. However, I do want "kernel threads", which means that kernel entries can be nested at most two deep (e.g. -- user-thread makes syscall, transitioning to its kernel-mode stack. Resulting kernel-thread is interrupted by the clock, which could invoke the scheduler, preempting the kernel thread with a higher-priority user-thread). I want "kernel threads" so that long-running kernel operations can be preempted (is there a better way to do this...? I can't think of one...)
The question is this -- Assuming that interrupts are enabled while the scheduler is running (but before it does the final stack switch of course), how can I protect the scheduler from itself? Here are some possible answers -- please let me know how insane they are:
- Use the self-interrupt technique so that the scheduler can only be interrupted by handlers that by definition do not invoke the scheduler. Problem: This is complex to implement, and avoiding it is one of the main reasons I don't want nested h/w interrupts in the first place.
- Use a goofy global var like Minix' k_reenter. Problem: Icky.
- Disable any h/w interrupts that could invoke the scheduler. Problem: This is probably all of them, since interrupt handlers may want to wake up their corresponding driver threads.
- Just disable interrupts while the scheduler runs, stupid!
Once I get this design decision out of my hair, maybe I can actually get something done.