# LinuxCNC 🚧
Controls CNC machines: milling machines, lathes, 3d printers, laser cutters, plasma cutters, robot arms, hexapods, and more. - LinuxCNC
see also
Setup
LinuxCNC 2.9.4
Live boot can be used to test latency.
Servo thread (1ms): 88k ns
Base thread (2.5µs): 87k ns
LinuxCNC on Linux Mint Debian Edition 6
- LinuxCNC is in Debian - This means it is now possible to install a fully functioning LinuxCNC system, including a Preempt-RT realtime kernel suitable for running real hardware, entirely from official Debian package repositories.
$ sudo apt update
$ sudo apt install linuxcnc-uspace
Then install RT kernel
$ sudo apt install -t bookworm-backports linux-image-rt-amd64
LinuxCNC on LinuxMint 22
- compile RT kernel
uname -a
Linux cnc 6.12.0 #1 SMP PREEMPT_RT Sun Apr 27 21:17:13 CEST 2025 x86_64 x86_64 x86_64 GNU/Linux
- this is OK- latency-test/linuxcnc is relying upon
/sys/kernel/realtime
to check if the OS is realtime - This is a part of the realtime patches that didn’t become mainline. - patch- applying patch
$ patch -p1 < /path/to/patchfile.patch
- applying patch
- compile linux cnc
- alternatively there is patch for linuxcnc as well to change the test method - patch
- then launch latency test
- RT detected with kernel patch
# launch latency test
$ latency-test
Note: Using POSIX non-realtime # <<== This is not good at all
- make sure PREEMPT-RT is active / enabled
- make sure
/sys/kernel/realtime
exist (see kernel patch above)
## well all of this is probably bullshit => patching kernel is the most important
# make sure user is part of realtime & video group
$ sudo groupadd realtime # create realtime group
$ sudo usermod -aG realtime $USER # add yourself to groups
$ sudo usermod -aG video $USER # add yourself to groups
# You must allow mlockall without limits.
$ sudo micro /etc/security/limits.d/realtime.conf
# add the following content
@realtime - rtprio 99
@realtime - memlock unlimited
# save and reboot
# test
$ ulimit -r
99
$ ulimit -l
unlimited
- add ui
- add probe plugin
GUI
- QtDragon
- Axis
- GMOCCAPY
- A Widescreen Blender-Style Interface (Discussion)
- probe basic (new UI) / 2 => Installing Probe Basic
- SilverDragon GUI
Configuration
Parallel port address
Parallel port is only seen by the kernel is pnpbios is active. (no pnpbios=0
options)
$ dmesg | grep parport
[ 11.551600] parport_pc 00:07: reported by Plug and Play ACPI
[ 11.551671] parport0: PC-style at 0x378 (0x778), irq 7, dma 3 [PCSPP,TRISTATE,COMPAT,ECP,DMA]
[ 11.648233] lp0: using parport0 (interrupt-driven).
Hardware Interface to CNC machine
- USB to Parallel port converter - Will the USB to Parallel port converters work with LinuxCNC?
- No, parallel converters will not work with LinuxCNC for step generation because they have large latencies to access the I/O pins.
- A normal hardware parallel port will change it’s output pin state typically in less than 1 uSec from when the host CPU does the port write.
- A USB parallel port may take from a few uSec to a few 10s of mS from the host write to the actual pins changing state. This random output timing makes evenly spaced step generation pretty much impossible.
- PCI Express Parallel Port Card for LinuxCNC
- NetMos / Moschip chipset works fine. These are the most widely used chips by card manufacturers, irrespective of what the actual card is branded as. MCS9900 appears to have the longest track record.
- avoid the 9805 and 9815 chips which are quite old and were a bit flakey,
- The 9845, 9865 and 9901 chips (often designated MCS9845, MCS9865 and MCS9901) work fine
- ASIX99100 may be problematic? only found discussion about driver issue.
- NetMos / Moschip chipset works fine. These are the most widely used chips by card manufacturers, irrespective of what the actual card is branded as. MCS9900 appears to have the longest track record.
- LinuxCNC - Hardware and Latency
- Parallell Port PCI & PCIe Add In Card Info Thread
- Parallel port Pci card.
Stepper Configuration
Latency-Test
- LinuxCNC latency and jitter improvements with PREEMPT_RT kernel parameter tuning - How one CPU is not like the other
The important number for software stepping is the max jitter of the base thread.
- If your “Max Jitter” number is less than about 15-20 microseconds (15’000-20’000 nanoseconds), the computer should give very nice results with software stepping.
- If the Max Jitter is more like 30-50 microseconds, you can still get good results, but your maximum step rate might be a little disappointing, especially if you use microstepping or have very fine pitch leadscrews.
-
If the numbers are 100 uS or more (100’000 nanoseconds), then the PC is not a good candidate for software stepping.
- Some archived results of systems that works
Stress system
- 3x glxgears (+ redim windows)
- youtube video playing in 720p in firefox
- stress with default cmdline / monitor temp
$ latency-test
or
$ latency-histogram # maybe more usefull
# charge the system
$ seq 3 | parallel -j 3 -n0 glxgears
Hardware
AMD A6-9500 config (2025)
Should be slightly better than previous config (+2%)
with kernel and default parameter
$ sudo micro /etc/default/grub
GRUB_CMDLINE_LINUX="... noapic acpi=off pnpbios=0 isolcpus=1"
Servo thread (1ms): 81k ns
Base thread (2.5µs):100k ns
# tuned with
GRUB_CMDLINE_LINUX="skew_tick=1 kthread_cpus=0 irqaffinity=0 rcu_nocb_poll rcu_nocbs=1 nohz=on nohz_full=1 isolcpus=1 intel_pstate=disable amd_pstate=disable idle=poll intel_idle.max_cstate=1 amd_idle.max_cstate=1 nowatchdog nosoftlockup quiet"
$ sudo update-grub
Servo thread (1ms): 60k ns
Base thread (2.5µs): 77k ns
# ++BIOS
# Cool"n'quiet disabled
# SVM disabled (virtualisation)
# ACPI HPET enabled
Note using nosmt is disabling proc 1 on this APU.
intel E2180 config (2019)
add Kernels options, with value found in LinuxCNC 2.7 wheezy image this reduced a lot jitter.
The Intel Core2Duo benefits greatly from the idle=poll parameter to the kernel, which disables the deep-sleep C-State of the CPU. The effect is equal to that of hogging one CPU core. RealTime
Option acpi=off
prevent kernel to shutdown pc.
$ sudo xedit /etc/default/grub
GRUB_CMDLINE_LINUX="... noapic acpi=off pnpbios=0 isolcpus=1"
$ sudo update-grub
Max Jitter:
GRUB_CMDLINE_LINUX="... noapic acpi=off pnpbios=0 isolcpus=1 intel_idle.max_cstate=0 processor.max_cstate=0 idle=poll"
Servo thread (1ms): 33k ns 62°C
Base thread (2.5µs): 58k ns
GRUB_CMDLINE_LINUX="... noapic acpi=off pnpbios=0 isolcpus=1"
Servo thread (1ms): 53k ns
Base thread (2.5µs): 38k ns
GRUB_CMDLINE_LINUX= default value
Servo thread (1ms): 45k ns
Base thread (2.5µs): 140k ns
## IRQ affinity
GRUB_CMDLINE_LINUX="... acpi=off pnpbios=0 isolcpus=1 intel_idle.max_cstate=0 processor.max_cstate=0 idle=poll acpi_irq_nobalance noirqbalance"
Servo thread (1ms): 66k ns 62°C
Base thread (2.5µs): 43k ns
GRUB_CMDLINE_LINUX="... noapic acpi=off pnpbios=0 isolcpus=1 intel_idle.max_cstate=0 processor.max_cstate=0 idle=poll acpi_irq_nobalance noirqbalance"
Servo thread (1ms): 25k 41k 22k 23k 35k 36k ns 62°C
Base thread (2.5µs): 49k 42k 43k 32k 31k 40k ns
BIOS/Hardware config
- Disable onboard audio
- Disable APM and ACPI bios settings
Turn everything off that you can. Any power saving, anything related to suspending, cpu frequency scaling, etc.
- Enabling ACPI could be the only way to get access to local APIC timer (much lower latency than PIC), as new mainboards do not come with legacy support of MPTABLEs.
- Disable C1E power-saving feature in BIOS (could save about ~10-15ms on recent CPUs), this feature is activated regardless of ACPI or APM, thus needs to be disabled independently. See Wikipedia for more information on this.
- If you have a CPU that is C-state capable, add the following line to the GRUB_CMDLINE_LINUX in
/etc/default/grub
:idle=poll
and runupdate-grub
. Theidle=poll
keeps the CPU in a loop checking to see if it is needed rather then it entering C1 waiting for a wakeup call. I’ve seen latencies go from 30-50us to around 4us (1-2us even) on 6 different systems. RealTime
Multicore
- The Isolcpus Boot Parameter And GRUB2
- Reducing latency on multicore pc’s - initial max jitter value was 30’000ns to the current value of less than 4’000ns:
- disable Vanderpool Technology (cpu vitualization stuff for vm’s)
- disable C1E support
- enable TM support (temperature monitoring - will throttle cpu if it overheats e.g. because of fan malfunction - will mess things up but better than a crash and toasted chip)
Interrupts (IRQ)
# wath irq pert type/cpy
$ watch -n1 -d cat /proc/interrupts
Linuxcnc HAL tutorial / github
- #1: The Basics
- wiring goes into .hal / setting goes into .ini
- kinematics / motion module
- net signal command / setp set parameter
- #2: INI improvements
- display axis,control / default.ngc / GCODE subroutine
- halui - running command from the ui
- axis HOME_LATCH_VEL (second search spead)
- user command file => to customize
axis
(linuxcnc ui written in python) (eg: disable command ‘r’)
- #4: PyVCP / gladeVCP - Virtual Control Panel that extend Axis GUI (button / slider / readout)
Jog-wheel
- WHB04B-6 CNC controller
- HAL #5: XBox controller, hal_input, and subroutines
- Gamepad controller for milling machine (03/05/12)
Wifi
FPGA
XFCE
- Using the Windows key to open Xfce application menu
- Top 7 Xfce Applications
- mousepad - graphical text editor
- thunar - file manager (default)
LinuxCNC/Debian
- Avahi is an mDNS/DNS daemon, service which implements Apples’s Zeroconf mechanism.
$ systemctl disable avahi-daemon