From ab5812e5b5a0506823f75a5aaec691775348ebdb Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Wed, 28 Aug 2024 17:13:52 +0200 Subject: [PATCH 01/20] latency test in RTCM --- include/trigger/Utilities.hpp | 24 ++++++++++++++++++++++++ plugins/RandomTCMakerModule.hpp | 1 + 2 files changed, 25 insertions(+) create mode 100644 include/trigger/Utilities.hpp diff --git a/include/trigger/Utilities.hpp b/include/trigger/Utilities.hpp new file mode 100644 index 00000000..93efd79f --- /dev/null +++ b/include/trigger/Utilities.hpp @@ -0,0 +1,24 @@ +/** + * @file Utilities.cpp + * + * This is part of the DUNE DAQ Application Framework, copyright 2021. + * Licensing/copyright details are in the COPYING file that you should have + * received with this code. + */ + +#ifndef TRIGGER_INCLUDE_TRIGGER_UTILITIES_HPP_ +#define TRIGGER_INCLUDE_TRIGGER_UTILITIES_HPP_ + +namespace dunedaq { +namespace trigger { + + using namespace std::chrono; + + std::atomic get_current_system_time() + { + return duration_cast(system_clock::now().time_since_epoch()).count(); + } + +} // namespace trigger +} // namespace dunedaq +#endif // TRIGGER_INCLUDE_TRIGGER_UTILITIES_HPP_ diff --git a/plugins/RandomTCMakerModule.hpp b/plugins/RandomTCMakerModule.hpp index a37d37f7..0014c17e 100644 --- a/plugins/RandomTCMakerModule.hpp +++ b/plugins/RandomTCMakerModule.hpp @@ -27,6 +27,7 @@ #include "utilities/TimestampEstimator.hpp" #include "triggeralgs/TriggerCandidate.hpp" #include "trigger/TCWrapper.hpp" +#include "trigger/Utilities.hpp" #include "trigger/opmon/randomtcmaker_info.pb.h" #include From e6ef2a3e5243944c0f38d7afca48c38db5d99f72 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Thu, 29 Aug 2024 15:56:56 +0200 Subject: [PATCH 02/20] new latency class and first implementation --- include/trigger/Latency.hpp | 67 +++++++++++++++++++ include/trigger/Utilities.hpp | 24 ------- plugins/CustomTCMaker.cpp | 16 +++++ plugins/CustomTCMaker.hpp | 6 ++ plugins/RandomTCMakerModule.cpp | 17 +++++ plugins/RandomTCMakerModule.hpp | 7 +- plugins/TriggerDataHandlerModule.cpp | 4 -- schema/trigger/opmon/customtcmaker_info.proto | 6 ++ .../trigger/opmon/hsisourcemodel_info.proto | 6 ++ schema/trigger/opmon/randomtcmaker_info.proto | 5 ++ schema/trigger/opmon/taprocessor_info.proto | 5 ++ schema/trigger/opmon/tpprocessor_info.proto | 5 ++ src/TAProcessor.cpp | 16 +++++ src/TPProcessor.cpp | 14 ++++ src/trigger/HSISourceModel.hpp | 30 +++++++-- src/trigger/TAProcessor.hpp | 17 +++-- src/trigger/TPProcessor.hpp | 17 +++-- 17 files changed, 221 insertions(+), 41 deletions(-) create mode 100644 include/trigger/Latency.hpp delete mode 100644 include/trigger/Utilities.hpp diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp new file mode 100644 index 00000000..e9d3c89d --- /dev/null +++ b/include/trigger/Latency.hpp @@ -0,0 +1,67 @@ +/** + * @file Latency.hpp + * + * This is part of the DUNE DAQ Application Framework, copyright 2021. + * Licensing/copyright details are in the COPYING file that you should have + * received with this code. + */ + +#ifndef TRIGGER_INCLUDE_TRIGGER_LATENCY_HPP_ +#define TRIGGER_INCLUDE_TRIGGER_LATENCY_HPP_ + +#include +#include + +namespace dunedaq { +namespace trigger { + + class Latency { + public: + Latency() + : m_latency_in(0), m_latency_out(0), m_clock_ticks_to_ms(16 * 1e-6) + {} + + // to convert 62.5MHz clock ticks to ms: 1/62500000 = 0.000000016 <- seconds per tick; 0.000016 <- ms per tick; + // 16*1e-6 <- sci notation + + // Function to get the current system time + std::atomic get_current_system_time() const + { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); + } + + // Function to update latency_in + void update_latency_in(uint64_t latency) + { + m_latency_in.store(latency * m_clock_ticks_to_ms); + } + + // Function to update latency_out + void update_latency_out(uint64_t latency) + { + m_latency_out.store(latency * m_clock_ticks_to_ms); + } + + // Function to get the value of latency_in + uint64_t get_latency_in() const + { + return m_latency_in.load() != 0 ? (get_current_system_time() - m_latency_in.load()) : 0; + } + + // Function to get the value of latency_out + uint64_t get_latency_out() const + { + return m_latency_out.load() != 0 ? (get_current_system_time() - m_latency_out.load()) : 0; + } + + private: + std::atomic m_latency_in; // Member variable to store latency_in + std::atomic m_latency_out; // Member variable to store latency_out + std::atomic m_clock_ticks_to_ms; + }; + +} // namespace trigger +} // namespace dunedaq + +#endif // TRIGGER_INCLUDE_TRIGGER_LATENCY_HPP_ diff --git a/include/trigger/Utilities.hpp b/include/trigger/Utilities.hpp deleted file mode 100644 index 93efd79f..00000000 --- a/include/trigger/Utilities.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @file Utilities.cpp - * - * This is part of the DUNE DAQ Application Framework, copyright 2021. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -#ifndef TRIGGER_INCLUDE_TRIGGER_UTILITIES_HPP_ -#define TRIGGER_INCLUDE_TRIGGER_UTILITIES_HPP_ - -namespace dunedaq { -namespace trigger { - - using namespace std::chrono; - - std::atomic get_current_system_time() - { - return duration_cast(system_clock::now().time_since_epoch()).count(); - } - -} // namespace trigger -} // namespace dunedaq -#endif // TRIGGER_INCLUDE_TRIGGER_UTILITIES_HPP_ diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index ab228290..ecd983b9 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -117,6 +117,15 @@ CustomTCMaker::generate_opmon_data() info.set_tc_failed_sent_count( m_tc_failed_sent_count.load() ); this->publish(std::move(info)); + + if (m_running_flag) { + opmon::CustomTCMakerLatency lat_info; + + lat_info.set_latency_in( m_latency_instance.get_latency_in() ); + lat_info.set_latency_out( m_latency_instance.get_latency_out() ); + + this->publish(std::move(lat_info)); + } } void @@ -142,6 +151,11 @@ CustomTCMaker::do_start(const nlohmann::json& obj) { m_running_flag.store(true); + // OpMon. + m_tc_made_count.store(0); + m_tc_sent_count.store(0); + m_tc_failed_sent_count.store(0); + auto start_params = obj.get(); std::string timestamp_method = m_conf->get_timestamp_method(); @@ -247,6 +261,7 @@ CustomTCMaker::send_trigger_candidates() } triggeralgs::TriggerCandidate candidate = create_candidate(m_next_trigger_timestamp, m_tc_timestamps.front().first); + m_latency_instance.update_latency_in( candidate.time_candidate ); m_tc_made_count++; TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() @@ -255,6 +270,7 @@ CustomTCMaker::send_trigger_candidates() TCWrapper tcw(candidate); try { m_trigger_candidate_sink->send(std::move(tcw), std::chrono::milliseconds(10)); + m_latency_instance.update_latency_out( candidate.time_candidate ); m_tc_sent_count++; m_tc_sent_count_type[m_tc_timestamps.front().first] += 1; } catch (const ers::Issue& e) { diff --git a/plugins/CustomTCMaker.hpp b/plugins/CustomTCMaker.hpp index 046036c7..83c874f7 100644 --- a/plugins/CustomTCMaker.hpp +++ b/plugins/CustomTCMaker.hpp @@ -26,6 +26,7 @@ #include "utilities/TimestampEstimator.hpp" #include "triggeralgs/TriggerCandidate.hpp" #include "trigger/TCWrapper.hpp" +#include "trigger/Latency.hpp" #include "trigger/opmon/customtcmaker_info.pb.h" #include @@ -117,6 +118,11 @@ class CustomTCMaker : public dunedaq::appfwk::DAQModule std::atomic m_tc_sent_count{ 0 }; std::atomic m_tc_failed_sent_count{ 0 }; void print_opmon_stats(); + + // Create an instance of the Latency class + dunedaq::trigger::Latency m_latency_instance; + std::atomic m_latency_in{ 0 }; + std::atomic m_latency_out{ 0 }; }; } // namespace trigger } // namespace dunedaq diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index 6cde5d09..8828b818 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -86,6 +86,15 @@ RandomTCMakerModule::generate_opmon_data() info.set_tc_failed_sent_count( m_tc_failed_sent_count.load() ); this->publish(std::move(info)); + + if (m_running_flag) { + opmon::RandomTCMakerLatency lat_info; + + lat_info.set_latency_in( m_latency_instance.get_latency_in() ); + lat_info.set_latency_out( m_latency_instance.get_latency_out() ); + + this->publish(std::move(lat_info)); + } } void @@ -101,6 +110,11 @@ RandomTCMakerModule::do_start(const nlohmann::json& obj) m_running_flag.store(true); + // OpMon. + m_tc_made_count.store(0); + m_tc_sent_count.store(0); + m_tc_failed_sent_count.store(0); + std::string timestamp_method = m_conf->get_timestamp_method(); if (timestamp_method == "kTimeSync") { TLOG_DEBUG(0) << "Creating TimestampEstimator"; @@ -220,6 +234,8 @@ RandomTCMakerModule::send_trigger_candidates() } next_trigger_timestamp = m_timestamp_estimator->get_timestamp_estimate(); triggeralgs::TriggerCandidate candidate = create_candidate(next_trigger_timestamp); + + m_latency_instance.update_latency_in( candidate.time_candidate ); m_tc_made_count++; TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() @@ -227,6 +243,7 @@ RandomTCMakerModule::send_trigger_candidates() TCWrapper tcw(candidate); try{ m_trigger_candidate_sink->send(std::move(tcw), std::chrono::milliseconds(10)); + m_latency_instance.update_latency_out( candidate.time_candidate ); m_tc_sent_count++; } catch (const ers::Issue& e) { ers::error(e); diff --git a/plugins/RandomTCMakerModule.hpp b/plugins/RandomTCMakerModule.hpp index 0014c17e..0ca9569a 100644 --- a/plugins/RandomTCMakerModule.hpp +++ b/plugins/RandomTCMakerModule.hpp @@ -27,7 +27,7 @@ #include "utilities/TimestampEstimator.hpp" #include "triggeralgs/TriggerCandidate.hpp" #include "trigger/TCWrapper.hpp" -#include "trigger/Utilities.hpp" +#include "trigger/Latency.hpp" #include "trigger/opmon/randomtcmaker_info.pb.h" #include @@ -104,6 +104,11 @@ class RandomTCMakerModule : public dunedaq::appfwk::DAQModule std::atomic m_tc_sent_count{ 0 }; std::atomic m_tc_failed_sent_count{ 0 }; void print_opmon_stats(); + + // Create an instance of the Latency class + dunedaq::trigger::Latency m_latency_instance; + std::atomic m_latency_in{ 0 }; + std::atomic m_latency_out{ 0 }; }; } // namespace trigger } // namespace dunedaq diff --git a/plugins/TriggerDataHandlerModule.cpp b/plugins/TriggerDataHandlerModule.cpp index 9b4beb1e..c8a69414 100644 --- a/plugins/TriggerDataHandlerModule.cpp +++ b/plugins/TriggerDataHandlerModule.cpp @@ -75,10 +75,6 @@ TriggerDataHandlerModule::create_readout(const appmodel::DataHandlerModule* modc std::string raw_dt = modconf->get_module_configuration()->get_input_data_type(); TLOG() << "Choosing specializations for DataHandlingModel with data_type:" << raw_dt << ']'; - TLOG() << "modconf: " << modconf; - TLOG() << modconf->class_name(); - TLOG() << modconf->get_module_configuration(); - // IF TriggerPrimitive (TP) if (raw_dt.find("TriggerPrimitive") != std::string::npos) { TLOG(TLVL_WORK_STEPS) << "Creating readout for TriggerPrimitive"; diff --git a/schema/trigger/opmon/customtcmaker_info.proto b/schema/trigger/opmon/customtcmaker_info.proto index 70d9d08a..5621da69 100644 --- a/schema/trigger/opmon/customtcmaker_info.proto +++ b/schema/trigger/opmon/customtcmaker_info.proto @@ -8,3 +8,9 @@ message CustomTCMakerInfo { uint32 tc_sent_count = 2; // Number of TCs sent by CTCM uint32 tc_failed_sent_count = 3; // Number of TCs that failed to be sent by CTCM } + +message CustomTCMakerLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} + diff --git a/schema/trigger/opmon/hsisourcemodel_info.proto b/schema/trigger/opmon/hsisourcemodel_info.proto index 9d57e2b2..bb536e67 100644 --- a/schema/trigger/opmon/hsisourcemodel_info.proto +++ b/schema/trigger/opmon/hsisourcemodel_info.proto @@ -9,3 +9,9 @@ message HSISourceModelInfo { uint32 tcs_sent_count = 3; // Number of TCs succesfully sent uint32 tcs_dropped_count = 4; // Number of TCs dropped (failed to send) } + +message HSISourceModelLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} + diff --git a/schema/trigger/opmon/randomtcmaker_info.proto b/schema/trigger/opmon/randomtcmaker_info.proto index d4ee3335..52d915a3 100644 --- a/schema/trigger/opmon/randomtcmaker_info.proto +++ b/schema/trigger/opmon/randomtcmaker_info.proto @@ -8,3 +8,8 @@ message RandomTCMakerInfo { uint32 tc_sent_count = 2; // Number of TCs sent by RTCM uint32 tc_failed_sent_count = 3; // Number of TCs that failed to be sent by RTCM } + +message RandomTCMakerLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} diff --git a/schema/trigger/opmon/taprocessor_info.proto b/schema/trigger/opmon/taprocessor_info.proto index 3f34b9bf..d19a310f 100644 --- a/schema/trigger/opmon/taprocessor_info.proto +++ b/schema/trigger/opmon/taprocessor_info.proto @@ -9,3 +9,8 @@ message TAProcessorInfo { uint32 tc_sent_count = 3; // Number of TCs sent uint32 tc_failed_sent_count = 4; // Number of TCs that failed to be sent } + +message TAProcessorLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} diff --git a/schema/trigger/opmon/tpprocessor_info.proto b/schema/trigger/opmon/tpprocessor_info.proto index dbbe0f27..7af948bc 100644 --- a/schema/trigger/opmon/tpprocessor_info.proto +++ b/schema/trigger/opmon/tpprocessor_info.proto @@ -9,3 +9,8 @@ message TPProcessorInfo { uint32 ta_sent_count = 3; // Number of TAs sent uint32 ta_failed_sent_count = 4; // Number of TAs that failed to be sent } + +message TPProcessorLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index 76717cf9..0f826598 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -54,6 +54,9 @@ TAProcessor::start(const nlohmann::json& args) m_tc_made_count.store(0); m_tc_sent_count.store(0); m_tc_failed_sent_count.store(0); + + m_running_flag = true; + inherited::start(args); } @@ -61,6 +64,7 @@ void TAProcessor::stop(const nlohmann::json& args) { inherited::stop(args); + m_running_flag = false; print_opmon_stats(); } @@ -116,6 +120,15 @@ TAProcessor::generate_opmon_data() info.set_tc_failed_sent_count( m_tc_failed_sent_count.load() ); this->publish(std::move(info)); + + if (m_running_flag) { + opmon::TAProcessorLatency lat_info; + + lat_info.set_latency_in( m_latency_instance.get_latency_in() ); + lat_info.set_latency_out( m_latency_instance.get_latency_out() ); + + this->publish(std::move(lat_info)); + } } /** @@ -124,6 +137,8 @@ TAProcessor::generate_opmon_data() void TAProcessor::find_tc(const TAWrapper* ta, std::shared_ptr tca) { + //time_activity gave 0 :/ + m_latency_instance.update_latency_in( ta->activity.time_start ); m_ta_received_count++; std::vector tcs; tca->operator()(ta->activity, tcs); @@ -133,6 +148,7 @@ TAProcessor::find_tc(const TAWrapper* ta, std::shared_ptrpublish(std::move(info)); + + if (m_running_flag) { + opmon::TPProcessorLatency lat_info; + + lat_info.set_latency_in( m_latency_instance.get_latency_in() ); + lat_info.set_latency_out( m_latency_instance.get_latency_out() ); + + this->publish(std::move(lat_info)); + } } /** @@ -127,6 +139,7 @@ TPProcessor::generate_opmon_data() void TPProcessor::find_ta(const TriggerPrimitiveTypeAdapter* tp, std::shared_ptr taa) { + m_latency_instance.update_latency_in( tp->tp.time_start ); // time_start or time_peak ? m_tp_received_count++; std::vector tas; taa->operator()(tp->tp, tas); @@ -137,6 +150,7 @@ TPProcessor::find_ta(const TriggerPrimitiveTypeAdapter* tp, std::shared_ptrtp.time_start, m_sourceid.id)); m_ta_failed_sent_count++; } + m_latency_instance.update_latency_out( tas.back().time_start ); m_ta_sent_count++; tas.pop_back(); } diff --git a/src/trigger/HSISourceModel.hpp b/src/trigger/HSISourceModel.hpp index c93d38dd..957f5925 100644 --- a/src/trigger/HSISourceModel.hpp +++ b/src/trigger/HSISourceModel.hpp @@ -14,6 +14,7 @@ #include "dfmessages/HSIEvent.hpp" #include "triggeralgs/TriggerCandidate.hpp" #include "trigger/Issues.hpp" +#include "trigger/Latency.hpp" #include "trigger/opmon/hsisourcemodel_info.pb.h" #include "iomanager/IOManager.hpp" @@ -102,6 +103,8 @@ class HSISourceModel : public datahandlinglibs::SourceConcept void start() { m_data_receiver->add_callback(std::bind(&HSISourceModel::handle_payload, this, std::placeholders::_1)); + m_running_flag = true; + m_received_events_count.store(0); m_tcs_made_count.store(0); m_tcs_sent_count.store(0); @@ -110,12 +113,14 @@ class HSISourceModel : public datahandlinglibs::SourceConcept void stop() { m_data_receiver->remove_callback(); + m_running_flag = false; print_opmon_stats(); } bool handle_payload(dfmessages::HSIEvent& data) // NOLINT(build/unsigned) { m_received_events_count++; + m_latency_instance.update_latency_in( data.timestamp ); // Prescale after n-hsi received if (m_received_events_count % m_prescale != 0) { @@ -153,6 +158,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept m_tcs_dropped_count++; } else { + m_latency_instance.update_latency_out( candidate.time_candidate ); m_tcs_sent_count++; } @@ -173,6 +179,15 @@ class HSISourceModel : public datahandlinglibs::SourceConcept info.set_tcs_dropped_count( m_tcs_dropped_count ); this->publish(std::move(info)); + + if (m_running_flag) { + opmon::HSISourceModelLatency lat_info; + + lat_info.set_latency_in( m_latency_instance.get_latency_in() ); + lat_info.set_latency_out( m_latency_instance.get_latency_out() ); + + this->publish(std::move(lat_info)); + } } void print_opmon_stats() @@ -197,13 +212,20 @@ class HSISourceModel : public datahandlinglibs::SourceConcept std::map m_signals; //Stats - std::atomic m_received_events_count{0}; - std::atomic m_tcs_made_count{0}; - std::atomic m_tcs_sent_count{0}; - std::atomic m_tcs_dropped_count{0}; + using metric_counter_type = uint64_t; + std::atomic m_received_events_count{0}; + std::atomic m_tcs_made_count{0}; + std::atomic m_tcs_sent_count{0}; + std::atomic m_tcs_dropped_count{0}; /// @brief {rescale for the input HSIEvents, default 1 uint64_t m_prescale; + + // Create an instance of the Latency class + bool m_running_flag = false; + dunedaq::trigger::Latency m_latency_instance; + std::atomic m_latency_in{ 0 }; + std::atomic m_latency_out{ 0 }; }; } // namespace dunedaq::trigger diff --git a/src/trigger/TAProcessor.hpp b/src/trigger/TAProcessor.hpp index ebae35e6..6b34e647 100644 --- a/src/trigger/TAProcessor.hpp +++ b/src/trigger/TAProcessor.hpp @@ -18,6 +18,7 @@ #include "trigger/Issues.hpp" #include "trigger/TAWrapper.hpp" +#include "trigger/Latency.hpp" #include "trigger/opmon/taprocessor_info.pb.h" #include "triggeralgs/TriggerCandidate.hpp" @@ -68,11 +69,19 @@ class TAProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_ta_received_count{ 0 }; // NOLINT(build/unsigned) - std::atomic m_tc_made_count{ 0 }; - std::atomic m_tc_sent_count{ 0 }; - std::atomic m_tc_failed_sent_count{ 0 }; + using metric_counter_type = uint64_t; + std::atomic m_ta_received_count{ 0 }; // NOLINT(build/unsigned) + std::atomic m_tc_made_count{ 0 }; + std::atomic m_tc_sent_count{ 0 }; + std::atomic m_tc_failed_sent_count{ 0 }; void print_opmon_stats(); + + // Create an instance of the Latency class + bool m_running_flag = false; + dunedaq::trigger::Latency m_latency_instance; + std::atomic m_latency_in{ 0 }; + std::atomic m_latency_out{ 0 }; + }; } // namespace trigger diff --git a/src/trigger/TPProcessor.hpp b/src/trigger/TPProcessor.hpp index f47569d4..d280d2bb 100644 --- a/src/trigger/TPProcessor.hpp +++ b/src/trigger/TPProcessor.hpp @@ -16,6 +16,7 @@ //#include "triggger/Issues.hpp" #include "trigger/TriggerPrimitiveTypeAdapter.hpp" +#include "trigger/Latency.hpp" #include "trigger/opmon/tpprocessor_info.pb.h" #include "triggeralgs/TriggerActivity.hpp" @@ -68,11 +69,19 @@ class TPProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_tp_received_count{ 0 }; // NOLINT(build/unsigned) - std::atomic m_ta_made_count{ 0 }; - std::atomic m_ta_sent_count{ 0 }; - std::atomic m_ta_failed_sent_count{ 0 }; + using metric_counter_type = uint64_t; + std::atomic m_tp_received_count{ 0 }; // NOLINT(build/unsigned) + std::atomic m_ta_made_count{ 0 }; + std::atomic m_ta_sent_count{ 0 }; + std::atomic m_ta_failed_sent_count{ 0 }; void print_opmon_stats(); + + // Create an instance of the Latency class + bool m_running_flag = false; + dunedaq::trigger::Latency m_latency_instance; + std::atomic m_latency_in{ 0 }; + std::atomic m_latency_out{ 0 }; + }; } // namespace trigger From 54c6a8af9e1959492c9304d3690d5edc3062d836 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Tue, 10 Sep 2024 11:42:05 +0200 Subject: [PATCH 03/20] fixing merge mistake --- src/TAProcessor.cpp | 1 - src/TPProcessor.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index dc4060f0..2dcd61b2 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -143,7 +143,6 @@ TAProcessor::find_tc(const TAWrapper* ta, std::shared_ptr Date: Tue, 10 Sep 2024 13:59:27 +0200 Subject: [PATCH 04/20] add tcproc proto --- schema/trigger/opmon/tcprocessor_info.proto | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/schema/trigger/opmon/tcprocessor_info.proto b/schema/trigger/opmon/tcprocessor_info.proto index 240a612f..f6717744 100644 --- a/schema/trigger/opmon/tcprocessor_info.proto +++ b/schema/trigger/opmon/tcprocessor_info.proto @@ -17,3 +17,8 @@ message TCProcessorInfo { uint32 tds_failed_bitword_tc_count = 24; // Number of TCs contributing to TDs (requests) that failed the bitword check uint32 tds_cleared_tc_count = 25; // Number of TCs contributing to TDs (requests) that were cleared at run stage change } + +message TCProcessorLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} From a004b1747cc48d13cfb5d785d830788a85880a79 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Tue, 10 Sep 2024 14:22:51 +0200 Subject: [PATCH 05/20] fixing running_flag globally --- plugins/CustomTCMaker.cpp | 2 +- plugins/RandomTCMakerModule.cpp | 2 +- src/TAProcessor.cpp | 6 +++--- src/TCProcessor.cpp | 2 +- src/TPProcessor.cpp | 6 +++--- src/trigger/HSISourceModel.hpp | 8 ++++---- src/trigger/TAProcessor.hpp | 2 +- src/trigger/TCProcessor.hpp | 6 ++++++ src/trigger/TPProcessor.hpp | 2 +- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index 8f0fd367..1b34dc8b 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -108,7 +108,7 @@ CustomTCMaker::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag) { + if (m_running_flag.load()) { opmon::CustomTCMakerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index 5cc6eba4..1724472b 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -77,7 +77,7 @@ RandomTCMakerModule::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag) { + if (m_running_flag.load()) { opmon::RandomTCMakerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index 2dcd61b2..8d226e41 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -55,7 +55,7 @@ TAProcessor::start(const nlohmann::json& args) m_tc_sent_count.store(0); m_tc_failed_sent_count.store(0); - m_running_flag = true; + m_running_flag.store(true); inherited::start(args); } @@ -64,7 +64,7 @@ void TAProcessor::stop(const nlohmann::json& args) { inherited::stop(args); - m_running_flag = false; + m_running_flag.store(false); print_opmon_stats(); } @@ -113,7 +113,7 @@ TAProcessor::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag) { + if (m_running_flag.load()) { opmon::TAProcessorLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index 4ef96e41..3b11d0a5 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -303,7 +303,7 @@ TCProcessor::create_decision(const PendingTD& pending_td) void TCProcessor::send_trigger_decisions() { - while (m_running_flag) { + while (m_running_flag.load()) { std::lock_guard lock(m_td_vector_mutex); auto ready_tds = get_ready_tds(m_pending_tds); TLOG_DEBUG(10) << "ready tds: " << ready_tds.size() << ", updated pending tds: " << m_pending_tds.size(); diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index 97662925..e54e1ce7 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -53,7 +53,7 @@ TPProcessor::start(const nlohmann::json& args) m_ta_sent_count.store(0); m_ta_failed_sent_count.store(0); - m_running_flag = true; + m_running_flag.store(true); inherited::start(args); } @@ -62,7 +62,7 @@ void TPProcessor::stop(const nlohmann::json& args) { inherited::stop(args); - m_running_flag = false; + m_running_flag.store(false); print_opmon_stats(); } @@ -115,7 +115,7 @@ TPProcessor::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag) { + if (m_running_flag.load()) { opmon::TPProcessorLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); diff --git a/src/trigger/HSISourceModel.hpp b/src/trigger/HSISourceModel.hpp index 957f5925..77f479f7 100644 --- a/src/trigger/HSISourceModel.hpp +++ b/src/trigger/HSISourceModel.hpp @@ -103,7 +103,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept void start() { m_data_receiver->add_callback(std::bind(&HSISourceModel::handle_payload, this, std::placeholders::_1)); - m_running_flag = true; + m_running_flag.store(true); m_received_events_count.store(0); m_tcs_made_count.store(0); @@ -113,7 +113,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept void stop() { m_data_receiver->remove_callback(); - m_running_flag = false; + m_running_flag.store(false); print_opmon_stats(); } @@ -180,7 +180,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept this->publish(std::move(info)); - if (m_running_flag) { + if (m_running_flag.load()) { opmon::HSISourceModelLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -222,7 +222,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept uint64_t m_prescale; // Create an instance of the Latency class - bool m_running_flag = false; + std::atomic m_running_flag{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; diff --git a/src/trigger/TAProcessor.hpp b/src/trigger/TAProcessor.hpp index 5b9509a7..5cc190dd 100644 --- a/src/trigger/TAProcessor.hpp +++ b/src/trigger/TAProcessor.hpp @@ -76,7 +76,7 @@ class TAProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_running_flag{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; diff --git a/src/trigger/TCProcessor.hpp b/src/trigger/TCProcessor.hpp index b2975eae..c1337d09 100644 --- a/src/trigger/TCProcessor.hpp +++ b/src/trigger/TCProcessor.hpp @@ -21,6 +21,7 @@ #include "trigger/Issues.hpp" #include "trigger/TCWrapper.hpp" +#include "trigger/Latency.hpp" #include "trigger/opmon/tcprocessor_info.pb.h" #include "daqdataformats/SourceID.hpp" @@ -186,6 +187,11 @@ class TCProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_tds_cleared_tc_count{ 0 }; std::atomic m_tc_ignored_count{ 0 }; + // latency + dunedaq::trigger::Latency m_latency_instance; + std::atomic m_latency_in{ 0 }; + std::atomic m_latency_out{ 0 }; + void print_opmon_stats(); }; diff --git a/src/trigger/TPProcessor.hpp b/src/trigger/TPProcessor.hpp index aa22966a..003254b7 100644 --- a/src/trigger/TPProcessor.hpp +++ b/src/trigger/TPProcessor.hpp @@ -76,7 +76,7 @@ class TPProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_running_flag{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; From 3a51e706c72723932fc3f99845c51b9fd1bc030c Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Tue, 10 Sep 2024 16:07:04 +0200 Subject: [PATCH 06/20] adding latency to tcproc, mlt --- include/trigger/Latency.hpp | 5 +++++ plugins/MLTModule.cpp | 22 +++++++++++++++++++ plugins/MLTModule.hpp | 9 ++++++++ .../opmon/moduleleveltrigger_info.proto | 10 +++++++++ src/TCProcessor.cpp | 11 ++++++++++ 5 files changed, 57 insertions(+) diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp index e9d3c89d..15e9181f 100644 --- a/include/trigger/Latency.hpp +++ b/include/trigger/Latency.hpp @@ -34,24 +34,28 @@ namespace trigger { // Function to update latency_in void update_latency_in(uint64_t latency) { + std::lock_guard lock(m_mutex); m_latency_in.store(latency * m_clock_ticks_to_ms); } // Function to update latency_out void update_latency_out(uint64_t latency) { + std::lock_guard lock(m_mutex); m_latency_out.store(latency * m_clock_ticks_to_ms); } // Function to get the value of latency_in uint64_t get_latency_in() const { + std::lock_guard lock(m_mutex); return m_latency_in.load() != 0 ? (get_current_system_time() - m_latency_in.load()) : 0; } // Function to get the value of latency_out uint64_t get_latency_out() const { + std::lock_guard lock(m_mutex); return m_latency_out.load() != 0 ? (get_current_system_time() - m_latency_out.load()) : 0; } @@ -59,6 +63,7 @@ namespace trigger { std::atomic m_latency_in; // Member variable to store latency_in std::atomic m_latency_out; // Member variable to store latency_out std::atomic m_clock_ticks_to_ms; + mutable std::mutex m_mutex; }; } // namespace trigger diff --git a/plugins/MLTModule.cpp b/plugins/MLTModule.cpp index 4b781868..3dd1014f 100644 --- a/plugins/MLTModule.cpp +++ b/plugins/MLTModule.cpp @@ -106,6 +106,21 @@ MLTModule::generate_opmon_data() td_info.set_inhibited(counts.inhibited.exchange(0)); this->publish( std::move(td_info), {{"type", name}} ); } + + // latency + if (m_running_flag.load()) { + // TC in, TD out + opmon::ModuleLevelTriggerLatency lat_info; + lat_info.set_latency_in( m_latency_instance.get_latency_in() ); + lat_info.set_latency_out( m_latency_instance.get_latency_out() ); + this->publish(std::move(lat_info)); + + // vs readout window requests + opmon::ModuleLevelTriggerRequestLatency lat_request_info; + lat_request_info.set_latency_window_start( m_latency_requests_instance.get_latency_in() ); + lat_request_info.set_latency_window_end( m_latency_requests_instance.get_latency_out() ); + this->publish(std::move(lat_request_info)); + } } void @@ -202,6 +217,7 @@ void MLTModule::trigger_decisions_callback(dfmessages::TriggerDecision& decision ) { m_td_msg_received_count++; + m_latency_instance.update_latency_in( decision.trigger_timestamp ); auto trigger_types = unpack_types(decision.trigger_type); for ( const auto t : trigger_types ) { @@ -223,6 +239,11 @@ MLTModule::trigger_decisions_callback(dfmessages::TriggerDecision& decision ) try { m_decision_output->send(std::move(decision), std::chrono::milliseconds(1)); + + // readout window latency update + m_latency_requests_instance.update_latency_in( decision.components.front().window_begin ); + m_latency_requests_instance.update_latency_out( decision.components.front().window_end ); + m_td_sent_count++; for ( const auto t : trigger_types ) { @@ -260,6 +281,7 @@ MLTModule::trigger_decisions_callback(dfmessages::TriggerDecision& decision ) } } + m_latency_instance.update_latency_out( decision.trigger_timestamp ); m_td_total_count++; } diff --git a/plugins/MLTModule.hpp b/plugins/MLTModule.hpp index 5a2dff10..7353ea0b 100644 --- a/plugins/MLTModule.hpp +++ b/plugins/MLTModule.hpp @@ -17,6 +17,7 @@ #include "trigger/Issues.hpp" #include "trigger/LivetimeCounter.hpp" #include "trigger/TokenManager.hpp" +#include "trigger/Latency.hpp" #include "trigger/opmon/moduleleveltrigger_info.pb.h" #include "appfwk/DAQModule.hpp" @@ -251,6 +252,14 @@ class MLTModule : public dunedaq::appfwk::DAQModule return m_trigger_counters[type]; } + // Create an instance of the Latency class + dunedaq::trigger::Latency m_latency_instance; + dunedaq::trigger::Latency m_latency_requests_instance; + std::atomic m_latency_in{ 0 }; + std::atomic m_latency_out{ 0 }; + std::atomic m_latency_window_start{ 0 }; + std::atomic m_latency_window_end{ 0 }; + void print_opmon_stats(); }; } // namespace trigger diff --git a/schema/trigger/opmon/moduleleveltrigger_info.proto b/schema/trigger/opmon/moduleleveltrigger_info.proto index 871366b3..715fd4dc 100644 --- a/schema/trigger/opmon/moduleleveltrigger_info.proto +++ b/schema/trigger/opmon/moduleleveltrigger_info.proto @@ -24,3 +24,13 @@ message TriggerDecisionInfo { uint32 paused = 4; // Number of paused (triggers are paused) uint32 inhibited = 5; // Number of inhibited (DFO is busy) } + +message ModuleLevelTriggerLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} + +message ModuleLevelTriggerRequestLatency { + uint32 latency_window_start = 1; + uint32 latency_window_end = 2; +} diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index 3b11d0a5..5d3ec0c5 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -194,6 +194,15 @@ TCProcessor::generate_opmon_data() info.set_tds_cleared_tc_count( m_tds_cleared_tc_count.load() ); this->publish(std::move(info)); + + if (m_running_flag.load()) { + opmon::TCProcessorLatency lat_info; + + lat_info.set_latency_in( m_latency_instance.get_latency_in() ); + lat_info.set_latency_out( m_latency_instance.get_latency_out() ); + + this->publish(std::move(lat_info)); + } } /** @@ -204,6 +213,7 @@ TCProcessor::make_td(const TCWrapper* tcw) { auto tc = tcw->candidate; + m_latency_instance.update_latency_in( tc.time_start ); m_tc_received_count++; if ( (m_use_readout_map) && (m_readout_window_map.count(tc.type)) ) { @@ -341,6 +351,7 @@ TCProcessor::call_tc_decision(const TCProcessor::PendingTD& pending_td) m_tds_dropped_tc_count += pending_td.contributing_tcs.size(); } else { + m_latency_instance.update_latency_out( pending_td.contributing_tcs.front().time_start ); m_tds_sent_count++; m_tds_sent_tc_count += pending_td.contributing_tcs.size(); } From 9155d64d45ee1ad810f5fbe8d7c7637730224419 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Tue, 10 Sep 2024 17:02:49 +0200 Subject: [PATCH 07/20] fix for latency get functions and weird time cases --- include/trigger/Latency.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp index 15e9181f..1c302f89 100644 --- a/include/trigger/Latency.hpp +++ b/include/trigger/Latency.hpp @@ -49,14 +49,26 @@ namespace trigger { uint64_t get_latency_in() const { std::lock_guard lock(m_mutex); - return m_latency_in.load() != 0 ? (get_current_system_time() - m_latency_in.load()) : 0; + if (m_latency_in.load() != 0) { + // in edge cases the TP time was more recent then current sys time... + // this is a catch for that + uint64_t diff = abs( int64_t(get_current_system_time()) - int64_t(m_latency_in.load()) ); + return diff; + } else { + return 0; + } } // Function to get the value of latency_out uint64_t get_latency_out() const { std::lock_guard lock(m_mutex); - return m_latency_out.load() != 0 ? (get_current_system_time() - m_latency_out.load()) : 0; + if (m_latency_out.load() != 0) { + uint64_t diff = abs( int64_t(get_current_system_time()) - int64_t(m_latency_out.load()) ); + return diff; + } else { + return 0; + } } private: From 6bd087cb473896c3e2aa2c5e611193571b3d1b6c Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Tue, 10 Sep 2024 17:03:13 +0200 Subject: [PATCH 08/20] adding comments to proto files --- schema/trigger/opmon/customtcmaker_info.proto | 1 + schema/trigger/opmon/hsisourcemodel_info.proto | 1 + schema/trigger/opmon/moduleleveltrigger_info.proto | 2 ++ schema/trigger/opmon/randomtcmaker_info.proto | 1 + schema/trigger/opmon/taprocessor_info.proto | 1 + schema/trigger/opmon/tcprocessor_info.proto | 1 + schema/trigger/opmon/tpprocessor_info.proto | 1 + 7 files changed, 8 insertions(+) diff --git a/schema/trigger/opmon/customtcmaker_info.proto b/schema/trigger/opmon/customtcmaker_info.proto index 5621da69..b1b564c6 100644 --- a/schema/trigger/opmon/customtcmaker_info.proto +++ b/schema/trigger/opmon/customtcmaker_info.proto @@ -9,6 +9,7 @@ message CustomTCMakerInfo { uint32 tc_failed_sent_count = 3; // Number of TCs that failed to be sent by CTCM } +// Message for CTCM latency vars message CustomTCMakerLatency { uint32 latency_in = 1; uint32 latency_out = 2; diff --git a/schema/trigger/opmon/hsisourcemodel_info.proto b/schema/trigger/opmon/hsisourcemodel_info.proto index bb536e67..b5f1ea80 100644 --- a/schema/trigger/opmon/hsisourcemodel_info.proto +++ b/schema/trigger/opmon/hsisourcemodel_info.proto @@ -10,6 +10,7 @@ message HSISourceModelInfo { uint32 tcs_dropped_count = 4; // Number of TCs dropped (failed to send) } +// Message for HSISM latency vars message HSISourceModelLatency { uint32 latency_in = 1; uint32 latency_out = 2; diff --git a/schema/trigger/opmon/moduleleveltrigger_info.proto b/schema/trigger/opmon/moduleleveltrigger_info.proto index 715fd4dc..02eb1c47 100644 --- a/schema/trigger/opmon/moduleleveltrigger_info.proto +++ b/schema/trigger/opmon/moduleleveltrigger_info.proto @@ -25,11 +25,13 @@ message TriggerDecisionInfo { uint32 inhibited = 5; // Number of inhibited (DFO is busy) } +// Message for MLT latency vars message ModuleLevelTriggerLatency { uint32 latency_in = 1; uint32 latency_out = 2; } +// Message for MLT TD requests latency vars message ModuleLevelTriggerRequestLatency { uint32 latency_window_start = 1; uint32 latency_window_end = 2; diff --git a/schema/trigger/opmon/randomtcmaker_info.proto b/schema/trigger/opmon/randomtcmaker_info.proto index 52d915a3..f3527095 100644 --- a/schema/trigger/opmon/randomtcmaker_info.proto +++ b/schema/trigger/opmon/randomtcmaker_info.proto @@ -9,6 +9,7 @@ message RandomTCMakerInfo { uint32 tc_failed_sent_count = 3; // Number of TCs that failed to be sent by RTCM } +// Message for RTCM latency vars message RandomTCMakerLatency { uint32 latency_in = 1; uint32 latency_out = 2; diff --git a/schema/trigger/opmon/taprocessor_info.proto b/schema/trigger/opmon/taprocessor_info.proto index d19a310f..845c5a2e 100644 --- a/schema/trigger/opmon/taprocessor_info.proto +++ b/schema/trigger/opmon/taprocessor_info.proto @@ -10,6 +10,7 @@ message TAProcessorInfo { uint32 tc_failed_sent_count = 4; // Number of TCs that failed to be sent } +// Message for TAP latency vars message TAProcessorLatency { uint32 latency_in = 1; uint32 latency_out = 2; diff --git a/schema/trigger/opmon/tcprocessor_info.proto b/schema/trigger/opmon/tcprocessor_info.proto index f6717744..f02bdc4b 100644 --- a/schema/trigger/opmon/tcprocessor_info.proto +++ b/schema/trigger/opmon/tcprocessor_info.proto @@ -18,6 +18,7 @@ message TCProcessorInfo { uint32 tds_cleared_tc_count = 25; // Number of TCs contributing to TDs (requests) that were cleared at run stage change } +// Message for TCP latency vars message TCProcessorLatency { uint32 latency_in = 1; uint32 latency_out = 2; diff --git a/schema/trigger/opmon/tpprocessor_info.proto b/schema/trigger/opmon/tpprocessor_info.proto index 7af948bc..e7ea730a 100644 --- a/schema/trigger/opmon/tpprocessor_info.proto +++ b/schema/trigger/opmon/tpprocessor_info.proto @@ -10,6 +10,7 @@ message TPProcessorInfo { uint32 ta_failed_sent_count = 4; // Number of TAs that failed to be sent } +// Message for TPP latency vars message TPProcessorLatency { uint32 latency_in = 1; uint32 latency_out = 2; From 0dcc5f29f3601129ca2b8a9a9ab2dc7c0b42f4ae Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Wed, 11 Sep 2024 14:50:15 +0200 Subject: [PATCH 09/20] reworking latency messages --- plugins/CustomTCMaker.cpp | 2 +- plugins/CustomTCMaker.hpp | 1 + plugins/MLTModule.cpp | 2 +- plugins/MLTModule.hpp | 1 + plugins/RandomTCMakerModule.cpp | 2 +- plugins/RandomTCMakerModule.hpp | 1 + schema/trigger/opmon/customtcmaker_info.proto | 7 ------- schema/trigger/opmon/hsisourcemodel_info.proto | 7 ------- schema/trigger/opmon/latency_info.proto | 10 ++++++++++ schema/trigger/opmon/moduleleveltrigger_info.proto | 6 ------ schema/trigger/opmon/randomtcmaker_info.proto | 6 ------ schema/trigger/opmon/taprocessor_info.proto | 6 ------ schema/trigger/opmon/tcprocessor_info.proto | 6 ------ schema/trigger/opmon/tpprocessor_info.proto | 6 ------ src/TAProcessor.cpp | 2 +- src/TCProcessor.cpp | 3 +-- src/TPProcessor.cpp | 2 +- src/trigger/HSISourceModel.hpp | 3 ++- src/trigger/TAProcessor.hpp | 3 ++- src/trigger/TCProcessor.hpp | 1 + src/trigger/TPProcessor.hpp | 3 ++- 21 files changed, 26 insertions(+), 54 deletions(-) create mode 100644 schema/trigger/opmon/latency_info.proto diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index 1b34dc8b..d1aed3c8 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -109,7 +109,7 @@ CustomTCMaker::generate_opmon_data() this->publish(std::move(info)); if (m_running_flag.load()) { - opmon::CustomTCMakerLatency lat_info; + opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); diff --git a/plugins/CustomTCMaker.hpp b/plugins/CustomTCMaker.hpp index 6c87399d..339e6f4d 100644 --- a/plugins/CustomTCMaker.hpp +++ b/plugins/CustomTCMaker.hpp @@ -28,6 +28,7 @@ #include "trigger/TCWrapper.hpp" #include "trigger/Latency.hpp" #include "trigger/opmon/customtcmaker_info.pb.h" +#include "trigger/opmon/latency_info.pb.h" #include #include diff --git a/plugins/MLTModule.cpp b/plugins/MLTModule.cpp index 3dd1014f..cce39c9e 100644 --- a/plugins/MLTModule.cpp +++ b/plugins/MLTModule.cpp @@ -110,7 +110,7 @@ MLTModule::generate_opmon_data() // latency if (m_running_flag.load()) { // TC in, TD out - opmon::ModuleLevelTriggerLatency lat_info; + opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); this->publish(std::move(lat_info)); diff --git a/plugins/MLTModule.hpp b/plugins/MLTModule.hpp index 7353ea0b..2521f2f2 100644 --- a/plugins/MLTModule.hpp +++ b/plugins/MLTModule.hpp @@ -19,6 +19,7 @@ #include "trigger/TokenManager.hpp" #include "trigger/Latency.hpp" #include "trigger/opmon/moduleleveltrigger_info.pb.h" +#include "trigger/opmon/latency_info.pb.h" #include "appfwk/DAQModule.hpp" diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index 1724472b..969bfece 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -78,7 +78,7 @@ RandomTCMakerModule::generate_opmon_data() this->publish(std::move(info)); if (m_running_flag.load()) { - opmon::RandomTCMakerLatency lat_info; + opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); diff --git a/plugins/RandomTCMakerModule.hpp b/plugins/RandomTCMakerModule.hpp index 77f10e5b..093bda8d 100644 --- a/plugins/RandomTCMakerModule.hpp +++ b/plugins/RandomTCMakerModule.hpp @@ -29,6 +29,7 @@ #include "trigger/TCWrapper.hpp" #include "trigger/Latency.hpp" #include "trigger/opmon/randomtcmaker_info.pb.h" +#include "trigger/opmon/latency_info.pb.h" #include #include diff --git a/schema/trigger/opmon/customtcmaker_info.proto b/schema/trigger/opmon/customtcmaker_info.proto index b1b564c6..70d9d08a 100644 --- a/schema/trigger/opmon/customtcmaker_info.proto +++ b/schema/trigger/opmon/customtcmaker_info.proto @@ -8,10 +8,3 @@ message CustomTCMakerInfo { uint32 tc_sent_count = 2; // Number of TCs sent by CTCM uint32 tc_failed_sent_count = 3; // Number of TCs that failed to be sent by CTCM } - -// Message for CTCM latency vars -message CustomTCMakerLatency { - uint32 latency_in = 1; - uint32 latency_out = 2; -} - diff --git a/schema/trigger/opmon/hsisourcemodel_info.proto b/schema/trigger/opmon/hsisourcemodel_info.proto index b5f1ea80..9d57e2b2 100644 --- a/schema/trigger/opmon/hsisourcemodel_info.proto +++ b/schema/trigger/opmon/hsisourcemodel_info.proto @@ -9,10 +9,3 @@ message HSISourceModelInfo { uint32 tcs_sent_count = 3; // Number of TCs succesfully sent uint32 tcs_dropped_count = 4; // Number of TCs dropped (failed to send) } - -// Message for HSISM latency vars -message HSISourceModelLatency { - uint32 latency_in = 1; - uint32 latency_out = 2; -} - diff --git a/schema/trigger/opmon/latency_info.proto b/schema/trigger/opmon/latency_info.proto new file mode 100644 index 00000000..f5c1ff8b --- /dev/null +++ b/schema/trigger/opmon/latency_info.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package dunedaq.trigger.opmon; + +// Message for latency variables +message TriggerLatency { + uint32 latency_in = 1; + uint32 latency_out = 2; +} + diff --git a/schema/trigger/opmon/moduleleveltrigger_info.proto b/schema/trigger/opmon/moduleleveltrigger_info.proto index 02eb1c47..6876a182 100644 --- a/schema/trigger/opmon/moduleleveltrigger_info.proto +++ b/schema/trigger/opmon/moduleleveltrigger_info.proto @@ -25,12 +25,6 @@ message TriggerDecisionInfo { uint32 inhibited = 5; // Number of inhibited (DFO is busy) } -// Message for MLT latency vars -message ModuleLevelTriggerLatency { - uint32 latency_in = 1; - uint32 latency_out = 2; -} - // Message for MLT TD requests latency vars message ModuleLevelTriggerRequestLatency { uint32 latency_window_start = 1; diff --git a/schema/trigger/opmon/randomtcmaker_info.proto b/schema/trigger/opmon/randomtcmaker_info.proto index f3527095..d4ee3335 100644 --- a/schema/trigger/opmon/randomtcmaker_info.proto +++ b/schema/trigger/opmon/randomtcmaker_info.proto @@ -8,9 +8,3 @@ message RandomTCMakerInfo { uint32 tc_sent_count = 2; // Number of TCs sent by RTCM uint32 tc_failed_sent_count = 3; // Number of TCs that failed to be sent by RTCM } - -// Message for RTCM latency vars -message RandomTCMakerLatency { - uint32 latency_in = 1; - uint32 latency_out = 2; -} diff --git a/schema/trigger/opmon/taprocessor_info.proto b/schema/trigger/opmon/taprocessor_info.proto index 845c5a2e..3f34b9bf 100644 --- a/schema/trigger/opmon/taprocessor_info.proto +++ b/schema/trigger/opmon/taprocessor_info.proto @@ -9,9 +9,3 @@ message TAProcessorInfo { uint32 tc_sent_count = 3; // Number of TCs sent uint32 tc_failed_sent_count = 4; // Number of TCs that failed to be sent } - -// Message for TAP latency vars -message TAProcessorLatency { - uint32 latency_in = 1; - uint32 latency_out = 2; -} diff --git a/schema/trigger/opmon/tcprocessor_info.proto b/schema/trigger/opmon/tcprocessor_info.proto index f02bdc4b..240a612f 100644 --- a/schema/trigger/opmon/tcprocessor_info.proto +++ b/schema/trigger/opmon/tcprocessor_info.proto @@ -17,9 +17,3 @@ message TCProcessorInfo { uint32 tds_failed_bitword_tc_count = 24; // Number of TCs contributing to TDs (requests) that failed the bitword check uint32 tds_cleared_tc_count = 25; // Number of TCs contributing to TDs (requests) that were cleared at run stage change } - -// Message for TCP latency vars -message TCProcessorLatency { - uint32 latency_in = 1; - uint32 latency_out = 2; -} diff --git a/schema/trigger/opmon/tpprocessor_info.proto b/schema/trigger/opmon/tpprocessor_info.proto index e7ea730a..dbbe0f27 100644 --- a/schema/trigger/opmon/tpprocessor_info.proto +++ b/schema/trigger/opmon/tpprocessor_info.proto @@ -9,9 +9,3 @@ message TPProcessorInfo { uint32 ta_sent_count = 3; // Number of TAs sent uint32 ta_failed_sent_count = 4; // Number of TAs that failed to be sent } - -// Message for TPP latency vars -message TPProcessorLatency { - uint32 latency_in = 1; - uint32 latency_out = 2; -} diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index 8d226e41..feb93a6a 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -114,7 +114,7 @@ TAProcessor::generate_opmon_data() this->publish(std::move(info)); if (m_running_flag.load()) { - opmon::TAProcessorLatency lat_info; + opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index 5d3ec0c5..657f8c89 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -15,7 +15,6 @@ #include "datahandlinglibs/ReadoutLogging.hpp" #include "datahandlinglibs/models/IterableQueueModel.hpp" #include "datahandlinglibs/utils/ReusableThread.hpp" - #include "trigger/TCWrapper.hpp" #include "triggeralgs/TriggerCandidate.hpp" @@ -196,7 +195,7 @@ TCProcessor::generate_opmon_data() this->publish(std::move(info)); if (m_running_flag.load()) { - opmon::TCProcessorLatency lat_info; + opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index e54e1ce7..459fb3e9 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -116,7 +116,7 @@ TPProcessor::generate_opmon_data() this->publish(std::move(info)); if (m_running_flag.load()) { - opmon::TPProcessorLatency lat_info; + opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); diff --git a/src/trigger/HSISourceModel.hpp b/src/trigger/HSISourceModel.hpp index 77f479f7..ab7b1bce 100644 --- a/src/trigger/HSISourceModel.hpp +++ b/src/trigger/HSISourceModel.hpp @@ -16,6 +16,7 @@ #include "trigger/Issues.hpp" #include "trigger/Latency.hpp" #include "trigger/opmon/hsisourcemodel_info.pb.h" +#include "trigger/opmon/latency_info.pb.h" #include "iomanager/IOManager.hpp" #include "iomanager/Sender.hpp" @@ -181,7 +182,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept this->publish(std::move(info)); if (m_running_flag.load()) { - opmon::HSISourceModelLatency lat_info; + opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); diff --git a/src/trigger/TAProcessor.hpp b/src/trigger/TAProcessor.hpp index 5cc190dd..8f0230fc 100644 --- a/src/trigger/TAProcessor.hpp +++ b/src/trigger/TAProcessor.hpp @@ -20,8 +20,9 @@ #include "trigger/TAWrapper.hpp" #include "trigger/Latency.hpp" #include "trigger/opmon/taprocessor_info.pb.h" -#include "triggeralgs/TriggerCandidate.hpp" +#include "trigger/opmon/latency_info.pb.h" +#include "triggeralgs/TriggerCandidate.hpp" #include "triggeralgs/Types.hpp" #include "triggeralgs/TriggerCandidateMaker.hpp" diff --git a/src/trigger/TCProcessor.hpp b/src/trigger/TCProcessor.hpp index c1337d09..126a3fdb 100644 --- a/src/trigger/TCProcessor.hpp +++ b/src/trigger/TCProcessor.hpp @@ -23,6 +23,7 @@ #include "trigger/TCWrapper.hpp" #include "trigger/Latency.hpp" #include "trigger/opmon/tcprocessor_info.pb.h" +#include "trigger/opmon/latency_info.pb.h" #include "daqdataformats/SourceID.hpp" #include "dfmessages/TriggerDecision.hpp" diff --git a/src/trigger/TPProcessor.hpp b/src/trigger/TPProcessor.hpp index 003254b7..3306e327 100644 --- a/src/trigger/TPProcessor.hpp +++ b/src/trigger/TPProcessor.hpp @@ -18,8 +18,9 @@ #include "trigger/TriggerPrimitiveTypeAdapter.hpp" #include "trigger/Latency.hpp" #include "trigger/opmon/tpprocessor_info.pb.h" -#include "triggeralgs/TriggerActivity.hpp" +#include "trigger/opmon/latency_info.pb.h" +#include "triggeralgs/TriggerActivity.hpp" #include "triggeralgs/Types.hpp" #include "triggeralgs/TriggerActivityMaker.hpp" From 64e03f1c13672c78d85feca95709e7b380f671cd Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Wed, 11 Sep 2024 17:45:10 +0200 Subject: [PATCH 10/20] making latency monitoring configurable --- plugins/CustomTCMaker.cpp | 8 +++++--- plugins/CustomTCMaker.hpp | 2 ++ plugins/MLTModule.cpp | 13 ++++++++----- plugins/MLTModule.hpp | 2 ++ plugins/RandomTCMakerModule.cpp | 7 ++++--- plugins/RandomTCMakerModule.hpp | 2 ++ src/TAProcessor.cpp | 1 + src/TCProcessor.cpp | 3 ++- src/TPProcessor.cpp | 3 ++- src/trigger/HSISourceModel.hpp | 11 ++++++++--- src/trigger/TAProcessor.hpp | 2 ++ src/trigger/TCProcessor.hpp | 2 ++ src/trigger/TPProcessor.hpp | 2 ++ 13 files changed, 42 insertions(+), 16 deletions(-) diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index d1aed3c8..e2a411a7 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -108,7 +108,7 @@ CustomTCMaker::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag.load()) { + if ( m_running_flag.load() && m_latency_monitoring.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -134,6 +134,8 @@ CustomTCMaker::do_configure(const nlohmann::json& /*obj*/) //// This parameter controls how many new timestamps are calculated when needed //// Currently precalculates events for the next 60 seconds //m_sorting_size_limit = 60 * m_conf0>clock_frequency_hz; + + m_latency_monitoring = m_conf->get_latency_monitoring_conf()->get_latency_monitoring(); } void @@ -251,7 +253,7 @@ CustomTCMaker::send_trigger_candidates() } triggeralgs::TriggerCandidate candidate = create_candidate(m_next_trigger_timestamp, m_tc_timestamps.front().first); - m_latency_instance.update_latency_in( candidate.time_candidate ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( candidate.time_candidate ); m_tc_made_count++; TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() @@ -260,7 +262,7 @@ CustomTCMaker::send_trigger_candidates() TCWrapper tcw(candidate); try { m_trigger_candidate_sink->send(std::move(tcw), std::chrono::milliseconds(10)); - m_latency_instance.update_latency_out( candidate.time_candidate ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); m_tc_sent_count++; m_tc_sent_count_type[m_tc_timestamps.front().first] += 1; } catch (const ers::Issue& e) { diff --git a/plugins/CustomTCMaker.hpp b/plugins/CustomTCMaker.hpp index 339e6f4d..04c77413 100644 --- a/plugins/CustomTCMaker.hpp +++ b/plugins/CustomTCMaker.hpp @@ -11,6 +11,7 @@ #include "appmodel/CustomTCMaker.hpp" #include "appmodel/CustomTCMakerConf.hpp" +#include "appmodel/LatencyMonitoringConf.hpp" #include "confmodel/Connection.hpp" #include "appfwk/ModuleConfiguration.hpp" @@ -120,6 +121,7 @@ class CustomTCMaker : public dunedaq::appfwk::DAQModule void print_opmon_stats(); // Create an instance of the Latency class + std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; diff --git a/plugins/MLTModule.cpp b/plugins/MLTModule.cpp index cce39c9e..3ae497be 100644 --- a/plugins/MLTModule.cpp +++ b/plugins/MLTModule.cpp @@ -67,6 +67,7 @@ MLTModule::init(std::shared_ptr mcfg) } // Now do the configuration: dummy for now + m_latency_monitoring = mtrg->get_configuration()->get_latency_monitoring_conf()->get_latency_monitoring(); m_configured_flag.store(true); } @@ -108,7 +109,7 @@ MLTModule::generate_opmon_data() } // latency - if (m_running_flag.load()) { + if ( m_running_flag.load() && m_latency_monitoring.load() ) { // TC in, TD out opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -217,7 +218,7 @@ void MLTModule::trigger_decisions_callback(dfmessages::TriggerDecision& decision ) { m_td_msg_received_count++; - m_latency_instance.update_latency_in( decision.trigger_timestamp ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( decision.trigger_timestamp ); auto trigger_types = unpack_types(decision.trigger_type); for ( const auto t : trigger_types ) { @@ -241,8 +242,10 @@ MLTModule::trigger_decisions_callback(dfmessages::TriggerDecision& decision ) m_decision_output->send(std::move(decision), std::chrono::milliseconds(1)); // readout window latency update - m_latency_requests_instance.update_latency_in( decision.components.front().window_begin ); - m_latency_requests_instance.update_latency_out( decision.components.front().window_end ); + if (m_latency_monitoring.load()) { + m_latency_requests_instance.update_latency_in( decision.components.front().window_begin ); + m_latency_requests_instance.update_latency_out( decision.components.front().window_end ); + } m_td_sent_count++; @@ -281,7 +284,7 @@ MLTModule::trigger_decisions_callback(dfmessages::TriggerDecision& decision ) } } - m_latency_instance.update_latency_out( decision.trigger_timestamp ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( decision.trigger_timestamp ); m_td_total_count++; } diff --git a/plugins/MLTModule.hpp b/plugins/MLTModule.hpp index 2521f2f2..eb9be222 100644 --- a/plugins/MLTModule.hpp +++ b/plugins/MLTModule.hpp @@ -28,6 +28,7 @@ #include "appmodel/TCReadoutMap.hpp" #include "appmodel/ROIGroupConf.hpp" #include "appmodel/SourceIDConf.hpp" +#include "appmodel/LatencyMonitoringConf.hpp" #include "confmodel/Connection.hpp" @@ -254,6 +255,7 @@ class MLTModule : public dunedaq::appfwk::DAQModule } // Create an instance of the Latency class + std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; dunedaq::trigger::Latency m_latency_requests_instance; std::atomic m_latency_in{ 0 }; diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index 969bfece..e40a5671 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -77,7 +77,7 @@ RandomTCMakerModule::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag.load()) { + if ( m_running_flag.load() && m_latency_monitoring.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -91,6 +91,7 @@ void RandomTCMakerModule::do_configure(const nlohmann::json& /*obj*/) { //m_conf = obj.get(); + m_latency_monitoring = m_conf->get_latency_monitoring_conf()->get_latency_monitoring(); } void @@ -225,7 +226,7 @@ RandomTCMakerModule::send_trigger_candidates() next_trigger_timestamp = m_timestamp_estimator->get_timestamp_estimate(); triggeralgs::TriggerCandidate candidate = create_candidate(next_trigger_timestamp); - m_latency_instance.update_latency_in( candidate.time_candidate ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( candidate.time_candidate ); m_tc_made_count++; TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() @@ -233,7 +234,7 @@ RandomTCMakerModule::send_trigger_candidates() TCWrapper tcw(candidate); try{ m_trigger_candidate_sink->send(std::move(tcw), std::chrono::milliseconds(10)); - m_latency_instance.update_latency_out( candidate.time_candidate ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); m_tc_sent_count++; } catch (const ers::Issue& e) { ers::error(e); diff --git a/plugins/RandomTCMakerModule.hpp b/plugins/RandomTCMakerModule.hpp index 093bda8d..1e7d5239 100644 --- a/plugins/RandomTCMakerModule.hpp +++ b/plugins/RandomTCMakerModule.hpp @@ -15,6 +15,7 @@ #include "appmodel/RandomTCMakerConf.hpp" #include "appmodel/RandomTCMakerModule.hpp" +#include "appmodel/LatencyMonitoringConf.hpp" #include "daqdataformats/SourceID.hpp" #include "dfmessages/TimeSync.hpp" @@ -106,6 +107,7 @@ class RandomTCMakerModule : public dunedaq::appfwk::DAQModule void print_opmon_stats(); // Create an instance of the Latency class + std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index feb93a6a..086109e3 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -98,6 +98,7 @@ TAProcessor::conf(const appmodel::DataHandlerModule* conf) inherited::add_postprocess_task(std::bind(&TAProcessor::find_tc, this, std::placeholders::_1, maker)); m_tcms.push_back(maker); } + m_latency_monitoring = dp->get_latency_monitoring_conf()->get_latency_monitoring(); inherited::conf(conf); } diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index 657f8c89..26447b13 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -113,7 +113,7 @@ TCProcessor::conf(const appmodel::DataHandlerModule* cfg) } - // TODO: Group links! + // TODO: Group links! //m_group_links_data = conf->get_groups_links(); parse_group_links(m_group_links_data); print_group_links(); @@ -169,6 +169,7 @@ TCProcessor::conf(const appmodel::DataHandlerModule* cfg) set_trigger_bitwords(bitwords); print_trigger_bitwords(m_trigger_bitwords); } + m_latency_monitoring = dp->get_latency_monitoring_conf()->get_latency_monitoring(); inherited::add_postprocess_task(std::bind(&TCProcessor::make_td, this, std::placeholders::_1)); inherited::conf(mtrg); diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index 459fb3e9..4e1a97a9 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -17,7 +17,6 @@ #include "datahandlinglibs/models/IterableQueueModel.hpp" #include "datahandlinglibs/utils/ReusableThread.hpp" - #include "triggeralgs/TriggerActivity.hpp" #include "trigger/AlgorithmPlugins.hpp" @@ -100,7 +99,9 @@ TPProcessor::conf(const appmodel::DataHandlerModule* conf) inherited::add_postprocess_task(std::bind(&TPProcessor::find_ta, this, std::placeholders::_1, maker)); m_tams.push_back(maker); } + m_latency_monitoring = dp->get_latency_monitoring_conf()->get_latency_monitoring(); inherited::conf(conf); + } void diff --git a/src/trigger/HSISourceModel.hpp b/src/trigger/HSISourceModel.hpp index ab7b1bce..fb3dc966 100644 --- a/src/trigger/HSISourceModel.hpp +++ b/src/trigger/HSISourceModel.hpp @@ -26,6 +26,8 @@ #include "appmodel/DataSubscriberModule.hpp" #include "appmodel/HSI2TCTranslatorConf.hpp" #include "appmodel/HSISignalWindow.hpp" +#include "appmodel/LatencyMonitoringConf.hpp" +#include "appmodel/DataProcessor.hpp" namespace dunedaq::trigger { @@ -99,6 +101,8 @@ class HSISourceModel : public datahandlinglibs::SourceConcept } m_prescale = hsi_conf->get_prescale(); + m_latency_monitoring = cfg->cast()->get_latency_monitoring_conf()->get_latency_monitoring(); + } void start() { @@ -121,7 +125,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept bool handle_payload(dfmessages::HSIEvent& data) // NOLINT(build/unsigned) { m_received_events_count++; - m_latency_instance.update_latency_in( data.timestamp ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( data.timestamp ); // Prescale after n-hsi received if (m_received_events_count % m_prescale != 0) { @@ -159,7 +163,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept m_tcs_dropped_count++; } else { - m_latency_instance.update_latency_out( candidate.time_candidate ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); m_tcs_sent_count++; } @@ -181,7 +185,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept this->publish(std::move(info)); - if (m_running_flag.load()) { + if ( m_running_flag.load() && m_latency_monitoring.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -224,6 +228,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept // Create an instance of the Latency class std::atomic m_running_flag{ false }; + std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; diff --git a/src/trigger/TAProcessor.hpp b/src/trigger/TAProcessor.hpp index 8f0230fc..89d93379 100644 --- a/src/trigger/TAProcessor.hpp +++ b/src/trigger/TAProcessor.hpp @@ -13,6 +13,7 @@ #include "logging/Logging.hpp" #include "appmodel/DataHandlerModule.hpp" +#include "appmodel/LatencyMonitoringConf.hpp" #include "datahandlinglibs/models/TaskRawDataProcessorModel.hpp" @@ -78,6 +79,7 @@ class TAProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_running_flag{ false }; + std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; diff --git a/src/trigger/TCProcessor.hpp b/src/trigger/TCProcessor.hpp index 126a3fdb..3b48a671 100644 --- a/src/trigger/TCProcessor.hpp +++ b/src/trigger/TCProcessor.hpp @@ -16,6 +16,7 @@ #include "appmodel/TCReadoutMap.hpp" #include "appmodel/ROIGroupConf.hpp" #include "appmodel/SourceIDConf.hpp" +#include "appmodel/LatencyMonitoringConf.hpp" #include "datahandlinglibs/models/TaskRawDataProcessorModel.hpp" @@ -189,6 +190,7 @@ class TCProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_tc_ignored_count{ 0 }; // latency + std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; diff --git a/src/trigger/TPProcessor.hpp b/src/trigger/TPProcessor.hpp index 3306e327..44aa1b63 100644 --- a/src/trigger/TPProcessor.hpp +++ b/src/trigger/TPProcessor.hpp @@ -25,6 +25,7 @@ #include "triggeralgs/TriggerActivityMaker.hpp" #include "appmodel/DataHandlerModule.hpp" +#include "appmodel/LatencyMonitoringConf.hpp" namespace dunedaq { namespace trigger { @@ -78,6 +79,7 @@ class TPProcessor : public datahandlinglibs::TaskRawDataProcessorModel m_running_flag{ false }; + std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; From ec83c08ed45c218d8d394eb989964322cac9ad4a Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Thu, 12 Sep 2024 18:28:05 +0200 Subject: [PATCH 11/20] making latency monitoring configurable --- plugins/CustomTCMaker.cpp | 2 +- plugins/MLTModule.cpp | 2 +- plugins/RandomTCMakerModule.cpp | 2 +- src/TAProcessor.cpp | 2 +- src/TCProcessor.cpp | 2 +- src/TPProcessor.cpp | 2 +- src/trigger/HSISourceModel.hpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index e2a411a7..d22b992a 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -135,7 +135,7 @@ CustomTCMaker::do_configure(const nlohmann::json& /*obj*/) //// Currently precalculates events for the next 60 seconds //m_sorting_size_limit = 60 * m_conf0>clock_frequency_hz; - m_latency_monitoring = m_conf->get_latency_monitoring_conf()->get_latency_monitoring(); + m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); } void diff --git a/plugins/MLTModule.cpp b/plugins/MLTModule.cpp index 3ae497be..b712143f 100644 --- a/plugins/MLTModule.cpp +++ b/plugins/MLTModule.cpp @@ -67,7 +67,7 @@ MLTModule::init(std::shared_ptr mcfg) } // Now do the configuration: dummy for now - m_latency_monitoring = mtrg->get_configuration()->get_latency_monitoring_conf()->get_latency_monitoring(); + m_latency_monitoring.store( mtrg->get_configuration()->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); m_configured_flag.store(true); } diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index e40a5671..680d5f7f 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -91,7 +91,7 @@ void RandomTCMakerModule::do_configure(const nlohmann::json& /*obj*/) { //m_conf = obj.get(); - m_latency_monitoring = m_conf->get_latency_monitoring_conf()->get_latency_monitoring(); + m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); } void diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index 086109e3..a751160b 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -98,7 +98,7 @@ TAProcessor::conf(const appmodel::DataHandlerModule* conf) inherited::add_postprocess_task(std::bind(&TAProcessor::find_tc, this, std::placeholders::_1, maker)); m_tcms.push_back(maker); } - m_latency_monitoring = dp->get_latency_monitoring_conf()->get_latency_monitoring(); + m_latency_monitoring.store( dp->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); inherited::conf(conf); } diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index 26447b13..11b2a924 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -169,7 +169,7 @@ TCProcessor::conf(const appmodel::DataHandlerModule* cfg) set_trigger_bitwords(bitwords); print_trigger_bitwords(m_trigger_bitwords); } - m_latency_monitoring = dp->get_latency_monitoring_conf()->get_latency_monitoring(); + m_latency_monitoring.store( dp->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); inherited::add_postprocess_task(std::bind(&TCProcessor::make_td, this, std::placeholders::_1)); inherited::conf(mtrg); diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index 4e1a97a9..c2fcd1ab 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -99,7 +99,7 @@ TPProcessor::conf(const appmodel::DataHandlerModule* conf) inherited::add_postprocess_task(std::bind(&TPProcessor::find_ta, this, std::placeholders::_1, maker)); m_tams.push_back(maker); } - m_latency_monitoring = dp->get_latency_monitoring_conf()->get_latency_monitoring(); + m_latency_monitoring.store( dp->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); inherited::conf(conf); } diff --git a/src/trigger/HSISourceModel.hpp b/src/trigger/HSISourceModel.hpp index fb3dc966..2bc3bf6e 100644 --- a/src/trigger/HSISourceModel.hpp +++ b/src/trigger/HSISourceModel.hpp @@ -101,7 +101,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept } m_prescale = hsi_conf->get_prescale(); - m_latency_monitoring = cfg->cast()->get_latency_monitoring_conf()->get_latency_monitoring(); + m_latency_monitoring.store( hsi_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); } From a1cbfc69b84d2892c278e26c690b49efcbc57aa1 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Fri, 13 Sep 2024 11:25:36 +0200 Subject: [PATCH 12/20] trigger latency configuration propagation --- schema/trigger/opmon/latency_info.proto | 3 +++ schema/trigger/opmon/moduleleveltrigger_info.proto | 2 ++ src/TAProcessor.cpp | 6 +++--- src/TCProcessor.cpp | 6 +++--- src/TPProcessor.cpp | 6 +++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/schema/trigger/opmon/latency_info.proto b/schema/trigger/opmon/latency_info.proto index f5c1ff8b..7069f7b9 100644 --- a/schema/trigger/opmon/latency_info.proto +++ b/schema/trigger/opmon/latency_info.proto @@ -3,6 +3,9 @@ syntax = "proto3"; package dunedaq.trigger.opmon; // Message for latency variables +// Latency represents the difference between current system (clock) time and the data time of particular (TX) data object +// Units are ms +// Used by many trigger modules message TriggerLatency { uint32 latency_in = 1; uint32 latency_out = 2; diff --git a/schema/trigger/opmon/moduleleveltrigger_info.proto b/schema/trigger/opmon/moduleleveltrigger_info.proto index 6876a182..cc5c16f2 100644 --- a/schema/trigger/opmon/moduleleveltrigger_info.proto +++ b/schema/trigger/opmon/moduleleveltrigger_info.proto @@ -26,6 +26,8 @@ message TriggerDecisionInfo { } // Message for MLT TD requests latency vars +// Latency represents the difference between current system (clock) time and the requested TD readout window (start/end) +// Units are ms message ModuleLevelTriggerRequestLatency { uint32 latency_window_start = 1; uint32 latency_window_end = 2; diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index a751160b..f10fa79f 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -114,7 +114,7 @@ TAProcessor::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag.load()) { + if ( m_running_flag.load() && m_latency_monitoring.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -131,7 +131,7 @@ void TAProcessor::find_tc(const TAWrapper* ta, std::shared_ptr tca) { //time_activity gave 0 :/ - m_latency_instance.update_latency_in( ta->activity.time_start ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( ta->activity.time_start ); m_ta_received_count++; std::vector tcs; tca->operator()(ta->activity, tcs); @@ -143,7 +143,7 @@ TAProcessor::find_tc(const TAWrapper* ta, std::shared_ptrpublish(std::move(info)); - if (m_running_flag.load()) { + if ( m_running_flag.load() && m_latency_monitoring.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -213,7 +213,7 @@ TCProcessor::make_td(const TCWrapper* tcw) { auto tc = tcw->candidate; - m_latency_instance.update_latency_in( tc.time_start ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( tc.time_start ); m_tc_received_count++; if ( (m_use_readout_map) && (m_readout_window_map.count(tc.type)) ) { @@ -351,7 +351,7 @@ TCProcessor::call_tc_decision(const TCProcessor::PendingTD& pending_td) m_tds_dropped_tc_count += pending_td.contributing_tcs.size(); } else { - m_latency_instance.update_latency_out( pending_td.contributing_tcs.front().time_start ); + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( pending_td.contributing_tcs.front().time_start ); m_tds_sent_count++; m_tds_sent_tc_count += pending_td.contributing_tcs.size(); } diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index c2fcd1ab..18e096df 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -116,7 +116,7 @@ TPProcessor::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag.load()) { + if (m_running_flag.load() && m_latency_monitoring.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -132,7 +132,7 @@ TPProcessor::generate_opmon_data() void TPProcessor::find_ta(const TriggerPrimitiveTypeAdapter* tp, std::shared_ptr taa) { - m_latency_instance.update_latency_in( tp->tp.time_start ); // time_start or time_peak ? + if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( tp->tp.time_start ); // time_start or time_peak ? m_tp_received_count++; std::vector tas; taa->operator()(tp->tp, tas); @@ -145,7 +145,7 @@ TPProcessor::find_ta(const TriggerPrimitiveTypeAdapter* tp, std::shared_ptr Date: Fri, 13 Sep 2024 14:01:47 +0200 Subject: [PATCH 13/20] adding the option for us precision in latency class --- include/trigger/Latency.hpp | 48 +++++++++++++++++++++++++------------ plugins/MLTModule.cpp | 4 +++- plugins/MLTModule.hpp | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp index 1c302f89..d70f1f9c 100644 --- a/include/trigger/Latency.hpp +++ b/include/trigger/Latency.hpp @@ -11,38 +11,55 @@ #include #include +#include namespace dunedaq { namespace trigger { class Latency { public: - Latency() - : m_latency_in(0), m_latency_out(0), m_clock_ticks_to_ms(16 * 1e-6) - {} - // to convert 62.5MHz clock ticks to ms: 1/62500000 = 0.000000016 <- seconds per tick; 0.000016 <- ms per tick; - // 16*1e-6 <- sci notation + // Enumeration for selecting time units + enum class TimeUnit { Milliseconds, Microseconds }; + + // Constructor with optional time unit selection (defaults to Milliseconds) + Latency(TimeUnit time_unit = TimeUnit::Milliseconds) + : m_latency_in(0), m_latency_out(0), m_time_unit(time_unit) + { + // Set the clock tick conversion factor based on time unit + if (m_time_unit == TimeUnit::Milliseconds) { + m_clock_ticks_conversion.store(16 * 1e-6); // For milliseconds: 1 tick = 16 * 10^-6 ms + } else { + m_clock_ticks_conversion.store(16 * 1e-3); + } + // to convert 62.5MHz clock ticks to ms: 1/62500000 = 0.000000016 <- seconds per tick; 0.000016 <- ms per tick; + // 16*1e-6 <- sci notation + } - // Function to get the current system time - std::atomic get_current_system_time() const + // Function to get the current system time in ms or ns based on time unit + uint64_t get_current_system_time() const { - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); + if (m_time_unit == TimeUnit::Milliseconds) { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); + } else { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); + } } // Function to update latency_in void update_latency_in(uint64_t latency) { std::lock_guard lock(m_mutex); - m_latency_in.store(latency * m_clock_ticks_to_ms); + m_latency_in.store(latency * m_clock_ticks_conversion.load()); } // Function to update latency_out void update_latency_out(uint64_t latency) { std::lock_guard lock(m_mutex); - m_latency_out.store(latency * m_clock_ticks_to_ms); + m_latency_out.store(latency * m_clock_ticks_conversion.load()); } // Function to get the value of latency_in @@ -52,8 +69,8 @@ namespace trigger { if (m_latency_in.load() != 0) { // in edge cases the TP time was more recent then current sys time... // this is a catch for that - uint64_t diff = abs( int64_t(get_current_system_time()) - int64_t(m_latency_in.load()) ); - return diff; + uint64_t diff = abs(int64_t(get_current_system_time()) - int64_t(m_latency_in.load())); + return diff; } else { return 0; } @@ -64,7 +81,7 @@ namespace trigger { { std::lock_guard lock(m_mutex); if (m_latency_out.load() != 0) { - uint64_t diff = abs( int64_t(get_current_system_time()) - int64_t(m_latency_out.load()) ); + uint64_t diff = abs(int64_t(get_current_system_time()) - int64_t(m_latency_out.load())); return diff; } else { return 0; @@ -74,8 +91,9 @@ namespace trigger { private: std::atomic m_latency_in; // Member variable to store latency_in std::atomic m_latency_out; // Member variable to store latency_out - std::atomic m_clock_ticks_to_ms; + std::atomic m_clock_ticks_conversion; // Dynamically adjusted conversion factor for clock ticks mutable std::mutex m_mutex; + TimeUnit m_time_unit; // Member variable to store the selected time unit (ms or ns) }; } // namespace trigger diff --git a/plugins/MLTModule.cpp b/plugins/MLTModule.cpp index b712143f..06d25a36 100644 --- a/plugins/MLTModule.cpp +++ b/plugins/MLTModule.cpp @@ -66,8 +66,10 @@ MLTModule::init(std::shared_ptr mcfg) m_decision_output = get_iom_sender(con->UID()); } - // Now do the configuration: dummy for now + // Latency related m_latency_monitoring.store( mtrg->get_configuration()->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + + // Now do the configuration: dummy for now m_configured_flag.store(true); } diff --git a/plugins/MLTModule.hpp b/plugins/MLTModule.hpp index eb9be222..54ef72b3 100644 --- a/plugins/MLTModule.hpp +++ b/plugins/MLTModule.hpp @@ -257,7 +257,7 @@ class MLTModule : public dunedaq::appfwk::DAQModule // Create an instance of the Latency class std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; - dunedaq::trigger::Latency m_latency_requests_instance; + dunedaq::trigger::Latency m_latency_requests_instance{dunedaq::trigger::Latency::TimeUnit::Microseconds}; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; std::atomic m_latency_window_start{ 0 }; From 0822cc0bdd572c503e9d0c78b47a5705e5fd73f7 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Fri, 13 Sep 2024 15:50:06 +0200 Subject: [PATCH 14/20] fixing incorrect tlog --- src/TCProcessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index 78cddf53..67e76cad 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -273,7 +273,7 @@ TCProcessor::create_decision(const PendingTD& pending_td) } } else { m_TD_bitword = get_TD_bitword(pending_td); - TLOG(5) << "[MLT] TD has bitword: " << m_TD_bitword << " " + TLOG_DEBUG(5) << "[MLT] TD has bitword: " << m_TD_bitword << " " << static_cast(m_TD_bitword.to_ulong()); decision.trigger_type = static_cast(m_TD_bitword.to_ulong()); // m_trigger_type; From dc4ea9c6636e4aa92865e87cf8aa6bd413be0fd4 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Thu, 19 Sep 2024 18:02:44 +0200 Subject: [PATCH 15/20] fix for latency class --- include/trigger/Latency.hpp | 16 +++++----------- .../trigger/opmon/moduleleveltrigger_info.proto | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp index d70f1f9c..a1b2532f 100644 --- a/include/trigger/Latency.hpp +++ b/include/trigger/Latency.hpp @@ -11,7 +11,6 @@ #include #include -#include namespace dunedaq { namespace trigger { @@ -28,9 +27,9 @@ namespace trigger { { // Set the clock tick conversion factor based on time unit if (m_time_unit == TimeUnit::Milliseconds) { - m_clock_ticks_conversion.store(16 * 1e-6); // For milliseconds: 1 tick = 16 * 10^-6 ms + m_clock_ticks_conversion = 16 * 1e-6; // For milliseconds: 1 tick = 16 * 10^-6 ms } else { - m_clock_ticks_conversion.store(16 * 1e-3); + m_clock_ticks_conversion = 16 * 1e-3; } // to convert 62.5MHz clock ticks to ms: 1/62500000 = 0.000000016 <- seconds per tick; 0.000016 <- ms per tick; // 16*1e-6 <- sci notation @@ -51,21 +50,18 @@ namespace trigger { // Function to update latency_in void update_latency_in(uint64_t latency) { - std::lock_guard lock(m_mutex); - m_latency_in.store(latency * m_clock_ticks_conversion.load()); + m_latency_in.store(latency * m_clock_ticks_conversion); } // Function to update latency_out void update_latency_out(uint64_t latency) { - std::lock_guard lock(m_mutex); - m_latency_out.store(latency * m_clock_ticks_conversion.load()); + m_latency_out.store(latency * m_clock_ticks_conversion); } // Function to get the value of latency_in uint64_t get_latency_in() const { - std::lock_guard lock(m_mutex); if (m_latency_in.load() != 0) { // in edge cases the TP time was more recent then current sys time... // this is a catch for that @@ -79,7 +75,6 @@ namespace trigger { // Function to get the value of latency_out uint64_t get_latency_out() const { - std::lock_guard lock(m_mutex); if (m_latency_out.load() != 0) { uint64_t diff = abs(int64_t(get_current_system_time()) - int64_t(m_latency_out.load())); return diff; @@ -91,8 +86,7 @@ namespace trigger { private: std::atomic m_latency_in; // Member variable to store latency_in std::atomic m_latency_out; // Member variable to store latency_out - std::atomic m_clock_ticks_conversion; // Dynamically adjusted conversion factor for clock ticks - mutable std::mutex m_mutex; + double m_clock_ticks_conversion; // Dynamically adjusted conversion factor for clock ticks TimeUnit m_time_unit; // Member variable to store the selected time unit (ms or ns) }; diff --git a/schema/trigger/opmon/moduleleveltrigger_info.proto b/schema/trigger/opmon/moduleleveltrigger_info.proto index cc5c16f2..bff25beb 100644 --- a/schema/trigger/opmon/moduleleveltrigger_info.proto +++ b/schema/trigger/opmon/moduleleveltrigger_info.proto @@ -27,7 +27,7 @@ message TriggerDecisionInfo { // Message for MLT TD requests latency vars // Latency represents the difference between current system (clock) time and the requested TD readout window (start/end) -// Units are ms +// Units are currently us (but use an enum and can be changed) message ModuleLevelTriggerRequestLatency { uint32 latency_window_start = 1; uint32 latency_window_end = 2; From bbddc50c7a8baed5248106638924d685d0034456 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Mon, 7 Oct 2024 22:32:28 +0200 Subject: [PATCH 16/20] some latency improvements --- plugins/CustomTCMaker.cpp | 7 +++---- plugins/MLTModule.cpp | 15 +++++++-------- plugins/MLTModule.hpp | 2 +- plugins/RandomTCMakerModule.cpp | 6 +++--- src/TAProcessor.cpp | 4 ++-- src/TCProcessor.cpp | 4 ++-- src/TPProcessor.cpp | 5 ++--- src/trigger/HSISourceModel.hpp | 4 ++-- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index 9edb555a..aea042cf 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -85,6 +85,7 @@ CustomTCMaker::init(std::shared_ptr mcfg) // Currently precalculates events for the next 60 seconds m_sorting_size_limit = 60 * m_conf->get_clock_frequency_hz(); + m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); } //void @@ -107,7 +108,7 @@ CustomTCMaker::generate_opmon_data() this->publish(std::move(info)); - if ( m_running_flag.load() && m_latency_monitoring.load() ) { + if ( m_latency_monitoring.load() && m_running_flag.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -133,8 +134,6 @@ CustomTCMaker::do_configure(const nlohmann::json& /*obj*/) //// This parameter controls how many new timestamps are calculated when needed //// Currently precalculates events for the next 60 seconds //m_sorting_size_limit = 60 * m_conf0>clock_frequency_hz; - - m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); } void @@ -258,9 +257,9 @@ CustomTCMaker::send_trigger_candidates() TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() << ", pushing a candidate with timestamp " << candidate.time_candidate; + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); try { m_trigger_candidate_sink->send(std::move(candidate), std::chrono::milliseconds(10)); - if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); m_tc_sent_count++; m_tc_sent_count_type[m_tc_timestamps.front().first] += 1; } catch (const ers::Issue& e) { diff --git a/plugins/MLTModule.cpp b/plugins/MLTModule.cpp index 813e5cfa..07929f92 100644 --- a/plugins/MLTModule.cpp +++ b/plugins/MLTModule.cpp @@ -111,7 +111,7 @@ MLTModule::generate_opmon_data() } // latency - if ( m_running_flag.load() && m_latency_monitoring.load() ) { + if ( m_latency_monitoring.load() && m_running_flag.load() ) { // TC in, TD out opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -240,15 +240,14 @@ MLTModule::trigger_decisions_callback(dfmessages::TriggerDecision& decision ) << decision.trigger_timestamp << " start " << decision.components.front().window_begin << " end " << decision.components.front().window_end << " number of links " << decision.components.size(); + // readout window latency update + if (m_latency_monitoring.load()) { + m_latency_requests_instance.update_latency_in( decision.components.front().window_begin ); + m_latency_requests_instance.update_latency_out( decision.components.front().window_end ); + } + try { m_decision_output->send(std::move(decision), std::chrono::milliseconds(1)); - - // readout window latency update - if (m_latency_monitoring.load()) { - m_latency_requests_instance.update_latency_in( decision.components.front().window_begin ); - m_latency_requests_instance.update_latency_out( decision.components.front().window_end ); - } - m_td_sent_count++; for ( const auto t : trigger_types ) { diff --git a/plugins/MLTModule.hpp b/plugins/MLTModule.hpp index 54ef72b3..8608ecc2 100644 --- a/plugins/MLTModule.hpp +++ b/plugins/MLTModule.hpp @@ -257,7 +257,7 @@ class MLTModule : public dunedaq::appfwk::DAQModule // Create an instance of the Latency class std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; - dunedaq::trigger::Latency m_latency_requests_instance{dunedaq::trigger::Latency::TimeUnit::Microseconds}; + dunedaq::trigger::Latency m_latency_requests_instance{ dunedaq::trigger::Latency::TimeUnit::Microseconds }; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; std::atomic m_latency_window_start{ 0 }; diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index b164766b..3bc5850b 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -62,6 +62,7 @@ RandomTCMakerModule::init(std::shared_ptr mcfg) m_time_sync_source = get_iom_receiver(con->UID()); } m_conf = mtrg->get_configuration(); + m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); } void @@ -75,7 +76,7 @@ RandomTCMakerModule::generate_opmon_data() this->publish(std::move(info)); - if ( m_running_flag.load() && m_latency_monitoring.load() ) { + if ( m_latency_monitoring.load() && m_running_flag.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -89,7 +90,6 @@ void RandomTCMakerModule::do_configure(const nlohmann::json& /*obj*/) { //m_conf = obj.get(); - m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); } void @@ -230,9 +230,9 @@ RandomTCMakerModule::send_trigger_candidates() TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() << ", pushing a candidate with timestamp " << candidate.time_candidate; + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); try{ m_trigger_candidate_sink->send(std::move(candidate), std::chrono::milliseconds(10)); - if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); m_tc_sent_count++; } catch (const ers::Issue& e) { ers::error(e); diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index f10fa79f..b7f1b5c1 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -114,7 +114,7 @@ TAProcessor::generate_opmon_data() this->publish(std::move(info)); - if ( m_running_flag.load() && m_latency_monitoring.load() ) { + if ( m_latency_monitoring.load() && m_running_flag.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -137,13 +137,13 @@ TAProcessor::find_tc(const TAWrapper* ta, std::shared_ptroperator()(ta->activity, tcs); for (auto tc : tcs) { m_tc_made_count++; + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( tc.time_candidate ); if(!m_tc_sink->try_send(std::move(tc), iomanager::Sender::s_no_block)) { ers::warning(TCDropped(ERS_HERE, tc.time_start, m_sourceid.id)); m_tc_failed_sent_count++; } else { m_tc_sent_count++; } - if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( tc.time_candidate ); } return; } diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index 67e76cad..d3275f68 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -195,7 +195,7 @@ TCProcessor::generate_opmon_data() this->publish(std::move(info)); - if ( m_running_flag.load() && m_latency_monitoring.load() ) { + if ( m_latency_monitoring.load() && m_running_flag.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -345,13 +345,13 @@ TCProcessor::call_tc_decision(const TCProcessor::PendingTD& pending_td) auto tn = decision.trigger_number; auto td_ts = decision.trigger_timestamp; + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( pending_td.contributing_tcs.front().time_start ); if(!m_td_sink->try_send(std::move(decision), iomanager::Sender::s_no_block)) { ers::warning(TDDropped(ERS_HERE, tn, td_ts)); m_tds_dropped_count++; m_tds_dropped_tc_count += pending_td.contributing_tcs.size(); } else { - if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( pending_td.contributing_tcs.front().time_start ); m_tds_sent_count++; m_tds_sent_tc_count += pending_td.contributing_tcs.size(); } diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index 18e096df..ba106e38 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -116,7 +116,7 @@ TPProcessor::generate_opmon_data() this->publish(std::move(info)); - if (m_running_flag.load() && m_latency_monitoring.load() ) { + if ( m_latency_monitoring.load() && m_running_flag.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); @@ -139,14 +139,13 @@ TPProcessor::find_ta(const TriggerPrimitiveTypeAdapter* tp, std::shared_ptrtry_send(std::move(tas.back()), iomanager::Sender::s_no_block)) { ers::warning(TADropped(ERS_HERE, tp->tp.time_start, m_sourceid.id)); m_ta_failed_sent_count++; } else { m_ta_sent_count++; } - if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( tas.back().time_start ); - tas.pop_back(); } return; diff --git a/src/trigger/HSISourceModel.hpp b/src/trigger/HSISourceModel.hpp index 2bc3bf6e..9906626d 100644 --- a/src/trigger/HSISourceModel.hpp +++ b/src/trigger/HSISourceModel.hpp @@ -158,12 +158,12 @@ class HSISourceModel : public datahandlinglibs::SourceConcept candidate.inputs = {}; m_tcs_made_count++; + if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); // Send the TC if (!m_data_sender->try_send(std::move(candidate), iomanager::Sender::s_no_block)) { m_tcs_dropped_count++; } else { - if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( candidate.time_candidate ); m_tcs_sent_count++; } @@ -185,7 +185,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept this->publish(std::move(info)); - if ( m_running_flag.load() && m_latency_monitoring.load() ) { + if ( m_latency_monitoring.load() && m_running_flag.load() ) { opmon::TriggerLatency lat_info; lat_info.set_latency_in( m_latency_instance.get_latency_in() ); From 6b33efd30e4f2ccf5404d26f5d537f25ffc600db Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Tue, 8 Oct 2024 18:33:05 +0200 Subject: [PATCH 17/20] small rework of latency class --- include/trigger/Latency.hpp | 155 ++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 78 deletions(-) diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp index a1b2532f..93a6c831 100644 --- a/include/trigger/Latency.hpp +++ b/include/trigger/Latency.hpp @@ -9,88 +9,87 @@ #ifndef TRIGGER_INCLUDE_TRIGGER_LATENCY_HPP_ #define TRIGGER_INCLUDE_TRIGGER_LATENCY_HPP_ +#include "utilities/TimestampEstimator.hpp" +#include "utilities/TimestampEstimatorSystem.hpp" + #include #include +#include // Include for std::ostream namespace dunedaq { -namespace trigger { - - class Latency { - public: - - // Enumeration for selecting time units - enum class TimeUnit { Milliseconds, Microseconds }; - - // Constructor with optional time unit selection (defaults to Milliseconds) - Latency(TimeUnit time_unit = TimeUnit::Milliseconds) - : m_latency_in(0), m_latency_out(0), m_time_unit(time_unit) - { - // Set the clock tick conversion factor based on time unit - if (m_time_unit == TimeUnit::Milliseconds) { - m_clock_ticks_conversion = 16 * 1e-6; // For milliseconds: 1 tick = 16 * 10^-6 ms - } else { - m_clock_ticks_conversion = 16 * 1e-3; - } - // to convert 62.5MHz clock ticks to ms: 1/62500000 = 0.000000016 <- seconds per tick; 0.000016 <- ms per tick; - // 16*1e-6 <- sci notation - } - - // Function to get the current system time in ms or ns based on time unit - uint64_t get_current_system_time() const - { - if (m_time_unit == TimeUnit::Milliseconds) { - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - } else { - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count(); - } - } - - // Function to update latency_in - void update_latency_in(uint64_t latency) - { - m_latency_in.store(latency * m_clock_ticks_conversion); - } - - // Function to update latency_out - void update_latency_out(uint64_t latency) - { - m_latency_out.store(latency * m_clock_ticks_conversion); - } - - // Function to get the value of latency_in - uint64_t get_latency_in() const - { - if (m_latency_in.load() != 0) { - // in edge cases the TP time was more recent then current sys time... - // this is a catch for that - uint64_t diff = abs(int64_t(get_current_system_time()) - int64_t(m_latency_in.load())); - return diff; - } else { - return 0; - } - } - - // Function to get the value of latency_out - uint64_t get_latency_out() const - { - if (m_latency_out.load() != 0) { - uint64_t diff = abs(int64_t(get_current_system_time()) - int64_t(m_latency_out.load())); - return diff; - } else { - return 0; - } - } - - private: - std::atomic m_latency_in; // Member variable to store latency_in - std::atomic m_latency_out; // Member variable to store latency_out - double m_clock_ticks_conversion; // Dynamically adjusted conversion factor for clock ticks - TimeUnit m_time_unit; // Member variable to store the selected time unit (ms or ns) - }; - -} // namespace trigger + namespace trigger { + + class Latency { + using latency = double; + + public: + // Enumeration for selecting time units + enum class TimeUnit { Milliseconds = 1, Microseconds = 2 }; + + // Constructor with optional time unit selection (defaults to Milliseconds) + Latency(TimeUnit time_unit = TimeUnit::Milliseconds) + : m_latency_in(0), m_latency_out(0), m_time_unit(time_unit), clock_freq(62500000) { + + setup_conversion(); + + // Start timestamp estimator + m_timestamp_estimator.reset(new utilities::TimestampEstimatorSystem(clock_freq)); + } + + ~Latency() { + m_timestamp_estimator.reset(nullptr); // Calls TimestampEstimator dtor + } + + // Function to get the current system time in ms or ns based on time unit + uint64_t get_current_system_time() const { + return m_timestamp_estimator->get_timestamp_estimate(); + } + + // Function to update latency_in + void update_latency_in(uint64_t latency) { + uint64_t current_time = get_current_system_time(); + uint64_t diff = (current_time >= latency) ? (current_time - latency) : 0; + m_latency_in.store( diff * m_clock_ticks_conversion ); + TLOG() << static_cast(m_time_unit) << " " << current_time << " " << latency << " " << diff << " " << m_latency_in.load(); + } + + // Function to update latency_out + void update_latency_out(uint64_t latency) { + uint64_t current_time = get_current_system_time(); + uint64_t diff = (current_time >= latency) ? (current_time - latency) : 0; + m_latency_out.store( diff * m_clock_ticks_conversion ); + } + + // Function to get the value of latency_in + latency get_latency_in() const { + return m_latency_in.load(); + } + + // Function to get the value of latency_out + latency get_latency_out() const { + return m_latency_out.load(); + } + + private: + void setup_conversion() { + if (m_time_unit == TimeUnit::Milliseconds) { + m_clock_ticks_conversion = 16 * 1e-6; // For milliseconds + } else { + m_clock_ticks_conversion = 16 * 1e-3; // For microseconds + } + } + + std::atomic m_latency_in; // Member variable to store latency_in + std::atomic m_latency_out; // Member variable to store latency_out + TimeUnit m_time_unit; // Member variable to store the selected time unit (ms or ns) + latency m_clock_ticks_conversion; // Conversion factor from ticks to the selected time unit + std::unique_ptr m_timestamp_estimator; + latency clock_freq; + // Function pointer or lambda for conversion based on time unit + std::function m_convert_latency; + }; + + } // namespace trigger } // namespace dunedaq #endif // TRIGGER_INCLUDE_TRIGGER_LATENCY_HPP_ From 22f6687bb882a25ba9f92f52cac13923b07293af Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Wed, 9 Oct 2024 16:16:42 +0200 Subject: [PATCH 18/20] latency: making micros the default --- include/trigger/Latency.hpp | 19 ++++++++----------- plugins/MLTModule.hpp | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp index 93a6c831..1d6c25d8 100644 --- a/include/trigger/Latency.hpp +++ b/include/trigger/Latency.hpp @@ -20,14 +20,14 @@ namespace dunedaq { namespace trigger { class Latency { - using latency = double; + using latency = uint64_t; public: // Enumeration for selecting time units - enum class TimeUnit { Milliseconds = 1, Microseconds = 2 }; + enum class TimeUnit { Microseconds = 1, Milliseconds = 2 }; // Constructor with optional time unit selection (defaults to Milliseconds) - Latency(TimeUnit time_unit = TimeUnit::Milliseconds) + Latency(TimeUnit time_unit = TimeUnit::Microseconds) : m_latency_in(0), m_latency_out(0), m_time_unit(time_unit), clock_freq(62500000) { setup_conversion(); @@ -41,7 +41,7 @@ namespace dunedaq { } // Function to get the current system time in ms or ns based on time unit - uint64_t get_current_system_time() const { + latency get_current_system_time() const { return m_timestamp_estimator->get_timestamp_estimate(); } @@ -50,7 +50,6 @@ namespace dunedaq { uint64_t current_time = get_current_system_time(); uint64_t diff = (current_time >= latency) ? (current_time - latency) : 0; m_latency_in.store( diff * m_clock_ticks_conversion ); - TLOG() << static_cast(m_time_unit) << " " << current_time << " " << latency << " " << diff << " " << m_latency_in.load(); } // Function to update latency_out @@ -72,21 +71,19 @@ namespace dunedaq { private: void setup_conversion() { - if (m_time_unit == TimeUnit::Milliseconds) { - m_clock_ticks_conversion = 16 * 1e-6; // For milliseconds + if (m_time_unit == TimeUnit::Microseconds) { + m_clock_ticks_conversion = 16 * 1e-3; } else { - m_clock_ticks_conversion = 16 * 1e-3; // For microseconds + m_clock_ticks_conversion = 16 * 1e-6; } } std::atomic m_latency_in; // Member variable to store latency_in std::atomic m_latency_out; // Member variable to store latency_out TimeUnit m_time_unit; // Member variable to store the selected time unit (ms or ns) - latency m_clock_ticks_conversion; // Conversion factor from ticks to the selected time unit + double m_clock_ticks_conversion; // Conversion factor from ticks to the selected time unit std::unique_ptr m_timestamp_estimator; latency clock_freq; - // Function pointer or lambda for conversion based on time unit - std::function m_convert_latency; }; } // namespace trigger diff --git a/plugins/MLTModule.hpp b/plugins/MLTModule.hpp index 8608ecc2..eb9be222 100644 --- a/plugins/MLTModule.hpp +++ b/plugins/MLTModule.hpp @@ -257,7 +257,7 @@ class MLTModule : public dunedaq::appfwk::DAQModule // Create an instance of the Latency class std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; - dunedaq::trigger::Latency m_latency_requests_instance{ dunedaq::trigger::Latency::TimeUnit::Microseconds }; + dunedaq::trigger::Latency m_latency_requests_instance; std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; std::atomic m_latency_window_start{ 0 }; From da978b7c6b697b5d42919f025aba237ab3f3ef2d Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Thu, 10 Oct 2024 12:03:49 +0200 Subject: [PATCH 19/20] simplifying latency monitoring --- include/trigger/Latency.hpp | 58 +++++++++++++++++++-------------- plugins/CustomTCMaker.cpp | 2 +- plugins/CustomTCMaker.hpp | 1 - plugins/MLTModule.cpp | 2 +- plugins/MLTModule.hpp | 1 - plugins/RandomTCMakerModule.cpp | 2 +- plugins/RandomTCMakerModule.hpp | 1 - src/TAProcessor.cpp | 2 +- src/TCProcessor.cpp | 2 +- src/TPProcessor.cpp | 2 +- src/trigger/HSISourceModel.hpp | 3 +- src/trigger/TAProcessor.hpp | 1 - src/trigger/TCProcessor.hpp | 1 - src/trigger/TPProcessor.hpp | 1 - 14 files changed, 40 insertions(+), 39 deletions(-) diff --git a/include/trigger/Latency.hpp b/include/trigger/Latency.hpp index 1d6c25d8..9337a821 100644 --- a/include/trigger/Latency.hpp +++ b/include/trigger/Latency.hpp @@ -26,37 +26,22 @@ namespace dunedaq { // Enumeration for selecting time units enum class TimeUnit { Microseconds = 1, Milliseconds = 2 }; - // Constructor with optional time unit selection (defaults to Milliseconds) + // Constructor with optional time unit selection (defaults to Microseconds) Latency(TimeUnit time_unit = TimeUnit::Microseconds) - : m_latency_in(0), m_latency_out(0), m_time_unit(time_unit), clock_freq(62500000) { - + : m_latency_in(0), m_latency_out(0), m_time_unit(time_unit) { setup_conversion(); - - // Start timestamp estimator - m_timestamp_estimator.reset(new utilities::TimestampEstimatorSystem(clock_freq)); } - ~Latency() { - m_timestamp_estimator.reset(nullptr); // Calls TimestampEstimator dtor - } - - // Function to get the current system time in ms or ns based on time unit - latency get_current_system_time() const { - return m_timestamp_estimator->get_timestamp_estimate(); - } + ~Latency() {} // Function to update latency_in void update_latency_in(uint64_t latency) { - uint64_t current_time = get_current_system_time(); - uint64_t diff = (current_time >= latency) ? (current_time - latency) : 0; - m_latency_in.store( diff * m_clock_ticks_conversion ); + update_single_latency(latency, m_latency_in); } // Function to update latency_out void update_latency_out(uint64_t latency) { - uint64_t current_time = get_current_system_time(); - uint64_t diff = (current_time >= latency) ? (current_time - latency) : 0; - m_latency_out.store( diff * m_clock_ticks_conversion ); + update_single_latency(latency, m_latency_out); } // Function to get the value of latency_in @@ -70,20 +55,43 @@ namespace dunedaq { } private: + // Set up conversion based on the selected time unit void setup_conversion() { if (m_time_unit == TimeUnit::Microseconds) { - m_clock_ticks_conversion = 16 * 1e-3; + m_clock_ticks_conversion = 16 * 1e-3; // Conversion for microseconds + m_get_current_time = []() { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); + }; } else { - m_clock_ticks_conversion = 16 * 1e-6; + m_clock_ticks_conversion = 16 * 1e-6; // Conversion for milliseconds + m_get_current_time = []() { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); + }; } } + // Function to get the current system time based on the set time unit + uint64_t get_current_system_time() const { + return m_get_current_time(); + } + + // Single update function for both latencies + void update_single_latency(uint64_t latency, std::atomic& latency_atomic) { + uint64_t current_time = get_current_system_time(); + uint64_t latency_time = latency * m_clock_ticks_conversion; + uint64_t diff = (current_time >= latency_time) ? (current_time - latency_time) : 0; + latency_atomic.store(diff); + } + std::atomic m_latency_in; // Member variable to store latency_in std::atomic m_latency_out; // Member variable to store latency_out TimeUnit m_time_unit; // Member variable to store the selected time unit (ms or ns) - double m_clock_ticks_conversion; // Conversion factor from ticks to the selected time unit - std::unique_ptr m_timestamp_estimator; - latency clock_freq; + double m_clock_ticks_conversion; // Conversion factor from ticks to the selected time unit + + // Lambda to get the current time + std::function m_get_current_time; }; } // namespace trigger diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index aea042cf..c7e28a8f 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -85,7 +85,7 @@ CustomTCMaker::init(std::shared_ptr mcfg) // Currently precalculates events for the next 60 seconds m_sorting_size_limit = 60 * m_conf->get_clock_frequency_hz(); - m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + m_latency_monitoring.store( m_conf->get_latency_monitoring() ); } //void diff --git a/plugins/CustomTCMaker.hpp b/plugins/CustomTCMaker.hpp index 82bcebd2..0b133488 100644 --- a/plugins/CustomTCMaker.hpp +++ b/plugins/CustomTCMaker.hpp @@ -11,7 +11,6 @@ #include "appmodel/CustomTCMaker.hpp" #include "appmodel/CustomTCMakerConf.hpp" -#include "appmodel/LatencyMonitoringConf.hpp" #include "confmodel/Connection.hpp" #include "appfwk/ModuleConfiguration.hpp" diff --git a/plugins/MLTModule.cpp b/plugins/MLTModule.cpp index 07929f92..db03cc7e 100644 --- a/plugins/MLTModule.cpp +++ b/plugins/MLTModule.cpp @@ -67,7 +67,7 @@ MLTModule::init(std::shared_ptr mcfg) } // Latency related - m_latency_monitoring.store( mtrg->get_configuration()->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + m_latency_monitoring.store( mtrg->get_configuration()->get_latency_monitoring() ); // Now do the configuration: dummy for now m_configured_flag.store(true); diff --git a/plugins/MLTModule.hpp b/plugins/MLTModule.hpp index eb9be222..e405a76a 100644 --- a/plugins/MLTModule.hpp +++ b/plugins/MLTModule.hpp @@ -28,7 +28,6 @@ #include "appmodel/TCReadoutMap.hpp" #include "appmodel/ROIGroupConf.hpp" #include "appmodel/SourceIDConf.hpp" -#include "appmodel/LatencyMonitoringConf.hpp" #include "confmodel/Connection.hpp" diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index 3bc5850b..a12b0a35 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -62,7 +62,7 @@ RandomTCMakerModule::init(std::shared_ptr mcfg) m_time_sync_source = get_iom_receiver(con->UID()); } m_conf = mtrg->get_configuration(); - m_latency_monitoring.store( m_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + m_latency_monitoring.store( m_conf->get_latency_monitoring() ); } void diff --git a/plugins/RandomTCMakerModule.hpp b/plugins/RandomTCMakerModule.hpp index 7f0440ff..f79e43f6 100644 --- a/plugins/RandomTCMakerModule.hpp +++ b/plugins/RandomTCMakerModule.hpp @@ -15,7 +15,6 @@ #include "appmodel/RandomTCMakerConf.hpp" #include "appmodel/RandomTCMakerModule.hpp" -#include "appmodel/LatencyMonitoringConf.hpp" #include "daqdataformats/SourceID.hpp" #include "dfmessages/TimeSync.hpp" diff --git a/src/TAProcessor.cpp b/src/TAProcessor.cpp index b7f1b5c1..8d712749 100644 --- a/src/TAProcessor.cpp +++ b/src/TAProcessor.cpp @@ -98,7 +98,7 @@ TAProcessor::conf(const appmodel::DataHandlerModule* conf) inherited::add_postprocess_task(std::bind(&TAProcessor::find_tc, this, std::placeholders::_1, maker)); m_tcms.push_back(maker); } - m_latency_monitoring.store( dp->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + m_latency_monitoring.store( dp->get_latency_monitoring() ); inherited::conf(conf); } diff --git a/src/TCProcessor.cpp b/src/TCProcessor.cpp index d3275f68..f5b9e650 100644 --- a/src/TCProcessor.cpp +++ b/src/TCProcessor.cpp @@ -169,7 +169,7 @@ TCProcessor::conf(const appmodel::DataHandlerModule* cfg) set_trigger_bitwords(bitwords); print_trigger_bitwords(m_trigger_bitwords); } - m_latency_monitoring.store( dp->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + m_latency_monitoring.store( dp->get_latency_monitoring() ); inherited::add_postprocess_task(std::bind(&TCProcessor::make_td, this, std::placeholders::_1)); inherited::conf(mtrg); diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index ba106e38..a4b2b3eb 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -99,7 +99,7 @@ TPProcessor::conf(const appmodel::DataHandlerModule* conf) inherited::add_postprocess_task(std::bind(&TPProcessor::find_ta, this, std::placeholders::_1, maker)); m_tams.push_back(maker); } - m_latency_monitoring.store( dp->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + m_latency_monitoring.store( dp->get_latency_monitoring() ); inherited::conf(conf); } diff --git a/src/trigger/HSISourceModel.hpp b/src/trigger/HSISourceModel.hpp index 9906626d..1a54b75e 100644 --- a/src/trigger/HSISourceModel.hpp +++ b/src/trigger/HSISourceModel.hpp @@ -26,7 +26,6 @@ #include "appmodel/DataSubscriberModule.hpp" #include "appmodel/HSI2TCTranslatorConf.hpp" #include "appmodel/HSISignalWindow.hpp" -#include "appmodel/LatencyMonitoringConf.hpp" #include "appmodel/DataProcessor.hpp" namespace dunedaq::trigger { @@ -101,7 +100,7 @@ class HSISourceModel : public datahandlinglibs::SourceConcept } m_prescale = hsi_conf->get_prescale(); - m_latency_monitoring.store( hsi_conf->get_latency_monitoring_conf()->get_enable_latency_monitoring() ); + m_latency_monitoring.store( hsi_conf->get_latency_monitoring() ); } diff --git a/src/trigger/TAProcessor.hpp b/src/trigger/TAProcessor.hpp index 89d93379..98df3c1e 100644 --- a/src/trigger/TAProcessor.hpp +++ b/src/trigger/TAProcessor.hpp @@ -13,7 +13,6 @@ #include "logging/Logging.hpp" #include "appmodel/DataHandlerModule.hpp" -#include "appmodel/LatencyMonitoringConf.hpp" #include "datahandlinglibs/models/TaskRawDataProcessorModel.hpp" diff --git a/src/trigger/TCProcessor.hpp b/src/trigger/TCProcessor.hpp index 3b48a671..222749d7 100644 --- a/src/trigger/TCProcessor.hpp +++ b/src/trigger/TCProcessor.hpp @@ -16,7 +16,6 @@ #include "appmodel/TCReadoutMap.hpp" #include "appmodel/ROIGroupConf.hpp" #include "appmodel/SourceIDConf.hpp" -#include "appmodel/LatencyMonitoringConf.hpp" #include "datahandlinglibs/models/TaskRawDataProcessorModel.hpp" diff --git a/src/trigger/TPProcessor.hpp b/src/trigger/TPProcessor.hpp index 44aa1b63..5eff3adb 100644 --- a/src/trigger/TPProcessor.hpp +++ b/src/trigger/TPProcessor.hpp @@ -25,7 +25,6 @@ #include "triggeralgs/TriggerActivityMaker.hpp" #include "appmodel/DataHandlerModule.hpp" -#include "appmodel/LatencyMonitoringConf.hpp" namespace dunedaq { namespace trigger { From 45905a792a25e6bf4cab8f552f7be639ce80fba6 Mon Sep 17 00:00:00 2001 From: MRiganSUSX Date: Fri, 11 Oct 2024 14:54:05 +0200 Subject: [PATCH 20/20] update for latencies for standalone makers --- plugins/CustomTCMaker.cpp | 4 +--- plugins/CustomTCMaker.hpp | 1 - plugins/RandomTCMakerModule.cpp | 4 +--- plugins/RandomTCMakerModule.hpp | 1 - schema/trigger/opmon/latency_info.proto | 9 ++++++++- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/CustomTCMaker.cpp b/plugins/CustomTCMaker.cpp index c7e28a8f..81ff44f0 100644 --- a/plugins/CustomTCMaker.cpp +++ b/plugins/CustomTCMaker.cpp @@ -109,9 +109,8 @@ CustomTCMaker::generate_opmon_data() this->publish(std::move(info)); if ( m_latency_monitoring.load() && m_running_flag.load() ) { - opmon::TriggerLatency lat_info; + opmon::TriggerLatencyStandalone lat_info; - lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); this->publish(std::move(lat_info)); @@ -251,7 +250,6 @@ CustomTCMaker::send_trigger_candidates() } triggeralgs::TriggerCandidate candidate = create_candidate(m_next_trigger_timestamp, m_tc_timestamps.front().first); - if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( candidate.time_candidate ); m_tc_made_count++; TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() diff --git a/plugins/CustomTCMaker.hpp b/plugins/CustomTCMaker.hpp index 0b133488..e3a26dcf 100644 --- a/plugins/CustomTCMaker.hpp +++ b/plugins/CustomTCMaker.hpp @@ -121,7 +121,6 @@ class CustomTCMaker : public dunedaq::appfwk::DAQModule // Create an instance of the Latency class std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; - std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; }; } // namespace trigger diff --git a/plugins/RandomTCMakerModule.cpp b/plugins/RandomTCMakerModule.cpp index a12b0a35..ea41c70c 100644 --- a/plugins/RandomTCMakerModule.cpp +++ b/plugins/RandomTCMakerModule.cpp @@ -77,9 +77,8 @@ RandomTCMakerModule::generate_opmon_data() this->publish(std::move(info)); if ( m_latency_monitoring.load() && m_running_flag.load() ) { - opmon::TriggerLatency lat_info; + opmon::TriggerLatencyStandalone lat_info; - lat_info.set_latency_in( m_latency_instance.get_latency_in() ); lat_info.set_latency_out( m_latency_instance.get_latency_out() ); this->publish(std::move(lat_info)); @@ -224,7 +223,6 @@ RandomTCMakerModule::send_trigger_candidates() next_trigger_timestamp = m_timestamp_estimator->get_timestamp_estimate(); triggeralgs::TriggerCandidate candidate = create_candidate(next_trigger_timestamp); - if (m_latency_monitoring.load()) m_latency_instance.update_latency_in( candidate.time_candidate ); m_tc_made_count++; TLOG_DEBUG(1) << get_name() << " at timestamp " << m_timestamp_estimator->get_timestamp_estimate() diff --git a/plugins/RandomTCMakerModule.hpp b/plugins/RandomTCMakerModule.hpp index f79e43f6..5dc76987 100644 --- a/plugins/RandomTCMakerModule.hpp +++ b/plugins/RandomTCMakerModule.hpp @@ -107,7 +107,6 @@ class RandomTCMakerModule : public dunedaq::appfwk::DAQModule // Create an instance of the Latency class std::atomic m_latency_monitoring{ false }; dunedaq::trigger::Latency m_latency_instance; - std::atomic m_latency_in{ 0 }; std::atomic m_latency_out{ 0 }; }; } // namespace trigger diff --git a/schema/trigger/opmon/latency_info.proto b/schema/trigger/opmon/latency_info.proto index 7069f7b9..9e38243e 100644 --- a/schema/trigger/opmon/latency_info.proto +++ b/schema/trigger/opmon/latency_info.proto @@ -4,10 +4,17 @@ package dunedaq.trigger.opmon; // Message for latency variables // Latency represents the difference between current system (clock) time and the data time of particular (TX) data object -// Units are ms +// Units are us // Used by many trigger modules message TriggerLatency { uint32 latency_in = 1; uint32 latency_out = 2; } +// Message for latency variables +// Latency represents the difference between current system (clock) time and the data time of particular (TX) data object +// Units are us +// Special case for Standalone makers +message TriggerLatencyStandalone { + uint32 latency_out = 1; +}