igb driver (ec_igb):
High latency, more than 30% of the ethercat cycle time, can result in lost ethercat frames, which means data are lost. High latency of the ecmc_rt thread can be related to:
Check which driver is in use by running (on the ecmc server):
lsmod | grep ec_
If the ec_master is using the ec_generic driver then a switch to igb driver is recommended.
The file /ioc/hosts/<hostname>/cfg/ETHERCATDRVR is listing the available drivers.
The recommended contents of the ETHERCATDRVR file is:
DEVICE_MODULES="igb generic"
In this case, the system will first try to use igb driver, if not possible it will fallback to the generic driver. After editing the file, the host needs to be rebooted in order for the changes to take effect.
** Reduce sample rate** Reducing the ethercat cycle time is often very efficient when it comes to reduce latency. Do not run the ecmc systems faster than needed. The default ecmc sample rate is 1Khz, which in many cases is not needed.
The sample rate is defined when require ecmccfg (example set to 500Hz, instead of 1kHz):
require ecmccfg "EC_RATE=500"
There are some restrictions on the sample rate. Normally, a rate in the range 100Hz-1Khz is a good choice. For other rates, please check the documentation of slaves in use. See heading “EtherCAT rate” below for more information.
** Affinity** Setting the affinity of the ecmc realtime thread can often improve the performance. First check how many cores the controller has.
At PSI, core 0 is always isolated, do not move any threads to core 0.
In order to pin the ecmc thread to a single core, add the following line to the startup script (after setAppMode.cmd):
#- go active (create ecmc_rt)
${SCRIPTEXEC} ${ecmccfg_DIR}setAppMode.cmd
#- Set affinity of ecmc_rt (core 5)
epicsThreadSetAffinity ecmc_rt 5
If more than one ecmc ioc is running on the server, then make sure the ecmc_rt threads run on different cores.
Further tuning might include moving other cpu intensive threads to dedicated cores, for instance the epics thread cbLow
:
afterInit "epicsThreadSetAffinity cbLow 6"
cbLow
is created at iocInit, therefore the “epicsThreadSetAffinity” must be executed with the “afterInit” command.
The affinity can also be set with the tools accessible in the EPICS module MCoreUtils.
The default EtherCAT frame rate in ecmc is set to 1kHz. For most applications this is however not needed and can therefore be reduced. A reduced EtherCAT rate reduces the load on the controller. In general, a good value for the frame rate is in the range 100Hz to 1kHz. For motion systems, a frame rate of 100Hz..500Hz is normally enough. Rates outside the 100Hz..1kHz range is normally not a good idea, and some slaves might not support it. However, in special cases both lower and higher rates might be possible and required.
Example: Set rate to 500Hz
require ecmccfg "EC_RATE=500"
...
For more information see the chapter describing startup.cmd.
As a comparison, TwinCAT default EtherCAT rates are:
Issues that could occur in rates below 100Hz:
Issues that could occur in rates over 1Kz:
NOTE: Some slave might support a high rate but could have built in signal filters of several ms which then makes sampling at higher freqs unnecessary/not needed.
In order to successfully run an ecmc ethercat system at higher rates some tuning might be needed: