-
Notifications
You must be signed in to change notification settings - Fork 141
Add real-time scheduling helper functions and documentation #535
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
Open
srvald
wants to merge
25
commits into
UniversalRobots:master
Choose a base branch
from
srvald:set_thread_priority_helper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0d429af
feat: add real-time helper functions for windows
srvald 551a81e
docs: add Windows soft real-time configuration guide and helper funct…
srvald 54f25d0
docs: helper functions example
srvald bcf53e1
test: add unit tests for scheduling and affinity helpers.
srvald 0eb997d
docs: show scheduling helper usage in RTDE example
srvald 7bbf842
fix: adjust wrong argument and file format
srvald ec350f4
fix: adjust format and wrong test expected return
srvald 85f2896
fix: example back to normal adding the scheduling helper functions
srvald 64e0774
fix: show UAC warning only when REALTIME priority.
srvald 4fc6d35
fix: remove GNU SOURCE
srvald 012ae04
fix: avoid cpu_set_t on apple
srvald 161f4de
fix: return false if cannot get affinity thread ubuntu
srvald d246b08
fix: add elif linux to avoid function to be used with Apple
srvald 0666c9f
fix: apply old process priority if thread priority fails at FiFo sche…
srvald 633483d
tests: compatible cpu affinity mask for github actions
srvald e91a534
tests: remove FIFO scheduling tests
srvald 7a48877
test: correct CPUs at thread affinity mask for ubuntu and some tests …
srvald 6c3f64c
fix: fix format
srvald e62bd2c
tests: resolve unused variable using Apple
srvald d09ed57
fix: adjust code format
srvald c3a202a
example: compatible with Apple
srvald 6fe9f2c
docs: Remove whitespace
srvald 37599d1
fix: adjust format and thread missing with Apple
srvald b56bdb0
refactor: if failure, set previos priority back
srvald 41f371c
fix: adjust format
srvald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,12 +48,18 @@ | |
| # define SCHED_FIFO (1) | ||
|
|
||
| typedef HANDLE pthread_t; | ||
| typedef HANDLE pprocess_t; | ||
|
|
||
| static inline pthread_t pthread_self() | ||
| { | ||
| return ::GetCurrentThread(); | ||
| } | ||
|
|
||
| static inline pprocess_t pprocess_self() | ||
| { | ||
| return ::GetCurrentProcess(); | ||
| } | ||
|
|
||
| static inline int sched_get_priority_max(int policy) | ||
| { | ||
| (void)policy; | ||
|
|
@@ -96,7 +102,88 @@ static inline int sched_get_priority_max(int policy) | |
|
|
||
| namespace urcl | ||
| { | ||
| bool setFiFoScheduling(pthread_t& thread, const int priority); | ||
|
|
||
| #ifdef _WIN32 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer if we had only one function definition and do the necessary platform-specific calls inside them. |
||
|
|
||
| /*! | ||
| * \brief Set the priority class of a process. | ||
| * | ||
| * Wraps the corresponding operating system API and verifies that the requested | ||
| * priority class has been applied successfully. | ||
| * | ||
| * \param process Process handle. | ||
| * \param priority Windows process priority class. | ||
| * | ||
| * \returns True if the priority class was applied successfully. | ||
| */ | ||
| bool setProcessPriority(pprocess_t& process, DWORD priority); | ||
|
|
||
| /*! | ||
| * \brief Restrict a process to a set of CPUs. | ||
| * | ||
| * Wraps the corresponding operating system API and verifies that the requested | ||
| * CPU affinity mask has been applied successfully. | ||
| * | ||
| * \param process Process handle. | ||
| * \param cpu_mask Bit mask describing the CPUs available to the process. | ||
| * | ||
| * \returns True if the affinity mask was applied successfully. | ||
| */ | ||
| bool setProcessAffinity(pprocess_t& process, DWORD_PTR cpu_mask); | ||
|
|
||
| /*! | ||
| * \brief Restrict a thread to a set of CPUs. | ||
| * | ||
| * \param thread Thread handle. | ||
| * \param cpu_mask Bit mask describing the CPUs available to the thread. | ||
| * | ||
| * \returns True if the affinity mask was applied successfully. | ||
| */ | ||
| bool setThreadAffinity(pthread_t& thread, DWORD_PTR cpu_mask); | ||
|
|
||
| /*! | ||
| * \brief Set the scheduling priority of a thread. | ||
| * | ||
| * Wraps the corresponding operating system API and verifies that the requested | ||
| * priority has been applied successfully. | ||
| * | ||
| * \param thread Thread handle. | ||
| * \param priority Windows thread priority value. | ||
| * | ||
| * \returns True if the priority was applied successfully. | ||
| */ | ||
| bool setThreadPriority(pthread_t& thread, const int priority); | ||
|
|
||
| #elif __linux__ | ||
|
|
||
| /*! | ||
| * \brief Restrict a thread to a set of CPUs. | ||
| * | ||
| * \param thread Thread handle. | ||
| * \param cpuset Set of CPUs available to the thread. | ||
| * | ||
| * \returns True if the CPU affinity was applied successfully. | ||
| */ | ||
| bool setThreadAffinity(pthread_t& thread, const cpu_set_t& cpuset); | ||
|
|
||
| #endif | ||
|
|
||
| /*! | ||
| * \brief Configure high-priority scheduling for a thread. | ||
| * | ||
| * On Linux, this configures ``SCHED_FIFO`` scheduling using the supplied | ||
| * priority. | ||
| * | ||
| * On Windows, this configures the process to use | ||
| * ``REALTIME_PRIORITY_CLASS`` and sets the thread to the supplied Windows | ||
| * thread priority. | ||
| * | ||
| * \param thread Thread handle. | ||
| * \param priority Scheduling priority to apply. | ||
| * | ||
| * \returns True if the scheduling configuration was applied successfully. | ||
| */ | ||
| bool setFiFoScheduling(pthread_t& thread, int priority); | ||
|
|
||
| /*! | ||
| * \brief Wait for a condition to be true. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Suggestion use a typedef such as
urcl::ThreadTandurcl::ProcessTfor both, windows and non-windows. Then, the function signatures can use this typedef-ed type and share their declarations.Also, consider using
void*on Windows and avoid includingwindows.h