ros-controls / realtime_tools

Contains a set of tools that can be used from a hard realtime thread, without breaking the realtime behavior.
https://control.ros.org
BSD 3-Clause "New" or "Revised" License
140 stars 76 forks source link

Use pthread_setaffinity_np for setting affinity rather than sched_setaffinity #190

Closed saikishor closed 3 weeks ago

saikishor commented 3 weeks ago

This PR aims to change the earlier approach with pthread_setaffinity_np as it is more generic and it can be scalable to all other controllers.

The good thing is it doesn't affect the recently merged changes : https://github.com/ros-controls/ros2_control/pull/1852

I've also added corresponding tests in different places

codecov-commenter commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 72.97%. Comparing base (45e93d7) to head (593dc27).

Files with missing lines Patch % Lines
src/realtime_helpers.cpp 90.90% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #190 +/- ## ========================================== + Coverage 72.13% 72.97% +0.84% ========================================== Files 8 8 Lines 384 396 +12 Branches 64 65 +1 ========================================== + Hits 277 289 +12 + Misses 69 68 -1 - Partials 38 39 +1 ``` | [Flag](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/190/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/190/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | `72.97% <90.90%> (+0.84%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/190?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls) | Coverage Δ | | |---|---|---| | [include/realtime\_tools/async\_function\_handler.hpp](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/190?src=pr&el=tree&filepath=include%2Frealtime_tools%2Fasync_function_handler.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-aW5jbHVkZS9yZWFsdGltZV90b29scy9hc3luY19mdW5jdGlvbl9oYW5kbGVyLmhwcA==) | `91.25% <ø> (ø)` | | | [src/realtime\_helpers.cpp](https://app.codecov.io/gh/ros-controls/realtime_tools/pull/190?src=pr&el=tree&filepath=src%2Frealtime_helpers.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ros-controls#diff-c3JjL3JlYWx0aW1lX2hlbHBlcnMuY3Bw) | `37.34% <90.90%> (+10.58%)` | :arrow_up: |
saikishor commented 3 weeks ago

@firesurfer can you check this once?

saikishor commented 3 weeks ago

In general this looks good to me with a minor notes: https://en.cppreference.com/w/cpp/thread/thread/native_handle native_handle is only available for systems with a posix threading model. I am not sure if there might be some weird combination of systems (apart from windows) where it is not available and might lead to compilation errors

Most of the systems now supports. The following information, I got it using Copilot

Systems that support a POSIX threading model (also known as POSIX threads or Pthreads) include most Unix-like operating systems. POSIX threads are a standard for thread creation and synchronization, defined by the POSIX.1c standard (IEEE Std 1003.1c-1995). Here are some systems that support POSIX threads:

Unix-like Operating Systems

Other Operating Systems

As this is the case, I think this should be good to go