From 7b4a2ae93233cf94096e6b9d97909e2423927fad Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Mon, 24 Apr 2017 13:55:10 +0200 Subject: [PATCH] shmem: configurable segment name. --- fairmq/options/FairMQProgOptions.cxx | 81 +++++++++++----------- fairmq/shmem/FairMQTransportFactorySHM.cxx | 10 +-- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index 704fece5..3b043b58 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -297,53 +297,56 @@ void FairMQProgOptions::InitOptionDescription() if (fUseConfigFile) { fMQOptionsInCmd.add_options() - ("id", po::value(), "Device ID (required argument).") - ("io-threads", po::value()->default_value(1), "Number of I/O threads.") - ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") - ("config", po::value()->default_value("static"), "Config source ('static'/).") - ("control", po::value()->default_value("interactive"), "States control ('interactive'/'static'/).") - ("network-interface", po::value()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") - ("config-key", po::value(), "Use provided value instead of device id for fetching the configuration from the config file.") - ("catch-signals", po::value()->default_value(1), "Enable signal handling (1/0).") - ("initialization-timeout", po::value()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") - ("port-range-min", po::value()->default_value(22000), "Start of the port range for dynamic initialization.") - ("port-range-max", po::value()->default_value(32000), "End of the port range for dynamic initialization.") - ("log-to-file", po::value()->default_value(""), "Log output to a file.") - ("shm-segment-size", po::value()->default_value(2000000000), "shmem transport: size of the shared memory segment (in bytes).") + ("id", po::value(), "Device ID (required argument).") + ("io-threads", po::value()->default_value(1), "Number of I/O threads.") + ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") + ("config", po::value()->default_value("static"), "Config source ('static'/).") + ("control", po::value()->default_value("interactive"), "States control ('interactive'/'static'/).") + ("network-interface", po::value()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") + ("config-key", po::value(), "Use provided value instead of device id for fetching the configuration from the config file.") + ("catch-signals", po::value()->default_value(1), "Enable signal handling (1/0).") + ("initialization-timeout", po::value()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") + ("port-range-min", po::value()->default_value(22000), "Start of the port range for dynamic initialization.") + ("port-range-max", po::value()->default_value(32000), "End of the port range for dynamic initialization.") + ("log-to-file", po::value()->default_value(""), "Log output to a file.") + ("shm-segment-size", po::value()->default_value(2000000000), "shmem transport: size of the shared memory segment (in bytes).") + ("shm-segment-name", po::value()->default_value("fairmq_shmem_main"), "shmem transport: name of the shared memory segment.") ; fMQOptionsInCfg.add_options() - ("id", po::value()->required(), "Device ID (required argument).") - ("io-threads", po::value()->default_value(1), "Number of I/O threads.") - ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") - ("config", po::value()->default_value("static"), "Config source ('static'/).") - ("control", po::value()->default_value("interactive"), "States control ('interactive'/'static'/).") - ("network-interface", po::value()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") - ("config-key", po::value(), "Use provided value instead of device id for fetching the configuration from the config file.") - ("catch-signals", po::value()->default_value(1), "Enable signal handling (1/0).") - ("initialization-timeout", po::value()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") - ("port-range-min", po::value()->default_value(22000), "Start of the port range for dynamic initialization.") - ("port-range-max", po::value()->default_value(32000), "End of the port range for dynamic initialization.") - ("log-to-file", po::value()->default_value(""), "Log output to a file.") - ("shm-segment-size", po::value()->default_value(2000000000), "shmem transport: size of the shared memory segment (in bytes).") + ("id", po::value()->required(), "Device ID (required argument).") + ("io-threads", po::value()->default_value(1), "Number of I/O threads.") + ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") + ("config", po::value()->default_value("static"), "Config source ('static'/).") + ("control", po::value()->default_value("interactive"), "States control ('interactive'/'static'/).") + ("network-interface", po::value()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") + ("config-key", po::value(), "Use provided value instead of device id for fetching the configuration from the config file.") + ("catch-signals", po::value()->default_value(1), "Enable signal handling (1/0).") + ("initialization-timeout", po::value()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") + ("port-range-min", po::value()->default_value(22000), "Start of the port range for dynamic initialization.") + ("port-range-max", po::value()->default_value(32000), "End of the port range for dynamic initialization.") + ("log-to-file", po::value()->default_value(""), "Log output to a file.") + ("shm-segment-size", po::value()->default_value(2000000000), "shmem transport: size of the shared memory segment (in bytes).") + ("shm-segment-name", po::value()->default_value("fairmq_shmem_main"), "shmem transport: name of the shared memory segment.") ; } else { fMQOptionsInCmd.add_options() - ("id", po::value()->required(), "Device ID (required argument)") - ("io-threads", po::value()->default_value(1), "Number of I/O threads") - ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") - ("config", po::value()->default_value("static"), "Config source ('static'/).") - ("control", po::value()->default_value("interactive"), "States control ('interactive'/'static'/).") - ("network-interface", po::value()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") - ("config-key", po::value(), "Use provided value instead of device id for fetching the configuration from the config file.") - ("catch-signals", po::value()->default_value(1), "Enable signal handling (1/0).") - ("initialization-timeout", po::value()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") - ("port-range-min", po::value()->default_value(22000), "Start of the port range for dynamic initialization.") - ("port-range-max", po::value()->default_value(32000), "End of the port range for dynamic initialization.") - ("log-to-file", po::value()->default_value(""), "Log output to a file.") - ("shm-segment-size", po::value()->default_value(2000000000), "shmem transport: size of the shared memory segment (in bytes).") + ("id", po::value()->required(), "Device ID (required argument)") + ("io-threads", po::value()->default_value(1), "Number of I/O threads") + ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") + ("config", po::value()->default_value("static"), "Config source ('static'/).") + ("control", po::value()->default_value("interactive"), "States control ('interactive'/'static'/).") + ("network-interface", po::value()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") + ("config-key", po::value(), "Use provided value instead of device id for fetching the configuration from the config file.") + ("catch-signals", po::value()->default_value(1), "Enable signal handling (1/0).") + ("initialization-timeout", po::value()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") + ("port-range-min", po::value()->default_value(22000), "Start of the port range for dynamic initialization.") + ("port-range-max", po::value()->default_value(32000), "End of the port range for dynamic initialization.") + ("log-to-file", po::value()->default_value(""), "Log output to a file.") + ("shm-segment-size", po::value()->default_value(2000000000), "shmem transport: size of the shared memory segment (in bytes).") + ("shm-segment-name", po::value()->default_value("fairmq_shmem_main"), "shmem transport: name of the shared memory segment.") ; } diff --git a/fairmq/shmem/FairMQTransportFactorySHM.cxx b/fairmq/shmem/FairMQTransportFactorySHM.cxx index 7ec7e63a..d8027c6b 100644 --- a/fairmq/shmem/FairMQTransportFactorySHM.cxx +++ b/fairmq/shmem/FairMQTransportFactorySHM.cxx @@ -53,10 +53,12 @@ void FairMQTransportFactorySHM::Initialize(const FairMQProgOptions* config) { int numIoThreads = 1; size_t segmentSize = 2000000000; + string segmentName = "fairmq_shmem_main"; if (config) { numIoThreads = config->GetValue("io-threads"); segmentSize = config->GetValue("shm-segment-size"); + segmentName = config->GetValue("shm-segment-name"); } else { @@ -77,7 +79,7 @@ void FairMQTransportFactorySHM::Initialize(const FairMQProgOptions* config) fSendHeartbeats = true; fHeartbeatThread = thread(&FairMQTransportFactorySHM::SendHeartbeats, this); - Manager::Instance().InitializeSegment("open_or_create", "FairMQSharedMemory", segmentSize); + Manager::Instance().InitializeSegment("open_or_create", segmentName, segmentSize); LOG(DEBUG) << "shmem: created/opened shared memory segment of " << segmentSize << " bytes. Available are " << Manager::Instance().Segment()->get_free_memory() << " bytes."; { // mutex scope @@ -202,9 +204,9 @@ void FairMQTransportFactorySHM::Terminate() if (fDeviceCounter->count == 0) { - LOG(DEBUG) << "shmem: last FairMQSharedMemory user, removing segment."; + LOG(DEBUG) << "shmem: last 'fairmq_shmem_main' user, removing segment."; - if (bipc::shared_memory_object::remove("FairMQSharedMemory")) + if (bipc::shared_memory_object::remove("fairmq_shmem_main")) { LOG(DEBUG) << "shmem: successfully removed shared memory segment after the device has stopped."; } @@ -215,7 +217,7 @@ void FairMQTransportFactorySHM::Terminate() } else { - LOG(DEBUG) << "shmem: other FairMQSharedMemory users present (" << fDeviceCounter->count << "), not removing it."; + LOG(DEBUG) << "shmem: other 'fairmq_shmem_main' users present (" << fDeviceCounter->count << "), not removing it."; } } }