Skip to content

Commit

Permalink
Code format
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Oct 30, 2019
1 parent 0ebcbf3 commit 960fee6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 41 deletions.
4 changes: 1 addition & 3 deletions bastion-executor/examples/blocking_run.rs
@@ -1,14 +1,12 @@
use bastion_executor::prelude::*;
use lightproc::proc_stack::ProcStack;


fn main() {
run(
async {
println!("DATA");
panic!("kaka");
},
ProcStack::default()
.with_after_panic(|| {println!("after panic")}),
ProcStack::default().with_after_panic(|| println!("after panic")),
);
}
14 changes: 8 additions & 6 deletions bastion-executor/examples/spawn_async.rs
@@ -1,16 +1,18 @@
use bastion_executor::prelude::*;
use lightproc::proc_stack::ProcStack;


fn main() {
let pid = 1;
let stack = ProcStack::default()
.with_pid(pid)
.with_after_panic(move || {println!("after panic {}", pid.clone())});
.with_after_panic(move || println!("after panic {}", pid.clone()));

let handle = spawn(async {
panic!("test");
}, stack);
let handle = spawn(
async {
panic!("test");
},
stack,
);

let pid = 2;
let stack = ProcStack::default().with_pid(pid);
Expand All @@ -19,6 +21,6 @@ fn main() {
async {
handle.await;
},
stack.clone()
stack.clone(),
);
}
2 changes: 1 addition & 1 deletion bastion-executor/src/distributor.rs
Expand Up @@ -4,8 +4,8 @@ use super::run_queue::{Stealer, Worker};

use lightproc::prelude::*;

use std::thread;
use crate::worker;
use std::thread;

pub(crate) struct Distributor {
pub round: usize,
Expand Down
4 changes: 2 additions & 2 deletions bastion-executor/src/lib.rs
Expand Up @@ -11,13 +11,13 @@ pub mod distributor;
pub mod load_balancer;
pub mod placement;
pub mod pool;
pub mod run;
pub mod run_queue;
pub mod sleepers;
pub mod thread_recovery;
pub mod worker;
pub mod run;

pub mod prelude {
pub use crate::run::*;
pub use crate::pool::*;
pub use crate::run::*;
}
11 changes: 5 additions & 6 deletions bastion-executor/src/load_balancer.rs
@@ -1,15 +1,11 @@


use super::placement;
use lazy_static::*;


use std::{thread, time};


use super::load_balancer;
use crossbeam_utils::sync::ShardedLock;
use rustc_hash::FxHashMap;
use super::load_balancer;

const SIXTY_MILLIS: time::Duration = time::Duration::from_millis(60);

Expand All @@ -23,7 +19,10 @@ impl LoadBalancer {
loop {
let mut m = 0_usize;
if let Ok(stats) = load_balancer::stats().try_read() {
m = stats.smp_queues.values().sum::<usize>()
m = stats
.smp_queues
.values()
.sum::<usize>()
.wrapping_div(placement::get_core_ids().unwrap().len());
}

Expand Down
22 changes: 14 additions & 8 deletions bastion-executor/src/pool.rs
@@ -1,6 +1,5 @@
use super::distributor::Distributor;


use super::run_queue::{Injector, Stealer, Worker};
use super::sleepers::Sleepers;
use super::worker;
Expand Down Expand Up @@ -32,7 +31,9 @@ impl Pool {

pub fn fetch_proc(&self, affinity: usize, local: &Worker<LightProc>) -> Option<LightProc> {
if let Ok(mut stats) = load_balancer::stats().try_write() {
stats.smp_queues.insert(affinity, local.worker_run_queue_size());
stats
.smp_queues
.insert(affinity, local.worker_run_queue_size());
}

if let Ok(stats) = load_balancer::stats().try_read() {
Expand All @@ -41,13 +42,18 @@ impl Pool {
return Some(proc);
}
} else {
let affine_core =
*stats.smp_queues.iter()
.max_by_key(|&(_core, stat)| stat).unwrap().1;
let stealer =
self.stealers.get(affine_core).unwrap();
let affine_core = *stats
.smp_queues
.iter()
.max_by_key(|&(_core, stat)| stat)
.unwrap()
.1;
let stealer = self.stealers.get(affine_core).unwrap();
if let Some(amount) = stealer.run_queue_size().checked_sub(stats.mean_level) {
if let Some(proc) = stealer.steal_batch_and_pop_with_amount(local, amount.wrapping_add(1)).success() {
if let Some(proc) = stealer
.steal_batch_and_pop_with_amount(local, amount.wrapping_add(1))
.success()
{
return Some(proc);
}
}
Expand Down
27 changes: 12 additions & 15 deletions bastion-executor/src/run.rs
@@ -1,19 +1,18 @@
use std::future::Future;
use std::cell::UnsafeCell;
use std::cell::Cell;
use std::pin::Pin;
use std::{mem, panic};
use lightproc::proc_stack::ProcStack;
use super::worker;
use std::sync::Arc;
use crossbeam_utils::sync::Parker;
use lightproc::proc_stack::ProcStack;
use std::cell::Cell;
use std::cell::UnsafeCell;
use std::future::Future;
use std::mem::ManuallyDrop;
use std::task::{Waker, RawWaker, Context, Poll, RawWakerVTable};

use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use std::{mem, panic};

pub fn run<F, T>(future: F, stack: ProcStack) -> T
where
F: Future<Output = T>,
where
F: Future<Output = T>,
{
unsafe {
// A place on the stack where the result will be stored.
Expand Down Expand Up @@ -59,11 +58,9 @@ pub fn run<F, T>(future: F, stack: ProcStack) -> T
}
}



fn block<F, T>(f: F) -> T
where
F: Future<Output = T>,
where
F: Future<Output = T>,
{
thread_local! {
// May hold a pre-allocated parker that can be reused for efficiency.
Expand Down

0 comments on commit 960fee6

Please sign in to comment.