hpx/threading_base/scheduling_policy.hpp#

Defined in header hpx/threading_base/scheduling_policy.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

The rules that decide when a scheduler wakes up a worker and what an idle worker does, apart from the scheduler that applies them.

namespace hpx
namespace threads
namespace policies

Enums

enum class wake_action : std::uint8_t#

What a scheduler does after it queued a new nano or small thread (see scheduling_policy::wake_for_small).

Values:

enumerator none#

nothing, the calling worker runs the thread once it is done with its current one

enumerator target_if_sleeping#

wake up the worker the thread was queued for if that one sleeps

enumerator one#

wake up one sleeping worker

enumerator all#

as for threads of other sizes (scheduler_base::do_some_work)

struct idle_step#
#include <scheduling_policy.hpp>

What an idle worker does for one backoff period (see scheduling_policy::idle_step_for).

Public Members

std::chrono::microseconds period#

the backoff period

std::uint64_t spin_rounds#

zero: sleep for the period (unless woken up); otherwise spin for this many rounds, or until there is work

std::uint32_t pauses_per_round#

the pause instructions per spin round

std::uint64_t steal_check_rounds#

look at the queues to steal from every this many spin rounds

Both are given also for a period to sleep, for a worker that becomes the sentinel and spins through it instead.

struct scheduling_policy_init_parameters#
#include <scheduling_policy.hpp>

The values from the configuration that the settings of scheduling_policy start with, apart from those that are in thread_queue_init_parameters (rules 6 and 7). Read when a local-priority-tuned-fifo scheduler is created and given to that one only: the local priority queue scheduler doesn’t read them.

Public Members

threads::task_size wake_one_max_size_ = threads::task_size::small_#
bool wake_target_only_ = true#
bool wake_if_nobody_spins_ = true#
bool wake_one_unless_placed_by_caller_ = true#
bool free_pass_after_wake_ = true#
std::uint32_t idle_backoff_spin_round_pauses_ = 16#
struct fixed_scheduling_rules#
#include <scheduling_policy.hpp>

The rules for new threads (2 to 4) at the defaults of their settings, used by the local priority queue scheduler. They decide as scheduling_policy::wake_for_small does at the default settings; see there for the parameters.

Public Functions

inline explicit constexpr fixed_scheduling_rules(std::size_t) noexcept#
template<typename HasSpinningWorker>
inline wake_action wake_for_small(thread_queue_init_parameters const&, std::size_t const target, std::size_t const caller, thread_priority const priority, bool const placed_by_caller, HasSpinningWorker &&has_spinning_worker) const#

Public Static Attributes

static constexpr bool tunes_idle = false#
class scheduling_policy#
#include <scheduling_policy.hpp>

The rules a scheduler applies when it decides whether to wake up a worker for new work and what an idle worker does next. The scheduler supplies the facts (queue lengths, whether workers spin or sleep) and carries out the decision (it keeps the queues and the sleep mask). The numbers and switches the rules use are tunable settings (see scheduler_tuning_parameters), which a tuner may change while the scheduler runs.

Public Functions

void register_idle_parameters(scheduler_tuning_parameters &parameters, thread_queue_init_parameters const &init, scheduling_policy_init_parameters const &policy_init)#

Register the settings of the rules for idle workers (6 to 8), with the values of the given configuration. Done by every scheduler.

void register_wake_parameters(scheduler_tuning_parameters &parameters, scheduling_policy_init_parameters const &policy_init)#

Register the settings of the rules for new threads (1 to 4), with the values of the given configuration. Done only by schedulers that wake up workers for nano and small threads themselves (see scheduler_base::wakes_up_for).

inline bool wakes_one_for(scheduler_tuning_parameters const &parameters, threads::task_size const size) const noexcept#

Rule 1: new threads of this size wake up at most one worker (see wake_for_small), larger and unsized ones wake up workers as before (hpx.scheduler_policy.wake_one_max_size).

template<typename HasSpinningWorker>
inline wake_action wake_for_small(scheduler_tuning_parameters const &parameters, std::size_t const target, std::size_t const caller, thread_priority const priority, bool const placed_by_caller, HasSpinningWorker &&has_spinning_worker) const#

Rules 2 to 4: whom to wake up after a new nano or small thread was queued on the worker target by the worker caller (the calling worker, or -1 for a thread outside of the pool). placed_by_caller tells whether the creator chose the worker (as opposed to round-robin or NUMA placement). has_spinning_worker returns whether an idle worker spins that would find the thread; it is called only if needed.

inline idle_step idle_step_for(scheduler_tuning_parameters const &parameters, std::size_t const worker, std::uint32_t const count, double const spin_rounds_per_us) const noexcept#

Rules 6 and 7: what the given worker does for its backoff period after count periods without work. The period doubles with every one, up to hpx.max_idle_backoff_time. Periods shorter than hpx.min_idle_backoff_time are spent spinning: a timed wait lasts at least the time the OS takes to wake the thread up (a millisecond or more on Windows, the timer slack of 50 us on Linux), so a short sleep would be a long one. A spinning worker looks at its own queues every round, but at the queues it steals from only every hpx.idle_backoff_steal_check_interval microseconds, since that reads the length of the queue of every victim. The spin counts rounds instead of reading the clock: times are converted to rounds with the rate measured at startup (spin_rounds_per_us, for rounds of calibration_pauses_per_round pauses), because a round lasts from a few nanoseconds (yield on AArch64) to most of a microsecond (pause on recent Intel cores).

inline bool free_pass_after_wake(scheduler_tuning_parameters const &parameters) const noexcept#

Rule 8: a worker woken up by a notification may steal once without the early minima of the scheduler (hpx.scheduler_policy.free_pass_after_wake).

Public Static Attributes

static constexpr std::uint32_t calibration_pauses_per_round = 16#

The pause instructions of a spin round the spin rate is measured with, and of the rounds of the schedulers that don’t tune them (see scheduler_base).

Private Members

std::size_t wake_one_max_size_ = scheduler_tuning_parameters::npos#
std::size_t wake_target_only_ = scheduler_tuning_parameters::npos#
std::size_t wake_if_nobody_spins_ = scheduler_tuning_parameters::npos#
std::size_t wake_one_unless_placed_by_caller_ = scheduler_tuning_parameters::npos#
std::size_t max_idle_backoff_time_ = scheduler_tuning_parameters::npos#
std::size_t min_idle_backoff_time_ = scheduler_tuning_parameters::npos#
std::size_t steal_check_interval_ = scheduler_tuning_parameters::npos#
std::size_t pauses_per_round_ = scheduler_tuning_parameters::npos#
std::size_t free_pass_after_wake_ = scheduler_tuning_parameters::npos#
class tuned_scheduling_rules#
#include <scheduling_policy.hpp>

The rules of scheduling_policy together with their tunable settings and the tuner that decides their values, used by the local-priority-tuned-fifo scheduler. wake_for_small has the interface of fixed_scheduling_rules::wake_for_small.

Public Functions

inline explicit tuned_scheduling_rules(std::size_t const num_workers)#
inline void register_parameters(thread_queue_init_parameters const &init, scheduling_policy_init_parameters const &policy_init)#

Register the settings of all rules, with the values of the given configuration.

inline void set_tuner(std::unique_ptr<scheduler_tuner> tuner)#

Set once the scheduler is constructed, before its workers start: the tuner that decides the values of the settings (see hpx.scheduler_tuner).

inline scheduler_tuning_parameters &parameters() noexcept#
inline scheduler_tuning_parameters const &parameters() const noexcept#
inline scheduling_policy const &policy() const noexcept#
template<typename HasSpinningWorker>
inline wake_action wake_for_small(thread_queue_init_parameters const&, std::size_t const target, std::size_t const caller, thread_priority const priority, bool const placed_by_caller, HasSpinningWorker &&has_spinning_worker) const#

Public Static Attributes

static constexpr bool tunes_idle = true#

Private Members

scheduler_tuning_parameters parameters_#
scheduling_policy policy_#
std::unique_ptr<scheduler_tuner> tuner_#