Skip to content

Commit

Permalink
iox-eclipse-iceoryx#605 remove f_ prefix and fix formula in readme
Browse files Browse the repository at this point in the history
Signed-off-by: Marika Lehmann <[email protected]>
  • Loading branch information
FerdinandSpitzschnueffler committed Mar 18, 2021
1 parent 01f3d13 commit d841e8c
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 91 deletions.
2 changes: 1 addition & 1 deletion doc/design/relocatable_pointer.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Let a1, b1, c1 and so on be the addresses of segment S, pointer p and object X i
c2 in application2. If application 2 maps the memory differently they will be shifted by some common offset d depending
on the individual memory mapping:

a2 = a1 + d, b2 = a2 + d, c2 = c1 + d
a2 = a1 + d, b2 = b1 + d, c2 = c1 + d

This is why storing a raw pointer to X will not be sufficient, the value c1 of p will not point to X in application 2.
However, storing the difference between the location of p and X will work since it is an invariant in both address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ struct alignas(32) ChunkManagement
using referenceCounterBase_t = uint64_t;
using referenceCounter_t = std::atomic<referenceCounterBase_t>;

ChunkManagement(const cxx::not_null<base_t*> f_chunkHeader,
const cxx::not_null<MemPool*> f_mempool,
const cxx::not_null<MemPool*> f_chunkManagementPool)
: m_chunkHeader(f_chunkHeader)
, m_mempool(f_mempool)
, m_chunkManagementPool(f_chunkManagementPool)
ChunkManagement(const cxx::not_null<base_t*> chunkHeader,
const cxx::not_null<MemPool*> mempool,
const cxx::not_null<MemPool*> chunkManagementPool)
: m_chunkHeader(chunkHeader)
, m_mempool(mempool)
, m_chunkManagementPool(chunkManagementPool)
{
}

Expand Down
26 changes: 13 additions & 13 deletions iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ namespace mepoo
{
struct MemPoolInfo
{
MemPoolInfo(uint32_t f_usedChunks, uint32_t f_minFreeChunks, uint32_t f_numChunks, uint32_t f_chunkSize)
: m_usedChunks(f_usedChunks)
, m_minFreeChunks(f_minFreeChunks)
, m_numChunks(f_numChunks)
, m_chunkSize(f_chunkSize)
MemPoolInfo(uint32_t usedChunks, uint32_t minFreeChunks, uint32_t numChunks, uint32_t chunkSize)
: m_usedChunks(usedChunks)
, m_minFreeChunks(minFreeChunks)
, m_numChunks(numChunks)
, m_chunkSize(chunkSize)
{
}
uint32_t m_usedChunks{0};
Expand All @@ -50,10 +50,10 @@ class MemPool
using freeList_t = concurrent::LoFFLi;
static constexpr uint64_t MEMORY_ALIGNMENT = posix::Allocator::MEMORY_ALIGNMENT;

MemPool(const cxx::greater_or_equal<uint32_t, MEMORY_ALIGNMENT> f_chunkSize,
const cxx::greater_or_equal<uint32_t, 1> f_numberOfChunks,
posix::Allocator* f_managementAllocator,
posix::Allocator* f_payloadAllocator);
MemPool(const cxx::greater_or_equal<uint32_t, MEMORY_ALIGNMENT> chunkSize,
const cxx::greater_or_equal<uint32_t, 1> numberOfChunks,
posix::Allocator* managementAllocator,
posix::Allocator* payloadAllocator);

MemPool(const MemPool&) = delete;
MemPool(MemPool&&) = delete;
Expand All @@ -75,14 +75,14 @@ class MemPool

rp::RelativePointer<uint8_t> m_rawMemory;

uint32_t m_chunkSize{0u};
uint32_t m_chunkSize{0U};
/// needs to be 32 bit since loffli supports only 32 bit numbers
/// (cas is only 64 bit and we need the other 32 bit for the aba counter)
uint32_t m_numberOfChunks{0u};
uint32_t m_numberOfChunks{0U};

/// @todo: put this into one struct and in a separate class in concurrent.
std::atomic<uint32_t> m_usedChunks{0u};
std::atomic<uint32_t> m_minFree{0u};
std::atomic<uint32_t> m_usedChunks{0U};
std::atomic<uint32_t> m_minFree{0U};
/// @todo: end

freeList_t m_freeIndices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ template <typename SharedMemoryObjectType = posix::SharedMemoryObject, typename
class MePooSegment
{
public:
MePooSegment(const MePooConfig& f_mempoolConfig,
posix::Allocator* f_managementAllocator,
const posix::PosixGroup& f_readerGroup,
const posix::PosixGroup& f_writerGroup,
MePooSegment(const MePooConfig& mempoolConfig,
posix::Allocator* managementAllocator,
const posix::PosixGroup& readerGroup,
const posix::PosixGroup& writerGroup,
const iox::mepoo::MemoryInfo& memoryInfo = iox::mepoo::MemoryInfo());

posix::PosixGroup getWriterGroup() const;
Expand All @@ -46,8 +46,8 @@ class MePooSegment
uint64_t getSegmentId() const;

protected:
SharedMemoryObjectType createSharedMemoryObject(const MePooConfig& f_mempoolConfig,
const posix::PosixGroup& f_writerGroup);
SharedMemoryObjectType createSharedMemoryObject(const MePooConfig& mempoolConfig,
const posix::PosixGroup& writerGroup);

protected:
SharedMemoryObjectType m_sharedMemoryObject;
Expand Down
47 changes: 24 additions & 23 deletions iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl
Original file line number Diff line number Diff line change
Expand Up @@ -28,58 +28,59 @@ namespace iox
namespace mepoo
{
template <typename SharedMemoryObjectType, typename MemoryManagerType>
inline MePooSegment<SharedMemoryObjectType, MemoryManagerType>::MePooSegment(const MePooConfig& f_mempoolConfig,
posix::Allocator* f_managementAllocator,
const posix::PosixGroup& f_readerGroup,
const posix::PosixGroup& f_writerGroup,
inline MePooSegment<SharedMemoryObjectType, MemoryManagerType>::MePooSegment(const MePooConfig& mempoolConfig,
posix::Allocator* managementAllocator,
const posix::PosixGroup& readerGroup,
const posix::PosixGroup& writerGroup,
const iox::mepoo::MemoryInfo& memoryInfo)
: m_sharedMemoryObject(std::move(createSharedMemoryObject(f_mempoolConfig, f_writerGroup)))
, m_readerGroup(f_readerGroup)
, m_writerGroup(f_writerGroup)
: m_sharedMemoryObject(std::move(createSharedMemoryObject(mempoolConfig, writerGroup)))
, m_readerGroup(readerGroup)
, m_writerGroup(writerGroup)
, m_memoryInfo(memoryInfo)
{
using namespace posix;
AccessController f_accessController;
if (!(f_readerGroup == f_writerGroup))
AccessController accessController;
if (!(readerGroup == writerGroup))
{
f_accessController.addPermissionEntry(
AccessController::Category::SPECIFIC_GROUP, AccessController::Permission::READ, f_readerGroup.getName());
accessController.addPermissionEntry(
AccessController::Category::SPECIFIC_GROUP, AccessController::Permission::READ, readerGroup.getName());
}
f_accessController.addPermissionEntry(
AccessController::Category::SPECIFIC_GROUP, AccessController::Permission::READWRITE, f_writerGroup.getName());
f_accessController.addPermissionEntry(AccessController::Category::USER, AccessController::Permission::READWRITE);
f_accessController.addPermissionEntry(AccessController::Category::GROUP, AccessController::Permission::READWRITE);
f_accessController.addPermissionEntry(AccessController::Category::OTHERS, AccessController::Permission::NONE);
accessController.addPermissionEntry(
AccessController::Category::SPECIFIC_GROUP, AccessController::Permission::READWRITE, writerGroup.getName());
accessController.addPermissionEntry(AccessController::Category::USER, AccessController::Permission::READWRITE);
accessController.addPermissionEntry(AccessController::Category::GROUP, AccessController::Permission::READWRITE);
accessController.addPermissionEntry(AccessController::Category::OTHERS, AccessController::Permission::NONE);

if (!f_accessController.writePermissionsToFile(m_sharedMemoryObject.getFileHandle()))
if (!accessController.writePermissionsToFile(m_sharedMemoryObject.getFileHandle()))
{
errorHandler(Error::kMEPOO__SEGMENT_COULD_NOT_APPLY_POSIX_RIGHTS_TO_SHARED_MEMORY);
}

m_memoryManager.configureMemoryManager(f_mempoolConfig, f_managementAllocator, m_sharedMemoryObject.getAllocator());
m_memoryManager.configureMemoryManager(mempoolConfig, managementAllocator, m_sharedMemoryObject.getAllocator());
m_sharedMemoryObject.finalizeAllocation();
}

template <typename SharedMemoryObjectType, typename MemoryManagerType>
inline SharedMemoryObjectType MePooSegment<SharedMemoryObjectType, MemoryManagerType>::createSharedMemoryObject(
const MePooConfig& f_mempoolConfig, const posix::PosixGroup& f_writerGroup)
inline SharedMemoryObjectType
MePooSegment<SharedMemoryObjectType, MemoryManagerType>::createSharedMemoryObject(const MePooConfig& mempoolConfig,
const posix::PosixGroup& writerGroup)
{
// we let the OS decide where to map the shm segments
constexpr void* BASE_ADDRESS_HINT{nullptr};

// on qnx the current working directory will be added to the /dev/shmem path if the leading slash is missing
posix::SharedMemory::Name_t shmName = "/" + f_writerGroup.getName();
posix::SharedMemory::Name_t shmName = "/" + writerGroup.getName();

return std::move(
SharedMemoryObjectType::create(shmName,
MemoryManager::requiredChunkMemorySize(f_mempoolConfig),
MemoryManager::requiredChunkMemorySize(mempoolConfig),
posix::AccessMode::READ_WRITE,
posix::OwnerShip::MINE,
BASE_ADDRESS_HINT,
static_cast<mode_t>(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))
.and_then([this](auto& sharedMemoryObject) {
this->setSegmentId(iox::rp::BaseRelativePointer::registerPtr(sharedMemoryObject.getBaseAddress(),
sharedMemoryObject.getSizeInBytes()));
sharedMemoryObject.getSizeInBytes()));

LogDebug() << "Roudi registered payload segment "
<< iox::log::HexFormat(reinterpret_cast<uint64_t>(sharedMemoryObject.getBaseAddress()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class SharedChunk
{
public:
SharedChunk() = default;
SharedChunk(ChunkManagement* const f_resource);
SharedChunk(const rp::RelativePointer<ChunkManagement>& f_resource);
SharedChunk(ChunkManagement* const resource);
SharedChunk(const rp::RelativePointer<ChunkManagement>& resource);
~SharedChunk();

SharedChunk(const SharedChunk& rhs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace popo
struct ChunkTuple
{
ChunkTuple() = default;
explicit ChunkTuple(rp::RelativePointer<mepoo::ChunkManagement> f_chunk) noexcept;
explicit ChunkTuple(rp::RelativePointer<mepoo::ChunkManagement> chunk) noexcept;

rp::BaseRelativePointer::id_t m_segmentId{rp::BaseRelativePointer::NULL_POINTER_ID};
rp::BaseRelativePointer::offset_t m_chunkOffset{rp::BaseRelativePointer::NULL_POINTER_OFFSET};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UsedChunkList
}

// only from runtime context
bool insert(mepoo::SharedChunk f_chunk)
bool insert(mepoo::SharedChunk chunk)
{
if (freeSpaceInList())
{
Expand All @@ -51,7 +51,7 @@ class UsedChunkList
m_usedListHead = m_freeListHead;

// store chunk mgmt ptr
m_data[m_usedListHead] = f_chunk.release();
m_data[m_usedListHead] = chunk.release();

// set freeListHead to the next free entry
m_freeListHead = nextFree;
Expand All @@ -67,18 +67,18 @@ class UsedChunkList
}

// only from runtime context
bool remove(const mepoo::ChunkHeader* f_chunkHeader, mepoo::SharedChunk& f_chunk)
bool remove(const mepoo::ChunkHeader* chunkHeader, mepoo::SharedChunk& chunk)
{
uint32_t previous = InvalidIndex;

// go through usedList with stored chunks
for (uint32_t current = m_usedListHead; current != InvalidIndex; current = m_list[current])
{
// does the entry match the one we want to remove?
if (m_data[current] != nullptr && m_data[current]->m_chunkHeader == f_chunkHeader)
if (m_data[current] != nullptr && m_data[current]->m_chunkHeader == chunkHeader)
{
// return the chunk mgmt entry as SharedChunk object
f_chunk = mepoo::SharedChunk(m_data[current]);
chunk = mepoo::SharedChunk(m_data[current]);
m_data[current] = nullptr;

// remove index from used list
Expand Down
22 changes: 11 additions & 11 deletions iceoryx_posh/source/mepoo/mem_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ namespace iox
{
namespace mepoo
{
MemPool::MemPool(const cxx::greater_or_equal<uint32_t, MEMORY_ALIGNMENT> f_chunkSize,
const cxx::greater_or_equal<uint32_t, 1> f_numberOfChunks,
posix::Allocator* f_managementAllocator,
posix::Allocator* f_payloadAllocator)
: m_chunkSize(f_chunkSize)
, m_numberOfChunks(f_numberOfChunks)
, m_minFree(f_numberOfChunks)
MemPool::MemPool(const cxx::greater_or_equal<uint32_t, MEMORY_ALIGNMENT> chunkSize,
const cxx::greater_or_equal<uint32_t, 1> numberOfChunks,
posix::Allocator* managementAllocator,
posix::Allocator* payloadAllocator)
: m_chunkSize(chunkSize)
, m_numberOfChunks(numberOfChunks)
, m_minFree(numberOfChunks)
{
if (isMultipleOfAlignment(f_chunkSize))
if (isMultipleOfAlignment(chunkSize))
{
m_rawMemory =
static_cast<uint8_t*>(f_payloadAllocator->allocate(static_cast<uint64_t>(m_numberOfChunks) * m_chunkSize));
static_cast<uint8_t*>(payloadAllocator->allocate(static_cast<uint64_t>(m_numberOfChunks) * m_chunkSize));
auto memoryLoFFLi =
static_cast<uint32_t*>(f_managementAllocator->allocate(freeList_t::requiredMemorySize(m_numberOfChunks)));
static_cast<uint32_t*>(managementAllocator->allocate(freeList_t::requiredMemorySize(m_numberOfChunks)));
m_freeIndices.init(memoryLoFFLi, m_numberOfChunks);
}
else
{
std::cerr << f_chunkSize << " :: " << f_numberOfChunks << std::endl;
std::cerr << chunkSize << " :: " << numberOfChunks << std::endl;
errorHandler(
Error::kMEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_LARGER_THAN_SHARED_MEMORY_ALIGNMENT_AND_MULTIPLE_OF_ALIGNMENT);
}
Expand Down
8 changes: 4 additions & 4 deletions iceoryx_posh/source/mepoo/shared_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace iox
{
namespace mepoo
{
SharedChunk::SharedChunk(ChunkManagement* const f_resource)
: m_chunkManagement(f_resource)
SharedChunk::SharedChunk(ChunkManagement* const resource)
: m_chunkManagement(resource)
{
}

SharedChunk::SharedChunk(const rp::RelativePointer<ChunkManagement>& f_resource)
: m_chunkManagement(f_resource)
SharedChunk::SharedChunk(const rp::RelativePointer<ChunkManagement>& resource)
: m_chunkManagement(resource)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace iox
{
namespace popo
{
ChunkTuple::ChunkTuple(iox::rp::RelativePointer<mepoo::ChunkManagement> f_chunk) noexcept
: m_segmentId(f_chunk.getId())
, m_chunkOffset(f_chunk.getOffset())
ChunkTuple::ChunkTuple(iox::rp::RelativePointer<mepoo::ChunkManagement> chunk) noexcept
: m_segmentId(chunk.getId())
, m_chunkOffset(chunk.getOffset())
{
}

Expand Down
22 changes: 11 additions & 11 deletions iceoryx_utils/include/iceoryx_utils/internal/concurrent/loffli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ class LoFFLi
/// };
/// @endcode

uint32_t m_size{0u};
uint32_t m_invalidIndex{0u};
std::atomic<Node> m_head{{0u, 1u}};
uint32_t m_size{0U};
uint32_t m_invalidIndex{0U};
std::atomic<Node> m_head{{0U, 1U}};
iox::rp::RelativePointer<uint32_t> m_nextFreeIndex;

public:
LoFFLi() = default;
/// @todo: why init not in ctor
/// @todo: f_size = capacity
/// @todo: size = capacity

/// Initializes the lock-free free-list
/// @param [in] f_freeIndicesMemory pointer to a memory with the size calculated by requiredMemorySize()
/// @param [in] f_size is the number of elements of the free-list; must be the same used at requiredMemorySize()
void init(cxx::not_null<uint32_t*> f_freeIndicesMemory, const uint32_t f_size);
/// @param [in] freeIndicesMemory pointer to a memory with the size calculated by requiredMemorySize()
/// @param [in] size is the number of elements of the free-list; must be the same used at requiredMemorySize()
void init(cxx::not_null<uint32_t*> freeIndicesMemory, const uint32_t size);

/// Pop a value from the free-list
/// @param [out] index for an element to use
Expand All @@ -85,11 +85,11 @@ class LoFFLi
bool push(const uint32_t index);

/// Calculates the required memory size for a free-list
/// @param [in] f_size is the number of elements of the free-list
/// @return the required memory size for a free-list with f_size elements
static inline constexpr std::size_t requiredMemorySize(const uint32_t f_size)
/// @param [in] size is the number of elements of the free-list
/// @return the required memory size for a free-list with size elements
static inline constexpr std::size_t requiredMemorySize(const uint32_t size)
{
return (static_cast<size_t>(f_size) + 1u) * sizeof(uint32_t);
return (static_cast<size_t>(size) + 1U) * sizeof(uint32_t);
}
};

Expand Down
10 changes: 5 additions & 5 deletions iceoryx_utils/source/concurrent/loffli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ namespace iox
{
namespace concurrent
{
void LoFFLi::init(cxx::not_null<uint32_t*> f_freeIndicesMemory, const uint32_t f_size)
void LoFFLi::init(cxx::not_null<uint32_t*> freeIndicesMemory, const uint32_t size)
{
cxx::Expects(f_size > 0);
cxx::Expects(f_size <= UINT32_MAX - 2U);
cxx::Expects(size > 0);
cxx::Expects(size <= UINT32_MAX - 2U);

m_nextFreeIndex = f_freeIndicesMemory;
m_size = f_size;
m_nextFreeIndex = freeIndicesMemory;
m_size = size;
m_invalidIndex = m_size + 1;

if (m_nextFreeIndex != nullptr)
Expand Down

0 comments on commit d841e8c

Please sign in to comment.