Skip to content

Commit

Permalink
Fixing stacksize control for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Nov 27, 2023
1 parent c8a2223 commit 0053860
Show file tree
Hide file tree
Showing 28 changed files with 800 additions and 694 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <hpx/config/compiler_specific.hpp>

#if defined(HPX_WINDOWS)
//#define HPX_HAVE_THREADS_GET_STACK_POINTER
#define HPX_HAVE_THREADS_GET_STACK_POINTER
#else
#if defined(HPX_GCC_VERSION)
#define HPX_HAVE_THREADS_GET_STACK_POINTER
Expand Down
10 changes: 6 additions & 4 deletions libs/full/actions/include/hpx/actions/actions_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#pragma once

#include <hpx/config.hpp>

#if defined(HPX_HAVE_NETWORKING)
#include <hpx/actions_base/actions_base_fwd.hpp>

namespace hpx { namespace actions {
namespace hpx::actions {

/// \cond NOINTERNAL

#if defined(HPX_HAVE_NETWORKING)
struct base_action;
struct HPX_EXPORT base_action_data;

Expand All @@ -23,6 +24,7 @@ namespace hpx { namespace actions {

template <typename Action>
struct transfer_continuation_action;
#endif
/// \endcond
}} // namespace hpx::actions
} // namespace hpx::actions

#endif
11 changes: 6 additions & 5 deletions libs/full/actions/include/hpx/actions/base_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

#include <cstddef>
#include <cstdint>
#include <memory>
#include <type_traits>
#include <utility>

#include <hpx/config/warnings_prefix.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace actions {
namespace hpx::actions {

///////////////////////////////////////////////////////////////////////////
// The \a base_action class is an abstract class used as the base class
// for all action types. It's main purpose is to allow polymorphic
Expand Down Expand Up @@ -180,19 +180,20 @@ namespace hpx { namespace actions {
std::uint64_t parent_phase_ = 0;
#endif
};
}} // namespace hpx::actions
} // namespace hpx::actions

///////////////////////////////////////////////////////////////////////////////
// serialization support for basic_action
namespace hpx { namespace serialization {
namespace hpx::serialization {

template <typename Archive, typename Component, typename R,
typename... Args, typename Derived>
HPX_FORCEINLINE void serialize(Archive& /* ar */,
::hpx::actions::basic_action<Component, R(Args...), Derived>& /* t */,
unsigned int const /* version */ = 0)
{
}
}} // namespace hpx::serialization
} // namespace hpx::serialization

#include <hpx/config/warnings_suffix.hpp>

Expand Down
3 changes: 1 addition & 2 deletions libs/full/actions/include/hpx/actions/invoke_function.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2021 Hartmut Kaiser
// Copyright (c) 2015-2023 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -10,7 +10,6 @@
#include <hpx/actions_base/basic_action.hpp>
#include <hpx/functional/invoke_result.hpp>

#include <cstddef>
#include <utility>

namespace hpx::components::server {
Expand Down
81 changes: 17 additions & 64 deletions libs/full/actions/include/hpx/actions/post_helper.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// SPDX-License-Identifier: BSL-1.0
Expand All @@ -12,10 +12,8 @@
#include <hpx/actions_base/actions_base_support.hpp>
#include <hpx/actions_base/traits/action_continuation.hpp>
#include <hpx/actions_base/traits/action_decorate_continuation.hpp>
#include <hpx/actions_base/traits/action_priority.hpp>
#include <hpx/actions_base/traits/action_schedule_thread.hpp>
#include <hpx/actions_base/traits/action_select_direct_execution.hpp>
#include <hpx/actions_base/traits/action_stacksize.hpp>
#include <hpx/async_base/launch_policy.hpp>
#include <hpx/coroutines/thread_enums.hpp>
#include <hpx/naming_base/address.hpp>
Expand All @@ -24,32 +22,16 @@

#include <chrono>
#include <exception>
#include <memory>
#include <thread>
#include <utility>

namespace hpx {

bool HPX_EXPORT is_pre_startup();
}

namespace hpx::detail {

///////////////////////////////////////////////////////////////////////
template <typename Action>
inline threads::thread_priority fix_priority(
threads::thread_priority priority)
{
return hpx::actions::detail::thread_priority<
traits::action_priority_v<Action>>::call(priority);
}

///////////////////////////////////////////////////////////////////////////
template <typename Action, typename... Ts>
void call_async(threads::thread_init_data&& data,
hpx::id_type const& target, naming::address::address_type lva,
naming::address::component_type comptype,
threads::thread_priority priority, Ts&&... vs)
naming::address::component_type comptype, Ts&&... vs)
{
using continuation_type = traits::action_continuation_t<Action>;

Expand All @@ -65,18 +47,6 @@ namespace hpx::detail {
target, lva, comptype, HPX_FORWARD(Ts, vs)...);
}

#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#if HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
data.description = threads::thread_description(
actions::detail::get_action_name<Action>(),
actions::detail::get_action_name_itt<Action>());
#else
data.description = actions::detail::get_action_name<Action>();
#endif
#endif
data.priority = fix_priority<Action>(priority);
data.stacksize = traits::action_stacksize_v<Action>;

while (!threads::threadmanager_is_at_least(hpx::state::running))
{
std::this_thread::sleep_for(
Expand All @@ -89,8 +59,7 @@ namespace hpx::detail {
template <typename Action, typename Continuation, typename... Ts>
void call_async(threads::thread_init_data&& data, Continuation&& cont,
hpx::id_type const& target, naming::address::address_type lva,
naming::address::component_type comptype,
threads::thread_priority priority, Ts&&... vs)
naming::address::component_type comptype, Ts&&... vs)
{
// first decorate the continuation
traits::action_decorate_continuation<Action>::call(cont);
Expand All @@ -100,18 +69,6 @@ namespace hpx::detail {
HPX_FORWARD(Continuation, cont), lva, comptype,
HPX_FORWARD(Ts, vs)...);

#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#if HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
data.description = threads::thread_description(
actions::detail::get_action_name<Action>(),
actions::detail::get_action_name_itt<Action>());
#else
data.description = actions::detail::get_action_name<Action>();
#endif
#endif
data.priority = fix_priority<Action>(priority);
data.stacksize = traits::action_stacksize_v<Action>;

while (!threads::threadmanager_is_at_least(hpx::state::running))
{
std::this_thread::sleep_for(
Expand Down Expand Up @@ -153,18 +110,17 @@ namespace hpx::detail {
template <typename... Ts>
static void call(threads::thread_init_data&& data,
hpx::id_type const& target, naming::address::address_type lva,
naming::address::component_type comptype,
threads::thread_priority priority, Ts&&... vs)
naming::address::component_type comptype, Ts&&... vs)
{
// route launch policy through component
launch policy =
launch const policy =
traits::action_select_direct_execution<Action>::call(
launch::async, lva);

if (policy == launch::async)
{
call_async<Action>(HPX_MOVE(data), target, lva, comptype,
priority, HPX_FORWARD(Ts, vs)...);
HPX_FORWARD(Ts, vs)...);
}
else
{
Expand All @@ -175,19 +131,18 @@ namespace hpx::detail {
template <typename Continuation, typename... Ts>
static void call(threads::thread_init_data&& data, Continuation&& cont,
hpx::id_type const& target, naming::address::address_type lva,
naming::address::component_type comptype,
threads::thread_priority priority, Ts&&... vs)
naming::address::component_type comptype, Ts&&... vs)
{
// route launch policy through component
launch policy =
launch const policy =
traits::action_select_direct_execution<Action>::call(
launch::async, lva);

if (policy == launch::async)
{
call_async<Action>(HPX_MOVE(data),
HPX_FORWARD(Continuation, cont), target, lva, comptype,
priority, HPX_FORWARD(Ts, vs)...);
HPX_FORWARD(Ts, vs)...);
}
else
{
Expand All @@ -205,11 +160,10 @@ namespace hpx::detail {
template <typename... Ts>
HPX_FORCEINLINE static void call(threads::thread_init_data&& data,
hpx::id_type const& target, naming::address::address_type lva,
naming::address::component_type comptype,
threads::thread_priority priority, Ts&&... vs)
naming::address::component_type comptype, Ts&&... vs)
{
// Direct actions should be able to be executed from a
// non-HPX thread as well
// Direct actions should be able to be executed from a non-HPX
// thread as well
if (this_thread::has_sufficient_stack_space() ||
!threads::threadmanager_is_at_least(hpx::state::running))
{
Expand All @@ -218,19 +172,18 @@ namespace hpx::detail {
else
{
call_async<Action>(HPX_MOVE(data), target, lva, comptype,
priority, HPX_FORWARD(Ts, vs)...);
HPX_FORWARD(Ts, vs)...);
}
}

template <typename Continuation, typename... Ts>
HPX_FORCEINLINE static void call(threads::thread_init_data&& data,
Continuation&& cont, hpx::id_type const& target,
naming::address::address_type lva,
naming::address::component_type comptype,
threads::thread_priority priority, Ts&&... vs)
naming::address::component_type comptype, Ts&&... vs)
{
// Direct actions should be able to be executed from a
// non-HPX thread as well
// Direct actions should be able to be executed from a non-HPX
// thread as well
if (this_thread::has_sufficient_stack_space() ||
!threads::threadmanager_is_at_least(hpx::state::running))
{
Expand All @@ -241,7 +194,7 @@ namespace hpx::detail {
{
call_async<Action>(HPX_MOVE(data),
HPX_FORWARD(Continuation, cont), target, lva, comptype,
priority, HPX_FORWARD(Ts, vs)...);
HPX_FORWARD(Ts, vs)...);
}
}
};
Expand Down
5 changes: 3 additions & 2 deletions libs/full/actions/include/hpx/actions/post_helper_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <hpx/naming_base/address.hpp>
#include <hpx/threading_base/thread_init_data.hpp>

namespace hpx { namespace detail {
namespace hpx::detail {

///////////////////////////////////////////////////////////////////////////
template <typename Action, typename... Ts>
Expand Down Expand Up @@ -40,4 +40,5 @@ namespace hpx { namespace detail {
template <typename Action,
bool DirectExecute = Action::direct_execution::value>
struct post_helper;
}} // namespace hpx::detail
} // namespace hpx::detail

27 changes: 19 additions & 8 deletions libs/full/actions/include/hpx/actions/transfer_action.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
// Copyright (c) 2011 Thomas Heller
//
Expand All @@ -18,6 +18,7 @@
#include <hpx/actions_base/actions_base_support.hpp>

#if defined(HPX_HAVE_NETWORKING)
#include <hpx/async_base/launch_policy.hpp>
#include <hpx/datastructures/serialization/tuple.hpp>
#include <hpx/serialization/input_archive.hpp>
#include <hpx/serialization/output_archive.hpp>
Expand All @@ -39,7 +40,7 @@ namespace hpx::actions {

///////////////////////////////////////////////////////////////////////////
template <typename Action>
struct transfer_action : transfer_base_action<Action>
struct transfer_action final : transfer_base_action<Action>
{
public:
transfer_action(transfer_action const&) = delete;
Expand All @@ -60,16 +61,18 @@ namespace hpx::actions {
explicit transfer_action(Ts&&... vs);

template <typename... Ts>
explicit transfer_action(threads::thread_priority priority, Ts&&... vs);
explicit transfer_action(hpx::launch policy, Ts&&... vs);

bool has_continuation() const override;

/// The \a get_thread_function constructs a proper thread function for
/// a \a thread, encapsulating the functionality and the arguments
/// of the action it is called for.
///
/// \param target
/// \param lva [in] This is the local virtual address of the
/// component the action has to be invoked on.
/// \param comptype
///
/// \returns This function returns a proper thread function usable
/// for a \a thread.
Expand Down Expand Up @@ -122,9 +125,8 @@ namespace hpx::actions {

template <typename Action>
template <typename... Ts>
transfer_action<Action>::transfer_action(
threads::thread_priority priority, Ts&&... vs)
: base_type(priority, HPX_FORWARD(Ts, vs)...)
transfer_action<Action>::transfer_action(hpx::launch policy, Ts&&... vs)
: base_type(policy, HPX_FORWARD(Ts, vs)...)
{
}

Expand Down Expand Up @@ -171,8 +173,14 @@ namespace hpx::actions {

threads::thread_init_data data;
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
#if HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
data.description = threads::thread_description(
actions::detail::get_action_name<Action>(),
actions::detail::get_action_name_itt<Action>());
#else
data.description = actions::detail::get_action_name<Action>();
#endif
#endif
#if defined(HPX_HAVE_THREAD_PARENT_REFERENCE)
data.parent_id = this->parent_id_;
data.parent_locality_id = this->parent_locality_;
Expand All @@ -181,8 +189,11 @@ namespace hpx::actions {
data.timer_data = hpx::util::external_timer::new_task(
data.description, data.parent_locality_id, data.parent_id);
#endif
data.priority = this->priority_;
data.stacksize = this->stacksize_;

hpx::detail::post_helper<typename base_type::derived_type>::call(
HPX_MOVE(data), HPX_MOVE(target), lva, comptype, this->priority_,
HPX_MOVE(data), HPX_MOVE(target), lva, comptype,
HPX_MOVE(hpx::get<Is>(this->arguments_))...);
}

Expand Down Expand Up @@ -222,7 +233,7 @@ namespace hpx::actions {
if (deferred_schedule)
{
// If this is a direct action and deferred schedule was requested,
// that is we are not the last parcel, return immediately
// i.e. if we are not the last parcel, return immediately
if constexpr (base_type::direct_execution::value)
{
return;
Expand Down
Loading

0 comments on commit 0053860

Please sign in to comment.