building linuxcnc-dev on ubuntu 16.04 preempt-rt kernel

03 Nov 2017 16:52 - 11 Apr 2018 22:09 #101272 by thang
This tutorial about how to install linuxcnc-dev on ubuntu 16.04 and preempt-rt kernel. It includes 3 steps:
step1: install preempt-rt kernel
step2: install linuxcnc-dev
step3: fix latency

Step 1: install preempt-rt
+ install some require packages
sudo apt-get install git
sudo apt-get install libssl-dev ( for compile preempt-rt kernel)
sudo apt-get install dpkg-dev
sudo apt-get install libncurses5-dev ( for menuconfig)
+ download kernel and patch
mkdir kernel
cd kernel
wget ( download patch)
(Edit apugh 11/4/18 This link does not work, try looking here for a newer patch: )
wget (download kernel)
tar -xzvf linux-4.9.47.tar.gz
+ patch kernel
cd linux-4.9.47
gzip -cd ../patch-4.9.47-rt37.patch.gz | patch -p1 --verbose
+ config kernel
make menuconfig
+ The menuconfig appear
select Processor type and features-->Preemption Model---> Fully Preemptible Kernel (RT)-->back to top menu
select Power management and ACPI option ---> disable susspend to RAM, Hybernation and CPU frequency scaling --> back to top menu
select Memory Debugging --> Check for stack overflows ( already deselect so dont select this -just check)
save and exit
+ compile kernel
make -j4 ( if you have a cpu quad core)
sudo make modules_install -j4
sudo make install -j4
+ now, check new kernel
cd /boot
you will see somethings like initrd.img-4.9.47-rt37, vmlinuz-4.9.47-rt37, and config-4.9.47-rt37
sudo update-grub
+ reboot ---> select advanced oftion--> select new kernel --> check kernel by : uname -r

Step2: building linuxcnc-dev
+ download linuxcnc-dev
git clone git:// linuxcnc-dev
git checkout 2.7 ( no necessary if u want to use master version)
+ install require packages
Go to system settings --> software & update --> tick Source code
sudo apt-get update
cd linuxcnc-dev/debian
./configure uspace noauto
cd ..
+ now install required packages showed after command dpkg-checkbuilddeps then comeback to dir linuxcnc-dev/src
cd src
./ ( if this command show error i think u need: sudo apt-get install autoconf )
./configure --with-realtime=uspace
make clear
make -j4
sudo make setuid
+ config RIP
cd ..
source ../scripts/rip-environment

Step 3: reduce latency
+ after you installed linuxcnc-dev, it's time to do first test with latency-test
+ if your latency spike up to 100-300ums or more after some seconds so i think u need fix smi. You can follow this link to fix it by rtai_smi.ko: . If it doesn't work, let try fix it by smictl that is described at the end of page. Here is detail how to fix smi by smictl:
sudo apt-get install git-core
git clone git:// && cd smictrl
git clone git:// debian
sudo apt-get install libpci-dev
sudo dpkg-buildpackage -uc –us
sudo dpkg -i ../smictrl_*.deb
sudo smictrl
sudo smictrl -s 0 ( run this command every after restart pc)
I got this solution from:
+ Now let try run latency-test again and hope it works
+ If your latency test still high a bit and you are using a CPU multicores then u can reduce latency by disable multicore very simple by:
sudo nano /etc/default/grub
add line GRUB_CMDLINE_LINUX_DEFAULT="isolcpus = 1" if you have duo core ( there are somethings else in " " just dont remove them), isolcpus = 1,2,3 if you have quad core cpu (1,2,3 mean core1,core2 and core3, cant disable core0)
sudo update-grub
Here is my result:
Last edit: 11 Apr 2018 22:09 by andypugh.
The following user(s) said Thank You: k-1, tivoi, AnnoyingMutt
03 Nov 2017 17:23 #101280 by andypugh
Latency is excellent, no need to do any further tuning.
03 Nov 2017 21:34 - 03 Nov 2017 22:49 #101293 by AnnoyingMutt
Great work.....just the link to your simctrl solution is not working in your post.......the link below does work and I'm guessing this is the one you were referring to.

And the rt patch link

Once again great job
Last edit: 03 Nov 2017 22:49 by AnnoyingMutt.
The following user(s) said Thank You: thang
04 Nov 2017 01:09 #101300 by thang
thank you, i edited
04 Nov 2017 04:51 #101302 by AnnoyingMutt
Just thinking out aloud...............
rtai_smi.ko and the other rati modules are not built during config --with-realtime=uspace, (and only whilst using rtai) that's right yeah ?

The latest kernel rtai-5.0.1 will support is 4.4.43, correct ?
06 Feb 2018 08:07 #105480 by thang
After using smictrl, i have a problem that my pc often cant turn off after use command "smictrl -s 0", does anyone get this problem too and have experience to fix it
12 Feb 2018 10:32 - 12 Feb 2018 12:59 #105785 by Bello
I'm trying to follow the steps to install linuxcnc on my ubuntu 16 but the packets you mentioned in the stepsd aren't exists yet.
I'm trying with linux-4.9.76.tar.gz
Last edit: 12 Feb 2018 12:59 by Bello.
09 Apr 2018 22:37 #108682 by dbanks
Can anybody validate this tutorial? I've been having a ton of trouble with the other ways I've tried. Has anyone had luck with this one in specific? Thanks in advance.
09 Apr 2018 23:34 #108683 by andypugh

dbanks wrote: Can anybody validate this tutorial? I've been having a ton of trouble with the other ways I've tried. Has anyone had luck with this one in specific? Thanks in advance.

Is here a particular reason that you don't want to use one of the LiveDVD installs? Or is that one of the ways that you have had trouble with?
09 Apr 2018 23:36 #108684 by dbanks
I've tried writing to a drive from terminal, from rufus/unetbootin, etc. Once it's been loaded with a bootable iso it disappears from the boot menu. No matter which way I've done it. The one time it didn't disappear, setting it did nothing anyway. Which method are you specifically referring to?
Time to create page: 0.129 seconds
Powered by Kunena Forum