-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
lib.rs
356 lines (315 loc) · 9.24 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#[cfg(feature = "args")]
pub mod args;
pub mod request;
mod response;
#[cfg(test)]
mod tests;
pub use request::Request;
pub use response::Response;
use amdgpu_sysfs::{
gpu_handle::{
fan_control::FanInfo,
overdrive::{ClocksTable as _, ClocksTableGen as AmdClocksTableGen},
PerformanceLevel,
},
hw_mon::Temperature,
};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap},
fmt,
str::FromStr,
};
pub const GIT_COMMIT: &str = env!("VERGEN_GIT_SHA");
#[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 {
[(40, 0.2), (50, 0.35), (60, 0.5), (70, 0.75), (80, 1.0)].into()
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Pong;
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug)]
pub struct SystemInfo {
pub version: String,
pub commit: Option<String>,
pub profile: String,
pub kernel_version: String,
pub amdgpu_overdrive_enabled: Option<bool>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DeviceListEntry {
pub id: String,
pub name: Option<String>,
}
impl fmt::Display for DeviceListEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.name {
Some(name) => name.fmt(f),
None => self.id.fmt(f),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GpuPciInfo {
pub device_pci_info: PciInfo,
pub subsystem_pci_info: PciInfo,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DeviceInfo {
pub pci_info: Option<GpuPciInfo>,
pub vulkan_info: Option<VulkanInfo>,
pub driver: String,
pub vbios_version: Option<String>,
pub link_info: LinkInfo,
pub drm_info: Option<DrmInfo>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DrmInfo {
pub device_name: Option<String>,
pub pci_revision_id: Option<u32>,
pub family_name: Option<String>,
pub family_id: Option<u32>,
pub asic_name: Option<String>,
pub chip_class: Option<String>,
pub compute_units: Option<u32>,
pub cuda_cores: Option<u32>,
pub vram_type: Option<String>,
pub vram_clock_ratio: f64,
pub vram_bit_width: Option<u32>,
pub vram_max_bw: Option<String>,
pub l1_cache_per_cu: Option<u32>,
pub l2_cache: Option<u32>,
pub l3_cache_mb: Option<u32>,
pub memory_info: Option<DrmMemoryInfo>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DrmMemoryInfo {
pub cpu_accessible_used: u64,
pub cpu_accessible_total: u64,
pub resizeable_bar: Option<bool>,
}
#[skip_serializing_none]
#[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<ClocksTable>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
pub enum ClocksTable {
Amd(AmdClocksTableGen),
Nvidia(NvidiaClocksTable),
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
pub struct NvidiaClocksTable {
pub gpc: Option<NvidiaClockInfo>,
pub mem: Option<NvidiaClockInfo>,
}
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
pub struct NvidiaClockInfo {
pub max: i32,
pub offset: i32,
pub offset_range: (i32, i32),
}
impl From<AmdClocksTableGen> for ClocksInfo {
fn from(table: AmdClocksTableGen) -> 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(ClocksTable::Amd(table)),
}
}
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
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>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VulkanDriverInfo {
pub version: u32,
pub name: Option<String>,
pub info: Option<String>,
pub driver_version: Option<String>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PciInfo {
pub vendor_id: String,
pub vendor: Option<String>,
pub model_id: String,
pub model: Option<String>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
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>,
pub throttle_info: Option<BTreeMap<String, Vec<String>>>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct FanStats {
pub control_enabled: bool,
pub control_mode: Option<FanControlMode>,
pub static_speed: Option<f64>,
pub curve: Option<FanCurveMap>,
pub pwm_current: Option<u8>,
pub speed_current: Option<u32>,
pub speed_max: Option<u32>,
pub speed_min: Option<u32>,
pub spindown_delay_ms: Option<u64>,
pub change_threshold: Option<u64>,
// RDNA3+ params
#[serde(default)]
pub pmfw_info: PmfwInfo,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct PmfwInfo {
pub acoustic_limit: Option<FanInfo>,
pub acoustic_target: Option<FanInfo>,
pub target_temp: Option<FanInfo>,
pub minimum_pwm: Option<FanInfo>,
pub zero_rpm_enable: Option<bool>,
pub zero_rpm_temperature: Option<FanInfo>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct ClockspeedStats {
pub gpu_clockspeed: Option<u64>,
pub current_gfxclk: Option<u16>,
pub vram_clockspeed: Option<u64>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct VoltageStats {
pub gpu: Option<u64>,
pub northbridge: Option<u64>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
pub struct VramStats {
pub total: Option<u64>,
pub used: Option<u64>,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
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, Default)]
pub struct PowerStates {
pub core: Vec<PowerState>,
pub vram: Vec<PowerState>,
}
impl PowerStates {
pub fn is_empty(&self) -> bool {
self.core.is_empty() && self.vram.is_empty()
}
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct PowerState {
pub enabled: bool,
pub min_value: Option<u64>,
pub value: u64,
pub index: Option<u8>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub enum InitramfsType {
Debian,
Mkinitcpio,
Dracut,
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct PmfwOptions {
pub acoustic_limit: Option<u32>,
pub acoustic_target: Option<u32>,
pub minimum_pwm: Option<u32>,
pub target_temperature: Option<u32>,
pub zero_rpm: Option<bool>,
pub zero_rpm_threshold: Option<u32>,
}
impl PmfwOptions {
pub fn is_empty(&self) -> bool {
*self == Self::default()
}
}
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub struct FanOptions<'a> {
pub id: &'a str,
pub enabled: bool,
pub mode: Option<FanControlMode>,
pub static_speed: Option<f64>,
pub curve: Option<FanCurveMap>,
#[serde(default)]
pub pmfw: PmfwOptions,
pub spindown_delay_ms: Option<u64>,
pub change_threshold: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub struct ProfilesInfo {
pub profiles: Vec<String>,
pub current_profile: Option<String>,
}