From b5d852b27d3494fa50aac737d7b344b72f17d1ab Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Mon, 24 Apr 2023 17:47:06 +0200 Subject: [PATCH] Remove fast_idle and delay_exit scheduler modes and related scheduling loop checks --- .../examples/guided_pool_test.cpp | 2 +- .../tests/unit/scheduler_priority_check.cpp | 1 - .../schedulers/tests/unit/schedule_last.cpp | 3 +- .../pika/thread_pools/scheduling_loop.hpp | 38 ++++--------------- .../pika/threading_base/scheduler_mode.hpp | 29 ++++---------- 5 files changed, 17 insertions(+), 56 deletions(-) diff --git a/libs/pika/resource_partitioner/examples/guided_pool_test.cpp b/libs/pika/resource_partitioner/examples/guided_pool_test.cpp index 685fb17c4..bfd06b2ab 100644 --- a/libs/pika/resource_partitioner/examples/guided_pool_test.cpp +++ b/libs/pika/resource_partitioner/examples/guided_pool_test.cpp @@ -229,7 +229,7 @@ void init_resource_partitioner_handler( init.affinity_data_, thread_queue_init, "shared-priority-scheduler"); std::unique_ptr scheduler(new high_priority_sched(scheduler_init)); - init.mode_ = scheduler_mode(scheduler_mode::delay_exit); + init.mode_ = scheduler_mode(); std::unique_ptr pool( new pika::threads::detail::scheduled_thread_pool( diff --git a/libs/pika/resource_partitioner/tests/unit/scheduler_priority_check.cpp b/libs/pika/resource_partitioner/tests/unit/scheduler_priority_check.cpp index 213dc729d..2c4985814 100644 --- a/libs/pika/resource_partitioner/tests/unit/scheduler_priority_check.cpp +++ b/libs/pika/resource_partitioner/tests/unit/scheduler_priority_check.cpp @@ -62,7 +62,6 @@ 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::reduce_thread_priority | - scheduler_mode::delay_exit | scheduler_mode::fast_idle_mode | scheduler_mode::enable_elasticity); } diff --git a/libs/pika/schedulers/tests/unit/schedule_last.cpp b/libs/pika/schedulers/tests/unit/schedule_last.cpp index 121d704b8..25844c35c 100644 --- a/libs/pika/schedulers/tests/unit/schedule_last.cpp +++ b/libs/pika/schedulers/tests/unit/schedule_last.cpp @@ -52,8 +52,7 @@ void test_scheduler(int argc, char* argv[]) std::unique_ptr scheduler(new Scheduler(init)); thread_pool_init.mode_ = pika::threads::scheduler_mode( - pika::threads::scheduler_mode::reduce_thread_priority | - pika::threads::scheduler_mode::delay_exit); + pika::threads::scheduler_mode::reduce_thread_priority); std::unique_ptr pool( new pika::threads::detail::scheduled_thread_pool( diff --git a/libs/pika/thread_pools/include/pika/thread_pools/scheduling_loop.hpp b/libs/pika/thread_pools/include/pika/thread_pools/scheduling_loop.hpp index 59836b67e..f3fc43320 100644 --- a/libs/pika/thread_pools/include/pika/thread_pools/scheduling_loop.hpp +++ b/libs/pika/thread_pools/include/pika/thread_pools/scheduling_loop.hpp @@ -414,16 +414,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( @@ -679,30 +673,12 @@ namespace pika::threads::detail { if (can_exit) { - if (!scheduler.SchedulingPolicy::has_scheduler_mode( - scheduler_mode::delay_exit)) - { - 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); - } // call back into invoking context if (!params.inner_.empty()) diff --git a/libs/pika/threading_base/include/pika/threading_base/scheduler_mode.hpp b/libs/pika/threading_base/include/pika/threading_base/scheduler_mode.hpp index c41136888..19f5775d7 100644 --- a/libs/pika/threading_base/include/pika/threading_base/scheduler_mode.hpp +++ b/libs/pika/threading_base/include/pika/threading_base/scheduler_mode.hpp @@ -20,48 +20,37 @@ namespace pika::threads { /// The kernel priority of the os-thread driving the scheduler will be /// reduced below normal. reduce_thread_priority = 0x001, - /// 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 = 0x002, - /// 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 = 0x004, /// 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 = 0x008, + enable_elasticity = 0x002, /// This option allows schedulers that support work thread/stealing to /// enable/disable it - enable_stealing = 0x010, + enable_stealing = 0x004, /// This option allows schedulersthat support it to disallow stealing /// between numa domains - enable_stealing_numa = 0x020, + enable_stealing_numa = 0x008, /// This option tells schedulersthat support it to add tasks round /// robin to queues on each core - assign_work_round_robin = 0x040, + assign_work_round_robin = 0x010, /// 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 = 0x080, + assign_work_thread_parent = 0x020, /// 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 = 0x100, + steal_high_priority_first = 0x040, /// This option tells schedulers that support it to steal tasks only /// when their local queues are empty - steal_after_local = 0x200, + steal_after_local = 0x080, /// This option allows for certain schedulers to explicitly disable /// exponential idle-back off - enable_idle_backoff = 0x0400, + enable_idle_backoff = 0x100, // clang-format off /// This option represents the default mode. default_mode = reduce_thread_priority | - delay_exit | enable_stealing | enable_stealing_numa | assign_work_round_robin | @@ -70,8 +59,6 @@ namespace pika::threads { /// This enables all available options. all_flags = reduce_thread_priority | - delay_exit | - fast_idle_mode | enable_elasticity | enable_stealing | enable_stealing_numa |