FreeNOS
|
Represents a single Core in a Central Processing Unit (CPU). More...
#include <CoreServer.h>
Public Member Functions | |
CoreServer () | |
Class constructor function. More... | |
Core::Result | test () |
Run a ping-pong test. More... | |
int | runCore () |
Routine for the slave processor core. More... | |
virtual Result | initialize () |
Initialize the server. More... | |
Public Member Functions inherited from ChannelServer< CoreServer, CoreMessage > | |
ChannelServer (CoreServer *inst) | |
Constructor function. More... | |
virtual | ~ChannelServer () |
Destructor function. More... | |
int | run () |
Enters an infinite loop, serving incoming requests. More... | |
void | setTimeout (const uint msec) |
Set a sleep timeout. More... | |
Protected Attributes | |
CoreManager * | m_cores |
Protected Attributes inherited from ChannelServer< CoreServer, CoreMessage > | |
CoreServer * | m_instance |
Server object instance. More... | |
ChannelClient * | m_client |
Client for sending replies. More... | |
ChannelRegistry & | m_registry |
Contains registered channels. More... | |
MemoryChannel | m_kernelEvent |
Kernel event channel. More... | |
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCount > | m_ipcHandlers |
IPC handler functions. More... | |
Index< MessageHandler< IRQHandlerFunction >, MaximumHandlerCount > | m_irqHandlers |
IRQ handler functions. More... | |
ProcessID | m_self |
ProcessID of ourselves. More... | |
Timer::Info | m_time |
System timer value. More... | |
Timer::Info | m_expiry |
System timer expiration value. More... | |
Private Member Functions | |
virtual Core::Result | bootCore (uint coreId, CoreInfo *info)=0 |
Boot a processor core. More... | |
virtual Core::Result | discoverCores ()=0 |
Discover processor cores. More... | |
virtual void | waitIPI () const =0 |
Wait for Inter-Processor-Interrupt. More... | |
virtual Core::Result | sendIPI (uint coreId)=0 |
Send Inter-Processor-Interrupt. More... | |
Core::Result | prepareCore (uint coreId, CoreInfo *info, ExecutableFormat::Region *regions) |
Prepare processor core for booting. More... | |
Core::Result | prepareCoreInfo () |
Prepare the CoreInfo array. More... | |
Core::Result | loadKernel () |
Load operating system kernel program. More... | |
Core::Result | unloadKernel () |
Unload operating system kernel program. More... | |
Core::Result | bootAll () |
Boot all processor cores. More... | |
Core::Result | setupChannels () |
Setup communication channels between CoreServers. More... | |
Core::Result | clearPages (Address addr, Size size) |
Clear memory pages with zeroes. More... | |
void | getCoreCount (CoreMessage *msg) |
Get and fill the number of processor cores. More... | |
void | createProcess (CoreMessage *msg) |
Create a process on the current processor core. More... | |
Core::Result | receiveFromMaster (CoreMessage *msg) |
Receive message from master. More... | |
Core::Result | sendToMaster (CoreMessage *msg) |
Send message to master. More... | |
Core::Result | receiveFromSlave (uint coreId, CoreMessage *msg) |
Receive message from slave. More... | |
Core::Result | sendToSlave (uint coreId, CoreMessage *msg) |
Send message to slave. More... | |
Private Attributes | |
ExecutableFormat * | m_kernel |
Memory::Range | m_kernelImage |
ExecutableFormat::Region | m_regions [16] |
Size | m_numRegions |
Index< CoreInfo, MaxCores > * | m_coreInfo |
SystemInformation | m_info |
Index< MemoryChannel, MaxCores > * | m_fromSlave |
Index< MemoryChannel, MaxCores > * | m_toSlave |
MemoryChannel * | m_toMaster |
MemoryChannel * | m_fromMaster |
Static Private Attributes | |
static const Size | MaxCores = 256 |
Maximum number of cores currently supported. More... | |
static const Size | MaxMessageRetry = 128 |
Number of times to busy wait on receiving a message. More... | |
static const char * | kernelPath = "/boot/kernel" |
The default kernel for starting new cores. More... | |
Additional Inherited Members | |
Public Types inherited from ChannelServer< CoreServer, CoreMessage > | |
enum | Result |
Result codes. More... | |
Static Public Member Functions inherited from AbstractFactory< CoreServer > | |
static CoreServer * | create () |
Abstract function to create an instance of T. More... | |
Protected Types inherited from ChannelServer< CoreServer, CoreMessage > | |
typedef void(CoreServer ::* | IPCHandlerFunction) (CoreMessage *) |
Member function pointer inside Base, to handle IPC messages. More... | |
typedef void(CoreServer ::* | IRQHandlerFunction) (Size) |
Member function pointer inside Base, to handle interrupts. More... | |
Protected Member Functions inherited from ChannelServer< CoreServer, CoreMessage > | |
void | addIPCHandler (const Size slot, IPCHandlerFunction h, const bool sendReply=true) |
Register a new IPC message action handler. More... | |
void | addIRQHandler (const Size slot, IRQHandlerFunction h) |
Register a new IRQ message vector handler. More... | |
virtual void | timeout () |
Called when sleep timeout is reached. More... | |
virtual bool | retryRequests () |
Retry any pending requests. More... | |
virtual void | onProcessTerminated (const ProcessID pid) |
Called whenever another Process is terminated. More... | |
void | retryAllRequests () |
Keep retrying requests until all served. More... | |
Represents a single Core in a Central Processing Unit (CPU).
Each core in a system will run its own instance of CoreServer. CoreServers will communicate and collaborate together to implement functionality.
Definition at line 49 of file CoreServer.h.
CoreServer::CoreServer | ( | ) |
Class constructor function.
Definition at line 31 of file CoreServer.cpp.
References ChannelServer< CoreServer, CoreMessage >::addIPCHandler(), Core::CreateProcess, createProcess(), Core::GetCoreCount, getCoreCount(), m_coreInfo, m_cores, m_fromMaster, m_fromSlave, m_kernel, m_kernelImage, m_numRegions, m_toMaster, m_toSlave, MemoryBlock::set(), and ZERO.
|
private |
Boot all processor cores.
Definition at line 600 of file CoreServer.cpp.
References bootCore(), coreId, List< T >::count(), ERROR, Index< T, N >::get(), CoreManager::getCores(), ListIterator< T >::hasCurrent(), m_coreInfo, m_cores, m_regions, Core::NotFound, prepareCore(), and Core::Success.
Referenced by initialize().
|
privatepure virtual |
Boot a processor core.
Implemented in SunxiCoreServer, IntelCoreServer, and SingleCoreServer.
Referenced by bootAll().
|
private |
Clear memory pages with zeroes.
addr | Physical memory address to clear |
size | Number of bytes to clear |
Definition at line 624 of file CoreServer.cpp.
References Memory::Range::access, DEBUG, MapContiguous, Memory::Range::phys, Memory::Readable, SELF, MemoryBlock::set(), Memory::Range::size, Core::Success, UnMap, Memory::User, Memory::Range::virt, VMCtl(), Memory::Writable, and ZERO.
Referenced by prepareCoreInfo().
|
private |
Create a process on the current processor core.
msg | CoreMessage containing process information |
Definition at line 82 of file CoreServer.cpp.
References Memory::Range::access, SystemInformation::coreId, CoreMessage::coreNumber, DEBUG, ERROR, ChannelMessage::from, StrictSingleton< ChannelClient >::instance(), Core::InvalidArgument, Core::IOError, LookupVirtual, m_info, MapContiguous, Memory::Range::phys, CoreMessage::programAddr, CoreMessage::programCmd, CoreMessage::programSize, Memory::Readable, API::ReadPhys, receiveFromSlave(), CoreMessage::result, SELF, sendToMaster(), sendToSlave(), Memory::Range::size, spawn(), Core::Success, API::Success, ChannelClient::syncSendTo(), UnMap, Memory::User, Memory::Range::virt, VMCopy(), VMCtl(), waitpid(), and ZERO.
Referenced by CoreServer().
|
privatepure virtual |
Discover processor cores.
Implemented in SunxiCoreServer, IntelCoreServer, and SingleCoreServer.
Referenced by initialize().
|
private |
Get and fill the number of processor cores.
msg | CoreMessage to fill in the core count |
Definition at line 207 of file CoreServer.cpp.
References SystemInformation::coreId, CoreMessage::coreNumber, List< T >::count(), DEBUG, CoreManager::getCores(), Core::InvalidArgument, m_cores, m_info, CoreMessage::result, and Core::Success.
Referenced by CoreServer().
|
virtual |
Initialize the server.
Reimplemented in SunxiCoreServer, IntelCoreServer, and SingleCoreServer.
Definition at line 260 of file CoreServer.cpp.
References bootAll(), SystemInformation::coreId, discoverCores(), ERROR, ChannelServer< CoreServer, CoreMessage >::IOError, loadKernel(), m_info, prepareCoreInfo(), setupChannels(), Core::Success, ChannelServer< CoreServer, CoreMessage >::Success, and unloadKernel().
Referenced by IntelCoreServer::initialize(), SunxiCoreServer::initialize(), and main().
|
private |
Load operating system kernel program.
Definition at line 315 of file CoreServer.cpp.
References Memory::Range::access, close(), DEBUG, ERROR, Core::ExecError, ExecutableFormat::find(), Lz4Decompressor::getUncompressedSize(), Lz4Decompressor::initialize(), Core::IOError, kernelPath, m_kernel, m_kernelImage, m_numRegions, m_regions, MapContiguous, O_RDONLY, open(), Memory::Range::phys, read(), Lz4Decompressor::read(), Memory::Readable, ExecutableFormat::regions(), Release, SELF, Memory::Range::size, stat::st_size, stat(), Core::Success, API::Success, ExecutableFormat::Success, Lz4Decompressor::Success, Memory::User, Memory::Range::virt, VMCtl(), Memory::Writable, and ZERO.
Referenced by initialize().
|
private |
Prepare processor core for booting.
coreId | Core identifier number |
info | CoreInfo pointer containing specific core information |
regions | Kernel executable memory regions |
Definition at line 441 of file CoreServer.cpp.
References Memory::Range::access, CoreInfo::bootImageAddress, SystemInformation::bootImageAddress, CoreInfo::bootImageSize, SystemInformation::bootImageSize, coreId, ExecutableFormat::Region::dataOffset, ExecutableFormat::Region::dataSize, DEBUG, ERROR, kernelPath, m_kernelImage, m_numRegions, m_regions, MapContiguous, CoreInfo::memory, SystemInformation::memoryAvail, Core::MemoryError, Core::OutOfMemory, Memory::Range::phys, Memory::Readable, ReserveMem, SELF, Memory::Range::size, Core::Success, API::Success, UnMap, Memory::User, Memory::Range::virt, ExecutableFormat::Region::virt, VMCopy(), VMCtl(), Memory::Writable, and API::Write.
Referenced by bootAll().
|
private |
Prepare the CoreInfo array.
Definition at line 539 of file CoreServer.cpp.
References CoreInfo::bootImageAddress, CoreInfo::bootImageSize, SystemInformation::bootImageSize, clearPages(), CoreInfo::coreChannelAddress, CoreInfo::coreChannelSize, coreId, CoreInfo::coreId, List< T >::count(), ExecutableFormat::entry(), ERROR, CoreManager::getCores(), ListIterator< T >::hasCurrent(), CoreInfo::heapAddress, CoreInfo::heapSize, Index< T, N >::insertAt(), CoreInfo::kernel, KERNEL_PATHLEN, SystemInformation::kernelAddress, CoreInfo::kernelCommand, CoreInfo::kernelEntry, kernelPath, SystemInformation::kernelSize, m_coreInfo, m_cores, m_kernel, MegaByte, CoreInfo::memory, SystemInformation::memorySize, Core::NotFound, NOTICE, PAGESIZE, Memory::Range::phys, MemoryBlock::set(), Memory::Range::size, strlcpy(), Core::Success, CoreInfo::timerCounter, and SystemInformation::timerCounter.
Referenced by initialize().
|
private |
Receive message from master.
msg | CoreMessage pointer |
Definition at line 683 of file CoreServer.cpp.
References m_fromMaster, MaxMessageRetry, Channel::NotFound, MemoryChannel::read(), Channel::Success, Core::Success, and waitIPI().
Referenced by runCore().
|
private |
Receive message from slave.
coreId | Core identifier |
msg | CoreMessage pointer |
Definition at line 718 of file CoreServer.cpp.
References coreId, Index< T, N >::get(), Core::IOError, m_fromSlave, MemoryChannel::read(), Channel::Success, and Core::Success.
Referenced by createProcess(), and test().
int CoreServer::runCore | ( | ) |
Routine for the slave processor core.
Definition at line 52 of file CoreServer.cpp.
References CoreMessage::action, SystemInformation::coreId, ERROR, MessageHandler< Func >::exec, Index< T, N >::get(), m_info, ChannelServer< CoreServer, CoreMessage >::m_ipcHandlers, receiveFromMaster(), ChannelServer< CoreServer, CoreMessage >::run(), MessageHandler< Func >::sendReply, and sendToMaster().
Referenced by main().
|
privatepure virtual |
Send Inter-Processor-Interrupt.
coreId | Core identifier number |
Implemented in SunxiCoreServer, IntelCoreServer, and SingleCoreServer.
Referenced by sendToSlave().
|
private |
Send message to master.
msg | CoreMessage pointer |
Definition at line 702 of file CoreServer.cpp.
References ERROR, MemoryChannel::flush(), Core::IOError, m_toMaster, CoreMessage::result, Channel::Success, Core::Success, and MemoryChannel::write().
Referenced by createProcess(), runCore(), and test().
|
private |
Send message to slave.
coreId | Core identifier |
msg | CoreMessage pointer |
Definition at line 730 of file CoreServer.cpp.
References coreId, ERROR, MemoryChannel::flush(), Index< T, N >::get(), Core::IOError, m_toSlave, Core::NotFound, CoreMessage::result, sendIPI(), Channel::Success, Core::Success, and MemoryChannel::write().
Referenced by createProcess().
|
private |
Setup communication channels between CoreServers.
Definition at line 642 of file CoreServer.cpp.
References Channel::Consumer, CoreInfo::coreChannelAddress, SystemInformation::coreChannelAddress, SystemInformation::coreId, coreInfo, List< T >::count(), DEBUG, Index< T, N >::get(), CoreManager::getCores(), Index< T, N >::insertAt(), m_coreInfo, m_cores, m_fromMaster, m_fromSlave, m_toMaster, m_toSlave, PAGESIZE, Channel::Producer, MemoryChannel::setPhysical(), and Core::Success.
Referenced by initialize().
Core::Result CoreServer::test | ( | ) |
Run a ping-pong test.
Definition at line 224 of file CoreServer.cpp.
References CoreMessage::action, SystemInformation::coreId, CoreMessage::coreNumber, List< T >::count(), ERROR, CoreManager::getCores(), m_cores, m_info, NOTICE, NULL, Core::PongResponse, receiveFromSlave(), ChannelMessage::Response, sendToMaster(), Core::Success, and ChannelMessage::type.
Referenced by main().
|
private |
Unload operating system kernel program.
Definition at line 426 of file CoreServer.cpp.
References ERROR, Core::IOError, m_kernelImage, m_regions, Release, SELF, MemoryBlock::set(), Core::Success, API::Success, and VMCtl().
Referenced by initialize().
|
privatepure virtual |
Wait for Inter-Processor-Interrupt.
Implemented in SunxiCoreServer, IntelCoreServer, and SingleCoreServer.
Referenced by receiveFromMaster().
|
staticprivate |
The default kernel for starting new cores.
Definition at line 61 of file CoreServer.h.
Referenced by loadKernel(), prepareCore(), and prepareCoreInfo().
Definition at line 251 of file CoreServer.h.
Referenced by bootAll(), CoreServer(), prepareCoreInfo(), and setupChannels().
|
protected |
Definition at line 240 of file CoreServer.h.
Referenced by bootAll(), CoreServer(), IntelCoreServer::discoverCores(), getCoreCount(), prepareCoreInfo(), setupChannels(), SunxiCoreServer::SunxiCoreServer(), and test().
|
private |
Definition at line 258 of file CoreServer.h.
Referenced by CoreServer(), receiveFromMaster(), and setupChannels().
|
private |
Definition at line 254 of file CoreServer.h.
Referenced by CoreServer(), receiveFromSlave(), and setupChannels().
|
private |
Definition at line 252 of file CoreServer.h.
Referenced by createProcess(), getCoreCount(), initialize(), runCore(), and test().
|
private |
Definition at line 244 of file CoreServer.h.
Referenced by CoreServer(), loadKernel(), and prepareCoreInfo().
|
private |
Definition at line 245 of file CoreServer.h.
Referenced by CoreServer(), loadKernel(), prepareCore(), and unloadKernel().
|
private |
Definition at line 249 of file CoreServer.h.
Referenced by CoreServer(), loadKernel(), and prepareCore().
|
private |
Definition at line 247 of file CoreServer.h.
Referenced by bootAll(), loadKernel(), prepareCore(), and unloadKernel().
|
private |
Definition at line 257 of file CoreServer.h.
Referenced by CoreServer(), sendToMaster(), and setupChannels().
|
private |
Definition at line 255 of file CoreServer.h.
Referenced by CoreServer(), sendToSlave(), and setupChannels().
|
staticprivate |
Maximum number of cores currently supported.
Definition at line 55 of file CoreServer.h.
|
staticprivate |
Number of times to busy wait on receiving a message.
Definition at line 58 of file CoreServer.h.
Referenced by receiveFromMaster().