forked from ilya-zlobintsev/LACT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
244 lines (214 loc) · 5.87 KB
/
lib.rs
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#[cfg(feature = "args")]
pub mod args;
pub mod request;
mod response;
#[cfg(test)]
mod tests;
pub use amdgpu_sysfs;
pub use request::Request;
pub use response::Response;
use amdgpu_sysfs::{
gpu_handle::{
overdrive::{ClocksTable, ClocksTableGen},
PerformanceLevel,
},
hw_mon::Temperature,
};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap},
str::FromStr,
};
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum FanControlMode {
Static,
#[default]
Curve,
}
impl FromStr for FanControlMode {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"curve" => Ok(Self::Curve),
"static" => Ok(Self::Static),
_ => Err("unknown fan control mode".to_string()),
}
}
}
pub type FanCurveMap = BTreeMap<i32, f32>;
pub fn default_fan_curve() -> FanCurveMap {
[
(30, 0.0),
(40, 0.2),
(50, 0.35),
(60, 0.5),
(70, 0.75),
(80, 1.0),
]
.into()
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Pong;
#[derive(Serialize, Deserialize, Debug)]
pub struct SystemInfo<'a> {
pub version: &'a str,
pub profile: &'a str,
pub kernel_version: String,
pub amdgpu_overdrive_enabled: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DeviceListEntry<'a> {
pub id: &'a str,
pub name: Option<&'a str>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GpuPciInfo {
pub device_pci_info: PciInfo,
pub subsystem_pci_info: PciInfo,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DeviceInfo<'a> {
#[serde(borrow)]
pub pci_info: Option<Cow<'a, GpuPciInfo>>,
pub vulkan_info: Option<VulkanInfo>,
pub driver: &'a str,
pub vbios_version: Option<String>,
pub link_info: LinkInfo,
pub drm_info: Option<DrmInfo>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DrmInfo {
pub family_name: String,
pub asic_name: String,
pub chip_class: String,
pub compute_units: u32,
pub vram_type: String,
pub vram_bit_width: u32,
pub vram_max_bw: String,
pub l1_cache_per_cu: u32,
pub l2_cache: u32,
pub l3_cache_mb: u32,
pub memory_info: Option<DrmMemoryInfo>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DrmMemoryInfo {
pub cpu_accessible_used: u64,
pub cpu_accessible_total: u64,
pub resizeable_bar: bool,
}
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
pub struct ClocksInfo {
pub max_sclk: Option<i32>,
pub max_mclk: Option<i32>,
pub max_voltage: Option<i32>,
pub table: Option<ClocksTableGen>,
}
impl From<ClocksTableGen> for ClocksInfo {
fn from(table: ClocksTableGen) -> Self {
let max_sclk = table.get_max_sclk();
let max_mclk = table.get_max_mclk();
let max_voltage = table.get_max_sclk_voltage();
Self {
max_sclk,
max_mclk,
max_voltage,
table: Some(table),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LinkInfo {
pub current_width: Option<String>,
pub current_speed: Option<String>,
pub max_width: Option<String>,
pub max_speed: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VulkanInfo {
pub device_name: String,
pub api_version: String,
pub driver: VulkanDriverInfo,
pub enabled_layers: Vec<String>,
pub features: IndexMap<Cow<'static, str>, bool>,
pub extensions: IndexMap<Cow<'static, str>, bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VulkanDriverInfo {
pub version: u32,
pub name: Option<String>,
pub info: Option<String>,
pub driver_version: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PciInfo {
pub vendor_id: String,
pub vendor: Option<String>,
pub model_id: String,
pub model: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DeviceStats {
pub fan: FanStats,
pub clockspeed: ClockspeedStats,
pub voltage: VoltageStats,
pub vram: VramStats,
pub power: PowerStats,
pub temps: HashMap<String, Temperature>,
pub busy_percent: Option<u8>,
pub performance_level: Option<PerformanceLevel>,
pub core_power_state: Option<usize>,
pub memory_power_state: Option<usize>,
pub pcie_power_state: Option<usize>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FanStats {
pub control_enabled: bool,
pub control_mode: Option<FanControlMode>,
pub static_speed: Option<f64>,
pub curve: Option<FanCurveMap>,
pub speed_current: Option<u32>,
pub speed_max: Option<u32>,
pub speed_min: Option<u32>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct ClockspeedStats {
pub gpu_clockspeed: Option<u64>,
pub vram_clockspeed: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct VoltageStats {
pub gpu: Option<u64>,
pub northbridge: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct VramStats {
pub total: Option<u64>,
pub used: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct PowerStats {
pub average: Option<f64>,
pub current: Option<f64>,
pub cap_current: Option<f64>,
pub cap_max: Option<f64>,
pub cap_min: Option<f64>,
pub cap_default: Option<f64>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PowerStates {
pub core: Vec<PowerState<u64>>,
pub vram: Vec<PowerState<u64>>,
}
impl PowerStates {
pub fn is_empty(&self) -> bool {
self.core.is_empty() && self.vram.is_empty()
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct PowerState<T> {
pub enabled: bool,
pub value: T,
}