Skip to content

DPDK EAL init in UHD4.9 pins application main thread to a single CPU core #902

@wfarah

Description

@wfarah

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

  1. Run a GNU Radio application using UHD with the DPDK transport enabled.
  2. Ensure the application’s main thread initially has a non-restricted CPU
    affinity (e.g., allowed on multiple cores).
  3. Observe thread affinity before and after UHD initialization (e.g., using
    htop)
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions