CPU affinity in Cloverleaf runtime (Windows/Linux)

CPU affinity enables binding a process or multiple processes to a specific CPU core, or range of CPUs, so that processes only run from that specific core. When trying to perform performance testing on a host with many cores, you can run multiple instances of a process, each one on different core. This enables higher CPU utilization.

Cloverleaf supports CPU affinity configuration on the Cloverleaf engine, Monitor Daemon, Host Server, Security Server, and Cloverleaf Windows service.

Configuration

The CPU affinity configuration is located at $HCIROOT/rootInfo. This is a key-value pair, where:

  • Key name is cpuaffinity.
  • Value is the list of available processor or core number IDs on the host, separated by a comma.

Example:

version=... 
: 
cpuaffinity=0,1,3,5,6,7 

Runtimes and the logs

After cpuaffinity is set in the rootInfo, Cloverleaf runtimes follow it to enable CPU affinity. The corresponding information is logged in the runtime log file.

For example, cpuaffinity is set in rootInfo as:

cpuaffinity=0,2,3 

The hciengine log contains:

[prod:prod:INFO/0:helloworld:12/11/2020 15:37:00] CPU affinity set is 0,2,3 
[prod:prod:INFO/0:helloworld:12/11/2020 15:37:01] Applying EO config: 'enable_all' 

The runtime CPU affinity status is verified by the host.

  • On Windows, in addition to the Task Manager PowerShell, the Get-process command also has the path.
  • On Linux, use the taskset command.

Example:

PS C:\WINDOWS\system32> Get-Process hciengine | Select-Object ProcessorAffinity 
ProcessorAffinity 
-----------------
               13

When cpuaffinity is set incorrectly in rootInfo, error information is logged in the runtime log, and runtime does not start.

[prod:prod:INFO/0:_hcimonitord_:01/19/2021 19:49:24] CPU affinity set is 0,1,2,x 
[prod:prod:ERR /0:_hcimonitord_:01/19/2021 19:49:28] CPU affinity setting is incorrect: 87

The Cloverleaf Windows service CPU affinity does not contain the log file. The status is information or an error that is logged in System Event. This is viewable in the Event Viewer tool.

The difference is when the cpuaffinity setting is incorrect. When this happens, the Cloverleaf Windows service reports an error in Event Viewer, and proceeds further without stop.