Example implementaion of real time threads with wrapper for POSIX thread.
PREEMPT_RT
kernel, follow instruction.md to patch and install. To patch Raspberry PI 4 kernel with PREEMPT_RT
follow instructions from raspberry-pi-rt.md
Download the source code and compile
git clone https://github.com/siddharthdeore/preempt.git
cd preempt
mkdir build && cd build
cmake ..
make
Execute example program with PREEMPT_RT
cd ../bin
sudo ./rt_thread
Test CPU affinity (pin thread to core)
./cpu_affinity
To check CPU affinity use htop system monitor, cores which have thread pinned succussfully shall show 100% CPU consumption.
Or use taskset
to check on which CPU core a process running
taskset -c -p $(pidof cpu_affinity)
install kernel tracer tools trace-cmd and KernelShark
sudo apt-get install -y trace-cmd
sudo apt-get install -y kernelshark
Trace CPU sched_switch
event
sudo trace-cmd record -e sched_switch ./rt_thread
Analize CPU trace with KernelShark GUI
kernelshark trace.dat
Fig: Kernelshark CPU trace for sched_switch event
Fig: Kernelshark sched_switch event ticks (zoom).
Issue: Unexpected freeze issue on COM Express Type 6
Description:
COM Express running Ubuntu 20.04 LTS freezes unexpectedly, this recurrent behavior has been noticed when processor usage goes close to 100% similar issue arise on when program/threads uses all processor cores, and when real time thread is affine to specific core.
Solution:
This behaviour obsereved with Ubuntu 18.04 LTS and 22.04 LTS and expected cause of such freezes is related to "CPU Power Management". Disabling all CPU power managements seems to have solved problem. Steps to Disable
Press "F2" or "DEL" key to enter Aptio Bios Setup utility. Select Advanced Tab
> Advanced
> Power & Performance
> CPU - Power Management Control
Set Boot mode [Turbo Performance]
Intel(R) SpeedStep(tm) [Disable]
Race To Halt (RTH) [Disable]
Intel(R) Speed Shift Technology [Disable]
HDC Control [Disable]
Current kernel `cmdline` flags can be checked with following command,
cat /proc/cmdline
To disable DWC features add following flags to kernel cmdline
dwc_otg.fiq_enable=0 dwc_otg.fiq_fsm_enable=0 dwc_otg.nak_holdoff=0
Remove the CPU 0 and CPU 1 from the general kernel SMP balance and scheduler algorithms.
isolcpus=0,1 xenomai.supported_cpus=0x3
# above line isolates cpu 0 and 1 from SMP balance, and set xenomai supported cpu mask to 0011
To set flags edit /etc/default/grub
and add flags to GRUB_CMDLINE_LINUX_DEFAULT, finaly update grub with sudo update-grub
RPI : flags can be set by adding above lines to /boot/cmdline.txt
,
-
realtime periodic thread Program -
cpu affinity -
thread priority -
Some of the tools listed below to be tested and integrated
- Linux Trace Toolkit
- Dynamic Probes
- kGDB (kernel debugger)
- Linux Kernel Crash Dump
- Linux Test Project
- LMBench
- Ballista
- strace
- System Call Tracker
This repository is maintained by:
Siddharth Deore |
---|