Skip to content

Commit

Permalink
Try #664:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Apr 26, 2023
2 parents 42d9a51 + 8f0875b commit c8d5e4e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void init_resource_partitioner_handler(
init.affinity_data_, thread_queue_init, "shared-priority-scheduler");
std::unique_ptr<high_priority_sched> scheduler(new high_priority_sched(scheduler_init));

init.mode_ = scheduler_mode(scheduler_mode::delay_exit);
init.mode_ = scheduler_mode();

std::unique_ptr<pika::threads::detail::thread_pool_base> pool(
new pika::threads::detail::scheduled_thread_pool<high_priority_sched>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ int pika_main(variables_map& vm)
scheduler_mode::steal_high_priority_first);
sched->remove_scheduler_mode(scheduler_mode::assign_work_thread_parent |
scheduler_mode::steal_after_local | scheduler_mode::do_background_work |
scheduler_mode::reduce_thread_priority | scheduler_mode::delay_exit |
scheduler_mode::fast_idle_mode | scheduler_mode::enable_elasticity);
scheduler_mode::reduce_thread_priority | scheduler_mode::enable_elasticity);
}

// setup executors for different task priorities on the pools
Expand Down
3 changes: 1 addition & 2 deletions libs/pika/schedulers/tests/unit/schedule_last.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ void test_scheduler(int argc, char* argv[])

thread_pool_init.mode_ = pika::threads::scheduler_mode(
pika::threads::scheduler_mode::do_background_work |
pika::threads::scheduler_mode::reduce_thread_priority |
pika::threads::scheduler_mode::delay_exit);
pika::threads::scheduler_mode::reduce_thread_priority);

std::unique_ptr<pika::threads::detail::thread_pool_base> pool(
new pika::threads::detail::scheduled_thread_pool<Scheduler>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,10 @@ namespace pika::threads::detail {
bool enable_stealing = scheduler.SchedulingPolicy::has_scheduler_mode(
::pika::threads::scheduler_mode::enable_stealing);

// stealing staged threads is enabled if:
// - fast idle mode is on: same as normal stealing
// - fast idle mode off: only after normal stealing has failed for
// a while
bool enable_stealing_staged = enable_stealing;
if (!scheduler.SchedulingPolicy::has_scheduler_mode(scheduler_mode::fast_idle_mode))
{
enable_stealing_staged =
enable_stealing_staged && idle_loop_count > params.max_idle_loop_count_ / 2;
}
// stealing staged threads is enabled only after normal stealing has
// failed for a while
bool enable_stealing_staged =
enable_stealing && idle_loop_count > params.max_idle_loop_count_ / 2;

if (PIKA_LIKELY(thrd ||
scheduler.SchedulingPolicy::get_next_thread(
Expand Down Expand Up @@ -809,52 +803,12 @@ namespace pika::threads::detail {

if (can_exit)
{
if (!scheduler.SchedulingPolicy::has_scheduler_mode(
scheduler_mode::delay_exit))
{
// If this is an inner scheduler, try to exit immediately
if (background_thread != nullptr)
{
PIKA_ASSERT(background_running);
*background_running = false;
auto priority =
get_thread_id_data(background_thread)->get_priority();

scheduler.SchedulingPolicy::decrement_background_thread_count();
scheduler.SchedulingPolicy::schedule_thread(
PIKA_MOVE(background_thread),
execution::thread_schedule_hint(
static_cast<std::int16_t>(num_thread)),
true, priority);
scheduler.SchedulingPolicy::do_some_work(num_thread);

background_thread = thread_id_type();
background_running.reset();
}
else
{
this_state.store(runtime_state::stopped);
break;
}
}
else
{
// Otherwise, keep idling for some time
if (!may_exit)
idle_loop_count = 0;
may_exit = true;
}
if (!may_exit)
idle_loop_count = 0;
may_exit = true;
}
}
}
else if (!may_exit && added == 0 &&
(scheduler.SchedulingPolicy::has_scheduler_mode(
scheduler_mode::fast_idle_mode)))
{
// speed up idle suspend if no work was stolen
idle_loop_count += params.max_idle_loop_count_ / 1024;
added = std::size_t(-1);
}

if (!call_background_thread(background_thread, next_thrd, scheduler, num_thread,
running, context_storage))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,38 @@ namespace pika::threads {
/// The kernel priority of the os-thread driving the scheduler will be
/// reduced below normal.
reduce_thread_priority = 0x002,
/// The scheduler will wait for some unspecified amount of time before
/// exiting the scheduling loop while being terminated to make sure no
/// other work is being scheduled during processing the shutdown
/// request.
delay_exit = 0x004,
/// Some schedulers have the capability to act as 'embedded'
/// schedulers. In this case it needs to periodically invoke a provided
/// callback into the outer scheduler more frequently than normal. This
/// option enables this behavior.
fast_idle_mode = 0x008,
/// This option allows for the scheduler to dynamically increase and
/// reduce the number of processing units it runs on. Setting this value
/// not succeed for schedulers that do not support this functionality.
enable_elasticity = 0x010,
enable_elasticity = 0x004,
/// This option allows schedulers that support work thread/stealing to
/// enable/disable it
enable_stealing = 0x020,
enable_stealing = 0x008,
/// This option allows schedulersthat support it to disallow stealing
/// between numa domains
enable_stealing_numa = 0x040,
enable_stealing_numa = 0x010,
/// This option tells schedulersthat support it to add tasks round
/// robin to queues on each core
assign_work_round_robin = 0x080,
assign_work_round_robin = 0x020,
/// This option tells schedulers that support it to add tasks round to
/// the same core/queue that the parent task is running on
assign_work_thread_parent = 0x100,
assign_work_thread_parent = 0x040,
/// This option tells schedulers that support it to always (try to)
/// steal high priority tasks from other queues before finishing their
/// own lower priority tasks
steal_high_priority_first = 0x200,
steal_high_priority_first = 0x080,
/// This option tells schedulers that support it to steal tasks only
/// when their local queues are empty
steal_after_local = 0x400,
steal_after_local = 0x100,
/// This option allows for certain schedulers to explicitly disable
/// exponential idle-back off
enable_idle_backoff = 0x0800,
enable_idle_backoff = 0x200,

// clang-format off
/// This option represents the default mode.
default_mode =
do_background_work |
reduce_thread_priority |
delay_exit |
enable_stealing |
enable_stealing_numa |
assign_work_round_robin |
Expand All @@ -76,8 +65,6 @@ namespace pika::threads {
all_flags =
do_background_work |
reduce_thread_priority |
delay_exit |
fast_idle_mode |
enable_elasticity |
enable_stealing |
enable_stealing_numa |
Expand Down

0 comments on commit c8d5e4e

Please sign in to comment.