Skip to content

Commit

Permalink
Making sure locality ids are never cached in AGAS cache
Browse files Browse the repository at this point in the history
-flyby: optimize a unnecessary copy of an id_type
  • Loading branch information
hkaiser committed Feb 5, 2024
1 parent 9c53b99 commit 7077d00
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
3 changes: 3 additions & 0 deletions libs/full/agas/src/addressing_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,9 @@ 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_);
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
51 changes: 30 additions & 21 deletions libs/full/naming_base/include/hpx/naming_base/gid_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,35 @@ 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<std::uint64_t>(locality_id) + 1)
<< gid_type::locality_id_shift) |
gid_type::dont_cache_mask,
static_cast<std::uint64_t>(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<std::uint32_t>(msb >> gid_type::locality_id_shift) -
1;
}

constexpr std::uint32_t get_locality_id_from_gid(
Expand Down Expand Up @@ -440,7 +456,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<std::uint64_t>(type)
<< gid_type::component_type_shift) &
gid_type::component_type_mask);
return gid_type(msb, gid.get_lsb());
}
Expand Down Expand Up @@ -505,20 +522,21 @@ 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));
return (msb >> gid_type::component_type_shift) &
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<std::uint64_t>(type)
<< gid_type::component_type_shift) &
gid_type::component_type_mask);
}

Expand Down Expand Up @@ -582,17 +600,6 @@ namespace hpx::naming {
return static_cast<std::int64_t>(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
{
Expand Down Expand Up @@ -631,7 +638,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<std::int16_t>(
(gid.get_msb() >> gid_type::credit_shift) &
gid_type::credit_base_mask);
}

Expand All @@ -651,7 +659,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<std::int64_t>(log2credits)
<< gid_type::credit_shift) &
gid_type::credit_mask) |
gid_type::has_credits_mask);
}
Expand Down
6 changes: 3 additions & 3 deletions libs/full/naming_base/include/hpx/naming_base/id_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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_;
}
Expand Down

0 comments on commit 7077d00

Please sign in to comment.