Skip to content

Bind epoll_loop to last online CPU#73

Open
li041 wants to merge 2 commits intosyswonder:mainfrom
li041:cpu-bind
Open

Bind epoll_loop to last online CPU#73
li041 wants to merge 2 commits intosyswonder:mainfrom
li041:cpu-bind

Conversation

@li041
Copy link

@li041 li041 commented Jan 26, 2026

  • Currently, the epoll_loop is created without CPU affinity, which
    can result in it being scheduled on CPU0. Since CPU0 is often handling
    interrupts and other critical system tasks (zone0), this can interfere
    with system responsiveness.

  • This PR changes the initialize_event_monitor to bind epoll_loop to
    the last online CPU available to the process. The thread affinity is
    set using pthread_setaffinity_np after determining the last CPU from
    sched_getaffinity.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds CPU affinity binding for the epoll_loop thread to prevent it from being scheduled on CPU0, which typically handles interrupts and critical system tasks. The implementation determines the last available CPU using sched_getaffinity and binds the event monitor thread to that CPU using pthread_setaffinity_np.

Changes:

  • Added _GNU_SOURCE definition and sched.h include for CPU affinity functions
  • Implemented CPU affinity logic in initialize_event_monitor to bind the epoll_loop thread to the last online CPU
  • Added logging for CPU affinity operations (success and failure cases)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@agicy agicy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@li041 li041 marked this pull request as draft January 28, 2026 12:14
@li041 li041 marked this pull request as ready for review January 28, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants