The Pedigree Project  0.1
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Scheduler Class Reference

This class manages how processes and threads are scheduled across processors. More...

#include <Scheduler.h>

+ Collaboration diagram for Scheduler:

Public Member Functions

bool initialise (Process *pKernelProcess)
 
void addThread (Thread *pThread, PerProcessorScheduler &PPSched)
 
void removeThread (Thread *pThread)
 
bool threadInSchedule (Thread *pThread)
 
size_t addProcess (Process *pProcess)
 
void removeProcess (Process *pProcess)
 
void yield ()
 
size_t getNumProcesses ()
 
ProcessgetProcess (size_t n)
 
void threadStatusChanged (Thread *pThread)
 
ProcessgetKernelProcess () const
 
PerProcessorSchedulergetBootstrapProcessorScheduler () const
 

Static Public Member Functions

static Schedulerinstance ()
 

Private Member Functions

 NOT_COPYABLE_OR_ASSIGNABLE (Scheduler)
 

Private Attributes

List< Process *, 0 > m_Processes
 
Atomic< size_t > m_NextPid
 
Tree< PerProcessorScheduler *, List< Thread * > * > m_PTMap
 
Tree< Thread *, PerProcessorScheduler * > m_TPMap
 
Processm_pKernelProcess
 
PerProcessorSchedulerm_pBspScheduler
 
Spinlock m_SchedulerLock
 

Static Private Attributes

static Scheduler m_Instance
 

Detailed Description

This class manages how processes and threads are scheduled across processors.

This is the "long term" scheduler - it load balances between processors and provides the interface for adding, listing and removing threads.

The load balancing is "lazy" in that the algorithm only runs on thread addition and removal.

Definition at line 44 of file Scheduler.h.

Member Function Documentation

size_t Scheduler::addProcess ( Process pProcess)

Adds a process.

Note
This is purely for enumeration purposes.
Returns
The ID that should be applied to this Process.

Definition at line 109 of file Scheduler.cc.

Referenced by Process::Process().

+ Here is the caller graph for this function:

void Scheduler::addThread ( Thread pThread,
PerProcessorScheduler PPSched 
)

Adds a thread to be load-balanced and accounted.

Parameters
pThreadThe new thread.
PPSchedThe per-processor scheduler the thread will start on.

Definition at line 79 of file Scheduler.cc.

Referenced by ProcessorThreadAllocator::addThread(), Thread::shutdown(), and Thread::Thread().

+ Here is the caller graph for this function:

size_t Scheduler::getNumProcesses ( )

Returns the number of processes currently in operation.

Definition at line 140 of file Scheduler.cc.

Referenced by MemoryPressureProcessKiller::compact(), ThreadsCommand::execute(), Rtc::irq(), Process::kill(), X64VirtualAddressSpace::mapUnlocked(), WaitCleanup::terminated(), and X86VirtualAddressSpace::X86VirtualAddressSpace().

+ Here is the caller graph for this function:

Process * Scheduler::getProcess ( size_t  n)

Returns the n'th process currently in operation.

Definition at line 149 of file Scheduler.cc.

References assert, List< T, nodePoolSize >::begin(), Dec, and WARNING.

Referenced by MemoryPressureProcessKiller::compact(), ThreadsCommand::execute(), Rtc::irq(), Process::kill(), X64VirtualAddressSpace::mapUnlocked(), WaitCleanup::terminated(), and X86VirtualAddressSpace::X86VirtualAddressSpace().

+ Here is the caller graph for this function:

bool Scheduler::initialise ( Process pKernelProcess)
static Scheduler& Scheduler::instance ( )
inlinestatic
void Scheduler::removeProcess ( Process pProcess)

Removes a process.

Note
This is purely for enumeration purposes.

Definition at line 119 of file Scheduler.cc.

References List< T, nodePoolSize >::begin().

Referenced by WaitCleanup::terminated(), and Process::~Process().

+ Here is the caller graph for this function:

void Scheduler::removeThread ( Thread pThread)

Removes a thread from being load-balanced and accounted.

Definition at line 87 of file Scheduler.cc.

Referenced by Thread::shutdown(), and Thread::~Thread().

+ Here is the caller graph for this function:

bool Scheduler::threadInSchedule ( Thread pThread)

Whether a thread is entered into the scheduler at all.

Definition at line 100 of file Scheduler.cc.

void Scheduler::yield ( )

Member Data Documentation

Scheduler Scheduler::m_Instance
staticprivate

The Scheduler instance.

Definition at line 104 of file Scheduler.h.

Atomic<size_t> Scheduler::m_NextPid
private

The next available process ID.

Definition at line 111 of file Scheduler.h.

PerProcessorScheduler* Scheduler::m_pBspScheduler
private

Pointer to the BSP's scheduler.

This may be necessary for threads that need to depend on e.g. interrupts that are only coming to the BSP, and having them run on a different CPU means they cannot control things like IRQs being enabled (not good).

Definition at line 129 of file Scheduler.h.

Process* Scheduler::m_pKernelProcess
private

Pointer to the kernel process.

Definition at line 120 of file Scheduler.h.

List<Process *, 0> Scheduler::m_Processes
private

All the processes currently in operation, for enumeration purposes.

Definition at line 108 of file Scheduler.h.

Tree<PerProcessorScheduler *, List<Thread *> *> Scheduler::m_PTMap
private

Map of processor->thread mappings, for load-balance accounting.

Definition at line 114 of file Scheduler.h.

Spinlock Scheduler::m_SchedulerLock
private

Main scheduler lock for modifying internal structures.

Definition at line 132 of file Scheduler.h.

Tree<Thread *, PerProcessorScheduler *> Scheduler::m_TPMap
private

Map of thread->processor mappings.

Definition at line 117 of file Scheduler.h.


The documentation for this class was generated from the following files: