base, sys_util: remove Timer::is_armed function

This is currently only used in tests, and removing it makes the
cross-platform Timer API simpler to implement. The Windows version of
Timer did not implement this API, so it was already unusable in portable
code.

BUG=b:215618361
TEST=tools/presubmit
TEST=cargo test -p base timer

Change-Id: I57ab15e8b652d0df3664d95bc7759b9c84fe5e10
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3570178
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2022-04-04 14:12:42 -07:00 committed by Chromeos LUCI
parent e584f835a8
commit 2d01c1df92
6 changed files with 2 additions and 81 deletions

View file

@ -42,10 +42,6 @@ macro_rules! build_timer {
self.0.wait().map(|_| ())
}
pub fn is_armed(&self) -> Result<bool> {
self.0.is_armed()
}
pub fn clear(&mut self) -> Result<()> {
self.0.clear()
}

View file

@ -12,10 +12,7 @@ use std::{
};
use sync::Mutex;
use libc::{
clock_getres, timerfd_create, timerfd_gettime, timerfd_settime, CLOCK_MONOTONIC, TFD_CLOEXEC,
{self},
};
use libc::{self, clock_getres, timerfd_create, timerfd_settime, CLOCK_MONOTONIC, TFD_CLOEXEC};
use super::{errno_result, EventFd, FakeClock, Result};
@ -92,20 +89,6 @@ impl TimerFd {
Ok(count)
}
/// Returns `true` if the timer is currently armed.
pub fn is_armed(&self) -> Result<bool> {
// Safe because we are zero-initializing a struct with only primitive member fields.
let mut spec: libc::itimerspec = unsafe { mem::zeroed() };
// Safe because timerfd_gettime is trusted to only modify `spec`.
let ret = unsafe { timerfd_gettime(self.as_raw_fd(), &mut spec) };
if ret < 0 {
return errno_result();
}
Ok(spec.it_value.tv_sec != 0 || spec.it_value.tv_nsec != 0)
}
/// Disarms the timer.
pub fn clear(&self) -> Result<()> {
// Safe because we are zero-initializing a struct with only primitive member fields.
@ -215,11 +198,6 @@ impl FakeTimerFd {
}
}
/// Returns `true` if the timer is currently armed.
pub fn is_armed(&self) -> Result<bool> {
Ok(self.deadline_ns.is_some())
}
/// Disarms the timer.
pub fn clear(&mut self) -> Result<()> {
self.deadline_ns = None;
@ -256,14 +234,11 @@ mod tests {
#[test]
fn one_shot() {
let tfd = TimerFd::new().expect("failed to create timerfd");
assert!(!tfd.is_armed().unwrap());
let dur = Duration::from_millis(200);
let now = Instant::now();
tfd.reset(dur, None).expect("failed to arm timer");
assert!(tfd.is_armed().unwrap());
let count = tfd.wait().expect("unable to wait for timer");
assert_eq!(count, 1);
@ -288,12 +263,10 @@ mod tests {
fn fake_one_shot() {
let clock = Arc::new(Mutex::new(FakeClock::new()));
let mut tfd = FakeTimerFd::new(clock.clone());
assert!(!tfd.is_armed().unwrap());
let dur = Duration::from_nanos(200);
tfd.reset(dur, None).expect("failed to arm timer");
assert!(tfd.is_armed().unwrap());
clock.lock().add_ns(200);
let count = tfd.wait().expect("unable to wait for timer");

View file

@ -151,11 +151,6 @@ impl FakeTimer {
}
}
/// Returns `true` if the timer is currently armed.
pub fn is_armed(&self) -> Result<bool> {
Ok(self.deadline_ns.is_some())
}
/// Disarms the timer.
pub fn clear(&mut self) -> Result<()> {
self.deadline_ns = None;
@ -276,12 +271,10 @@ mod tests {
fn fake_one_shot() {
let clock = Arc::new(Mutex::new(FakeClock::new()));
let mut tfd = FakeTimer::new(clock.clone());
assert_eq!(tfd.is_armed().unwrap(), false);
let dur = Duration::from_nanos(200);
tfd.reset(dur, None).expect("failed to arm timer");
assert_eq!(tfd.is_armed().unwrap(), true);
clock.lock().add_ns(200);
let result = tfd.wait(None).expect("unable to wait for timer");
@ -293,11 +286,9 @@ mod tests {
fn fake_one_shot_timeout() {
let clock = Arc::new(Mutex::new(FakeClock::new()));
let mut tfd = FakeTimer::new(clock.clone());
assert_eq!(tfd.is_armed().unwrap(), false);
let dur = Duration::from_nanos(200);
tfd.reset(dur, None).expect("failed to arm timer");
assert_eq!(tfd.is_armed().unwrap(), true);
clock.lock().add_ns(100);
let result = tfd

View file

@ -69,14 +69,11 @@ mod tests {
async fn this_test(ex: &URingExecutor) {
let tfd = TimerFd::new().expect("failed to create timerfd");
assert_eq!(tfd.is_armed().unwrap(), false);
let dur = Duration::from_millis(200);
let now = Instant::now();
tfd.reset(dur, None).expect("failed to arm timer");
assert_eq!(tfd.is_armed().unwrap(), true);
let t = TimerAsync::new_uring(tfd, ex).unwrap();
let count = t.next_val().await.expect("unable to wait for timer");
@ -92,14 +89,11 @@ mod tests {
fn one_shot_fd() {
async fn this_test(ex: &FdExecutor) {
let tfd = TimerFd::new().expect("failed to create timerfd");
assert_eq!(tfd.is_armed().unwrap(), false);
let dur = Duration::from_millis(200);
let now = Instant::now();
tfd.reset(dur, None).expect("failed to arm timer");
assert_eq!(tfd.is_armed().unwrap(), true);
let t = TimerAsync::new_poll(tfd, ex).unwrap();
let count = t.next_val().await.expect("unable to wait for timer");

View file

@ -12,10 +12,7 @@ use std::{
};
use sync::Mutex;
use libc::{
clock_getres, timerfd_create, timerfd_gettime, timerfd_settime, CLOCK_MONOTONIC, TFD_CLOEXEC,
{self},
};
use libc::{self, clock_getres, timerfd_create, timerfd_settime, CLOCK_MONOTONIC, TFD_CLOEXEC};
use super::{errno_result, EventFd, FakeClock, Result};
@ -92,20 +89,6 @@ impl TimerFd {
Ok(count)
}
/// Returns `true` if the timer is currently armed.
pub fn is_armed(&self) -> Result<bool> {
// Safe because we are zero-initializing a struct with only primitive member fields.
let mut spec: libc::itimerspec = unsafe { mem::zeroed() };
// Safe because timerfd_gettime is trusted to only modify `spec`.
let ret = unsafe { timerfd_gettime(self.as_raw_fd(), &mut spec) };
if ret < 0 {
return errno_result();
}
Ok(spec.it_value.tv_sec != 0 || spec.it_value.tv_nsec != 0)
}
/// Disarms the timer.
pub fn clear(&self) -> Result<()> {
// Safe because we are zero-initializing a struct with only primitive member fields.
@ -215,11 +198,6 @@ impl FakeTimerFd {
}
}
/// Returns `true` if the timer is currently armed.
pub fn is_armed(&self) -> Result<bool> {
Ok(self.deadline_ns.is_some())
}
/// Disarms the timer.
pub fn clear(&mut self) -> Result<()> {
self.deadline_ns = None;
@ -256,14 +234,11 @@ mod tests {
#[test]
fn one_shot() {
let tfd = TimerFd::new().expect("failed to create timerfd");
assert!(!tfd.is_armed().unwrap());
let dur = Duration::from_millis(200);
let now = Instant::now();
tfd.reset(dur, None).expect("failed to arm timer");
assert!(tfd.is_armed().unwrap());
let count = tfd.wait().expect("unable to wait for timer");
assert_eq!(count, 1);
@ -288,12 +263,10 @@ mod tests {
fn fake_one_shot() {
let clock = Arc::new(Mutex::new(FakeClock::new()));
let mut tfd = FakeTimerFd::new(clock.clone());
assert!(!tfd.is_armed().unwrap());
let dur = Duration::from_nanos(200);
tfd.reset(dur, None).expect("failed to arm timer");
assert!(tfd.is_armed().unwrap());
clock.lock().add_ns(200);
let count = tfd.wait().expect("unable to wait for timer");

View file

@ -69,14 +69,11 @@ mod tests {
async fn this_test(ex: &URingExecutor) {
let tfd = TimerFd::new().expect("failed to create timerfd");
assert_eq!(tfd.is_armed().unwrap(), false);
let dur = Duration::from_millis(200);
let now = Instant::now();
tfd.reset(dur, None).expect("failed to arm timer");
assert_eq!(tfd.is_armed().unwrap(), true);
let t = TimerAsync::new_uring(tfd, ex).unwrap();
let count = t.next_val().await.expect("unable to wait for timer");
@ -92,14 +89,11 @@ mod tests {
fn one_shot_fd() {
async fn this_test(ex: &FdExecutor) {
let tfd = TimerFd::new().expect("failed to create timerfd");
assert_eq!(tfd.is_armed().unwrap(), false);
let dur = Duration::from_millis(200);
let now = Instant::now();
tfd.reset(dur, None).expect("failed to arm timer");
assert_eq!(tfd.is_armed().unwrap(), true);
let t = TimerAsync::new_poll(tfd, ex).unwrap();
let count = t.next_val().await.expect("unable to wait for timer");