diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7e001c454c158a38343f60174ed2024f9a2c232d..8a3becd911ca237aa181267efa334e2639c22266 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -129,3 +129,5 @@ jobs: run: cd frontends/sdl && cargo run --release -- --headless --cycles 10000000 - name: Run benchmark run: cd frontends/sdl && cargo run --release -- --benchmark + - name: Run benchmark, only for CPU + run: cd frontends/sdl && cargo run --release -- --benchmark --cpu-only diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs index ccba9557a9d38279a15a292f56e34a4da5663d44..276782a837c019fc184b10209d8c9ed3743fddac 100644 --- a/frontends/sdl/src/main.rs +++ b/frontends/sdl/src/main.rs @@ -40,17 +40,22 @@ const VOLUME: f32 = 64.0; pub struct Benchmark { count: usize, chunk_size: Option<usize>, + cpu_only: Option<bool>, } impl Benchmark { - pub fn new(count: usize, chunk_size: Option<usize>) -> Self { - Self { count, chunk_size } + pub fn new(count: usize, cpu_only: Option<bool>, chunk_size: Option<usize>) -> Self { + Self { + count, + cpu_only, + chunk_size, + } } } impl Default for Benchmark { fn default() -> Self { - Self::new(50000000, None) + Self::new(50000000, None, None) } } @@ -221,13 +226,18 @@ impl Emulator { self.load_rom(None); } - pub fn benchmark(&mut self, params: Benchmark) { + pub fn benchmark(&mut self, params: &Benchmark) { println!("Going to run benchmark..."); let count = params.count; let chunk_size = params.chunk_size.unwrap_or(1); + let cpu_only = params.cpu_only.unwrap_or(false); let mut cycles = 0u64; + if cpu_only { + self.system.set_all_enabled(false); + } + let initial = SystemTime::now(); if chunk_size > 1 { @@ -320,7 +330,7 @@ impl Emulator { Event::KeyDown { keycode: Some(Keycode::B), .. - } => self.benchmark(Benchmark::default()), + } => self.benchmark(&Benchmark::default()), Event::KeyDown { keycode: Some(Keycode::T), .. @@ -491,11 +501,16 @@ impl Emulator { } } - pub fn run_benchmark(&mut self, params: Benchmark) { + pub fn run_benchmark(&mut self, params: &Benchmark) { let count = params.count; let chunk_size = params.chunk_size.unwrap_or(1); + let cpu_only = params.cpu_only.unwrap_or(false); let mut cycles = 0u64; + if cpu_only { + self.system.set_all_enabled(false); + } + let initial = SystemTime::now(); if chunk_size > 1 { @@ -640,6 +655,16 @@ struct Args { )] benchmark: bool, + #[arg( + long, + default_value_t = 500000000, + help = "The size of the benchmark in clock ticks" + )] + bench_count: usize, + + #[arg(long, default_value_t = false, help = "Run benchmark only for the CPU")] + cpu_only: bool, + #[arg( long, default_value_t = false, @@ -711,7 +736,7 @@ fn main() { // not and runs it accordingly, note that if running in headless // mode the number of cycles to be run may be specified if args.benchmark { - emulator.run_benchmark(Benchmark::new(500000000, None)); + emulator.run_benchmark(&Benchmark::new(args.bench_count, Some(args.cpu_only), None)); } else if args.headless { emulator.run_headless(if args.cycles > 0 { Some(args.cycles) diff --git a/src/gb.rs b/src/gb.rs index 437c5ecebade820779474da41c22b5a562a6eff8..7b18a41fdc68b5947b2078d4ece2b4d58edd79ff 100644 --- a/src/gb.rs +++ b/src/gb.rs @@ -775,6 +775,14 @@ impl GameBoy { (*self.gbc).borrow_mut().set_serial_enabled(value); } + pub fn set_all_enabled(&mut self, value: bool) { + self.set_ppu_enabled(value); + self.set_apu_enabled(value); + self.set_dma_enabled(value); + self.set_timer_enabled(value); + self.set_serial_enabled(value); + } + pub fn clock_freq(&self) -> u32 { self.clock_freq }