dope_runtime/process/failure/
bus.rs1use std::mem;
2
3use dope_core::platform::affinity;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6#[repr(u32)]
7pub enum Event {
8 Installed,
9 Ready,
10 Drain,
11 Done,
12 Failed,
13}
14
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16#[repr(transparent)]
17pub struct Invalid(u32);
18
19#[derive(Clone, Copy, Debug, PartialEq, Eq)]
20pub struct RecordSize {
21 pub expected: usize,
22 pub actual: usize,
23}
24
25#[derive(Debug)]
26pub struct Startup {
27 pub cpu: affinity::Cpu,
28 pub event: Event,
29 pub workers: usize,
30 pub installed: usize,
31 pub ready: usize,
32 pub gated: bool,
33}
34
35#[derive(Debug)]
36pub struct Drain {
37 pub cause: DrainCause,
38 pub workers: usize,
39 pub drained: usize,
40 pub done: usize,
41}
42
43#[derive(Debug)]
44pub enum DrainCause {
45 Event { cpu: affinity::Cpu, event: Event },
46 Order,
47}
48
49#[derive(Debug)]
50pub struct Shutdown {
51 pub cpu: affinity::Cpu,
52 pub event: Event,
53 pub workers: usize,
54 pub done: usize,
55}
56
57impl Event {
58 pub(in crate::process) const fn encode(self) -> u32 {
59 self as u32
60 }
61
62 pub(in crate::process) const fn decode(value: u32) -> Result<Self, Invalid> {
63 match value {
64 0 => Ok(Self::Installed),
65 1 => Ok(Self::Ready),
66 2 => Ok(Self::Drain),
67 3 => Ok(Self::Done),
68 4 => Ok(Self::Failed),
69 value => Err(Invalid(value)),
70 }
71 }
72}
73
74#[derive(Clone, Copy, Debug, PartialEq, Eq)]
75pub enum Write {
76 Syscall(dope_core::Errno),
77 Record(RecordSize),
78}
79
80#[derive(Clone, Copy, Debug, PartialEq, Eq)]
81pub struct Fault {
82 pub event: Event,
83 pub failure: Write,
84 pub shutdown: Option<dope_core::Errno>,
85}
86
87#[derive(Debug)]
88pub enum Report {
89 Clean,
90 Failed(Fault),
91}
92
93#[derive(Debug)]
94pub struct Sequence {
95 pub gated: bool,
96 pub previous: Option<Event>,
97 pub event: Event,
98}
99
100#[derive(Debug)]
101pub enum Read {
102 Syscall(dope_core::Errno),
103 Stopped(dope_core::Errno),
105 Closed,
106 Record(RecordSize),
107 Event(Invalid),
108 Sequence(Sequence),
109}
110
111#[derive(Debug)]
112pub enum State {
113 StartupEvent(Startup),
114 RuntimeEvent { cpu: affinity::Cpu, event: Event },
115 DrainEvent(Drain),
116 DrainOrder(Drain),
117 ShutdownEvent(Shutdown),
118}
119
120const _: () = {
121 assert!(mem::size_of::<Event>() == mem::size_of::<u32>());
122 assert!(mem::size_of::<Invalid>() == mem::size_of::<u32>());
123};