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

[catpowder] Enhancement: add buffer pooling and multiple ring entries to XDP backend #1495

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ x86 = "0.52.0"
yaml-rust = "0.4.5"

# Demikernel crates (published on crates.io).
demikernel-dpdk-bindings = { version = "1.1.6", optional = true }
demikernel-dpdk-bindings = { version = "1.1.7", optional = true }
demikernel-network-simulator = { version = "0.1.0" }

# Windows-specific dependencies.
Expand All @@ -53,7 +53,7 @@ windows = { version = "0.57.0", features = [
"Win32_System_SystemInformation",
"Win32_System_Threading",
] }
demikernel-xdp-bindings = { version = "1.0.0", optional = true }
demikernel-xdp-bindings = { version = "1.0.1", optional = true }
# for interacting with socket2.
windows-sys = { version = "0.52.0", features = ["Win32_Networking_WinSock"] }

Expand Down
10 changes: 10 additions & 0 deletions scripts/config/azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ raw_socket:
linux_interface_name: "abcde"
xdp_interface_index: 0
xdp_cohost_mode: false
xdp_always_poke_tx: false
# Enable the following for XDP cohosting mode, or override in environment:
# xdp_tcp_ports: [80, 443]
# xdp_udp_ports: [53]
# Enable the following line if you have a VF interface
# xdp_vf_interface_index: 0
# The number of buffers to allocate for sending packets. Must be larger than the tx_ring_size.
tx_buffer_count: 4096
# The number of buffers to allocate for receiving packets for each RSS queue. Must be larger than
# the rx_ring_size.
rx_buffer_count: 4096
# The number of entries in the TX producer/consumer rings; must be a power of 2.
tx_ring_size: 128
# The number of entries in each RX producer/consumer ring for each RSS queue; must be a power of 2.
rx_ring_size: 128
dpdk:
eal_init: ["-c", "0xff", "-n", "4", "-a", "WW:WW.W", "--proc-type=auto", "--vdev=net_vdev_netvsc0,iface=abcde"]
tcp_socket_options:
Expand Down
10 changes: 10 additions & 0 deletions scripts/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ raw_socket:
linux_interface_name: "abcde"
xdp_interface_index: 0
xdp_cohost_mode: false
xdp_always_poke_tx: false
# Enable the following for XDP cohosting mode, or override in environment:
# xdp_tcp_ports: [80, 443]
# xdp_udp_ports: [53]
# Enable the following line if you have a VF interface
# xdp_vf_interface_index: 0
# The number of buffers to allocate for sending packets. Must be larger than the tx_ring_size.
tx_buffer_count: 4096
# The number of buffers to allocate for receiving packets for each RSS queue. Must be larger than
# the rx_ring_size.
rx_buffer_count: 4096
# The number of entries in the TX producer/consumer rings; must be a power of 2.
tx_ring_size: 128
# The number of entries in each RX producer/consumer ring for each RSS queue; must be a power of 2.
rx_ring_size: 128
dpdk:
eal_init: ["", "-c", "0xff", "-n", "4", "-a", "WW:WW.W","--proc-type=auto"]
tcp_socket_options:
Expand Down
3 changes: 3 additions & 0 deletions src/rust/catpowder/win/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ impl Drop for XdpApi {
}
}
}

unsafe impl Send for XdpApi {}
unsafe impl Sync for XdpApi {}
89 changes: 0 additions & 89 deletions src/rust/catpowder/win/ring/buffer.rs

This file was deleted.

39 changes: 29 additions & 10 deletions src/rust/catpowder/win/ring/generic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

use std::{marker::PhantomData, mem::MaybeUninit};

use crate::runtime::libxdp;

//======================================================================================================================
Expand All @@ -9,25 +11,31 @@ use crate::runtime::libxdp;

/// A wrapper structure for a XDP ring.
#[repr(C)]
pub struct XdpRing(libxdp::XSK_RING);
pub struct XdpRing<T>(libxdp::XSK_RING, PhantomData<T>);

//======================================================================================================================
// Implementations
//======================================================================================================================

impl XdpRing {
impl<T> XdpRing<T> {
/// Initializes a XDP ring.
pub(super) fn new(info: &libxdp::XSK_RING_INFO) -> Self {
Self(unsafe {
let ring: libxdp::XSK_RING = unsafe {
let mut ring: libxdp::XSK_RING = std::mem::zeroed();
libxdp::_XskRingInitialize(&mut ring, info);
ring
})
};

if !ring.SharedElements.cast::<T>().is_aligned() {
panic!("XdpRing::new(): ring memory is not aligned for type T");
}

Self(ring, PhantomData)
}

/// Reserves a consumer slot in the target ring.
pub(super) fn consumer_reserve(&mut self, count: u32, idx: *mut u32) -> u32 {
unsafe { libxdp::_XskRingConsumerReserve(&mut self.0, count, idx) }
pub(super) fn consumer_reserve(&mut self, count: u32, idx: &mut u32) -> u32 {
unsafe { libxdp::_XskRingConsumerReserve(&mut self.0, count, idx as *mut u32) }
}

/// Releases a consumer slot in the target ring.
Expand All @@ -36,8 +44,8 @@ impl XdpRing {
}

/// Reserves a producer slot in the target ring.
pub(super) fn producer_reserve(&mut self, count: u32, idx: *mut u32) -> u32 {
unsafe { libxdp::_XskRingProducerReserve(&mut self.0, count, idx) }
pub(super) fn producer_reserve(&mut self, count: u32, idx: &mut u32) -> u32 {
unsafe { libxdp::_XskRingProducerReserve(&mut self.0, count, idx as *mut u32) }
}

/// Submits a producer slot in the target ring.
Expand All @@ -46,7 +54,18 @@ impl XdpRing {
}

/// Gets the element at the target index.
pub(super) fn get_element(&self, idx: u32) -> *mut std::ffi::c_void {
unsafe { libxdp::_XskRingGetElement(&self.0, idx) }
pub(super) fn get_element(&self, idx: u32) -> &mut MaybeUninit<T> {
// Safety: the alignment of ring elements is validated by the constructor. We rely on the XDP runtime to
// provide valid memory for the ring.
unsafe { &mut *libxdp::_XskRingGetElement(&self.0, idx).cast() }
}

#[allow(dead_code)]
pub(super) fn needs_poke(&self) -> bool {
unsafe { libxdp::_XskRingProducerNeedPoke(&self.0) != 0 }
}

pub(super) fn has_error(&self) -> bool {
unsafe { libxdp::_XskRingError(&self.0) != 0 }
}
}
2 changes: 0 additions & 2 deletions src/rust/catpowder/win/ring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Modules
//======================================================================================================================

mod buffer;
mod generic;
mod rule;
mod rx_ring;
Expand All @@ -16,6 +15,5 @@ mod umemreg;
// Exports
//======================================================================================================================

pub use buffer::XdpBuffer;
pub use rx_ring::RxRing;
pub use tx_ring::TxRing;
Loading
Loading