Skip to content

Commit a04bfde

Browse files
committed
Improve doc concerning latency testing and tuning
1 parent 1adfeb1 commit a04bfde

9 files changed

Lines changed: 403 additions & 121 deletions

File tree

‎docs/po4a.cfg‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
[type: AsciiDoc_def] src/hal/tutorial.adoc $lang:build/adoc/$lang/hal/tutorial.adoc
138138
[type: AsciiDoc_def] src/hal/twopass.adoc $lang:build/adoc/$lang/hal/twopass.adoc
139139
[type: AsciiDoc_def] src/install/latency-test.adoc $lang:build/adoc/$lang/install/latency-test.adoc
140+
[type: AsciiDoc_def] src/install/latency-tuning.adoc $lang:build/adoc/$lang/install/latency-tuning.adoc
140141
[type: AsciiDoc_def] src/integrator/steppers.adoc $lang:build/adoc/$lang/integrator/steppers.adoc
141142
[type: AsciiDoc_def] src/integrator/stepper-timing.adoc $lang:build/adoc/$lang/integrator/stepper-timing.adoc
142143
[type: AsciiDoc_def] src/integrator/wiring.adoc $lang:build/adoc/$lang/integrator/wiring.adoc

‎docs/src/Master_Documentation.adoc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ include::config/integrator-concepts.adoc[]
6464

6565
include::install/latency-test.adoc[]
6666

67+
include::install/latency-tuning.adoc[]
68+
6769
include::motion/tweaking-steppers.adoc[]
6870

6971
include::config/ini-config.adoc[]

‎docs/src/Submakefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ DOC_SRCS_EN := \
238238
hal/tutorial.adoc \
239239
hal/twopass.adoc \
240240
install/latency-test.adoc \
241+
install/latency-tuning.adoc \
241242
integrator/steppers.adoc \
242243
integrator/stepper-timing.adoc \
243244
integrator/wiring.adoc \
20.7 KB
Loading

‎docs/src/getting-started/system-requirements.adoc‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ such as checking G-code, testing config files and learning the system.
5454
To work with these kernel versions there are two versions of LinuxCNC distributed.
5555
The package names are "linuxcnc" and "linuxcnc-uspace".
5656

57-
The realtime kernel options are preempt-rt, RTAI and Xenomai.
57+
The realtime kernel options are PREEMPT_RT, RTAI, Xenomai3 and Xenomai4 EVL.
58+
59+
For most cases, PREEMPT_RT is the simplest option. For better latency, Xenomai4 EVL can help.
60+
61+
RTAI is not maintained any more but still works on some systems.
5862

5963
You can discover the kernel version of your system with the command:
6064

@@ -63,41 +67,52 @@ uname -a
6367
----
6468

6569
If you see (as above) `-rt-` in the kernel name then you are running the
66-
preempt-rt kernel and should install the "uspace" version of LinuxCNC.
70+
PREEMPT_RT kernel and should install the "uspace" version of LinuxCNC.
6771
You should also install uspace for "sim" configs on non-realtime kernels.
6872

6973
If you see `-rtai-` in the kernel name then you are running RTAI
7074
realtime. See below for the LinuxCNC version to install.
7175

7276
=== Preempt-RT with 'linuxcnc-uspace' package
7377

74-
Preempt-RT is the newest of the realtime systems, and is also the version
78+
Preempt-RT is the version
7579
that is closest to a mainline kernel. Preempt-RT kernels are available
7680
as precompiled packages from the main repositories. The search term
7781
"PREEMPT_RT" will find them, and one can be downloaded and installed
7882
just like any other package.
79-
Preempt-RT will generally have the best driver support and is the only
80-
option for systems using the Mesa ethernet-connected hardware driver
81-
cards. In general preempt-rt has the worst latency of the available
83+
Preempt-RT will generally have the best support.
84+
In general Preempt-RT has the worst latency of the available
8285
systems, but there are exceptions.
8386

87+
=== Xenomai3 with 'linuxcnc-uspace' package
88+
89+
Xenomai3 is supported, but you will have to find or build the kernel
90+
and compile LinuxCNC from source to utilise it.
91+
92+
Prebuilt experimental kernels can be found here: https://github.com/hdiethelm/xenomai3-linuxcnc
93+
94+
=== Xenomai4 EVL with 'linuxcnc-uspace' package
95+
96+
Xenomai4 is supported, but you will have to find or build the kernel
97+
and compile LinuxCNC from source to utilise it. It has support for
98+
Mesa ethernet-connected hardware driver with out of band realtime ethernet.
99+
100+
Prebuilt experimental kernels can be found here: https://github.com/hdiethelm/xenomai4-linuxcnc
101+
84102
=== RTAI with 'linuxcnc' package
85103

86104
RTAI has been the mainstay of LinuxCNC distributions for many years. It
87105
will generally give the best realtime performance in terms of low
88106
latency, but might have poorer peripheral support and not as many screen
89107
resolutions. An RTAI kernel is available from the LinuxCNC package
90108
repository. If you installed from the Live/Install image then switching
91-
kernel and LinuxCNC flavour is described in [Installing-RTAI].
109+
kernel and LinuxCNC flavour is described in <<cha:Installing-RTAI>>.
92110

93-
=== Xenomai with 'linuxcnc-uspace' package
94-
95-
Xenomai is also supported, but you will have to find or build the kernel
96-
and compile LinuxCNC from source to utilise it.
111+
Prebuilt experimental kernels can be found here: https://github.com/NTULINUX/RTAI
97112

98113
=== RTAI with 'linuxcnc-uspace' package
99114

100-
It is also possible to run LinuxCNC with RTAI in user-space mode.
115+
It is possible to run LinuxCNC with RTAI in user-space mode.
101116
As with Xenomai you will need to compile from source to do this.
102117

103118
== Problematic Hardware

‎docs/src/index.tmpl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<ul>
6868
<li><a href="config/integrator-concepts.html">Integrator Concepts</a></li>
6969
<li><a href="install/latency-test.html">Latency Test</a></li>
70+
<li><a href="install/latency-tuning.html">Latency Tuning</a></li>
7071
<li><a href="motion/tweaking-steppers.html">Stepper Tuning</a></li>
7172
<li><a href="config/ini-config.html">INI Configuration</a></li>
7273
<li><a href="config/ini-homing.html">Homing Configuration</a></li>

‎docs/src/install/latency-test.adoc‎

Lines changed: 74 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,48 @@ However, software step pulses also have some disadvantages:
3333
- jitter in the generated pulses
3434
- loads the CPU
3535

36+
[[sec:latency-to-achive]]
37+
== What to Achieve?
38+
This depends on your application. If step pulses are directly generated by the PC, minimal
39+
latency is key to achieve a hight step rate. See <<cha:stepper-config>>
40+
for requirements.
41+
42+
As soon as the step pulses are generated using an external hardware like Mesa cards, the latency
43+
constraints are looser.
44+
45+
If the servo-thread has period of 1 ms, latency of 100-200 us can still be used.
46+
47+
However, in this case, the total thread runtime is more important. The time from where
48+
the thread should have started to the next cycle should never exceed the thread's period.
49+
If this happens, the following warning is shown:
50+
----
51+
Unexpected realtime delay on task 0 with period 1000000
52+
This Message will only display once per session.
53+
Run the Latency Test and resolve before continuing.
54+
----
55+
56+
Especially for ethernet connected cards, the ethernet latency is often the limiting factor,
57+
not the pure thread start latency. When using ethernet, LinuxCNC sends a request to the card
58+
and waits for the response. This has to happen in one thread period.
59+
60+
Often, bad thread latency correlates with bad ethernet latency, due to the LinuxCNC and ethernet
61+
kernel latency adds up.
62+
63+
[[sec:latency-load]]
64+
== Perform Latency Tests
65+
Having a system that has low latency when mostly idle but behaves badly as soon
66+
as some load is added will result in an unreliable system.
67+
68+
While the test is running, you should 'abuse' the computer.
69+
Move windows around on the screen. Surf the web. Copy some large files
70+
around on the disk. Play some music.
71+
Run an OpenGL program such as glxgears.
72+
Run a load and stress tool such as stress-ng.
73+
The idea is to put the PC through its paces while
74+
the latency test checks to see what the worst case numbers are.
75+
76+
For quick comparisons between different settings, a test of a few minutes are fine.
77+
However, for final testing, a several hours long test should be performed.
3678

3779
[[sec:latency-tests]]
3880
== Latency Tests
@@ -87,13 +129,6 @@ After starting a latency test you should see something like this:
87129
.HAL Latency Test
88130
image::../config/images/latency-test_en.png["HAL Latency Test",align="center"]
89131

90-
While the test is running, you should 'abuse' the computer.
91-
Move windows around on the screen. Surf the web. Copy some large files
92-
around on the disk. Play some music.
93-
Run an OpenGL program such as glxgears.
94-
The idea is to put the PC through its paces while
95-
the latency test checks to see what the worst case numbers are.
96-
97132
The important number for software stepping is the 'max jitter' of the base thread.
98133
In the example above, that is 6693 nanoseconds (ns), or 6.693 microseconds (µs).
99134
Record this number, and enter it in StepConf when it is requested.
@@ -103,7 +138,7 @@ You should run the test for at least several minutes; sometimes
103138
the worst case latency doesn't happen very often, or only happens
104139
when you do some particular action. For instance, one Intel
105140
motherboard worked pretty well most of the time, but every 64
106-
seconds it had a very bad 300 µs latency. Fortunately that was fixable, see <<_latency_tuning>>.
141+
seconds it had a very bad 300 µs latency. Fortunately that was fixable, see <<cha:latency_tuning>>.
107142

108143
So, what do the results mean?
109144

@@ -156,7 +191,7 @@ Options:
156191
.`latency-plot` Window
157192
image::../config/images/latency-plot.png["latency-plot Window"]
158193

159-
194+
[[sec:latency-histogram]]
160195
=== Latency Histogram
161196

162197
The application latency-histogram displays a histogram of latency (jitter) for
@@ -192,6 +227,36 @@ Use `--show` to show count for the off-chart [pos|neg] bin.
192227
.`latency-histogram` Window
193228
image::../config/images/latency-histogram.png["latency-histogram Window"]
194229

230+
[[sec:latency-ping]]
231+
=== Latency Ping
232+
233+
The application latency-ping displays a histogram of the round trip time for
234+
a realtime thread pinging an ip address. This useful for network latency tuning where
235+
ip_address should be a Mesa card, an EtherCAT device or any other device which
236+
has a realtime capable ethernet interface to be used together with LinuxCNC.
237+
238+
Due to ping is used, it should work with virtually any device without any setup.
239+
240+
It is recommended to use the `if_name` argument to allow for static arp, so arp
241+
renewal is disabled and does not influence the response time.
242+
243+
----
244+
Usage:
245+
latency-ping [-t timeout] [-p period] [-n nbins ] [-b binsize ] ip_address [if_name]
246+
247+
Example:
248+
latency-ping 192.168.1.121 enp1s0
249+
250+
Defaults: timeout=800000nS period=1000000nS nbins=200 binsize=period/2/nbins
251+
Equivalently: timeout=800µs period=1ms nbins=200 binsize=2500
252+
253+
Times may be specified with suffix "s", "ms", "us" "µs", or "ns"
254+
Times without a suffix and less than 1000 are taken to be in us;
255+
other times without a suffix are taken to be in ns
256+
----
257+
258+
.`latency-ping` Window
259+
image::../config/images/latency-ping.png["latency-ping Window"]
195260

196261
[[sec:latency-status-bar]]
197262
=== Realtime status bar
@@ -227,95 +292,4 @@ isolcpus::
227292
for latency>>.
228293

229294

230-
[[_latency_tuning]]
231-
== Latency tuning
232-
233-
LinuxCNC can run on many different hardware platforms and with many
234-
different realtime kernels, and they all may benefit from tuning for
235-
optimal latency.
236-
237-
A primary goal in tuning the system for LinuxCNC is to reserve a CPU for the exclusive use of LinuxCNC's realtime tasks, so that other tasks (both user programs and kernel threads) do not interfere with LinuxCNC's access to that CPU.
238-
239-
When specific tuning options are believed to be universally helpful
240-
LinuxCNC does this tuning automatically at startup, but many tuning
241-
options are machine-specific and cannot be done automatically. The person
242-
installing LinuxCNC will need to experimentally determine the optimal
243-
tuning for their system.
244-
245-
246-
=== Tuning the BIOS for latency
247-
248-
PC BIOSes vary wildly in their latency behavior.
249-
250-
Tuning the BIOS is tedious because you have to reboot the computer,
251-
make one small tweak in the BIOS, boot Linux, and run the latency test
252-
(potentially for a long time) to see what effects your BIOS change had.
253-
Then repeat for all the other BIOS settings you want to try.
254-
255-
Because BIOSes are all different and non-standard, providing a detailed
256-
BIOS tuning guide is not practical. In general, some things to try
257-
tuning in the BIOS are:
258-
259-
* Disable ACPI, APM, and any other power-saving features. This includes
260-
anything related to power saving, suspending, CPU sleep states, CPU
261-
frequency scaling, etc.
262-
263-
* Disable CPU "turbo" mode.
264-
265-
* Disable CPU hyperthreading.
266-
267-
* Disable (or otherwise control) System Management Interrupt (SMI).
268-
269-
* Disable any hardware you do not intend to use.
270-
271-
272-
[[sec:latency-governor]]
273-
=== CPU frequency governor
274-
275-
Frequency scaling lets the CPU lower its clock speed to save power, which adds
276-
latency while the CPU ramps back up to service a realtime thread. For the best
277-
latency, set the governor to `performance` on every CPU:
278-
279-
----
280-
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
281-
----
282-
283-
This setting does not survive a reboot. To make it permanent, apply it at boot
284-
with a small systemd service, or with a CPU frequency management tool such as
285-
`cpupower` (Debian/Ubuntu package `linux-cpupower`) or `tuned`.
286-
287-
288-
[[sec:tuning-preempt-rt]]
289-
=== Tuning Preempt-RT for latency
290-
291-
The Preempt-RT kernel may benefit from tuning in order to provide the
292-
best latency for LinuxCNC. Tuning may be done via the kernel command
293-
line, sysctl, and via files in `/proc` and `/sys`.
294-
295-
Some tuning parameters to look into:
296-
297-
Kernel command line::
298-
299-
Details here: <https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt>
300-
301-
* `isolcpus`: Prevent most non-LinuxCNC processes from using these
302-
CPUs, leaving more CPU time available for LinuxCNC.
303-
304-
* `irqaffinity`: Select which CPUs service interrupts, so that the
305-
CPUs reserved for LinuxCNC realtime don't have to perform this task.
306-
307-
* `rcu_nocbs`: Prevent RCU callbacks from running on these CPUs.
308-
309-
* `rcu_nocb_poll`: Poll for RCU callbacks instead of using sleep/wake.
310-
311-
* `nohz_full`: Disable clock tick on these CPUs.
312-
313-
Sysctl::
314-
315-
Details here: <https://www.kernel.org/doc/html/latest/scheduler/sched-rt-group.html>
316-
317-
* `sysctl.kernel.sched_rt_runtime_us`: Set to -1 to remove the limit
318-
on how much time realtime tasks may use.
319-
320-
321295
// vim: set syntax=asciidoc:

0 commit comments

Comments
 (0)