Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ringbuffer performance #4027

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Alan-Jowett
Copy link
Member

@Alan-Jowett Alan-Jowett commented Nov 20, 2024

Description

This pull request includes significant changes to the eBPF ring buffer implementation, focusing on improving synchronization, memory management, and adding new functionality. The most important changes include the introduction of spin locks for better concurrency control, a new flag-based system for record states, and the addition of a stress test for the ring buffer.

Synchronization and Memory Management Improvements:

  • libs/runtime/ebpf_ring_buffer.c: Introduced cxplat_spin_lock_t for both producer and consumer locks, replacing the previous ebpf_lock_t. This change improves concurrency control by using spin locks, which are more efficient in high-contention scenarios.
  • libs/runtime/ebpf_ring_buffer.c: Modified the ebpf_ring_buffer_reserve and ebpf_ring_buffer_output functions to use a new flag-based system for record states, ensuring better synchronization and memory management. [1] [2]

New Flag-Based System for Record States:

  • libs/shared/ebpf_ring_buffer_record.h: Introduced new flags EBPF_RING_BUFFER_RECORD_FLAG_LOCKED and EBPF_RING_BUFFER_RECORD_FLAG_DISCARDED to manage the state of records in the ring buffer. This change simplifies the handling of record states and improves code readability. [1] [2]

Additional Functionality:

  • libs/runtime/unit/platform_unit_test.cpp: Added a new stress test case ring_buffer_stress to evaluate the performance and reliability of the ring buffer under high load conditions. This test helps ensure the robustness of the ring buffer implementation.

Other Notable Changes:

  • libs/api/ebpf_api.cpp: Added a loop to wait for the producer to finish writing if the record is locked, ensuring data consistency.
  • external/usersim: Updated the submodule commit reference to point to the latest commit.

Testing

CI/CD + dedicated stress test

Documentation

No.

Installation

No.

libs/api/ebpf_api.cpp Outdated Show resolved Hide resolved
@Alan-Jowett Alan-Jowett marked this pull request as draft November 22, 2024 21:26
@Alan-Jowett
Copy link
Member Author

There exists a race condition around the producer wrapping.

@Alan-Jowett Alan-Jowett changed the title Lock-free ringbuf output Improve ringbuffer performance Nov 24, 2024
Signed-off-by: Alan Jowett <[email protected]>
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.

4 participants