Skip to content

Commit

Permalink
add option for cpu thread pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
bold committed Aug 14, 2018
1 parent 196ce03 commit e0a7250
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ timeout: 5000 # default 5000ms

# delay after disks will be woken up (if 0 no wakeup) [s]
wakeup_after: 240 # default 240s

# pin worker threads to cpu cores
cpu_thread_pinning: false # pin worker threads to cpu cores | default false
```
### Donate
Expand Down
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ logfile_max_size : 20 # maximum size per logfile in MiB
console_log_pattern: '{({d(%H:%M:%S)} [{l}]):16.16} {m}{n}'
logfile_log_pattern: '{({d(%Y-%m-%d %H:%M:%S)} [{l}]):26.26} {m}{n}'

cpu_thread_pinning: false # default false

# More detailed log patterns
#console_log_pattern: '{d(%H:%M:%S.%3f%z)} [{h({l}):<5}] [{T}] [{t}] - {M}:{m}{n}'
#logfile_log_pattern: '{d(%Y-%m-%dT%H:%M:%S.%3f%z)} [{h({l}):<5}] [{T}]-[{t}] [{f}:{L}] - {M}:{m}{n}'
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub struct Cfg {

#[serde(default = "default_logfile_log_level")]
pub logfile_log_level: String,

#[serde(default = "default_cpu_thread_pinning")]
pub cpu_thread_pinning: bool,
}

fn default_secret_phrase() -> String {
Expand Down Expand Up @@ -118,6 +121,10 @@ fn default_wakeup_after() -> i64 {
240
}

fn default_cpu_thread_pinning() -> bool {
false
}

pub fn load_cfg(config: &str) -> Cfg {
let cfg_str = fs::read_to_string(config).expect("failed to open config");
let cfg: Cfg = serde_yaml::from_str(&cfg_str).expect("failed to parse config");
Expand Down
4 changes: 3 additions & 1 deletion src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ impl Miner {
for id in 0..worker_thread_count {
let core_id = core_ids[id % core_ids.len()];
thread::spawn({
core_affinity::set_for_current(core_id);
if cfg.cpu_thread_pinning {
core_affinity::set_for_current(core_id);
}

create_worker_task(
rx_read_replies.clone(),
Expand Down

0 comments on commit e0a7250

Please sign in to comment.