Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tgerdesnv committed May 31, 2024
1 parent aac7521 commit 7f3bbfa
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/c++/perf_analyzer/concurrency_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ConcurrencyWorker::HandleNoConcurrency()
wake_signal_.wait(lock, [this]() {
return exiting_ || (thread_config_->concurrency_ > 0);
});
// Stop executing if concurrency is 0 and early exit is requested
// Stop executing if concurrency is 0 and we are exiting
if (exiting_ && thread_config_->concurrency_ == 0) {
return true;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ ConcurrencyWorker::WaitForResponses()
std::unique_lock<std::mutex> lk(cb_mtx_);
thread_stat_->idle_timer.Start();
cb_cv_.wait(lk, [this] {
if (notified_ || exiting_) {
if (notified_ || (exiting_ && fast_exit_)) {
notified_ = false;
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/c++/perf_analyzer/infer_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ InferContext::AsyncCallbackFuncImpl(cb::InferResult* result)
// Add the request record to thread request records vector with
// proper locking
std::lock_guard<std::mutex> lock(thread_stat_->mu_);

// If we are fast exiting, do not handle the request and instead exit
// immediately
if (exiting_ && fast_exit_) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/c++/perf_analyzer/infer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class InferContext {
void Init();

// Signal to the context to stop working and exit
// If fast exit is true, everything should be immediately dropped
// If fast exit is false, the context should still handle outstanding requests
// before exiting
void Exit(bool fast_exit)
{
exiting_ = true;
Expand Down
1 change: 0 additions & 1 deletion src/c++/perf_analyzer/load_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ LoadManager::StopWorkerThreads()
{
bool fast_exit = shared_memory_type_ == SharedMemoryType::NO_SHARED_MEMORY;

// FIXME do I need to acquire the lock first?
for (auto& worker : workers_) {
worker->Exit(fast_exit);
}
Expand Down
9 changes: 4 additions & 5 deletions src/c++/perf_analyzer/load_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ LoadWorker::Exit(bool fast_exit)
ctx->Exit(fast_exit);
}

exiting_ = true;
fast_exit_ = fast_exit;
exiting_ = true;

{
std::lock_guard<std::mutex> lk(cb_mtx_);
Expand All @@ -68,9 +68,8 @@ LoadWorker::HandleExitConditions()
{
if (ShouldExit()) {
CompleteOngoingSequences();
if (!fast_exit_) {
WaitForOngoingRequests();
}
thread_stat_->idle_timer.Start();
WaitForOngoingRequests();
return true;
}
return false;
Expand All @@ -90,7 +89,7 @@ LoadWorker::CompleteOngoingSequences()
void
LoadWorker::WaitForOngoingRequests()
{
while (GetNumOngoingRequests() != 0 && !fast_exit_) {
while (GetNumOngoingRequests() != 0 && !(exiting_ && fast_exit_)) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/c++/perf_analyzer/load_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class LoadWorker : public IWorker {

virtual ~LoadWorker() = default;

// Tell the worker thread to stop issuing new requests and to exit
// If fast_exit is true, the worker thread should exit as fast as possible. If
// it is false, it should still wait for all outstanding requests before
// exiting
virtual void Exit(bool fast_exit) override;

protected:
Expand Down

0 comments on commit 7f3bbfa

Please sign in to comment.