Skip to content

Commit 5a1f27e

Browse files
committed
Fix performance issues in l2fwd
1 parent ef161a7 commit 5a1f27e

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

bindings/dpdk/src/eal.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ use thiserror::Error;
1616

1717
const MAGIC: &str = "be0dd4ab";
1818

19-
pub const DEFAULT_TX_DESC: u16 = 1024;
20-
pub const DEFAULT_RX_DESC: u16 = 1024;
21-
pub const DEFAULT_RX_POOL_SIZE: usize = 8192;
22-
pub const DEFAULT_RX_PER_CORE_CACHE: usize = 0;
23-
pub const DEFAULT_PACKET_DATA_LENGTH: usize = 2048;
19+
pub const DEFAULT_TX_DESC: u16 = 4096;
20+
pub const DEFAULT_RX_DESC: u16 = 4096;
21+
pub const DEFAULT_RX_PER_CORE_CACHE: usize = 256;
22+
pub const DEFAULT_RX_POOL_SIZE: usize = DEFAULT_TX_DESC as usize + DEFAULT_RX_DESC as usize +
23+
DEFAULT_RX_BURST + DEFAULT_RX_PER_CORE_CACHE;
24+
pub const DEFAULT_PACKET_DATA_LENGTH: usize = 2048 + 128;
2425
pub const DEFAULT_PROMISC: bool = true;
2526
pub const DEFAULT_RX_BURST: usize = 32;
2627
pub const DEFAULT_TX_BURST: usize = 32;

l2fwd/src/main.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use anyhow::Context;
2-
use dpdk::arrayvec::{self, ArrayVec};
2+
use dpdk::arrayvec::ArrayVec;
33
use dpdk::eal::{self, Eal, LCoreId, Port, TxQ};
44
use dpdk::tx_buffer::TxBuffer;
55
use log::{info, warn};
66
use smoltcp::wire::{EthernetAddress, EthernetFrame};
77
use structopt::StructOpt;
88

99
use dpdk::eal::EalGlobalApi;
10-
use std::cell::Cell;
1110
use std::env;
1211

1312
mod utils;
@@ -187,21 +186,18 @@ fn forward_loop(eal: &Eal, lcore: LCoreId, fwds: Vec<ForwardDesc>) {
187186
let mut prev_tsc = 0;
188187
let drain_tsc = (eal.get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US;
189188

190-
let sent = Cell::new(0);
191-
let dropped = Cell::new(0);
189+
let mut _sent = 0;
190+
let mut _dropped = 0;
192191
let mut _recv = 0;
193-
let handle_tx_res =
194-
|(sent_cnt, dropped_pkts): (usize, Option<arrayvec::Drain<'_, _, MAX_PKT_BURST>>)| {
195-
sent.set(sent.get() + sent_cnt);
196-
dropped.set(dropped.get() + dropped_pkts.map_or(0, |d| d.len()));
197-
};
198192

199193
loop {
200194
let cur_tsc = eal.get_tsc_cycles();
201195
let diff_tsc = cur_tsc - prev_tsc;
202196
if diff_tsc > drain_tsc {
203197
for (dst, tx_buf) in itertools::izip!(&mut dsts, &mut tx_bufs) {
204-
handle_tx_res(tx_buf.flush(dst));
198+
let (cur_sent, cur_dropped_iter) = tx_buf.flush(dst);
199+
_sent += cur_sent;
200+
_dropped += cur_dropped_iter.map_or(0, |d| d.len());
205201
}
206202
prev_tsc = cur_tsc;
207203
}
@@ -223,7 +219,9 @@ fn forward_loop(eal: &Eal, lcore: LCoreId, fwds: Vec<ForwardDesc>) {
223219
// flush, but in the current implementation we can't do it
224220
// because we have common prev_tsc for all fwds handled by
225221
// this lcore.
226-
handle_tx_res(tx_buf.tx(dst, pkt));
222+
let (cur_sent, cur_dropped_iter) = tx_buf.tx(dst, pkt);
223+
_sent += cur_sent;
224+
_dropped += cur_dropped_iter.map_or(0, |d| d.len());
227225
}
228226
}
229227
}

0 commit comments

Comments
 (0)