todo 0.3.1
This commit is contained in:
parent
8891623fd7
commit
a09c6a9332
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1831,7 +1831,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tswn"
|
name = "tswn"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base16384",
|
"base16384",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tswn"
|
name = "tswn"
|
||||||
description = "tool shenjack work shop namerena"
|
description = "tool shenjack work shop namerena"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
## 0.3.x
|
## 0.3.x
|
||||||
|
|
||||||
|
### 0.3.1
|
||||||
|
|
||||||
|
- 去掉了 `--bench` 选项
|
||||||
|
- 现在可以直接使用 `--core-pick` 选项来选择核心了
|
||||||
|
- 并且单线程模式下效果和 benchmark 模式下一样了
|
||||||
|
|
||||||
### 0.3.0
|
### 0.3.0
|
||||||
|
|
||||||
把 `--bench-core` 改成了 `--core-pick`
|
把 `--bench-core` 改成了 `--core-pick`
|
||||||
|
@ -40,6 +40,49 @@ pub struct CacluateConfig {
|
|||||||
pub core_affinity: Option<usize>,
|
pub core_affinity: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 启动计算的调度函数
|
||||||
|
pub fn start_main(cli_config: crate::Command, outfile: PathBuf) {
|
||||||
|
|
||||||
|
// if cli_arg.bench {
|
||||||
|
// info!("开始 benchmark");
|
||||||
|
// cli_arg.thread_count = 1;
|
||||||
|
// let mut config = cli_arg.as_cacl_config();
|
||||||
|
// config.core_affinity = Some(1 << cli_arg.pick_core);
|
||||||
|
// set_process_cores(config.core_affinity.unwrap());
|
||||||
|
// cacluate::cacl(config, 1, &out_path);
|
||||||
|
// } else {
|
||||||
|
// let mut n = 0;
|
||||||
|
// let mut cores = 0;
|
||||||
|
// if cli_arg.thread_count == 1 {
|
||||||
|
// // 单线程运行的时候也是让他放在主线程跑
|
||||||
|
// let mut config = cli_arg.as_cacl_config();
|
||||||
|
// config.core_affinity = Some(1 << cli_arg.pick_core);
|
||||||
|
// set_process_cores(config.core_affinity.unwrap());
|
||||||
|
// cacluate::cacl(config, 1, &out_path);
|
||||||
|
// } else {
|
||||||
|
// for i in 0..cli_arg.thread_count {
|
||||||
|
// n += 1;
|
||||||
|
// let mut config = cli_arg.as_cacl_config();
|
||||||
|
// // 核心亲和性: n, n+1
|
||||||
|
// config.core_affinity = Some(1 << i);
|
||||||
|
// cores |= 1 << i;
|
||||||
|
// let out_path = out_path.clone();
|
||||||
|
// let thread_name = format!("thread_{}", n);
|
||||||
|
// threads.push(std::thread::spawn(move || {
|
||||||
|
// info!("线程 {} 开始计算", thread_name);
|
||||||
|
// cacluate::cacl(config, n, &out_path);
|
||||||
|
// info!("线程 {} 结束计算", thread_name);
|
||||||
|
// }));
|
||||||
|
// }
|
||||||
|
// set_process_cores(cores);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for t in threads {
|
||||||
|
// t.join().unwrap();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) {
|
pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) {
|
||||||
// 初始猜测的时间间隔
|
// 初始猜测的时间间隔
|
||||||
|
@ -36,10 +36,7 @@ pub struct Command {
|
|||||||
/// 预期状态输出时间间隔 (秒)
|
/// 预期状态输出时间间隔 (秒)
|
||||||
#[arg(long, short = 'r', default_value_t = 10)]
|
#[arg(long, short = 'r', default_value_t = 10)]
|
||||||
pub report_interval: u64,
|
pub report_interval: u64,
|
||||||
/// Windows 下会强制单线程, 且设置线程亲和性为核心 0
|
/// 单线程模式模式下的核心亲和性核心号 (从 0 开始)
|
||||||
#[arg(long = "bench", default_value_t = false)]
|
|
||||||
pub bench: bool,
|
|
||||||
/// 单线程模式 / benchmark 模式下的核心亲和性核心号 (从 0 开始)
|
|
||||||
#[arg(long = "core-pick", default_value_t = 0)]
|
#[arg(long = "core-pick", default_value_t = 0)]
|
||||||
pub pick_core: usize,
|
pub pick_core: usize,
|
||||||
}
|
}
|
||||||
@ -54,7 +51,7 @@ impl Command {
|
|||||||
qp_expect: self.qp_expect,
|
qp_expect: self.qp_expect,
|
||||||
team: self.team.clone(),
|
team: self.team.clone(),
|
||||||
report_interval: self.report_interval,
|
report_interval: self.report_interval,
|
||||||
core_affinity: if self.bench { Some(1 << self.pick_core) } else { None },
|
core_affinity: if self.thread_count == 1 { Some(1 << self.pick_core) } else { None },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +99,6 @@ fn main() {
|
|||||||
let left = cli_arg.start % cli_arg.thread_count as u64;
|
let left = cli_arg.start % cli_arg.thread_count as u64;
|
||||||
cli_arg.end = cli_arg.end.wrapping_add(left);
|
cli_arg.end = cli_arg.end.wrapping_add(left);
|
||||||
|
|
||||||
let mut threads = vec![];
|
|
||||||
let now = chrono::Local::now().format("%Y-%m-%d_%H-%M-%S").to_string();
|
let now = chrono::Local::now().format("%Y-%m-%d_%H-%M-%S").to_string();
|
||||||
// namerena-<team>-<time>.csv
|
// namerena-<team>-<time>.csv
|
||||||
// <time>: %Y-%m-%d-%H-%M-%S
|
// <time>: %Y-%m-%d-%H-%M-%S
|
||||||
@ -112,6 +108,7 @@ fn main() {
|
|||||||
// 先创建文件夹
|
// 先创建文件夹
|
||||||
if let Err(e) = std::fs::create_dir_all(out_path.parent().unwrap()) {
|
if let Err(e) = std::fs::create_dir_all(out_path.parent().unwrap()) {
|
||||||
warn!("创建文件夹失败: {}", e);
|
warn!("创建文件夹失败: {}", e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("开始: {} 结尾: {}", cli_arg.start, cli_arg.end);
|
info!("开始: {} 结尾: {}", cli_arg.start, cli_arg.end);
|
||||||
@ -122,42 +119,6 @@ fn main() {
|
|||||||
info!("预期状态输出时间间隔: {} 秒", cli_arg.report_interval);
|
info!("预期状态输出时间间隔: {} 秒", cli_arg.report_interval);
|
||||||
info!("是否启动 benchmark 模式: {}", cli_arg.bench);
|
info!("是否启动 benchmark 模式: {}", cli_arg.bench);
|
||||||
|
|
||||||
if cli_arg.bench {
|
cacluate::start_main(cli_arg, out_path);
|
||||||
info!("开始 benchmark");
|
|
||||||
cli_arg.thread_count = 1;
|
|
||||||
let mut config = cli_arg.as_cacl_config();
|
|
||||||
config.core_affinity = Some(1 << cli_arg.pick_core);
|
|
||||||
set_process_cores(config.core_affinity.unwrap());
|
|
||||||
cacluate::cacl(config, 1, &out_path);
|
|
||||||
} else {
|
|
||||||
let mut n = 0;
|
|
||||||
let mut cores = 0;
|
|
||||||
if cli_arg.thread_count == 1 {
|
|
||||||
// 单线程运行的时候也是让他放在主线程跑
|
|
||||||
let mut config = cli_arg.as_cacl_config();
|
|
||||||
config.core_affinity = Some(1 << cli_arg.pick_core);
|
|
||||||
set_process_cores(config.core_affinity.unwrap());
|
|
||||||
cacluate::cacl(config, 1, &out_path);
|
|
||||||
} else {
|
|
||||||
for i in 0..cli_arg.thread_count {
|
|
||||||
n += 1;
|
|
||||||
let mut config = cli_arg.as_cacl_config();
|
|
||||||
// 核心亲和性: n, n+1
|
|
||||||
config.core_affinity = Some(1 << i);
|
|
||||||
cores |= 1 << i;
|
|
||||||
let out_path = out_path.clone();
|
|
||||||
let thread_name = format!("thread_{}", n);
|
|
||||||
threads.push(std::thread::spawn(move || {
|
|
||||||
info!("线程 {} 开始计算", thread_name);
|
|
||||||
cacluate::cacl(config, n, &out_path);
|
|
||||||
info!("线程 {} 结束计算", thread_name);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
set_process_cores(cores);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for t in threads {
|
|
||||||
t.join().unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user