From 8c7a4ccdfde8cdd375bdb7f7570bbad65783b8fd Mon Sep 17 00:00:00 2001 From: ilyazzz Date: Sun, 18 Apr 2021 12:48:08 +0300 Subject: [PATCH] Get ppfeaturemask from the kernel module info (#29) * Switch to using the kernel module info for checking ppfeaturemask --- gui/src/app.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/gui/src/app.rs b/gui/src/app.rs index aa64fef..1b7fc00 100644 --- a/gui/src/app.rs +++ b/gui/src/app.rs @@ -218,16 +218,28 @@ impl App { } { - let cmdline = - fs::read_to_string("/proc/cmdline").expect("Failed to read /proc/cmdline"); - // It's overkill to both show and hide the frame, but it needs to be done in set_info because show_all overrides the default hidden state of the frame. - if !cmdline.contains("amdgpu.ppfeaturemask") { - log::info!("amdgpu.ppfeaturemask not detected, showing the warning"); - self.root_stack.oc_page.warning_frame.show(); - } else { - log::info!("overclocking support enabled, not showing the warning"); - self.root_stack.oc_page.warning_frame.hide(); + match fs::read_to_string("/sys/module/amdgpu/parameters/ppfeaturemask") { + Ok(ppfeaturemask) => { + const PP_OVERDRIVE_MASK: i32 = 0x4000; + + let ppfeaturemask = ppfeaturemask.trim().strip_prefix("0x").unwrap(); + + log::trace!("ppfeaturemask {}", ppfeaturemask); + + let ppfeaturemask: u64 = + u64::from_str_radix(ppfeaturemask, 16).expect("Invalid ppfeaturemask"); + + if (ppfeaturemask & PP_OVERDRIVE_MASK as u64) > 0 { + self.root_stack.oc_page.warning_frame.hide(); + } else { + self.root_stack.oc_page.warning_frame.show(); + } + } + Err(_) => { + log::info!("Failed to read feature mask! This is expected if your system doesn't have an AMD GPU."); + self.root_stack.oc_page.warning_frame.hide(); + } } }