Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
scheduler.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2018 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 #ifndef _TBB_scheduler_H
22 #define _TBB_scheduler_H
23 
24 #include "scheduler_common.h"
25 #include "tbb/spin_mutex.h"
26 #include "mailbox.h"
27 #include "tbb_misc.h" // for FastRandom
28 #include "itt_notify.h"
29 #include "../rml/include/rml_tbb.h"
30 
31 #include "intrusive_list.h"
32 
33 #if __TBB_SURVIVE_THREAD_SWITCH
34 #include "cilk-tbb-interop.h"
35 #endif /* __TBB_SURVIVE_THREAD_SWITCH */
36 
37 namespace tbb {
38 namespace internal {
39 
40 template<typename SchedulerTraits> class custom_scheduler;
41 
42 //------------------------------------------------------------------------
43 // generic_scheduler
44 //------------------------------------------------------------------------
45 
46 #define EmptyTaskPool ((task**)0)
47 #define LockedTaskPool ((task**)~(intptr_t)0)
48 
51  static const bool worker = false;
52  static const bool master = true;
54  bool type : 1;
56 
57  bool outermost : 1;
59  unsigned char : 6;
60 };
61 
64  size_t my_arena_index; // TODO: make it unsigned and pair with my_affinity_id to fit into cache line
65 
68 
71 
74 
76 
78 
85 
87 
88 #if __TBB_SCHEDULER_OBSERVER
89  observer_proxy* my_last_global_observer;
91 #endif
92 
93 #if __TBB_ARENA_OBSERVER
94  observer_proxy* my_last_local_observer;
96 #endif
97 #if __TBB_TASK_PRIORITY
98 
101  volatile intptr_t *my_ref_top_priority;
102 
104  volatile uintptr_t *my_ref_reload_epoch;
105 #endif /* __TBB_TASK_PRIORITY */
106 };
107 
109 
116  , public ::rml::job
117  , public intrusive_list_node
118  , public scheduler_state {
119 public: // almost every class in TBB uses generic_scheduler
120 
123 
124  static bool is_version_3_task( task& t ) {
125  return (t.prefix().extra_state & 0x0F)>=0x1;
126  }
127 
130 #if __TBB_ipf
131  uintptr_t my_rsb_stealing_threshold;
133 #endif
134 
135  static const size_t null_arena_index = ~size_t(0);
136 
137  inline bool is_task_pool_published () const;
138 
139  inline bool is_local_task_pool_quiescent () const;
140 
141  inline bool is_quiescent_local_task_pool_empty () const;
142 
143  inline bool is_quiescent_local_task_pool_reset () const;
144 
147 
150 
153 
154 #if __TBB_HOARD_NONLOCAL_TASKS
155  task* my_nonlocal_free_list;
157 #endif
158 
161 
163 
165 
166  inline void attach_mailbox( affinity_id id );
167 
168  /* A couple of bools can be located here because space is otherwise just padding after my_affinity_id. */
169 
172 
173 #if __TBB_COUNT_TASK_NODES
174  intptr_t my_task_node_count;
176 #endif /* __TBB_COUNT_TASK_NODES */
177 
179  void init_stack_info ();
180 
182  bool can_steal () {
183  int anchor;
184  // TODO IDEA: Add performance warning?
185 #if __TBB_ipf
186  return my_stealing_threshold < (uintptr_t)&anchor && (uintptr_t)__TBB_get_bsp() < my_rsb_stealing_threshold;
187 #else
188  return my_stealing_threshold < (uintptr_t)&anchor;
189 #endif
190  }
191 
193 
194  void publish_task_pool();
195 
197 
198  void leave_task_pool();
199 
201 
202  inline void reset_task_pool_and_leave ();
203 
205 
206  task** lock_task_pool( arena_slot* victim_arena_slot ) const;
207 
209 
210  void unlock_task_pool( arena_slot* victim_arena_slot, task** victim_task_pool ) const;
211 
213 
215  void acquire_task_pool() const;
216 
218 
220  void release_task_pool() const;
221 
223 
225 
227  inline void commit_spawned_tasks( size_t new_tail );
228 
230 
231  inline void commit_relocated_tasks( size_t new_tail );
232 
234 
238 
240 
245 #if __TBB_TASK_ISOLATION
246  task* get_task( size_t T, isolation_tag isolation, bool& tasks_omitted );
247 #else
248  task* get_task( size_t T );
249 #endif /* __TBB_TASK_ISOLATION */
250 
258 
260  static bool is_proxy( const task& t ) {
261  return t.prefix().extra_state==es_task_proxy;
262  }
263 
265  task* steal_task( __TBB_ISOLATION_ARG( arena_slot& victim_arena_slot, isolation_tag isolation ) );
266 
269  static const size_t min_task_pool_size = 64;
270 
272 
274  size_t prepare_task_pool( size_t n );
275 
277  static generic_scheduler* create_master( arena* a );
278 
280  bool cleanup_master( bool blocking_terminate );
281 
283  static generic_scheduler* create_worker( market& m, size_t index );
284 
286  static void cleanup_worker( void* arg, bool worker );
287 
288 protected:
289  template<typename SchedulerTraits> friend class custom_scheduler;
291 
292 public:
293 #if TBB_USE_ASSERT > 1
294 
296  void assert_task_pool_valid() const;
297 #else
298  void assert_task_pool_valid() const {}
299 #endif /* TBB_USE_ASSERT <= 1 */
300 
301  void attach_arena( arena*, size_t index, bool is_master );
302  void nested_arena_entry( arena*, size_t );
303  void nested_arena_exit();
304  void wait_until_empty();
305 
306  void spawn( task& first, task*& next ) __TBB_override;
307 
309 
310  void enqueue( task&, void* reserved ) __TBB_override;
311 
312  void local_spawn( task* first, task*& next );
313  void local_spawn_root_and_wait( task* first, task*& next );
314  virtual void local_wait_for_all( task& parent, task* child ) = 0;
315 
317  void free_scheduler();
318 
320 
321  task& allocate_task( size_t number_of_bytes,
323 
325 
326  template<free_task_hint h>
327  void free_task( task& t );
328 
330  inline void deallocate_task( task& t );
331 
333  inline bool is_worker() const;
334 
336  inline bool outermost_level() const;
337 
339 
342  inline bool master_outermost_level () const;
343 
345  inline bool worker_outermost_level () const;
346 
348  unsigned max_threads_in_arena();
349 
350 #if __TBB_COUNT_TASK_NODES
351  intptr_t get_task_node_count( bool count_arena_workers = false );
352 #endif /* __TBB_COUNT_TASK_NODES */
353 
355  static task* plugged_return_list() {return (task*)(intptr_t)(-1);}
356 
359 
361  // TODO IDEA: see if putting my_return_list on separate cache line improves performance
363 
365 
366  virtual task* receive_or_steal_task( __TBB_ISOLATION_ARG( __TBB_atomic reference_count& completion_ref_count, isolation_tag isolation ) ) = 0;
367 
369  void free_nonlocal_small_task( task& t );
370 
371 #if __TBB_TASK_GROUP_CONTEXT
372 
378  inline task_group_context* default_context ();
379 
381  char _padding1[NFS_MaxLineSize - sizeof(context_list_node_t)];
382 
384  context_list_node_t my_context_list_head;
385 
387  // TODO: check whether it can be deadly preempted and replace by spinning/sleeping mutex
388  spin_mutex my_context_list_mutex;
389 
391 
397  uintptr_t my_context_state_propagation_epoch;
398 
400 
403  tbb::atomic<uintptr_t> my_local_ctx_list_update;
404 
405 #if __TBB_TASK_PRIORITY
406  inline intptr_t effective_reference_priority () const;
408 
409  // TODO: move into slots and fix is_out_of_work
411  task* my_offloaded_tasks;
412 
414  task** my_offloaded_task_list_tail_link;
415 
417  uintptr_t my_local_reload_epoch;
418 
420  volatile bool my_pool_reshuffling_pending;
421 
423 
424  task* reload_tasks( __TBB_ISOLATION_EXPR( isolation_tag isolation ) );
425 
426  task* reload_tasks( task*& offloaded_tasks, task**& offloaded_task_list_link, __TBB_ISOLATION_ARG( intptr_t top_priority, isolation_tag isolation ) );
427 
429 
430  task* winnow_task_pool ( __TBB_ISOLATION_EXPR( isolation_tag isolation ) );
431 
433 
434  task *get_task_and_activate_task_pool( size_t H0 , __TBB_ISOLATION_ARG( size_t T0, isolation_tag isolation ) );
435 
437  inline void offload_task ( task& t, intptr_t task_priority );
438 #endif /* __TBB_TASK_PRIORITY */
439 
441 
442  void cleanup_local_context_list ();
443 
446  template <typename T>
447  void propagate_task_group_state ( T task_group_context::*mptr_state, task_group_context& src, T new_state );
448 
449  // check consistency
450  static void assert_context_valid(const task_group_context *tgc) {
452 #if TBB_USE_ASSERT
453  __TBB_ASSERT(tgc, NULL);
454  uintptr_t ctx = tgc->my_version_and_traits;
455  __TBB_ASSERT(is_alive(ctx), "referenced task_group_context was destroyed");
456  static const char *msg = "task_group_context is invalid";
457  __TBB_ASSERT(!(ctx&~(3|(7<<task_group_context::traits_offset))), msg); // the value fits known values of versions and traits
462  __TBB_ASSERT(tgc->my_owner, msg);
463  __TBB_ASSERT(tgc->my_node.my_next && tgc->my_node.my_prev, msg);
464  }
465 #if __TBB_TASK_PRIORITY
466  assert_priority_valid(tgc->my_priority);
467 #endif
468  if(tgc->my_parent)
469 #if TBB_USE_ASSERT > 1
470  assert_context_valid(tgc->my_parent);
471 #else
472  __TBB_ASSERT(is_alive(tgc->my_parent->my_version_and_traits), msg);
473 #endif
474 #endif
475  }
476 #endif /* __TBB_TASK_GROUP_CONTEXT */
477 
478 #if _WIN32||_WIN64
479 private:
481  ::rml::server::execution_resource_t master_exec_resource;
482 public:
483 #endif /* _WIN32||_WIN64 */
484 
485 #if __TBB_TASK_GROUP_CONTEXT
486 
488  tbb::atomic<uintptr_t> my_nonlocal_ctx_list_update;
489 #endif /* __TBB_TASK_GROUP_CONTEXT */
490 
491 #if __TBB_SURVIVE_THREAD_SWITCH
492  __cilk_tbb_unwatch_thunk my_cilk_unwatch_thunk;
493 #if TBB_USE_ASSERT
494 
496  enum cilk_state_t {
497  cs_none=0xF000, // Start at nonzero value so that we can detect use of zeroed memory.
498  cs_running,
499  cs_limbo,
500  cs_freed
501  };
502  cilk_state_t my_cilk_state;
503 #endif /* TBB_USE_ASSERT */
504 #endif /* __TBB_SURVIVE_THREAD_SWITCH */
505 
506 #if __TBB_STATISTICS
507 
510  mutable statistics_counters my_counters;
511 #endif /* __TBB_STATISTICS */
512 
513 }; // class generic_scheduler
514 
515 
516 } // namespace internal
517 } // namespace tbb
518 
519 #include "arena.h"
520 #include "governor.h"
521 
522 namespace tbb {
523 namespace internal {
524 
528 }
529 
532  task** tp = my_arena_slot->task_pool;
533  return tp == EmptyTaskPool || tp == LockedTaskPool;
534 }
535 
537  __TBB_ASSERT( is_local_task_pool_quiescent(), "Task pool is not quiescent" );
539 }
540 
542  __TBB_ASSERT( is_local_task_pool_quiescent(), "Task pool is not quiescent" );
544 }
545 
547  return my_properties.outermost;
548 }
549 
551  return !is_worker() && outermost_level();
552 }
553 
555  return is_worker() && outermost_level();
556 }
557 
558 #if __TBB_TASK_GROUP_CONTEXT
559 inline task_group_context* generic_scheduler::default_context () {
560  return my_dummy_task->prefix().context;
561 }
562 #endif /* __TBB_TASK_GROUP_CONTEXT */
563 
565  __TBB_ASSERT(id>0,NULL);
567  my_affinity_id = id;
568 }
569 
570 inline bool generic_scheduler::is_worker() const {
572 }
573 
575  __TBB_ASSERT(my_arena, NULL);
576  return my_arena->my_num_slots;
577 }
578 
581 #if TBB_USE_ASSERT
582  task_prefix& p = t.prefix();
583  p.state = 0xFF;
584  p.extra_state = 0xFF;
585  poison_pointer(p.next);
586 #endif /* TBB_USE_ASSERT */
588 #if __TBB_COUNT_TASK_NODES
589  --my_task_node_count;
590 #endif /* __TBB_COUNT_TASK_NODES */
591 }
592 
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);
596 }
597 #endif /* __TBB_COUNT_TASK_NODES */
598 
600  __TBB_ASSERT( my_arena_slot->task_pool == LockedTaskPool, "Task pool must be locked when resetting task pool" );
603  leave_task_pool();
604 }
605 
606 //TODO: move to arena_slot
607 inline void generic_scheduler::commit_spawned_tasks( size_t new_tail ) {
608  __TBB_ASSERT ( new_tail <= my_arena_slot->my_task_pool_size, "task deque end was overwritten" );
609  // emit "task was released" signal
610  ITT_NOTIFY(sync_releasing, (void*)((uintptr_t)my_arena_slot+sizeof(uintptr_t)));
611  // Release fence is necessary to make sure that previously stored task pointers
612  // are visible to thieves.
614 }
615 
618  "Task pool must be locked when calling commit_relocated_tasks()" );
620  // Tail is updated last to minimize probability of a thread making arena
621  // snapshot being misguided into thinking that this task pool is empty.
622  __TBB_store_release( my_arena_slot->tail, new_tail );
624 }
625 
626 template<free_task_hint hint>
628 #if __TBB_HOARD_NONLOCAL_TASKS
629  static const int h = hint&(~local_task);
630 #else
631  static const free_task_hint h = hint;
632 #endif
633  GATHER_STATISTIC(--my_counters.active_tasks);
634  task_prefix& p = t.prefix();
635  // Verify that optimization hints are correct.
636  __TBB_ASSERT( h!=small_local_task || p.origin==this, NULL );
637  __TBB_ASSERT( !(h&small_task) || p.origin, NULL );
638  __TBB_ASSERT( !(h&local_task) || (!p.origin || uintptr_t(p.origin) > uintptr_t(4096)), "local_task means allocated");
639  poison_value(p.depth);
640  poison_value(p.ref_count);
641  poison_pointer(p.owner);
642  __TBB_ASSERT( 1L<<t.state() & (1L<<task::executing|1L<<task::allocated), NULL );
643  p.state = task::freed;
644  if( h==small_local_task || p.origin==this ) {
645  GATHER_STATISTIC(++my_counters.free_list_length);
646  p.next = my_free_list;
647  my_free_list = &t;
648  } else if( !(h&local_task) && p.origin && uintptr_t(p.origin) < uintptr_t(4096) ) {
649  // a special value reserved for future use, do nothing since
650  // origin is not pointing to a scheduler instance
651  } else if( !(h&local_task) && p.origin ) {
652  GATHER_STATISTIC(++my_counters.free_list_length);
653 #if __TBB_HOARD_NONLOCAL_TASKS
654  if( !(h&no_cache) ) {
655  p.next = my_nonlocal_free_list;
656  my_nonlocal_free_list = &t;
657  } else
658 #endif
660  } else {
661  GATHER_STATISTIC(--my_counters.big_tasks);
662  deallocate_task(t);
663  }
664 }
665 
666 #if __TBB_TASK_PRIORITY
667 inline intptr_t generic_scheduler::effective_reference_priority () const {
668  // Workers on the outermost dispatch level (i.e. with empty stack) use market's
669  // priority as a reference point (to speedup discovering process level priority
670  // changes). But when there are enough workers to service (even if only partially)
671  // a lower priority arena, they should use arena's priority as a reference, lest
672  // be trapped in a futile spinning (because market's priority would prohibit
673  // executing ANY tasks in this arena).
674  return !worker_outermost_level() ||
676 #if __TBB_ENQUEUE_ENFORCED_CONCURRENCY
677  && my_arena->my_concurrency_mode!=arena_base::cm_enforced_global
678 #endif
679  ) ? *my_ref_top_priority : my_arena->my_top_priority;
680 }
681 
682 inline void generic_scheduler::offload_task ( task& t, intptr_t /*priority*/ ) {
683  GATHER_STATISTIC( ++my_counters.prio_tasks_offloaded );
684  __TBB_ASSERT( !is_proxy(t), "The proxy task cannot be offloaded" );
685  __TBB_ASSERT( my_offloaded_task_list_tail_link && !*my_offloaded_task_list_tail_link, NULL );
686 #if TBB_USE_ASSERT
687  t.prefix().state = task::ready;
688 #endif /* TBB_USE_ASSERT */
689  t.prefix().next_offloaded = my_offloaded_tasks;
690  my_offloaded_tasks = &t;
691 }
692 #endif /* __TBB_TASK_PRIORITY */
693 
694 #if __TBB_FP_CONTEXT || __TBB_TASK_GROUP_CONTEXT
695 
699 template <bool report_tasks>
700 class context_guard_helper {
701 #if __TBB_TASK_GROUP_CONTEXT
702  const task_group_context *curr_ctx;
703 #endif
704 #if __TBB_FP_CONTEXT
705  cpu_ctl_env guard_cpu_ctl_env;
706  cpu_ctl_env curr_cpu_ctl_env;
707 #endif
708 public:
709  context_guard_helper()
710 #if __TBB_TASK_GROUP_CONTEXT
711  : curr_ctx(NULL)
712 #endif
713  {
714 #if __TBB_FP_CONTEXT
715  guard_cpu_ctl_env.get_env();
716  curr_cpu_ctl_env = guard_cpu_ctl_env;
717 #endif
718  }
719  ~context_guard_helper() {
720 #if __TBB_FP_CONTEXT
721  if ( curr_cpu_ctl_env != guard_cpu_ctl_env )
722  guard_cpu_ctl_env.set_env();
723 #endif
724 #if __TBB_TASK_GROUP_CONTEXT
725  if (report_tasks && curr_ctx)
726  ITT_TASK_END;
727 #endif
728  }
729  void set_ctx( const task_group_context *ctx ) {
730  generic_scheduler::assert_context_valid(ctx);
731 #if __TBB_FP_CONTEXT
732  const cpu_ctl_env &ctl = *punned_cast<cpu_ctl_env*>(&ctx->my_cpu_ctl_env);
733 #endif
734 #if __TBB_TASK_GROUP_CONTEXT
735  if(ctx != curr_ctx) {
736 #endif
737 #if __TBB_FP_CONTEXT
738  if ( ctl != curr_cpu_ctl_env ) {
739  curr_cpu_ctl_env = ctl;
740  curr_cpu_ctl_env.set_env();
741  }
742 #endif
743 #if __TBB_TASK_GROUP_CONTEXT
744  // if task group context was active, report end of current execution frame.
745  if (report_tasks) {
746  if (curr_ctx)
747  ITT_TASK_END;
748  // reporting begin of new task group context execution frame.
749  // using address of task group context object to group tasks (parent).
750  // id of task execution frame is NULL and reserved for future use.
751  ITT_TASK_BEGIN(ctx,ctx->my_name,NULL);
752  curr_ctx = ctx;
753  }
754  }
755 #endif
756  }
757  void restore_default() {
758 #if __TBB_FP_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;
762  }
763 #endif
764  }
765 };
766 #else
767 template <bool T>
770  void restore_default() {}
771 };
772 #endif /* __TBB_FP_CONTEXT */
773 
774 } // namespace internal
775 } // namespace tbb
776 
777 #endif /* _TBB_scheduler_H */
static generic_scheduler * create_worker(market &m, size_t index)
Initialize a scheduler for a worker thread.
Definition: scheduler.cpp:1146
#define __TBB_ISOLATION_ARG(arg1, isolation)
task object is freshly allocated or recycled.
Definition: task.h:604
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.
Definition: scheduler.h:580
uintptr_t my_stealing_threshold
Position in the call stack specifying its maximal filling when stealing is still allowed.
Definition: scheduler.h:129
#define LockedTaskPool
Definition: scheduler.h:47
arena_slot * my_arena_slot
Pointer to the slot in the arena we own at the moment.
Definition: scheduler.h:67
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:309
task_group_context * my_parent
Pointer to the context of the parent cancellation group. NULL for isolated contexts.
Definition: task.h:371
A fast random number generator.
Definition: tbb_misc.h:134
Base class for user-defined tasks.
Definition: task.h:576
void local_spawn(task *first, task *&next)
Definition: scheduler.cpp:596
Work stealing task scheduler.
Definition: scheduler.h:115
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.
Definition: scheduler.cpp:298
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:220
void __TBB_store_with_release(volatile T &location, V value)
Definition: tbb_machine.h:717
unsigned max_threads_in_arena()
Returns the concurrency limit of the current arena.
Definition: scheduler.h:574
task * my_free_list
Free list of small tasks that can be reused.
Definition: scheduler.h:152
#define __TBB_CONTEXT_ARG1(context)
affinity_id my_affinity_id
The mailbox id assigned to this scheduler.
Definition: scheduler.h:84
A lock that occupies a single byte.
Definition: spin_mutex.h:40
task * get_task(__TBB_ISOLATION_EXPR(isolation_tag isolation))
Get a task from the local pool.
Definition: scheduler.cpp:945
free_task_hint
Optimization hint to free_task that enables it omit unnecessary tests and code.
Memory prefix to a task object.
Definition: task.h:180
bool can_steal()
Returns true if stealing is allowed.
Definition: scheduler.h:182
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.
Definition: scheduler.h:149
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.
Definition: scheduler.h:358
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.
Definition: scheduler.cpp:261
A scheduler with a customized evaluation loop.
unsigned num_workers_active()
The number of workers active in the arena.
Definition: arena.h:220
Bitwise-OR of local_task and small_task.
task is running, and will be destroyed after method execute() completes.
Definition: task.h:598
#define __TBB_store_release
Definition: tbb_machine.h:861
void spawn_root_and_wait(task &first, task *&next) __TBB_override
For internal use only.
Definition: scheduler.cpp:677
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
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.
Definition: scheduler.cpp:556
#define __TBB_override
Definition: tbb_stddef.h:244
void const char const char int ITT_FORMAT __itt_group_sync p
scheduler_properties my_properties
Definition: scheduler.h:86
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.
Definition: scheduler.h:160
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.
Definition: scheduler.cpp:147
void local_spawn_root_and_wait(task *first, task *&next)
Definition: scheduler.cpp:652
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)
Definition: scheduler.h:564
void attach_arena(arena *, size_t index, bool is_master)
Definition: arena.cpp:40
static const size_t min_task_pool_size
Definition: scheduler.h:269
bool is_quiescent_local_task_pool_reset() const
Definition: scheduler.h:541
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.
Definition: scheduler.h:122
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:117
void commit_spawned_tasks(size_t new_tail)
Makes newly spawned tasks visible to thieves.
Definition: scheduler.h:607
size_t prepare_task_pool(size_t n)
Makes sure that the task pool can accommodate at least n more elements.
Definition: scheduler.cpp:400
internal::context_list_node_t my_node
Used to form the thread specific list of contexts without additional memory allocation.
Definition: task.h:376
Class representing source of mail.
Definition: mailbox.h:189
task is in ready pool, or is going to be put there, or was just taken off.
Definition: task.h:602
void release_task_pool() const
Unlocks the local task pool.
Definition: scheduler.cpp:483
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.
Definition: scheduler.cpp:498
__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.
Definition: task.h:413
Used to form groups of tasks.
Definition: task.h:319
Bit-field representing properties of a sheduler.
Definition: scheduler.h:50
bool master_outermost_level() const
True if the scheduler is on the outermost dispatch level in a master thread.
Definition: scheduler.h:550
#define ITT_TASK_END
Definition: itt_notify.h:127
void spawn(task &first, task *&next) __TBB_override
For internal use only.
Definition: scheduler.cpp:673
void free_nonlocal_small_task(task &t)
Free a small task t that that was allocated by a different scheduler.
Definition: scheduler.cpp:373
bool my_auto_initialized
True if *this was created by automatic TBB initialization.
Definition: scheduler.h:171
Disable caching for a small task.
intptr_t my_priority
Priority level of the task group (in normalized representation)
Definition: task.h:420
static task * plugged_return_list()
Special value used to mark my_return_list as not taking any more entries.
Definition: scheduler.h:355
unsigned my_num_workers_allotted
The number of workers that have been marked out by the resource manager to service the arena.
Definition: arena.h:51
intptr_t isolation_tag
A tag for task isolation.
Definition: task.h:126
#define __TBB_ISOLATION_EXPR(isolation)
void acquire_task_pool() const
Locks the local task pool.
Definition: scheduler.cpp:454
uintptr_t my_version_and_traits
Version for run-time checks and behavioral traits of the context.
Definition: task.h:407
Task is known to have been allocated by this scheduler.
void __TBB_store_relaxed(volatile T &location, V value)
Definition: tbb_machine.h:743
state_type state() const
Current execution state.
Definition: task.h:838
bool is_local_task_pool_quiescent() const
Definition: scheduler.h:530
__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.
Definition: scheduler.cpp:1042
bool type
Indicates that a scheduler acts as a master or a worker.
Definition: scheduler.h:54
unsigned char
Reserved bits.
Definition: scheduler.h:59
task * get_mailbox_task(__TBB_ISOLATION_EXPR(isolation_tag isolation))
Attempt to get a task from the mailbox.
Definition: scheduler.cpp:1107
void commit_relocated_tasks(size_t new_tail)
Makes relocated tasks visible to thieves and releases the local task pool.
Definition: scheduler.h:616
The graph class.
#define __TBB_CONTEXT_ARG(arg1, context)
#define ITT_TASK_BEGIN(type, name, id)
Definition: itt_notify.h:126
market * my_market
The market I am in.
Definition: scheduler.h:146
Tag for v3 task_proxy.
static void cleanup_worker(void *arg, bool worker)
Perform necessary cleanup when a worker thread finishes.
Definition: scheduler.cpp:1201
unsigned short affinity_id
An id as used for specifying affinity.
Definition: task.h:122
unsigned my_num_slots
The number of slots in the arena.
Definition: arena.h:136
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)
Definition: scheduler.h:70
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.
Definition: task.h:606
bool outermost_level() const
True if the scheduler is on the outermost dispatch level.
Definition: scheduler.h:546
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:381
__TBB_atomic kind_type my_kind
Flavor of this context: bound or isolated.
Definition: task.h:366
mail_outbox & mailbox(affinity_id id)
Get reference to mailbox corresponding to given affinity_id.
Definition: arena.h:191
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
long my_ref_count
Reference count for scheduler.
Definition: scheduler.h:164
bool outermost
Indicates that a scheduler is on outermost level.
Definition: scheduler.h:57
uintptr_t my_state
Internal state (combination of state flags, currently only may_have_children).
Definition: task.h:416
static const kind_type dying
Definition: task.h:553
T __TBB_load_relaxed(const volatile T &location)
Definition: tbb_machine.h:739
void nested_arena_entry(arena *, size_t)
Definition: arena.cpp:631
void leave_task_pool()
Leave the task pool.
Definition: scheduler.cpp:1133
void publish_task_pool()
Used by workers to enter the task pool.
Definition: scheduler.cpp:1121
void set_ctx(__TBB_CONTEXT_ARG1(task_group_context *))
Definition: scheduler.h:769
static bool is_proxy(const task &t)
True if t is a task_proxy.
Definition: scheduler.h:260
bool cleanup_master(bool blocking_terminate)
Perform necessary cleanup when a master thread stops using TBB.
Definition: scheduler.cpp:1211
void attach(mail_outbox &putter)
Attach inbox to a corresponding outbox.
Definition: mailbox.h:197
void unlock_task_pool(arena_slot *victim_arena_slot, task **victim_task_pool) const
Unlocks victim's task pool.
Definition: scheduler.cpp:547
size_t my_arena_index
Index of the arena slot the scheduler occupies now, or occupied last time.
Definition: scheduler.h:64
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
Definition: task.h:920
void reset_task_pool_and_leave()
Resets head and tail indices to 0, and leaves task pool.
Definition: scheduler.h:599
bool is_quiescent_local_task_pool_empty() const
Definition: scheduler.h:536
bool is_worker() const
True if running on a worker thread, false otherwise.
Definition: scheduler.h:570
intptr_t reference_count
A reference count.
Definition: task.h:119
static bool is_version_3_task(task &t)
Definition: scheduler.h:124
static const size_t null_arena_index
Definition: scheduler.h:135
task * my_return_list
List of small tasks that have been returned to this scheduler by other schedulers.
Definition: scheduler.h:362
uintptr_t my_cancellation_requested
Specifies whether cancellation was requested for this task group.
Definition: task.h:401
void enqueue(task &, void *reserved) __TBB_override
For internal use only.
Definition: scheduler.cpp:681
#define __TBB_atomic
Definition: tbb_stddef.h:241
task * my_innermost_running_task
Innermost task whose task::execute() is running. A dummy task on the outermost level.
Definition: scheduler.h:73
#define EmptyTaskPool
Definition: scheduler.h:46
void free_task(task &t)
Put task on free list.
Definition: scheduler.h:627
static generic_scheduler * create_master(arena *a)
Initialize a scheduler for a master thread.
Definition: scheduler.cpp:1159
bool worker_outermost_level() const
True if the scheduler is on the outermost dispatch level in a worker thread.
Definition: scheduler.h:554
#define GATHER_STATISTIC(x)
#define poison_value(g)

Copyright © 2005-2018 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.