From 57f3d8db4a50bd84c02765ba0d0aa927b3f1e9d5 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sat, 4 Feb 2017 20:25:48 -0600 Subject: [PATCH] Added priority-queue lifo scheduler - flyby: removed unneeded #includes - flyby: removed unneeded type definitions --- docs/manual/commandline.qbk | 5 ++- docs/manual/scheduling_policies.qbk | 7 +++- .../local_priority_queue_scheduler.hpp | 2 - .../policies/static_queue_scheduler.hpp | 2 - hpx/runtime/threads_fwd.hpp | 22 ----------- src/hpx_init.cpp | 38 +++++++++++++------ src/runtime/threads/detail/thread_pool.cpp | 12 +++++- src/runtime/threads/threadmanager.cpp | 12 +++++- src/runtime_impl.cpp | 12 +++++- src/util/command_line_handling.cpp | 2 +- src/util/parse_command_line.cpp | 3 +- src/util/runtime_configuration.cpp | 2 +- 12 files changed, 70 insertions(+), 49 deletions(-) diff --git a/docs/manual/commandline.qbk b/docs/manual/commandline.qbk index ac80ffb8f7f0..382cbf913fc7 100644 --- a/docs/manual/commandline.qbk +++ b/docs/manual/commandline.qbk @@ -85,8 +85,9 @@ described in the table below: [[`--hpx:print-bind`] [print to the console the bit masks calculated from the arguments specified to all `--hpx:bind` options.]] [[`--hpx:queuing arg`] [the queue scheduling policy to use, options are - 'local/l', 'local-priority/lo', 'abp/a', 'abp-priority', - 'hierarchy/h', and 'periodic/pe' (default: local-priority/lo)]] + 'local/l', 'local-priority-fifo/lo', 'local-priority-lifo', 'abp/a', + 'abp-priority', 'hierarchy/h', and 'periodic/pe' + (default: local-priority-fifo/lo)]] [[`--hpx:hierarchy-arity`] [the arity of the of the thread queue tree, valid for `--hpx:queuing=hierarchy` only (default: 2)]] [[`--hpx:high-priority-threads arg`] [the number of operating system threads diff --git a/docs/manual/scheduling_policies.qbk b/docs/manual/scheduling_policies.qbk index cef36c7ba38b..d26f05c88079 100644 --- a/docs/manual/scheduling_policies.qbk +++ b/docs/manual/scheduling_policies.qbk @@ -19,7 +19,7 @@ information). [heading Priority Local Scheduling Policy (default policy)] -* default or invoke using: [hpx_cmdline `--hpx:queuing=local-priority`] (or `-qpr`) +* default or invoke using: [hpx_cmdline `--hpx:queuing=local-priority-fifo`] (or `-qlo`) The priority local scheduling policy maintains one queue per operating system (OS) thread. The OS thread pulls its work from this queue. By default the number @@ -38,6 +38,11 @@ same NUMA domain first, only after that work is stolen from other NUMA domains. This scheduler is enabled at build time by default and will be available always. +This scheduler can be used with two underlying queueing policies (FIFO: +first-in-first-out, and LIFO: last-in-first-out). The default is FIFO. In order +to use the LIFO policiy use the command line option +[hpx_cmdline `--hpx:queuing=local-priority-lifo`]. + [heading Static Priority Scheduling Policy] * invoke using: [hpx_cmdline `--hpx:queuing=static-priority`] (or `-qs`) diff --git a/hpx/runtime/threads/policies/local_priority_queue_scheduler.hpp b/hpx/runtime/threads/policies/local_priority_queue_scheduler.hpp index e90285230069..1c3fc155a095 100644 --- a/hpx/runtime/threads/policies/local_priority_queue_scheduler.hpp +++ b/hpx/runtime/threads/policies/local_priority_queue_scheduler.hpp @@ -934,7 +934,6 @@ namespace hpx { namespace threads { namespace policies } } - #ifdef HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION // no new work is available, are we deadlocked? if (HPX_UNLIKELY(minimal_deadlock_detection && LHPX_ENABLED(error))) @@ -1117,7 +1116,6 @@ namespace hpx { namespace threads { namespace policies } protected: - boost::mutex void_mtx_; std::size_t max_queue_thread_count_; std::vector queues_; std::vector high_priority_queues_; diff --git a/hpx/runtime/threads/policies/static_queue_scheduler.hpp b/hpx/runtime/threads/policies/static_queue_scheduler.hpp index 8bf29169fcc9..d0e5a60ad0f4 100644 --- a/hpx/runtime/threads/policies/static_queue_scheduler.hpp +++ b/hpx/runtime/threads/policies/static_queue_scheduler.hpp @@ -17,8 +17,6 @@ #include #include -#include - #include #include #include diff --git a/hpx/runtime/threads_fwd.hpp b/hpx/runtime/threads_fwd.hpp index a97fda25d6fc..63c451870340 100644 --- a/hpx/runtime/threads_fwd.hpp +++ b/hpx/runtime/threads_fwd.hpp @@ -94,28 +94,6 @@ namespace hpx class HPX_EXPORT hierarchy_scheduler; #endif - typedef local_priority_queue_scheduler< - boost::mutex, - lockfree_fifo, // FIFO pending queuing - lockfree_fifo, // FIFO staged queuing - lockfree_lifo // LIFO terminated queuing - > fifo_priority_queue_scheduler; - -#if defined(HPX_HAVE_ABP_SCHEDULER) - struct lockfree_abp_fifo; - struct lockfree_abp_lifo; - - typedef local_priority_queue_scheduler< - boost::mutex, - lockfree_abp_fifo, // FIFO + ABP pending queuing - lockfree_abp_fifo, // FIFO + ABP staged queuing - lockfree_lifo // LIFO terminated queuing - > abp_fifo_priority_queue_scheduler; -#endif - - // define the default scheduler to use - typedef fifo_priority_queue_scheduler queue_scheduler; - class HPX_EXPORT callback_notifier; } diff --git a/src/hpx_init.cpp b/src/hpx_init.cpp index ab95d190a3ad..f59ce33b9164 100644 --- a/src/hpx_init.cpp +++ b/src/hpx_init.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2013 Hartmut Kaiser +// Copyright (c) 2007-2017 Hartmut Kaiser // Copyright (c) 2010-2011 Phillip LeBlanc, Dylan Stark // Copyright (c) 2011 Bryce Lelbach // @@ -899,6 +899,7 @@ namespace hpx /////////////////////////////////////////////////////////////////////// // local scheduler with priority queue (one queue for each OS threads // plus one separate queue for high priority HPX-threads) + template int run_priority_local(startup_function_type startup, shutdown_function_type shutdown, util::command_line_handling& cfg, bool blocking) @@ -915,9 +916,11 @@ namespace hpx get_affinity_description(cfg, affinity_desc); // scheduling policy - typedef hpx::threads::policies:: local_priority_queue_scheduler<> - local_queue_policy; - local_queue_policy::init_parameter_type init( + typedef hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, Queuing + > local_queue_policy; + + typename local_queue_policy::init_parameter_type init( cfg.num_threads_, num_high_priority_queues, 1000, numa_sensitive, "core-local_priority_queue_scheduler"); threads::policies::init_affinity_data affinity_init( @@ -934,7 +937,7 @@ namespace hpx } /////////////////////////////////////////////////////////////////////// - // priority abp scheduler: local priority deques for each OS thread, + // priority abp scheduler: local priority dequeues for each OS thread, // with work stealing from the "bottom" of each. int run_priority_abp(startup_function_type startup, shutdown_function_type shutdown, @@ -948,8 +951,10 @@ namespace hpx get_num_high_priority_queues(cfg); // scheduling policy - typedef hpx::threads::policies::abp_fifo_priority_queue_scheduler - abp_priority_queue_policy; + typedef hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_fifo + > abp_priority_queue_policy; + abp_priority_queue_policy::init_parameter_type init( cfg.num_threads_, num_high_priority_queues, 1000, cfg.numa_sensitive_, "core-abp_fifo_priority_queue_scheduler"); @@ -1108,14 +1113,25 @@ namespace hpx result = run_static(std::move(startup), std::move(shutdown), cfg, blocking); } - else if (0 == std::string("local-priority").find(cfg.queuing_)) + else if (0 == std::string("local-priority-fifo").find(cfg.queuing_)) { // local scheduler with priority queue (one queue for each // OS thread plus separate dequeues for low/high priority /// HPX-threads) - cfg.queuing_ = "local-priority"; - result = run_priority_local(std::move(startup), - std::move(shutdown), cfg, blocking); + cfg.queuing_ = "local-priority-fifo"; + result = run_priority_local< + hpx::threads::policies::lockfree_fifo + >(std::move(startup), std::move(shutdown), cfg, blocking); + } + else if (0 == std::string("local-priority-lifo").find(cfg.queuing_)) + { + // local scheduler with priority queue (one queue for each + // OS thread plus separate dequeues for low/high priority + /// HPX-threads) + cfg.queuing_ = "local-priority-lifo"; + result = run_priority_local< + hpx::threads::policies::lockfree_lifo + >(std::move(startup), std::move(shutdown), cfg, blocking); } else if (0 == std::string("static-priority").find(cfg.queuing_)) { diff --git a/src/runtime/threads/detail/thread_pool.cpp b/src/runtime/threads/detail/thread_pool.cpp index 6f5d3aeb9d57..c47fa0cbae73 100644 --- a/src/runtime/threads/detail/thread_pool.cpp +++ b/src/runtime/threads/detail/thread_pool.cpp @@ -1434,11 +1434,19 @@ template class HPX_EXPORT hpx::threads::detail::thread_pool< #include template class HPX_EXPORT hpx::threads::detail::thread_pool< - hpx::threads::policies::local_priority_queue_scheduler<> >; + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_fifo + > >; +template class HPX_EXPORT hpx::threads::detail::thread_pool< + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_lifo + > >; #if defined(HPX_HAVE_ABP_SCHEDULER) template class HPX_EXPORT hpx::threads::detail::thread_pool< - hpx::threads::policies::abp_fifo_priority_queue_scheduler>; + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_abp_fifo + > >; #endif #if defined(HPX_HAVE_HIERARCHY_SCHEDULER) diff --git a/src/runtime/threads/threadmanager.cpp b/src/runtime/threads/threadmanager.cpp index ed57314e9c94..393ed72a57e4 100644 --- a/src/runtime/threads/threadmanager.cpp +++ b/src/runtime/threads/threadmanager.cpp @@ -1313,11 +1313,19 @@ template class HPX_EXPORT hpx::threads::threadmanager_impl< #include template class HPX_EXPORT hpx::threads::threadmanager_impl< - hpx::threads::policies::local_priority_queue_scheduler<> >; + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_fifo + > >; +template class HPX_EXPORT hpx::threads::threadmanager_impl< + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_lifo + > >; #if defined(HPX_HAVE_ABP_SCHEDULER) template class HPX_EXPORT hpx::threads::threadmanager_impl< - hpx::threads::policies::abp_fifo_priority_queue_scheduler>; + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_abp_fifo + > >; #endif #if defined(HPX_HAVE_HIERARCHY_SCHEDULER) diff --git a/src/runtime_impl.cpp b/src/runtime_impl.cpp index 0785d088afac..4d585779f7a8 100644 --- a/src/runtime_impl.cpp +++ b/src/runtime_impl.cpp @@ -875,11 +875,19 @@ template class HPX_EXPORT hpx::runtime_impl< #include template class HPX_EXPORT hpx::runtime_impl< - hpx::threads::policies::local_priority_queue_scheduler<> >; + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_fifo + > >; +template class HPX_EXPORT hpx::runtime_impl< + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_lifo + > >; #if defined(HPX_HAVE_ABP_SCHEDULER) template class HPX_EXPORT hpx::runtime_impl< - hpx::threads::policies::abp_fifo_priority_queue_scheduler>; + hpx::threads::policies::local_priority_queue_scheduler< + boost::mutex, hpx::threads::policies::lockfree_abp_fifo + > >; #endif #if defined(HPX_HAVE_HIERARCHY_SCHEDULER) diff --git a/src/util/command_line_handling.cpp b/src/util/command_line_handling.cpp index bf1dee2682e6..c5bc96ecf191 100644 --- a/src/util/command_line_handling.cpp +++ b/src/util/command_line_handling.cpp @@ -674,7 +674,7 @@ namespace hpx { namespace util } // handle setting related to schedulers - queuing_ = detail::handle_queueing(cfgmap, vm, "local-priority"); + queuing_ = detail::handle_queueing(cfgmap, vm, "local-priority-fifo"); ini_config += "hpx.scheduler=" + queuing_; affinity_domain_ = detail::handle_affinity(cfgmap, vm, "pu"); diff --git a/src/util/parse_command_line.cpp b/src/util/parse_command_line.cpp index 012cb67330e1..cb4e4f33d6a3 100644 --- a/src/util/parse_command_line.cpp +++ b/src/util/parse_command_line.cpp @@ -451,7 +451,8 @@ namespace hpx { namespace util "the number of total cores in the system)") ("hpx:queuing", value(), "the queue scheduling policy to use, options are " - "'local', 'local-priority', 'abp-priority', " + "'local', 'local-priority-fifo','local-priority-lifo', " + "'abp-priority', " "'hierarchy', 'static', 'static-priority', and " "'periodic-priority' (default: 'local-priority'; " "all option values can be abbreviated)") diff --git a/src/util/runtime_configuration.cpp b/src/util/runtime_configuration.cpp index 1d9f3999ff03..d845988b0cae 100644 --- a/src/util/runtime_configuration.cpp +++ b/src/util/runtime_configuration.cpp @@ -181,7 +181,7 @@ namespace hpx { namespace util "localities = 1", "first_pu = 0", "runtime_mode = console", - "scheduler = local-priority", + "scheduler = local-priority-fifo", "affinity = pu", "pu_step = 1", "pu_offset = 0",