Skip to content

Commit d6177ca

Browse files
authored
Cache routes received from next_hop (#499)
This PR inserts a caching layer in front of `next_hop` to store routes for a given `(IpAddr6, L4Hash)` for around 100ms, and reorganises routing-related code into `xde::route`. This is a necessary step as today we spend around 21% of `xde_mc_tx` in route lookup on a per-outbound-packet basis. As a consequence, we need install a new `Periodic` to flush expired entries every 1s, as otherwise we can have a large amountof detritus pileup from different L4Hash values. Currently this is implemented as a per-port cache rather than shared across the driver -- I've done this because it will give us better sharding of concurrent readers/writers at higher port/guest counts. The PR as-is pulls us up from ~1.74Gbps to 2Gbps on a single link between sn9/14.
1 parent cf268a6 commit d6177ca

6 files changed

Lines changed: 743 additions & 389 deletions

File tree

lib/opte/src/d_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<const L: usize> LabelBlock<L> {
145145
}
146146

147147
/// Provides access to all stored [`CStr`]s.
148-
pub fn entries<'a>(&'a self) -> LabelBlockIter<'a, L> {
148+
pub fn entries(&self) -> LabelBlockIter<'_, L> {
149149
LabelBlockIter { pos: 0, inner: self }
150150
}
151151

lib/opte/src/engine/packet.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl PacketChain {
469469

470470
/// Removes the next packet from the top of the chain and returns
471471
/// it, taking ownership.
472-
pub fn next(&mut self) -> Option<Packet<Initialized>> {
472+
pub fn pop_front(&mut self) -> Option<Packet<Initialized>> {
473473
if let Some(ref mut list) = &mut self.inner {
474474
unsafe {
475475
let curr = list.head.as_ptr();
@@ -554,7 +554,7 @@ impl Drop for PacketChain {
554554
unsafe { ddi::freemsgchain(list.head.as_ptr()) };
555555
}
556556
} else {
557-
while let Some(pkt) = self.next() {
557+
while let Some(pkt) = self.pop_front() {
558558
drop(pkt);
559559
}
560560
}
@@ -3945,7 +3945,7 @@ mod test {
39453945

39463946
fn create_linked_mblks(n: usize) -> Vec<*mut mblk_t> {
39473947
let mut els = vec![];
3948-
for i in 0..n {
3948+
for _ in 0..n {
39493949
els.push(allocb(8));
39503950
}
39513951

@@ -3962,7 +3962,7 @@ mod test {
39623962

39633963
#[test]
39643964
fn chain_has_correct_ends() {
3965-
let mut els = create_linked_mblks(3);
3965+
let els = create_linked_mblks(3);
39663966

39673967
let chain = unsafe { PacketChain::new(els[0]) }.unwrap();
39683968
let chain_inner = chain.inner.as_ref().unwrap();
@@ -3976,7 +3976,7 @@ mod test {
39763976

39773977
let mut chain = unsafe { PacketChain::new(els[0]) }.unwrap();
39783978

3979-
let p0 = chain.next().unwrap();
3979+
let p0 = chain.pop_front().unwrap();
39803980
assert_eq!(p0.mblk_addr(), els[0] as uintptr_t);
39813981
unsafe {
39823982
assert!((*els[0]).b_prev.is_null());
@@ -4024,10 +4024,10 @@ mod test {
40244024
let mut chain = unsafe { PacketChain::new(els[0]) }.unwrap();
40254025

40264026
for i in 0..els.len() {
4027-
let pkt = chain.next().unwrap();
4027+
let pkt = chain.pop_front().unwrap();
40284028
assert_eq!(pkt.mblk_addr(), els[i] as uintptr_t);
40294029
}
40304030

4031-
assert!(chain.next().is_none());
4031+
assert!(chain.pop_front().is_none());
40324032
}
40334033
}

lib/opte/src/engine/rule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl<'a> Rule<Finalized> {
834834
#[cfg(debug_assertions)]
835835
{
836836
if let Some(preds) = &self.state.preds {
837-
if preds.hdr_preds.len() == 0 && preds.data_preds.len() == 0 {
837+
if preds.hdr_preds.is_empty() && preds.data_preds.is_empty() {
838838
panic!(
839839
"bug: RulePredicates must have at least one \
840840
predicate"

xde/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
// Copyright 2022 Oxide Computer Company
5+
// Copyright 2024 Oxide Computer Company
66

77
// xde - A mac provider for OPTE-based network implementations.
88
#![feature(extern_types)]
@@ -44,6 +44,7 @@ pub mod dls;
4444
pub mod ip;
4545
pub mod mac;
4646
mod mac_sys;
47+
pub mod route;
4748
pub mod secpolicy;
4849
pub mod sys;
4950
pub mod xde;

0 commit comments

Comments
 (0)