Setting up Real-time Linux and EtherCAT Master on an Advantech Embedded IPC

See how easy it is to setup and install a real-time Linux kernel with Ubuntu 22.04 LTS on an Advantech IPC for use with acontis' EtherCAT Master software EC-Master.

Introduction

According to acontis customers, Linux is the most popular choice for a real-time OS (RTOS) for EtherCAT applications. For demanding applications that require fast processor performance, x86 CPU architecture is typically the best choice. For these reasons, Industrial PCs (IPC), also known as Embedded PCs, are a great fit for EtherCAT applications, but it is important that the BIOS on the IPC provides sufficient options to configure the system for real-time performance. Advantech is one manufacturer of an IPC that satisfies these requirements, and so here we will show how to setup an Advantech MIC770-V3 IPC with real-time Linux in order to run the acontis EtherCAT Master software EC-Master.

Installing the Linux Distribution

Here we will use Ubuntu Desktop 22.04 LTS, but any Linux distribution will work. For Ubuntu, you can download the OS from https://releases.ubuntu.com/22.04/, select an appropriate installation image, and follow the instructions from the Ubuntu tutorial page: https://ubuntu.com/tutorials/install-ubuntu-desktop#1-overview.

Installing the Real-time Kernel

The main line Linux kernel included with most Linux distributions by default is not a real-time kernel, so it is necessary that we install a real-time kernel. With Ubunutu 22.04, there are now two ways to do this: either use the pre-built real-time kernel available in Ubuntu 22.04, or build a real-time kernel by yourself.

In order to install the real-time kernel included in Ubuntu 22.04 LTS, just follow instructions at https://ubuntu.com/blog/real-time-ubuntu-released. The real-time kernel requires an Ubuntu Pro subscription, which is free for personal use. After attaching the machine to an Ubuntu Pro subscription, the real-time kernel can be enabled with one simple command.

Alternatively, you can build a real-time kernel by yourself by applying the PREEMPT_RT patch. You can find more information for how to do this here.

For our tests here we are going to use the pre-built real-time kernel version 5.15.0-1032-realtime included in Ubuntu 22.04 LTS from Canonical.

BIOS Settings

Before we proceed further, it is necessary to change some settings in the BIOS to achieve real-time performance. The main concerns are to deactivate hyper-threading, virtualization support, and power saving options. We have further optimizations and recommendations in our Developer Center: https://developer.acontis.com/rt-faq/items/FAQ1013.html and https://developer.acontis.com/pcob.html

We recommend changing the following BIOS settings:

 

Optimizing the Real-time Kernel

The next level of real-time performance optimization is to configure the Linux real-time kernel. Fortunately, since we are using a pre-built real-time kernel included in Ubuntu 22.04 LTS, there is no need to rebuild the kernel for this; everything can be done via kernel command line parameters. For our purposes we can focus on just a few of the kernel parameters:

  1. 1. “Power and clocking management” group:
      • cpuidle.off=1
      • intel_idle.max_cstate=0
      • cpufreq.off=1
      • processor.max_cstate=0
      • processor_idle.max_cstate=0
      • intel_pstate=disable
      • rcupdate.rcu_cpu_stall_suppress=1
      • idle=poll
  2. 2. “Core isolation” group:
      • nohz_full=3
      • isolcpus=3
      • rcu_nocbs=3
      • irqaffinity=0
  3. 3. “Graphics Settings” group:
      • i915.enable_rc6=0
      • i915.enable_dc=0
      • i915.disable_power_well=0
      • i915.enable_guc=2

A full list of the kernel command line parameters can be found here: https://www.kernel.org/doc/html/v5.15/admin-guide/kernel-parameters.html.

Installing acontis EC-Master

  1. 1. Extract the evaluation version of EC-Master ‘EC-Master-V3.1-Linux-x86_64Bit-Eval.tar.gz’ into ~/ EC-Master-V3.1-Linux-x86_64Bit-Eval
    tar –xf EC-Master-V3.1-Linux-x86_64Bit-Eval.tar.gz –-one-top-level
  2. 2. Build the atemsys kernel module
    cd EC-Master-V3.1-Linux-x86_64Bit-Eval/Sources/LinkOsLayer/Linux/atemsys
  3. 3. Unbind the standard Ethernet driver
    Echo “0000:02:00.0” | sudo tee –a /sys/class/net/enp2s0/device/driver/unbind
  4. 4. Load the atemsys kernel module
    sudo insmod atemsys.ko

More information and further instructions about the EC-Master example application is in our Developer Center here: https://public.acontis.com/manuals/EC-Master/3.1/html/ec-master-class-b/gettingstarted.html#running-ecmasterdemo. More information about the acontis atemsys kernel module for use with our real-time Ethernet drivers here: https://public.acontis.com/manuals/EC-Master/3.1/html/ec-master-class-b/os_linux.html#atemsys-kernel-module

Performance Tests

We are going to measure the actual cycle time of the EcMasterDemo example application using the built-in performance measurement capability. With this performance measurement turned on the EcMasterDemo application periodically outputs the measured minimal, average, and maximum values for the cycle times, along with further measurements of the underlying job tasks and application task:

0011944217: ============================================================================
0011944217: PerfMsmt 'Cycle Time                                          ' (min/avg/max) [usec]:  930.3/ 999.9/1079.4
0011944217: PerfMsmt 'Task Duration (JOB_Total + App)    ' (min/avg/max) [usec]:      1.9/   20.3/   119.8
0011944217: PerfMsmt 'JOB_Total                                            ' (min/avg/max) [usec]:     1.2/   19.3/   124.3
0011944217: PerfMsmt 'JOB_ProcessAllRxFrames Duration' (min/avg/max) [usec]:     0.1/     2.8/      54.5
0011944217: PerfMsmt 'JOB_SendAllCycFrames Duration   ' (min/avg/max) [usec]:     0.2/  11.6/      89.5
0011944217: PerfMsmt 'JOB_MasterTimer Duration             ' (min/avg/max) [usec]:    0.4/    1.1/      61.5
0011944217: PerfMsmt 'JOB_SendAcycFrames Duration      ' (min/avg/max) [usec]:    0.1/    3.7/      57.8
0011944217: PerfMsmt 'myAppWorkPd                                   ' (min/avg/max) [usec]:    0.1/    0.2/      28.3

In order to simulate a load on the system we will use the BurnInTest v5.0 for Linux (http://www.passmark.com/products/bit.htm) with the following settings:

Each test runs for at least 24 hours.

The example application will use the acontis real-time Ethernet driver for Intel Ethernet controllers via the atemsys kernel module we inserted above, and will be executed isolated on core 3, using command line switch ‘-a’ available from the example application:

./EcMasterDemo -f eni.xml -i8254x 1 1 –a 3 -perf …

Below is a summary of the results of some test runs in the table. As you can see, it is possible to improve the real-time behavior of a prebuilt Linux kernel using only kernel parameters.

Description

Kernel parameters used

Cycle Time (µS)

Min.

Avg.

Max.

Reference ‘Out-of-the-box’ Ubuntu 22.04 LTS, kernel 5.15.0-56.

default

500.2

1000.0

1524.4

Ubuntu 22.04 LTS with real-time kernel 5.15.0-1032-realtime with “Power and clocking management” parameters

*1

901.7

999.9

1104.5

Ubuntu 22.04 LTS with real-time kernel 5.15.0-1032-realtime with “Power and clocking management” + “Core isolation”

*2

914.7

1000.0

1095.1

Ubuntu 22.04 LTS with real-time kernel 5.15.0-1032-realtime with “Power and clocking management” + “Core isolation” + “Graphics Settings”

*3

930.3

1000.0

1079.4

Notes:
(*1) cpuidle.off=1 intel_idle.max_cstate=0 cpufreq.off=1 processor.max_cstate=0 processor_idle.max_cstate=0 intel_pstate=disable rcupdate.rcu_cpu_stall_suppress=1 idle=poll
(*2) cpuidle.off=1 intel_idle.max_cstate=0 cpufreq.off=1 processor.max_cstate=0 processor_idle.max_cstate=0 intel_pstate=disable rcupdate.rcu_cpu_stall_suppress=1 idle=poll nohz_full=3 isolcpus=3 rcu_nocbs=3 irqaffinity=0
(*3) cpuidle.off=1 intel_idle.max_cstate=0 cpufreq.off=1 processor.max_cstate=0 processor_idle.max_cstate=0 intel_pstate=disable rcupdate.rcu_cpu_stall_suppress=1 idle=poll nohz_full=3 isolcpus=3 rcu_nocbs=3 irqaffinity=0 i915.enable_rc6=0 i915.enable_dc=0 i915.disable_power_well=0 i915.enable_guc=2

Conclusions

With Ubuntu 22.04 LTS it is easier than ever to install a real-time Linux kernel and turn your Linux distribution into an RTOS. Furthermore, an Advantech IPC is a great choice to easily install and setup real-time Linux and also the acontis EtherCAT Master software EC-Master. With some simple kernel parameter optimizations, the real-time performance in Linux can be further improved with minimal effort.