-
Notifications
You must be signed in to change notification settings - Fork 3
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 OS scheduling parameters control #18
Comments
Nice, could you join our regular call on Mon next week and tell us a little bit more about your work? |
Hi everyone, I wanted to provide some feedback on this proposal as a follow-up to our RT working group meeting on last monday (27th Jan 23). First, I like the idea of having a replacement for std::thread in an interface compatible way. This is somewhat similar with what I tried to achieve with replacing std::mutex (see ros2/rcpputils#174). I took a look at the pull requests referenced above and if I understood them correctly the thread configuration is implemented in a global way, i.e. there is no distinction possible for different executor instances. I think that this distinction is necessary and I adressed this functionality in a proposal that I published recently, see https://discourse.ros.org/t/adding-thread-configuration-functionality-for-rclcpp-executors/29753 I agree with Carlos that it would make sense to have a factory interface for thread creation in C++ (something which I also wrote about in my afore mentioned ROS discourse article). This approach would be more flexible since, for example, it allows creating a thread pool implementation. Ideally all new interfaces should be optional, i.e. it should always be possible to pass nullptr where they are used. Putting all thread configuration related code into a separate ROS2 realtime support package, either an existing one or a new one, and in case of C++ "hiding" the new functionality behind interfaces seems to be a neat approach. Alternatively, a CMake option could be used which allows turning new functionality on or off without changing a line of code, for example see https://github.com/ros2/rcpputils/pull/174/files#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20a It seems that a lot is going on recently in the ROS2 community, in particular with the takeover of OSRC by Google and the new Space ROS working group. I wonder if some other team has also started on implementing thread configuration functionality for ROS 2? Maybe someone with good connections can try to find out? The TSC meeting might be a good place to ask that question? Best, Martin @razr @carlossvg @JanStaschulat |
In case there is consensus that we should have a C based low level OS & POSIX abstraction I could also adapt my implementations of rclcpp::PIMutex and rclcpp::RecursivePIMutex accordingly (see https://github.com/ros2/rcpputils/blob/e75a51280bb4e0f1c8b72ff7b241c14c1cedb342/src/mutex.cpp ) once we figured out how to organize that abstraction layer. Should not be a big deal. |
^ FYI @shuhaowu |
@WideAwakeTN
In my understanding, each ROS parameter belongs to each node, not each process. But, intrinsically, threads belong to each process. So, it seems natural to receive scheduling parameters of the thread pool used by ROS 2 executors at "rcl" level (not as ROS parameters at "rclcpp" level).
Do you mean that we have to prepare other infrastructures to set scheduling parameters, like ROS parameters? (Q2)
I know there was a pointing out that the rclcpp's implementation should be platform agnostic. But, if we could prepare a fallback implementation for which the environment had not been supported yet, it would still have backward compatibility.
As I said in the last meeting, we have to prepare some infrastructures (of course, including your PIMutex) to support real-time capabilities in the ROS 2 framework.
If necessary, my team will move the rclcpp::thread implementation to rcpputils. Could you kindly address any documents or requirements of ROS 2 to direct us to separate the environment-specific code from rclcpp? (Q4) My team could not find any rule specifying where we should place such code.
As I said at the last meeting, I'm not sure if this issue ticket is the correct thread where we discuss this topic. If you have, could you kindly point out a proper thread or place to discuss this topic? Or do we have to invite them here somehow? (Q5)
Thanks for your consideration. |
I added the "fallback" above in the commit below. |
Regarding Q1 and Q2: I have no concrete plans on how to best implement and parse parameters for executors. In any case, the executors would need some name or ID which can be referenced in a config file. The parsing of thread configurations can happen at the rcl level, like in your implementation and like it also is the case for the node parameters, as far as I know. But I think there should be a discussion on where to store the thread configurations: in a new config file or an ordinary ROS parameters file which could be extended to also contain thread configurations for executors. I bring this point up because it might be handy to add parameter functionality to executors in general, for example to configure the queue size of an internal ring buffer of a particular executor instance. To prevent confusion: I suspect that executor parameters and node parameters will not share the same codebase since executor parameters have different characteristics than node parameters, i.e. in my opinion executor parameters don't have to be accessible through services and they don't change during runtime. Regarding Q3: it might be nice to have all code that could cause trouble compiling ROS2, since that code is OS dependent, in a separate package. For example, if someone wanted to compile ROS2 on an unsupported system, for example FreeRTOS, that person would only need to change or rewrite that package. A separate package would also prevent adding confusing ifdefs to already existing packages. In case of my PiMutex classes I finally tried to put most of the ifdefs into the respective CMakeLists.txt, but I am also open to put OS dependent code into a separate package. Regarding Q4: I am not entirely sure if rclcpp or rcpputils is more appropriate for your thread class. Maybe someone else can comment on that. I would move the PiMutex classes to rclcpp, in case it turns our that this namespace is more appropriate. Regarding Q5: As far as I know "Next generation ROS" at https://discourse.ros.org/c/ng-ros/25 is the best place to propose new stuff. But, I am not sure if the persons in charge, like the maintainers, will take notice. My latest article which proposed to introduce named executors even remained unanswered as of now. There is also a technical steering commitee (TSC), but I don't know how to reach them or how they create technical roadmaps. I took a look at your thread class implementation. I guess an interface would make sense for the threads, e.g. rclcpp::IThread or rcpputils::IThread. In this way someone could implement a thread class in his own package, for example to support concurrency on an unsupported microcontroller system. The thread interface approach would also fit better with the idea of having a thread factory, which in turn would allow the implementation of thread pools. Note: what was written above are just my personal opinions and suggestions. I have no official affiliation with OSRF. |
Then, would you agree that we might well just add a string parameter (e.g. ID) for each thread attribute configuration as an initial proposal? (Q6)
I know we cannot create a fully comprehensive design of configurations related to executors at once. But, only for thread configurations used by the executor, the current parameter set we are discussing seems relatively good as an initial proposal.
I completely agree with you.
As you can see in the commit, we choose almost the same approach to pack the environment-specific code to avoid unnecessary ifdefs, using CMakeLists.txt.
As I mentioned in the 13th March meeting, I will transfer this discussion into ROS Discourse after the topics to be discussed here are agreed with you.
Our intention is to provide an infrastructure for ROS 2 function developers (not application developers) to implement real-time executors. So, we think the thread management features, which use such an interface, should be included in each executor implementation(so such an implementation is not needed).
When our team tried to control the thread priority for each thread controlled by the existing multithread executor, we found there was no measure to control it within the ROS 2 feature in itself. |
Maybe it’s helpful to come up with a somewhat complete set of questions? I tried to collect all the questions that came to my mind so far in the bullet list below. Topic: How to provide thread configuration functionality in the context of ROS2? Regarding plain C:
Regarding C++:
Regarding Python:
@smorita-esol |
Our team is adding some comments to @WideAwakeTN 's list. Could you kindly inform me of any additional comments or items to be discussed before the end of this week? Then, we could append them the list to be shared before submitted. |
I've thrown the updated list to a ROS Discourse thread as below. |
This is a prototype implementation of RCLCPP for discussion about the thread configuration feature to receive and apply a set of scheduling parameters for the threads controlled by the ROS 2 executor. Our basic idea is as below. 1. Implement a new class rclcpp::thread and modify rclcpp to use it. This class has the same function set as the std::thread but also additional features to control its thread attributions. 2. Modify the rcl layer to receive a set of scheduling parameters. The parameters are described in YAML format and passed via command line parameters, environment variables, or files. 3. the rclcpp reads the parameters from rcl and applies them to each thread in the thread pool. There have been some discussions about this pull request, as below. [ROS Discourse] https://discourse.ros.org/t/adding-thread-attributes-configuration-in-ros-2-framework/30701 [ROS 2 Real-Time Working Group] ros-realtime/ros-realtime.github.io#18
This is a prototype implementation of RCL for discussion about the thread configuration feature to receive and apply a set of scheduling parameters for the threads controlled by the ROS 2 executor. Our basic idea is as below. 1. Implement a new class rclcpp::thread and modify rclcpp to use it. This class has the same function set as the std::thread but also additional features to control its thread attributions. 2. Modify the rcl layer to receive a set of scheduling parameters. The parameters are described in YAML format and passed via command line parameters, environment variables, or files. 3. the rclcpp reads the parameters from rcl and applies them to each thread in the thread pool. There have been some discussions about this pull request, as below. [ROS Discourse] https://discourse.ros.org/t/adding-thread-attributes-configuration-in-ros-2-framework/30701 [ROS 2 Real-Time Working Group] ros-realtime/ros-realtime.github.io#18
This is a prototype implementation of RCLCPP for discussion about the thread configuration feature to receive and apply a set of scheduling parameters for the threads controlled by the ROS 2 executor. Our basic idea is as below. 1. Implement a new class rclcpp::thread and modify rclcpp to use it. This class has the same function set as the std::thread but also additional features to control its thread attributions. 2. Modify the rcl layer to receive a set of scheduling parameters. The parameters are described in YAML format and passed via command line parameters, environment variables, or files. 3. the rclcpp reads the parameters from rcl and applies them to each thread in the thread pool. There have been some discussions about this pull request, as below. [ROS Discourse] https://discourse.ros.org/t/adding-thread-attributes-configuration-in-ros-2-framework/30701 [ROS 2 Real-Time Working Group] ros-realtime/ros-realtime.github.io#18 Signed-off-by: Shoji Morita <[email protected]>
This is a prototype implementation of RCL for discussion about the thread configuration feature to receive and apply a set of scheduling parameters for the threads controlled by the ROS 2 executor. Our basic idea is as below. 1. Implement a new class rclcpp::thread and modify rclcpp to use it. This class has the same function set as the std::thread but also additional features to control its thread attributions. 2. Modify the rcl layer to receive a set of scheduling parameters. The parameters are described in YAML format and passed via command line parameters, environment variables, or files. 3. the rclcpp reads the parameters from rcl and applies them to each thread in the thread pool. There have been some discussions about this pull request, as below. [ROS Discourse] https://discourse.ros.org/t/adding-thread-attributes-configuration-in-ros-2-framework/30701 [ROS 2 Real-Time Working Group] ros-realtime/ros-realtime.github.io#18 Signed-off-by: Shoji Morita <[email protected]>
Referring to the draft paper of the executor design below, I found that we face the same challenge below (particularly b.).
https://docs.google.com/document/d/1O53xOVlk4zwsfNukLaDbSWfT64wnoD9xh2EjWwX43qo/edit
My team is currently investigating how to pass the scheduling parameters to the ROS 2 Executor. And we have already implemented a prototype to receive and apply a set of scheduling parameters for the threads controlled by the ROS 2 real-time executor. We'd like to share the code with the community as some pull requests, but it might be better to share it here and get some feedback from the members who face the same problem here beforehand.
Our basic idea is as below.
This class has the same function set as the std::thread but also additional features to control its thread attributions.
The parameters are described in YAML format and passed via command line parameters, environment variables, or files.
*1. the current implementation uses them only for the Multithread Executor.
I've forked the rcl and rclcpp repositories to our team's account and created pull requests for them so that we will be able to have a discussion about it.
rcl: esol-community/rcl#1
rclcpp: esol-community/rclcpp#1
And, considering the discussion below, my team will add a rclcpp::thread implementation delegating all the functions to the std::thread ASAP so as to be able to be used in the environment where the specific rclcpp::thread is not implemented yet.
ros2/rcutils#406
The text was updated successfully, but these errors were encountered: