From dd4087b08ff85222a7729a11056cf93d7a6277b7 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 21 Jan 2022 18:42:02 +0100 Subject: [PATCH 1/3] [lib/env] Make the string parameters non-rvalue references --- emper/lib/env.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/emper/lib/env.hpp b/emper/lib/env.hpp index 4d97aaec..5ec0819b 100644 --- a/emper/lib/env.hpp +++ b/emper/lib/env.hpp @@ -9,7 +9,7 @@ namespace emper::lib::env { -static auto getBoolFromEnv(const std::string&& key) -> std::optional { +static auto getBoolFromEnv(const std::string& key) -> std::optional { DBG("parse " << key << " environment variable"); char* envVar = std::getenv(key.c_str()); if (!envVar) { @@ -29,7 +29,7 @@ static auto getBoolFromEnv(const std::string&& key) -> std::optional { } template -static auto getUnsignedFromEnv(const std::string&& key) -> std::optional { +static auto getUnsignedFromEnv(const std::string& key) -> std::optional { DBG("parse " << key << " environment variable"); char* envVar = std::getenv(key.c_str()); if (!envVar) { -- GitLab From e96374cd3510624dff67b0ee2cd84f7ff90e7d25 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 21 Jan 2022 17:39:31 +0100 Subject: [PATCH 2/3] [Runtime] Move EMPER_* environment variable handling into module Also add a DBG message that is emitted if such a EMPER_* environment variable has been processed. --- emper/Runtime.cpp | 34 +++++++++++++++++++++++++++++++--- emper/Runtime.hpp | 14 ++++---------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/emper/Runtime.cpp b/emper/Runtime.cpp index b0bd380b..1c9f097e 100644 --- a/emper/Runtime.cpp +++ b/emper/Runtime.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020-2021 Florian Schmaus, Florian Fischer +// Copyright © 2020-2022 Florian Schmaus, Florian Fischer #include "Runtime.hpp" #include @@ -36,6 +36,7 @@ #include "io/IoContext.hpp" #include "io/Stats.hpp" #include "lib/DebugUtil.hpp" +#include "lib/env.hpp" #include "log/LogBuffer.hpp" #include "stats/FromAnywhere.hpp" #include "stats/Worker.hpp" @@ -323,9 +324,12 @@ auto Runtime::workerLoop(Worker* worker) -> void* { } auto Runtime::getDefaultWorkerCount() -> workerid_t { - auto workerCountEnv = emper::lib::env::getUnsignedFromEnv("EMPER_WORKER_COUNT"); + static const std::string workerCountEnvVarName = "EMPER_WORKER_COUNT"; + auto workerCountEnv = emper::lib::env::getUnsignedFromEnv(workerCountEnvVarName); if (workerCountEnv) { - return workerCountEnv.value(); + auto value = workerCountEnv.value(); + DBG("Processed " << workerCountEnvVarName << "=" << value); + return value; } // The CPU count reported by sysconf(_SC_NPROCESSORS_ONLN), sysconf(_SC_NPROCESSORS_CONF) @@ -482,3 +486,27 @@ void Runtime::executeAndWait(std::function f) { fiberFinished.lock(); } + +auto Runtime::shouldPinWorkers() -> bool { + static const std::string pinWorkersEnvVarName = "EMPER_PIN_WORKERS"; + auto pinWorkersEnv = emper::lib::env::getBoolFromEnv(pinWorkersEnvVarName); + if (pinWorkersEnv) { + auto value = pinWorkersEnv.value(); + DBG("Processed " << pinWorkersEnvVarName << "=" << value); + return value; + } + + return true; +} + +auto Runtime::getDefaultPinningOffset() -> workerid_t { + static const std::string pinningOffsetEnvVarName = "EMPER_PINNING_OFFSET"; + auto pinningOffsetEnv = emper::lib::env::getUnsignedFromEnv(pinningOffsetEnvVarName); + if (pinningOffsetEnv) { + auto value = pinningOffsetEnv.value(); + DBG("Processed " << pinningOffsetEnvVarName << "=" << value); + return value; + } + + return 0; +} diff --git a/emper/Runtime.hpp b/emper/Runtime.hpp index 8261c8d5..d91d779d 100644 --- a/emper/Runtime.hpp +++ b/emper/Runtime.hpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020-2021 Florian Schmaus +// Copyright © 2020-2022 Florian Schmaus #pragma once #include // for pthread_t @@ -25,8 +25,7 @@ #include "Scheduler.hpp" // for Scheduler #include "WakeupStrategy.hpp" #include "Worker.hpp" -#include "emper-common.h" // for workerid_t -#include "lib/env.hpp" +#include "emper-common.h" // for workerid_t #include "lib/sync/Latch.hpp" // for Latch #include "lib/sync/Semaphore.hpp" #include "sleep_strategy/WorkerSleepStrategy.hpp" @@ -121,13 +120,8 @@ class Runtime : public Logger { static auto getDefaultWorkerCount() -> workerid_t; - static auto shouldPinWorkers() -> bool { - return emper::lib::env::getBoolFromEnv("EMPER_PIN_WORKERS").value_or(true); - } - - static auto getDefaultPinningOffset() -> workerid_t { - return emper::lib::env::getUnsignedFromEnv("EMPER_PINNING_OFFSET").value_or(0); - } + static auto shouldPinWorkers() -> bool; + static auto getDefaultPinningOffset() -> workerid_t; protected: void addNewWorkerHook(const std::function& hook) { -- GitLab From 28cc18d2d72011f9a11c1bcfabcd9528d121770b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 21 Jan 2022 17:40:18 +0100 Subject: [PATCH 3/3] [lib/env] Remove noisy DBG statement That debug statement is noisy, as it is emitted all the time, irregardless whether or not the environment variable is set. --- emper/lib/env.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/emper/lib/env.hpp b/emper/lib/env.hpp index 5ec0819b..d03784be 100644 --- a/emper/lib/env.hpp +++ b/emper/lib/env.hpp @@ -10,7 +10,6 @@ namespace emper::lib::env { static auto getBoolFromEnv(const std::string& key) -> std::optional { - DBG("parse " << key << " environment variable"); char* envVar = std::getenv(key.c_str()); if (!envVar) { return std::nullopt; @@ -30,7 +29,6 @@ static auto getBoolFromEnv(const std::string& key) -> std::optional { template static auto getUnsignedFromEnv(const std::string& key) -> std::optional { - DBG("parse " << key << " environment variable"); char* envVar = std::getenv(key.c_str()); if (!envVar) { return std::nullopt; -- GitLab