reuse_pool: only do acquire_clock if we reused from a different thread

This commit is contained in:
Ralf Jung 2024-04-20 09:08:09 +02:00
parent 7dcfb54dc6
commit cb1b4a6977
3 changed files with 8 additions and 4 deletions

View File

@ -171,7 +171,9 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
memory_kind, memory_kind,
ecx.get_active_thread(), 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()); data_race.acquire_clock(&clock, ecx.get_active_thread());
} }
reuse_addr reuse_addr

View File

@ -78,6 +78,7 @@ impl ReusePool {
subpool.insert(pos, (addr, size, thread, clock)); 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( pub fn take_addr(
&mut self, &mut self,
rng: &mut impl Rng, rng: &mut impl Rng,
@ -85,7 +86,7 @@ impl ReusePool {
align: Align, align: Align,
kind: MemoryKind, kind: MemoryKind,
thread: ThreadId, 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. // 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) { if kind == MemoryKind::Stack || !rng.gen_bool(self.address_reuse_rate) {
return None; return None;
@ -122,6 +123,7 @@ impl ReusePool {
let (chosen_addr, chosen_size, chosen_thread, clock) = subpool.remove(idx); let (chosen_addr, chosen_size, chosen_thread, clock) = subpool.remove(idx);
debug_assert!(chosen_size >= size && chosen_addr % align.bytes() == 0); debug_assert!(chosen_size >= size && chosen_addr % align.bytes() == 0);
debug_assert!(cross_thread_reuse || chosen_thread == thread); 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) }))
} }
} }

View File

@ -152,7 +152,7 @@ impl VClock {
} }
/// Get a mutable slice to the internal vector with minimum `min_len` /// 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 /// the `min_len`-1 nth element to a non-zero value
#[inline] #[inline]
fn get_mut_with_min_len(&mut self, min_len: usize) -> &mut [VTimestamp] { fn get_mut_with_min_len(&mut self, min_len: usize) -> &mut [VTimestamp] {