Skip to content

Commit

Permalink
[catpowder] Enhancement: Improve XDP LibOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ppenna committed Jul 8, 2024
1 parent 9439fa5 commit c86c304
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 96 deletions.
4 changes: 4 additions & 0 deletions src/rust/catpowder/win/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ impl XdpApi {
}
}

//======================================================================================================================
// Trait Implementations
//======================================================================================================================

impl Drop for XdpApi {
fn drop(&mut self) {
let api: xdp_rs::XDP_API_TABLE = unsafe {
Expand Down
14 changes: 9 additions & 5 deletions src/rust/catpowder/win/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//======================================================================================================================

use crate::catpowder::win::umemreg::UmemReg;
use ::std::ops::{
Deref,
DerefMut,
};
use std::{
use ::std::{
cell::RefCell,
ops::{
Deref,
DerefMut,
},
rc::Rc,
};

Expand Down Expand Up @@ -59,6 +59,10 @@ impl XdpBuffer {
}
}

//======================================================================================================================
// Trait Implementations
//======================================================================================================================

impl Deref for XdpBuffer {
type Target = [u8];

Expand Down
2 changes: 0 additions & 2 deletions src/rust/catpowder/win/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ mod params;
mod program;
mod ring;
mod rule;
mod rx_ring;
mod socket;
mod tx_ring;
mod umemreg;

//======================================================================================================================
Expand Down
45 changes: 0 additions & 45 deletions src/rust/catpowder/win/ring.rs

This file was deleted.

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

//======================================================================================================================
// Structures
//======================================================================================================================

pub(super) struct XdpRing(xdp_rs::XSK_RING);

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

impl XdpRing {
pub(super) fn initialize(info: &xdp_rs::XSK_RING_INFO) -> Self {
Self(unsafe {
let mut ring: xdp_rs::XSK_RING = std::mem::zeroed();
xdp_rs::_XskRingInitialize(&mut ring, info);
ring
})
}

pub(super) fn consumer_reserve(&mut self, count: u32, idx: *mut u32) -> u32 {
unsafe { xdp_rs::_XskRingConsumerReserve(&mut self.0, count, idx) }
}

pub(super) fn consumer_release(&mut self, count: u32) {
unsafe { xdp_rs::_XskRingConsumerRelease(&mut self.0, count) }
}

pub(super) fn producer_reserve(&mut self, count: u32, idx: *mut u32) -> u32 {
unsafe { xdp_rs::_XskRingProducerReserve(&mut self.0, count, idx) }
}

pub(super) fn producer_submit(&mut self, count: u32) {
unsafe { xdp_rs::_XskRingProducerSubmit(&mut self.0, count) }
}

pub(super) fn get_element(&self, idx: u32) -> *mut std::ffi::c_void {
unsafe { xdp_rs::_XskRingGetElement(&self.0, idx) }
}
}
17 changes: 17 additions & 0 deletions src/rust/catpowder/win/ring/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

//======================================================================================================================
// Modules
//======================================================================================================================

mod generic;
mod rx_ring;
mod tx_ring;

//======================================================================================================================
// Exports
//======================================================================================================================

pub use rx_ring::RxRing;
pub use tx_ring::TxRing;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
api::XdpApi,
buffer::XdpBuffer,
program::XdpProgram,
ring::XdpRing,
ring::generic::XdpRing,
rule::XdpRule,
socket::XdpSocket,
umemreg::UmemReg,
Expand Down Expand Up @@ -89,18 +89,18 @@ impl RxRing {
&mut option_length as *mut u32,
)?;

let mut rx_fill_ring: XdpRing = XdpRing::ring_initialize(&ring_info.Fill);
let rx_ring: XdpRing = XdpRing::ring_initialize(&ring_info.Rx);
let mut rx_fill_ring: XdpRing = XdpRing::initialize(&ring_info.Fill);
let rx_ring: XdpRing = XdpRing::initialize(&ring_info.Rx);

trace!("Reserving RX ring buffer.");
let mut ring_index: u32 = 0;
rx_fill_ring.ring_producer_reserve(RING_SIZE, &mut ring_index);
rx_fill_ring.producer_reserve(RING_SIZE, &mut ring_index);

let b: *mut u64 = rx_fill_ring.ring_get_element(ring_index) as *mut u64;
let b: *mut u64 = rx_fill_ring.get_element(ring_index) as *mut u64;
unsafe { *b = 0 };

trace!("Submitting RX ring buffer.");
rx_fill_ring.ring_producer_submit(RING_SIZE);
rx_fill_ring.producer_submit(RING_SIZE);

trace!("Setting RX Fill ring.");

Expand All @@ -124,25 +124,25 @@ impl RxRing {
}

pub fn consumer_reserve(&mut self, count: u32, idx: &mut u32) -> u32 {
self.rx_ring.ring_consumer_reserve(count, idx)
self.rx_ring.consumer_reserve(count, idx)
}

pub fn get_element(&self, idx: u32) -> XdpBuffer {
XdpBuffer::new(
self.rx_ring.ring_get_element(idx) as *mut xdp_rs::XSK_BUFFER_DESCRIPTOR,
self.rx_ring.get_element(idx) as *mut xdp_rs::XSK_BUFFER_DESCRIPTOR,
self.mem.clone(),
)
}

pub fn consumer_release(&mut self, count: u32) {
self.rx_ring.ring_consumer_release(count);
self.rx_ring.consumer_release(count);
}

pub fn producer_reserve(&mut self, count: u32, idx: &mut u32) -> u32 {
self.rx_fill_ring.ring_producer_reserve(count, idx)
self.rx_fill_ring.producer_reserve(count, idx)
}

pub fn producer_submit(&mut self, count: u32) {
self.rx_fill_ring.ring_producer_submit(count);
self.rx_fill_ring.producer_submit(count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
catpowder::win::{
api::XdpApi,
buffer::XdpBuffer,
ring::XdpRing,
ring::generic::XdpRing,
socket::XdpSocket,
umemreg::UmemReg,
},
Expand Down Expand Up @@ -82,8 +82,8 @@ impl TxRing {
&mut option_length as *mut u32,
)?;

let tx_ring: XdpRing = XdpRing::ring_initialize(&ring_info.Tx);
let tx_completion_ring: XdpRing = XdpRing::ring_initialize(&ring_info.Completion);
let tx_ring: XdpRing = XdpRing::initialize(&ring_info.Tx);
let tx_completion_ring: XdpRing = XdpRing::initialize(&ring_info.Completion);

trace!("XDP program created.");
Ok(Self {
Expand All @@ -105,24 +105,24 @@ impl TxRing {
}

pub fn consumer_reserve(&mut self, count: u32, idx: &mut u32) -> u32 {
self.tx_completion_ring.ring_consumer_reserve(count, idx)
self.tx_completion_ring.consumer_reserve(count, idx)
}

pub fn consumer_release(&mut self, count: u32) {
self.tx_completion_ring.ring_consumer_release(count);
self.tx_completion_ring.consumer_release(count);
}

pub fn producer_reserve(&mut self, count: u32, idx: &mut u32) -> u32 {
self.tx_ring.ring_producer_reserve(count, idx)
self.tx_ring.producer_reserve(count, idx)
}

pub fn producer_submit(&mut self, count: u32) {
self.tx_ring.ring_producer_submit(count);
self.tx_ring.producer_submit(count);
}

pub fn get_element(&self, idx: u32) -> XdpBuffer {
XdpBuffer::new(
self.tx_ring.ring_get_element(idx) as *mut xdp_rs::XSK_BUFFER_DESCRIPTOR,
self.tx_ring.get_element(idx) as *mut xdp_rs::XSK_BUFFER_DESCRIPTOR,
self.mem.clone(),
)
}
Expand Down
Loading

0 comments on commit c86c304

Please sign in to comment.