-
Notifications
You must be signed in to change notification settings - Fork 101
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
Decoupled the additional feature from rcl to rcutils, reflecting on t… #424
Open
smorita-esol
wants to merge
5
commits into
ros2:rolling
Choose a base branch
from
esol-community:origin/sched_param_control_for_osrf
base: rolling
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
5 commits
Select commit
Hold shift + click to select a range
aeb3495
Decoupled the additional feature from rcl to rcutils, reflecting on t…
smorita-esol ec49b25
Update thread_attr.h
smorita-esol 51e57d7
Added tests and fixed problems found in the test.
smorita-esol bfab6e3
Modified to receive multiple core affinity parameters according to th…
smorita-esol d27d544
Modified the structure of member names to reflect the point made on t…
smorita-esol 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 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 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 |
---|---|---|
@@ -0,0 +1,312 @@ | ||
// Copyright 2023 eSOL Co.,Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RCUTILS__THREAD_ATTR_H_ | ||
#define RCUTILS__THREAD_ATTR_H_ | ||
|
||
#include <stdbool.h> | ||
|
||
#include "rcutils/visibility_control.h" | ||
|
||
#include "rcutils/allocator.h" | ||
#include "rcutils/macros.h" | ||
#include "rcutils/types/rcutils_ret.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
typedef enum rcutils_thread_scheduling_policy_e | ||
{ | ||
RCUTILS_THREAD_SCHEDULING_POLICY_UNKNOWN = 0, | ||
RCUTILS_THREAD_SCHEDULING_POLICY_FIFO = 1, | ||
RCUTILS_THREAD_SCHEDULING_POLICY_RR = 2, | ||
RCUTILS_THREAD_SCHEDULING_POLICY_SPORADIC = 3, | ||
RCUTILS_THREAD_SCHEDULING_POLICY_OTHER = 4, | ||
RCUTILS_THREAD_SCHEDULING_POLICY_IDLE = 5, | ||
RCUTILS_THREAD_SCHEDULING_POLICY_BATCH = 6, | ||
RCUTILS_THREAD_SCHEDULING_POLICY_DEADLINE = 7 | ||
} rcutils_thread_scheduling_policy_t; | ||
|
||
typedef struct rcutils_thread_core_affinity_s | ||
{ | ||
// Array for bit pattern of core affinity | ||
uint8_t * set; | ||
// Bit count in the set | ||
size_t core_count; | ||
// Allocator used to allocate the set | ||
rcutils_allocator_t allocator; | ||
} rcutils_thread_core_affinity_t; | ||
|
||
typedef struct rcutils_thread_attr_s | ||
{ | ||
/// Thread core affinity | ||
rcutils_thread_core_affinity_t core_affinity; | ||
/// Thread scheduling policy. | ||
rcutils_thread_scheduling_policy_t scheduling_policy; | ||
/// Thread priority. | ||
int priority; | ||
/// Thread attribute tag | ||
char const * tag; | ||
} rcutils_thread_attr_t; | ||
|
||
/// Hold thread attribute rules. | ||
typedef struct rcutils_thread_attrs_s | ||
{ | ||
/// Private implementation array. | ||
rcutils_thread_attr_t * attributes; | ||
/// Number of threads attribute | ||
size_t num_attributes; | ||
/// Number of threads attribute capacity | ||
size_t capacity_attributes; | ||
/// Allocator used to allocate objects in this struct | ||
rcutils_allocator_t allocator; | ||
} rcutils_thread_attrs_t; | ||
|
||
/** | ||
* \brief Return a rcutils_thread_attrs_t struct with members initialized to zero value. | ||
* \return a rcutils_thread_attrs_t struct with members initialized to zero value. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_thread_attrs_t | ||
rcutils_get_zero_initialized_thread_attrs(void); | ||
|
||
/** | ||
* \brief Initialize list of thread attributes. | ||
* \param[out] thread_attrs list of thread attributes to be initialized | ||
* \param[in] allocator memory allocator to be used | ||
* \return #RCUTILS_RET_OK if the structure was initialized succeessfully, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_attrs_init( | ||
rcutils_thread_attrs_t * thread_attrs, | ||
rcutils_allocator_t allocator); | ||
|
||
/** | ||
* \brief Initialize list of thread attributes with a capacity. | ||
* \param[out] thread_attrs list of thread attributes to be initialized | ||
* \param[in] allocator memory allocator to be used | ||
* \return #RCUTILS_RET_OK if the structure was initialized succeessfully, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_attrs_init_with_capacity( | ||
rcutils_thread_attrs_t * thread_attrs, | ||
rcutils_allocator_t allocator, | ||
size_t capacity); | ||
|
||
/** | ||
* \brief Free list of thread attributes | ||
* \param[in] thread_attrs structure to be deallocated. | ||
* \return #RCUTILS_RET_OK if the memory was successfully freed, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_attrs_fini( | ||
rcutils_thread_attrs_t * thread_attrs); | ||
|
||
/** | ||
* \brief Copy list of thread attributes | ||
* \param[in] thread_attrs Source list of thread attributes | ||
* \param[out] out_thread_attrs Destination location | ||
* \return #RCUTILS_RET_OK if the source list was succesfully copied to the destination, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if may function arguments are invalid, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed | ||
*/ | ||
rcutils_ret_t | ||
rcutils_thread_attrs_copy( | ||
rcutils_thread_attrs_t const * thread_attrs, | ||
rcutils_thread_attrs_t * out_thread_attrs); | ||
|
||
/** | ||
* \brief Add thread attribute to the list of thread attributes. | ||
* \param[in,out] thread_attrs list of thread attributes to add a thread attribute to | ||
* \param[in] sched_policy thread scheduling policy of adding attribute | ||
* \param[in] core_affinity thread core affinity of adding attribute | ||
* \param[in] priority thread priority of adding attribute | ||
* \param[in] tag thread attribute tag of adding attribute | ||
* \return #RCUTILS_RET_OK if the thread attribute was successfully added, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_attrs_add_attr( | ||
rcutils_thread_attrs_t * thread_attrs, | ||
rcutils_thread_scheduling_policy_t sched_policy, | ||
rcutils_thread_core_affinity_t const * core_affinity, | ||
int priority, | ||
char const * tag); | ||
|
||
/** | ||
* \brief Return a zero-initialized rcutils_thread_core_affinity_t object. | ||
* \return zero-initialized rcutils_thread_core_affinity_t. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_thread_core_affinity_t | ||
rcutils_get_zero_initialized_thread_core_affinity(void); | ||
|
||
/** | ||
* \brief Initialize thread core affinity. | ||
* \param[out] affinity thread core affinity to be initialized. | ||
* \param[in] allocator allocator for internal memory operations for the thread core affinity. | ||
* \return #RCUTILS_RET_OK if affinity was successfully initialized, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_init( | ||
rcutils_thread_core_affinity_t * affinity, | ||
rcutils_allocator_t allocator); | ||
|
||
/** | ||
* \brief Initialize thread core affinity with number of cores. | ||
* \param[out] affinity thread core affinity to be initialized. | ||
* \param[in] num_cores initial number of core in the thread core affinity | ||
* \param[in] allocator allocator for internal memory operations for the thread core affinity. | ||
* \return #RCUTILS_RET_OK if affinity was successfully initialized, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_init_with_capacity( | ||
rcutils_thread_core_affinity_t * affinity, | ||
size_t num_cores, | ||
rcutils_allocator_t allocator); | ||
|
||
/** | ||
* \brief Copy thread core affinity. | ||
* \param[in] src core affinity to be copied. | ||
* \param[out] dest the destination. | ||
* \return #RCUTILS_RET_OK if affinity was successfully copied, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_copy( | ||
rcutils_thread_core_affinity_t const * src, rcutils_thread_core_affinity_t * dest); | ||
|
||
/** | ||
* \brief Free thread core affinity. | ||
* \param[in,out] affinity thread core affinity to be freed | ||
* \return #RCUTILS_RET_OK if affitiny was successfully freed, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_fini(rcutils_thread_core_affinity_t * affinity); | ||
|
||
/** | ||
* \brief Add processor number to thread core affinity. | ||
* \param[in,out] affinity thread core affinity | ||
* \param[in] no processor number to be added to the affinity set | ||
* \return #RCUTILS_RET_OK if the processor number is successfully added to the affinity. | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_set(rcutils_thread_core_affinity_t * affinity, size_t no); | ||
|
||
/** | ||
* \brief Remove processor number from thread core affinity. | ||
* \param[in,out] affinity thread core affinity | ||
* \param[in] no processor number to be removed from the affinity set | ||
* \return #RCUTILS_RET_OK if the processor number is successfully removed from the affinity. | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_unset(rcutils_thread_core_affinity_t * affinity, size_t no); | ||
|
||
/** | ||
* \brief Add processor numbers which are included in a range to thread core affinity. | ||
* \param[in,out] affinity thread core affinity | ||
* \param[in] min_no lower bound of the processor number range to be added (inclusive) | ||
* \param[in] max_no upper bound of the processor number range to be added (inclusive) | ||
* \return #RCUTILS_RET_OK if the processor numbers are successfully added to the affinity. | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if max_no less than min_no, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_fill( | ||
rcutils_thread_core_affinity_t * affinity, size_t min_no, size_t max_no); | ||
|
||
/** | ||
* \brief Remove processor numbers which are included in a range from thread core affinity. | ||
* \param[in,out] affinity thread core affinity | ||
* \param[in] min_no lower bound of the processor number range to be removed (inclusive) | ||
* \param[in] max_no upper bound of the processor number range to be removed (inclusive) | ||
* \return #RCUTILS_RET_OK if the processor numbers are successfully removed from the affinity. | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or | ||
* \return #RCUTILS_RET_INVALID_ARGUMENT if max_no less than min_no, or | ||
* \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or | ||
* \return #RCUTILS_RET_ERROR an unspecified error occur. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
rcutils_ret_t | ||
rcutils_thread_core_affinity_clear( | ||
rcutils_thread_core_affinity_t * affinity, size_t min_no, size_t max_no); | ||
|
||
/** | ||
* \brief check if thread core affinity contains processor number. | ||
* \param[in] affinity thread core affinity | ||
* \param[in] no processor number to check | ||
* \return true if the thread core affinity includes the number, false otherwise. | ||
*/ | ||
RCUTILS_PUBLIC | ||
RCUTILS_WARN_UNUSED | ||
bool | ||
rcutils_thread_core_affinity_is_set(rcutils_thread_core_affinity_t const * affinity, size_t no); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RCUTILS__THREAD_ATTR_H_ |
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.
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.
Thanks for your suggestion.
I've addressed it in ec49b25.