diff --git a/libs/full/agas/include/hpx/agas/addressing_service.hpp b/libs/full/agas/include/hpx/agas/addressing_service.hpp index 72013cad7a1d..4c445f13a603 100644 --- a/libs/full/agas/include/hpx/agas/addressing_service.hpp +++ b/libs/full/agas/include/hpx/agas/addressing_service.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -70,7 +71,7 @@ namespace hpx { namespace agas { using migrated_objects_table_type = std::set; using refcnt_requests_type = std::map; - mutable mutex_type gva_cache_mtx_; + mutable hpx::shared_mutex gva_cache_mtx_; std::shared_ptr gva_cache_; mutable mutex_type migrated_objects_mtx_; diff --git a/libs/full/agas/src/addressing_service.cpp b/libs/full/agas/src/addressing_service.cpp index e1de0a50e05a..98cd0342deec 100644 --- a/libs/full/agas/src/addressing_service.cpp +++ b/libs/full/agas/src/addressing_service.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -840,7 +842,9 @@ namespace hpx::agas { { // NOTE: This should still be migration safe. return naming::detail::strip_internal_bits_and_component_type_from_gid( - msb) == get_local_locality().get_msb(); + msb) == + naming::detail::strip_internal_bits_and_component_type_from_gid( + get_local_locality().get_msb()); } bool addressing_service::resolve_locally_known_addresses( @@ -1017,7 +1021,7 @@ namespace hpx::agas { } // don't look at cache if id is marked as non-cache-able - if (!naming::detail::store_in_cache(id)) + if (!naming::detail::store_in_cache(id) || naming::is_locality(id)) { if (&ec != &throws) ec = make_success_code(); @@ -1129,7 +1133,7 @@ namespace hpx::agas { } // Resolve the gva to the real resolved address (which is just a gva - // with as fully resolved LVA and and offset of zero). + // with as fully resolved LVA and offset of zero). naming::gid_type const base_gid = hpx::get<0>(rep); gva const base_gva = hpx::get<1>(rep); @@ -1218,8 +1222,9 @@ namespace hpx::agas { if (get<0>(rep) == naming::invalid_gid || get<2>(rep) == naming::invalid_gid) return false; + // Resolve the gva to the real resolved address (which is - // just a gva with as fully resolved LVA and and offset of + // just a gva with as fully resolved LVA and offset of // zero). naming::gid_type base_gid = get<0>(rep); gva const base_gva = get<1>(rep); @@ -1693,7 +1698,7 @@ namespace hpx::agas { } // don't look at cache if id is marked as non-cache-able - if (!naming::detail::store_in_cache(id)) + if (!naming::detail::store_in_cache(id) || naming::is_locality(id)) { if (&ec != &throws) ec = make_success_code(); @@ -1745,7 +1750,7 @@ namespace hpx::agas { gva_cache_key const key(gid, count); { - std::unique_lock lock(gva_cache_mtx_); + std::unique_lock lock(gva_cache_mtx_); if (!gva_cache_->update_if(key, g, check_for_collisions)) { if (LAGAS_ENABLED(warning)) @@ -1793,9 +1798,12 @@ namespace hpx::agas { return false; } + // don't look at cache if gid is marked as non-cache-able + HPX_ASSERT(naming::detail::store_in_cache(gid)); + gva_cache_key const k(gid); - std::unique_lock lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); if (gva_cache_key idbase_key; gva_cache_->get_entry(k, idbase_key, gva)) { std::uint64_t const id_msb = @@ -1833,7 +1841,7 @@ namespace hpx::agas { LAGAS_(warning).format( "addressing_service::clear_cache, clearing cache"); - std::lock_guard lock(gva_cache_mtx_); + std::unique_lock lock(gva_cache_mtx_); gva_cache_->clear(); @@ -1858,17 +1866,15 @@ namespace hpx::agas { } // don't look at cache if id is marked as non-cache-able - if (!naming::detail::store_in_cache(id)) + if (!naming::detail::store_in_cache(id) || naming::is_locality(id)) { if (&ec != &throws) ec = make_success_code(); return; } - naming::gid_type gid = naming::detail::get_stripped_gid(id); - // don't look at the cache if the id is locally managed - if (naming::get_locality_id_from_gid(gid) == + if (naming::get_locality_id_from_gid(id) == naming::get_locality_id_from_gid(locality_)) { if (&ec != &throws) @@ -1876,11 +1882,12 @@ namespace hpx::agas { return; } + naming::gid_type gid = naming::detail::get_stripped_gid(id); try { LAGAS_(warning).format("addressing_service::remove_cache_entry"); - std::lock_guard lock(gva_cache_mtx_); + std::unique_lock lock(gva_cache_mtx_); gva_cache_->erase([&gid](std::pair const& p) { return gid == p.first.get_gid(); @@ -1911,31 +1918,31 @@ namespace hpx::agas { // Helper functions to access the current cache statistics std::uint64_t addressing_service::get_cache_entries(bool /* reset */) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->size(); } std::uint64_t addressing_service::get_cache_hits(bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().hits(reset); } std::uint64_t addressing_service::get_cache_misses(bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().misses(reset); } std::uint64_t addressing_service::get_cache_evictions(bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().evictions(reset); } std::uint64_t addressing_service::get_cache_insertions(bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().insertions(reset); } @@ -1943,55 +1950,55 @@ namespace hpx::agas { std::uint64_t addressing_service::get_cache_get_entry_count( bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_get_entry_count(reset); } std::uint64_t addressing_service::get_cache_insertion_entry_count( bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_insert_entry_count(reset); } std::uint64_t addressing_service::get_cache_update_entry_count( bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_update_entry_count(reset); } std::uint64_t addressing_service::get_cache_erase_entry_count( bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_erase_entry_count(reset); } std::uint64_t addressing_service::get_cache_get_entry_time(bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_get_entry_time(reset); } std::uint64_t addressing_service::get_cache_insertion_entry_time( bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_insert_entry_time(reset); } std::uint64_t addressing_service::get_cache_update_entry_time( bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_update_entry_time(reset); } std::uint64_t addressing_service::get_cache_erase_entry_time( bool reset) const { - std::lock_guard lock(gva_cache_mtx_); + std::shared_lock lock(gva_cache_mtx_); return gva_cache_->get_statistics().get_erase_entry_time(reset); } diff --git a/libs/full/agas/src/route.cpp b/libs/full/agas/src/route.cpp index a9e237b7fab6..8c1eafeba9a2 100644 --- a/libs/full/agas/src/route.cpp +++ b/libs/full/agas/src/route.cpp @@ -77,7 +77,8 @@ namespace hpx::agas::server { } // retain don't store in cache flag - if (!naming::detail::store_in_cache(gid)) + if (!naming::detail::store_in_cache(gid) && + !naming::is_locality(gid)) { naming::detail::set_dont_store_in_cache( hpx::get<0>(cache_address)); diff --git a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp index 449979cd5fb3..f770e7135a3a 100644 --- a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp +++ b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp @@ -99,7 +99,7 @@ namespace hpx::parcelset { } template - void put_parcel_impl(PutParcel&& pp, hpx::id_type dest, + void put_parcel_impl(PutParcel&& pp, hpx::id_type const& dest, naming::address&& addr, std::unique_ptr&& action) { @@ -128,10 +128,9 @@ namespace hpx::parcelset { } else { - auto result = - naming::detail::split_gid_if_needed(dest.get_gid()); - - if (result.has_value()) + if (auto result = + naming::detail::split_gid_if_needed(dest.get_gid()); + result.has_value()) { pp(detail::create_parcel::call_with_action( HPX_MOVE(result).get_value(), HPX_MOVE(addr), @@ -151,7 +150,7 @@ namespace hpx::parcelset { { split_gid.then(hpx::launch::sync, put_parcel_cont{ - HPX_FORWARD(PutParcel, pp), HPX_MOVE(dest), + HPX_FORWARD(PutParcel, pp), dest, HPX_MOVE(addr), HPX_MOVE(action)}); } } diff --git a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel_fwd.hpp b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel_fwd.hpp index 56d5391243a6..5b61d1205015 100644 --- a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel_fwd.hpp +++ b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel_fwd.hpp @@ -47,7 +47,7 @@ namespace hpx::parcelset { }; template - void put_parcel_impl(PutParcel&& pp, hpx::id_type dest, + void put_parcel_impl(PutParcel&& pp, hpx::id_type const& dest, naming::address&& addr, std::unique_ptr&& action); } // namespace detail diff --git a/libs/full/naming_base/include/hpx/naming_base/gid_type.hpp b/libs/full/naming_base/include/hpx/naming_base/gid_type.hpp index 2be7c5c82f2f..5e49da7d36e2 100644 --- a/libs/full/naming_base/include/hpx/naming_base/gid_type.hpp +++ b/libs/full/naming_base/include/hpx/naming_base/gid_type.hpp @@ -371,19 +371,34 @@ HPX_IS_BITWISE_SERIALIZABLE(hpx::naming::gid_type) namespace hpx::naming { + namespace detail { + + /////////////////////////////////////////////////////////////////////// + constexpr bool store_in_cache(gid_type const& id) noexcept + { + return (id.get_msb() & gid_type::dont_cache_mask) ? false : true; + } + + constexpr void set_dont_store_in_cache(gid_type& gid) noexcept + { + gid.set_msb(gid.get_msb() | gid_type::dont_cache_mask); + } + } // namespace detail + /////////////////////////////////////////////////////////////////////////// // Handle conversion to/from locality_id constexpr gid_type get_gid_from_locality_id( std::uint32_t locality_id) noexcept { - return gid_type( - (std::uint64_t(locality_id) + 1) << gid_type::locality_id_shift, - std::uint64_t(0)); + return gid_type((static_cast(locality_id) + 1) + << gid_type::locality_id_shift, + static_cast(0)); } constexpr std::uint32_t get_locality_id_from_gid(std::uint64_t msb) noexcept { - return std::uint32_t(msb >> gid_type::locality_id_shift) - 1; + return static_cast(msb >> gid_type::locality_id_shift) - + 1; } constexpr std::uint32_t get_locality_id_from_gid( @@ -440,7 +455,8 @@ namespace hpx::naming { std::uint64_t msb = gid.get_msb() & ~gid_type::component_type_mask; HPX_ASSERT(!(msb & gid_type::dynamically_assigned)); - msb |= ((std::uint64_t(type) << gid_type::component_type_shift) & + msb |= ((static_cast(type) + << gid_type::component_type_shift) & gid_type::component_type_mask); return gid_type(msb, gid.get_lsb()); } @@ -505,7 +521,7 @@ namespace hpx::naming { } /////////////////////////////////////////////////////////////////////// - inline constexpr std::uint32_t get_component_type_from_gid( + constexpr std::uint32_t get_component_type_from_gid( std::uint64_t msb) noexcept { HPX_ASSERT(!(msb & gid_type::dynamically_assigned)); @@ -513,12 +529,13 @@ namespace hpx::naming { gid_type::component_type_base_mask; } - inline constexpr std::uint64_t add_component_type_to_gid( + constexpr std::uint64_t add_component_type_to_gid( std::uint64_t msb, std::uint32_t type) noexcept { HPX_ASSERT(!(msb & gid_type::dynamically_assigned)); return (msb & ~gid_type::component_type_mask) | - ((std::uint64_t(type) << gid_type::component_type_shift) & + ((static_cast(type) + << gid_type::component_type_shift) & gid_type::component_type_mask); } @@ -582,17 +599,6 @@ namespace hpx::naming { return static_cast(1) << log2credits; } - /////////////////////////////////////////////////////////////////////// - constexpr bool store_in_cache(gid_type const& id) noexcept - { - return (id.get_msb() & gid_type::dont_cache_mask) ? false : true; - } - - constexpr void set_dont_store_in_cache(gid_type& gid) noexcept - { - gid.set_msb(gid.get_msb() | gid_type::dont_cache_mask); - } - /////////////////////////////////////////////////////////////////////// constexpr bool is_migratable(gid_type const& id) noexcept { @@ -631,7 +637,8 @@ namespace hpx::naming { gid_type const& gid) noexcept { HPX_ASSERT(has_credits(gid)); - return std::int16_t((gid.get_msb() >> gid_type::credit_shift) & + return static_cast( + (gid.get_msb() >> gid_type::credit_shift) & gid_type::credit_base_mask); } @@ -651,7 +658,8 @@ namespace hpx::naming { HPX_ASSERT(0 == (log2credits & ~gid_type::credit_base_mask)); id.set_msb((id.get_msb() & ~gid_type::credit_mask) | - ((std::int64_t(log2credits) << gid_type::credit_shift) & + ((static_cast(log2credits) + << gid_type::credit_shift) & gid_type::credit_mask) | gid_type::has_credits_mask); } diff --git a/libs/full/naming_base/include/hpx/naming_base/id_type.hpp b/libs/full/naming_base/include/hpx/naming_base/id_type.hpp index cfeef69c6d83..cb55c2953e8f 100644 --- a/libs/full/naming_base/include/hpx/naming_base/id_type.hpp +++ b/libs/full/naming_base/include/hpx/naming_base/id_type.hpp @@ -101,7 +101,7 @@ namespace hpx { ~id_type() = default; naming::gid_type& get_gid(); - naming::gid_type const& get_gid() const; + naming::gid_type& get_gid() const; // This function is used in AGAS unit tests and application code, do not // remove. @@ -195,7 +195,7 @@ namespace hpx { namespace naming::detail { /////////////////////////////////////////////////////////////////////// - inline void set_dont_store_in_cache(id_type& id) noexcept + inline void set_dont_store_in_cache(id_type const& id) noexcept { id.set_msb(id.get_msb() | gid_type::dont_cache_mask); } @@ -344,7 +344,7 @@ namespace hpx { { return *gid_; } - inline naming::gid_type const& id_type::get_gid() const + inline naming::gid_type& id_type::get_gid() const { return *gid_; }