Skip to content

Commit

Permalink
Implement cleanup logic to restore CPU cores on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
voioo committed Jan 5, 2025
1 parent b7de431 commit 0ff18dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/core/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,20 @@ impl CoreManager {
Ok(())
}
}

impl Drop for CoreManager {
fn drop(&mut self) {
info!("Cleaning up - restoring all cores...");

let available_cores = Self::get_available_cores();
for core_num in available_cores.iter().skip(1) {
let online_path = format!("/sys/devices/system/cpu/cpu{}/online", core_num);
match fs::write(&online_path, "1") {
Ok(_) => debug!("Enabled core {} during cleanup", core_num),
Err(e) => error!("Failed to enable core {} during cleanup: {}", core_num, e),
}
}

info!("Cleanup complete - all cores should be enabled");
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let running = Arc::new(AtomicBool::new(true));
let r = running.clone();
ctrlc::set_handler(move || {
println!("Ctrl+C received, restoring cores and shutting down...");
info!("Shutdown signal received, initiating cleanup...");
r.store(false, Ordering::SeqCst);
})?;

Expand Down

0 comments on commit 0ff18dd

Please sign in to comment.