1. What is latency?
Latency is how long it takes the PC to stop what it is doing and respond to an external request, such as running one of LinuxCNC’s periodic realtime threads. The lower the latency, the faster you can run the realtime threads, and the smoother motion will be (and potentially faster, in the case of software stepping).
Die Latenzzeit ist viel wichtiger als die CPU-Geschwindigkeit. Ein bescheidener Pentium II, der auf Unterbrechungen jedes Mal innerhalb von 10 Mikrosekunden reagiert, kann bessere Ergebnisse liefern als das neueste und schnellste P4-Hyperthreading-Biest.
The CPU isn’t the only factor in determining latency. Motherboards, video cards, USB ports, and a number of other things can hurt the latency. The best way to find out what you are dealing with is to run the latency test.
Die Erzeugung von Schrittimpulsen in der Software hat einen sehr großen Vorteil - sie ist kostenlos. So gut wie jeder PC verfügt über eine parallele Schnittstelle, die in der Lage ist, die von der Software erzeugten Schrittimpulse auszugeben. Die Software-Schrittimpulse haben jedoch auch einige Nachteile:
-
begrenzte maximale Schrittfrequenz
-
Jitter (variierende zeitliche Abstände) in den erzeugten Impulsen
-
belastet die CPU
2. Latency Tests
LinuxCNC includes several latency tests. They all produce equivalent information. Running these tests will help determine if a computers is suitable for driving a CNC machine.
Anmerkung
|
Do not run LinuxCNC or StepConf while the latency test is running. |
2.1. Latenz-Test
To run the test, open a terminal window (in Ubuntu, from Applications → Accessories → Terminal) and run the following command:
latency-test
Damit wird der Latenztest mit einer Basis-Thread-Periode von 25 µs und einer Servo-Thread-Periode von 1 ms gestartet. Die Periodenzeiten können in der Befehlszeile angegeben werden:
latency-test 50000 1000000
Damit wird der Latenztest mit einer Basis-Thread-Periode von 50 µs und einer Servo-Thread-Periode von 1 ms gestartet.
Die verfügbaren Optionen können Sie in der Befehlszeile eingeben:
latency-test -h
After starting a latency test you should see something like this:

Während der Test läuft, sollten Sie den Computer beschäftigen: Bewegen Sie die Fenster auf dem Bildschirm. Surfen Sie im Internet. Kopieren Sie einige große Dateien auf der Festplatte. Spielen Sie etwas Musik ab. Führen Sie ein OpenGL-Programm wie z. B. glxgears aus. Die Idee ist, den PC auf Herz und Nieren zu prüfen, während der Latenztest den schlimmsten Fall ermittelt.
The important number for software stepping is the max jitter of the base thread. In the example above, that is 6693 nanoseconds (ns), or 6.693 microseconds (µs). Record this number, and enter it in StepConf when it is requested.
In the example above, latency-test only ran for a few seconds. You should run the test for at least several minutes; sometimes the worst case latency doesn’t happen very often, or only happens when you do some particular action. For instance, one Intel motherboard worked pretty well most of the time, but every 64 seconds it had a very bad 300 us latency. Fortunately that was fixable, see https://wiki.linuxcnc.org/cgi-bin/wiki.pl?FixingSMIIssues
Was bedeuten also die Ergebnisse? Wenn Ihre Max-Jitter-Zahl weniger als 15-20 Mikrosekunden (15000-20000 Nanosekunden) beträgt, sollte der Computer mit Software-Stepping sehr gute Ergebnisse liefern. Wenn die maximale Latenzzeit eher bei 30-50 Mikrosekunden liegt, können Sie immer noch gute Ergebnisse erzielen, aber Ihre maximale Schrittrate könnte etwas enttäuschend sein, insbesondere wenn Sie Mikroschrittverfahren verwenden oder sehr feine Spindelsteigungen haben. Wenn die Zahlen 100 us oder mehr (100.000 Nanosekunden) betragen, ist der PC kein guter Kandidat für Software-Stepping. Zahlen über 1 Millisekunde (1.000.000 Nanosekunden) bedeuten, dass der PC ist kein guter Kandidat für LinuxCNC, unabhängig davon, ob Sie Software-Stepping verwenden oder nicht.
Anmerkung
|
If you get high numbers, there may be ways to improve them. Another PC had very bad latency (several milliseconds) when using the onboard video. But a $5 used video card solved the problem. LinuxCNC does not require bleeding edge hardware. |
Weitere Informationen zum Stepper-Tuning finden Sie im Kapitel Stepper Tuning.
Additional command line tools are available for examining latency when LinuxCNC is not running.
2.2. Latency Plot
latency-plot erstellt ein Streifendiagramm für einen Basis- und einen Servo-Thread. Es kann nützlich sein, um Spitzen in der Latenz zu sehen, wenn andere Anwendungen gestartet oder verwendet werden. Verwendung:
latency-plot --help
Usage:
latency-plot --help | -?
latency-plot --hal [Options]
Options:
--base nS (base thread interval, default: 25000)
--servo nS (servo thread interval, default: 1000000)
--time mS (report interval, default: 1000)
--relative (relative clock time (default))
--actual (actual clock time)

latency-plot
-Fenster2.3. Latenz-Histogramm
latency-histogram zeigt ein Histogramm der Latenz (Jitter) für einen Basis- und einen Servo-Thread an.
Usage:
latency-histogram --help | -?
latency-histogram [Options]
Optionen:
--base ns (Basisgewindeintervall, Voreinstellung: 25000, min: 5000)
--servo ns (Servo-Thread-Intervall, Voreinstellung: 1000000, Mindestwert: 25000)
--bbinsize ns (Basis-Bin-Größe, Voreinstellung: 100
--sbinsize ns (Servo-Bin-Größe, Voreinstellung: 100)
--bbins n (Basis-Bins, Voreinstellung: 200
--sbins n (Servo-Bins, Voreinstellung: 200
--logscale 0|1 (logarithmische Skala der y-Achse, Voreinstellung: 1)
--text note (zusätzlicher Hinweis, Voreinstellung: "" )
--show (zeigt die Anzahl der nicht angezeigten Bins)
--nobase (nur Servo-Thread)
--verbose (Fortschritt und Fehlersuche)
--nox (keine Benutzeroberfläche, Anzeige von elapsed,min,max,sdev für jeden Thread)
Notes:
LinuxCNC and HAL should not be running, stop with halrun -U.
Large number of bins and/or small binsizes will slow updates.
For single thread, specify --nobase (and options for servo thread).
Measured latencies outside of the +/- bin range are reported
with special end bars. Use --show to show count for
the off-chart [pos|neg] bin

3. Latency tuning
LinuxCNC can run on many different hardware platforms and with many different realtime kernels, and they all may benefit from tuning for optimal latency.
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.
When specific tuning options are believed to be universally helpful LinuxCNC does this tuning automatically at startup, but many tuning options are machine-specific and cannot be done automatically. The person installing LinuxCNC will need to experimentally determine the optimal tuning for their system.
3.1. Tuning the BIOS for latency
PC BIOSes vary wildly in their latency behavior.
Tuning the BIOS is tedious because you have to reboot the computer, make one small tweak in the BIOS, boot Linux, and run the latency test (potentially for a long time) to see what effects your BIOS change had. Then repeat for all the other BIOS settings you want to try.
Because BIOSes are all different and non-standard, providing a detailed BIOS tuning guide is not practical. In general, some things to try tuning in the BIOS are:
-
Disable ACPI, APM, and any other power-saving features. This includes anything related to power saving, suspending, CPU sleep states, CPU frequency scaling, etc.
-
Disable CPU "turbo" mode.
-
Disable CPU hyperthreading.
-
Disable (or otherwise control) System Management Interrupt (SMI).
-
Disable any hardware you do not intend to use.
3.2. Tuning Preempt-RT for latency
The Preempt-RT kernel may benefit from tuning in order to provide the best latency for LinuxCNC. Tuning may be done via the kernel command line, sysctl, and via files in /proc
and /sys
.
Some tuning parameters to look into:
- Kernel command line
-
Details here: https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt
-
isolcpus
: Prevent most non-LinuxCNC processes from using these CPUs, leaving more CPU time available for LinuxCNC. -
irqaffinity
: Select which CPUs service interrupts, so that the CPUs reserved for LinuxCNC realtime don’t have to perform this task. -
rcu_nocbs
: Prevent RCU callbacks from running on these CPUs. -
rcu_nocb_poll
: Poll for RCU callbacks instead of using sleep/wake. -
nohz_full
: Disable clock tick on these CPUs.
-
- Sysctl
-
Details here: https://www.kernel.org/doc/html/latest/scheduler/sched-rt-group.html
-
sysctl.kernel.sched_rt_runtime_us
: Set to -1 to remove the limit on how much time realtime tasks may use.
-