From e20301661828ddf1097e213fa39ca61543be84ba Mon Sep 17 00:00:00 2001 From: aurianer Date: Tue, 9 Apr 2024 16:36:51 +0200 Subject: [PATCH 1/7] Remove thread_mapper as PAPI not used anymore and usage of os_thread_type --- libs/pika/runtime/CMakeLists.txt | 2 - .../include/pika/runtime/os_thread_type.hpp | 11 - .../runtime/include/pika/runtime/runtime.hpp | 24 +- .../include/pika/runtime/runtime_fwd.hpp | 10 - .../include/pika/runtime/thread_mapper.hpp | 158 ----------- libs/pika/runtime/src/runtime.cpp | 73 ++--- libs/pika/runtime/src/thread_mapper.cpp | 249 ------------------ .../pika/runtime/tests/unit/thread_mapper.cpp | 65 ----- 8 files changed, 18 insertions(+), 574 deletions(-) delete mode 100644 libs/pika/runtime/include/pika/runtime/thread_mapper.hpp delete mode 100644 libs/pika/runtime/src/thread_mapper.cpp delete mode 100644 libs/pika/runtime/tests/unit/thread_mapper.cpp diff --git a/libs/pika/runtime/CMakeLists.txt b/libs/pika/runtime/CMakeLists.txt index 8a9bffea0..294234ad1 100644 --- a/libs/pika/runtime/CMakeLists.txt +++ b/libs/pika/runtime/CMakeLists.txt @@ -23,7 +23,6 @@ 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 ) @@ -35,7 +34,6 @@ set(runtime_sources runtime_handlers.cpp runtime.cpp state.cpp - thread_mapper.cpp thread_pool_helpers.cpp thread_stacktrace.cpp ) diff --git a/libs/pika/runtime/include/pika/runtime/os_thread_type.hpp b/libs/pika/runtime/include/pika/runtime/os_thread_type.hpp index 1c1b5148a..cd1dcd9fb 100644 --- a/libs/pika/runtime/include/pika/runtime/os_thread_type.hpp +++ b/libs/pika/runtime/include/pika/runtime/os_thread_type.hpp @@ -28,15 +28,4 @@ namespace pika { /// Return a human-readable name representing one of the kernel thread types PIKA_EXPORT std::string get_os_thread_type_name(os_thread_type type); - /////////////////////////////////////////////////////////////////////////// - /// Registration data for kernel threads that is maintained by the runtime - /// internally - struct os_thread_data - { - std::string label_; ///< name used for thread registration - std::thread::id id_; ///< thread id of corresponding kernel thread - std::uint64_t native_handle_; ///< the threads native handle - os_thread_type type_; ///< pika thread type - }; - } // namespace pika diff --git a/libs/pika/runtime/include/pika/runtime/runtime.hpp b/libs/pika/runtime/include/pika/runtime/runtime.hpp index cec8b44d9..e456d0eb4 100644 --- a/libs/pika/runtime/include/pika/runtime/runtime.hpp +++ b/libs/pika/runtime/include/pika/runtime/runtime.hpp @@ -12,13 +12,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include @@ -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); @@ -105,9 +102,6 @@ namespace pika::detail { /// \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 @@ -319,14 +313,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 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; @@ -367,10 +353,6 @@ namespace pika::detail { long instance_number_; static std::atomic instance_number_counter_; - // certain components (such as PAPI) require all threads to be - // registered with the library - std::unique_ptr thread_support_; - // topology and affinity data pika::threads::detail::topology& topology_; @@ -402,11 +384,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, + 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, bool service_thread, error_code& ec); - void init_tss_helper(char const* context, os_thread_type type, std::size_t local_thread_num, + 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, bool service_thread); diff --git a/libs/pika/runtime/include/pika/runtime/runtime_fwd.hpp b/libs/pika/runtime/include/pika/runtime/runtime_fwd.hpp index 213f7bc3f..773ee897e 100644 --- a/libs/pika/runtime/include/pika/runtime/runtime_fwd.hpp +++ b/libs/pika/runtime/include/pika/runtime/runtime_fwd.hpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -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 const& f); - /// Register a function to be called during system shutdown PIKA_EXPORT bool register_on_exit(pika::util::detail::function const&); diff --git a/libs/pika/runtime/include/pika/runtime/thread_mapper.hpp b/libs/pika/runtime/include/pika/runtime/thread_mapper.hpp deleted file mode 100644 index 1fd2a8fb2..000000000 --- a/libs/pika/runtime/include/pika/runtime/thread_mapper.hpp +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) 2012 Maciej Brodowicz -// Copyright (c) 2020 Hartmut Kaiser -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#if defined(__linux__) && !defined(__ANDROID) && !defined(ANDROID) -# include -#endif - -namespace pika::util { - - /////////////////////////////////////////////////////////////////////////// - // enumerates active OS threads and maintains their metadata - - class thread_mapper; - - namespace detail { - - // type for callback function invoked when thread is unregistered - using thread_mapper_callback_type = pika::util::detail::function; - - // thread-specific data - class PIKA_EXPORT os_thread_data - { - public: - os_thread_data() = default; - os_thread_data(std::string const& label, os_thread_type type); - - protected: - friend class pika::util::thread_mapper; - - void invalidate(); - bool is_valid() const; - - private: - // label of this thread - std::string label_; - - // associated thread ID, typically an ID of a kernel thread - std::thread::id id_; - - // the native_handle() of the associated thread - std::uint64_t tid_; - -#if defined(__linux__) && !defined(__ANDROID) && !defined(ANDROID) - // the Linux thread id (required by PAPI) - pid_t linux_tid_; -#endif - - // callback function invoked when unregistering a thread - thread_mapper_callback_type cleanup_; - - // type of this OS thread in the context of the runtime - os_thread_type type_; - }; - } // namespace detail - - /////////////////////////////////////////////////////////////////////////// - class PIKA_EXPORT thread_mapper - { - public: - PIKA_NON_COPYABLE(thread_mapper); - - public: - using callback_type = detail::thread_mapper_callback_type; - - // erroneous thread index - static constexpr std::uint32_t invalid_index = std::uint32_t(-1); - - // erroneous low-level thread ID - static constexpr std::uint64_t invalid_tid = std::uint64_t(-1); - - public: - thread_mapper(); - ~thread_mapper(); - - /////////////////////////////////////////////////////////////////////// - // registers invoking OS thread with a unique label - std::uint32_t register_thread(char const* label, os_thread_type type); - - // unregisters the calling OS thread - bool unregister_thread(); - - /////////////////////////////////////////////////////////////////////// - // returns unique index based on registered thread label - std::uint32_t get_thread_index(std::string const& label) const; - - // returns the number of threads registered so far - std::uint32_t get_thread_count() const; - - /////////////////////////////////////////////////////////////////////// - // register callback function for a thread, invoked when unregistering - // that thread - bool register_callback(std::uint32_t tix, callback_type const&); - - // cancel callback - bool revoke_callback(std::uint32_t tix); - - // returns thread id - std::thread::id get_thread_id(std::uint32_t tix) const; - - // returns low level thread id (native_handle) - std::uint64_t get_thread_native_handle(std::uint32_t tix) const; - -#if defined(__linux__) && !defined(__ANDROID) && !defined(ANDROID) - pid_t get_linux_thread_id(std::uint32_t tix) const; -#endif - - // returns the label of registered thread tix - std::string const& get_thread_label(std::uint32_t tix) const; - - // returns the type of the registered thread - os_thread_type get_thread_type(std::uint32_t tix) const; - - // enumerate all registered OS threads - bool enumerate_os_threads( - pika::util::detail::function const& f) const; - - // retrieve all data stored for a given thread - os_thread_data get_os_thread_data(std::string const& label) const; - - private: - using mutex_type = pika::concurrency::detail::spinlock; - - using thread_map_type = std::vector; - using label_map_type = std::map; - - // main lock - mutable mutex_type mtx_; - - // mapping from thread IDs to thread indices - thread_map_type thread_map_; - - // mapping between pika thread labels and thread indices - label_map_type label_map_; - }; -} // namespace pika::util - -#include diff --git a/libs/pika/runtime/src/runtime.cpp b/libs/pika/runtime/src/runtime.cpp index f7cf179c0..2f8e6b10f 100644 --- a/libs/pika/runtime/src/runtime.cpp +++ b/libs/pika/runtime/src/runtime.cpp @@ -22,14 +22,12 @@ #include #include #include -#include #include #include #include #include #include #include -#include #include #include #include @@ -250,7 +248,6 @@ namespace pika::detail { runtime::runtime(pika::util::runtime_configuration& rtcfg, bool initialize) : rtcfg_(rtcfg) , instance_number_(++instance_number_counter_) - , thread_support_(new pika::util::thread_mapper) , topology_(resource::get_partitioner().get_topology()) , state_(pika::runtime_state::invalid) , on_start_func_(global_on_start_func) @@ -266,8 +263,7 @@ namespace pika::detail { // set notification policies only after the object was completely // initialized - runtime::set_notification_policies( - runtime::get_notification_policy("worker-thread", os_thread_type::worker_thread)); + runtime::set_notification_policies(runtime::get_notification_policy("worker-thread")); init_global_data(); @@ -278,7 +274,6 @@ namespace pika::detail { runtime::runtime(pika::util::runtime_configuration& rtcfg) : rtcfg_(rtcfg) , instance_number_(++instance_number_counter_) - , thread_support_(new pika::util::thread_mapper) , topology_(resource::get_partitioner().get_topology()) , state_(pika::runtime_state::invalid) , on_start_func_(global_on_start_func) @@ -584,20 +579,6 @@ namespace pika::detail { rt->unregister_thread(); } - // 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. - os_thread_data get_os_thread_data(std::string const& label) - { - return get_runtime().get_os_thread_data(label); - } - - /// Enumerate all OS threads that have registered with the runtime. - bool enumerate_os_threads(pika::util::detail::function const& f) - { - return get_runtime().enumerate_os_threads(f); - } - /////////////////////////////////////////////////////////////////////////// void report_error(std::size_t num_thread, std::exception_ptr const& e) { @@ -1105,7 +1086,7 @@ namespace pika::detail { // Register this thread with the runtime system to allow calling // certain pika functionality from the main thread. Also calls // registered startup callbacks. - init_tss_helper("main-thread", os_thread_type::main_thread, 0, 0, "", "", false); + init_tss_helper("main-thread", 0, 0, "", "", false); // start the thread manager thread_manager_->run(); @@ -1403,11 +1384,8 @@ namespace pika::detail { return result; } - pika::util::thread_mapper& runtime::get_thread_mapper() { return *thread_support_; } - /////////////////////////////////////////////////////////////////////////// - pika::threads::callback_notifier runtime::get_notification_policy( - char const* prefix, os_thread_type type) + pika::threads::callback_notifier runtime::get_notification_policy(char const* prefix) { using report_error_t = bool (runtime::*)(std::size_t, std::exception_ptr const&, bool); @@ -1419,7 +1397,7 @@ namespace pika::detail { notification_policy_type notifier; notifier.add_on_start_thread_callback(pika::util::detail::bind( - &runtime::init_tss_helper, this, prefix, type, _1, _2, _3, _4, false)); + &runtime::init_tss_helper, this, prefix, _1, _2, _3, _4, false)); notifier.add_on_stop_thread_callback( pika::util::detail::bind(&runtime::deinit_tss_helper, this, prefix, _1)); notifier.set_on_error_callback(pika::util::detail::bind( @@ -1428,19 +1406,19 @@ namespace pika::detail { return notifier; } - void runtime::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 runtime::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, + bool service_thread) { error_code ec(throwmode::lightweight); - return init_tss_ex(context, type, local_thread_num, global_thread_num, pool_name, postfix, - service_thread, ec); + return init_tss_ex( + context, local_thread_num, global_thread_num, pool_name, postfix, service_thread, ec); } // NOLINTBEGIN(bugprone-easily-swappable-parameters) - void runtime::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 runtime::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, + bool service_thread, error_code& ec) // NOLINTEND(bugprone-easily-swappable-parameters) { std::ostringstream fullname; @@ -1461,9 +1439,6 @@ namespace pika::detail { char const* name = detail::thread_name().c_str(); - // initialize thread mapping for external libraries (i.e. PAPI) - thread_support_->register_thread(name, type); - // register this thread with any possibly active Intel tool PIKA_ITT_THREAD_SET_NAME(name); @@ -1522,9 +1497,6 @@ namespace pika::detail { // call thread-specific user-supplied on_stop handler if (on_stop_func_) { on_stop_func_(global_thread_num, global_thread_num, "", context); } - // reset PAPI support - thread_support_->unregister_thread(); - // reset thread local storage detail::thread_name().clear(); } @@ -1560,8 +1532,8 @@ namespace pika::detail { std::string thread_name(name); thread_name += "-thread"; - init_tss_ex(thread_name.c_str(), os_thread_type::custom_thread, global_thread_num, - global_thread_num, "", nullptr, service_thread, ec); + init_tss_ex(thread_name.c_str(), global_thread_num, global_thread_num, "", nullptr, + service_thread, ec); return !ec ? true : false; } @@ -1573,25 +1545,10 @@ namespace pika::detail { return true; } - // 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. - os_thread_data runtime::get_os_thread_data(std::string const& label) const - { - return thread_support_->get_os_thread_data(label); - } - - /// Enumerate all OS threads that have registered with the runtime. - bool runtime::enumerate_os_threads( - pika::util::detail::function const& f) const - { - return thread_support_->enumerate_os_threads(f); - } - /////////////////////////////////////////////////////////////////////////// pika::threads::callback_notifier get_notification_policy(char const* prefix) { - return get_runtime().get_notification_policy(prefix, os_thread_type::worker_thread); + return get_runtime().get_notification_policy(prefix); } namespace threads { diff --git a/libs/pika/runtime/src/thread_mapper.cpp b/libs/pika/runtime/src/thread_mapper.cpp deleted file mode 100644 index e08d754d3..000000000 --- a/libs/pika/runtime/src/thread_mapper.cpp +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (c) 2012 Maciej Brodowicz -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#if defined(PIKA_WINDOWS) -# include -#else -# include -#endif - -#if defined(__linux__) && !defined(__ANDROID) && !defined(ANDROID) -# include -# include -#endif - -namespace pika::util { - - namespace detail { - - /////////////////////////////////////////////////////////////////////// - std::uint64_t get_system_thread_id() - { -#if defined(PIKA_WINDOWS) - return std::uint64_t(::GetCurrentThreadId()); -#else - return std::uint64_t(::pthread_self()); -#endif - } - - // thread-specific data - os_thread_data::os_thread_data(std::string const& label, os_thread_type type) - : label_(label) - , id_(std::this_thread::get_id()) - , tid_(get_system_thread_id()) -#if defined(__linux__) && !defined(__ANDROID) && !defined(ANDROID) - , linux_tid_(static_cast(syscall(SYS_gettid))) -#endif - , cleanup_() - , type_(type) - { - } - - void os_thread_data::invalidate() - { - tid_ = thread_mapper::invalid_tid; - cleanup_.reset(); - } - - bool os_thread_data::is_valid() const { return tid_ != thread_mapper::invalid_tid; } - } // namespace detail - - /////////////////////////////////////////////////////////////////////////// - thread_mapper::thread_mapper() = default; - - thread_mapper::~thread_mapper() - { - std::lock_guard m(mtx_); - - std::uint32_t i = 0; - for (auto&& tinfo : thread_map_) - { - if (tinfo.cleanup_) { tinfo.cleanup_(i++); } - } - } - - std::uint32_t thread_mapper::register_thread(char const* name, os_thread_type type) - { - std::lock_guard m(mtx_); - - auto tid = detail::get_system_thread_id(); - for (auto&& tinfo : thread_map_) - { - if (tinfo.tid_ == tid) - { - PIKA_THROW_EXCEPTION(pika::error::bad_parameter, "thread_mapper::register_thread", - "thread already registered"); - } - } - - // create mappings - thread_map_.push_back(detail::os_thread_data(name, type)); - - std::size_t idx = thread_map_.size() - 1; - label_map_[name] = idx; - - return static_cast(idx); - } - - bool thread_mapper::unregister_thread() - { - std::lock_guard m(mtx_); - - std::uint32_t i = 0; - auto tid = detail::get_system_thread_id(); - for (auto&& tinfo : thread_map_) - { - if (tinfo.tid_ == tid) - { - label_map_.erase(tinfo.label_); - if (tinfo.cleanup_) { tinfo.cleanup_(i); } - - std::size_t size = thread_map_.size(); - if (static_cast(i) == size) { thread_map_.resize(size - 1); } - else { tinfo.invalidate(); } - return true; - } - ++i; - } - return false; - } - - bool thread_mapper::register_callback(std::uint32_t tix, callback_type const& cb) - { - std::lock_guard m(mtx_); - - auto idx = static_cast(tix); - if (idx >= thread_map_.size() || !thread_map_[tix].is_valid()) { return false; } - - thread_map_[tix].cleanup_ = cb; - return true; - } - - bool thread_mapper::revoke_callback(std::uint32_t tix) - { - std::lock_guard m(mtx_); - - auto idx = static_cast(tix); - if (idx >= thread_map_.size() || !thread_map_[tix].is_valid()) { return false; } - - thread_map_[tix].cleanup_.reset(); - return true; - } - - std::thread::id thread_mapper::get_thread_id(std::uint32_t tix) const - { - std::lock_guard m(mtx_); - - auto idx = static_cast(tix); - if (idx >= thread_map_.size()) { return std::thread::id{}; } - return thread_map_[idx].id_; - } - - std::uint64_t thread_mapper::get_thread_native_handle(std::uint32_t tix) const - { - std::lock_guard m(mtx_); - - auto idx = static_cast(tix); - if (idx >= thread_map_.size()) { return thread_mapper::invalid_tid; } - return thread_map_[idx].tid_; - } - -#if defined(__linux__) && !defined(__ANDROID) && !defined(ANDROID) - pid_t thread_mapper::get_linux_thread_id(std::uint32_t tix) const - { - std::lock_guard m(mtx_); - - auto idx = static_cast(tix); - if (idx >= thread_map_.size()) { return -1; } - return thread_map_[idx].linux_tid_; - } -#endif - - std::string const& thread_mapper::get_thread_label(std::uint32_t tix) const - { - std::lock_guard m(mtx_); - - auto idx = static_cast(tix); - if (idx >= thread_map_.size()) - { - static std::string invalid_label; - return invalid_label; - } - return thread_map_[idx].label_; - } - - os_thread_type thread_mapper::get_thread_type(std::uint32_t tix) const - { - std::lock_guard m(mtx_); - - auto idx = static_cast(tix); - if (idx >= thread_map_.size()) { return os_thread_type::unknown; } - return thread_map_[idx].type_; - } - - std::uint32_t thread_mapper::get_thread_index(std::string const& label) const - { - std::lock_guard m(mtx_); - - auto it = label_map_.find(label); - if (it == label_map_.end()) { return invalid_index; } - return static_cast(it->second); - } - - std::uint32_t thread_mapper::get_thread_count() const - { - std::lock_guard m(mtx_); - - return static_cast(label_map_.size()); - } - - // retrieve all data stored for a given thread - os_thread_data thread_mapper::get_os_thread_data(std::string const& label) const - { - std::lock_guard m(mtx_); - - auto it = label_map_.find(label); - if (it == label_map_.end()) - { - return os_thread_data{ - "", std::thread::id{}, thread_mapper::invalid_tid, os_thread_type::unknown}; - } - - auto idx = static_cast(it->second); - if (idx >= thread_map_.size()) - { - return os_thread_data{ - "", std::thread::id{}, thread_mapper::invalid_tid, os_thread_type::unknown}; - } - - auto const& tinfo = thread_map_[idx]; - return os_thread_data{tinfo.label_, tinfo.id_, tinfo.tid_, tinfo.type_}; - } - - bool thread_mapper::enumerate_os_threads( - pika::util::detail::function const& f) const - { - std::lock_guard m(mtx_); - for (auto const& tinfo : thread_map_) - { - os_thread_data data{tinfo.label_, tinfo.id_, tinfo.tid_, tinfo.type_}; - if (!f(data)) { return false; } - } - return true; - } - -} // namespace pika::util diff --git a/libs/pika/runtime/tests/unit/thread_mapper.cpp b/libs/pika/runtime/tests/unit/thread_mapper.cpp deleted file mode 100644 index 68db45f6d..000000000 --- a/libs/pika/runtime/tests/unit/thread_mapper.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2020 Hartmut Kaiser -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -void enumerate_threads(std::size_t num_custom_threads) -{ - std::size_t counts[std::size_t(pika::os_thread_type::custom_thread) + 1] = {0}; - - bool result = pika::detail::enumerate_os_threads([&counts](pika::os_thread_data const& data) { - if (data.type_ != pika::os_thread_type::unknown) - { - PIKA_TEST(std::size_t(data.type_) <= std::size_t(pika::os_thread_type::custom_thread)); - - ++counts[std::size_t(data.type_)]; - PIKA_TEST( - data.label_.find(pika::get_os_thread_type_name(data.type_)) != std::string::npos); - } - return true; - }); - PIKA_TEST(result); - - std::size_t num_workers = pika::get_num_worker_threads(); - PIKA_TEST_EQ(counts[std::size_t(pika::os_thread_type::worker_thread)], num_workers); - - PIKA_TEST_EQ(counts[std::size_t(pika::os_thread_type::custom_thread)], num_custom_threads); -} - -int pika_main() -{ - enumerate_threads(0); - - auto* rt = pika::detail::get_runtime_ptr(); - - std::thread t([rt]() { - pika::detail::register_thread(rt, "custom"); - enumerate_threads(1); - pika::detail::unregister_thread(rt); - }); - t.join(); - - pika::finalize(); - return EXIT_SUCCESS; -} - -int main(int argc, char* argv[]) -{ - pika::init_params init_args; - - PIKA_TEST_EQ(pika::init(pika_main, argc, argv, init_args), 0); - - return 0; -} From 78b832db55f34fe2b3af87428e79454410a66c34 Mon Sep 17 00:00:00 2001 From: aurianer Date: Tue, 9 Apr 2024 17:56:41 +0200 Subject: [PATCH 2/7] Remove get_thread_count and use get_runtime --- .../init_runtime/tests/unit/pika_wait.cpp | 19 +++++++++---- .../pika/runtime/thread_pool_helpers.hpp | 28 ------------------- libs/pika/runtime/src/thread_pool_helpers.cpp | 11 -------- .../pika/synchronization/tests/unit/event.cpp | 2 -- .../local/heterogeneous_timed_task_spawn.cpp | 6 ++-- .../performance/local/htts_v2/htts2_pika.cpp | 12 ++++---- tests/performance/local/timed_task_spawn.cpp | 8 ++++-- 7 files changed, 30 insertions(+), 56 deletions(-) diff --git a/libs/pika/init_runtime/tests/unit/pika_wait.cpp b/libs/pika/init_runtime/tests/unit/pika_wait.cpp index 2c8f7d89f..f68991941 100644 --- a/libs/pika/init_runtime/tests/unit/pika_wait.cpp +++ b/libs/pika/init_runtime/tests/unit/pika_wait.cpp @@ -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() @@ -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) diff --git a/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp b/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp index 425813455..f158a2977 100644 --- a/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp +++ b/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp @@ -55,34 +55,6 @@ namespace pika::resource { } // namespace pika::resource namespace pika::threads { - /// The function \a get_thread_count returns the number of currently - /// known threads. - /// - /// \param state [in] This specifies the thread-state for which the - /// number of threads should be retrieved. - /// - /// \note If state == unknown this function will not only return the - /// number of currently existing threads, but will add the number - /// of registered task descriptions (which have not been - /// converted into threads yet). - PIKA_EXPORT std::int64_t get_thread_count( - detail::thread_schedule_state state = detail::thread_schedule_state::unknown); - - /// The function \a get_thread_count returns the number of currently - /// known threads. - /// - /// \param priority [in] This specifies the thread-priority for which the - /// number of threads should be retrieved. - /// \param state [in] This specifies the thread-state for which the - /// number of threads should be retrieved. - /// - /// \note If state == unknown this function will not only return the - /// number of currently existing threads, but will add the number - /// of registered task descriptions (which have not been - /// converted into threads yet). - PIKA_EXPORT std::int64_t get_thread_count(execution::thread_priority priority, - detail::thread_schedule_state state = detail::thread_schedule_state::unknown); - /// The function \a get_idle_core_count returns the number of currently /// idling threads (cores). PIKA_EXPORT std::int64_t get_idle_core_count(); diff --git a/libs/pika/runtime/src/thread_pool_helpers.cpp b/libs/pika/runtime/src/thread_pool_helpers.cpp index 258e9f53a..a5a143c8c 100644 --- a/libs/pika/runtime/src/thread_pool_helpers.cpp +++ b/libs/pika/runtime/src/thread_pool_helpers.cpp @@ -67,17 +67,6 @@ namespace pika::resource { } // namespace pika::resource namespace pika::threads { - std::int64_t get_thread_count(detail::thread_schedule_state state) - { - return pika::detail::get_runtime().get_thread_manager().get_thread_count(state); - } - - std::int64_t get_thread_count( - execution::thread_priority priority, detail::thread_schedule_state state) - { - return pika::detail::get_runtime().get_thread_manager().get_thread_count(state, priority); - } - std::int64_t get_idle_core_count() { return pika::detail::get_runtime().get_thread_manager().get_idle_core_count(); diff --git a/libs/pika/synchronization/tests/unit/event.cpp b/libs/pika/synchronization/tests/unit/event.cpp index 5db679234..a8313b2d5 100644 --- a/libs/pika/synchronization/tests/unit/event.cpp +++ b/libs/pika/synchronization/tests/unit/event.cpp @@ -24,8 +24,6 @@ using pika::program_options::options_description; using pika::program_options::value; using pika::program_options::variables_map; -using pika::threads::get_thread_count; - using pika::this_thread::suspend; using pika::experimental::event; diff --git a/tests/performance/local/heterogeneous_timed_task_spawn.cpp b/tests/performance/local/heterogeneous_timed_task_spawn.cpp index daf6bc3b9..e34b55b77 100644 --- a/tests/performance/local/heterogeneous_timed_task_spawn.cpp +++ b/tests/performance/local/heterogeneous_timed_task_spawn.cpp @@ -39,8 +39,8 @@ using pika::threads::detail::make_thread_function_nullary; using pika::threads::detail::register_work; using pika::threads::detail::thread_init_data; +using pika::detail::get_runtime; using pika::this_thread::suspend; -using pika::threads::get_thread_count; using pika::chrono::detail::high_resolution_timer; @@ -190,7 +190,9 @@ int pika_main(variables_map& vm) // should be resumed after most of the null pika-threads have been // executed. If we haven't, we just reschedule ourselves again. suspend(); - } while (get_thread_count(pika::execution::thread_priority::normal) > 1); + } while (get_runtime().get_thread_manager().get_thread_count( + pika::threads::detail::thread_schedule_state::unknown, + pika::execution::thread_priority::normal) > 1); /////////////////////////////////////////////////////////////////////// // Print the results. diff --git a/tests/performance/local/htts_v2/htts2_pika.cpp b/tests/performance/local/htts_v2/htts2_pika.cpp index d1dda2d7d..919054e9c 100644 --- a/tests/performance/local/htts_v2/htts2_pika.cpp +++ b/tests/performance/local/htts_v2/htts2_pika.cpp @@ -118,14 +118,16 @@ struct pika_driver : htts2::driver void wait_for_tasks(pika::barrier<>& finished) { - std::uint64_t const pending_count = - pika::threads::get_thread_count(pika::execution::thread_priority::normal, - pika::threads::detail::thread_schedule_state::pending); + using pika::detail::get_runtime; + std::uint64_t const pending_count = get_runtime().get_thread_manager().get_thread_count( + pika::threads::detail::thread_schedule_state::pending, + pika::execution::thread_priority::normal); if (pending_count == 0) { - std::uint64_t const all_count = - pika::threads::get_thread_count(pika::execution::thread_priority::normal); + std::uint64_t const all_count = get_runtime().get_thread_manager().get_thread_count( + pika::threads::detail::thread_schedule_state::unknown, + pika::execution::thread_priority::normal); if (all_count != 1) { diff --git a/tests/performance/local/timed_task_spawn.cpp b/tests/performance/local/timed_task_spawn.cpp index 619162681..f4938da9d 100644 --- a/tests/performance/local/timed_task_spawn.cpp +++ b/tests/performance/local/timed_task_spawn.cpp @@ -50,8 +50,8 @@ using pika::threads::detail::make_thread_function_nullary; using pika::threads::detail::register_work; using pika::threads::detail::thread_init_data; +using pika::detail::get_runtime; using pika::this_thread::suspend; -using pika::threads::get_thread_count; using pika::chrono::detail::high_resolution_timer; @@ -153,12 +153,14 @@ void print_results(std::uint64_t cores, double walltime, double warmup_estimate, /////////////////////////////////////////////////////////////////////////////// void wait_for_tasks(pika::barrier& finished, std::uint64_t suspended_tasks) { - std::uint64_t const pending_count = get_thread_count(pika::execution::thread_priority::normal, + std::uint64_t const pending_count = get_runtime().get_thread_manager().get_thread_count( + pika::execution::thread_priority::normal, pika::threads::detail::thread_schedule_state::pending); if (pending_count == 0) { - std::uint64_t const all_count = get_thread_count(pika::execution::thread_priority::normal); + std::uint64_t const all_count = get_runtime().get_thread_manager().get_thread_count( + pika::execution::thread_priority::normal); if (all_count != suspended_tasks + 1) { From 37d3093ce9a112395fa74e1cc35abb8a2fa23db5 Mon Sep 17 00:00:00 2001 From: aurianer Date: Tue, 9 Apr 2024 18:51:33 +0200 Subject: [PATCH 3/7] Remove enumerate_threads and unused get_idle_core_* --- examples/quickstart/enumerate_threads.cpp | 2 +- .../pika/runtime/thread_pool_helpers.hpp | 22 ------------------- libs/pika/runtime/src/thread_pool_helpers.cpp | 18 --------------- libs/pika/runtime/src/thread_stacktrace.cpp | 4 ++-- 4 files changed, 3 insertions(+), 43 deletions(-) diff --git a/examples/quickstart/enumerate_threads.cpp b/examples/quickstart/enumerate_threads.cpp index b26b521ce..9fb110868 100644 --- a/examples/quickstart/enumerate_threads.cpp +++ b/examples/quickstart/enumerate_threads.cpp @@ -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( diff --git a/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp b/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp index f158a2977..f3d52bd34 100644 --- a/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp +++ b/libs/pika/runtime/include/pika/runtime/thread_pool_helpers.hpp @@ -53,25 +53,3 @@ namespace pika::resource { /// Return true if the pool with the given index exists PIKA_EXPORT bool pool_exists(std::size_t pool_index); } // namespace pika::resource - -namespace pika::threads { - /// The function \a get_idle_core_count returns the number of currently - /// idling threads (cores). - PIKA_EXPORT std::int64_t get_idle_core_count(); - - /// The function \a get_idle_core_mask returns a bit-mask representing the - /// currently idling threads (cores). - PIKA_EXPORT detail::mask_type get_idle_core_mask(); - - /// The function \a enumerate_threads will invoke the given function \a f - /// for each thread with a matching thread state. - /// - /// \param f [in] The function which should be called for each - /// matching thread. Returning 'false' from this function - /// will stop the enumeration process. - /// \param state [in] This specifies the thread-state for which the - /// threads should be enumerated. - PIKA_EXPORT bool enumerate_threads( - pika::util::detail::function const& f, - detail::thread_schedule_state state = detail::thread_schedule_state::unknown); -} // namespace pika::threads diff --git a/libs/pika/runtime/src/thread_pool_helpers.cpp b/libs/pika/runtime/src/thread_pool_helpers.cpp index a5a143c8c..5e08bb25d 100644 --- a/libs/pika/runtime/src/thread_pool_helpers.cpp +++ b/libs/pika/runtime/src/thread_pool_helpers.cpp @@ -65,21 +65,3 @@ namespace pika::resource { return pika::detail::get_runtime().get_thread_manager().pool_exists(pool_index); } } // namespace pika::resource - -namespace pika::threads { - std::int64_t get_idle_core_count() - { - return pika::detail::get_runtime().get_thread_manager().get_idle_core_count(); - } - - detail::mask_type get_idle_core_mask() - { - return pika::detail::get_runtime().get_thread_manager().get_idle_core_mask(); - } - - bool enumerate_threads(pika::util::detail::function const& f, - detail::thread_schedule_state state) - { - return pika::detail::get_runtime().get_thread_manager().enumerate_threads(f, state); - } -} // namespace pika::threads diff --git a/libs/pika/runtime/src/thread_stacktrace.cpp b/libs/pika/runtime/src/thread_stacktrace.cpp index ce175dc52..96ee5a36b 100644 --- a/libs/pika/runtime/src/thread_stacktrace.cpp +++ b/libs/pika/runtime/src/thread_stacktrace.cpp @@ -26,7 +26,7 @@ namespace pika::detail { { std::vector thread_ids_vector; // - pika::threads::enumerate_threads( + pika::detail::get_runtime().get_thread_manager().enumerate_threads( [&thread_ids_vector](pika::threads::detail::thread_id_type id) -> bool { thread_ids_vector.push_back(id); return true; // always continue enumeration @@ -42,7 +42,7 @@ namespace pika::detail { { std::vector thread_data_vector; // - pika::threads::enumerate_threads( + pika::detail::get_runtime().get_thread_manager().enumerate_threads( [&thread_data_vector](pika::threads::detail::thread_id_type id) -> bool { pika::threads::detail::thread_data* data = get_thread_id_data(id); thread_data_vector.push_back(data); From 9189adb567d70949040ab0768a1ad4ecd646af57 Mon Sep 17 00:00:00 2001 From: aurianer Date: Tue, 9 Apr 2024 18:57:22 +0200 Subject: [PATCH 4/7] Remove service threads --- .../runtime/include/pika/runtime/runtime.hpp | 14 ++---- libs/pika/runtime/src/runtime.cpp | 49 +++---------------- .../include/pika/topology/topology.hpp | 12 ----- libs/pika/topology/src/topology.cpp | 16 ------ 4 files changed, 11 insertions(+), 80 deletions(-) diff --git a/libs/pika/runtime/include/pika/runtime/runtime.hpp b/libs/pika/runtime/include/pika/runtime/runtime.hpp index e456d0eb4..78a86b96a 100644 --- a/libs/pika/runtime/include/pika/runtime/runtime.hpp +++ b/libs/pika/runtime/include/pika/runtime/runtime.hpp @@ -276,12 +276,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 /// '-thread#' which is used to register the thread. It /// is the user's responsibility to ensure that each (composed) @@ -297,7 +291,7 @@ namespace pika::detail { /// succeeded or not. /// virtual bool register_thread(char const* name, std::size_t num = 0, - bool service_thread = true, error_code& ec = throws); + error_code& ec = throws); /// \brief Unregister an external OS-thread with pika /// @@ -385,12 +379,10 @@ namespace pika::detail { void deinit_tss_helper(char const* context, std::size_t num); 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, - bool service_thread, error_code& ec); + std::size_t global_thread_num, char const* pool_name, char const* postfix); 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, - bool service_thread); + std::size_t global_thread_num, char const* pool_name, char const* postfix); void notify_finalize(); void wait_finalize(); diff --git a/libs/pika/runtime/src/runtime.cpp b/libs/pika/runtime/src/runtime.cpp index 2f8e6b10f..072ab214f 100644 --- a/libs/pika/runtime/src/runtime.cpp +++ b/libs/pika/runtime/src/runtime.cpp @@ -568,7 +568,7 @@ namespace pika::detail { bool register_thread(runtime* rt, char const* name, error_code& ec) { PIKA_ASSERT(rt); - return rt->register_thread(name, 0, true, ec); + return rt->register_thread(name, 0, ec); } // Unregister the thread from pika, this should be done once in @@ -1086,7 +1086,7 @@ namespace pika::detail { // Register this thread with the runtime system to allow calling // certain pika functionality from the main thread. Also calls // registered startup callbacks. - init_tss_helper("main-thread", 0, 0, "", "", false); + init_tss_helper("main-thread", 0, 0, "", ""); // start the thread manager thread_manager_->run(); @@ -1397,7 +1397,7 @@ namespace pika::detail { notification_policy_type notifier; notifier.add_on_start_thread_callback(pika::util::detail::bind( - &runtime::init_tss_helper, this, prefix, _1, _2, _3, _4, false)); + &runtime::init_tss_helper, this, prefix, _1, _2, _3, _4)); notifier.add_on_stop_thread_callback( pika::util::detail::bind(&runtime::deinit_tss_helper, this, prefix, _1)); notifier.set_on_error_callback(pika::util::detail::bind( @@ -1407,18 +1407,15 @@ namespace pika::detail { } void runtime::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, - bool service_thread) + std::size_t global_thread_num, char const* pool_name, char const* postfix) { error_code ec(throwmode::lightweight); - return init_tss_ex( - context, local_thread_num, global_thread_num, pool_name, postfix, service_thread, ec); + return init_tss_ex(context, local_thread_num, global_thread_num, pool_name, postfix); } // NOLINTBEGIN(bugprone-easily-swappable-parameters) void runtime::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, - bool service_thread, error_code& ec) + std::size_t global_thread_num, char const* pool_name, char const* postfix) // NOLINTEND(bugprone-easily-swappable-parameters) { std::ostringstream fullname; @@ -1459,35 +1456,6 @@ namespace pika::detail { on_start_func_(local_thread_num, global_thread_num, pool_name, context); } - // if this is a service thread, set its service affinity - if (service_thread) - { - // FIXME: We don't set the affinity of the service threads on BG/Q, - // as this is causing a hang (needs to be investigated) -#if !defined(__bgq__) - pika::threads::detail::mask_cref_type used_processing_units = - thread_manager_->get_used_processing_units(); - - // --pika:bind=none should disable all affinity definitions - if (pika::threads::detail::any(used_processing_units)) - { - this->topology_.set_thread_affinity_mask( - this->topology_.get_service_affinity_mask(used_processing_units), ec); - - // comment this out for now as on CircleCI this is causing - // unending grief - // if (ec) - // { - // PIKA_THROW_EXCEPTION(pika::error::kernel_error, - // "runtime::init_tss_ex", - // "failed to set thread affinity mask ({}) for service " - // "thread: {}", - // pika::threads::detail::to_string(used_processing_units), - // detail::thread_name()); - // } - } -#endif - } } void runtime::deinit_tss_helper(char const* context, std::size_t global_thread_num) @@ -1527,13 +1495,12 @@ namespace pika::detail { /// Register an external OS-thread with pika bool runtime::register_thread( - char const* name, std::size_t global_thread_num, bool service_thread, error_code& ec) + char const* name, std::size_t global_thread_num, error_code& ec) { std::string thread_name(name); thread_name += "-thread"; - init_tss_ex(thread_name.c_str(), global_thread_num, global_thread_num, "", nullptr, - service_thread, ec); + init_tss_ex(thread_name.c_str(), global_thread_num, global_thread_num, "", nullptr); return !ec ? true : false; } diff --git a/libs/pika/topology/include/pika/topology/topology.hpp b/libs/pika/topology/include/pika/topology/topology.hpp index 99d612a00..1b00adccf 100644 --- a/libs/pika/topology/include/pika/topology/topology.hpp +++ b/libs/pika/topology/include/pika/topology/topology.hpp @@ -118,18 +118,6 @@ namespace pika::threads::detail { /// the function will throw on error instead. mask_cref_type get_machine_affinity_mask(error_code& ec = throws) const; - /// \brief Return a bit mask where each set bit corresponds to a - /// processing unit available to the service threads in the - /// application. - /// - /// \param used_processing_units [in] This is the mask of processing - /// units which are not available for service threads. - /// \param ec [in,out] this represents the error status on exit, - /// if this is pre-initialized to \a pika#throws - /// the function will throw on error instead. - mask_type get_service_affinity_mask( - mask_cref_type used_processing_units, error_code& ec = throws) const; - /// \brief Return a bit mask where each set bit corresponds to a /// processing unit available to the given thread inside /// the socket it is running on. diff --git a/libs/pika/topology/src/topology.cpp b/libs/pika/topology/src/topology.cpp index 8f2827d82..a97b172b0 100644 --- a/libs/pika/topology/src/topology.cpp +++ b/libs/pika/topology/src/topology.cpp @@ -133,22 +133,6 @@ namespace pika::threads::detail { return os; } - /////////////////////////////////////////////////////////////////////////// - mask_type topology::get_service_affinity_mask( - mask_cref_type used_processing_units, error_code& ec) const - { - // We bind the service threads to the first NUMA domain. This is useful - // as the first NUMA domain is likely to have the PCI controllers etc. - mask_cref_type machine_mask = this->get_numa_node_affinity_mask(0, ec); - if (ec || !any(machine_mask)) return mask_type(); - - if (&ec != &throws) ec = make_success_code(); - - mask_type res = ~used_processing_units & machine_mask; - - return (!any(res)) ? machine_mask : res; - } - bool topology::reduce_thread_priority(error_code& ec) const { PIKA_UNUSED(ec); From db2752f1bb3dda91c6fb7c0648dd69e03fb8d4a3 Mon Sep 17 00:00:00 2001 From: aurianer Date: Tue, 9 Apr 2024 19:02:44 +0200 Subject: [PATCH 5/7] Remove os_thread_type files --- libs/pika/runtime/CMakeLists.txt | 2 -- .../include/pika/runtime/os_thread_type.hpp | 31 ----------------- libs/pika/runtime/src/os_thread_type.cpp | 33 ------------------- 3 files changed, 66 deletions(-) delete mode 100644 libs/pika/runtime/include/pika/runtime/os_thread_type.hpp delete mode 100644 libs/pika/runtime/src/os_thread_type.cpp diff --git a/libs/pika/runtime/CMakeLists.txt b/libs/pika/runtime/CMakeLists.txt index 294234ad1..5acdfedbe 100644 --- a/libs/pika/runtime/CMakeLists.txt +++ b/libs/pika/runtime/CMakeLists.txt @@ -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 @@ -30,7 +29,6 @@ set(runtime_headers set(runtime_sources custom_exception_info.cpp debugging.cpp - os_thread_type.cpp runtime_handlers.cpp runtime.cpp state.cpp diff --git a/libs/pika/runtime/include/pika/runtime/os_thread_type.hpp b/libs/pika/runtime/include/pika/runtime/os_thread_type.hpp deleted file mode 100644 index cd1dcd9fb..000000000 --- a/libs/pika/runtime/include/pika/runtime/os_thread_type.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2020 Hartmut Kaiser -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#include - -#include -#include -#include - -namespace pika { - - /////////////////////////////////////////////////////////////////////////// - /// Types of kernel threads registered with the runtime - enum class os_thread_type - { - unknown = -1, - main_thread = 0, ///< kernel thread represents main thread - worker_thread, ///< kernel thread is used to schedule pika threads - timer_thread, ///< kernel is used by timer operations - custom_thread ///< kernel is registered by the application - }; - - /// Return a human-readable name representing one of the kernel thread types - PIKA_EXPORT std::string get_os_thread_type_name(os_thread_type type); - -} // namespace pika diff --git a/libs/pika/runtime/src/os_thread_type.cpp b/libs/pika/runtime/src/os_thread_type.cpp deleted file mode 100644 index 6a233f06a..000000000 --- a/libs/pika/runtime/src/os_thread_type.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2020 Hartmut Kaiser -// -// SPDX-License-Identifier: BSL-1.0 -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include -#include - -#include - -namespace pika { - - namespace detail { - // clang-format off - static char const* const thread_type_names[] = { - "unknown", - "main-thread", - "worker-thread", - "io-thread", - "timer-thread", - "custom-thread" - }; - // clang-format on - } // namespace detail - - std::string get_os_thread_type_name(os_thread_type type) - { - int idx = static_cast(type); - if (idx < -1 || idx > static_cast(os_thread_type::custom_thread)) { idx = -1; } - return detail::thread_type_names[idx + 1]; - } -} // namespace pika From a036b6cb246de5b743503eeaff392fd54048a2ea Mon Sep 17 00:00:00 2001 From: aurianer Date: Wed, 10 Apr 2024 16:08:28 +0200 Subject: [PATCH 6/7] Remove get_instance_number related to runtime and affinity_data --- .../include/pika/affinity/affinity_data.hpp | 1 - libs/pika/affinity/src/affinity_data.cpp | 3 +-- .../examples/system_characteristics.hpp | 2 +- .../runtime/include/pika/runtime/runtime.hpp | 9 ++------ libs/pika/runtime/src/runtime.cpp | 21 +++---------------- 5 files changed, 7 insertions(+), 29 deletions(-) diff --git a/libs/pika/affinity/include/pika/affinity/affinity_data.hpp b/libs/pika/affinity/include/pika/affinity/affinity_data.hpp index e0dfaeaeb..00df8897c 100644 --- a/libs/pika/affinity/include/pika/affinity/affinity_data.hpp +++ b/libs/pika/affinity/include/pika/affinity/affinity_data.hpp @@ -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 instance_number_counter_; ///< counter for instance numbers }; } // namespace pika::detail diff --git a/libs/pika/affinity/src/affinity_data.cpp b/libs/pika/affinity/src/affinity_data.cpp index 21b6ce9ae..ff21b456b 100644 --- a/libs/pika/affinity/src/affinity_data.cpp +++ b/libs/pika/affinity/src/affinity_data.cpp @@ -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, @@ -285,5 +285,4 @@ namespace pika::detail { return (num_pu + offset) % hardware_concurrency; } - std::atomic affinity_data::instance_number_counter_(-1); } // namespace pika::detail diff --git a/libs/pika/resource_partitioner/examples/system_characteristics.hpp b/libs/pika/resource_partitioner/examples/system_characteristics.hpp index 237d86c4d..76910b3d3 100644 --- a/libs/pika/resource_partitioner/examples/system_characteristics.hpp +++ b/libs/pika/resource_partitioner/examples/system_characteristics.hpp @@ -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 diff --git a/libs/pika/runtime/include/pika/runtime/runtime.hpp b/libs/pika/runtime/include/pika/runtime/runtime.hpp index 78a86b96a..aacc388bd 100644 --- a/libs/pika/runtime/include/pika/runtime/runtime.hpp +++ b/libs/pika/runtime/include/pika/runtime/runtime.hpp @@ -97,8 +97,6 @@ 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(); @@ -290,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, - 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 /// @@ -344,9 +342,6 @@ namespace pika::detail { pika::util::runtime_configuration rtcfg_; - long instance_number_; - static std::atomic instance_number_counter_; - // topology and affinity data pika::threads::detail::topology& topology_; diff --git a/libs/pika/runtime/src/runtime.cpp b/libs/pika/runtime/src/runtime.cpp index 072ab214f..7155cf695 100644 --- a/libs/pika/runtime/src/runtime.cpp +++ b/libs/pika/runtime/src/runtime.cpp @@ -247,7 +247,6 @@ namespace pika::detail { /////////////////////////////////////////////////////////////////////////// runtime::runtime(pika::util::runtime_configuration& rtcfg, bool initialize) : rtcfg_(rtcfg) - , instance_number_(++instance_number_counter_) , topology_(resource::get_partitioner().get_topology()) , state_(pika::runtime_state::invalid) , on_start_func_(global_on_start_func) @@ -273,7 +272,6 @@ namespace pika::detail { // this constructor is called by the distributed runtime only runtime::runtime(pika::util::runtime_configuration& rtcfg) : rtcfg_(rtcfg) - , instance_number_(++instance_number_counter_) , topology_(resource::get_partitioner().get_topology()) , state_(pika::runtime_state::invalid) , on_start_func_(global_on_start_func) @@ -355,9 +353,6 @@ namespace pika::detail { LPROGRESS_; - // allow to reuse instance number if this was the only instance - if (0 == instance_number_counter_) --instance_number_counter_; - resource::detail::delete_partitioner(); #if defined(PIKA_HAVE_GPU_SUPPORT) @@ -389,11 +384,6 @@ namespace pika::detail { pika::util::runtime_configuration const& runtime::get_config() const { return rtcfg_; } - std::size_t runtime::get_instance_number() const - { - return static_cast(instance_number_); - } - pika::runtime_state runtime::get_state() const { return state_.load(); } pika::threads::detail::topology const& runtime::get_topology() const { return topology_; } @@ -404,9 +394,6 @@ namespace pika::detail { state_.store(s); } - /////////////////////////////////////////////////////////////////////////// - std::atomic runtime::instance_number_counter_(-1); - /////////////////////////////////////////////////////////////////////////// namespace { std::chrono::time_point& runtime_uptime() @@ -1396,8 +1383,8 @@ namespace pika::detail { notification_policy_type notifier; - notifier.add_on_start_thread_callback(pika::util::detail::bind( - &runtime::init_tss_helper, this, prefix, _1, _2, _3, _4)); + notifier.add_on_start_thread_callback( + pika::util::detail::bind(&runtime::init_tss_helper, this, prefix, _1, _2, _3, _4)); notifier.add_on_stop_thread_callback( pika::util::detail::bind(&runtime::deinit_tss_helper, this, prefix, _1)); notifier.set_on_error_callback(pika::util::detail::bind( @@ -1455,7 +1442,6 @@ namespace pika::detail { { on_start_func_(local_thread_num, global_thread_num, pool_name, context); } - } void runtime::deinit_tss_helper(char const* context, std::size_t global_thread_num) @@ -1494,8 +1480,7 @@ namespace pika::detail { } /// Register an external OS-thread with pika - bool runtime::register_thread( - char const* name, std::size_t global_thread_num, error_code& ec) + bool runtime::register_thread(char const* name, std::size_t global_thread_num, error_code& ec) { std::string thread_name(name); thread_name += "-thread"; From 158593175d649063465369ebae0896ca508d2f9e Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Mon, 6 May 2024 12:56:15 +0200 Subject: [PATCH 7/7] Add missing include to thread_stacktrace.cpp --- libs/pika/runtime/src/thread_stacktrace.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/pika/runtime/src/thread_stacktrace.cpp b/libs/pika/runtime/src/thread_stacktrace.cpp index 96ee5a36b..af3164a5f 100644 --- a/libs/pika/runtime/src/thread_stacktrace.cpp +++ b/libs/pika/runtime/src/thread_stacktrace.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include #include #include #include