Skip to content

Commit 161cd08

Browse files
committed
fix: performance improved
1 parent 50af6e6 commit 161cd08

5 files changed

Lines changed: 13 additions & 91 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ cargo_metadata = { version = "0.23.1", default-features = false }
1717
log = { version = "0.4.28", default-features = false }
1818
which = { version = "8.0.0", features=["real-sys"], default-features = false }
1919

20+
[profile.release]
21+
lto = "fat"
22+
codegen-units = 1
23+
strip = "symbols"
24+
panic = "abort"
25+
opt-level = 3
26+
2027
[profile.release.package.snoopy-ebpf]
2128
debug = 2
2229
codegen-units = 1

snoopy-ebpf/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ pub fn update_xdp_ingress(ctx: XdpContext) -> u32 {
7575

7676
#[inline]
7777
fn try_update_xdp_ingress(ctx: &XdpContext) -> Result<(), &'static str> {
78-
let data = ctx.data() as u64;
79-
let data_end = ctx.data_end() as u64;
80-
let metadata = ctx.metadata() as u64;
81-
let metadata_end = ctx.metadata_end() as u64;
82-
let bytes = (data_end - data) + (metadata_end - metadata);
78+
// On-wire bytes only — XDP metadata (bpf_xdp_adjust_meta region) is driver/HW
79+
// scratch space, not part of the packet, so omit it to match the TC variant
80+
// which uses ctx.len().
81+
let bytes = ctx.data_end() as u64 - ctx.data() as u64;
8382

8483
let counter = INGRESS_COUNTER
8584
.get_ptr_mut(0)

snoopy/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ aya = { workspace = true }
99
aya-log = { workspace = true }
1010
clap = { version = "4.5.53", features = ["derive"] }
1111
env_logger = { version = "0.11.8", default-features = false }
12-
human_bytes = "0.4.3"
1312
libc = { version = "0.2.177", default-features = false }
1413
log = { workspace = true }
1514
pnet = { version = "0.35.0", features = ["serde"] }
1615
serde = { version = "1.0.228", features = ["derive"] }
1716
serde_json = "1.0.145"
1817
serde_with = "3.16.0"
19-
tokio = { version = "1.48.0", features = ["full"] }
18+
tokio = { version = "1.48.0", default-features = false, features = ["macros", "rt", "time", "sync", "net"] }
2019

2120
[build-dependencies]
2221
anyhow = { workspace = true }

snoopy/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Arguments {
4141
pub metrics_rate: u64,
4242
}
4343

44-
#[tokio::main(worker_threads = 2)]
44+
#[tokio::main(flavor = "current_thread")]
4545
async fn main() -> anyhow::Result<()> {
4646
if std::env::var("RUST_LOG").is_err() {
4747
unsafe {

0 commit comments

Comments
 (0)