From 207dddff9e0d42d6de494c9524dbac006fdd1145 Mon Sep 17 00:00:00 2001 From: vasilito Date: Wed, 8 Jul 2026 01:14:05 +0300 Subject: [PATCH] thermald: use Redox /scheme/sys/msr for CPU temperature reads --- .../system/thermald/source/src/main.rs | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/local/recipes/system/thermald/source/src/main.rs b/local/recipes/system/thermald/source/src/main.rs index f8808fbecc..227e210f4a 100644 --- a/local/recipes/system/thermald/source/src/main.rs +++ b/local/recipes/system/thermald/source/src/main.rs @@ -189,27 +189,55 @@ fn zone_name_for_entry(entry: &fs::DirEntry) -> Option { } fn read_msr(cpu: u32, msr: u32) -> Option { - let path = format!("/dev/cpu/{cpu}/msr"); - let mut file = fs::File::open(&path).ok()?; - let mut buf = [0u8; 8]; - use std::io::{Read, Seek, SeekFrom}; - file.seek(SeekFrom::Start(msr as u64)).ok()?; - file.read_exact(&mut buf).ok()?; - Some(u64::from_le_bytes(buf)) + #[cfg(target_os = "redox")] + { + let path = format!("/scheme/sys/msr/{}/0x{:x}", cpu, msr); + let mut file = fs::File::open(&path).ok()?; + let mut buf = [0u8; 8]; + use std::io::Read; + file.read_exact(&mut buf).ok()?; + Some(u64::from_le_bytes(buf)) + } + #[cfg(not(target_os = "redox"))] + { + let path = format!("/dev/cpu/{cpu}/msr"); + let mut file = fs::File::open(&path).ok()?; + let mut buf = [0u8; 8]; + use std::io::{Read, Seek, SeekFrom}; + file.seek(SeekFrom::Start(msr as u64)).ok()?; + file.read_exact(&mut buf).ok()?; + Some(u64::from_le_bytes(buf)) + } } fn cpu_count() -> u32 { - let mut count = 0u32; - if let Ok(entries) = fs::read_dir("/dev/cpu") { - for entry in entries.filter_map(Result::ok) { - if let Ok(name) = entry.file_name().into_string() { - if name.parse::().is_ok() { - count += 1; + #[cfg(target_os = "redox")] + { + if let Ok(data) = fs::read_to_string("/scheme/sys/cpu") { + for line in data.lines() { + if let Some(rest) = line.strip_prefix("CPUs: ") { + if let Ok(n) = rest.trim().parse::() { + return n.max(1); + } } } } + 1 + } + #[cfg(not(target_os = "redox"))] + { + let mut count = 0u32; + if let Ok(entries) = fs::read_dir("/dev/cpu") { + for entry in entries.filter_map(Result::ok) { + if let Ok(name) = entry.file_name().into_string() { + if name.parse::().is_ok() { + count += 1; + } + } + } + } + count.max(1) } - count.max(1) } fn read_cpu_temperature(cpu: u32) -> Option {