From 090d9cbbfdbdcb316a0f68f95b7cdaf01bb1d384 Mon Sep 17 00:00:00 2001 From: Jonathan Lifflander Date: Mon, 19 Sep 2022 21:52:46 -0700 Subject: [PATCH] #1969: scheduler: reduce calls to get the current time --- src/vt/runtime/component/component_pack.cc | 8 +++++ src/vt/runtime/component/component_pack.h | 7 +++++ src/vt/runtime/component/progressable.h | 7 +++++ src/vt/runtime/runtime.h | 7 +++++ src/vt/scheduler/scheduler.cc | 34 ++++++++++++++-------- src/vt/scheduler/scheduler.h | 3 ++ src/vt/timetrigger/time_trigger_manager.cc | 4 +++ src/vt/timetrigger/time_trigger_manager.h | 2 ++ 8 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/vt/runtime/component/component_pack.cc b/src/vt/runtime/component/component_pack.cc index ecbc3ce66f..e283b623f0 100644 --- a/src/vt/runtime/component/component_pack.cc +++ b/src/vt/runtime/component/component_pack.cc @@ -110,6 +110,14 @@ int ComponentPack::progress(TimeType current_time) { return total; } +bool ComponentPack::needsCurrentTime() { + bool needs_time = false; + for (auto&& pollable : pollable_components_) { + needs_time = needs_time || pollable->needsCurrentTime(); + } + return needs_time; +} + std::list ComponentPack::topoSort() { std::list order; diff --git a/src/vt/runtime/component/component_pack.h b/src/vt/runtime/component/component_pack.h index 6c010a12c3..a455833810 100644 --- a/src/vt/runtime/component/component_pack.h +++ b/src/vt/runtime/component/component_pack.h @@ -116,6 +116,13 @@ struct ComponentPack { */ int progress(TimeType current_time); + /** + * \internal \brief Needs current time + * + * \return whether any component needs the current time on the progress call + */ + bool needsCurrentTime(); + /** * \internal \brief Extract the first component from a running pack that * matches \c name. diff --git a/src/vt/runtime/component/progressable.h b/src/vt/runtime/component/progressable.h index 66028d287b..0c345cf2c0 100644 --- a/src/vt/runtime/component/progressable.h +++ b/src/vt/runtime/component/progressable.h @@ -62,6 +62,13 @@ struct Progressable { * \return the number of units executed---zero if no progress was made */ virtual int progress(TimeType current_time) = 0; + + /** + * \brief Whether the component needs the current time + * + * \return whether it needs time + */ + virtual bool needsCurrentTime() { return false; } }; }}} /* end namespace vt::runtime::component */ diff --git a/src/vt/runtime/runtime.h b/src/vt/runtime/runtime.h index b2a4c8d2c5..26b0a38f9c 100644 --- a/src/vt/runtime/runtime.h +++ b/src/vt/runtime/runtime.h @@ -129,6 +129,13 @@ struct Runtime { */ int progress(TimeType current_time) { if (p_) return p_->progress(current_time); else return 0; } + /** + * \brief Check if any pollable components needs the current time + * + * \return whether it needs the current time + */ + bool needsCurrentTime() { if (p_) return p_->needsCurrentTime(); else return false; } + /** * \brief Check if runtime has terminated * diff --git a/src/vt/scheduler/scheduler.cc b/src/vt/scheduler/scheduler.cc index ced76058a2..58890baeda 100644 --- a/src/vt/scheduler/scheduler.cc +++ b/src/vt/scheduler/scheduler.cc @@ -109,6 +109,11 @@ Scheduler::Scheduler() # endif } +void Scheduler::startup() { + special_progress_ = + theConfig()->vt_sched_progress_han != 0 or progress_time_enabled_; +} + void Scheduler::preDiagnostic() { vtLiveTime.stop(); } @@ -236,23 +241,28 @@ void Scheduler::runProgress(bool msg_only, TimeType current_time) { printMemoryUsage(); } - // Reset count of processed handlers since the last time progress was invoked - processed_after_last_progress_ = 0; - last_progress_time_ = timing::getCurrentTime(); - + if (special_progress_) { + // Reset count of processed handlers since the last time progress was invoked + processed_after_last_progress_ = 0; + last_progress_time_ = timing::getCurrentTime(); + } } void Scheduler::runSchedulerOnceImpl(bool msg_only) { - auto current_time = timing::getCurrentTime(); - auto time_since_last_progress = current_time - last_progress_time_; - if ( - work_queue_.empty() or - shouldCallProgress(processed_after_last_progress_, time_since_last_progress) - ) { - runProgress(msg_only, current_time); + if (special_progress_) { + auto current_time = timing::getCurrentTime(); + auto time_since_last_progress = current_time - last_progress_time_; + if (shouldCallProgress(processed_after_last_progress_, time_since_last_progress)) { + runProgress(msg_only, current_time); + } + } else if (work_queue_.empty()) { + if (curRT->needsCurrentTime()) { + runProgress(msg_only, timing::getCurrentTime()); + } else { + runProgress(msg_only, TimeType{0}); + } } - if (not work_queue_.empty()) { queueSizeGauge.update(work_queue_.size()); diff --git a/src/vt/scheduler/scheduler.h b/src/vt/scheduler/scheduler.h index 45e4fde9c8..4cc2e96d95 100644 --- a/src/vt/scheduler/scheduler.h +++ b/src/vt/scheduler/scheduler.h @@ -135,6 +135,7 @@ struct Scheduler : runtime::component::Component { std::string name() override { return "Scheduler"; } void preDiagnostic() override; + void startup() override; /** * \internal \brief Check for termination when running on a single node @@ -423,6 +424,8 @@ struct Scheduler : runtime::component::Component { std::size_t threshold_memory_usage_ = 0; std::size_t last_memory_usage_poll_ = 0; + bool special_progress_ = false; /**< time-based/k-handler progress enabled */ + // Access to triggerEvent. template friend void vt::runInEpochRooted(Callable&& fn); diff --git a/src/vt/timetrigger/time_trigger_manager.cc b/src/vt/timetrigger/time_trigger_manager.cc index 4bcab00187..a661a3d86d 100644 --- a/src/vt/timetrigger/time_trigger_manager.cc +++ b/src/vt/timetrigger/time_trigger_manager.cc @@ -92,4 +92,8 @@ int TimeTriggerManager::progress(TimeType current_time) { return 0; } +bool TimeTriggerManager::needsCurrentTime() { + return queue_.size() != 0; +} + }} /* end namespace vt::timetrigger */ diff --git a/src/vt/timetrigger/time_trigger_manager.h b/src/vt/timetrigger/time_trigger_manager.h index 0e55038672..8da2cb2d5d 100644 --- a/src/vt/timetrigger/time_trigger_manager.h +++ b/src/vt/timetrigger/time_trigger_manager.h @@ -75,6 +75,8 @@ struct TimeTriggerManager int progress(TimeType current_time) override; + bool needsCurrentTime() override; + /** * \brief Register a time-based trigger with a specific period *