From 68ff2078f55022aa0bebe1b3264cc06c321c5733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:23:56 +0100 Subject: [PATCH 1/4] Make `scheduler::manual::collect_container_info ()` const --- nano/node/scheduler/manual.cpp | 2 +- nano/node/scheduler/manual.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nano/node/scheduler/manual.cpp b/nano/node/scheduler/manual.cpp index d409824559..7fc908bd32 100644 --- a/nano/node/scheduler/manual.cpp +++ b/nano/node/scheduler/manual.cpp @@ -84,7 +84,7 @@ void nano::scheduler::manual::run () } } -std::unique_ptr nano::scheduler::manual::collect_container_info (std::string const & name) +std::unique_ptr nano::scheduler::manual::collect_container_info (std::string const & name) const { nano::unique_lock lock{ mutex }; diff --git a/nano/node/scheduler/manual.hpp b/nano/node/scheduler/manual.hpp index 3edfa1dc75..f29f42d2b2 100644 --- a/nano/node/scheduler/manual.hpp +++ b/nano/node/scheduler/manual.hpp @@ -22,7 +22,7 @@ class manual final { std::deque, boost::optional, nano::election_behavior>> queue; nano::node & node; - nano::mutex mutex; + mutable nano::mutex mutex; nano::condition_variable condition; bool stopped{ false }; std::thread thread; @@ -41,6 +41,6 @@ class manual final // Call action with confirmed block, may be different than what we started with void push (std::shared_ptr const &, boost::optional const & = boost::none, nano::election_behavior = nano::election_behavior::normal); - std::unique_ptr collect_container_info (std::string const & name); + std::unique_ptr collect_container_info (std::string const & name) const; }; // class manual } // nano::scheduler From 5ca4a71bb9521b99b8b1fba7c0f69faa13209685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:24:15 +0100 Subject: [PATCH 2/4] Add optimistic scheduler container info --- nano/node/scheduler/optimistic.cpp | 10 ++++++++++ nano/node/scheduler/optimistic.hpp | 2 ++ 2 files changed, 12 insertions(+) diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index b47ddb9fdf..bd5247957f 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -130,6 +130,7 @@ void nano::scheduler::optimistic::run () debug_assert (!candidates.empty ()); auto candidate = candidates.front (); candidates.pop_front (); + lock.unlock (); run_one (transaction, candidate); @@ -161,6 +162,15 @@ void nano::scheduler::optimistic::run_one (store::transaction const & transactio } } +std::unique_ptr nano::scheduler::optimistic::collect_container_info (const std::string & name) const +{ + nano::lock_guard guard{ mutex }; + + auto composite = std::make_unique (name); + composite->add_component (std::make_unique (container_info{ "candidates", candidates.size (), sizeof (decltype (candidates)::value_type) })); + return composite; +} + /* * optimistic_scheduler_config */ diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index 627b74d621..c590c8f17d 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -66,6 +66,8 @@ class optimistic final */ void notify (); + std::unique_ptr collect_container_info (std::string const & name) const; + private: bool activate_predicate (nano::account_info const &, nano::confirmation_height_info const &) const; From be27552fb1d5a9ff336fc9bfb06b3562344d843a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:24:27 +0100 Subject: [PATCH 3/4] Add hinted scheduler container info --- nano/node/scheduler/hinted.cpp | 15 +++++++++++++++ nano/node/scheduler/hinted.hpp | 2 ++ 2 files changed, 17 insertions(+) diff --git a/nano/node/scheduler/hinted.cpp b/nano/node/scheduler/hinted.cpp index 54f5bdf7b8..d6d7521ff1 100644 --- a/nano/node/scheduler/hinted.cpp +++ b/nano/node/scheduler/hinted.cpp @@ -163,10 +163,14 @@ void nano::scheduler::hinted::run () if (!stopped) { + lock.unlock (); + if (predicate ()) { run_iterative (); } + + lock.lock (); } } } @@ -185,6 +189,8 @@ nano::uint128_t nano::scheduler::hinted::final_tally_threshold () const bool nano::scheduler::hinted::cooldown (const nano::block_hash & hash) { + nano::lock_guard guard{ mutex }; + auto const now = std::chrono::steady_clock::now (); // Check if the hash is still in the cooldown period using the hashed index @@ -211,6 +217,15 @@ bool nano::scheduler::hinted::cooldown (const nano::block_hash & hash) return false; // No need to cooldown } +std::unique_ptr nano::scheduler::hinted::collect_container_info (const std::string & name) const +{ + nano::lock_guard guard{ mutex }; + + auto composite = std::make_unique (name); + composite->add_component (std::make_unique (container_info{ "cooldowns", cooldowns_m.size (), sizeof (decltype (cooldowns_m)::value_type) })); + return composite; +} + /* * hinted_config */ diff --git a/nano/node/scheduler/hinted.hpp b/nano/node/scheduler/hinted.hpp index 590697c39f..feca940da5 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -58,6 +58,8 @@ class hinted final */ void notify (); + std::unique_ptr collect_container_info (std::string const & name) const; + private: bool predicate () const; void run (); From b54aef1bf1b539aa259d487945fc7e4aa4ae56d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:24:54 +0100 Subject: [PATCH 4/4] Collect container info from all schedulers --- nano/node/scheduler/component.cpp | 6 ++---- nano/node/scheduler/component.hpp | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index 2108c683bb..0d44042448 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -39,12 +39,10 @@ void nano::scheduler::component::stop () std::unique_ptr nano::scheduler::component::collect_container_info (std::string const & name) { - nano::unique_lock lock{ mutex }; - auto composite = std::make_unique (name); - //composite->add_component (hinted.collect_container_info ("hinted")); + composite->add_component (hinted.collect_container_info ("hinted")); composite->add_component (manual.collect_container_info ("manual")); - //composite->add_component (optimistic.collect_container_info ("optimistic")); + composite->add_component (optimistic.collect_container_info ("optimistic")); composite->add_component (priority.collect_container_info ("priority")); return composite; } diff --git a/nano/node/scheduler/component.hpp b/nano/node/scheduler/component.hpp index 257902438a..41a3f2b153 100644 --- a/nano/node/scheduler/component.hpp +++ b/nano/node/scheduler/component.hpp @@ -23,7 +23,6 @@ class component final std::unique_ptr manual_impl; std::unique_ptr optimistic_impl; std::unique_ptr priority_impl; - nano::mutex mutex; public: explicit component (nano::node & node);