ROS2의 ros2_control에서 control_manager를 사용할 경우, preempt_rt 커널 (soft realtime)을 사용할 것을 권장하고 있다. 커널 빌드는 매번 하고 있긴 한데, 일단은 방법을 정리해두면 나중에도 찾기 쉬울듯 하여 정리함. 커널 버전은 그냥 rt 패치가 존재하는 가장 최신 버전을 사용하면 될듯.
필요한 패키지 설치
$ sudo apt install build-essential libncurses-dev flex bison libssl-dev debhelper libelf-dev gawk
다음으로 커널 소스 및 RT 패치 파일을 받아옴.
$ wget https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.16.1.tar.gz
$ wget https://www.kernel.org/pub/linux/kernel/projects/rt/6.16/patch-6.16-rt3.patch.xz
압축을 풀고, 패치 적용
$ tar zxf linux-6.16.1.tar.gz
$ xz -d patch-6.16-rt3.patch.xz
$ cd linux-6.16.1
$ patch -p1 < ../patch-6.16-rt3.patch
기존 config 파일 가져오기
$ cp /boot/config-`uname -r` .config
커널 설정하기
$ make menuconfig
커널 설정
General setup --->
Preemption Model (Scheduler controlled preemption model) --->
(X) Scheduler controlled preemption model
[*] Fully Preemptible Kernel (Real-Time)
Timers subsystem --->
Timer tick handling (Full dynticks system (tickless)) --->
(X) Full dynticks system (tickless)
[*] High Resolution Timer Support
Processor type and features --->
Timer frequency (1000 HZ) --->
(X) 1000 HZ
Power management and ACPI options --->
CPU Frequency scaling --->
Default CPUFreq governor (performance) --->
(X) performance
저장하고 나와서,
$ scripts/config --disable SYSTEM_TRUSTED_KEYS
$ scripts/config --set-str CONFIG_SYSTEM_TRUSTED_KEYS ""
$ scripts/config --disable SYSTEM_REVOCATION_KEYS
$ scripts/config --set-str CONFIG_SYSTEM_REVOCATION_KEYS ""
$ scripts/config --disable CONFIG_DEBUG_INFO_BTF
$ scripts/config --disable GDB_SCRIPTS
$ scripts/config --disable DEBUG_INFO
$ scripts/config --disable DEBUG_INFO_SPLIT
$ scripts/config --disable DEBUG_INFO_REDUCED
$ scripts/config --disable DEBUG_INFO_COMPRESSED
$ scripts/config --set-val DEBUG_INFO_NONE y
$ scripts/config --set-val DEBUG_INFO_DWARF5 n
$ scripts/config --disable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
빌드 시작 (-j
다음 숫자는 컴파일에 사용될 코어의 수로, 각자의 CPU 갯수에 따라 조정해서 사용)
$ make -j12 bindeb-pkg
대략 25~30분 정도 걸리는 듯.
커널 설치
$ cd ..
$ sudo dpkg -i linux-headers-6.16.1-rt3_6.16.1-5_amd64.deb linux-libc-dev_6.16.1-5_amd64.deb linux-image-6.16.1-rt3_6.16.1-5_amd64.deb
설치가 완료되면, 재부팅해서 uname -a 로 커널 버전 확인.
$ uname -a
Linux byeongkyu-workpc 6.16.1-rt3 #5 SMP PREEMPT_RT Wed Aug 20 15:05:48 KST 2025 x86_64 x86_64 x86_64 GNU/Linux
주의사항!! preempt_rt 커널의 경우 nvidia 그래픽 드라이버가 기본적으로 지원하지 않음.
해결방법 (에러난 이후에)
$ export IGNORE_PREEMPT_RT_PRESENCE=1
$ sudo -E dkms install nvidia/580.65.06 -k 6.16.1-rt3
$ sudo dpkg -i linux-headers-6.16.1-rt3_6.16.1-5_amd64.deb linux-libc-dev_6.16.1-5_amd64.deb linux-image-6.16.1-rt3_6.16.1-5_amd64.deb
재부팅 이후 cyclictest로 성능 측정

대충 stress가 없는 경우, 최대 latency가 154us 정도로 나오는듯.
사용자 계정을 realtime 그룹에 추가해서 sudo 명령없이 실행할 수 있도록 등록
$ sudo addgroup realtime
$ sudo usermod -a -G realtime $(whoami)
추가 설정
$ sudo vi /etc/security/limits.conf
@realtime soft rtprio 99
@realtime soft priority 99
@realtime soft memlock unlimited
@realtime hard rtprio 99
@realtime hard priority 99
@realtime hard memlock unlimited
끝!
Leave a Reply