From 007e7f9c0fbc71c789d5a551012c2f6724e25e6b Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 16 Jan 2016 10:05:46 -0700 Subject: Stop game once score reached --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- TODO.md | 2 +- src/main.rs | 24 +++++++++++++++++++++--- src/shareable_cache.rs | 1 - src/system.rs | 12 +++++++++--- 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 "] [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>, caches: Vec>>>, } impl<'a> SyscallHandler<'a> { - pub fn new(memory: SharedMemory<'a>, + pub fn new(memory: Rc>, caches: Vec>>>) -> 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) + } } -- cgit v1.2.3