1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

Kernel: When a lock is busy, donate remaining process ticks to lock holder.

Since we know who's holding the lock, and we're gonna have to yield anyway,
we can just ask the scheduler to donate any remaining ticks to that process.
This commit is contained in:
Andreas Kling 2019-02-07 11:12:23 +01:00
parent 4df92709c8
commit 5582a0a254
15 changed files with 51 additions and 15 deletions

View file

@ -192,6 +192,24 @@ bool Scheduler::pick_next()
}
}
bool Scheduler::donate_to(Process* beneficiary, const char* reason)
{
(void)reason;
unsigned ticks_left = current->ticks_left();
if (!beneficiary || beneficiary->state() != Process::Runnable || ticks_left <= 1) {
return yield();
}
unsigned ticks_to_donate = ticks_left - 1;
#ifdef SCHEDULER_DEBUG
dbgprintf("%s(%u) donating %u ticks to %s(%u), reason=%s\n", current->name().characters(), current->pid(), ticks_to_donate, beneficiary->name().characters(), beneficiary->pid(), reason);
#endif
context_switch(*beneficiary);
beneficiary->set_ticks_left(ticks_to_donate);
switch_now();
return 0;
}
bool Scheduler::yield()
{
InterruptDisabler disabler;
@ -229,12 +247,6 @@ bool Scheduler::context_switch(Process& process)
process.set_ticks_left(time_slice);
process.did_schedule();
if (process.tss().cs & 3) {
++process.m_ticks_in_user;
} else {
++process.m_ticks_in_kernel;
}
if (current == &process)
return false;