aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2016-01-12 09:07:06 -0700
committerDavid Li <li.davidm96@gmail.com>2016-01-12 09:07:06 -0700
commit73a1c6f06224a7e892c90186ff15567e11ced31c (patch)
tree58813dcca33ba910c3e8a659b548aeb587d50364 /src
parentc1625c144872e34c4156dc67c78512094a75fd3c (diff)
Update secondary cache (if applicable) on write
Diffstat (limited to 'src')
-rw-r--r--src/shareable_cache.rs15
1 files changed, 15 insertions, 0 deletions
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)
}
}