From 2f416cb1539e48b2553f67e7cae1f3199e4b2357 Mon Sep 17 00:00:00 2001 From: shenjack-5600u <3695888@qq.com> Date: Sun, 28 Apr 2024 06:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=9B=E7=A8=8B=E4=BA=B2?= =?UTF-8?q?=E5=92=8C=E6=80=A7=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- miner/Cargo.toml | 2 +- miner/docs/.gitignore | 3 ++- miner/docs/updates.md | 7 +++++++ miner/src/main.rs | 21 +++++++++++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 miner/docs/updates.md diff --git a/Cargo.lock b/Cargo.lock index 84036e1..a12b450 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1831,7 +1831,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tswn" -version = "0.1.8" +version = "0.1.9" dependencies = [ "base16384", "chrono", diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 96550f8..db639a0 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tswn" description = "tool shenjack work shop namerena" -version = "0.1.8" +version = "0.1.9" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/miner/docs/.gitignore b/miner/docs/.gitignore index cb1d07b..afdbdd3 100644 --- a/miner/docs/.gitignore +++ b/miner/docs/.gitignore @@ -1 +1,2 @@ -runs \ No newline at end of file +runs +namerena \ No newline at end of file diff --git a/miner/docs/updates.md b/miner/docs/updates.md new file mode 100644 index 0000000..e035dc9 --- /dev/null +++ b/miner/docs/updates.md @@ -0,0 +1,7 @@ +# tswn 的 更新 + +## 0.1.x + +### 0.1.6~9 + +更新了一大堆核心亲和性相关的东西 diff --git a/miner/src/main.rs b/miner/src/main.rs index 855319b..0677a5e 100644 --- a/miner/src/main.rs +++ b/miner/src/main.rs @@ -81,6 +81,23 @@ pub fn set_thread2core(core: usize) { } } +pub fn set_process_cores(cores: usize) { + #[cfg(windows)] + unsafe { + use windows_sys::Win32::System::Threading::{SetProcessAffinityMask, GetCurrentProcess}; + let process = GetCurrentProcess(); + let core_mask = cores; + match SetProcessAffinityMask(process, core_mask) { + 0 => warn!("设置进程亲和性失败 {}", std::io::Error::last_os_error()), + x => info!("设置进程亲和性成功 {}", x), + } + } + #[cfg(linux)] + { + warn!("Linux 下不支持设置进程亲和性 (未实现) {}", cores) + } +} + fn main() { tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init(); let mut cli_arg = Command::parse(); @@ -113,14 +130,17 @@ fn main() { info!("开始 benchmark"); let mut config = cli_arg.as_cacl_config(); config.core_affinity = Some(0001 << cli_arg.bench_core); + set_process_cores(cli_arg.bench_core); cacluate::cacl(config, 1, &out_path); } else { let mut n = 0; + let mut cores = 0; 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((0001 << i) + (0001 << (i + 1))); + cores |= (0001 << i) + (0001 << (i + 1)); let out_path = out_path.clone(); let thread_name = format!("thread_{}", n); threads.push(std::thread::spawn(move || { @@ -129,6 +149,7 @@ fn main() { info!("线程 {} 结束计算", thread_name); })); } + set_process_cores(cores); } info!("开始计算");