diff --git a/Cargo.lock b/Cargo.lock index fdd8a7a..f98657a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1831,7 +1831,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tswn" -version = "0.3.0" +version = "0.3.1" dependencies = [ "base16384", "chrono", diff --git a/miner/Cargo.toml b/miner/Cargo.toml index c6b9701..ac864cc 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tswn" description = "tool shenjack work shop namerena" -version = "0.3.0" +version = "0.3.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/miner/docs/updates.md b/miner/docs/updates.md index ea5cc00..0ffe6e6 100644 --- a/miner/docs/updates.md +++ b/miner/docs/updates.md @@ -2,6 +2,12 @@ ## 0.3.x +### 0.3.1 + +- 去掉了 `--bench` 选项 +- 现在可以直接使用 `--core-pick` 选项来选择核心了 +- 并且单线程模式下效果和 benchmark 模式下一样了 + ### 0.3.0 把 `--bench-core` 改成了 `--core-pick` diff --git a/miner/src/cacluate.rs b/miner/src/cacluate.rs index 8aa66d6..fe15ed5 100644 --- a/miner/src/cacluate.rs +++ b/miner/src/cacluate.rs @@ -40,6 +40,49 @@ pub struct CacluateConfig { pub core_affinity: Option, } +/// 启动计算的调度函数 +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)] pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) { // 初始猜测的时间间隔 diff --git a/miner/src/main.rs b/miner/src/main.rs index 8c5a7aa..1923eab 100644 --- a/miner/src/main.rs +++ b/miner/src/main.rs @@ -36,10 +36,7 @@ pub struct Command { /// 预期状态输出时间间隔 (秒) #[arg(long, short = 'r', default_value_t = 10)] pub report_interval: u64, - /// Windows 下会强制单线程, 且设置线程亲和性为核心 0 - #[arg(long = "bench", default_value_t = false)] - pub bench: bool, - /// 单线程模式 / benchmark 模式下的核心亲和性核心号 (从 0 开始) + /// 单线程模式模式下的核心亲和性核心号 (从 0 开始) #[arg(long = "core-pick", default_value_t = 0)] pub pick_core: usize, } @@ -54,7 +51,7 @@ impl Command { qp_expect: self.qp_expect, team: self.team.clone(), 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; 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(); // namerena--