Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call getenv in side threads #984

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libkineto/include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,8 @@ class Config : public AbstractConfig {

constexpr char kUseDaemonEnvVar[] = "KINETO_USE_DAEMON";

#if __linux__
bool isDaemonEnvVarSet();
#endif

} // namespace libkineto
2 changes: 1 addition & 1 deletion libkineto/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Config::Config()
factories->addFeatureConfigs(*this);
}
#if __linux__
enableIpcFabric_ = (getenv(kUseDaemonEnvVar) != nullptr);
enableIpcFabric_ = libkineto::isDaemonEnvVarSet();
#endif
}

Expand Down
12 changes: 11 additions & 1 deletion libkineto/src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
#include "Logger.h"

namespace KINETO_NAMESPACE {
#if __linux__
bool isDaemonEnvVarSet() {
static bool rc = [] {
void *ptr = getenv(kUseDaemonEnvVar);
return ptr != nullptr;
}();
return rc;
}
#endif


#if __linux__ || defined(HAS_CUPTI)
static bool initialized = false;
Expand Down Expand Up @@ -131,7 +141,7 @@ void libkineto_init(bool cpuOnly, bool logOnError) {

// Factory to connect to open source daemon if present
#if __linux__
if (getenv(kUseDaemonEnvVar) != nullptr) {
if (libkineto::isDaemonEnvVarSet()) {
LOG(INFO) << "Registering daemon config loader, cpuOnly = "
<< cpuOnly;
DaemonConfigLoader::registerFactory();
Expand Down
Loading