Skip to content

Commit

Permalink
DEBUG: put acquire/release on all dedup atomics
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Jan 21, 2022
1 parent 29d27b9 commit 813e526
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions perf/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,14 @@ impl Deduper {
let now = Instant::now();
//this should reset every 500k unique packets per 1m sized deduper
//false positive rate is 1/1000 at that point
let saturated = self.saturated.load(Ordering::Relaxed);
let saturated = self.saturated.load(Ordering::Acquire);
if saturated || now.duration_since(self.age) > self.max_age {
for i in &self.filter {
i.store(0, Ordering::Relaxed);
i.store(0, Ordering::Release);
}
self.seed = thread_rng().gen();
self.age = now;
self.saturated.store(false, Ordering::Relaxed);
self.saturated.store(false, Ordering::Release);
}
}

Expand All @@ -471,11 +471,11 @@ impl Deduper {
let len = self.filter.len();
let pos = (usize::try_from(hash).unwrap()).wrapping_rem(len);
// saturate each position with or
let prev = self.filter[pos].fetch_or(hash, Ordering::Relaxed);
let prev = self.filter[pos].fetch_or(hash, Ordering::AcqRel);
if prev == u64::MAX {
self.saturated.store(true, Ordering::Relaxed);
self.saturated.store(true, Ordering::Release);
//reset this value
self.filter[pos].store(hash, Ordering::Relaxed);
self.filter[pos].store(hash, Ordering::Release);
}
if hash == prev & hash {
packet.meta.set_discard(true);
Expand Down Expand Up @@ -1361,7 +1361,7 @@ mod tests {
assert_eq!(discard, 0);
filter.reset();
for i in filter.filter {
assert_eq!(i.load(Ordering::Relaxed), 0);
assert_eq!(i.load(Ordering::Acquire), 0);
}
}

Expand All @@ -1370,17 +1370,17 @@ mod tests {
fn test_dedup_saturated() {
let filter = Deduper::new(1_000_000, 0);
let mut discard = 0;
assert!(!filter.saturated.load(Ordering::Relaxed));
assert!(!filter.saturated.load(Ordering::Acquire));
for i in 0..1000 {
let mut batches =
to_packet_batches(&(0..1000).map(|_| test_tx()).collect::<Vec<_>>(), 128);
discard += filter.dedup_packets(&mut batches) as usize;
println!("{} {}", i, discard);
if filter.saturated.load(Ordering::Relaxed) {
if filter.saturated.load(Ordering::Acquire) {
break;
}
}
assert!(filter.saturated.load(Ordering::Relaxed));
assert!(filter.saturated.load(Ordering::Acquire));
}

#[test]
Expand Down

0 comments on commit 813e526

Please sign in to comment.