Skip to content

Commit

Permalink
Tie the process to a single CPU while profiling
Browse files Browse the repository at this point in the history
To mitigate the effect of migration between big.LITTLE cores
  • Loading branch information
Javier-varez committed May 22, 2024
1 parent 6b2441e commit d9fdcd2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rusty-boy-sdl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "../README.md"

[features]
approximate = []
profile = ["nix"]

[dependencies]
cartridge = { path = "../cartridge" }
Expand All @@ -25,3 +26,4 @@ sdl2 = "0.36"
clap = { version = "4.5.4", features = ["derive"] }
env_logger = "0.11.3"
log = "0.4"
nix = { version = "0.28", features = ["sched"], optional = true }
12 changes: 12 additions & 0 deletions rusty-boy-sdl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,19 @@ fn save_file(rom_path: &Path, data: &[u8]) -> anyhow::Result<()> {
Ok(())
}

#[cfg(feature = "profile")]
fn configure_sched_affinity() -> anyhow::Result<()> {
log::info!("Setting CPU affinity");
let mut cpuset = nix::sched::CpuSet::new();
cpuset.set(0)?; // Just one cpu
nix::sched::sched_setaffinity(nix::unistd::Pid::this(), &cpuset)?;
Ok(())
}

fn main() -> anyhow::Result<()> {
#[cfg(feature = "profile")]
configure_sched_affinity()?;

env_logger::init();

let args = Args::parse();
Expand Down

0 comments on commit d9fdcd2

Please sign in to comment.