CODESYS Benchmark¶
The CODESYS* benchmark is an example application that allows deterministic control and test of the CODESYS* SoftPLC. The application is defined such that a main task occurs every 250us. Within the main task is a configurable workload which iterates a number of user defined times. The specific workload is configurable to either: “floating point”, “arithmetic”, or “boolean” operations. Cycle execution times are measured from which minimum, maximum, and jitter measurements are derived. These measurements allow performance characterization of the CODESYS* SoftPLC on the target system.
This benchmark can be ran natively, or in a container environment. Running in a container environment is easier to setup, but will perform slightly worse than running natively. If you’re running this benchmark for the first time, it is recommended to run in a container environment.
The following steps are applicable to:
![]()
Install a container engine, if not already done:
![]()
The preferred container engine on Debian* and Canonical Ubuntu* based systems is Docker*. Install Docker on the target system, if not already done.
The preferred container engine on Red Hat Enterprise Linux* based systems is Podman*. Install Podman* on the target system, if not already done:
$ sudo dnf install podmanOn the target system, install the
codesys-benchmark-scripts
package from the ECI repository. Setup the ECI repository, then perform the following command to install this component:
$ sudo apt install codesys-benchmark-scripts
$ sudo dnf install codesys-benchmark-scriptsNavigate to
/opt/benchmarking/codesys
and build thecodesyscontrol
container image with thecodesys-eci-benchmark
benchmark:
$ cd /opt/benchmarking/codesys/docker $ docker build -f ./Dockerfile.controlruntime \ -t codesyscontrol:4.5.0.0 . \ --build-arg ECI_DEB=codesys-eci-benchmark \ --build-arg CDS_VERSION=4.5.0.0
$ cd /opt/benchmarking/codesys/docker $ sudo podman build --format docker \ -f ./Dockerfile.controlruntime \ -t codesyscontrol:4.5.0.0 . \ --build-arg ECI_DEB=codesys-eci-benchmark \ --build-arg CDS_VERSION=4.5.0.0Note
If you are building behind a proxy, you may need to add the following build arguments:
--build-arg http_proxy="http://<proxy:port>" --build-arg https_proxy="http://<proxy:port>"
.Navigate to
/opt/benchmarking/codesys/utility
. This directory contains a number of useful scripts for improving the real-time performance of the CODESYS* Linux* runtime.The scripts available at
/opt/benchmarking/codesys/utility
include:
start_codesys_native.sh
: Optimizes the system (see list below), stops non-essential services, and restarts the CODESYS* Linux* runtime
start_codesys_container.sh
: Optimizes the system (see list below) and starts the containerized CODESYS* Linux* runtime with RT priority.
taskset_codesys.sh
: Optimizes the system (see list below)The scripts also perform the following runtime optimizations:
Uses CAT to allocate exclusive access of half the last-level cache to cores 1,3
Assigns benchmark thread affinity to cores 1,3
Assigns non-benchmark thread affinity to core 0
Changes the priority of benchmark thread to 90 (using:
chrt -f 90
)Disables kernel machine check interrupt
Increases the thread runtime utilization to infinity
When executing the scripts, not all task affinity can be changed. This is expected behavior. An example output is shown below:
$ sudo /opt/benchmarking/codesys/utility/start_codesys_native.sh Stopping unecessary services Failed to stop ofono.service: Unit ofono.service not loaded. Failed to stop wpa_supplicant.service: Unit wpa_supplicant.service not loaded. Failed to stop bluetooth.service: Unit bluetooth.service not loaded. Stopping Docker Daemon Warning: Stopping docker.service, but it can still be activated by: docker.socket Stopping Codesys Runtime Disabling Machine Check Disabling RT runtime limit New COS default: 0xff0 Changing CPU affinity of existing interrupts setting 1 to affine for core 0 setting 4 to affine for core 0 setting 8 to affine for core 0 setting 9 to affine for core 0 setting 12 to affine for core 0 setting 14 to affine for core 0 setting 16 to affine for core 0 setting 18 to affine for core 0 setting 27 to affine for core 0 setting 29 to affine for core 0 setting 120 to affine for core 0 setting 121 to affine for core 0 setting 123 to affine for core 0 setting 124 to affine for core 0 setting 125 to affine for core 0 setting 126 to affine for core 0 taskset: failed to set pid 3's affinity: Invalid argument taskset: failed to set pid 4's affinity: Invalid argument taskset: failed to set pid 16's affinity: Invalid argument taskset: failed to set pid 23's affinity: Invalid argument Starting Codesys Runtime Changing affinity of Codesys Runtime tasks Codesys preparation complete.Run the
start_codesys_container.sh
script available at/opt/benchmarking/codesys/utility
to reload the CODESYS* Linux* runtime and start the benchmark:
$ cd /opt/benchmarking/codesys/utility $ sudo ./start_codesys_container.sh
$ cd /opt/benchmarking/codesys/utility $ sudo ./start_codesys_container.sh podmanThe CODESYS* benchmark is configured to host a web visualization at
http://<target-ip-address>:8080
. Open this URL in a web browser. If the benchmark is working correctly, the web visualization should be similar to the following image:Tip
If you cannot connect to the web server, verify that port 8080 is not blocked by a firewall. On Red Hat Enterprise Linux* based systems, you may need to open port 8080 in the firewall with the following commands:
$ sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent $ sudo firewall-cmd --reload![]()
Run the
taskset_codesys.sh
script at/opt/benchmarking/codesys/utility
to move all CODESYS* tasks to CPU cores 1,3 and change the priority of all CODESYS* tasks to RT:$ sudo ./taskset_codesys.shUse the RESET buttons in the web visualization to reset the statistics after running the
taskset_codesys.sh
script. This CODESYS* benchmark demonstrates that real-time performance can be achieved with proper kernel and runtime configurations.Use the slider and arrow buttons to increase or decrease the number of workload iterations per cycle.
The colored LEDs are connected to variables mapped to an OPC UA server. Connect an OPC UA client to the CODESYS* OPC UA server to read/write the values. You can download a popular free OPC UA client called UaExpert from: https://www.unified-automation.com/products/development-tools/uaexpert.html.
Prerequisites
A Microsoft Windows* system (x64 bit) to host the CODESYS IDE
A target system with the CODESYS* Linux* Runtime installed (See Install CODESYS Linux Runtime)
Ability to modify IP address of both the Microsoft Windows* PC and target system
Ability to connect both the Microsoft Windows* PC and target system via Ethernet network
The following steps are applicable to:
![]()
This CODESYS* benchmark project was created and validated using CODESYS* V3.5 SP17 Patch 2 + (64-bit). Project compatibility differences may occur when changing CODESYS* version.
![]()
See also
This section assumes you are already familiar with CODESYS* and how to deploy a workload to the CODESYS* Linux* runtime. For a detailed tutorial, see section: Application #2: CODESYS OPC UA Publish/Subscribe
Use the Intel edgesoftware utility to download the ECI release archive, if not done already.
Copy the
CODESYS_Example_Applications.zip
archive from the ECI release archive (release-eci_#.#.zip
) to the Microsoft Windows* system. This archive is located in the ECI release archive within theEdge-Controls-for-Industrial
directory as follows:└── Edge-Controls-for-Industrial ├── Codesys_Example_Applications.zip ├── Dockerfiles.tar.gz └── eci-release.tar.gzExtract the
CODESYS_Example_Applications.zip
archive. Navigate to the Benchmark directory. Double-click Benchmark_Linux_3.5.x.x.project to open the project with CODESYS*.The benchmark application was created assuming the target system will use an IP address of
10.11.12.50
on interfaceeno1
. However, you should change these to match the target system. You need to change two IP addresses to accomplish this:IP Address #1:
IP address in the CODESYS* application (change via the CODESYS* IDE) - Double-click “Ethernet” from the Devices pane. The IP address settings are displayed on the left pane.
![]()
IP Address #2:
IP address of the Microsoft Windows* PC running CODESYS* IDE. Microsoft Windows* is configured with
10.11.12.55
to be on the same subnet as the CODESYS* Linux* runtime.![]()
The following steps are applicable to:
![]()
On the target system, Install CODESYS Linux Runtime if not already done.
On the target system, install the
codesys-benchmark-scripts
package from the ECI repository. Setup the ECI repository, then perform the following command to install this component:
$ sudo apt install codesys-benchmark-scripts
$ sudo dnf install codesys-benchmark-scriptsNavigate to
/opt/benchmarking/codesys/utility
. This directory contains a number of useful scripts for improving the real-time performance of the CODESYS* Linux* runtime.The scripts available at
/opt/benchmarking/codesys/utility
include:
start_codesys_native.sh
: Optimizes the system (see list below), stops non-essential services, and restarts the CODESYS* runtime
start_codesys_container.sh
: Optimizes the system (see list below) and starts the containerized CODESYS* Linux* runtime with RT priority.
taskset_codesys.sh
: Optimizes the system (see list below)The scripts also perform the following runtime optimizations:
Uses CAT to allocate exclusive access of half the last-level cache to cores 1,3
Assigns benchmark thread affinity to cores 1,3
Assigns non-benchmark thread affinity to core 0
Changes the priority of benchmark thread to 90 (using:
chrt -f 90
)Disables kernel machine check interrupt
Increases the thread runtime utilization to infinity
When executing the scripts, not all task affinity can be changed. This is expected behavior. An example output is shown below:
$ sudo /opt/benchmarking/codesys/utility/start_codesys_native.sh Stopping unecessary services Failed to stop ofono.service: Unit ofono.service not loaded. Failed to stop wpa_supplicant.service: Unit wpa_supplicant.service not loaded. Failed to stop bluetooth.service: Unit bluetooth.service not loaded. Stopping Docker Daemon Warning: Stopping docker.service, but it can still be activated by: docker.socket Stopping Codesys Runtime Disabling Machine Check Disabling RT runtime limit New COS default: 0xff0 Changing CPU affinity of existing interrupts setting 1 to affine for core 0 setting 4 to affine for core 0 setting 8 to affine for core 0 setting 9 to affine for core 0 setting 12 to affine for core 0 setting 14 to affine for core 0 setting 16 to affine for core 0 setting 18 to affine for core 0 setting 27 to affine for core 0 setting 29 to affine for core 0 setting 120 to affine for core 0 setting 121 to affine for core 0 setting 123 to affine for core 0 setting 124 to affine for core 0 setting 125 to affine for core 0 setting 126 to affine for core 0 taskset: failed to set pid 3's affinity: Invalid argument taskset: failed to set pid 4's affinity: Invalid argument taskset: failed to set pid 16's affinity: Invalid argument taskset: failed to set pid 23's affinity: Invalid argument Starting Codesys Runtime Changing affinity of Codesys Runtime tasks Codesys preparation complete.Run the
start_codesys_native.sh
script available at/opt/benchmarking/codesys/utility
to reload the CODESYS* Linux* runtime in preparation of the benchmark:$ cd /opt/benchmarking/codesys/utility $ ./start_codesys_native.shBuild, download, and run the CODESYS* benchmark as outlined in OPC UA Publish/Subscribe Example. The CODESYS* benchmark is configured to host a web visualization at
http://<target-ip-address>:8080
. Open this URL in a web browser. If the benchmark is working correctly, the web visualization should be similar to the following image:Tip
If you cannot connect to the web server, verify that port 8080 is not blocked by a firewall. On Red Hat Enterprise Linux* based systems, you may need to open port 8080 in the firewall with the following commands:
$ sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent $ sudo firewall-cmd --reload![]()
Run the
taskset_codesys.sh
script at/opt/benchmarking/codesys/utility
to move all CODESYS* tasks to CPU cores 1,3 and change the priority of all CODESYS* tasks to RT:$ ./taskset_codesys.sh
Use the RESET buttons in the web visualization to reset the statistics after running the
taskset_codesys.sh
script. This CODESYS* benchmark demonstrates that real-time performance can be achieved with proper kernel and runtime configurations.Use the slider and arrow buttons to increase or decrease the number of workload iterations per cycle.
The colored LEDs are connected to variables mapped to an OPC UA server. Connect an OPC UA client to the CODESYS* OPC UA server to read/write the values. You can download a popular free OPC UA client called UaExpert from: https://www.unified-automation.com/products/development-tools/uaexpert.html.