Skip to content

Commit

Permalink
Merge pull request #2483 from STEllAR-GROUP/lifo_scheduler
Browse files Browse the repository at this point in the history
Added priority-queue lifo scheduler
  • Loading branch information
sithhell committed Feb 8, 2017
2 parents 401befd + d6c3359 commit c096523
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 178 deletions.
5 changes: 3 additions & 2 deletions docs/manual/commandline.qbk
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion docs/manual/scheduling_policies.qbk
Expand Up @@ -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
Expand All @@ -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`)
Expand Down
22 changes: 13 additions & 9 deletions hpx/runtime/threads/policies/hierarchy_scheduler.hpp
Expand Up @@ -8,7 +8,10 @@
#define HPX_THREADMANAGER_SCHEDULING_HIERARCHY

#include <hpx/config.hpp>

#if defined(HPX_HAVE_HIERARCHY_SCHEDULER)
#include <hpx/exception_fwd.hpp>
#include <hpx/runtime/threads/policies/lockfree_queue_backends.hpp>
#include <hpx/runtime/threads/policies/scheduler_base.hpp>
#include <hpx/runtime/threads/policies/thread_queue.hpp>
#include <hpx/runtime/threads/thread_data.hpp>
Expand All @@ -18,6 +21,7 @@

#include <boost/atomic.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/thread/mutex.hpp>

#include <cstddef>
#include <cstdint>
Expand All @@ -33,12 +37,11 @@ namespace hpx { namespace threads { namespace policies
///////////////////////////////////////////////////////////////////////////
/// The hierarchy_scheduler maintains a tree of queues of work items
/// (threads). Every OS threads walks that tree to obtain new work
template <typename Mutex
, typename PendingQueuing
, typename StagedQueuing
, typename TerminatedQueuing
>
class hierarchy_scheduler : public scheduler_base
template <typename Mutex = boost::mutex,
typename PendingQueuing = lockfree_fifo,
typename StagedQueuing = lockfree_fifo,
typename TerminatedQueuing = lockfree_lifo>
class HPX_EXPORT hierarchy_scheduler : public scheduler_base
{
private:
// The maximum number of active threads this thread manager should
Expand Down Expand Up @@ -105,14 +108,14 @@ namespace hpx { namespace threads { namespace policies
boost::atomic<bool> v;
flag_type() { v = false; }
flag_type(flag_type const & f) { v.store(f.v.load()); }
flag_type & operator=(flag_type const & f) { v.store(f.v.load());
return *this; }
flag_type & operator=(flag_type const & f)
{ v.store(f.v.load()); return *this; }
flag_type & operator=(bool b) { v.store(b); return *this;}
bool operator==(bool b) { return v == b; }
operator bool() { return v; }
};

typedef std::vector<flag_type > level_flag_type;
typedef std::vector<flag_type> level_flag_type;
typedef std::vector<level_flag_type> flag_tree_type;
flag_tree_type work_flag_tree;
flag_tree_type task_flag_tree;
Expand Down Expand Up @@ -800,4 +803,5 @@ namespace hpx { namespace threads { namespace policies
#include <hpx/config/warnings_suffix.hpp>

#endif
#endif

17 changes: 8 additions & 9 deletions hpx/runtime/threads/policies/local_priority_queue_scheduler.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -9,6 +9,7 @@

#include <hpx/config.hpp>
#include <hpx/runtime/threads/policies/affinity_data.hpp>
#include <hpx/runtime/threads/policies/lockfree_queue_backends.hpp>
#include <hpx/runtime/threads/policies/scheduler_base.hpp>
#include <hpx/runtime/threads/policies/thread_queue.hpp>
#include <hpx/runtime/threads/thread_data.hpp>
Expand All @@ -20,6 +21,7 @@

#include <boost/atomic.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/thread/mutex.hpp>

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -51,12 +53,11 @@ namespace hpx { namespace threads { namespace policies
/// High priority threads are executed by the first N OS threads before any
/// other work is executed. Low priority threads are executed by the last
/// OS thread whenever no other work is available.
template <typename Mutex
, typename PendingQueuing
, typename StagedQueuing
, typename TerminatedQueuing
>
class local_priority_queue_scheduler : public scheduler_base
template <typename Mutex = boost::mutex,
typename PendingQueuing = lockfree_fifo,
typename StagedQueuing = lockfree_fifo,
typename TerminatedQueuing = lockfree_lifo>
class HPX_EXPORT local_priority_queue_scheduler : public scheduler_base
{
protected:
// The maximum number of active threads this thread manager should
Expand Down Expand Up @@ -934,7 +935,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)))
Expand Down Expand Up @@ -1117,7 +1117,6 @@ namespace hpx { namespace threads { namespace policies
}

protected:
boost::mutex void_mtx_;
std::size_t max_queue_thread_count_;
std::vector<thread_queue_type*> queues_;
std::vector<thread_queue_type*> high_priority_queues_;
Expand Down
18 changes: 11 additions & 7 deletions hpx/runtime/threads/policies/local_queue_scheduler.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -8,7 +8,10 @@
#define HPX_THREADMANAGER_SCHEDULING_LOCAL_QUEUE_MAR_15_2011_0926AM

#include <hpx/config.hpp>

#if defined(HPX_HAVE_LOCAL_SCHEDULER)
#include <hpx/runtime/threads/policies/affinity_data.hpp>
#include <hpx/runtime/threads/policies/lockfree_queue_backends.hpp>
#include <hpx/runtime/threads/policies/scheduler_base.hpp>
#include <hpx/runtime/threads/policies/thread_queue.hpp>
#include <hpx/runtime/threads/thread_data.hpp>
Expand All @@ -20,6 +23,7 @@

#include <boost/atomic.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/thread/mutex.hpp>

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -47,12 +51,11 @@ namespace hpx { namespace threads { namespace policies
/// The local_queue_scheduler maintains exactly one queue of work
/// items (threads) per OS thread, where this OS thread pulls its next work
/// from.
template <typename Mutex
, typename PendingQueuing
, typename StagedQueuing
, typename TerminatedQueuing
>
class local_queue_scheduler : public scheduler_base
template <typename Mutex = boost::mutex,
typename PendingQueuing = lockfree_fifo,
typename StagedQueuing = lockfree_fifo,
typename TerminatedQueuing = lockfree_lifo>
class HPX_EXPORT local_queue_scheduler : public scheduler_base
{
protected:
// The maximum number of active threads this thread manager should
Expand Down Expand Up @@ -813,4 +816,5 @@ namespace hpx { namespace threads { namespace policies
#include <hpx/config/warnings_suffix.hpp>

#endif
#endif

18 changes: 11 additions & 7 deletions hpx/runtime/threads/policies/periodic_priority_queue_scheduler.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
// Copyright (c) 2011 Thomas Heller
//
Expand All @@ -9,11 +9,15 @@
#define HPX_THREADMANAGER_SCHEDULING_PERIODIC_PRIORITY_QUEUE_HPP

#include <hpx/config.hpp>

#if defined(HPX_HAVE_PERIODIC_PRIORITY_SCHEDULER)
#include <hpx/runtime/threads/detail/periodic_maintenance.hpp>
#include <hpx/runtime/threads/policies/local_priority_queue_scheduler.hpp>
#include <hpx/runtime/threads/policies/lockfree_queue_backends.hpp>
#include <hpx/runtime/threads_fwd.hpp>

#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>

#include <cstddef>
#include <cstdint>
Expand All @@ -33,12 +37,11 @@ namespace hpx { namespace threads { namespace policies
/// High priority threads are executed by the first N OS threads before any
/// other work is executed. Low priority threads are executed by the last
/// OS thread whenever no other work is available.
template <typename Mutex
, typename PendingQueuing
, typename StagedQueuing
, typename TerminatedQueuing
>
class periodic_priority_queue_scheduler
template <typename Mutex = boost::mutex,
typename PendingQueuing = lockfree_fifo,
typename StagedQueuing = lockfree_fifo,
typename TerminatedQueuing = lockfree_lifo>
class HPX_EXPORT periodic_priority_queue_scheduler
: public local_priority_queue_scheduler<
Mutex, PendingQueuing, StagedQueuing, TerminatedQueuing
>
Expand Down Expand Up @@ -234,3 +237,4 @@ namespace hpx { namespace threads { namespace policies
#include <hpx/config/warnings_suffix.hpp>

#endif
#endif
20 changes: 13 additions & 7 deletions hpx/runtime/threads/policies/static_priority_queue_scheduler.hpp
@@ -1,5 +1,5 @@
// Copyright (c) 2013 Thomas Heller
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -9,8 +9,14 @@
#define HPX_THREADMANAGER_SCHEDULING_STATIC_PRIOTITY_QUEUE_HPP

#include <hpx/config.hpp>

#if defined(HPX_HAVE_STATIC_PRIORITY_SCHEDULER)
#include <hpx/runtime/threads/policies/lockfree_queue_backends.hpp>
#include <hpx/runtime/threads/policies/local_priority_queue_scheduler.hpp>
#include <hpx/runtime/threads_fwd.hpp>
#include <hpx/util/assert.hpp>

#include <boost/thread/mutex.hpp>

#include <cstddef>
#include <cstdint>
Expand All @@ -30,12 +36,11 @@ namespace hpx { namespace threads { namespace policies
/// other work is executed. Low priority threads are executed by the last
/// OS thread whenever no other work is available.
/// This scheduler does not do any work stealing.
template <typename Mutex
, typename PendingQueuing
, typename StagedQueuing
, typename TerminatedQueuing
>
class static_priority_queue_scheduler
template <typename Mutex = boost::mutex,
typename PendingQueuing = lockfree_fifo,
typename StagedQueuing = lockfree_fifo,
typename TerminatedQueuing = lockfree_lifo>
class HPX_EXPORT static_priority_queue_scheduler
: public local_priority_queue_scheduler<
Mutex, PendingQueuing, StagedQueuing, TerminatedQueuing
>
Expand Down Expand Up @@ -161,4 +166,5 @@ namespace hpx { namespace threads { namespace policies
#include <hpx/config/warnings_suffix.hpp>

#endif
#endif

19 changes: 11 additions & 8 deletions hpx/runtime/threads/policies/static_queue_scheduler.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -8,16 +8,19 @@
#define HPX_THREADMANAGER_SCHEDULING_STATIC_QUEUE_JUL_22_2015_0103PM

#include <hpx/config.hpp>

#if defined(HPX_HAVE_STATIC_SCHEDULER)
#include <hpx/runtime/threads/policies/affinity_data.hpp>
#include <hpx/runtime/threads/policies/local_queue_scheduler.hpp>
#include <hpx/runtime/threads/policies/scheduler_base.hpp>
#include <hpx/runtime/threads/policies/lockfree_queue_backends.hpp>
#include <hpx/runtime/threads/policies/thread_queue.hpp>
#include <hpx/runtime/threads/thread_data.hpp>
#include <hpx/runtime/threads/topology.hpp>
#include <hpx/runtime/threads_fwd.hpp>
#include <hpx/util/assert.hpp>
#include <hpx/util/logging.hpp>

#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>

#include <cstddef>
#include <cstdint>
Expand All @@ -44,11 +47,10 @@ namespace hpx { namespace threads { namespace policies
/// The local_queue_scheduler maintains exactly one queue of work
/// items (threads) per OS thread, where this OS thread pulls its next work
/// from.
template <typename Mutex
, typename PendingQueuing
, typename StagedQueuing
, typename TerminatedQueuing
>
template <typename Mutex = boost::mutex,
typename PendingQueuing = lockfree_fifo,
typename StagedQueuing = lockfree_fifo,
typename TerminatedQueuing = lockfree_lifo>
class static_queue_scheduler
: public local_queue_scheduler<
Mutex, PendingQueuing, StagedQueuing, TerminatedQueuing
Expand Down Expand Up @@ -147,4 +149,5 @@ namespace hpx { namespace threads { namespace policies
#include <hpx/config/warnings_suffix.hpp>

#endif
#endif

18 changes: 9 additions & 9 deletions hpx/runtime/threads/policies/throttle_queue_scheduler.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
// Copyright (c) 2014 Allan Porterfield
//
Expand All @@ -10,12 +10,13 @@

#include <hpx/config.hpp>

#if defined(HPX_HAVE_THROTTLE_SCHEDULER)

#if defined(HPX_HAVE_THROTTLE_SCHEDULER) && defined(HPX_HAVE_APEX)
#include <hpx/runtime/threads/policies/local_queue_scheduler.hpp>
#include <hpx/runtime/threads_fwd.hpp>

#include <apex_api.hpp>

#include <boost/thread/mutex.hpp>
#include <boost/thread/shared_mutex.hpp>

#include <cstddef>
Expand Down Expand Up @@ -68,12 +69,11 @@ namespace hpx { namespace threads { namespace policies
/// The throttle_queue_scheduler maintains exactly one queue of work
/// items (threads) per OS thread, where this OS thread pulls its next work
/// from.
template <typename Mutex
, typename PendingQueuing
, typename StagedQueuing
, typename TerminatedQueuing
>
class throttle_queue_scheduler
template <typename Mutex = boost::mutex,
typename PendingQueuing = lockfree_fifo,
typename StagedQueuing = lockfree_fifo,
typename TerminatedQueuing = lockfree_lifo>
class HPX_EXPORT throttle_queue_scheduler
: public local_queue_scheduler<
Mutex, PendingQueuing, StagedQueuing, TerminatedQueuing>
{
Expand Down
2 changes: 2 additions & 0 deletions hpx/runtime/threads/thread_data_fwd.hpp
Expand Up @@ -13,6 +13,8 @@
#include <hpx/runtime/threads/coroutines/coroutine_fwd.hpp>
#include <hpx/runtime/threads/thread_enums.hpp>
#include <hpx/util_fwd.hpp>
#include <hpx/util/function.hpp>
#include <hpx/util/unique_function.hpp>

#include <boost/intrusive_ptr.hpp>

Expand Down

0 comments on commit c096523

Please sign in to comment.