21 #ifndef _TBB_scheduler_H 22 #define _TBB_scheduler_H 29 #include "../rml/include/rml_tbb.h" 33 #if __TBB_SURVIVE_THREAD_SWITCH 40 template<
typename SchedulerTraits>
class custom_scheduler;
46 #define EmptyTaskPool ((task**)0) 47 #define LockedTaskPool ((task**)~(intptr_t)0) 88 #if __TBB_SCHEDULER_OBSERVER 89 observer_proxy* my_last_global_observer;
93 #if __TBB_ARENA_OBSERVER 94 observer_proxy* my_last_local_observer;
97 #if __TBB_TASK_PRIORITY 101 volatile intptr_t *my_ref_top_priority;
104 volatile uintptr_t *my_ref_reload_epoch;
125 return (t.
prefix().extra_state & 0x0F)>=0x1;
131 uintptr_t my_rsb_stealing_threshold;
154 #if __TBB_HOARD_NONLOCAL_TASKS 155 task* my_nonlocal_free_list;
173 #if __TBB_COUNT_TASK_NODES 174 intptr_t my_task_node_count;
245 #if __TBB_TASK_ISOLATION 293 #if TBB_USE_ASSERT > 1 326 template<free_task_h
int h>
350 #if __TBB_COUNT_TASK_NODES 351 intptr_t get_task_node_count(
bool count_arena_workers =
false );
371 #if __TBB_TASK_GROUP_CONTEXT 397 uintptr_t my_context_state_propagation_epoch;
405 #if __TBB_TASK_PRIORITY 406 inline intptr_t effective_reference_priority ()
const;
411 task* my_offloaded_tasks;
414 task** my_offloaded_task_list_tail_link;
417 uintptr_t my_local_reload_epoch;
420 volatile bool my_pool_reshuffling_pending;
437 inline void offload_task (
task& t, intptr_t task_priority );
442 void cleanup_local_context_list ();
446 template <
typename T>
455 __TBB_ASSERT(is_alive(ctx),
"referenced task_group_context was destroyed");
456 static const char *msg =
"task_group_context is invalid";
465 #if __TBB_TASK_PRIORITY 469 #if TBB_USE_ASSERT > 1 481 ::rml::server::execution_resource_t master_exec_resource;
485 #if __TBB_TASK_GROUP_CONTEXT 491 #if __TBB_SURVIVE_THREAD_SWITCH 502 cilk_state_t my_cilk_state;
510 mutable statistics_counters my_counters;
558 #if __TBB_TASK_GROUP_CONTEXT 584 p.extra_state = 0xFF;
588 #if __TBB_COUNT_TASK_NODES 589 --my_task_node_count;
593 #if __TBB_COUNT_TASK_NODES 594 inline intptr_t generic_scheduler::get_task_node_count(
bool count_arena_workers ) {
595 return my_task_node_count + (count_arena_workers?
my_arena->workers_task_node_count(): 0);
608 __TBB_ASSERT ( new_tail <= my_arena_slot->my_task_pool_size,
"task deque end was overwritten" );
618 "Task pool must be locked when calling commit_relocated_tasks()" );
626 template<free_task_h
int h
int>
628 #if __TBB_HOARD_NONLOCAL_TASKS 648 }
else if( !(
h&
local_task) &&
p.origin && uintptr_t(
p.origin) < uintptr_t(4096) ) {
653 #if __TBB_HOARD_NONLOCAL_TASKS 655 p.next = my_nonlocal_free_list;
656 my_nonlocal_free_list = &t;
666 #if __TBB_TASK_PRIORITY 667 inline intptr_t generic_scheduler::effective_reference_priority ()
const {
676 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY 677 &&
my_arena->my_concurrency_mode!=arena_base::cm_enforced_global
679 ) ? *my_ref_top_priority :
my_arena->my_top_priority;
682 inline void generic_scheduler::offload_task (
task& t, intptr_t ) {
685 __TBB_ASSERT( my_offloaded_task_list_tail_link && !*my_offloaded_task_list_tail_link, NULL );
689 t.
prefix().next_offloaded = my_offloaded_tasks;
690 my_offloaded_tasks = &t;
694 #if __TBB_FP_CONTEXT || __TBB_TASK_GROUP_CONTEXT 699 template <
bool report_tasks>
700 class context_guard_helper {
701 #if __TBB_TASK_GROUP_CONTEXT 702 const task_group_context *curr_ctx;
705 cpu_ctl_env guard_cpu_ctl_env;
706 cpu_ctl_env curr_cpu_ctl_env;
709 context_guard_helper()
710 #if __TBB_TASK_GROUP_CONTEXT 715 guard_cpu_ctl_env.get_env();
716 curr_cpu_ctl_env = guard_cpu_ctl_env;
719 ~context_guard_helper() {
721 if ( curr_cpu_ctl_env != guard_cpu_ctl_env )
722 guard_cpu_ctl_env.set_env();
724 #if __TBB_TASK_GROUP_CONTEXT 725 if (report_tasks && curr_ctx)
729 void set_ctx(
const task_group_context *ctx ) {
730 generic_scheduler::assert_context_valid(ctx);
732 const cpu_ctl_env &ctl = *punned_cast<cpu_ctl_env*>(&ctx->my_cpu_ctl_env);
734 #if __TBB_TASK_GROUP_CONTEXT 735 if(ctx != curr_ctx) {
738 if ( ctl != curr_cpu_ctl_env ) {
739 curr_cpu_ctl_env = ctl;
740 curr_cpu_ctl_env.set_env();
743 #if __TBB_TASK_GROUP_CONTEXT 759 if ( curr_cpu_ctl_env != guard_cpu_ctl_env ) {
760 guard_cpu_ctl_env.set_env();
761 curr_cpu_ctl_env = guard_cpu_ctl_env;
static generic_scheduler * create_worker(market &m, size_t index)
Initialize a scheduler for a worker thread.
#define __TBB_ISOLATION_ARG(arg1, isolation)
task object is freshly allocated or recycled.
const size_t task_prefix_reservation_size
Number of bytes reserved for a task prefix.
void deallocate_task(task &t)
Return task object to the memory allocator.
uintptr_t my_stealing_threshold
Position in the call stack specifying its maximal filling when stealing is still allowed.
arena_slot * my_arena_slot
Pointer to the slot in the arena we own at the moment.
generic_scheduler(market &)
void poison_pointer(T *__TBB_atomic &)
task_group_context * my_parent
Pointer to the context of the parent cancellation group. NULL for isolated contexts.
A fast random number generator.
Base class for user-defined tasks.
void local_spawn(task *first, task *&next)
Work stealing task scheduler.
task & allocate_task(size_t number_of_bytes, __TBB_CONTEXT_ARG(task *parent, task_group_context *context))
Allocate task object, either from the heap or a free list.
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
void __TBB_store_with_release(volatile T &location, V value)
unsigned max_threads_in_arena()
Returns the concurrency limit of the current arena.
task * my_free_list
Free list of small tasks that can be reused.
#define __TBB_CONTEXT_ARG1(context)
affinity_id my_affinity_id
The mailbox id assigned to this scheduler.
A lock that occupies a single byte.
task * get_task(__TBB_ISOLATION_EXPR(isolation_tag isolation))
Get a task from the local pool.
free_task_hint
Optimization hint to free_task that enables it omit unnecessary tests and code.
Memory prefix to a task object.
bool can_steal()
Returns true if stealing is allowed.
void * __TBB_get_bsp()
Retrieves the current RSE backing store pointer. IA64 specific.
FastRandom my_random
Random number generator used for picking a random victim from which to steal.
Data structure to be inherited by the types that can form intrusive lists.
__TBB_atomic intptr_t my_small_task_count
Number of small tasks that have been allocated by this scheduler.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id parent
void free_scheduler()
Destroy and deallocate this scheduler object.
A scheduler with a customized evaluation loop.
unsigned num_workers_active()
The number of workers active in the arena.
Bitwise-OR of local_task and small_task.
task is running, and will be destroyed after method execute() completes.
#define __TBB_store_release
void spawn_root_and_wait(task &first, task *&next) __TBB_override
For internal use only.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
auto first(Container &c) -> decltype(begin(c))
task * prepare_for_spawning(task *t)
Checks if t is affinitized to another thread, and if so, bundles it as proxy.
void const char const char int ITT_FORMAT __itt_group_sync p
scheduler_properties my_properties
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function h
task * my_dummy_task
Fake root task created by slave threads.
virtual task * receive_or_steal_task(__TBB_ISOLATION_ARG(__TBB_atomic reference_count &completion_ref_count, isolation_tag isolation))=0
Try getting a task from other threads (via mailbox, stealing, FIFO queue, orphans adoption).
void init_stack_info()
Sets up the data necessary for the stealing limiting heuristics.
void local_spawn_root_and_wait(task *first, task *&next)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p sync_releasing
void attach_mailbox(affinity_id id)
void attach_arena(arena *, size_t index, bool is_master)
static const size_t min_task_pool_size
bool is_quiescent_local_task_pool_reset() const
static const size_t quick_task_size
If sizeof(task) is <=quick_task_size, it is handled on a free list instead of malloc'd.
#define ITT_NOTIFY(name, obj)
void commit_spawned_tasks(size_t new_tail)
Makes newly spawned tasks visible to thieves.
size_t prepare_task_pool(size_t n)
Makes sure that the task pool can accommodate at least n more elements.
internal::context_list_node_t my_node
Used to form the thread specific list of contexts without additional memory allocation.
Class representing source of mail.
task is in ready pool, or is going to be put there, or was just taken off.
void release_task_pool() const
Unlocks the local task pool.
task **__TBB_atomic task_pool
task ** lock_task_pool(arena_slot *victim_arena_slot) const
Locks victim's task pool, and returns pointer to it. The pointer can be NULL.
__TBB_atomic size_t head
Index of the first ready task in the deque.
internal::generic_scheduler * my_owner
Scheduler instance that registered this context in its thread specific list.
Used to form groups of tasks.
Bit-field representing properties of a sheduler.
bool master_outermost_level() const
True if the scheduler is on the outermost dispatch level in a master thread.
void spawn(task &first, task *&next) __TBB_override
For internal use only.
void free_nonlocal_small_task(task &t)
Free a small task t that that was allocated by a different scheduler.
bool my_auto_initialized
True if *this was created by automatic TBB initialization.
Disable caching for a small task.
intptr_t my_priority
Priority level of the task group (in normalized representation)
static task * plugged_return_list()
Special value used to mark my_return_list as not taking any more entries.
unsigned my_num_workers_allotted
The number of workers that have been marked out by the resource manager to service the arena.
intptr_t isolation_tag
A tag for task isolation.
#define __TBB_ISOLATION_EXPR(isolation)
void acquire_task_pool() const
Locks the local task pool.
uintptr_t my_version_and_traits
Version for run-time checks and behavioral traits of the context.
Task is known to have been allocated by this scheduler.
void __TBB_store_relaxed(volatile T &location, V value)
state_type state() const
Current execution state.
bool is_local_task_pool_quiescent() const
__TBB_atomic size_t tail
Index of the element following the last ready task in the deque.
task * steal_task(__TBB_ISOLATION_ARG(arena_slot &victim_arena_slot, isolation_tag isolation))
Steal task from another scheduler's ready pool.
bool type
Indicates that a scheduler acts as a master or a worker.
unsigned char
Reserved bits.
task * get_mailbox_task(__TBB_ISOLATION_EXPR(isolation_tag isolation))
Attempt to get a task from the mailbox.
void commit_relocated_tasks(size_t new_tail)
Makes relocated tasks visible to thieves and releases the local task pool.
#define __TBB_CONTEXT_ARG(arg1, context)
#define ITT_TASK_BEGIN(type, name, id)
market * my_market
The market I am in.
static void cleanup_worker(void *arg, bool worker)
Perform necessary cleanup when a worker thread finishes.
unsigned short affinity_id
An id as used for specifying affinity.
unsigned my_num_slots
The number of slots in the arena.
virtual void local_wait_for_all(task &parent, task *child)=0
arena * my_arena
The arena that I own (if master) or am servicing at the moment (if worker)
Task is known to be a small task.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id id
task object is on free list, or is going to be put there, or was just taken off.
bool outermost_level() const
True if the scheduler is on the outermost dispatch level.
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
__TBB_atomic kind_type my_kind
Flavor of this context: bound or isolated.
mail_outbox & mailbox(affinity_id id)
Get reference to mailbox corresponding to given affinity_id.
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
long my_ref_count
Reference count for scheduler.
bool outermost
Indicates that a scheduler is on outermost level.
void assert_task_pool_valid() const
uintptr_t my_state
Internal state (combination of state flags, currently only may_have_children).
static const kind_type dying
T __TBB_load_relaxed(const volatile T &location)
void nested_arena_entry(arena *, size_t)
void leave_task_pool()
Leave the task pool.
void publish_task_pool()
Used by workers to enter the task pool.
void set_ctx(__TBB_CONTEXT_ARG1(task_group_context *))
static bool is_proxy(const task &t)
True if t is a task_proxy.
bool cleanup_master(bool blocking_terminate)
Perform necessary cleanup when a master thread stops using TBB.
void attach(mail_outbox &putter)
Attach inbox to a corresponding outbox.
void unlock_task_pool(arena_slot *victim_arena_slot, task **victim_task_pool) const
Unlocks victim's task pool.
size_t my_arena_index
Index of the arena slot the scheduler occupies now, or occupied last time.
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
void reset_task_pool_and_leave()
Resets head and tail indices to 0, and leaves task pool.
bool is_quiescent_local_task_pool_empty() const
bool is_worker() const
True if running on a worker thread, false otherwise.
intptr_t reference_count
A reference count.
static bool is_version_3_task(task &t)
static const size_t null_arena_index
task * my_return_list
List of small tasks that have been returned to this scheduler by other schedulers.
uintptr_t my_cancellation_requested
Specifies whether cancellation was requested for this task group.
void enqueue(task &, void *reserved) __TBB_override
For internal use only.
task * my_innermost_running_task
Innermost task whose task::execute() is running. A dummy task on the outermost level.
void free_task(task &t)
Put task on free list.
static generic_scheduler * create_master(arena *a)
Initialize a scheduler for a master thread.
bool worker_outermost_level() const
True if the scheduler is on the outermost dispatch level in a worker thread.
#define GATHER_STATISTIC(x)
bool is_task_pool_published() const