// store all information required for static allocation in // proxies_static_allocation_data // also store new proxy scheduler void resource_manager::preprocess_static_allocation( std::size_t min_punits, std::size_t max_punits) { proxies_map_type::iterator it; proxies_static_allocation_data.clear(); for (proxies_map_type::iterator it = proxies_.begin(); it != proxies_.end(); ++it) { proxy_data& p = (*it).second; static_allocation_data st; st.proxy_ = p.proxy_; // ask executor for its policies error_code ec1(lightweight); st.min_proxy_cores_ = p.proxy_->get_policy_element(detail::min_concurrency, ec1); if (ec1) st.min_proxy_cores_ = 1; st.max_proxy_cores_ = p.proxy_->get_policy_element(detail::max_concurrency, ec1); if (ec1) st.max_proxy_cores_ = get_os_thread_count(); st.num_borrowed_cores_ = 0; st.num_owned_cores_ = 0; for (coreids_type coreids : p.core_ids_) { if (punits_[coreids.first].use_count_ > 1) st.num_borrowed_cores_++; if (punits_[coreids.first].use_count_ == 1) st.num_owned_cores_++; } proxies_static_allocation_data.insert( allocation_data_map_type::value_type((*it).first , st)); } std::size_t cookie = next_cookie_ + 1; static_allocation_data st; st.min_proxy_cores_ = min_punits; st.max_proxy_cores_ = max_punits; st.adjusted_desired_ = static_cast<double>(max_punits); st.num_cores_stolen_ = 0; proxies_static_allocation_data.insert( allocation_data_map_type::value_type(cookie , st)); }
// Request an initial resource allocation std::size_t resource_manager::initial_allocation( detail::manage_executor* proxy, error_code& ec) { if (nullptr == proxy) { HPX_THROWS_IF(ec, bad_parameter, "resource_manager::init_allocation", "manage_executor pointer is a nullptr"); return std::size_t(-1); } // ask executor for its policies error_code ec1(lightweight); std::size_t min_punits = proxy->get_policy_element(detail::min_concurrency, ec1); if (ec1) min_punits = 1; std::size_t max_punits = proxy->get_policy_element(detail::max_concurrency, ec1); if (ec1) max_punits = get_os_thread_count(); // lock the resource manager from this point on std::lock_guard<mutex_type> l(mtx_); // allocate initial resources for the given executor std::vector<std::pair<std::size_t, std::size_t> > cores = allocate_virt_cores(proxy, min_punits, max_punits, ec); if (ec) return std::size_t(-1); // attach the given proxy to this resource manager std::size_t cookie = ++next_cookie_; proxies_.insert(proxies_map_type::value_type( cookie, proxy_data(proxy, std::move(cores)))); if (&ec != &throws) ec = make_success_code(); return cookie; }
threads::thread_state_ex_enum suspend( util::steady_time_point const& abs_time, util::thread_description const& description, error_code& ec) { // schedule a thread waking us up at_time threads::thread_self& self = threads::get_self(); threads::thread_id_type id = threads::get_self_id(); // handle interruption, if needed threads::interruption_point(id, ec); if (ec) return threads::wait_unknown; // let the thread manager do other things while waiting threads::thread_state_ex_enum statex = threads::wait_unknown; { #ifdef HPX_HAVE_VERIFY_LOCKS // verify that there are no more registered locks for this OS-thread util::verify_no_locks(); #endif #ifdef HPX_HAVE_THREAD_DESCRIPTION detail::reset_lco_description desc(id, description, ec); #endif #ifdef HPX_HAVE_THREAD_BACKTRACE_ON_SUSPENSION detail::reset_backtrace bt(id, ec); #endif threads::thread_id_type timer_id = threads::set_thread_state(id, abs_time, threads::pending, threads::wait_timeout, threads::thread_priority_boost, ec); if (ec) return threads::wait_unknown; // suspend the HPX-thread statex = self.yield(threads::suspended); if (statex != threads::wait_timeout) { error_code ec1(lightweight); // do not throw threads::set_thread_state(timer_id, threads::pending, threads::wait_abort, threads::thread_priority_boost, ec1); } } // handle interruption, if needed threads::interruption_point(id, ec); if (ec) return threads::wait_unknown; // handle interrupt and abort if (statex == threads::wait_abort) { std::ostringstream strm; strm << "thread(" << threads::get_self_id() << ", " << threads::get_thread_description(id) << ") aborted (yield returned wait_abort)"; HPX_THROWS_IF(ec, yield_aborted, "suspend_at", strm.str()); } if (&ec != &throws) ec = make_success_code(); return statex; }