Skip to content

Specialize get_task for the case of no isolation#1805

Open
akukanov wants to merge 5 commits intomasterfrom
dev/get-task-no-isolation-akukanov
Open

Specialize get_task for the case of no isolation#1805
akukanov wants to merge 5 commits intomasterfrom
dev/get-task-no-isolation-akukanov

Conversation

@akukanov
Copy link
Copy Markdown
Contributor

@akukanov akukanov commented Aug 5, 2025

Description

After introducing in #1779 a couple of additional operations in get_task (which is on the hot path in the task scheduler) that are only useful when the scheduler runs in the task isolation mode, I thought that maybe this function deserves two separate implementations, with and without isolation. This PR elaborates on that idea.

Additionally, it unifies the handling of proxy tasks in get_task and steal_task into a single routine task_proxy::try_extract_task_from.

Type of change

  • Refactoring/optimization

Tests

  • not needed - covered by the existing tests

Documentation

  • not needed

Breaks backward compatibility?

  • No

Other information

The PR is developed on top of #1779, and so should either be merged afterwards or significantly changed if the base PR is rejected.

@akukanov akukanov force-pushed the dev/get-task-no-isolation-akukanov branch from 2965223 to c6870af Compare December 15, 2025 13:36
Base automatically changed from dev/improve-task-omission-akukanov to master December 19, 2025 13:23
@akukanov akukanov force-pushed the dev/get-task-no-isolation-akukanov branch from c6870af to 632adb6 Compare December 19, 2025 13:43
Comment thread src/tbb/mailbox.h Outdated

//! Checks if a given task is a proxy, then either extracts the real task or frees the proxy.
template<bool B = false>
static task* try_extract_task_from ( task* t, execution_data_ext& ed, std::integral_constant<bool, B> stolen = {} ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line is too wide. Let's try keeping them not longer than ~100 characters.

Suggested change
static task* try_extract_task_from ( task* t, execution_data_ext& ed, std::integral_constant<bool, B> stolen = {} ) {
static task* try_extract_task_from ( task* t, execution_data_ext& ed,
std::integral_constant<bool, B> stolen = {} ) {

Copy link
Copy Markdown
Contributor Author

@akukanov akukanov Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me just remove a couple of extra spaces, so that it fits into 120 symbols. Given that in this very file there are lines with more than 140 symbols, and no consistent style for spaces around parentheses, I think that should be enough.

Comment thread src/tbb/mailbox.h
//! Checks if a given task is a proxy, then either extracts the real task or frees the proxy.
template<bool B = false>
static task* try_extract_task_from ( task* t, execution_data_ext& ed, std::integral_constant<bool, B> stolen = {} ) {
__TBB_ASSERT(t && !is_poisoned(t), "Not a valid task pointer");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try_extract_task_from seems to be always called from the places where t != nullptr. Perhaps, this function could accept a reference on the task instead. Thus, the dereferences would not be needed anywhere in this function, and the nullptr check would be naturally integrated into the function contract.

Copy link
Copy Markdown
Contributor Author

@akukanov akukanov Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not feel right to me. It seems like trading two pointer dereferences for getting a task address just as many times.
In general, these parts of the scheduler mostly deal with task pointers as data, not with tasks as objects. One can argue that operations with task_proxy need to access the object state and so to dereference the pointer - and that's true but this logic is encapsulated in task_accessor, and dereferencing is done when its functions are called. For this function, I prefer the semantics of "take what appears to be a valid task pointer, and return the pointer to the actual task. unwrapped from proxy if necessary".

Comment thread src/tbb/task_dispatcher.h Outdated
}
// Retrieve the task from local task pool
if (t || (slot.is_task_pool_published() && (t = slot.get_task(ed, isolation)))) {
if (t || (slot.is_task_pool_published() && (t = slot.get_task(ed, isolation, use_isolation)))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, make this part a bit more readable?

Suggested change
if (t || (slot.is_task_pool_published() && (t = slot.get_task(ed, isolation, use_isolation)))) {
if ( !t && slot.is_task_pool_published() ) {
t = slot.get_task(ed, isolation, use_isolation);
}
if ( t ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I instead moved the is_task_pool_published check into get_task.

Comment thread src/tbb/arena_slot.cpp Outdated
//------------------------------------------------------------------------

d1::task* arena_slot::get_task(execution_data_ext& ed, isolation_type isolation) {
d1::task* arena_slot::get_task(execution_data_ext& ed, isolation_type isolation, std::false_type) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment describing what the last parameter mean for function definitions as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@omalyshe omalyshe added this to the 2023.1.0 milestone Mar 9, 2026
@akukanov akukanov force-pushed the dev/get-task-no-isolation-akukanov branch from 632adb6 to 2951d54 Compare March 9, 2026 20:37
@akukanov akukanov force-pushed the dev/get-task-no-isolation-akukanov branch from 2951d54 to 3a7d027 Compare March 10, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants