Skip to content

Commit

Permalink
Merge pull request #3046 from msimberg/suspend-thread
Browse files Browse the repository at this point in the history
Add OS thread suspension
  • Loading branch information
sithhell committed Dec 8, 2017
2 parents 141890e + 903664d commit 82f7b28
Show file tree
Hide file tree
Showing 24 changed files with 943 additions and 296 deletions.
7 changes: 6 additions & 1 deletion examples/resource_partitioner/shared_priority_scheduler.hpp
Expand Up @@ -565,7 +565,7 @@ namespace threads {
}

///////////////////////////////////////////////////////////////////////
bool cleanup_terminated(bool delete_all = false)
bool cleanup_terminated(bool delete_all)
{
bool empty = true;
for (std::size_t i = 0; i != queues_.size(); ++i)
Expand Down Expand Up @@ -593,6 +593,11 @@ namespace threads {
return empty;
}

bool cleanup_terminated(std::size_t num_threads, bool delete_all)
{
return cleanup_terminated(delete_all);
}

///////////////////////////////////////////////////////////////////////
// create a new thread and schedule it if the initial state is equal
// to pending
Expand Down
35 changes: 35 additions & 0 deletions hpx/runtime/threads/detail/scheduled_thread_pool.hpp
Expand Up @@ -103,6 +103,11 @@ namespace hpx { namespace threads { namespace detail
state, priority, num, reset);
}

std::int64_t get_background_thread_count()
{
return sched_->Scheduler::get_background_thread_count();
}

bool enumerate_threads(
util::function_nonser<bool(thread_id_type)> const& f,
thread_state_enum state) const
Expand All @@ -117,6 +122,7 @@ namespace hpx { namespace threads { namespace detail

void set_scheduler_mode(threads::policies::scheduler_mode mode)
{
mode_ = mode;
return sched_->Scheduler::set_scheduler_mode(mode);
}

Expand All @@ -127,6 +133,8 @@ namespace hpx { namespace threads { namespace detail
void stop_locked(Lock& l, bool blocking = true);
void stop (std::unique_lock<compat::mutex>& l, bool blocking = true);

void resume(error_code& ec = throws);

///////////////////////////////////////////////////////////////////
compat::thread& get_os_thread_handle(std::size_t global_thread_num)
{
Expand All @@ -144,6 +152,22 @@ namespace hpx { namespace threads { namespace detail
return threads_.size();
}

std::size_t get_active_os_thread_count() const
{
std::size_t active_os_thread_count = 0;
for (std::size_t thread_num = 0; thread_num < threads_.size();
++thread_num)
{
if (sched_->Scheduler::get_state(thread_num).load() ==
state_running)
{
++active_os_thread_count;
}
}

return active_os_thread_count;
}

#ifdef HPX_HAVE_THREAD_STEALING_COUNTS
std::int64_t get_num_pending_misses(std::size_t num, bool reset)
{
Expand Down Expand Up @@ -242,6 +266,12 @@ namespace hpx { namespace threads { namespace detail
void remove_processing_unit(
std::size_t virt_core, error_code& = hpx::throws);

// Suspend the given processing unit on the scheduler.
void suspend_processing_unit(std::size_t virt_core, error_code&);

// Resume the given processing unit on the scheduler.
void resume_processing_unit(std::size_t virt_core, error_code&);

protected:
friend struct init_tss_helper<Scheduler>;

Expand All @@ -251,6 +281,11 @@ namespace hpx { namespace threads { namespace detail
std::size_t thread_num, std::shared_ptr<compat::barrier> startup,
error_code& ec = hpx::throws);

void suspend_processing_unit_internal(std::size_t virt_core,
error_code& = hpx::throws);
void resume_processing_unit_internal(std::size_t virt_core,
error_code& = hpx::throws);

private:
std::vector<compat::thread> threads_; // vector of OS-threads

Expand Down

0 comments on commit 82f7b28

Please sign in to comment.