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

Add support to parse multiple cores for setting CPU affinity #208

Merged

Conversation

saikishor
Copy link
Member

This PR adds a new method that helps to set multiple CPUs for affinity instead of only one and this will help in choosing couple of CPUs to run the controller_manager etc

@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.

Project coverage is 72.72%. Comparing base (069df6d) to head (9ac21d4).

Files with missing lines Patch % Lines
src/realtime_helpers.cpp 76.47% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
+ Coverage   72.55%   72.72%   +0.17%     
==========================================
  Files           7        7              
  Lines         419      429      +10     
  Branches       68       71       +3     
==========================================
+ Hits          304      312       +8     
  Misses         73       73              
- Partials       42       44       +2     
Flag Coverage Δ
unittests 72.72% <76.47%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/realtime_helpers.cpp 39.79% <76.47%> (+4.56%) ⬆️

@firesurfer
Copy link
Contributor

I just saw the PR by chance and was interested as I authored the original one. I am wondering in which (realtime) scenario would you like to prefer a set of cores? From my understanding every time a thread is executed on the different core we suffer from

a) Context switch overhead
b) Additional cache misses

Both brings in an uncertainty which we do not want in RT scenarios.

The only case I can imagine this could help is modern CPUs with multiple dies inside (e.g. most Ryzen processors). But the OS scheduler will already take care of trying not to move threads between cores on different dies per default.

@saikishor
Copy link
Member Author

@firesurfer You can set it at the startup as we do in the ros2_control_node or in the configure of controllers and hardware components

@firesurfer
Copy link
Contributor

@firesurfer You can set it at the startup as we do in the ros2_control_node or in the configure of controllers and hardware components

I am aware of that. But I just wanted to understand why it is an advantage in a RT scenario to use the group of cores instead of tying the thread to a single core.

@saikishor
Copy link
Member Author

I am aware of that. But I just wanted to understand why it is an advantage in a RT scenario to use the group of cores instead of tying the thread to a single core.

By default, it uses mostly Core 0 as other. If you can use a set of performance cores, it would be better for the RT application, if your application needs more computational power than one core, then this definitely helps

@saikishor saikishor requested a review from firesurfer November 28, 2024 08:47
Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

LGTM

@christophfroehlich christophfroehlich merged commit efcb786 into ros-controls:master Nov 28, 2024
24 checks passed
@saikishor saikishor deleted the multi/cpu/affinity branch November 28, 2024 09:57
@christophfroehlich
Copy link
Contributor

@Mergifyio backport humble

Copy link

mergify bot commented Dec 4, 2024

backport humble

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Dec 4, 2024
christophfroehlich added a commit that referenced this pull request Dec 6, 2024
…#208) (#223)

Add support to parse multiple cores for setting CPU affinity (#208)

(cherry picked from commit efcb786)

Co-authored-by: Sai Kishor Kothakota <sai.kishor@pal-robotics.com>
Co-authored-by: Christoph Fröhlich <christophfroehlich@users.noreply.github.com>
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.

4 participants