Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2417 Discussions

TBB Source Code: Tasks Queues and Stealing

AJ13
New Contributor I
216 Views
Hi,

I'm looking at the TBB source in detail, in particular the scheduler.

What I would like to be able to do is write my own task stealing algorithm, in particular I want to be able to steal tasks from all CPUs at once (that have certain properties) and actually take them away from TBB altogether (migrate to another system).

Any pointers on where in the code I should be looking to interface? Right now I'm tracing through task.cpp, but I don't understand what is meant by "Gate" and "Arena". What are the actual task lists processed by CPUs?

Thanks,

AJ
0 Kudos
3 Replies
AJ13
New Contributor I
216 Views
Actually... I could almost use task scheduler observer for my project... I just need to know when a CPU is idle and can't steal work.
Dmitry_Vyukov
Valued Contributor I
216 Views
aj.guillon@gmail.com:
Hi,
What I would like to be able to do is write my own task stealing algorithm, in particular I want to be able to steal tasks from all CPUs at once (that have certain properties) and actually take them away from TBB altogether (migrate to another system).

Any pointers on where in the code I should be looking to interface? Right now I'm tracing through task.cpp, but I don't understand what is meant by "Gate" and "Arena". What are the actual task lists processed by CPUs?



I'm not quite sure what you want to do... Do you want to integrate with TBB? Or to create your own solution?

Anyway, Gate is thread blocking/signaling mechanism. When worker thread is out of work it blocks on gate. When new tasks are submitted, gate is signaled. Gate is a kind of condition variable for lock-free algorithms. It allows thread to wait on predicate, but with extremely low overhead on fast-path.

Arena is work-stealing deque. But quite complicated algorithm, Cilk-style, not like work-stealing deque in Java Fork/Join Framework for example.

You can take a look at following functions.
GenericSchedule::get_task() - pops task from own work-stealing deque.
GenericSchedule::steal_task() - steals task from foreign work-stealing deque.

Dmitry_Vyukov
Valued Contributor I
216 Views
aj.guillon@gmail.com:
Actually... I could almost use task scheduler observer for my project... I just need to know when a CPU is idle and can't steal work.


When thread is idle and can't steal work from other threads, it calls Gate::wait() method. There is exactly one such point in source code, so you can easily identify this moment.


Reply