-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix get_stack_base in linux v2 #1485
Fix get_stack_base in linux v2 #1485
Conversation
src/tbb/governor.cpp
Outdated
size_t np_stack_size = 0; | ||
pthread_attr_t np_attr_stack; | ||
if (0 == pthread_getattr_np(pthread_self(), &np_attr_stack)) { | ||
if (0 == pthread_attr_getstacksize(&np_attr_stack, &np_stack_size)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this call be sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is sufficient.
If stack size is not set by pthread_attr_setstacksize(), inside pthread_attr_getstacksize() can handle it. (by RLIMIT_STACK)
src/tbb/governor.cpp
Outdated
#else | ||
return a.my_threading_control->worker_stack_size(); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add implementation for the rest of OS? (The same logic as for get_stack_base
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of OS are no portable way to get stack size.
get_stack_base() like the below.
- windows: get stack_base and stack_limit (no stack size)
- linux: pthread_attr_np API
- others: no way for stack base and size -> just using current stack pointer
@aleksei-fedotov what do you think? |
@pavelkumbrasev Any update for this? I'm waiting for an reply. |
And maybe the commentary also need to be updated. |
@aleksei-fedotov
|
@bongkyu7-kim Yeah, but according to this part of the comment that was done on purpose. To be clear, I don't disagree with your proposal. I just disagree with the implementation approach you chose. I think we can do better. The issues I see with the patch:
So, to improve the code I propose the following:
|
|
@bongkyu7-kim I looked at your previous PR #1389. So, I suggest having the following changes:
|
ebb9960
to
680e0e6
Compare
@aleksei-fedotov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bongkyu7-kim almost done. I believe one more change and we finish it.
Good that we avoided changing the commentary part as it remains relevant.
680e0e6
to
8f8047a
Compare
In case of pthread_attr_getstack() returns np_stack_size = 1MB, - calculated stack_base = stack_limit + stack_size(default: 4MB) - real stack_base = stack_limit + np_stack_size(1MB) stack_base is wrong because calculated with 4MB stack size. Due to this wrong stack_base, task_dispatcher::can_steal() can be always false. It causes abnormal long loop in task_dispatcher::receive_or_steal_task(). Correct this problem using np_stack_size instead of stack_size. Signed-off-by: Bongkyu Kim <[email protected]>
8f8047a
to
cbb3656
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the patch looks good to me. Nice job, @bongkyu7-kim!
I suppose PR #1389 can be closed as well?
@aleksei-fedotov |
In case of pthread_attr_getstack() returns np_stack_size = 1MB,
Due to this wrong stack_base, task_dispatcher::can_steal() can be always false. It causes abnormal long loop in task_dispatcher::receive_or_steal_task().
Correct stack_size by pthread_attr_getstacksize() in linux.
Description
Add a comprehensive description of proposed changes
Fixes # - issue number(s) if exists
Type of change
Choose one or multiple, leave empty if none of the other choices apply
Add a respective label(s) to PR if you have permissions
Tests
Documentation
Breaks backward compatibility
Notify the following users
@pavelkumbrasev
Other information