File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 6
6
pub use criterion:: { black_box, Criterion } ;
7
7
use vm_memory:: { GuestAddress , GuestMemory , GuestMemoryMmap } ;
8
8
9
- const REGION_SIZE : u64 = 0x10_0000 ;
9
+ const REGION_SIZE : usize = 0x10_0000 ;
10
10
const REGIONS_COUNT : u64 = 256 ;
11
11
12
12
pub fn benchmark_for_guest_memory ( c : & mut Criterion ) {
@@ -16,7 +16,7 @@ pub fn benchmark_for_guest_memory(c: &mut Criterion) {
16
16
fn find_region ( mem : & GuestMemoryMmap ) {
17
17
for i in 0 ..REGIONS_COUNT {
18
18
let _ = mem
19
- . find_region ( black_box ( GuestAddress ( i * REGION_SIZE ) ) )
19
+ . find_region ( black_box ( GuestAddress ( i * REGION_SIZE as u64 ) ) )
20
20
. unwrap ( ) ;
21
21
}
22
22
}
Original file line number Diff line number Diff line change @@ -15,10 +15,12 @@ mod volatile;
15
15
use volatile:: benchmark_for_volatile;
16
16
17
17
#[ cfg( feature = "backend-mmap" ) ]
18
- pub fn create_guest_memory_mmap ( size : u64 , count : u64 ) -> GuestMemoryMmap {
18
+ // Use this function with caution. It does not check against overflows
19
+ // and `GuestMemoryMmap::from_ranges` errors.
20
+ fn create_guest_memory_mmap ( size : usize , count : u64 ) -> GuestMemoryMmap {
19
21
let mut regions: Vec < ( GuestAddress , usize ) > = Vec :: new ( ) ;
20
22
for i in 0 ..count {
21
- regions. push ( ( GuestAddress ( i * size) , size as usize ) ) ;
23
+ regions. push ( ( GuestAddress ( i * size as u64 ) , size) ) ;
22
24
}
23
25
24
26
GuestMemoryMmap :: from_ranges ( regions. as_slice ( ) ) . unwrap ( )
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ use criterion::{black_box, Criterion};
15
15
16
16
use vm_memory:: { ByteValued , Bytes , GuestAddress , GuestMemory } ;
17
17
18
- const REGION_SIZE : u64 = 0x8000_0000 ;
18
+ const REGION_SIZE : usize = 0x8000_0000 ;
19
19
const REGIONS_COUNT : u64 = 8 ;
20
20
const ACCESS_SIZE : usize = 0x200 ;
21
21
@@ -55,8 +55,10 @@ enum AccessKind {
55
55
impl AccessKind {
56
56
fn make_offset ( & self , access_size : usize ) -> u64 {
57
57
match * self {
58
- AccessKind :: InRegion ( idx) => REGION_SIZE * idx,
59
- AccessKind :: CrossRegion ( idx) => REGION_SIZE * ( idx + 1 ) - ( access_size / 2 ) as u64 ,
58
+ AccessKind :: InRegion ( idx) => REGION_SIZE as u64 * idx,
59
+ AccessKind :: CrossRegion ( idx) => {
60
+ REGION_SIZE as u64 * ( idx + 1 ) - ( access_size as u64 / 2 )
61
+ }
60
62
}
61
63
}
62
64
}
@@ -67,7 +69,7 @@ pub fn benchmark_for_mmap(c: &mut Criterion) {
67
69
// Just a sanity check.
68
70
assert_eq ! (
69
71
memory. last_addr( ) ,
70
- GuestAddress ( REGION_SIZE * REGIONS_COUNT - 0x01 )
72
+ GuestAddress ( REGION_SIZE as u64 * REGIONS_COUNT - 0x01 )
71
73
) ;
72
74
73
75
let some_small_dummy = SmallDummy {
You can’t perform that action at this time.
0 commit comments