21#include <fairlogger/Logger.h>
26#include <boost/interprocess/managed_external_buffer.hpp>
27#include <boost/interprocess/allocators/allocator.hpp>
32using namespace boost::interprocess;
44ShmManager::ShmManager() =
default;
46void* ShmManager::tryAttach(
bool& success)
55 LOG(info) <<
"FOUND ID TO ATTACH " << mShmID;
64 addr_wanted = (
void*)atoll(addrstr);
69 LOG(info) <<
"TRYING ADDRESS " << addr_wanted;
70 auto addr = shmat(mShmID, addr_wanted, 0);
71 if (addr != (
void*)-1) {
73 assert(addr == addr_wanted);
81 addr = shmat(mShmID,
nullptr, 0);
82 if (addr == (
void*)(-1)) {
83 LOG(fatal) <<
"SHOULD NOT HAPPEN";
87 info->failures.fetch_add(1);
90 mSegInfoPtr =
nullptr;
100 LOG(info) <<
"ATTACHED WORKERS " << mSegInfoPtr->
counter;
101 LOG(info) <<
"CONNECTION FAILURES " << mSegInfoPtr->
failures;
103 LOG(info) <<
"no segment info to print";
112 LOG(warn) <<
"A SEGMENT IS ALREADY INITIALIZED";
118 LOG(warn) <<
"A SEGMET IS ALREADY PRESENT ON THE SYSTEM";
123 LOG(info) <<
"CREATING SIM SHARED MEM SEGMENT FOR " << nsegments <<
" WORKERS";
126 if ((mShmID = shmget(IPC_PRIVATE, totalsize, IPC_CREAT | 0600)) == -1) {
127 perror(
"shmget: shmget failed");
131 auto addr = shmat(mShmID,
nullptr, 0);
133 LOG(
debug) <<
"COMMON ADDRESS " << addr <<
" AS NUMBER " << (
unsigned long long)addr;
137 std::memcpy(addr, &info,
sizeof(info));
149 shmctl(mShmID, IPC_RMID,
nullptr);
152 LOG(info) <<
"SHARED MEM INITIALIZED AT ID " << mShmID;
154 LOG(warn) <<
"COULD NOT CREATE SHARED MEMORY ... FALLING BACK TO SIMPLE MODE";
164 LOG(info) <<
"OCCUPYING A SEGMENT IN A SHARED REGION";
167 LOG(warn) <<
"NO INFORMATION ABOUT SHARED SEGMENT FOUND";
172 LOG(warn) <<
"REGION ALREADY OCCUPIED OR CREATED";
183 LOG(info) <<
"OCCUPYING A SEGMENT IN A SHARED REGION";
186 LOG(warn) <<
"NO INFORMATION ABOUT SHARED SEGMENT FOUND";
191 LOG(warn) <<
"REGION ALREADY OCCUPIED OR CREATED";
196 auto addr = tryAttach(
b);
201 const int segmentcounter = info->counter.fetch_add(npools);
202 LOG(info) <<
"SEGMENTCOUNT " << segmentcounter;
205 mBufferPtr = (
void*)(((
char*)addr) + offset_in_bytes);
208 assert((
unsigned long long)((
char*)mBufferPtr - (
char*)addr) + mPoolSize <= info->allocedbytes);
210 boostmanagedbuffer =
new boost::interprocess::wmanaged_external_buffer(create_only, mBufferPtr, mPoolSize);
211 boostallocator =
new boost::interprocess::allocator<char, wmanaged_external_buffer::segment_manager>(
212 boostmanagedbuffer->get_segment_manager());
214 LOG(info) <<
"SHARED MEM OCCUPIED AT ID " << mShmID <<
" AND SEGMENT COUNTER " << segmentcounter;
216 LOG(info) <<
"ATTACH NOT SUCCESSFUL";
220ShmManager::~ShmManager()
229 void* addr =
nullptr;
230 std::lock_guard<std::mutex> lock(mAllocMutex);
232 addr = (
void*)boostallocator->allocate(
size).get();
233 }
catch (
const std::exception&
e) {
234 LOG(fatal) <<
"THROW IN BOOST SHM ALLOCATION";
241 std::lock_guard<std::mutex> lock(mAllocMutex);
242 boostallocator->deallocate((
char*)
ptr,
s);
249 LOG(
debug) <<
"REMOVING SHARED MEM SEGMENT ID " << mShmID;
251 shmctl(mShmID, IPC_RMID,
nullptr);
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
void * getmemblock(size_t size)
void printSegInfo() const
void freememblock(void *, std::size_t=1)
bool attachToGlobalSegment()
bool createGlobalSegment(int nsubsegments=1)
void occupySegment(bool wholeRegion=false)
GLboolean GLboolean GLboolean b
constexpr size_t SHMPOOLSIZE
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Common utility functions.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"