Skip to content

Commit e8a636f

Browse files
committed
benchmark: Add riscv64 benchmark tests
As clippy command in our CI mandates: `cargo clippy --workspace --bins --examples --benches --all-features --all-targets -- -D warnings -D clippy::undocumented_unsafe_blocks`, add benchmarck test to appease clippy. Signed-off-by: Ruoqing He <[email protected]>
1 parent 1e09639 commit e8a636f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

benches/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ mod aarch64;
2121
#[cfg(target_arch = "aarch64")]
2222
use aarch64::*;
2323

24+
#[cfg(target_arch = "riscv64")]
25+
mod riscv64;
26+
#[cfg(target_arch = "riscv64")]
27+
use riscv64::*;
28+
2429
criterion_group! {
2530
name = benches;
2631
config = Criterion::default().sample_size(500);

benches/riscv64/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE-BSD-3-Clause file.
5+
//
6+
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
7+
extern crate criterion;
8+
extern crate linux_loader;
9+
extern crate vm_memory;
10+
11+
use linux_loader::configurator::fdt::FdtBootConfigurator;
12+
use linux_loader::configurator::{BootConfigurator, BootParams};
13+
use vm_memory::{ByteValued, GuestAddress, GuestMemoryMmap};
14+
15+
use criterion::{black_box, Criterion};
16+
17+
const MEM_SIZE: usize = 0x100_0000;
18+
const FDT_MAX_SIZE: usize = 0x20;
19+
20+
fn create_guest_memory() -> GuestMemoryMmap {
21+
GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), MEM_SIZE)]).unwrap()
22+
}
23+
24+
#[derive(Clone, Copy, Default)]
25+
#[allow(dead_code)]
26+
pub struct FdtPlaceholder([u8; FDT_MAX_SIZE]);
27+
28+
// SAFETY: The layout of the structure is fixed and can be initialized by
29+
// reading its content from byte array.
30+
unsafe impl ByteValued for FdtPlaceholder {}
31+
32+
fn build_fdt_boot_params() -> BootParams {
33+
let fdt = FdtPlaceholder([0u8; FDT_MAX_SIZE]);
34+
let fdt_addr = GuestAddress((MEM_SIZE - FDT_MAX_SIZE - 1) as u64);
35+
BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr)
36+
}
37+
38+
pub fn criterion_benchmark(c: &mut Criterion) {
39+
let guest_mem = create_guest_memory();
40+
let fdt_boot_params = build_fdt_boot_params();
41+
c.bench_function("configure_fdt", |b| {
42+
b.iter(|| {
43+
black_box(FdtBootConfigurator::write_bootparams::<GuestMemoryMmap>(
44+
&fdt_boot_params,
45+
&guest_mem,
46+
))
47+
.unwrap();
48+
})
49+
});
50+
}

0 commit comments

Comments
 (0)