提交 dd5516e9 编写于 作者: H hustccc

update main.rs

上级 dc5aa526
......@@ -107,167 +107,235 @@ fn main() -> ! {
// }
let workload = workload.join(url2path(repo_url));
// enter XiangShan and make init
{
let stdout_f = workload.join("stdout.txt");
let stderr_f = workload.join("stderr.txt");
let mut make = Make::new("make");
make.set_args(vec!["init"]);
match make.set_workdir(workload.to_str()) {
Ok(_) => {}, // do nothing
Err(make_err) => {
log::error!("{}, thread {} exit", make_err.as_str(), thread_id::get());
// TODO: specify exit code
exit(-1);
}
}
match make.excute(stdout_f.to_str(), stderr_f.to_str()) {
Ok(exit_code) => {
log::info!("make with args: {:?} excute return {}", make.get_args(), exit_code);
if exit_code != 0 {
log::error!("exit not zero, thread {} exit.", thread_id::get());
exit(-1);
}
},
Err(make_err) => {
log::error!("{}, thread {} exit.", make_err.as_str(), thread_id::get());
// TODO: specify exit code
match Make::init(workload.to_str()) {
Ok(exit_code) => {
log::info!("make init in {:?} exit with {}", workload, exit_code);
if exit_code != 0 {
log::error!("exit code not zero, thread {} exit.", thread_id::get());
exit(-1);
}
},
Err(err_code) => {
log::error!("make init in {:?} error with {}, thread {} exit.", workload, err_code, thread_id::get());
exit(-1);
}
// make drop here
}
// make emu
{
let stdout_f = workload.join("stdout.txt");
let stderr_f = workload.join("stderr.txt");
let mut make = Make::new("numactl");
make.set_args(vec!["-C", "0-63", "make", "build/emu", "EMU_TARCE=1", "SIM_ARGS=\"--disable-all\"", "EMU_THREADS=8", "-j64"]);
match make.set_workdir(workload.to_str()) {
Ok(_) => {}, // do nothing
Err(make_err) => {
log::error!("{}, thread {} exit", make_err.as_str(), thread_id::get());
// TODO: specify exit code
exit(-1);
}
}
make.exe.env("NEMU_HOME", NEMU_HOME);
make.exe.env("AM_HOME", AM_HOME);
match make.excute(stdout_f.to_str(), stderr_f.to_str()) {
Ok(exit_code) => {
log::info!("make with args: {:?} excute return {}", make.get_args(), exit_code);
if exit_code != 0 {
log::error!("exit not zero, thread {} exit.", thread_id::get());
exit(-1);
}
},
Err(make_err) => {
log::error!("{}, thread {} exit.", make_err.as_str(), thread_id::get());
// TODO: specify exit code
// {
// let stdout_f = workload.join("stdout.txt");
// let stderr_f = workload.join("stderr.txt");
// let mut make = Make::new("make");
// make.set_args(vec!["init"]);
// match make.set_workdir(workload.to_str()) {
// Ok(_) => {}, // do nothing
// Err(make_err) => {
// log::error!("{}, thread {} exit", make_err.as_str(), thread_id::get());
// // TODO: specify exit code
// exit(-1);
// }
// }
// match make.excute(stdout_f.to_str(), stderr_f.to_str()) {
// Ok(exit_code) => {
// log::info!("make with args: {:?} excute return {}", make.get_args(), exit_code);
// if exit_code != 0 {
// log::error!("exit not zero, thread {} exit.", thread_id::get());
// exit(-1);
// }
// },
// Err(make_err) => {
// log::error!("{}, thread {} exit.", make_err.as_str(), thread_id::get());
// // TODO: specify exit code
// exit(-1);
// }
// }
// // make drop here
// }
// numatcl -C 0-255 make build/emu EMU_TRACE=1 SIM_ARGS="--disable-all" EMU_THREADS=8 -j256
match Numactl::make_emu(workload.to_str(), NEMU_HOME, AM_HOME) {
Ok(exit_code) => {
log::info!("make emu in {:?} exit with {}", workload, exit_code);
if exit_code != 0 {
log::error!("exit code not zero, thread {} exit.", thread_id::get());
exit(-1);
}
},
Err(err_code) => {
log::error!("make emu in {:?} error with {}, thread {} exit.", workload, err_code, thread_id::get());
exit(-1);
}
// make drop here
}
// {
// let stdout_f = workload.join("stdout.txt");
// let stderr_f = workload.join("stderr.txt");
// let mut make = Make::new("numactl");
// make.set_args(vec!["-C", "0-255", "make", "build/emu", "EMU_TARCE=1", "SIM_ARGS=\"--disable-all\"", "EMU_THREADS=8", "-j256"]);
// match make.set_workdir(workload.to_str()) {
// Ok(_) => {}, // do nothing
// Err(make_err) => {
// log::error!("{}, thread {} exit", make_err.as_str(), thread_id::get());
// // TODO: specify exit code
// exit(-1);
// }
// }
// make.exe.env("NEMU_HOME", NEMU_HOME);
// make.exe.env("AM_HOME", AM_HOME);
// match make.excute(stdout_f.to_str(), stderr_f.to_str()) {
// Ok(exit_code) => {
// log::info!("make with args: {:?} excute return {}", make.get_args(), exit_code);
// if exit_code != 0 {
// log::error!("exit not zero, thread {} exit.", thread_id::get());
// exit(-1);
// }
// },
// Err(make_err) => {
// log::error!("{}, thread {} exit.", make_err.as_str(), thread_id::get());
// // TODO: specify exit code
// exit(-1);
// }
// }
// // make drop here
// }
// create ../emu_res dir &&
// numactl -C [] emu -I 1000000 -i /bigdata/zyy/checkpoints_profiles/betapoint_profile_06/gcc_200/0/_8000000000_.gz
let res_dir = workload.join("../emu_res");
{
if !res_dir.exists() {
match fs::create_dir_all(res_dir.as_path()) {
Ok(_) => {}, // do nothing
Err(msg) => {
log::error!("Failed in creating res_dir {:?} with msg
{} , thread {} exit.", res_dir, msg, thread_id::get());
// TODO: specify exit code
exit(-1);
},
}
}
let stdout_f = res_dir.join("stdout.txt");
let stderr_f = res_dir.join("stderr.txt");
let emu_path = workload.join("./build/emu");
let emu = if let Some(path) = emu_path.to_str() {
log::info!("create emu in {}", path);
path
} else {
log::error!("no path in emu_path, thread {} exit", thread_id::get());
exit(-1);
};
let mut cpu_percent_collector = match psutil::cpu::CpuPercentCollector::new() {
Ok(collector) => collector,
Err(_) => {
log::error!("new CpuPercentCollector error, thread {} exit.", thread_id::get());
exit(-1);
}
};
let mut numactl = Numactl::new("numactl");
let cpu_percents = match cpu_percent_collector.cpu_percent_percpu() {
Ok(percents) => percents,
Err(_) => {
log::error!("get cpu_percent_percpu error, thread {} exit.", thread_id::get());
exit(-1);
}
};
let (mut begin, mut end) = (0, 0);
let mut count = 0;
for _ in 0..3 {
begin = 0;
end = 0;
for i in 0..cpu_percents.len() {
if cpu_percents[i] > 50.0 {
begin += 1;
end = begin;
} else {
end += 1;
}
if (end - begin) >= 7 {
// found 8 free cpus, break
break;
}
}
if (end - begin) >= 7 {
log::info!("found avaiable 8 cpus, ready to run emu.");
break;
}
count += 1;
thread::sleep(Duration::from_secs(SLEEP_TIME * 100));
}
if count >= 3 {
log::error!("no 8 cpus avaiable, thread {} exit.", thread_id::get());
exit(-1);
}
let mut cpu_ids = begin.to_string();
cpu_ids.push_str("-");
cpu_ids.push_str(end.to_string().as_str());
log::info!("avaiable cpus: {}", cpu_ids);
numactl.set_args(vec!["-C", cpu_ids.as_str(), emu, "-I", "1000000", "-i", EMU_TARGET]);
match numactl.set_workdir(workload.to_str()) {
if !res_dir.exists() {
match fs::create_dir_all(res_dir.as_path()) {
Ok(_) => {}, // do nothing
Err(emu_err) => {
log::error!("{}, thread {} exit", emu_err.as_str(), thread_id::get());
Err(msg) => {
log::error!("Failed in creating res_dir {:?} with msg
{} , thread {} exit.", res_dir, msg, thread_id::get());
// TODO: specify exit code
exit(-1);
}
},
}
// set env `NOOP_HOME` to currnet workload
numactl.exe.env("NOOP_HOME", workload.to_path_buf());
numactl.exe.env("NEMU_HOME", NEMU_HOME);
numactl.exe.env("AM_HOME", AM_HOME);
match numactl.excute(stdout_f.to_str(), stderr_f.to_str()) {
}
let stdout_f = res_dir.join("stdout.txt");
let stderr_f = res_dir.join("stderr.txt");
let emu_path = workload.join("./build/emu");
let emu = if let Some(path) = emu_path.to_str() {
log::info!("create emu in {}", path);
path
} else {
log::error!("no path in emu_path, thread {} exit", thread_id::get());
exit(-1);
};
match Numactl::run_emu(
workload.to_str(),
stdout_f.to_str(),
stderr_f.to_str(),
emu,
EMU_TARGET,
NEMU_HOME,
AM_HOME,
8) {
Ok(exit_code) => {
log::info!("make with args: {:?} excute return {}", numactl.get_args(), exit_code);
log::info!("run emu in {:?} exit with {}", workload, exit_code);
if exit_code != 0 {
log::error!("exit not zero, thread {} exit.", thread_id::get());
log::error!("exit code not zero, thread {} exit.", thread_id::get());
exit(-1);
}
},
Err(emu_err) => {
log::error!("{}, thread {} exit.", emu_err.as_str(), thread_id::get());
// TODO: specify exit code
Err(err_code) => {
log::error!("run emu in {:?} error with {}, thread {} exit.", workload, err_code, thread_id::get());
exit(-1);
}
}
}
// {
// if !res_dir.exists() {
// match fs::create_dir_all(res_dir.as_path()) {
// Ok(_) => {}, // do nothing
// Err(msg) => {
// log::error!("Failed in creating res_dir {:?} with msg
// {} , thread {} exit.", res_dir, msg, thread_id::get());
// // TODO: specify exit code
// exit(-1);
// },
// }
// }
// let stdout_f = res_dir.join("stdout.txt");
// let stderr_f = res_dir.join("stderr.txt");
// let emu_path = workload.join("./build/emu");
// let emu = if let Some(path) = emu_path.to_str() {
// log::info!("create emu in {}", path);
// path
// } else {
// log::error!("no path in emu_path, thread {} exit", thread_id::get());
// exit(-1);
// };
// let mut cpu_percent_collector = match psutil::cpu::CpuPercentCollector::new() {
// Ok(collector) => collector,
// Err(_) => {
// log::error!("new CpuPercentCollector error, thread {} exit.", thread_id::get());
// exit(-1);
// }
// };
// let mut numactl = Numactl::new("numactl");
// let cpu_percents = match cpu_percent_collector.cpu_percent_percpu() {
// Ok(percents) => percents,
// Err(_) => {
// log::error!("get cpu_percent_percpu error, thread {} exit.", thread_id::get());
// exit(-1);
// }
// };
// let (mut begin, mut end) = (0, 0);
// let mut count = 0;
// for _ in 0..3 {
// begin = 0;
// end = 0;
// for i in 0..cpu_percents.len() {
// if cpu_percents[i] > 50.0 {
// begin += 1;
// end = begin;
// } else {
// end += 1;
// }
// if (end - begin) >= 7 {
// // found 8 free cpus, break
// break;
// }
// }
// if (end - begin) >= 7 {
// log::info!("found avaiable 8 cpus, ready to run emu.");
// break;
// }
// count += 1;
// thread::sleep(Duration::from_secs(SLEEP_TIME * 100));
// }
// if count >= 3 {
// log::error!("no 8 cpus avaiable, thread {} exit.", thread_id::get());
// exit(-1);
// }
// let mut cpu_ids = begin.to_string();
// cpu_ids.push_str("-");
// cpu_ids.push_str(end.to_string().as_str());
// log::info!("avaiable cpus: {}", cpu_ids);
// numactl.set_args(vec!["-C", cpu_ids.as_str(), emu, "-I", "1000000", "-i", EMU_TARGET]);
// match numactl.set_workdir(workload.to_str()) {
// Ok(_) => {}, // do nothing
// Err(emu_err) => {
// log::error!("{}, thread {} exit", emu_err.as_str(), thread_id::get());
// // TODO: specify exit code
// exit(-1);
// }
// }
// // set env `NOOP_HOME` to currnet workload
// numactl.exe.env("NOOP_HOME", workload.to_path_buf());
// numactl.exe.env("NEMU_HOME", NEMU_HOME);
// numactl.exe.env("AM_HOME", AM_HOME);
// match numactl.excute(stdout_f.to_str(), stderr_f.to_str()) {
// Ok(exit_code) => {
// log::info!("make with args: {:?} excute return {}", numactl.get_args(), exit_code);
// if exit_code != 0 {
// log::error!("exit not zero, thread {} exit.", thread_id::get());
// exit(-1);
// }
// },
// Err(emu_err) => {
// log::error!("{}, thread {} exit.", emu_err.as_str(), thread_id::get());
// // TODO: specify exit code
// exit(-1);
// }
// }
// }
log::info!("thread {} return 0", thread_id::get());
});
......
......@@ -9,4 +9,5 @@ edition = "2018"
[dependencies]
log = "0.4"
simple_logger = "1.11.0"
xscommand-macros = { path = "macros" }
\ No newline at end of file
xscommand-macros = { path = "macros" }
psutil = "3.2.0"
......@@ -55,10 +55,10 @@ impl<'a> Git<'a> {
}
// git log
pub fn log(stdout: &str, stderr: &str) -> Result<i32, i32> {
pub fn log(stdout: Option<&str>, stderr: Option<&str>) -> Result<i32, i32> {
let mut git = Git::new("git");
git.set_args(vec!["log"]);
match git.excute(Some(stdout), Some(stderr)) {
match git.excute(stdout, stderr) {
Ok(exit_code) => Ok(exit_code),
Err(err) => Err(err.err_code()),
}
......
......@@ -7,7 +7,7 @@ use std::{
process::{Command, Stdio}
};
use super::{XSCommand, DefaultErr};
use super::{XSCommand, XSCommandErr, DefaultErr};
use xscommand_macros::XSCommand;
/// Make XSCommand
......@@ -19,8 +19,28 @@ pub struct Make<'a> {
}
impl<'a> Make<'a> {
pub fn emu() -> i32 {
todo!()
pub fn init(workload: Option<&str>) -> Result<i32, i32> {
let mut make = Make::new("make");
make.set_args(vec!["init"]);
if let Err(err) = make.set_workdir(workload) {
return Err(err.err_code());
};
match make.excute(None, None) {
Ok(exit_code) => Ok(exit_code),
Err(err) => Err(err.err_code()),
}
}
pub fn emu(workload: Option<&str>) -> Result<i32, i32> {
let mut make = Make::new("make");
make.set_args(vec!["build/emu", "EMU_TARCE=1", "SIM_ARGS=\"--disable-all\"", "EMU_THREADS=8", "-j10"]);
if let Err(err) = make.set_workdir(workload) {
return Err(err.err_code());
};
match make.excute(None, None) {
Ok(exit_code) => Ok(exit_code),
Err(err) => Err(err.err_code()),
}
}
}
// impl<'a> XSCommand<'a, DefaultErr> for Make<'a> {
......
/// Numactl XSCommand Implementation
///
extern crate psutil;
use super::{XSCommand, DefaultErr};
use std::{
fs::File,
use super::{XSCommand, XSCommandErr, DefaultErr};
use std::{fs::File,
os::unix::io::{FromRawFd, IntoRawFd},
process::{Command, Stdio}
process::{Command, Stdio, exit},
thread,
time::Duration,
vec,
};
use xscommand_macros::XSCommand;
......@@ -17,10 +20,98 @@ pub struct Numactl<'a> {
}
impl<'a> Numactl<'a> {
pub fn make_emu() -> i32 {
todo!()
pub fn make_emu(workload: Option<&str>, nemu_home: &str, am_home: &str) -> Result<i32, i32> {
let mut numactl = Numactl::new("numactl");
numactl.set_args(vec!["-C", "0-255", "make", "build/emu", "EMU_TARCE=1", "SIM_ARGS=\"--disable-all\"", "EMU_THREADS=8", "-j256"]);
if let Err(err) = numactl.set_workdir(workload) {
return Err(err.err_code());
};
numactl.exe.env("NEMU_HOME", nemu_home);
numactl.exe.env("AM_HOME", am_home);
match numactl.excute(None, None) {
Ok(exit_code) => Ok(exit_code),
Err(err) => Err(err.err_code()),
}
}
pub fn run_emu() -> i32 {
todo!()
pub fn run_emu(
workload: Option<&str>,
stdout: Option<&str>,
stderr: Option<&str>,
emu_path: &str,
img_path: &str,
nemu_home: &str,
am_home: &str,
thread_num: usize) -> Result<i32, i32> {
let mut numactl = Numactl::new("numactl");
let mut cpu_percent_collector = match psutil::cpu::CpuPercentCollector::new() {
Ok(collector) => collector,
Err(_) => {
// TODO: specify exit code
let exit_code = -1;
log::error!("new CpuPercentCollector error, exit with {}", exit_code);
exit(exit_code);
}
};
let cpu_percents = match cpu_percent_collector.cpu_percent_percpu() {
Ok(percents) => percents,
Err(_) => {
// TODO: specify exit code
let exit_code = -1;
log::error!("get cpu_percent_percpu error, exit with {}.", exit_code);
exit(exit_code);
}
};
let (mut begin, mut end) = (0, 0);
let mut count = 0;
for _ in 0..3 {
begin = 0;
end = 0;
for i in 0..cpu_percents.len() {
if cpu_percents[i] > 50.0 {
begin += 1;
end = begin;
} else {
end += 1;
}
if (end - begin) >= (thread_num - 1) {
// found 8 free cpus, break
break;
}
}
if (end - begin) >= (thread_num - 1) {
log::info!("found avaiable 8 cpus, ready to run emu.");
break;
}
count += 1;
thread::sleep(Duration::from_secs(120));
}
if count >= 3 {
// TODO: specify exit code
let exit_code = -1;
log::error!("no {} cpus avaiable, exit with {}.", thread_num, exit_code);
exit(exit_code);
}
let mut cpu_ids = begin.to_string();
cpu_ids.push_str("-");
cpu_ids.push_str(end.to_string().as_str());
log::info!("avaiable cpus: {}", cpu_ids);
numactl.set_args(vec!["-C", cpu_ids.as_str(), emu_path, "-I", "1000000", "-i", img_path]);
if let Err(err) = numactl.set_workdir(workload) {
return Err(err.err_code());
};
if let Some(noop_home) = workload {
numactl.exe.env("NOOP_HOME", noop_home);
} else {
// TODO: specify exit code
let exit_code = -1;
log::error!("workload.to_str() return None, exit with {}.", exit_code);
exit(exit_code);
}
numactl.exe.env("NEMU_HOME", nemu_home);
numactl.exe.env("AM_HOME", am_home);
match numactl.excute(stdout, stderr) {
Ok(exit_code) => Ok(exit_code),
Err(err) => Err(err.err_code()),
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册