1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use self::sched::SchedStats;
use super::*;
use crate::machine_impl::*;
use crossbeam::deque;
use d3_derive::*;
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub enum MonitorMessage {
Terminate,
AddSender(CoreStatsSender),
RemoveSender(CoreStatsSender),
Parked(usize),
Terminated(usize),
ExecutorStats(ExecutorStats),
SchedStats(SchedStats),
}
pub type MonitorSender = crossbeam::channel::Sender<MonitorMessage>;
#[derive(Debug, Copy, Clone, MachineImpl)]
pub enum CoreStatsMessage {
ExecutorStats(ExecutorStats),
SchedStats(SchedStats),
}
pub type CoreStatsSender = Sender<CoreStatsMessage>;
pub trait MonitorFactory {
fn get_sender(&self) -> MonitorSender;
fn start(&self, executor: ExecutorControlObj) -> MonitorControlObj;
}
pub type MonitorFactoryObj = Arc<dyn MonitorFactory>;
pub trait MonitorControl: Send + Sync {
fn stop(&self);
fn add_sender(&self, sender: CoreStatsSender);
fn remove_sender(&self, sender: CoreStatsSender);
}
pub type MonitorControlObj = Arc<dyn MonitorControl>;
pub trait ExecutorFactory {
fn with_workers(&self, workers: usize);
fn get_queues(&self) -> (TaskInjector, SchedTaskInjector);
fn start(&self, monitor: MonitorSender, scheduler: SchedSender) -> ExecutorControlObj;
}
pub type ExecutorFactoryObj = Arc<dyn ExecutorFactory>;
pub type TaskInjector = Arc<deque::Injector<Task>>;
pub type SchedTaskInjector = Arc<deque::Injector<SchedTask>>;
pub trait ExecutorControl: Send + Sync {
fn parked_executor(&self, id: usize);
fn wake_parked_threads(&self);
fn joinable_executor(&self, id: usize);
fn stop(&self);
}
pub type ExecutorControlObj = Arc<dyn ExecutorControl>;
#[allow(dead_code)]
pub enum SchedCmd {
Start,
Stop,
Terminate(bool),
New(MachineAdapter),
Waiting(usize),
Remove(usize),
ErrorRecv(usize),
RecvBlock(usize, Instant),
RebuildStealers,
}
pub type SchedSender = crossbeam::channel::Sender<SchedCmd>;
pub type SchedReceiver = crossbeam::channel::Receiver<SchedCmd>;
pub trait SchedulerFactory {
fn get_sender(&self) -> SchedSender;
fn start(&self, monitor: MonitorSender, queues: (TaskInjector, SchedTaskInjector)) -> Arc<dyn Scheduler>;
}
pub trait Scheduler: Send + Sync {
fn assign_machine(&self, machine: MachineAdapter);
fn stop(&self);
}