Changeset 751e2eb for benchmark/readyQ/locality.rs
- Timestamp:
- Dec 18, 2020, 2:53:20 PM (2 years ago)
- Branches:
- arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 5d369c7
- Parents:
- 49ce636
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/locality.rs
r49ce636 r751e2eb 1 use std::io::{self, Write};2 1 use std::ptr; 3 2 use std::sync::Arc; 4 use std::sync::atomic::{AtomicU64, AtomicBool,Ordering};5 use std::time:: {Instant,Duration};3 use std::sync::atomic::{AtomicU64, Ordering}; 4 use std::time::Instant; 6 5 use std::thread::{self, ThreadId}; 7 6 8 7 use tokio::runtime::Builder; 9 8 use tokio::sync; 10 use tokio::time; 11 12 use clap::{Arg, App, ArgMatches}; 13 use isatty::stdout_isatty; 9 10 use clap::{App, Arg}; 14 11 use num_format::{Locale, ToFormattedString}; 15 12 use rand::Rng; 16 13 17 // ================================================== 18 struct BenchData { 19 clock_mode: bool, 20 stop: AtomicBool, 21 stop_count: u64, 22 duration: f64, 23 threads_left: AtomicU64, 24 } 25 26 impl BenchData { 27 fn new(options: ArgMatches, nthreads: usize) -> BenchData { 28 let (clock_mode, stop_count, duration) = if options.is_present("iterations") { 29 (false, 30 options.value_of("iterations").unwrap().parse::<u64>().unwrap(), 31 -1.0) 32 } else { 33 (true, 34 std::u64::MAX, 35 options.value_of("duration").unwrap().parse::<f64>().unwrap()) 36 }; 37 38 BenchData{ 39 clock_mode: clock_mode, 40 stop: AtomicBool::new(false), 41 stop_count: stop_count, 42 duration: duration, 43 threads_left: AtomicU64::new(nthreads as u64), 44 } 45 } 46 } 47 48 async fn wait(bench: &BenchData, start: &Instant, is_tty: bool) { 49 loop { 50 time::sleep(Duration::from_micros(100000)).await; 51 let delta = start.elapsed(); 52 if is_tty { 53 print!(" {:.1}\r", delta.as_secs_f32()); 54 io::stdout().flush().unwrap(); 55 } 56 if bench.clock_mode && delta >= Duration::from_secs_f64(bench.duration) { 57 break; 58 } 59 else if !bench.clock_mode && bench.threads_left.load(Ordering::Relaxed) == 0 { 60 break; 61 } 62 } 63 } 14 #[path = "../bench.rs"] 15 mod bench; 64 16 65 17 // ================================================== … … 240 192 } 241 193 242 async fn local(start: Arc<sync::Barrier>, idata: MyDataPtr, spots : Arc<Vec<MySpot>>, cnt: u64, share: bool, id: usize, bench: Arc<BenchData>) -> Result{194 async fn local(start: Arc<sync::Barrier>, idata: MyDataPtr, spots : Arc<Vec<MySpot>>, cnt: u64, share: bool, id: usize, exp: Arc<bench::BenchData>) -> Result{ 243 195 let mut state = rand::thread_rng().gen::<u64>(); 244 196 let mut data = idata; … … 267 219 // Check if the experiment is over 268 220 if closed { break } // yes, spot was closed 269 if bench.clock_mode && bench.stop.load(Ordering::Relaxed) { break } // yes, time's up270 if ! bench.clock_mode && r.count >= bench.stop_count { break } // yes, iterations reached221 if exp.clock_mode && exp.stop.load(Ordering::Relaxed) { break } // yes, time's up 222 if !exp.clock_mode && r.count >= exp.stop_count { break } // yes, iterations reached 271 223 272 224 assert_ne!(data.ptr as *const MyData, ptr::null()); … … 284 236 } 285 237 286 bench.threads_left.fetch_sub(1, Ordering::SeqCst);238 exp.threads_left.fetch_sub(1, Ordering::SeqCst); 287 239 r 288 240 } … … 292 244 fn main() { 293 245 let options = App::new("Locality Tokio") 294 .arg(Arg::with_name("duration") .short("d").long("duration") .takes_value(true).default_value("5").help("Duration of the experiments in seconds")) 295 .arg(Arg::with_name("iterations").short("i").long("iterations").takes_value(true).conflicts_with("duration").help("Number of iterations of the experiments")) 296 .arg(Arg::with_name("nthreads") .short("t").long("nthreads") .takes_value(true).default_value("1").help("Number of threads to use")) 297 .arg(Arg::with_name("nprocs") .short("p").long("nprocs") .takes_value(true).default_value("1").help("Number of processors to use")) 246 .args(&bench::args()) 298 247 .arg(Arg::with_name("size") .short("w").long("worksize") .takes_value(true).default_value("2").help("Size of the array for each threads, in words (64bit)")) 299 248 .arg(Arg::with_name("work") .short("c").long("workcnt") .takes_value(true).default_value("2").help("Number of words to touch when working (random pick, cells can be picked more than once)")) … … 315 264 assert_eq!(&s, "1,000,000"); 316 265 317 let bench = Arc::new(BenchData::new(options, nprocs));266 let exp = Arc::new(bench::BenchData::new(options, nprocs)); 318 267 let mut results = Result::new(); 319 268 … … 342 291 share, 343 292 i, 344 bench.clone(),293 exp.clone(), 345 294 )) 346 295 }).collect(); … … 349 298 println!("Starting"); 350 299 351 let is_tty = stdout_isatty();352 300 let start = Instant::now(); 353 301 barr.wait().await; 354 302 355 wait(&bench, &start, is_tty).await; 356 357 bench.stop.store(true, Ordering::SeqCst); 358 elapsed = start.elapsed(); 303 elapsed = exp.wait(&start).await; 359 304 360 305 println!("\nDone");
Note: See TracChangeset
for help on using the changeset viewer.