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

Reset TLS on Profiling Entrance #999

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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/ThreadUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ std::string processName(int32_t pid);
// and its parents.
std::vector<std::pair<int32_t, std::string>> pidCommandPairsOfAncestors();

// Resets all cached Thread local state, this must be done on
// forks to prevent stale values from being retained.
void resetTLS();

} // namespace libkineto
4 changes: 4 additions & 0 deletions libkineto/include/libkineto.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class LibkinetoApi {
suppressLibkinetoLogMessages();
}

void resetKinetoTLS() {
resetTLS();
}

// Provides access to profier configuration manaegement
ConfigLoader& configLoader() {
return configLoader_;
Expand Down
2 changes: 2 additions & 0 deletions libkineto/src/ActivityProfilerProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ActivityProfilerController.h"
#include "Config.h"
#include "Logger.h"
#include "ThreadUtil.h"

namespace KINETO_NAMESPACE {

Expand All @@ -31,6 +32,7 @@ void ActivityProfilerProxy::init() {
}

void ActivityProfilerProxy::scheduleTrace(const std::string& configStr) {
resetTLS();
Config config;
config.parse(configStr);
controller_->scheduleTrace(config);
Expand Down
4 changes: 3 additions & 1 deletion libkineto/src/ConfigLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ void ConfigLoader::stopThread() {
std::lock_guard<std::mutex> lock(updateThreadMutex_);
updateThreadCondVar_.notify_one();
}
updateThread_->join();
if (updateThread_->joinable()) {
updateThread_->join();
}
updateThread_ = nullptr;
}
}
Expand Down
8 changes: 8 additions & 0 deletions libkineto/src/ThreadUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ int32_t threadId() {
return _tid;
}

// Resets all cached Thread local state, this must be done on
// forks to prevent stale values from being retained.
void resetTLS() {
_pid = 0;
_tid = 0;
_sysTid = 0;
}

namespace {
static constexpr size_t kMaxThreadNameLength = 16;

Expand Down
1 change: 1 addition & 0 deletions libkineto/src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ConfigLoader.h"
#include "DaemonConfigLoader.h"
#include "DeviceUtil.h"
#include "ThreadUtil.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops lets remove

#ifdef HAS_CUPTI
#include "CuptiActivityApi.h"
#include "CuptiCallbackApi.h"
Expand Down
Loading