Skip to content

Commit

Permalink
Merge pull request #6435 from STEllAR-GROUP/parcel_layer_tweaks
Browse files Browse the repository at this point in the history
Parcel layer tweaks
  • Loading branch information
hkaiser committed Feb 14, 2024
2 parents e4a8eb8 + c824fbd commit bd9e3cb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 59 deletions.
3 changes: 2 additions & 1 deletion libs/full/agas/include/hpx/agas/addressing_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <hpx/naming_base/address.hpp>
#include <hpx/naming_base/id_type.hpp>
#include <hpx/parcelset/parcelset_fwd.hpp>
#include <hpx/synchronization/shared_mutex.hpp>
#include <hpx/synchronization/spinlock.hpp>

#include <atomic>
Expand Down Expand Up @@ -70,7 +71,7 @@ namespace hpx { namespace agas {
using migrated_objects_table_type = std::set<naming::gid_type>;
using refcnt_requests_type = std::map<naming::gid_type, std::int64_t>;

mutable mutex_type gva_cache_mtx_;
mutable hpx::shared_mutex gva_cache_mtx_;
std::shared_ptr<gva_cache_type> gva_cache_;

mutable mutex_type migrated_objects_mtx_;
Expand Down
59 changes: 33 additions & 26 deletions libs/full/agas/src/addressing_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <hpx/runtime_local/runtime_local_fwd.hpp>
#include <hpx/serialization/serialize.hpp>
#include <hpx/serialization/vector.hpp>
#include <hpx/synchronization/shared_mutex.hpp>
#include <hpx/thread_support/assert_owns_lock.hpp>
#include <hpx/thread_support/unlock_guard.hpp>
#include <hpx/util/get_entry_as.hpp>
Expand All @@ -42,6 +43,7 @@
#include <map>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <sstream>
#include <string>
#include <system_error>
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1745,7 +1750,7 @@ namespace hpx::agas {
gva_cache_key const key(gid, count);

{
std::unique_lock<mutex_type> lock(gva_cache_mtx_);
std::unique_lock<hpx::shared_mutex> lock(gva_cache_mtx_);
if (!gva_cache_->update_if(key, g, check_for_collisions))
{
if (LAGAS_ENABLED(warning))
Expand Down Expand Up @@ -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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> lock(gva_cache_mtx_);
if (gva_cache_key idbase_key; gva_cache_->get_entry(k, idbase_key, gva))
{
std::uint64_t const id_msb =
Expand Down Expand Up @@ -1833,7 +1841,7 @@ namespace hpx::agas {
LAGAS_(warning).format(
"addressing_service::clear_cache, clearing cache");

std::lock_guard<mutex_type> lock(gva_cache_mtx_);
std::unique_lock<hpx::shared_mutex> lock(gva_cache_mtx_);

gva_cache_->clear();

Expand All @@ -1858,29 +1866,28 @@ 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)
ec = make_success_code();
return;
}

naming::gid_type gid = naming::detail::get_stripped_gid(id);
try
{
LAGAS_(warning).format("addressing_service::remove_cache_entry");

std::lock_guard<mutex_type> lock(gva_cache_mtx_);
std::unique_lock<hpx::shared_mutex> lock(gva_cache_mtx_);

gva_cache_->erase([&gid](std::pair<gva_cache_key, gva> const& p) {
return gid == p.first.get_gid();
Expand Down Expand Up @@ -1911,87 +1918,87 @@ 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> lock(gva_cache_mtx_);
return gva_cache_->size();
}

std::uint64_t addressing_service::get_cache_hits(bool reset) const
{
std::lock_guard<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> lock(gva_cache_mtx_);
return gva_cache_->get_statistics().insertions(reset);
}

///////////////////////////////////////////////////////////////////////////
std::uint64_t addressing_service::get_cache_get_entry_count(
bool reset) const
{
std::lock_guard<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> 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<mutex_type> lock(gva_cache_mtx_);
std::shared_lock<hpx::shared_mutex> lock(gva_cache_mtx_);
return gva_cache_->get_statistics().get_erase_entry_time(reset);
}

Expand Down
3 changes: 2 additions & 1 deletion libs/full/agas/src/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace hpx::parcelset {
}

template <typename PutParcel>
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<actions::base_action>&& action)
{
Expand Down Expand Up @@ -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),
Expand All @@ -151,7 +150,7 @@ namespace hpx::parcelset {
{
split_gid.then(hpx::launch::sync,
put_parcel_cont<PutParcel>{
HPX_FORWARD(PutParcel, pp), HPX_MOVE(dest),
HPX_FORWARD(PutParcel, pp), dest,
HPX_MOVE(addr), HPX_MOVE(action)});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace hpx::parcelset {
};

template <typename PutParcel>
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<actions::base_action>&& action);
} // namespace detail
Expand Down
Loading

0 comments on commit bd9e3cb

Please sign in to comment.