Skip to content

feat(thread): add interrupt mode and FdGroup API wrappers#105

Open
jr42 wants to merge 2 commits intoopenebs:developfrom
jr42:pr/interrupt-mode
Open

feat(thread): add interrupt mode and FdGroup API wrappers#105
jr42 wants to merge 2 commits intoopenebs:developfrom
jr42:pr/interrupt-mode

Conversation

@jr42
Copy link
Copy Markdown

@jr42 jr42 commented Apr 12, 2026

Summary

Safe Rust wrappers for SPDK's interrupt mode facility and fd_group
hierarchical event multiplexing API (available since SPDK 24.09),
enabling custom reactors to sleep in fd_group_wait() instead of
busy-polling.

New Thread methods:

  • interrupt_mode_enable() / interrupt_mode_is_enabled(): global init and query
  • set_interrupt_mode(enable): per-thread poll/interrupt switching
  • get_interrupt_fd() / get_interrupt_fd_group(): access thread event fds

New FdGroup struct with RAII lifecycle:

  • create() / Drop: lifecycle management
  • wait(timeout): block until events (fd_group_wait)
  • nest(child) / unnest(child): hierarchical event multiplexing
  • add() / add_with_fd_type(): fd registration with optional auto-drain

New constant:

  • FD_TYPE_EVENTFD: marks eventfds for auto-draining in fd_group_wait()

These APIs enable the mayastor reactor to implement interrupt mode,
reducing CPU from ~1000m per core to <300m when idle.

Depends-On: openebs/spdk#70 (iSCSI + bdev interrupt fixes)
Ref: openebs/mayastor#1745

Test plan

  • Builds cleanly with updated libspdk
  • Used by mayastor reactor interrupt mode (73/86 pytest tests pass)
  • Production validated on 3-node cluster (16 volumes, 10+ days)
  • No regressions in poll mode

jr42 added 2 commits April 13, 2026 21:26
Add safe Rust wrappers for SPDK's interrupt mode facility (available
since SPDK 24.09) and the fd_group hierarchical event multiplexing API.

New Thread methods:
- interrupt_mode_enable/is_enabled: global init and query
- set_interrupt_mode: per-thread poll/interrupt switching
- get_interrupt_fd/get_interrupt_fd_group: access thread event fds

New FdGroup struct with RAII lifecycle:
- create/wait/nest/unnest: hierarchical event multiplexing
- add/add_with_fd_type: fd registration with optional auto-drain

New FD_TYPE_EVENTFD constant for auto-draining eventfds in
fd_group_wait.

These APIs enable custom reactors to sleep in fd_group_wait() instead
of busy-polling, reducing CPU usage from ~100% to near-zero when idle.

Ref: openebs/mayastor#1745
Signed-off-by: Jeremias Reith <jr42@users.noreply.github.com>
Update SPDK revision to include iSCSI poll group interrupt registration
and bdev wait_for_examine periodic poller fix, both required for
interrupt mode with custom reactors.

Note: temporarily points to jr42/spdk fork until the upstream PR is
merged into openebs/spdk, at which point owner should revert to
"openebs" and rev/sha256 updated to the merged commit.

Depends-On: openebs/spdk PR (iSCSI + bdev interrupt fixes)
Signed-off-by: Jeremias Reith <jr42@users.noreply.github.com>
@jr42 jr42 force-pushed the pr/interrupt-mode branch from f97d1d7 to 45647ff Compare April 13, 2026 19:27
Copy link
Copy Markdown
Member

@tiagolobocastro tiagolobocastro left a comment

Choose a reason for hiding this comment

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

We'll have to merge the dependent PR before this one, I'll try to review it a little later today

Comment thread src/thread.rs
/// fd_type value for eventfds: `fd_group_wait()` auto-drains these
/// by reading the counter to 0 before invoking the callback.
/// Matches `SPDK_FD_TYPE_EVENTFD` in `spdk/fd_group.h`.
pub const FD_TYPE_EVENTFD: u32 = 0x1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should have access to it, via crate::libspdk::SPDK_FD_TYPE_EVENTFD ?

Comment thread src/thread.rs

impl Debug for FdGroup {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "FdGroup({:p})", self.inner)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth including the owner?

Comment thread src/thread.rs

impl FdGroup {
/// Create a new fd_group.
pub fn create() -> Result<Self, i32> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Should we return nix::Error here? and throughout

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.

3 participants