Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.6 #148

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog
## [Unreleased]

## [v0.6.0]

### Added

- [[#160]](https://github.com/rust-vmm/vm-memory/pull/160): Add `ArcRef` and `AtomicBitmapArc` bitmap
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]
name = "vm-memory"
version = "0.5.0"
version = "0.6.0"
description = "Safe abstractions for accessing the VM physical memory"
keywords = ["memory"]
categories = ["memory-management"]
authors = ["Liu Jiang <[email protected]>"]
repository = "https://github.com/rust-vmm/vm-memory"
readme = "README.md"
Expand Down
35 changes: 9 additions & 26 deletions src/volatile_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,9 +1368,8 @@ mod tests {
use std::mem::size_of_val;
use std::path::Path;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread::{sleep, spawn};
use std::time::Duration;
use std::sync::{Arc, Barrier};
use std::thread::spawn;

use matches::assert_matches;
use vmm_sys_util::tempfile::TempFile;
Expand Down Expand Up @@ -1563,36 +1562,20 @@ mod tests {
let a = VecMem::new(1);
let a_clone = a.clone();
let v_ref = a.get_ref::<u8>(0).unwrap();
let barrier = Arc::new(Barrier::new(2));
let barrier1 = barrier.clone();

v_ref.store(99);
spawn(move || {
sleep(Duration::from_millis(10));
barrier1.wait();
let clone_v_ref = a_clone.get_ref::<u8>(0).unwrap();
clone_v_ref.store(0);
barrier1.wait();
});

// Technically this is a race condition but we have to observe the v_ref's value changing
// somehow and this helps to ensure the sleep actually happens before the store rather then
// being reordered by the compiler.
assert_eq!(v_ref.load(), 99);

// Granted we could have a machine that manages to perform this many volatile loads in the
// amount of time the spawned thread sleeps, but the most likely reason the retry limit will
// get reached is because v_ref.load() is not actually performing the required volatile read
// or v_ref.store() is not doing a volatile write. A timer based solution was avoided
// because that might use a syscall which could hint the optimizer to reload v_ref's pointer
// regardless of volatile status. Note that we use a longer retry duration for optimized
// builds.
#[cfg(debug_assertions)]
const RETRY_MAX: usize = 500_000_000;
#[cfg(not(debug_assertions))]
const RETRY_MAX: usize = 10_000_000_000;

let mut retry = 0;
while v_ref.load() == 99 && retry < RETRY_MAX {
retry += 1;
}

assert_ne!(retry, RETRY_MAX, "maximum retry exceeded");
barrier.wait();
barrier.wait();
assert_eq!(v_ref.load(), 0);
}

Expand Down