FreeNOS
Data Structures | Public Member Functions | Private Types | Private Member Functions | Private Attributes
MemoryChannel Class Reference

Unidirectional point-to-point channel using shared memory. More...

#include <MemoryChannel.h>

Inheritance diagram for MemoryChannel:
Channel

Data Structures

struct  RingHead
 Defines in-memory ring header. More...
 

Public Member Functions

 MemoryChannel (const Mode mode, const Size messageSize)
 Constructor. More...
 
virtual ~MemoryChannel ()
 Destructor. More...
 
Result setVirtual (const Address data, const Address feedback, const bool hardReset=true)
 Set memory pages by virtual address. More...
 
Result setPhysical (const Address data, const Address feedback, const bool hardReset=true)
 Set memory pages by physical address. More...
 
Result unmap ()
 Unmap memory pages from virtual address space. More...
 
virtual Result read (void *buffer)
 Read a message. More...
 
virtual Result write (const void *buffer)
 Write a message. More...
 
virtual Result flush ()
 Flush message buffers. More...
 
bool operator== (const MemoryChannel &ch) const
 
bool operator!= (const MemoryChannel &ch) const
 
- Public Member Functions inherited from Channel
 Channel (const Mode mode, const Size messageSize)
 Constructor. More...
 
virtual ~Channel ()
 Destructor. More...
 
const Size getMessageSize () const
 Get message size. More...
 

Private Types

typedef struct MemoryChannel::RingHead RingHead
 Defines in-memory ring header. More...
 

Private Member Functions

Result reset (const bool hardReset)
 Reset to initial state. More...
 
Result flushPage (const Address page) const
 Flush memory page. More...
 

Private Attributes

const Size m_maximumMessages
 Maximum number of messages that can be stored. More...
 
Arch::IO m_data
 The data page. More...
 
Arch::IO m_feedback
 The feedback page. More...
 
RingHead m_head
 Local RingHead. More...
 

Additional Inherited Members

- Public Types inherited from Channel
enum  Result {
  Success, InvalidArgument, InvalidMode, InvalidSize,
  IOError, ChannelFull, NotFound, NotSupported
}
 Result codes. More...
 
enum  Mode { Producer, Consumer }
 Channel modes. More...
 
- Protected Attributes inherited from Channel
const Mode m_mode
 Channel mode. More...
 
const Size m_messageSize
 Message size. More...
 

Detailed Description

Unidirectional point-to-point channel using shared memory.

Implemented by using two separated memory pages. The data page is for the consumer in which it only reads the incoming data payloads. The producer writes payloads to the data page. The feedback page is written only by the consumer, where it stores the feedback information from its consumption.

Definition at line 43 of file MemoryChannel.h.

Member Typedef Documentation

◆ RingHead

Defines in-memory ring header.

Constructor & Destructor Documentation

◆ MemoryChannel()

MemoryChannel::MemoryChannel ( const Mode  mode,
const Size  messageSize 
)

Constructor.

Parameters
modeChannel mode is either a producer or consumer
messageSizeSize of each individual message in bytes

Definition at line 23 of file MemoryChannel.cpp.

References assert, PAGESIZE, and reset().

◆ ~MemoryChannel()

MemoryChannel::~MemoryChannel ( )
virtual

Destructor.

Definition at line 33 of file MemoryChannel.cpp.

Member Function Documentation

◆ flush()

MemoryChannel::Result MemoryChannel::flush ( )
virtual

Flush message buffers.

Ensures that all messages are written through caches.

Returns
Result code.

Reimplemented from Channel.

Definition at line 158 of file MemoryChannel.cpp.

References Channel::Consumer, flushPage(), IO::getBase(), m_data, m_feedback, Channel::m_mode, Channel::Producer, and Channel::Success.

Referenced by Process::raiseEvent(), CoreServer::sendToMaster(), and CoreServer::sendToSlave().

◆ flushPage()

MemoryChannel::Result MemoryChannel::flushPage ( const Address  page) const
private

Flush memory page.

Parameters
pageMemory page to flush
Returns
Result code.

Definition at line 170 of file MemoryChannel.cpp.

References CacheClean, Cache::cleanData(), ERROR, Channel::IOError, isKernel, SELF, Channel::Success, API::Success, Memory::Range::virt, and VMCtl().

Referenced by flush().

◆ operator!=()

bool MemoryChannel::operator!= ( const MemoryChannel ch) const
inline

Definition at line 147 of file MemoryChannel.h.

◆ operator==()

bool MemoryChannel::operator== ( const MemoryChannel ch) const
inline

Definition at line 142 of file MemoryChannel.h.

◆ read()

MemoryChannel::Result MemoryChannel::read ( void *  buffer)
virtual

◆ reset()

MemoryChannel::Result MemoryChannel::reset ( const bool  hardReset)
private

Reset to initial state.

Parameters
hardResetTrue to always start using the channel from beginning of data/feedback pages. False for soft-reset to read the new value of m_head back from the data page.
Returns
Result code.

Definition at line 37 of file MemoryChannel.cpp.

References Channel::Consumer, m_data, m_feedback, m_head, Channel::m_mode, Channel::Producer, ARMIO::read(), MemoryBlock::set(), and Channel::Success.

Referenced by MemoryChannel(), setPhysical(), and setVirtual().

◆ setPhysical()

MemoryChannel::Result MemoryChannel::setPhysical ( const Address  data,
const Address  feedback,
const bool  hardReset = true 
)

Set memory pages by physical address.

This function maps the given physical addresses into the current address space using IO::map.

Parameters
dataPhysical memory address of the data page. Read/Write for the producer, Read-only for the consumer.
feedbackPhysical memory address of the feedback page. Read/write for the consumer, read-only for the producer.
hardResetPerform a hard reset after setting pages.
Returns
Result code.

Definition at line 64 of file MemoryChannel.cpp.

References Channel::Consumer, ERROR, Channel::IOError, m_data, m_feedback, Channel::m_mode, IO::map(), PAGESIZE, Channel::Producer, Memory::Readable, reset(), IO::Success, Memory::User, and Memory::Writable.

Referenced by MpiProxy::createChannels(), MpiTarget::createReadChannel(), MpiTarget::createWriteChannel(), and CoreServer::setupChannels().

◆ setVirtual()

MemoryChannel::Result MemoryChannel::setVirtual ( const Address  data,
const Address  feedback,
const bool  hardReset = true 
)

Set memory pages by virtual address.

This function assumes that the given virtual addresses are already mapped into the associated address space.

Parameters
dataVirtual memory address of the data page. Read/Write for the producer, Read-only for the consumer.
feedbackVirtual memory address of the feedback page. Read/write for the consumer, read-only for the producer.
hardResetPerform a hard reset after setting pages.
Returns
Result code.

Definition at line 54 of file MemoryChannel.cpp.

References m_data, m_feedback, reset(), and IO::setBase().

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::accept(), ChannelServer< DatastoreServer, DatastoreMessage >::ChannelServer(), ChannelClient::connect(), and Process::initialize().

◆ unmap()

MemoryChannel::Result MemoryChannel::unmap ( )

Unmap memory pages from virtual address space.

Returns
Result code

Definition at line 99 of file MemoryChannel.cpp.

References Channel::IOError, m_data, m_feedback, Channel::Success, IO::Success, and IO::unmap().

Referenced by MpiProxy::createChannels().

◆ write()

MemoryChannel::Result MemoryChannel::write ( const void *  buffer)
virtual

Write a message.

Parameters
bufferInput buffer for the message.
Returns
Result code.

Reimplemented from Channel.

Definition at line 138 of file MemoryChannel.cpp.

References Channel::ChannelFull, MemoryChannel::RingHead::index, m_data, m_feedback, m_head, m_maximumMessages, Channel::m_messageSize, ARMIO::read(), Channel::Success, and ARMIO::write().

Referenced by MpiProxy::processSend(), Process::raiseEvent(), MpiTarget::send(), CoreServer::sendToMaster(), and CoreServer::sendToSlave().

Field Documentation

◆ m_data

Arch::IO MemoryChannel::m_data
private

The data page.

Definition at line 179 of file MemoryChannel.h.

Referenced by flush(), read(), reset(), setPhysical(), setVirtual(), unmap(), and write().

◆ m_feedback

Arch::IO MemoryChannel::m_feedback
private

The feedback page.

Definition at line 182 of file MemoryChannel.h.

Referenced by flush(), read(), reset(), setPhysical(), setVirtual(), unmap(), and write().

◆ m_head

RingHead MemoryChannel::m_head
private

Local RingHead.

Definition at line 185 of file MemoryChannel.h.

Referenced by read(), reset(), and write().

◆ m_maximumMessages

const Size MemoryChannel::m_maximumMessages
private

Maximum number of messages that can be stored.

Definition at line 176 of file MemoryChannel.h.

Referenced by read(), and write().


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