thermald: use Redox /scheme/sys/msr for CPU temperature reads
This commit is contained in:
@@ -189,27 +189,55 @@ fn zone_name_for_entry(entry: &fs::DirEntry) -> Option<String> {
|
||||
}
|
||||
|
||||
fn read_msr(cpu: u32, msr: u32) -> Option<u64> {
|
||||
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::<u32>().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::<u32>() {
|
||||
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::<u32>().is_ok() {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
count.max(1)
|
||||
}
|
||||
count.max(1)
|
||||
}
|
||||
|
||||
fn read_cpu_temperature(cpu: u32) -> Option<f64> {
|
||||
|
||||
Reference in New Issue
Block a user