forked from MightyPork/crsn
use 'spin_sleep' for more accurate execution rate, add "s", "m", "u" suffix support to the -C argument
This commit is contained in:
Generated
+11
-3
@@ -179,6 +179,7 @@ dependencies = [
|
|||||||
"num-traits",
|
"num-traits",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"sexp",
|
"sexp",
|
||||||
|
"spin_sleep",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -898,9 +899,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "sexp"
|
name = "sexp"
|
||||||
version = "1.1.4"
|
version = "1.1.4"
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha-1"
|
name = "sha-1"
|
||||||
@@ -933,6 +931,16 @@ version = "1.4.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
|
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spin_sleep"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2a98101bdc3833e192713c2af0b0dd2614f50d1cf1f7a97c5221b7aac052acc7"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ log = "0.4.11"
|
|||||||
num-traits = "0.2.12"
|
num-traits = "0.2.12"
|
||||||
parking_lot = "0.11.0"
|
parking_lot = "0.11.0"
|
||||||
nudge = "0.2.1"
|
nudge = "0.2.1"
|
||||||
|
spin_sleep = "1.0.0"
|
||||||
|
|||||||
@@ -11,4 +11,3 @@ description = "A small, simple, self-contained, s-expression parser and pretty-p
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.11"
|
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::{self, FromStr};
|
use std::str::{self, FromStr};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use std::thread::JoinHandle;
|
use std::thread::JoinHandle;
|
||||||
use std::time::Duration;
|
use std::time::{Duration};
|
||||||
|
|
||||||
pub use info::ThreadInfo;
|
pub use info::ThreadInfo;
|
||||||
pub use state::RunState;
|
pub use state::RunState;
|
||||||
@@ -66,11 +66,16 @@ impl RunThread {
|
|||||||
|
|
||||||
/// Start synchronously
|
/// Start synchronously
|
||||||
pub fn run(mut self) {
|
pub fn run(mut self) {
|
||||||
|
let mut loop_helper = spin_sleep::LoopHelper::builder()
|
||||||
|
.build_with_target_rate(1.0/self.info.cycle_time.as_secs_f64());
|
||||||
|
|
||||||
|
loop_helper.loop_start();
|
||||||
'run: loop {
|
'run: loop {
|
||||||
match self.eval_op() {
|
match self.eval_op() {
|
||||||
Ok(EvalRes { cycles, advance }) => {
|
Ok(EvalRes { cycles, advance }) => {
|
||||||
if cycles > 0 {
|
for _ in 0..cycles {
|
||||||
std::thread::sleep(self.info.cycle_time * (cycles as u32));
|
loop_helper.loop_sleep();
|
||||||
|
loop_helper.loop_start();
|
||||||
}
|
}
|
||||||
trace!("Step {}; Status = {}", advance, self.state.frame.status);
|
trace!("Step {}; Status = {}", advance, self.state.frame.status);
|
||||||
self.state.frame.pc.advance(advance);
|
self.state.frame.pc.advance(advance);
|
||||||
|
|||||||
+19
-18
@@ -92,22 +92,8 @@ impl AppConfig for Config {
|
|||||||
clap::Arg::with_name("cycle")
|
clap::Arg::with_name("cycle")
|
||||||
.long("cycle")
|
.long("cycle")
|
||||||
.short("C")
|
.short("C")
|
||||||
.value_name("MILLIS")
|
.value_name("MICROS")
|
||||||
.help("Cycle time (ms)")
|
.help("Cycle time (us, append \"s\" or \"ms\" for coarser time)")
|
||||||
.validator(|s| {
|
|
||||||
let t = s.trim();
|
|
||||||
if t.is_empty() {
|
|
||||||
Err("cycle time requires an argument".into())
|
|
||||||
} else {
|
|
||||||
if t.chars()
|
|
||||||
.find(|c| !c.is_ascii_digit())
|
|
||||||
.is_some() {
|
|
||||||
Err("cycle time requires an integer number".into())
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -115,8 +101,23 @@ impl AppConfig for Config {
|
|||||||
fn configure(mut self, clap: &ArgMatches) -> anyhow::Result<Self> {
|
fn configure(mut self, clap: &ArgMatches) -> anyhow::Result<Self> {
|
||||||
self.program_file = clap.value_of("input").unwrap().to_string();
|
self.program_file = clap.value_of("input").unwrap().to_string();
|
||||||
self.assemble_only = clap.is_present("asm-only");
|
self.assemble_only = clap.is_present("asm-only");
|
||||||
if let Some(c) = clap.value_of("cycle") {
|
if let Some(t) = clap.value_of("cycle") {
|
||||||
self.cycle_time = Duration::from_millis(c.parse().unwrap());
|
let (t, mul) = if t.ends_with("us") {
|
||||||
|
(&t[..(t.len()-2)], 1)
|
||||||
|
} else if t.ends_with("ms") {
|
||||||
|
(&t[..(t.len()-2)], 1000)
|
||||||
|
} else if t.ends_with("m") {
|
||||||
|
(&t[..(t.len()-1)], 1000)
|
||||||
|
} else if t.ends_with("u") {
|
||||||
|
(&t[..(t.len()-1)], 1)
|
||||||
|
} else if t.ends_with("s") {
|
||||||
|
(&t[..(t.len()-1)], 1000_000)
|
||||||
|
} else {
|
||||||
|
(t, 1)
|
||||||
|
};
|
||||||
|
|
||||||
|
self.cycle_time = Duration::from_micros(t.parse::<u64>().expect("parse -C value") * mul);
|
||||||
|
println!("ct = {:?}", self.cycle_time);
|
||||||
}
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user