diff --git a/local/patches/base/P47-thermald-backend.patch b/local/patches/base/P47-thermald-backend.patch new file mode 100644 index 0000000000..1c0711dd11 --- /dev/null +++ b/local/patches/base/P47-thermald-backend.patch @@ -0,0 +1,110 @@ +--- a/drivers/thermald/src/main.rs 2026-05-20 17:21:01.313394180 +0300 ++++ b/drivers/thermald/src/main.rs 2026-05-20 17:16:58.080082312 +0300 +@@ -2 +2 @@ +-use std::{thread, time}; ++use std::{fs, thread, time}; +@@ -4,6 +4,36 @@ +-fn read_temp() -> Option { +- for zone in 0..4 { +- let path = format!("/scheme/acpi/thermal_zone/{}/temperature", zone); +- if let Ok(data) = std::fs::read_to_string(&path) { +- if let Ok(mv) = data.trim().parse::() { +- return Some(mv as f32 / 1000.0); ++const THERMAL_POLL_S: u64 = 5; ++const CRITICAL_TEMP: f32 = 85.0; ++const WARNING_TEMP: f32 = 70.0; ++ ++fn read_acpi_thermal_zones() -> Vec<(String, f32)> { ++ let mut temps = Vec::new(); ++ if let Ok(entries) = fs::read_dir("/scheme/acpi/thermal") { ++ for entry in entries.flatten() { ++ let name = entry.file_name().into_string().unwrap_or_default(); ++ if name.starts_with('.') { ++ continue; ++ } ++ let path = format!("/scheme/acpi/thermal/{}/temperature", name); ++ if let Ok(data) = fs::read_to_string(&path) { ++ if let Ok(temp_c) = data.trim().parse::() { ++ temps.push((name, temp_c)); ++ } ++ } ++ } ++ } ++ temps ++} ++ ++fn read_coretemp_cpus() -> Vec<(String, f32)> { ++ let mut temps = Vec::new(); ++ if let Ok(entries) = fs::read_dir("/scheme/coretemp") { ++ for entry in entries.flatten() { ++ let name = entry.file_name().into_string().unwrap_or_default(); ++ if name.starts_with('.') || !name.starts_with("cpu") { ++ continue; ++ } ++ let path = format!("/scheme/coretemp/{}/temperature", name); ++ if let Ok(data) = fs::read_to_string(&path) { ++ if let Ok(temp_c) = data.trim().parse::() { ++ temps.push((name, temp_c)); ++ } +@@ -13 +43 @@ +- None ++ temps +@@ -17,2 +47,7 @@ +- common::setup_logging("system", "thermald", "thermald", +- common::output_level(), common::file_level()); ++ common::setup_logging( ++ "system", ++ "thermald", ++ "thermald", ++ common::output_level(), ++ common::file_level(), ++ ); +@@ -19,0 +55 @@ ++ +@@ -21,5 +57,17 @@ +- if let Some(temp) = read_temp() { +- if temp > 85.0 { +- log::error!("thermald: CRITICAL {:.1}C", temp); +- } else if temp > 70.0 { +- log::warn!("thermald: WARNING {:.1}C", temp); ++ let acpi_temps = read_acpi_thermal_zones(); ++ let cpu_temps = read_coretemp_cpus(); ++ ++ let mut max_temp: f32 = 0.0; ++ let mut max_source = String::new(); ++ ++ for (name, temp) in &acpi_temps { ++ if *temp > max_temp { ++ max_temp = *temp; ++ max_source = format!("ACPI {}", name); ++ } ++ if *temp > CRITICAL_TEMP { ++ log::error!("thermald: CRITICAL ACPI {} = {:.1}C", name, temp); ++ } else if *temp > WARNING_TEMP { ++ log::warn!("thermald: WARNING ACPI {} = {:.1}C", name, temp); ++ } else { ++ log::debug!("thermald: ACPI {} = {:.1}C", name, temp); +@@ -28 +76,22 @@ +- thread::sleep(time::Duration::from_secs(5)); ++ ++ for (name, temp) in &cpu_temps { ++ if *temp > max_temp { ++ max_temp = *temp; ++ max_source = format!("coretemp {}", name); ++ } ++ if *temp > CRITICAL_TEMP { ++ log::error!("thermald: CRITICAL CPU {} = {:.1}C", name, temp); ++ } else if *temp > WARNING_TEMP { ++ log::warn!("thermald: WARNING CPU {} = {:.1}C", name, temp); ++ } else { ++ log::debug!("thermald: CPU {} = {:.1}C", name, temp); ++ } ++ } ++ ++ if max_temp > 0.0 { ++ log::info!("thermald: max temp = {:.1}C from {}", max_temp, max_source); ++ } else { ++ log::warn!("thermald: no temperature sources available"); ++ } ++ ++ thread::sleep(time::Duration::from_secs(THERMAL_POLL_S)); diff --git a/recipes/core/base/recipe.toml b/recipes/core/base/recipe.toml index 914d82b1b9..cfc97cfe1f 100644 --- a/recipes/core/base/recipe.toml +++ b/recipes/core/base/recipe.toml @@ -93,6 +93,8 @@ patches = [ "P45-net-msix-adoption.patch", # P46: Migrate ahcid and ac97d to MSI-X via pci_allocate_interrupt_vector "P46-storage-audio-msix.patch", + # P47: Update thermald to read from P44 thermal zones and coretempd + "P47-thermald-backend.patch", ] [package]