支持进程亲和性设置
This commit is contained in:
parent
8ab812eabd
commit
2f416cb153
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1831,7 +1831,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "tswn"
|
||||
version = "0.1.8"
|
||||
version = "0.1.9"
|
||||
dependencies = [
|
||||
"base16384",
|
||||
"chrono",
|
||||
|
@ -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
|
||||
|
3
miner/docs/.gitignore
vendored
3
miner/docs/.gitignore
vendored
@ -1 +1,2 @@
|
||||
runs
|
||||
runs
|
||||
namerena
|
7
miner/docs/updates.md
Normal file
7
miner/docs/updates.md
Normal file
@ -0,0 +1,7 @@
|
||||
# tswn 的 更新
|
||||
|
||||
## 0.1.x
|
||||
|
||||
### 0.1.6~9
|
||||
|
||||
更新了一大堆核心亲和性相关的东西
|
@ -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!("开始计算");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user