aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml2
-rw-r--r--TODO.md2
-rw-r--r--src/main.rs24
-rw-r--r--src/shareable_cache.rs1
-rw-r--r--src/system.rs12
6 files changed, 34 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 580d37c..bf0cee2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7,7 +7,7 @@ dependencies = [
"log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustv 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustv 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -114,7 +114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustv"
-version = "0.4.1"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elfloader32 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 0136efc..b62d741 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ authors = ["David Li <li.davidm96@gmail.com>"]
[dependencies]
log = "0.3"
env_logger = "0.3"
-rustv = "0.5.0"
+rustv = "0.5.1"
docopt = "0.6"
rand = "0.3"
rustc-serialize = "0.3"
diff --git a/TODO.md b/TODO.md
index e44b042..fb685ab 100644
--- a/TODO.md
+++ b/TODO.md
@@ -30,7 +30,7 @@ https://git.lidavidm.me/cacheracer/.
## Scoring
-- [ ] Stop game once score reached
+- [x] Stop game once score reached
- [ ] Provide visualization (possibly using console?) like one used at
tournament
diff --git a/src/main.rs b/src/main.rs
index ce1f336..f4ef2cc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -138,12 +138,30 @@ fn main() {
let mut simulator = simulator::Simulator::new(
cores, memory_ref.clone(), steppable_caches, system);
- // let cycles = 0x1000000;
- let cycles = 0x50000;
+ let cycles = 0x1000000;
+ // let cycles = 0x50000;
let start = time::precise_time_s();
- simulator.run_max(cycles);
+ match simulator.run_max(cycles) {
+ simulator::HaltReason::OutOfCycles => {
+ println!("Out of cycles, halting...");
+ },
+ simulator::HaltReason::SystemHalt => {
+ println!("Team has reached payload goal, halting...");
+ },
+ simulator::HaltReason::CoresHalted => {
+ println!("All cores have stopped, halting...");
+ },
+ }
let end = time::precise_time_s();
+ for (core_id, cycles_stalled, total_cycles) in simulator.report().iter().cloned() {
+ println!("Core {}: stalled {:08} of {:08} cycles ({:.2}%)",
+ core_id,
+ cycles_stalled,
+ total_cycles,
+ 100.0 * (cycles_stalled as f32) / (total_cycles as f32));
+ }
+
println!("{} cycles in {:04} seconds ({} cycles/sec)",
cycles, end - start, (cycles as f64) / (end - start));
let (p1, p2) = memory_ref.borrow().score();
diff --git a/src/shareable_cache.rs b/src/shareable_cache.rs
index e61e907..3a2dd56 100644
--- a/src/shareable_cache.rs
+++ b/src/shareable_cache.rs
@@ -99,7 +99,6 @@ macro_rules! check_traps {
$cache.borrow_mut().$write_value($address, $value);
if num_traps_set > 0 {
- println!("Traps set: {}", num_traps_set);
match result {
Ok(()) => {
info!("[memory] core {}: {} write trap(s) set at address {:x},\
diff --git a/src/system.rs b/src/system.rs
index a69beb4..f0f3095 100644
--- a/src/system.rs
+++ b/src/system.rs
@@ -3,20 +3,21 @@ use std::cell::RefCell;
use std::rc::Rc;
use rustv::isa;
-use rustv::memory::{Mmu, SharedMemory};
+use rustv::memory::{MemoryInterface, Mmu};
use rustv::register_file::RegisterFile;
use rustv::syscall;
use rustv::trap::Trap;
+use memory_tracker::MemoryTracker;
use shareable_cache::ShareableCache;
pub struct SyscallHandler<'a> {
- memory: SharedMemory<'a>,
+ memory: Rc<RefCell<MemoryTracker>>,
caches: Vec<Rc<RefCell<ShareableCache<'a>>>>,
}
impl<'a> SyscallHandler<'a> {
- pub fn new(memory: SharedMemory<'a>,
+ pub fn new(memory: Rc<RefCell<MemoryTracker>>,
caches: Vec<Rc<RefCell<ShareableCache<'a>>>>)
-> SyscallHandler<'a> {
SyscallHandler {
@@ -93,4 +94,9 @@ impl<'a> syscall::SyscallHandler for SyscallHandler<'a> {
}
}
}
+
+ fn should_halt(&self) -> bool {
+ let (p1, p2) = self.memory.borrow().score();
+ (p1 >= 0x1000000) || (p2 >= 0x1000000)
+ }
}