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 --- src/main.rs | 24 +++++++++++++++++++++--- src/shareable_cache.rs | 1 - src/system.rs | 12 +++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src') 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