Skip to content

Commit 858edf4

Browse files
committed
docs: Add instructions on how to create a real-time-capable systemd service
1 parent 2016a15 commit 858edf4

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

doc/PreemptRt.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ubuntu realtime-kernel/`PREEMPT_RT` set-up
22

3-
Author: [Tobit Flatscher](https://github.com/2b-t) (August 2021 - February 2023)
3+
Author: [Tobit Flatscher](https://github.com/2b-t) (2021 - 2024)
44

55
## 1. Setting-up `PREEMPT_RT`
66

@@ -262,7 +262,7 @@ Now it is time to build the kernel:
262262
$ sudo dpkg -r linux-image-${PREEMPT_RT_VER_FULL}
263263
```
264264

265-
The advantage of the Debian package is that you can distribute and remove it more easily than the direct installation.
265+
The advantage of the Debian package is that you can distribute and remove it more easily than the direct installation. The generation of the debug version might take much longer than the release version. Just be patient!
266266

267267
- Alternatively you can build and **install it directly** without creating a Debian package first
268268

@@ -302,9 +302,27 @@ In this context `rtprio` is the maximum real-time priority allowed for non-privi
302302

303303
### 1.4 Set real-time schedule
304304

305-
The real-time schedule of a process can be set from the command line with `chrt` as discussed [here](https://askubuntu.com/questions/51283/how-to-run-a-program-with-sched-rr-policy-from-command-line).
305+
The real-time schedule of a process can be set from the command line with `chrt` as discussed [here](https://askubuntu.com/questions/51283/how-to-run-a-program-with-sched-rr-policy-from-command-line) or from within the process as discussed in the [chapter on real-time programming](./RealTimeProgramming.md). For a [systemd service](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html) (for the basics refer also to [this tutorial](https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6)) you can either set a priority to the service itself by specifying `CPUSchedulingPolicy=fifo` and `CPUSchedulingPriority=90` as described [here](https://superuser.com/a/403386) or specify a maximum priority that the process can be set to through the parameter `LimitRTPRIO` inside the corresponding service file, e.g. `/etc/systemd/system/my.service`:
306306

307+
```
308+
[Unit]
309+
Description=My service
310+
311+
[Service]
312+
Environment=SOME_VAR=some_value
313+
ExecStart=./path/to/my/process
314+
KillMode=process
315+
KillSignal=SIGINT
316+
# This allows the process to set the priority from inside the program to this maximum value
317+
LimitRTPRIO=99
318+
Type=simple
319+
User=my_user
320+
321+
[Install]
322+
WantedBy=multi-user.target
323+
```
307324

325+
In the case of `LimitRTPRIO` make sure to set the priority and scheduling process from inside the code and check the return values as well as with `htop` to make sure it was set successfully.
308326

309327
### 1.5 Set boot order
310328

0 commit comments

Comments
 (0)