Issue Description
Calling rte_eal_init() inside UHD’s DPDK transport modifies the CPU affinity
of the calling thread by pinning it to the DPDK “main lcore”. When UHD is used
from applications such as GNU Radio, this can unintentionally pin the main
application thread (e.g., the GNU Radio scheduler) to a single CPU core.
Because UHD does not restore the original thread affinity after DPDK EAL
initialization, the application’s main thread may remain constrained to a
single CPU core, significantly reducing scheduling flexibility and the application
is unable to keep up with real-time processing.
A proposed fix saves the calling thread’s CPU affinity before invoking
rte_eal_init() and restores it immediately afterward.
Setup Details
- UHD version: 4.9.0.0
- DPDK version: 23.11.4
- OS: Ubuntu 24.04.3 LTS
- Hardware:
- USRP model: X440
- Host CPU: multi-core aarch64
- Application:
- GNU Radio using UHD DPDK transport
Expected Behavior
Initializing the DPDK EAL inside UHD should not permanently alter the CPU
affinity of the calling application thread. After UHD initialization, the
calling thread should retain its original affinity policy unless explicitly
modified by the application.
Actual Behaviour
After calling rte_eal_init(), the calling thread becomes pinned to the DPDK
main lcore (typically the first core in the EAL core list). The original CPU
affinity is not restored, leaving the application’s main thread constrained to
a single CPU core.
Steps to reproduce the problem
- Run a GNU Radio application using UHD with the DPDK transport enabled.
- Ensure the application’s main thread initially has a non-restricted CPU
affinity (e.g., allowed on multiple cores).
- Observe thread affinity before and after UHD initialization (e.g., using
htop)
- Note that after UHD initializes DPDK, the calling thread is pinned to a
single CPU core.
Additional Information
A patch is proposed that:
- Saves the calling thread’s CPU affinity using
pthread_getaffinity_np()
before calling rte_eal_init()
- Restores the affinity using
pthread_setaffinity_np() immediately after
initialization
I’m happy to open a PR with this change if it aligns with the intended behavior.
Issue Description
Calling
rte_eal_init()inside UHD’s DPDK transport modifies the CPU affinityof the calling thread by pinning it to the DPDK “main lcore”. When UHD is used
from applications such as GNU Radio, this can unintentionally pin the main
application thread (e.g., the GNU Radio scheduler) to a single CPU core.
Because UHD does not restore the original thread affinity after DPDK EAL
initialization, the application’s main thread may remain constrained to a
single CPU core, significantly reducing scheduling flexibility and the application
is unable to keep up with real-time processing.
A proposed fix saves the calling thread’s CPU affinity before invoking
rte_eal_init()and restores it immediately afterward.Setup Details
Expected Behavior
Initializing the DPDK EAL inside UHD should not permanently alter the CPU
affinity of the calling application thread. After UHD initialization, the
calling thread should retain its original affinity policy unless explicitly
modified by the application.
Actual Behaviour
After calling
rte_eal_init(), the calling thread becomes pinned to the DPDKmain lcore (typically the first core in the EAL core list). The original CPU
affinity is not restored, leaving the application’s main thread constrained to
a single CPU core.
Steps to reproduce the problem
affinity (e.g., allowed on multiple cores).
htop)single CPU core.
Additional Information
A patch is proposed that:
pthread_getaffinity_np()before calling
rte_eal_init()pthread_setaffinity_np()immediately afterinitialization
I’m happy to open a PR with this change if it aligns with the intended behavior.