Skip to content

Commit 6865d6b

Browse files
committed
Try to increase priority of processes using runtime benchmarks
1 parent 9204901 commit 6865d6b

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/benchlib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ serde_json = "1.0.83"
1313
log = "0.4.17"
1414
env_logger = "0.9.0"
1515
clap = { version = "3.2", features = ["derive"] }
16+
libc = "0.2"
1617

1718
[target.'cfg(unix)'.dependencies]
1819
perf-event = "0.4.7"

collector/benchlib/src/benchmark.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::cli::{parse_cli, Args, BenchmarkArgs};
22
use crate::measure::benchmark_function;
33
use crate::messages::BenchmarkResult;
4+
use crate::process::raise_process_priority;
45
use log::LevelFilter;
56
use std::collections::HashMap;
67

@@ -48,6 +49,8 @@ impl BenchmarkSuite {
4849
/// Execute the benchmark suite. It will parse CLI arguments and decide what to do based on
4950
/// them.
5051
pub fn run(self) -> anyhow::Result<()> {
52+
raise_process_priority();
53+
5154
let args = parse_cli()?;
5255
match args {
5356
Args::Benchmark(args) => {

collector/benchlib/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! This library defines an API for performing benchmarks of Rust code. It is tailored for the
2-
//! use-case of `rustc-perf`, that's why we don't use e.g. `criterion` or `iai`.
1+
//! This library defines an API for performing benchmarks of Rust code and various other utilities
2+
//! for measuring and benchmarking. It is tailored for the use-case of `rustc-perf`, that's why we
3+
//! don't use e.g. `criterion` or `iai`.
34
//!
45
//! We want to be able to define short benchmarks in code, measure specific perf. counters and most
56
//! importantly, consume the benchmark results in a programmatic way.
@@ -16,3 +17,4 @@ pub mod benchmark;
1617
mod cli;
1718
pub mod measure;
1819
pub mod messages;
20+
pub mod process;

collector/benchlib/src/process.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#[cfg(unix)]
2+
pub fn raise_process_priority() {
3+
unsafe {
4+
// Try to reduce jitter in wall time by increasing our priority to the
5+
// maximum
6+
for i in (1..21).rev() {
7+
let r = libc::setpriority(libc::PRIO_PROCESS as _, libc::getpid() as libc::id_t, -i);
8+
if r == 0 {
9+
break;
10+
}
11+
}
12+
}
13+
}
14+
15+
#[cfg(windows)]
16+
pub fn raise_process_priority() {}

collector/runtime-benchmarks/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/src/bin/rustc-fake.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn main() {
6868
let wrapper = args.remove(pos);
6969
let wrapper = wrapper.to_str().unwrap();
7070

71-
raise_priority();
71+
benchlib::process::raise_process_priority();
7272

7373
// These strings come from `PerfTool::name()`.
7474
match wrapper {
@@ -490,20 +490,6 @@ fn exec(cmd: &mut Command) -> ! {
490490
panic!("failed to exec `{}`: {}", cmd_d, error);
491491
}
492492

493-
#[cfg(unix)]
494-
fn raise_priority() {
495-
unsafe {
496-
// Try to reduce jitter in wall time by increasing our priority to the
497-
// maximum
498-
for i in (1..21).rev() {
499-
let r = libc::setpriority(libc::PRIO_PROCESS as _, libc::getpid() as libc::id_t, -i);
500-
if r == 0 {
501-
break;
502-
}
503-
}
504-
}
505-
}
506-
507493
#[cfg(unix)]
508494
fn print_memory() {
509495
use std::mem;
@@ -555,8 +541,5 @@ fn run_summarize(name: &str, prof_out_dir: &Path, prefix: &str) -> anyhow::Resul
555541
fs::read_to_string(&json).with_context(|| format!("failed to read {:?}", json))
556542
}
557543

558-
#[cfg(windows)]
559-
fn raise_priority() {}
560-
561544
#[cfg(windows)]
562545
fn print_memory() {}

0 commit comments

Comments
 (0)