From 73a1c6f06224a7e892c90186ff15567e11ced31c Mon Sep 17 00:00:00 2001 From: David Li Date: Tue, 12 Jan 2016 09:07:06 -0700 Subject: Update secondary cache (if applicable) on write --- src/shareable_cache.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/shareable_cache.rs b/src/shareable_cache.rs index 9f558cd..9e0725a 100644 --- a/src/shareable_cache.rs +++ b/src/shareable_cache.rs @@ -45,6 +45,16 @@ impl<'a> ShareableCache<'a> { (primary_accessible, secondary_accessible) } + + fn snoop(cache: &mut SharedMemory<'a>, + address: isa::Address, value: isa::Word) { + // Cache snooping: update all cache lines when a write is made + if cache.borrow().is_address_accessible(address) { + // Depends on invariant: write_word completes instantly + // when the address is accessible (in-cache) + cache.borrow_mut().write_word(address, value); + } + } } impl<'a> MemoryInterface for ShareableCache<'a> { @@ -97,22 +107,27 @@ impl<'a> MemoryInterface for ShareableCache<'a> { self.address_accessible(address); if primary_accessible { + ShareableCache::snoop(&mut self.secondary, address, value); self.primary.borrow_mut().write_word(address, value) } else if secondary_accessible { + ShareableCache::snoop(&mut self.primary, address, value); self.secondary.borrow_mut().write_word(address, value) } else { self.use_secondary = !self.use_secondary; if self.use_secondary { + ShareableCache::snoop(&mut self.primary, address, value); self.secondary.borrow_mut().write_word(address, value) } else { + ShareableCache::snoop(&mut self.secondary, address, value); self.primary.borrow_mut().write_word(address, value) } } } else { + ShareableCache::snoop(&mut self.secondary, address, value); self.primary.borrow_mut().write_word(address, value) } } -- cgit v1.2.3