Skip to content

Commit b5140b2

Browse files
zhaofengliarkivm
authored andcommitted
maglev: More optimizations
1 parent fd162b8 commit b5140b2

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

sys/driver/ixgbe/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ panic = "abort"
1515
[profile.release]
1616
panic = "abort"
1717
debug = true
18+
lto = true
1819

1920
[dependencies]
2021
syscalls = { path = "../../../sys/interfaces/syscalls", version = "0.1.0" }

sys/lib/libbenchnet/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ rref = { path = "../rref", version = "0.1.0" }
1616
usr = { path = "../../../sys/interfaces/usr", version = "0.1.0" }
1717
console = { path = "../console", version = "0.1.0" }
1818
hashbrown = "0.7.2"
19-
2019
sashstore-redleaf = { path = "../sashstore" }
2120

2221
[dependencies.fnv]

sys/lib/libbenchnet/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,9 +1080,15 @@ pub fn run_maglev_fwd_udptest_rref(net: &dyn Net, pkt_len: usize) -> Result<()>
10801080

10811081
/*
10821082
if let Some(_) = backend {
1083+
/*
10831084
for i in 0..6 {
10841085
(pkt).swap(i, 6 + i);
10851086
}
1087+
*/
1088+
unsafe {
1089+
ptr::copy(our_mac.as_ptr(), pkt.as_mut_ptr().offset(6), our_mac.capacity());
1090+
ptr::copy(sender_mac.as_ptr(), pkt.as_mut_ptr().offset(0), sender_mac.capacity());
1091+
}
10861092
}
10871093
*/
10881094
unsafe {
@@ -1134,8 +1140,6 @@ pub fn run_maglev_fwd_udptest_rref(net: &dyn Net, pkt_len: usize) -> Result<()>
11341140

11351141
let adj_runtime = elapsed as f64 / CPU_MHZ as f64;
11361142

1137-
maglev.dump_stats();
1138-
11391143
if sum > 0 && fwd_sum > 0 {
11401144
println!("runtime: {:.2} seconds", adj_runtime);
11411145

@@ -1171,6 +1175,8 @@ pub fn run_maglev_fwd_udptest_rref(net: &dyn Net, pkt_len: usize) -> Result<()>
11711175
print_hist!(submit_tx_hist);
11721176

11731177
println!("+++++++++++++++++++++++++++++++++++++++++++++++++");
1178+
maglev.dump_stats();
1179+
11741180
Ok(())
11751181
}
11761182

sys/lib/libbenchnet/src/maglev.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,24 @@ use core::default::Default;
3131

3232
use hashbrown::HashMap;
3333
use sashstore_redleaf::indexmap::Index;
34-
3534
use console::println;
3635

3736
const TABLE_SIZE: usize = 65537;
38-
const CACHE_SIZE: usize = 1 << 24;
37+
const CACHE_SIZE: usize = 1 << 21;
3938

4039
static mut HIT_COUNT: usize = 0;
4140
static mut HASHMAP_TOTAL: usize = 0;
4241

42+
/*
43+
lut (consistent hashing), cache (connection tracking)
44+
45+
- receive the packet
46+
- generate flowhash from 5-tuple
47+
- lookup in cache
48+
- if found in cache: just return
49+
- if not found: (lut[hash] -> backend number) and insert into cache
50+
*/
51+
4352
type FnvHashFactory = BuildHasherDefault<FnvHasher>;
4453
type XxHashFactory = BuildHasherDefault<XxHash>;
4554

sys/lib/libbenchnet/src/packettool.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,53 @@ pub fn fix_udp_checksum(frame: &mut [u8]) {
5656
frame[ETH_HEADER_LEN + v4len + UDP_CHECKSUM_OFFSET + 1] = 0;
5757
}
5858

59+
#[inline(always)]
60+
fn fnv_a(data: &[u8], state: &mut u64) {
61+
for byte in data.iter() {
62+
*state *= 0x100000001b3;
63+
*state ^= u64::from(*byte);
64+
}
65+
}
66+
5967
pub fn get_flowhash(frame: &[u8]) -> Option<usize> {
6068
// Ugly but fast (supposedly)
61-
let h1f: BuildHasherDefault<FnvHasher> = Default::default();
62-
let mut h1 = h1f.build_hasher();
69+
// let h1f: BuildHasherDefault<FnvHasher> = Default::default();
70+
// let mut h1 = h1f.build_hasher();
71+
let mut state: u64 = 0xcbf29ce484222325;
6372

73+
/*
6474
if frame[ETH_HEADER_LEN] >> 4 != 4 {
6575
// This shitty implementation can only handle IPv4 :(
6676
return None
6777
}
78+
*/
6879

6980
// Length of IPv4 header
7081
let v4len = (frame[ETH_HEADER_LEN] & 0b1111) as usize * 4;
7182

7283
// Hash source/destination IP addresses
73-
frame[(ETH_HEADER_LEN + IPV4_SRCDST_OFFSET)..(ETH_HEADER_LEN + IPV4_SRCDST_OFFSET + IPV4_SRCDST_LEN)].hash(&mut h1);
84+
fnv_a(&frame[(ETH_HEADER_LEN + IPV4_SRCDST_OFFSET)..(ETH_HEADER_LEN + IPV4_SRCDST_OFFSET + IPV4_SRCDST_LEN)], &mut state);
85+
// frame[(ETH_HEADER_LEN + IPV4_SRCDST_OFFSET)..(ETH_HEADER_LEN + IPV4_SRCDST_OFFSET + IPV4_SRCDST_LEN)].hash(&mut h1);
7486

7587
// Hash IP protocol number
7688
let proto = frame[ETH_HEADER_LEN + IPV4_PROTO_OFFSET];
89+
/*
7790
if proto != 6 && proto != 17 {
7891
// This shitty implementation can only handle TCP and UDP
7992
return None;
8093
}
81-
proto.hash(&mut h1);
94+
*/
95+
state *= 0x100000001b3;
96+
state ^= u64::from(proto);
97+
98+
// proto.hash(&mut h1);
8299

83100
// Hash source/destination port
84-
frame[(ETH_HEADER_LEN + v4len)..(ETH_HEADER_LEN + v4len + 4)].hash(&mut h1);
101+
fnv_a(&frame[(ETH_HEADER_LEN + v4len)..(ETH_HEADER_LEN + v4len + 4)], &mut state);
102+
// frame[(ETH_HEADER_LEN + v4len)..(ETH_HEADER_LEN + v4len + 4)].hash(&mut h1);
85103

86-
Some(h1.finish() as usize)
104+
// Some(h1.finish() as usize)
105+
Some(state as usize)
87106
}
88107

89108
pub fn get_mut_udp_payload(frame: &mut [u8]) -> Option<(usize, &mut [u8])> {

0 commit comments

Comments
 (0)