The Pedigree Project
0.1
|
Public Member Functions | |
PerProcessorScheduler () | |
void | initialise (Thread *pThread) |
void | schedule (Thread::Status nextStatus=Thread::Ready, Thread *pNewThread=0, Spinlock *pLock=0) |
void | checkEventState (uintptr_t userStack) |
void | eventHandlerReturned () NORETURN |
void | addThread (Thread *pThread, Thread::ThreadStartFunc pStartFunction, void *pParam, bool bUsermode, void *pStack) |
void | addThread (Thread *pThread, SyscallState &state) |
void | killCurrentThread (Spinlock *pLock=0) NORETURN |
void | sleep (Spinlock *pLock=0) |
void | timer (uint64_t delta, InterruptState &state) |
void | removeThread (Thread *pThread) |
void | threadStatusChanged (Thread *pThread) |
void | setIdle (Thread *pThread) |
Private Member Functions | |
PerProcessorScheduler (const PerProcessorScheduler &) | |
PerProcessorScheduler & | operator= (const PerProcessorScheduler &) |
Static Private Member Functions | |
static void | deleteThreadThenRestoreState (Thread *pThread, SchedulerState &newState, volatile uintptr_t *pLock=0) NORETURN |
static void | deleteThread (Thread *pThread) |
static int | processorAddThread (void *instance) NORETURN |
Private Attributes | |
SchedulingAlgorithm * | m_pSchedulingAlgorithm |
Mutex | m_NewThreadDataLock |
ConditionVariable | m_NewThreadDataCondition |
List< void * > | m_NewThreadData |
Thread * | m_pIdleThread |
Definition at line 37 of file PerProcessorScheduler.h.
PerProcessorScheduler::PerProcessorScheduler | ( | ) |
Default constructor - Creates an empty scheduler with a new idle thread.
Definition at line 46 of file PerProcessorScheduler.cc.
|
private |
Copy-constructor
void PerProcessorScheduler::addThread | ( | Thread * | pThread, |
Thread::ThreadStartFunc | pStartFunction, | ||
void * | pParam, | ||
bool | bUsermode, | ||
void * | pStack | ||
) |
Adds a new thread.
pThread | The thread to add. |
pStartFunction | The function to start the thread with. |
pParam | void* parameter to give to the function. |
bUsermode | Start the thread in User Mode? |
pStack | Stack to start the thread with. |
Definition at line 479 of file PerProcessorScheduler.cc.
References Spinlock::acquire(), SchedulingAlgorithm::addThread(), LocksCommand::checkSchedule(), FATAL, Process::getAddressSpace(), Processor::getInterrupts(), Thread::getKernelStack(), Thread::getLock(), Thread::getParent(), Thread::getStatus(), Thread::getTlsBase(), Processor::id(), Processor::information(), Processor::jumpKernel(), Processor::jumpUser(), LocksCommand::lockReleased(), Thread::m_Lock, m_pSchedulingAlgorithm, Process::recordTime(), Spinlock::release(), Processor::saveState(), Thread::setCpuId(), Processor::setInterrupts(), Thread::setScheduler(), Thread::setStatus(), Processor::setTlsBase(), Thread::state(), Processor::switchAddressSpace(), and Spinlock::unwind().
Referenced by ProcessorThreadAllocator::addThread(), and processorAddThread().
void PerProcessorScheduler::addThread | ( | Thread * | pThread, |
SyscallState & | state | ||
) |
Adds a new thread.
pThread | The thread to add. |
state | The syscall state to jump to. |
Definition at line 607 of file PerProcessorScheduler.cc.
References Spinlock::acquire(), SchedulingAlgorithm::addThread(), LocksCommand::checkSchedule(), FATAL, Process::getAddressSpace(), Processor::getInterrupts(), Thread::getKernelStack(), Thread::getLock(), Thread::getParent(), Thread::getStatus(), Thread::getTlsBase(), Processor::id(), Processor::information(), LocksCommand::lockReleased(), Thread::m_Lock, m_pSchedulingAlgorithm, NOTICE, Process::recordTime(), Spinlock::release(), Processor::restoreState(), Processor::saveState(), Thread::setCpuId(), Processor::setInterrupts(), Thread::setScheduler(), Thread::setStatus(), Processor::setTlsBase(), Thread::state(), Processor::switchAddressSpace(), Process::trackTime(), and Spinlock::unwind().
void PerProcessorScheduler::checkEventState | ( | uintptr_t | userStack | ) |
Looks for event handlers to run, and if found, dispatches one.
userStack | The stack to use if the event has a user-mode handler. Usually obtained from an interruptState or syscallState. |
Definition at line 310 of file PerProcessorScheduler.cc.
References PhysicalMemoryManager::allocatePage(), VirtualAddressSpace::allocateStack(), Event::getHandlerAddress(), Event::getHandlerBuffer(), Thread::getId(), Processor::getInterrupts(), VirtualAddressSpace::getMapping(), Thread::getNextEvent(), PhysicalMemoryManager::getPageSize(), Thread::getParent(), Thread::getScheduler(), Thread::getStateLevel(), Event::getTrampoline(), Processor::information(), PhysicalMemoryManager::instance(), Event::isDeletable(), Thread::isInterruptible(), VirtualAddressSpace::isMapped(), Processor::jumpUser(), VirtualAddressSpace::KernelMode, VirtualAddressSpace::map(), panic(), Thread::popState(), Thread::pushState(), Process::recordTime(), Processor::saveState(), Thread::sendEvent(), Event::serialize(), Processor::setInterrupts(), Process::trackTime(), and VirtualAddressSpace::Write.
Referenced by schedule(), and sleep().
|
staticprivate |
Switches stacks, calls PerProcessorScheduler::deleteThread, then context switches.
Referenced by killCurrentThread().
void PerProcessorScheduler::eventHandlerReturned | ( | ) |
Assumes this thread has just returned from executing a event handler, and lets it resume normal execution.
Definition at line 468 of file PerProcessorScheduler.cc.
References Processor::information(), Thread::popState(), Processor::restoreState(), Processor::setInterrupts(), and Thread::state().
void PerProcessorScheduler::initialise | ( | Thread * | pThread | ) |
Initialises the scheduler with the given thread.
Definition at line 126 of file PerProcessorScheduler.cc.
References SchedulingAlgorithm::addThread(), Thread::detach(), Thread::getKernelStack(), Thread::getParent(), Machine::getSchedulerTimer(), Thread::getTlsBase(), Processor::id(), Processor::information(), m_pSchedulingAlgorithm, panic(), processorAddThread(), Thread::setCpuId(), Thread::setStatus(), and Processor::setTlsBase().
void PerProcessorScheduler::killCurrentThread | ( | Spinlock * | pLock = 0 | ) |
Destroys the currently running thread.
Definition at line 711 of file PerProcessorScheduler.cc.
References Spinlock::acquire(), LocksCommand::checkSchedule(), deleteThreadThenRestoreState(), Thread::detached(), Spinlock::exit(), FATAL, Process::getAddressSpace(), Thread::getKernelStack(), Thread::getLock(), SchedulingAlgorithm::getNext(), Thread::getParent(), Thread::getTlsBase(), Processor::information(), LocksCommand::lockReleased(), m_pSchedulingAlgorithm, panic(), SchedulingAlgorithm::removeThread(), Processor::setInterrupts(), Thread::setStatus(), Processor::setTlsBase(), Thread::shutdown(), Thread::state(), and Processor::switchAddressSpace().
|
private |
Assignment operator
Referenced by Thread::detached().
|
staticprivate |
Definition at line 71 of file PerProcessorScheduler.cc.
References Spinlock::acquire(), Semaphore::acquire(), addThread(), List< T, nodePoolSize >::count(), FATAL, Thread::getStatus(), Processor::id(), Processor::information(), Thread::m_Lock, List< T, nodePoolSize >::popFront(), List< T, nodePoolSize >::pushBack(), schedule(), Thread::setCpuId(), and ConditionVariable::wait().
Referenced by initialise().
void PerProcessorScheduler::schedule | ( | Thread::Status | nextStatus = Thread::Ready , |
Thread * | pNewThread = 0 , |
||
Spinlock * | pLock = 0 |
||
) |
Picks another thread to run, if there is one, and switches to it.
nextStatus | The thread status to assign the current thread when it is swapped. |
pNewThread | Overrides the next thread to switch to. |
pLock | Optional lock to release when the thread is safely locked. |
Definition at line 152 of file PerProcessorScheduler.cc.
References Spinlock::acquire(), checkEventState(), LocksCommand::checkSchedule(), Spinlock::exit(), FATAL, Process::getAddressSpace(), Processor::getInterrupts(), Thread::getKernelStack(), Thread::getLock(), SchedulingAlgorithm::getNext(), Thread::getParent(), Thread::getScheduler(), Thread::getStateLevel(), Thread::getTlsBase(), Processor::information(), LocksCommand::lockReleased(), m_pSchedulingAlgorithm, Process::recordTime(), Spinlock::release(), Processor::restoreState(), Processor::saveState(), Processor::setInterrupts(), Thread::setStatus(), Processor::setTlsBase(), Thread::state(), Processor::switchAddressSpace(), Process::trackTime(), Spinlock::unwind(), and WARNING.
Referenced by processorAddThread(), sleep(), and timer().
void PerProcessorScheduler::sleep | ( | Spinlock * | pLock = 0 | ) |
Puts a thread to sleep.
pLock | Optional, will release this lock when the thread is successfully in the sleep state. |
Definition at line 787 of file PerProcessorScheduler.cc.
References checkEventState(), Processor::information(), Spinlock::release(), and schedule().
|
virtual |
TimerHandler callback.
Implements TimerHandler.
Definition at line 812 of file PerProcessorScheduler.cc.
References Subsystem::exit(), Thread::Exit, Thread::getParent(), Thread::getUnwindState(), Processor::information(), m_pSchedulingAlgorithm, schedule(), and SchedulingAlgorithm::threadStatusChanged().
|
private |
The current SchedulingAlgorithm
Definition at line 122 of file PerProcessorScheduler.h.
Referenced by addThread(), initialise(), killCurrentThread(), schedule(), and timer().