Skip to content

Commit

Permalink
Merge pull request #346 from DUNE-DAQ/asztuc/mlt_threadoccupancy_fix
Browse files Browse the repository at this point in the history
Fixing TCProcessor's high mlt-dec thread occupancy
  • Loading branch information
eflumerf authored Oct 8, 2024
2 parents 1c425d6 + 470a376 commit 016df91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/TCProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ TCProcessor::stop(const nlohmann::json& args)
{
inherited::stop(args);
m_running_flag.store(false);

// Make sure condition_variable knows we flipped running flag
{
std::lock_guard<std::mutex> lock(m_td_vector_mutex);
m_cv.notify_all();
}

// Wait for the TD-sending thread to stop
m_send_trigger_decisions_thread.join();

// Drop all TDs in vectors at run stage change. Have to do this
Expand Down Expand Up @@ -113,7 +121,6 @@ TCProcessor::conf(const appmodel::DataHandlerModule* cfg)
link->get_sid()});
}


// TODO: Group links!
//m_group_links_data = conf->get_groups_links();
parse_group_links(m_group_links_data);
Expand Down Expand Up @@ -233,6 +240,7 @@ TCProcessor::make_td(const TCWrapper* tcw)
else {
std::lock_guard<std::mutex> lock(m_td_vector_mutex);
add_tc(tc);
m_cv.notify_one();
TLOG_DEBUG(10) << "pending tds size: " << m_pending_tds.size();
}
return;
Expand Down Expand Up @@ -302,9 +310,15 @@ TCProcessor::create_decision(const PendingTD& pending_td)

void
TCProcessor::send_trigger_decisions() {
// A unique lock that can be locked and unlocked
std::unique_lock<std::mutex> lock(m_td_vector_mutex);

while (m_running_flag) {
std::lock_guard<std::mutex> lock(m_td_vector_mutex);
// Either there are pending TDs, or wait for a bit
m_cv.wait(lock, [this] {
return !m_pending_tds.empty() || !m_running_flag;
});

auto ready_tds = get_ready_tds(m_pending_tds);
TLOG_DEBUG(10) << "ready tds: " << ready_tds.size() << ", updated pending tds: " << m_pending_tds.size();

Expand Down
1 change: 1 addition & 0 deletions src/trigger/TCProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class TCProcessor : public datahandlinglibs::TaskRawDataProcessorModel<TCWrapper
};
std::vector<PendingTD> m_pending_tds;
std::mutex m_td_vector_mutex;
std::condition_variable m_cv;

void add_tc(const triggeralgs::TriggerCandidate tc);
void add_tc_ignored(const triggeralgs::TriggerCandidate tc);
Expand Down

0 comments on commit 016df91

Please sign in to comment.