22 #include "pedigree/kernel/process/Scheduler.h" 23 #include "pedigree/kernel/Log.h" 24 #include "pedigree/kernel/process/PerProcessorScheduler.h" 25 #include "pedigree/kernel/process/ProcessorThreadAllocator.h" 26 #include "pedigree/kernel/process/RoundRobinCoreAllocator.h" 27 #include "pedigree/kernel/processor/Processor.h" 28 #include "pedigree/kernel/processor/ProcessorInformation.h" 29 #include "pedigree/kernel/utilities/Iterator.h" 30 #include "pedigree/kernel/utilities/Vector.h" 31 #include "pedigree/kernel/utilities/assert.h" 32 #include "pedigree/kernel/utilities/utility.h" 38 #define SCHEDULER_HAS_SAFE_SPINLOCKS true 43 #define SCHEDULER_HAS_RECURSIVE_SPINLOCKS true 45 Scheduler::Scheduler()
46 : m_Processes(), m_NextPid(0), m_PTMap(), m_TPMap(), m_pKernelProcess(0),
47 m_pBspScheduler(0), m_SchedulerLock(false)
54 ProcessorThreadAllocator::instance().
setAlgorithm(pRoundRobin);
56 m_pKernelProcess = pKernelProcess;
66 procList.
pushBack(&((*it)->getScheduler()));
74 pRoundRobin->initialise(procList);
81 m_SchedulerLock.acquire(
82 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
83 m_TPMap.insert(pThread, &PPSched);
84 m_SchedulerLock.release();
89 m_SchedulerLock.acquire(
90 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
94 pPpSched->removeThread(pThread);
95 m_TPMap.remove(pThread);
97 m_SchedulerLock.release();
102 m_SchedulerLock.acquire(
103 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
105 m_SchedulerLock.release();
106 return pPpSched != 0;
111 m_SchedulerLock.acquire(
112 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
113 m_Processes.pushBack(pProcess);
114 size_t result = (m_NextPid += 1) - 1;
115 m_SchedulerLock.release();
121 m_SchedulerLock.acquire(
122 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
124 it != m_Processes.end(); it++)
128 m_Processes.erase(it);
132 m_SchedulerLock.release();
142 m_SchedulerLock.acquire(
143 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
144 size_t result = m_Processes.count();
145 m_SchedulerLock.release();
151 m_SchedulerLock.acquire(
152 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
153 if (n >= m_Processes.count())
156 "Scheduler::getProcess(" <<
Dec << n
157 <<
") parameter outside range.");
158 m_SchedulerLock.release();
165 it != m_Processes.end(); it++)
175 m_SchedulerLock.release();
179 void Scheduler::threadStatusChanged(
Thread *pThread)
181 m_SchedulerLock.acquire(
182 SCHEDULER_HAS_RECURSIVE_SPINLOCKS, SCHEDULER_HAS_SAFE_SPINLOCKS);
185 m_SchedulerLock.release();
187 pSched->threadStatusChanged(pThread);
void pushBack(const T &value)
This class manages how processes and threads are scheduled across processors.
static Scheduler m_Instance
static ProcessorInformation & information()
bool threadInSchedule(Thread *pThread)
void removeProcess(Process *pProcess)
void removeThread(Thread *pThread)
void setAlgorithm(ThreadToCoreAllocationAlgorithm *pAlgorithm)
Sets the algorithm to use for allocating threads to cores.
Process * getProcess(size_t n)
size_t addProcess(Process *pProcess)
static ProcessorInformation m_ProcessorInformation
void addThread(Thread *pThread, PerProcessorScheduler &PPSched)
bool initialise(Process *pKernelProcess)