Use junction temperature when available

This commit is contained in:
Ilya Zlobintsev 2021-08-13 11:59:30 +03:00
parent 438e4200a7
commit a7d203c7d5
2 changed files with 22 additions and 10 deletions

View File

@ -236,26 +236,29 @@ impl HWMon {
while s.fan_control.load(Ordering::SeqCst) {
let temps = s.get_temps();
log::trace!("Temps: {:?}", temps);
let edge_temps = temps.get("edge").unwrap();
// Use junction temp when available, otherwise fall back to edge
let temps = match temps.get("junction") {
Some(temp) => temp,
None => temps.get("edge").unwrap(),
};
let temp = edge_temps.current;
if temp >= edge_temps.crit || temp <= edge_temps.crit_hyst {
if temps.current >= temps.crit || temps.current <= temps.crit_hyst {
println!("CRITICAL TEMPERATURE DETECTED! FORCING MAX FAN SPEED");
fs::write(s.hwmon_path.join("pwm1"), 255.to_string())
.expect("Failed to set gpu temp in critical scenario (Warning: GPU Overheating!)");
}
log::trace!("Current gpu temp: {}", temp);
log::trace!("Current gpu temp: {}", temps.current);
let curve = s.fan_curve.read().unwrap();
for (t_low, s_low) in curve.iter() {
match curve.range(t_low..).nth(1) {
Some((t_high, s_high)) => {
if (t_low..t_high).contains(&&temp) {
if (t_low..t_high).contains(&&temps.current) {
let speed_ratio =
(temp - t_low) as f64 / (t_high - t_low) as f64; //The ratio of which speed to choose within the range of current lower and upper speeds
(temps.current - t_low) as f64 / (t_high - t_low) as f64; //The ratio of which speed to choose within the range of current lower and upper speeds
let speed_percent =
s_low + ((s_high - s_low) * speed_ratio);
let pwm = (255f64 * (speed_percent / 100f64)) as i64;

View File

@ -173,10 +173,19 @@ impl StatsGrid {
stats.power_avg.unwrap_or_else(|| 0),
stats.power_cap.unwrap_or_else(|| 0)
));
if let Some(temp) = stats.temperatures.get("edge") {
self.gpu_temperature_label
.set_markup(&format!("<b>{}°C</b>", temp.current));
let temp = match stats.temperatures.get("junction") {
Some(temp) => Some(temp.current),
None => match stats.temperatures.get("edge") {
Some(temp) => Some(temp.current),
None => None,
}
};
if let Some(temp) = temp {
self.gpu_temperature_label.set_markup(&format!("<b>{}°C</b>", temp));
}
self.gpu_usage_label
.set_markup(&format!("<b>{}%</b>", stats.gpu_usage.unwrap_or_default()));
}