Compare target pwm value to pwm1_min and pwm1_max instead of fan rpm
- Add PWM values to monitor
This commit is contained in:
parent
0794605006
commit
73a0a4d7fc
56
src/main.rs
56
src/main.rs
@ -27,6 +27,8 @@ pub struct HwMon {
|
|||||||
name: String,
|
name: String,
|
||||||
fan_min: Option<u32>,
|
fan_min: Option<u32>,
|
||||||
fan_max: Option<u32>,
|
fan_max: Option<u32>,
|
||||||
|
pwm_min: Option<u32>,
|
||||||
|
pwm_max: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HwMon {
|
impl HwMon {
|
||||||
@ -36,6 +38,8 @@ impl HwMon {
|
|||||||
name: String::from(name),
|
name: String::from(name),
|
||||||
fan_min: None,
|
fan_min: None,
|
||||||
fan_max: None,
|
fan_max: None,
|
||||||
|
pwm_min: None,
|
||||||
|
pwm_max: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,10 +73,10 @@ impl HwMon {
|
|||||||
self.read("fan1_max")
|
self.read("fan1_max")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap_or(255),
|
.unwrap_or(1500),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
self.fan_max.unwrap_or(255)
|
self.fan_max.unwrap_or(1500)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fan_speed(&self) -> std::io::Result<u64> {
|
pub fn fan_speed(&self) -> std::io::Result<u64> {
|
||||||
@ -82,6 +86,37 @@ impl HwMon {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pwm_min(&mut self) -> u32 {
|
||||||
|
if self.pwm_min.is_none() {
|
||||||
|
self.pwm_min = Some(
|
||||||
|
self.read("pwm1_min")
|
||||||
|
.unwrap_or_default()
|
||||||
|
.parse()
|
||||||
|
.unwrap_or(0),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
self.pwm_min.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pwm_max(&mut self) -> u32 {
|
||||||
|
if self.pwm_max.is_none() {
|
||||||
|
self.pwm_max = Some(
|
||||||
|
self.read("pwm1_max")
|
||||||
|
.unwrap_or_default()
|
||||||
|
.parse()
|
||||||
|
.unwrap_or(255),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
self.pwm_max.unwrap_or(255)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pwm_speed(&self) -> std::io::Result<u64> {
|
||||||
|
self.read("pwm1")?.parse().map_err(|_e| {
|
||||||
|
log::warn!("Read from gpu monitor failed. Invalid fan speed");
|
||||||
|
std::io::Error::from(ErrorKind::InvalidInput)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_fan_manual(&self) -> bool {
|
pub fn is_fan_manual(&self) -> bool {
|
||||||
self.read("pwm1_enable")
|
self.read("pwm1_enable")
|
||||||
.map(|s| s.as_str() == "1")
|
.map(|s| s.as_str() == "1")
|
||||||
@ -288,13 +323,13 @@ fn service(config: Config) -> std::io::Result<()> {
|
|||||||
for controller in controllers.iter_mut() {
|
for controller in controllers.iter_mut() {
|
||||||
let gpu_temp = controller.hw_mon.gpu_temp().unwrap_or_default();
|
let gpu_temp = controller.hw_mon.gpu_temp().unwrap_or_default();
|
||||||
|
|
||||||
let speed = config.speed_for_temp(gpu_temp);
|
let target_pwm = config.speed_for_temp(gpu_temp);
|
||||||
if controller.hw_mon.fan_min() > speed || controller.hw_mon.fan_max() < speed {
|
if controller.hw_mon.pwm_min() > target_pwm || controller.hw_mon.pwm_max() < target_pwm {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = controller.hw_mon.set_speed(speed as u64) {
|
if let Err(e) = controller.hw_mon.set_speed(target_pwm as u64) {
|
||||||
log::error!("Failed to change speed to {}. {:?}", speed, e);
|
log::error!("Failed to change speed to {}. {:?}", target_pwm, e);
|
||||||
}
|
}
|
||||||
controller.last_temp = gpu_temp;
|
controller.last_temp = gpu_temp;
|
||||||
}
|
}
|
||||||
@ -342,15 +377,18 @@ fn monitor_cards(config: Config) -> std::io::Result<()> {
|
|||||||
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
|
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
|
||||||
for card in controllers.iter_mut() {
|
for card in controllers.iter_mut() {
|
||||||
println!(
|
println!(
|
||||||
"Card {:3} | Temp | fan speed | MAX | MIN ",
|
"Card {:3} | Temp | RPM | MIN | MAX | PWM ({}-{})",
|
||||||
card.hw_mon.card.0
|
card.hw_mon.card.to_string().replace("card", ""),
|
||||||
|
card.hw_mon.pwm_min(),
|
||||||
|
card.hw_mon.pwm_max()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
" | {:>5.2} | {:>9} | {:>4} | {:>4}",
|
" | {:>5.2} | {:>4} | {:>4} | {:>4} | {:>4}",
|
||||||
card.hw_mon.gpu_temp().unwrap_or_default(),
|
card.hw_mon.gpu_temp().unwrap_or_default(),
|
||||||
card.hw_mon.fan_speed().unwrap_or_default(),
|
card.hw_mon.fan_speed().unwrap_or_default(),
|
||||||
card.hw_mon.fan_min(),
|
card.hw_mon.fan_min(),
|
||||||
card.hw_mon.fan_max(),
|
card.hw_mon.fan_max(),
|
||||||
|
card.hw_mon.pwm_speed().unwrap_or_default(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
std::thread::sleep(std::time::Duration::from_secs(4));
|
std::thread::sleep(std::time::Duration::from_secs(4));
|
||||||
|
Loading…
Reference in New Issue
Block a user