mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 00:56:14 +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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user