Skip to content

Commit f1d38fc

Browse files
committed
Do not panic if base_frequency is not present in sysfs
Some CPU's apparently do not have it despite that not being mentioned anywhere in the kernel docs.
1 parent 9db14ba commit f1d38fc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crates/power-daemon/src/systeminfo.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,16 @@ impl CPUInfo {
234234

235235
let cpufreq_path = entry.path().join("cpufreq/");
236236

237-
let base_frequency =
238-
file_content_to_u32(cpufreq_path.join("base_frequency")) / 1000;
237+
let base_frequency_path = cpufreq_path.join("base_frequency");
238+
239+
// Some cpu's straight up do not have base_frequency and it's
240+
// not mentioned anywhere in kernel docs
241+
let base_frequency = if fs::metadata(&base_frequency_path).is_ok() {
242+
file_content_to_u32(base_frequency_path) / 1000
243+
} else {
244+
0
245+
};
246+
239247
let current_frequency =
240248
file_content_to_u32(cpufreq_path.join("scaling_cur_freq")) / 1000;
241249

0 commit comments

Comments
 (0)