Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding stealing_loop_backoff::pause #1257

Closed
blonded04 opened this issue Nov 14, 2023 · 1 comment
Closed

Understanding stealing_loop_backoff::pause #1257

blonded04 opened this issue Nov 14, 2023 · 1 comment
Assignees
Labels

Comments

@blonded04
Copy link
Contributor

AFAIK stealing_loop_backoff::pause is called every iteration of task_dispatcher::local_wait_for_all loop, and interally it calles std::this_thread::yield().

However, if I comment line d0::yield() inside stealing_loop_backoff::pause, when I have N cores on my system and I run N tasks in parallel -- performance degrades by an order of magnitude. How so? Why does hinting the OS scheduler to move my thread away from core increases performance in case of N threads N tasks?

@pavelkumbrasev
Copy link
Contributor

Basically, stealing_loop_backoff::pause is designed to decrease threads contention in the scheduler. The pause will be called when thread cannot find work in the arena so instead of busing system with another attempt to find a task we call pause.
For the start we will call just processor pauses because we assume that there are tasks in the system and they will be distributed across threads in short time so we call a short wait. But after the 2 * P attempts we will start calling yield and we have 100 attempts to find a task until thread will try to transfer arena to Empty state and leave.
To summarize stealing_loop_backoff::pause might help performance by:

  1. Decreasing contention in the system (that might end-up with lowering frequency of cores which threads are waiting -> that in turn might help to increase frequency of a core that is doing serial part of the job)
  2. Keep threads in scheduler until new portion of the work will arrive for example start of next parallel_for:
    tbb::parallel_for();
    /* serial work */
    tbb::parallel_for();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants