Page 1 of 1

Calling of the scheduler and IPL/DPC

Posted: Mon Nov 13, 2023 4:56 am
by lockna
Hello everyone!

I'm in the process of rewriting my scheduler because I came across a big mistake that I built my scheduler on.
I have set up my scheduler so that it receives an interrupt context as an argument.
This is of course unfavourable if, for example, a thread wants to sleep. So that I can then call the scheduler, I would have to fire a self-ipi. But this option is not particularly attractive. Or even if I just want to yield, I would also have to generate a self-ipi.
Or how else is this regulated?

I've just seen both. LyreOS always uses the interrupt context and uses a self-ipi for this.
Others have a separate context from the TrapFrame, which only saves the callee-saved registers and you can switch back and forth freely in the kernel.

Option two would be nicer, wouldn't it?

Which brings me to my next question.
I'm in the process of implementing a kind of event queue for various things. For example, an event is generated when a thread goes to sleep. This event is in the future and is practically the wake_up function. With a timer, which always fires on the closest event in time, the handling function for the event is then called in the timer_interrupt.
Should I also include the preemption of a thread in this event queue? Or should I rather have a periodic timer in the scheduler that creates a timer interrupt where I can preempt?
What would you prefer?

My last question would be about IPLs and DPCs in general.


At the beginning of the interrupt context, the IPL is raised to the IPL of the respective interrupt.
So that no low-order interrupt can interrupt it.
At the end, I fall back to the old IPL.
In the function that reduces my IPL, I then check whether I have fallen below the level for DPCs, don't I?
If this is the case, then the DPCs that have joined the DPC queue in the meantime are executed in sequence, but am I right in assuming that they are still executed in the interrupt context? Or will they be executed differently at some point?

I am/was of the opinion that this still happens in the interrupt context, but I'd better ask again.

I hope this is the right category for this sort of questions.
Cheers

Re: Calling of the scheduler and IPL/DPC

Posted: Tue Jan 16, 2024 12:46 am
by lockna
I figured this stuff already out.

I decided to make reschedule an event in the EventQueue too and don't schedule anything with a TrapFrame or anything. So, independently from interrupts.
Since the DPC mechanism is quite attractive I also implemented it.
I got the needed information from Inside Windows NT and Windows Internals book.