Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup runtime module - part 2 #1091

Merged
merged 9 commits into from
May 6, 2024
2 changes: 1 addition & 1 deletion examples/quickstart/enumerate_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int pika_main()
pika::this_thread::yield();

// Enumerate all suspended threads
pika::threads::enumerate_threads(
pika::detail::get_runtime().get_thread_manager().enumerate_threads(
[](pika::threads::detail::thread_id_type id) -> bool {
std::cout << "thread " << pika::thread::id(id) << " is "
<< pika::threads::detail::get_thread_state_name(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ namespace pika::detail {
no_affinity_; ///< mask of processing units which have no affinity
bool use_process_mask_; ///< use the process CPU mask to limit available PUs
std::size_t num_pus_needed_;
static std::atomic<int> instance_number_counter_; ///< counter for instance numbers
};
} // namespace pika::detail

Expand Down
3 changes: 1 addition & 2 deletions libs/pika/affinity/src/affinity_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace pika::detail {
threads::detail::resize(no_affinity_, threads::detail::hardware_concurrency());
}

affinity_data::~affinity_data() { --instance_number_counter_; }
affinity_data::~affinity_data() {}

// NOLINTBEGIN(bugprone-easily-swappable-parameters)
void affinity_data::init(std::size_t num_threads, std::size_t max_cores, std::size_t pu_offset,
Expand Down Expand Up @@ -285,5 +285,4 @@ namespace pika::detail {
return (num_pu + offset) % hardware_concurrency;
}

std::atomic<int> affinity_data::instance_number_counter_(-1);
} // namespace pika::detail
19 changes: 14 additions & 5 deletions libs/pika/init_runtime/tests/unit/pika_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace ex = pika::execution::experimental;
namespace tt = pika::this_thread::experimental;

using pika::detail::get_runtime;
using pika::threads::detail::thread_schedule_state;

void test_wait()
Expand All @@ -30,13 +31,21 @@ void test_wait()

if (pika::threads::detail::get_self_ptr())
{
PIKA_TEST_EQ(pika::threads::get_thread_count(thread_schedule_state::active), 1);
PIKA_TEST_EQ(
get_runtime().get_thread_manager().get_thread_count(thread_schedule_state::active), 1);
}
else
{
PIKA_TEST_EQ(
get_runtime().get_thread_manager().get_thread_count(thread_schedule_state::active), 0);
}
else { PIKA_TEST_EQ(pika::threads::get_thread_count(thread_schedule_state::active), 0); }

PIKA_TEST_EQ(pika::threads::get_thread_count(thread_schedule_state::pending), 0);
PIKA_TEST_EQ(pika::threads::get_thread_count(thread_schedule_state::suspended), 0);
PIKA_TEST_EQ(pika::threads::get_thread_count(thread_schedule_state::staged), 0);
PIKA_TEST_EQ(
get_runtime().get_thread_manager().get_thread_count(thread_schedule_state::pending), 0);
PIKA_TEST_EQ(
get_runtime().get_thread_manager().get_thread_count(thread_schedule_state::suspended), 0);
PIKA_TEST_EQ(
get_runtime().get_thread_manager().get_thread_count(thread_schedule_state::staged), 0);
}

int main(int argc, char** argv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void print_system_characteristics()
// -------------------------------------- //

//! -------------------------------------- runtime
std::cout << "[Runtime], instance number " << rt->get_instance_number() << "\n"
std::cout << "[Runtime] instance "
<< "called by thread named " << pika::detail::get_thread_name() << "\n\n";

//! -------------------------------------- thread_manager
Expand Down
4 changes: 0 additions & 4 deletions libs/pika/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set(runtime_headers
pika/runtime/get_os_thread_count.hpp
pika/runtime/get_thread_name.hpp
pika/runtime/get_worker_thread_num.hpp
pika/runtime/os_thread_type.hpp
pika/runtime/report_error.hpp
pika/runtime/runtime_handlers.hpp
pika/runtime/runtime.hpp
Expand All @@ -23,19 +22,16 @@ set(runtime_headers
pika/runtime/shutdown_function.hpp
pika/runtime/startup_function.hpp
pika/runtime/thread_hooks.hpp
pika/runtime/thread_mapper.hpp
pika/runtime/thread_pool_helpers.hpp
pika/runtime/thread_stacktrace.hpp
)

set(runtime_sources
custom_exception_info.cpp
debugging.cpp
os_thread_type.cpp
runtime_handlers.cpp
runtime.cpp
state.cpp
thread_mapper.cpp
thread_pool_helpers.cpp
thread_stacktrace.cpp
)
Expand Down
42 changes: 0 additions & 42 deletions libs/pika/runtime/include/pika/runtime/os_thread_type.hpp

This file was deleted.

45 changes: 7 additions & 38 deletions libs/pika/runtime/include/pika/runtime/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
#include <pika/modules/program_options.hpp>
#include <pika/modules/thread_manager.hpp>
#include <pika/modules/topology.hpp>
#include <pika/runtime/os_thread_type.hpp>
#include <pika/runtime/runtime_fwd.hpp>
#include <pika/runtime/shutdown_function.hpp>
#include <pika/runtime/startup_function.hpp>
#include <pika/runtime/state.hpp>
#include <pika/runtime/thread_hooks.hpp>
#include <pika/runtime/thread_mapper.hpp>
#include <pika/runtime_configuration/runtime_configuration.hpp>
#include <pika/threading_base/callback_notifier.hpp>

Expand Down Expand Up @@ -55,8 +53,7 @@ namespace pika::detail {
/// Generate a new notification policy instance for the given thread
/// name prefix
using notification_policy_type = pika::threads::callback_notifier;
virtual notification_policy_type get_notification_policy(
char const* prefix, os_thread_type type);
virtual notification_policy_type get_notification_policy(char const* prefix);

runtime_state get_state() const;
void set_state(runtime_state s);
Expand Down Expand Up @@ -100,14 +97,9 @@ namespace pika::detail {

pika::util::runtime_configuration const& get_config() const;

std::size_t get_instance_number() const;

/// \brief Return the system uptime measure on the thread executing this call
static std::uint64_t get_system_uptime();

/// \brief Return a reference to the internal PAPI thread manager
pika::util::thread_mapper& get_thread_mapper();

pika::threads::detail::topology const& get_topology() const;

/// \brief Run the pika runtime system, use the given function for the
Expand Down Expand Up @@ -282,12 +274,6 @@ namespace pika::detail {
/// \param num [in] The sequence number to use for thread
/// registration. The default for this parameter
/// is zero.
/// \param service_thread [in] The thread should be registered as a
/// service thread. The default for this parameter
/// is 'true'. Any service threads will be pinned
/// to cores not currently used by any of the pika
/// worker threads.
///
/// \note The function will compose a thread name of the form
/// '<name>-thread#<num>' which is used to register the thread. It
/// is the user's responsibility to ensure that each (composed)
Expand All @@ -302,8 +288,8 @@ namespace pika::detail {
/// \returns This function will return whether the requested operation
/// succeeded or not.
///
virtual bool register_thread(char const* name, std::size_t num = 0,
bool service_thread = true, error_code& ec = throws);
virtual bool register_thread(
char const* name, std::size_t num = 0, error_code& ec = throws);

/// \brief Unregister an external OS-thread with pika
///
Expand All @@ -319,14 +305,6 @@ namespace pika::detail {
///
virtual bool unregister_thread();

/// Access data for a given OS thread that was previously registered by
/// \a register_thread.
virtual os_thread_data get_os_thread_data(std::string const& label) const;

/// Enumerate all OS threads that have registered with the runtime.
virtual bool enumerate_os_threads(
pika::util::detail::function<bool(os_thread_data const&)> const& f) const;

notification_policy_type::on_startstop_type on_start_func() const;
notification_policy_type::on_startstop_type on_stop_func() const;
notification_policy_type::on_error_type on_error_func() const;
Expand Down Expand Up @@ -364,13 +342,6 @@ namespace pika::detail {

pika::util::runtime_configuration rtcfg_;

long instance_number_;
static std::atomic<int> instance_number_counter_;

// certain components (such as PAPI) require all threads to be
// registered with the library
std::unique_ptr<pika::util::thread_mapper> thread_support_;

// topology and affinity data
pika::threads::detail::topology& topology_;

Expand Down Expand Up @@ -402,13 +373,11 @@ namespace pika::detail {

void deinit_tss_helper(char const* context, std::size_t num);

void init_tss_ex(char const* context, os_thread_type type, std::size_t local_thread_num,
std::size_t global_thread_num, char const* pool_name, char const* postfix,
bool service_thread, error_code& ec);
void init_tss_ex(char const* context, std::size_t local_thread_num,
std::size_t global_thread_num, char const* pool_name, char const* postfix);

void init_tss_helper(char const* context, os_thread_type type, std::size_t local_thread_num,
std::size_t global_thread_num, char const* pool_name, char const* postfix,
bool service_thread);
void init_tss_helper(char const* context, std::size_t local_thread_num,
std::size_t global_thread_num, char const* pool_name, char const* postfix);

void notify_finalize();
void wait_finalize();
Expand Down
10 changes: 0 additions & 10 deletions libs/pika/runtime/include/pika/runtime/runtime_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <pika/runtime/get_os_thread_count.hpp>
#include <pika/runtime/get_thread_name.hpp>
#include <pika/runtime/get_worker_thread_num.hpp>
#include <pika/runtime/os_thread_type.hpp>
#include <pika/runtime/report_error.hpp>
#include <pika/runtime/shutdown_function.hpp>
#include <pika/runtime/startup_function.hpp>
Expand Down Expand Up @@ -48,15 +47,6 @@ namespace pika::detail {
/// the end before the external thread exists.
PIKA_EXPORT void unregister_thread(runtime* rt);

/// Access data for a given OS thread that was previously registered by
/// \a register_thread. This function must be called from a thread that was
/// previously registered with the runtime.
PIKA_EXPORT os_thread_data get_os_thread_data(std::string const& label);

/// Enumerate all OS threads that have registered with the runtime.
PIKA_EXPORT bool enumerate_os_threads(
pika::util::detail::function<bool(os_thread_data const&)> const& f);

/// Register a function to be called during system shutdown
PIKA_EXPORT bool register_on_exit(pika::util::detail::function<void()> const&);

Expand Down
Loading
Loading