From ed7c634d8129ecd02c77e5e23a23dbac18914873 Mon Sep 17 00:00:00 2001 From: Matthieu Le brazidec Date: Wed, 13 Nov 2019 02:51:30 +0100 Subject: [PATCH 1/2] Cleaned up bastion-executor and lightproc's dependencies imports and replaced rustc_hash with fxhash. --- bastion-executor/Cargo.toml | 2 +- bastion-executor/src/distributor.rs | 9 +++------ bastion-executor/src/load_balancer.rs | 11 ++++------- bastion-executor/src/pool.rs | 12 +++++------- bastion-executor/src/run.rs | 5 ++--- bastion-executor/src/run_queue.rs | 13 +++---------- bastion-executor/src/worker.rs | 13 ++++--------- lightproc/src/proc_stack.rs | 1 - 8 files changed, 22 insertions(+), 44 deletions(-) diff --git a/bastion-executor/Cargo.toml b/bastion-executor/Cargo.toml index bec4b6ee..67e96d58 100644 --- a/bastion-executor/Cargo.toml +++ b/bastion-executor/Cargo.toml @@ -22,10 +22,10 @@ unstable = ["numanji", "allocator-suite", "jemallocator"] [dependencies] crossbeam-utils = "0.6" crossbeam-epoch = "0.7" +fxhash = "0.2" lazy_static = "1.4" libc = "0.2" num_cpus = "1.10" -rustc-hash = "1.0.1" pin-utils = "0.1.0-alpha.4" lightproc = { version = "= 0.3.3-alpha.1", "path" = "../lightproc" } diff --git a/bastion-executor/src/distributor.rs b/bastion-executor/src/distributor.rs index d3d2996a..d4e873dc 100644 --- a/bastion-executor/src/distributor.rs +++ b/bastion-executor/src/distributor.rs @@ -3,13 +3,10 @@ //! //! Distributor provides a fair distribution of threads and pinning them to cores for fair execution. //! It assigns threads in round-robin fashion to all cores. -use super::placement; -use super::placement::CoreId; -use super::run_queue::{Stealer, Worker}; - -use lightproc::prelude::*; - +use crate::placement::{self, CoreId}; +use crate::run_queue::{Stealer, Worker}; use crate::worker; +use lightproc::prelude::*; use std::thread; pub(crate) struct Distributor { diff --git a/bastion-executor/src/load_balancer.rs b/bastion-executor/src/load_balancer.rs index 78cc741b..68b910f6 100644 --- a/bastion-executor/src/load_balancer.rs +++ b/bastion-executor/src/load_balancer.rs @@ -4,15 +4,12 @@ //! Load balancer calculates sampled mean to provide average process execution amount //! to all runtime. //! - -use super::placement; +use crate::load_balancer; +use crate::placement; +use crossbeam_utils::sync::ShardedLock; +use fxhash::FxHashMap; use lazy_static::*; - use std::thread; - -use super::load_balancer; -use crossbeam_utils::sync::ShardedLock; -use rustc_hash::FxHashMap; use std::time::Duration; /// diff --git a/bastion-executor/src/pool.rs b/bastion-executor/src/pool.rs index 79070ae0..217f2438 100644 --- a/bastion-executor/src/pool.rs +++ b/bastion-executor/src/pool.rs @@ -4,13 +4,11 @@ //! Pool management and tracking belongs here. //! We spawn futures onto the pool with [spawn] method of global run queue or //! with corresponding [Worker]'s spawn method. - -use super::distributor::Distributor; - -use super::run_queue::{Injector, Stealer}; -use super::sleepers::Sleepers; -use super::worker; -use lazy_static::*; +use crate::distributor::Distributor; +use crate::run_queue::{Injector, Stealer}; +use crate::sleepers::Sleepers; +use crate::worker; +use lazy_static::lazy_static; use lightproc::prelude::*; use std::future::Future; diff --git a/bastion-executor/src/run.rs b/bastion-executor/src/run.rs index 35881bcf..4a3d5757 100644 --- a/bastion-executor/src/run.rs +++ b/bastion-executor/src/run.rs @@ -2,11 +2,10 @@ //! Blocking run of the async processes //! //! -use super::worker; +use crate::worker; use crossbeam_utils::sync::Parker; use lightproc::proc_stack::ProcStack; -use std::cell::Cell; -use std::cell::UnsafeCell; +use std::cell::{Cell, UnsafeCell}; use std::future::Future; use std::mem::ManuallyDrop; use std::pin::Pin; diff --git a/bastion-executor/src/run_queue.rs b/bastion-executor/src/run_queue.rs index 5e7b7f60..41392dac 100644 --- a/bastion-executor/src/run_queue.rs +++ b/bastion-executor/src/run_queue.rs @@ -51,22 +51,15 @@ //! [`steal()`]: struct.Stealer.html#method.steal //! [`steal_batch()`]: struct.Stealer.html#method.steal_batch //! [`steal_batch_and_pop()`]: struct.Stealer.html#method.steal_batch_and_pop - -extern crate crossbeam_epoch as epoch; -extern crate crossbeam_utils as utils; - +use crossbeam_epoch::{self as epoch, Atomic, Owned}; +use crossbeam_utils::{Backoff, CachePadded}; use std::cell::{Cell, UnsafeCell}; -use std::cmp; -use std::fmt; use std::iter::FromIterator; use std::marker::PhantomData; use std::mem::{self, ManuallyDrop}; -use std::ptr; use std::sync::atomic::{self, AtomicIsize, AtomicPtr, AtomicUsize, Ordering}; use std::sync::Arc; - -use epoch::{Atomic, Owned}; -use utils::{Backoff, CachePadded}; +use std::{cmp, fmt, ptr}; // Minimum buffer capacity. const MIN_CAP: usize = 64; diff --git a/bastion-executor/src/worker.rs b/bastion-executor/src/worker.rs index 992d2307..d0191daf 100644 --- a/bastion-executor/src/worker.rs +++ b/bastion-executor/src/worker.rs @@ -3,17 +3,12 @@ //! //! This worker implementation relies on worker run queue statistics which are hold in the pinned global memory //! where workload distribution calculated and amended to their own local queues. - -use std::cell::{Cell, UnsafeCell}; -use std::ptr; - -use super::pool; -use super::run_queue::Worker; use crate::load_balancer; -use crate::pool::Pool; -use crate::run_queue::Steal; -use core::iter; +use crate::pool::{self, Pool}; +use crate::run_queue::{Steal, Worker}; use lightproc::prelude::*; +use std::cell::{Cell, UnsafeCell}; +use std::{iter, ptr}; /// /// Get the current process's stack diff --git a/lightproc/src/proc_stack.rs b/lightproc/src/proc_stack.rs index b71cbfda..3e068fc2 100644 --- a/lightproc/src/proc_stack.rs +++ b/lightproc/src/proc_stack.rs @@ -5,7 +5,6 @@ //! //! If we want to make an analogy, stack abstraction is similar to actor lifecycle abstractions //! in frameworks like Akka, but tailored version for Rust environment. - use std::fmt::{self, Debug, Formatter}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; From bcbc192c3e021573bcd452fcc2ca7033296318b4 Mon Sep 17 00:00:00 2001 From: Matthieu Le brazidec Date: Wed, 13 Nov 2019 02:57:29 +0100 Subject: [PATCH 2/2] Updated Pool and Distributor's fields visibility, updated Distributor's methods visibility and fixed a typo. --- bastion-executor/src/distributor.rs | 6 +++--- bastion-executor/src/load_balancer.rs | 4 ++-- bastion-executor/src/pool.rs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bastion-executor/src/distributor.rs b/bastion-executor/src/distributor.rs index d4e873dc..6097362d 100644 --- a/bastion-executor/src/distributor.rs +++ b/bastion-executor/src/distributor.rs @@ -10,17 +10,17 @@ use lightproc::prelude::*; use std::thread; pub(crate) struct Distributor { - pub cores: Vec, + pub(crate) cores: Vec, } impl Distributor { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Distributor { cores: placement::get_core_ids().expect("Core mapping couldn't be fetched"), } } - pub fn assign(self) -> Vec> { + pub(crate) fn assign(self) -> Vec> { let mut stealers = Vec::>::new(); for core in self.cores { diff --git a/bastion-executor/src/load_balancer.rs b/bastion-executor/src/load_balancer.rs index 68b910f6..a6d0e485 100644 --- a/bastion-executor/src/load_balancer.rs +++ b/bastion-executor/src/load_balancer.rs @@ -13,9 +13,9 @@ use std::thread; use std::time::Duration; /// -/// Loadbalancer struct which is just a convenience wrapper over the statistics calculations. +/// Load-balancer struct which is just a convenience wrapper over the statistics calculations. #[derive(Debug)] -pub struct LoadBalancer(); +pub struct LoadBalancer; impl LoadBalancer { /// diff --git a/bastion-executor/src/pool.rs b/bastion-executor/src/pool.rs index 217f2438..c92e1583 100644 --- a/bastion-executor/src/pool.rs +++ b/bastion-executor/src/pool.rs @@ -51,13 +51,13 @@ where pub struct Pool { /// /// Global run queue implementation - pub injector: Injector, + pub(crate) injector: Injector, /// /// Stealers of the workers - pub stealers: Vec>, + pub(crate) stealers: Vec>, /// /// Container of parked threads - pub sleepers: Sleepers, + pub(crate) sleepers: Sleepers, } impl Pool {