Skip to content

Commit 1c32479

Browse files
authored
Merge pull request #1770 from Kobzol/ci-codegen-backend
Add CI workflow for benchmarking Cranelift backend
2 parents 2d336b1 + d6c617a commit 1c32479

File tree

4 files changed

+86
-34
lines changed

4 files changed

+86
-34
lines changed

.github/workflows/ci.yml

+34-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ jobs:
9090
- name: Run unit tests
9191
run: cargo test --all
9292

93-
9493
test_benchmarks:
9594
strategy:
9695
matrix:
@@ -149,6 +148,40 @@ jobs:
149148
PROFILES: ${{ matrix.PROFILES }}
150149
SHELL: "/bin/bash"
151150

151+
test_backends:
152+
name: Test codegen backend benchmarks
153+
runs-on: ubuntu-latest
154+
steps:
155+
- name: Checkout the source code
156+
uses: actions/checkout@v2
157+
with:
158+
fetch-depth: 1
159+
160+
- name: Install latest beta
161+
uses: actions-rs/toolchain@v1
162+
with:
163+
toolchain: beta
164+
override: true
165+
166+
- name: Configure environment
167+
run: |
168+
sudo apt-get update
169+
sudo apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`
170+
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
171+
172+
- uses: Swatinem/rust-cache@v2
173+
174+
- name: Build collector
175+
run: cargo build -p collector
176+
177+
- name: Check compile benchmarks
178+
run: sh -x -c "ci/check-compile-benchmarks.sh"
179+
env:
180+
BENCH_INCLUDE_EXCLUDE_OPTS: "--include helloworld --exclude helloworld-tiny"
181+
PROFILES: Debug,Opt
182+
BACKENDS: Cranelift
183+
SHELL: "/bin/bash"
184+
152185
test_runtime_benchmarks:
153186
name: Test runtime benchmarks
154187
runs-on: ubuntu-latest

ci/check-compile-benchmarks.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ bash -c "while true; do sleep 30; echo \$(date) - running ...; done" &
66
PING_LOOP_PID=$!
77
trap 'kill $PING_LOOP_PID' ERR 1 2 3 6
88

9+
BACKENDS=${BACKENDS:-Llvm}
10+
911
# Install a toolchain.
1012
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
11-
bindir=`cargo run -p collector --bin collector install_next`
13+
bindir=`cargo run -p collector --bin collector install_next --backends ${BACKENDS}`
1214

1315
# Do some benchmarking.
1416
RUST_BACKTRACE=1 \
@@ -21,6 +23,7 @@ RUST_BACKTRACE=1 \
2123
--profiles $PROFILES \
2224
--cargo $bindir/cargo \
2325
--scenarios All \
26+
--backends $BACKENDS \
2427
--rustdoc $bindir/rustdoc \
2528
$BENCH_INCLUDE_EXCLUDE_OPTS
2629

collector/src/bin/collector.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,11 @@ enum Commands {
575575
},
576576

577577
/// Installs the next commit for perf.rust-lang.org
578-
InstallNext,
578+
InstallNext {
579+
/// Install additional components to enable benchmarking of the given backends.
580+
#[arg(long = "backends", value_parser = EnumArgParser::<CodegenBackend>::default(), default_value = "Llvm")]
581+
codegen_backends: MultiEnumValue<CodegenBackend>,
582+
},
579583

580584
/// Download a crate into collector/benchmarks.
581585
Download(DownloadCommand),
@@ -979,8 +983,12 @@ fn main_result() -> anyhow::Result<i32> {
979983
runs,
980984
} => {
981985
let sha = commit.sha.to_string();
982-
let sysroot = Sysroot::install(sha.clone(), &target_triple)
983-
.with_context(|| format!("failed to install sysroot for {:?}", commit))?;
986+
let sysroot = Sysroot::install(
987+
sha.clone(),
988+
&target_triple,
989+
vec![CodegenBackend::Llvm],
990+
)
991+
.with_context(|| format!("failed to install sysroot for {:?}", commit))?;
984992

985993
let mut benchmarks = get_compile_benchmarks(
986994
&compile_benchmark_dir,
@@ -1155,7 +1163,7 @@ fn main_result() -> anyhow::Result<i32> {
11551163
Ok(0)
11561164
}
11571165

1158-
Commands::InstallNext => {
1166+
Commands::InstallNext { codegen_backends } => {
11591167
let last_sha = Command::new("git")
11601168
.arg("ls-remote")
11611169
.arg("https://github.com/rust-lang/rust.git")
@@ -1165,7 +1173,7 @@ fn main_result() -> anyhow::Result<i32> {
11651173
let last_sha = String::from_utf8(last_sha.stdout).expect("utf8");
11661174
let last_sha = last_sha.split_whitespace().next().expect(&last_sha);
11671175
let commit = get_commit_or_fake_it(last_sha).expect("success");
1168-
let mut sysroot = Sysroot::install(commit.sha, &target_triple)?;
1176+
let mut sysroot = Sysroot::install(commit.sha, &target_triple, codegen_backends.0)?;
11691177
sysroot.preserve(); // don't delete it
11701178

11711179
// Print the directory containing the toolchain.

collector/src/toolchain.rs

+35-27
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ pub struct Sysroot {
2020
}
2121

2222
impl Sysroot {
23-
pub fn install(sha: String, triple: &str) -> anyhow::Result<Self> {
23+
pub fn install(
24+
sha: String,
25+
triple: &str,
26+
backends: Vec<CodegenBackend>,
27+
) -> anyhow::Result<Self> {
2428
let unpack_into = "cache";
2529

2630
fs::create_dir_all(unpack_into)?;
@@ -31,10 +35,13 @@ impl Sysroot {
3135
triple: triple.to_owned(),
3236
};
3337

34-
download.get_and_extract(ModuleVariant::Rustc)?;
35-
download.get_and_extract(ModuleVariant::Std)?;
36-
download.get_and_extract(ModuleVariant::Cargo)?;
37-
download.get_and_extract(ModuleVariant::RustSrc)?;
38+
download.get_and_extract(Component::Rustc)?;
39+
download.get_and_extract(Component::Std)?;
40+
download.get_and_extract(Component::Cargo)?;
41+
download.get_and_extract(Component::RustSrc)?;
42+
if backends.contains(&CodegenBackend::Cranelift) {
43+
download.get_and_extract(Component::Cranelift)?;
44+
}
3845

3946
let sysroot = download.into_sysroot()?;
4047

@@ -70,29 +77,30 @@ struct SysrootDownload {
7077

7178
const BASE_URL: &str = "https://ci-artifacts.rust-lang.org/rustc-builds";
7279

73-
// FIXME(eddyb) rename to just `Component`.
7480
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
75-
enum ModuleVariant {
81+
enum Component {
7682
Cargo,
7783
Rustc,
7884
Std,
7985
RustSrc,
86+
Cranelift,
8087
}
8188

82-
impl fmt::Display for ModuleVariant {
89+
impl fmt::Display for Component {
8390
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8491
match *self {
85-
ModuleVariant::Cargo => write!(f, "cargo"),
86-
ModuleVariant::Rustc => write!(f, "rustc"),
87-
ModuleVariant::Std => write!(f, "rust-std"),
88-
ModuleVariant::RustSrc => write!(f, "rust-src"),
92+
Component::Cargo => write!(f, "cargo"),
93+
Component::Rustc => write!(f, "rustc"),
94+
Component::Std => write!(f, "rust-std"),
95+
Component::RustSrc => write!(f, "rust-src"),
96+
Component::Cranelift => write!(f, "rustc-codegen-cranelift"),
8997
}
9098
}
9199
}
92100

93-
impl ModuleVariant {
101+
impl Component {
94102
fn url(&self, channel: &str, sysroot: &SysrootDownload, triple: &str) -> String {
95-
let suffix = if *self == ModuleVariant::RustSrc {
103+
let suffix = if *self == Component::RustSrc {
96104
String::new()
97105
} else {
98106
format!("-{}", triple)
@@ -137,15 +145,15 @@ impl SysrootDownload {
137145
})
138146
}
139147

140-
fn get_and_extract(&self, variant: ModuleVariant) -> anyhow::Result<()> {
148+
fn get_and_extract(&self, component: Component) -> anyhow::Result<()> {
141149
let archive_path = self.directory.join(format!(
142150
"{}-{}-{}.tar.xz",
143-
self.rust_sha, self.triple, variant,
151+
self.rust_sha, self.triple, component,
144152
));
145153
if archive_path.exists() {
146154
let reader = BufReader::new(File::open(&archive_path)?);
147155
let decompress = XzDecoder::new(reader);
148-
let extract = self.extract(variant, decompress);
156+
let extract = self.extract(component, decompress);
149157
match extract {
150158
Ok(()) => return Ok(()),
151159
Err(err) => {
@@ -158,17 +166,17 @@ impl SysrootDownload {
158166
// We usually have nightlies but we want to avoid breaking down if we
159167
// accidentally end up with a beta or stable commit.
160168
let urls = [
161-
variant.url("nightly", self, &self.triple),
162-
variant.url("beta", self, &self.triple),
163-
variant.url("stable", self, &self.triple),
169+
component.url("nightly", self, &self.triple),
170+
component.url("beta", self, &self.triple),
171+
component.url("stable", self, &self.triple),
164172
];
165173
for url in &urls {
166174
log::debug!("requesting: {}", url);
167175
let resp = reqwest::blocking::get(url)?;
168176
log::debug!("{}", resp.status());
169177
if resp.status().is_success() {
170178
let reader = XzDecoder::new(BufReader::new(resp));
171-
match self.extract(variant, reader) {
179+
match self.extract(component, reader) {
172180
Ok(()) => return Ok(()),
173181
Err(err) => {
174182
log::warn!("extracting {} failed: {:?}", url, err);
@@ -181,17 +189,17 @@ impl SysrootDownload {
181189
"unable to download sha {} triple {} module {} from any of {:?}",
182190
self.rust_sha,
183191
self.triple,
184-
variant,
192+
component,
185193
urls
186194
))
187195
}
188196

189-
fn extract<T: Read>(&self, variant: ModuleVariant, reader: T) -> anyhow::Result<()> {
197+
fn extract<T: Read>(&self, component: Component, reader: T) -> anyhow::Result<()> {
190198
let mut archive = Archive::new(reader);
191-
let prefix = if variant == ModuleVariant::Std {
192-
format!("rust-std-{}", self.triple)
193-
} else {
194-
variant.to_string()
199+
let prefix = match component {
200+
Component::Std => format!("rust-std-{}", self.triple),
201+
Component::Cranelift => format!("{component}-preview"),
202+
_ => component.to_string(),
195203
};
196204

197205
let unpack_into = self.directory.join(&self.rust_sha);

0 commit comments

Comments
 (0)