====== Test and Tune an RT Kernel ====== In order for the EtherCAT bus to comply with all real-time time limits, the Linux operating system of the master must also provide a certain real-time performance. The RT performance of the master is measured with the maximum jitter time in microseconds. ===== RT Requirements ===== The requirements vary depending on the system. Basically the maximum jitter should be less than 100us. Depending on the system, a larger jitter can be tolerated or a smaller jitter is necessary. In networks with distributed clocks (DC) which are operated in MasterShift mode, all clocks are synchronized with a clock from a slave. The master only has to send the EtherCAT packet early enough. The exact timing is not relevant. Fundamentally the following applies: \\ ''Calculation time of the control algorithm + Calculation time of the EtherCAT master + Maximum jitter < Period length'' If the network is operated in BusShift mode or without DC, the RT requirements are higher. In such systems the OS provides the clock for the whole system.\\ ''max. jitter OS = min jitter EtherCAT bus'' If the master cannot guarantee a stable clock, the masterShift mode is recommended. See [[embedded_systems:ethercat:understanding_ethercat:understanding_sync_with_dc|Distributed Clocks]] for more information. ===== Measure RT Performance ===== ==== Cyclictest ==== The Cyclictest is a software that can be used to easily measure the maximum jitter of a system. [[software:linux:realtime:cyclictest|Cyclictest]] explains how to install and use the software. === Quick Measurement === ''sudo ./cyclictest -p 80 -t5 -n'' ===== Improve RT performance ===== If the RT performance is not sufficient, the maximum jitter could be reduced with the following measures: ==== Intel Scaling Governor ==== Modern processors change the CPU frequency depending on the load to save power. With an RT-OS this can lead to increased jitter. If the frequency is fixed, the RT performance can be improved. ATTENTION: If the CPU is fixed at a high temperature, the CPU can run hot. If the Governor is changed manually, the CPU temperature should be monitored! The frequency is controlled by the OS by a [[https://wiki.archlinux.org/index.php/CPU_frequency_scaling#Scaling_governors|scaling governor]]. The ''performance'' governor should run the cpu at the maximum frequency. To get the current active governor:\\ ''cpupower frequency-info'' To set the governor:\\ ''sudo cpupower frequency-set -g powersave'' ==== Intel cstates ==== Intel cstates indicate the power saving state of the processor. These states can be locked with kernel parameters on the C0 state (no power saving measures). {{:embedded_systems:ethercat:controlling_processor_c-state_usage_in_linux_v1.1_nov2013.pdf|Background information}} Display current kernel parameters:\\ ''cat /proc/cmdline'' Add the following [[software:linux:linux_os:kernel_parameter|kernel parameters]]: * cpuidle.off=1 * intel_idle.max_cstate=0