Core Allocation CPU Affinity Support for Applications & systemd Services on i.MX8QXP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Core Allocation CPU Affinity Support for Applications & systemd Services on i.MX8QXP

208 Views
Ram2
Contributor III

Hi NXP Team,

We are working on the i.MX8QXP platform running Yocto Linux Nanbield (custom HMI build).
Our setup uses 4 Cortex-A35 cores, and we want to optimize CPU utilization for specific applications and systemd services.

Assign a systemd service to run only on a particular CPU core?
We are exploring CPU load balancing and deterministic performance for certain tasks within our custom HMI application stack.

Please advise on:

  • Supported CPU affinity mechanisms on i.MX8QXP

  • Any NXP documentation references or examples for CPU isolation/assignment

0 Kudos
Reply
1 Reply

162 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello,

# CPU Affinity Support for i.MX8QXP

The i.MX8QXP platform with its 4 Cortex-A35 cores supports multiple CPU affinity mechanisms to optimize utilization for specific applications and systemd services.

## Supported CPU Affinity Mechanisms

1. **taskset Command**
- Assign specific applications to run on designated cores
- Example: `taskset -c 0,1 your_application`
- For systemd services: Use `CPUAffinity=` directive in service unit files

2. **Kernel Boot Parameters**
- `isolcpus=` - Isolates CPUs from the kernel scheduler
- `nohz_full=` - Reduces timer interrupts on specified cores
- `rcu_nocbs=` - Moves RCU callback processing off specified cores
- `irqaffinity=` - Directs hardware interrupts to specific cores

3. **Systemd Service Configuration**
- Add to your service unit files:
```
[Service]
CPUAffinity=0-1 # Restrict to cores 0 and 1
```

4. **Runtime CPU Management**
- Enable/disable cores dynamically:
```
echo 0 > /sys/devices/system/cpu/cpu3/online
```

5. **Process/Thread Specific Affinity**
- In C/C++ applications: `pthread_setaffinity_np()`
- For running processes: `taskset -p -c 2,3 [PID]`

For optimal deterministic performance, use a combination of `isolcpus`, `nohz_full`, and `irqaffinity` boot parameters to dedicate specific cores to your critical applications while keeping system services on separate cores.

Note that complete isolation isn't entirely possible as certain kernel threads (migration, ksoftirqd, kworker) will remain present on all cores, but their impact on performance is minimal.

Regards

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2249354%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ECore%20Allocation%20CPU%20Affinity%20Support%20for%20Applications%20%26amp%3B%20systemd%20Services%20on%20i.MX8QXP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2249354%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20NXP%20Team%2C%3C%2FP%3E%3CP%3EWe%20are%20working%20on%20the%20i.MX8QXP%20platform%20running%20Yocto%20Linux%20Nanbield%20(custom%20HMI%20build).%3CBR%20%2F%3EOur%20setup%20uses%20%3CSTRONG%3E4%20Cortex-A35%20cores%3C%2FSTRONG%3E%2C%20and%20we%20want%20to%20optimize%20CPU%20utilization%20for%20specific%20applications%20and%20systemd%20services.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3EAssign%20a%20systemd%20service%20to%20run%20only%20on%20a%20particular%20CPU%20core%3C%2FSTRONG%3E%3F%3CBR%20%2F%3EWe%20are%20exploring%20CPU%20load%20balancing%20and%20deterministic%20performance%20for%20certain%20tasks%20within%20our%20custom%20HMI%20application%20stack.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EPlease%20advise%20on%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3ESupported%20CPU%20affinity%20mechanisms%20on%20i.MX8QXP%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EAny%20NXP%20documentation%20references%20or%20examples%20for%20CPU%20isolation%2Fassignment%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2250442%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Core%20Allocation%20CPU%20Affinity%20Support%20for%20Applications%20%26amp%3B%20systemd%20Services%20on%20i.MX8QXP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2250442%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%23%20CPU%20Affinity%20Support%20for%20i.MX8QXP%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20i.MX8QXP%20platform%20with%20its%204%20Cortex-A35%20cores%20supports%20multiple%20CPU%20affinity%20mechanisms%20to%20optimize%20utilization%20for%20specific%20applications%20and%20systemd%20services.%3CBR%20%2F%3E%3CBR%20%2F%3E%23%23%20Supported%20CPU%20Affinity%20Mechanisms%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20**taskset%20Command**%3CBR%20%2F%3E-%20Assign%20specific%20applications%20to%20run%20on%20designated%20cores%3CBR%20%2F%3E-%20Example%3A%20%60taskset%20-c%200%2C1%20your_application%60%3CBR%20%2F%3E-%20For%20systemd%20services%3A%20Use%20%60CPUAffinity%3D%60%20directive%20in%20service%20unit%20files%3CBR%20%2F%3E%3CBR%20%2F%3E2.%20**Kernel%20Boot%20Parameters**%3CBR%20%2F%3E-%20%60isolcpus%3D%60%20-%20Isolates%20CPUs%20from%20the%20kernel%20scheduler%3CBR%20%2F%3E-%20%60nohz_full%3D%60%20-%20Reduces%20timer%20interrupts%20on%20specified%20cores%3CBR%20%2F%3E-%20%60rcu_nocbs%3D%60%20-%20Moves%20RCU%20callback%20processing%20off%20specified%20cores%3CBR%20%2F%3E-%20%60irqaffinity%3D%60%20-%20Directs%20hardware%20interrupts%20to%20specific%20cores%3CBR%20%2F%3E%3CBR%20%2F%3E3.%20**Systemd%20Service%20Configuration**%3CBR%20%2F%3E-%20Add%20to%20your%20service%20unit%20files%3A%3CBR%20%2F%3E%60%60%60%3CBR%20%2F%3E%5BService%5D%3CBR%20%2F%3ECPUAffinity%3D0-1%20%23%20Restrict%20to%20cores%200%20and%201%3CBR%20%2F%3E%60%60%60%3CBR%20%2F%3E%3CBR%20%2F%3E4.%20**Runtime%20CPU%20Management**%3CBR%20%2F%3E-%20Enable%2Fdisable%20cores%20dynamically%3A%3CBR%20%2F%3E%60%60%60%3CBR%20%2F%3Eecho%200%20%26gt%3B%20%2Fsys%2Fdevices%2Fsystem%2Fcpu%2Fcpu3%2Fonline%3CBR%20%2F%3E%60%60%60%3CBR%20%2F%3E%3CBR%20%2F%3E5.%20**Process%2FThread%20Specific%20Affinity**%3CBR%20%2F%3E-%20In%20C%2FC%2B%2B%20applications%3A%20%60pthread_setaffinity_np()%60%3CBR%20%2F%3E-%20For%20running%20processes%3A%20%60taskset%20-p%20-c%202%2C3%20%5BPID%5D%60%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20optimal%20deterministic%20performance%2C%20use%20a%20combination%20of%20%60isolcpus%60%2C%20%60nohz_full%60%2C%20and%20%60irqaffinity%60%20boot%20parameters%20to%20dedicate%20specific%20cores%20to%20your%20critical%20applications%20while%20keeping%20system%20services%20on%20separate%20cores.%3CBR%20%2F%3E%3CBR%20%2F%3ENote%20that%20complete%20isolation%20isn't%20entirely%20possible%20as%20certain%20kernel%20threads%20(migration%2C%20ksoftirqd%2C%20kworker)%20will%20remain%20present%20on%20all%20cores%2C%20but%20their%20impact%20on%20performance%20is%20minimal.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ERegards%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E