diff options
| author | Ralf Jung <post@ralfj.de> | 2024-04-20 09:08:09 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-04-20 09:08:09 +0200 |
| commit | cb1b4a6977cfe1149005a3131a08d0bbce456833 (patch) | |
| tree | 1f09af392c6215855c089eb90b1aab8a18cfcee8 | |
| parent | 7dcfb54dc625f4937d583d96de3dc41af73d2f17 (diff) | |
| download | rust-cb1b4a6977cfe1149005a3131a08d0bbce456833.tar.gz rust-cb1b4a6977cfe1149005a3131a08d0bbce456833.zip | |
reuse_pool: only do acquire_clock if we reused from a different thread
| -rw-r--r-- | src/tools/miri/src/alloc_addresses/mod.rs | 4 | ||||
| -rw-r--r-- | src/tools/miri/src/alloc_addresses/reuse_pool.rs | 6 | ||||
| -rw-r--r-- | src/tools/miri/src/concurrency/vector_clock.rs | 2 |
3 files changed, 8 insertions, 4 deletions
diff --git a/src/tools/miri/src/alloc_addresses/mod.rs b/src/tools/miri/src/alloc_addresses/mod.rs index d59a2cee94e..2bbb34c9a4b 100644 --- a/src/tools/miri/src/alloc_addresses/mod.rs +++ b/src/tools/miri/src/alloc_addresses/mod.rs @@ -171,7 +171,9 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { memory_kind, ecx.get_active_thread(), ) { - if let Some(data_race) = &ecx.machine.data_race { + if let Some(clock) = clock + && let Some(data_race) = &ecx.machine.data_race + { data_race.acquire_clock(&clock, ecx.get_active_thread()); } reuse_addr diff --git a/src/tools/miri/src/alloc_addresses/reuse_pool.rs b/src/tools/miri/src/alloc_addresses/reuse_pool.rs index fd0b24cc29b..77fc9f53f9e 100644 --- a/src/tools/miri/src/alloc_addresses/reuse_pool.rs +++ b/src/tools/miri/src/alloc_addresses/reuse_pool.rs @@ -78,6 +78,7 @@ impl ReusePool { subpool.insert(pos, (addr, size, thread, clock)); } + /// Returns the address to use and optionally a clock we have to synchronize with. pub fn take_addr( &mut self, rng: &mut impl Rng, @@ -85,7 +86,7 @@ impl ReusePool { align: Align, kind: MemoryKind, thread: ThreadId, - ) -> Option<(u64, VClock)> { + ) -> Option<(u64, Option<VClock>)> { // Determine whether we'll even attempt a reuse. As above, we don't do reuse for stack addresses. if kind == MemoryKind::Stack || !rng.gen_bool(self.address_reuse_rate) { return None; @@ -122,6 +123,7 @@ impl ReusePool { let (chosen_addr, chosen_size, chosen_thread, clock) = subpool.remove(idx); debug_assert!(chosen_size >= size && chosen_addr % align.bytes() == 0); debug_assert!(cross_thread_reuse || chosen_thread == thread); - Some((chosen_addr, clock)) + // No synchronization needed if we reused from the current thread. + Some((chosen_addr, if chosen_thread == thread { None } else { Some(clock) })) } } diff --git a/src/tools/miri/src/concurrency/vector_clock.rs b/src/tools/miri/src/concurrency/vector_clock.rs index fe719943dcb..0178b01e0b8 100644 --- a/src/tools/miri/src/concurrency/vector_clock.rs +++ b/src/tools/miri/src/concurrency/vector_clock.rs @@ -152,7 +152,7 @@ impl VClock { } /// Get a mutable slice to the internal vector with minimum `min_len` - /// elements, to preserve invariants this vector must modify + /// elements. To preserve invariants, the caller must modify /// the `min_len`-1 nth element to a non-zero value #[inline] fn get_mut_with_min_len(&mut self, min_len: usize) -> &mut [VTimestamp] { |
