![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file
Package Dependencies
System Dependencies
Dependant Packages
Launch files
Messages
Services
Plugins
Recent questions tagged minimal_scheduling at Robotics Stack Exchange
![]() |
minimal_scheduling package from ros2-realtime-examples repominimal_cpu_affinity minimal_memory_lock minimal_scheduling |
ROS Distro
|
Package Summary
Tags | No category tags. |
Version | 0.0.1 |
License | Apache License 2.0 |
Build type | AMENT_CMAKE |
Use | RECOMMENDED |
Repository Summary
Description | Minimal ROS 2 real-time cookbook recipes |
Checkout URI | https://github.com/ros-realtime/ros2-realtime-examples.git |
VCS Type | git |
VCS Version | rolling |
Last Updated | 2023-06-05 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | real-time cpp realtime ros ros2 rclcpp |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Package Description
Additional Links
Maintainers
- Carlos San Vicente
Authors
- Carlos San Vicente
- Jan Staschulat
minimal_scheduling
These examples show how to configure the thread scheduling policy and priority using pthread APIs.
In order to show the effects of using a real-time scheduling policy, the examples show the number of involuntary context switches in each callback execution. An involuntary context switches happens when the kernel scheduler preempts a task to schedule a higher priority thread or by a I/O request.
Using a real-time scheduling policy and using a real-time priority removes or reduces the number of involuntary context switches.
Note: The code shown in the examples is not necessarily real-time safe. The aim of these examples is to show a minimal usage example for a particular concept.
Requirements
Adjust permissions for the scheduler. Add to /etc/security/limits.conf
(as sudo):
<your username> - rtprio 98
How to run
minimal_scheduling_main_thread
For this example, we will be configuring the main thread scheduling policy of the main thread, where the node is spinning. In this case, the middleware threads will not inherit these settings because they are created after the scheduling configuration.
Using SCHED_OTHER scheduling policy
We start with the default settings, which means we don’t configure the main thread scheduling
policy and priority. In Linux, by default, the SCHED_OTHER
scheduling policy is used. Since,
this is not a real-time scheduling policy the main thread might be preempted frequently. For this
reason, we expect to see a high number of involuntary context switches.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread
Using SCHED_FIFO scheduling policy
Now we run the same example but using the SCHED_FIFO
scheduling policy and setting a priority
of 80.
There are just a few kernel threads running with a higher priority, so we expect to see a few number of involuntary context switches or none.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_FIFO --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
$ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr
TID COMMAND RTPRIO CLS PSR
6775 minimal_sched_f 80 FF 7
6776 minimal_sched_f - TS 1
6777 gc - TS 1
6778 dq.builtins - TS 0
6779 dq.user - TS 6
6780 tev - TS 2
6781 recv - TS 4
6782 recvMC - TS 0
6783 recvUC - TS 1
6784 minimal_sched_f - TS 0
Note we are not configuring the threads created by the RMW middleware. These threads will run with normal priority. This option might be preferred when middleware communications shall not participate in the real-time execution. Also, some DDS implementations allow to configure each thread scheduling individually, allowing to set a priority different creator thread.
Using SCHED_RR scheduling policy
Now we run the same example but using the SCHED_RR
scheduling policy and setting a priority
of 80. We expect to see the same results as in the previous case.
$ ros2 run minimal_scheduling minimal_scheduling_main_thread --sched SCHED_RR --priority 80
Using htop
or ps
we can observe the priorities and the scheduling policies of the threads.
```bash $ ps -C minimal_schedul -L -o tid,comm,rtprio,cls,psr TID COMMAND RTPRIO CLS PSR 16359 minimal_schedul 80 RR 3 16360 minimal_schedul - TS 6 16361 gc - TS 1 16362 dq.builtins - TS 6 16363 dq.user - TS 1
File truncated at 100 lines see the full file