Skip to content

Commit

Permalink
Adding enable_elasticity option to pool configuration
Browse files Browse the repository at this point in the history
- fixing performance problem related to get_used_processing_units() for
  non-elastic pools
  • Loading branch information
hkaiser committed Nov 21, 2017
1 parent e7e1ee2 commit b12dd16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions hpx/runtime/threads/detail/scheduled_thread_pool_impl.hpp
Expand Up @@ -1347,6 +1347,14 @@ namespace hpx { namespace threads { namespace detail
std::size_t virt_core, std::size_t thread_num,
std::shared_ptr<compat::barrier> startup, error_code& ec)
{
if (!(mode_ & enable_elasticity))
{
HPX_THROW_EXCEPTION(invalid_status,
"scheduled_thread_pool<Scheduler>::add_processing_unit",
"this thread pool does not support dynamicly adding processing "
"units");
}

resource::get_partitioner().assign_pu(id_.name(), virt_core);

std::unique_lock<pu_mutex_type> l(used_processing_units_mtx_);
Expand Down Expand Up @@ -1397,6 +1405,14 @@ namespace hpx { namespace threads { namespace detail
void scheduled_thread_pool<Scheduler>::remove_processing_unit(
std::size_t virt_core, error_code& ec)
{
if (!(mode_ & enable_elasticity))
{
HPX_THROW_EXCEPTION(invalid_status,
"scheduled_thread_pool<Scheduler>::remove_processing_unit",
"this thread pool does not support dynamicly removing "
"processing units");
}

compat::thread t;

// inform the scheduler to stop the virtual core
Expand Down
3 changes: 2 additions & 1 deletion hpx/runtime/threads/policies/scheduler_mode.hpp
Expand Up @@ -14,7 +14,8 @@ namespace hpx { namespace threads { namespace policies
do_background_work = 0x1,
reduce_thread_priority = 0x02,
delay_exit = 0x04,
fast_idle_mode = 0x08
fast_idle_mode = 0x08,
enable_elasticity = 0x10
};
}}}

Expand Down
7 changes: 7 additions & 0 deletions src/runtime/threads/detail/thread_pool_base.cpp
Expand Up @@ -47,6 +47,13 @@ namespace hpx { namespace threads { namespace detail
///////////////////////////////////////////////////////////////////////////
mask_cref_type thread_pool_base::get_used_processing_units() const
{
if (!(mode_ & threads::policies::enable_elasticity))
{
return used_processing_units_;
}

// FIXME: this is broken as the function returns a reference allowing
// to access the value of the mask without it being guarded.
std::lock_guard<pu_mutex_type> l(used_processing_units_mtx_);
return used_processing_units_;
}
Expand Down

0 comments on commit b12dd16

Please sign in to comment.