Krishna
Krishna

Reputation: 23

when schedule() returns?

In case of blocking IO, say, driver read, we call wait_event_interruptible() with some condition. When the condition is met, read will be done. I looked into wait_event_interruptible() function, it checks for condition and calls schedule(). schedule() will look for the next runnable process and does context switch and other process will run. Does it mean that, the next instruction to be executed for the current process will be inside schedule() function when this process is woken up again?

  1. If yes, if multiple process voluntarily calls schedule, then all processes will have next instruction to be executed once after it gets woken up will be well inside schedule()?

  2. In case of ret_from_interrupt, schedule() is called. When it will return? as iret is executed after that.

Upvotes: 2

Views: 800

Answers (2)

vonbrand
vonbrand

Reputation: 11831

Re point 2: The iret instruction (return from interrupt handler) is executed and that gets you into ret_from_interrupt. Then Linux passes control to the task next to run (schedule()). One of the overriding considerations when writing interrupt handlers is that while they are executing many other activities are inhibited (other, lower priority, interrupts are the prime example), so you want to get out of there as fast as possible. That is why most interrupt handlers just stash away work to be done before returning, and said work is then handled elsewhere (today in some special kernel thread).

Upvotes: 0

Alexey Frunze
Alexey Frunze

Reputation: 62106

I think the answer to the first question is yes as that's a fairly typical way of implementing context switching. That's how OS161 works, for example.

If the scheduler is called from an ISR, everything should be the same. The scheduler should change the context and return to the ISR and the ISR should then return using IRET. It will return to a different process/thread if the scheduler chooses to switch to a different one and therefore loads its context and saves the old one.

Upvotes: 1

Related Questions