scheduler: Use precomputed time slice lengths
This commit is contained in:
@@ -579,10 +579,9 @@ reschedule(int32 nextState)
|
||||
bigtime_t quantum = nextThreadData->ComputeQuantum();
|
||||
add_timer(quantumTimer, &reschedule_event, quantum,
|
||||
B_ONE_SHOT_RELATIVE_TIMER);
|
||||
} else {
|
||||
nextThreadData->StartQuantum();
|
||||
} else
|
||||
gCurrentMode->rebalance_irqs(true);
|
||||
}
|
||||
nextThreadData->StartQuantum();
|
||||
|
||||
modeLocker.Unlock();
|
||||
if (nextThread != oldThread)
|
||||
@@ -674,6 +673,8 @@ scheduler_set_operation_mode(scheduler_mode mode)
|
||||
gCurrentMode = sSchedulerModes[mode];
|
||||
gCurrentMode->switch_to_mode();
|
||||
|
||||
ThreadData::ComputeQuantumLengths();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
using namespace Scheduler;
|
||||
|
||||
|
||||
bigtime_t Scheduler::gQuantumLengths[THREAD_MAX_SET_PRIORITY + 1];
|
||||
|
||||
|
||||
ThreadData::ThreadData(Thread* thread)
|
||||
:
|
||||
fThread(thread)
|
||||
@@ -116,12 +119,37 @@ ThreadData::ComputeQuantum()
|
||||
quantum = std::max(quantum, gCurrentMode->minimal_quantum);
|
||||
|
||||
fTimeLeft = quantum;
|
||||
fQuantumStart = system_time();
|
||||
|
||||
return quantum;
|
||||
}
|
||||
|
||||
|
||||
/* static */ void
|
||||
ThreadData::ComputeQuantumLengths()
|
||||
{
|
||||
for (int32 priority = 0; priority <= THREAD_MAX_SET_PRIORITY; priority++) {
|
||||
const bigtime_t kQuantum0 = gCurrentMode->base_quantum;
|
||||
if (priority >= B_URGENT_DISPLAY_PRIORITY) {
|
||||
gQuantumLengths[priority] = kQuantum0;
|
||||
continue;
|
||||
}
|
||||
|
||||
const bigtime_t kQuantum1
|
||||
= kQuantum0 * gCurrentMode->quantum_multipliers[0];
|
||||
if (priority > B_NORMAL_PRIORITY) {
|
||||
gQuantumLengths[priority] = _ScaleQuantum(kQuantum1, kQuantum0,
|
||||
B_URGENT_DISPLAY_PRIORITY, B_NORMAL_PRIORITY, priority);
|
||||
continue;
|
||||
}
|
||||
|
||||
const bigtime_t kQuantum2
|
||||
= kQuantum0 * gCurrentMode->quantum_multipliers[1];
|
||||
gQuantumLengths[priority] = _ScaleQuantum(kQuantum2, kQuantum1,
|
||||
B_NORMAL_PRIORITY, B_IDLE_PRIORITY, priority);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ThreadData::_ComputeEffectivePriority() const
|
||||
{
|
||||
@@ -181,23 +209,7 @@ ThreadData::_ChooseCPU(CoreEntry* core, bool& rescheduleNeeded) const
|
||||
inline bigtime_t
|
||||
ThreadData::_GetBaseQuantum() const
|
||||
{
|
||||
int32 priority = GetEffectivePriority();
|
||||
|
||||
const bigtime_t kQuantum0 = gCurrentMode->base_quantum;
|
||||
if (priority >= B_URGENT_DISPLAY_PRIORITY)
|
||||
return kQuantum0;
|
||||
|
||||
const bigtime_t kQuantum1
|
||||
= kQuantum0 * gCurrentMode->quantum_multipliers[0];
|
||||
if (priority > B_NORMAL_PRIORITY) {
|
||||
return _ScaleQuantum(kQuantum1, kQuantum0, B_URGENT_DISPLAY_PRIORITY,
|
||||
B_NORMAL_PRIORITY, priority);
|
||||
}
|
||||
|
||||
const bigtime_t kQuantum2
|
||||
= kQuantum0 * gCurrentMode->quantum_multipliers[1];
|
||||
return _ScaleQuantum(kQuantum2, kQuantum1, B_NORMAL_PRIORITY,
|
||||
B_IDLE_PRIORITY, priority);
|
||||
return gQuantumLengths[GetEffectivePriority()];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ public:
|
||||
inline CoreEntry* Core() const { return fCore; }
|
||||
inline void UnassignCore() { fCore = NULL; }
|
||||
|
||||
static void ComputeQuantumLengths();
|
||||
private:
|
||||
inline int32 _GetPenalty() const;
|
||||
inline int32 _GetMinimalPriority() const;
|
||||
@@ -118,6 +119,8 @@ public:
|
||||
virtual void operator()(ThreadData* thread) = 0;
|
||||
};
|
||||
|
||||
extern bigtime_t gQuantumLengths[THREAD_MAX_SET_PRIORITY + 1];
|
||||
|
||||
|
||||
inline bool
|
||||
ThreadData::HasCacheExpired() const
|
||||
|
||||
Reference in New Issue
Block a user