Skip to content

Commit

Permalink
feat: add support for disabling overdrive
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-zlobintsev committed Jan 22, 2024
1 parent 4223433 commit 292c94a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
1 change: 1 addition & 0 deletions lact-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl DaemonClient {

request_plain!(get_system_info, SystemInfo, SystemInfo);
request_plain!(enable_overdrive, EnableOverdrive, String);
request_plain!(disable_overdrive, DisableOverdrive, String);
request_plain!(generate_debug_snapshot, GenerateSnapshot, String);
request_with_id!(get_device_info, DeviceInfo, DeviceInfo);
request_with_id!(get_device_stats, DeviceStats, DeviceStats);
Expand Down
1 change: 1 addition & 0 deletions lact-daemon/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async fn handle_request<'a>(request: Request<'a>, handler: &'a Handler) -> anyho
ok_response(handler.set_enabled_power_states(id, kind, states).await?)
}
Request::EnableOverdrive => ok_response(system::enable_overdrive()?),
Request::DisableOverdrive => ok_response(system::disable_overdrive()?),
Request::GenerateSnapshot => ok_response(handler.generate_snapshot()?),
Request::ConfirmPendingConfig(command) => {
ok_response(handler.confirm_pending_config(command)?)
Expand Down
17 changes: 17 additions & 0 deletions lact-daemon/src/server/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
fs::{self, File, Permissions},
io::Write,
os::unix::prelude::PermissionsExt,
path::Path,
process::Command,
};
use tracing::{info, warn};
Expand Down Expand Up @@ -70,6 +71,22 @@ pub fn enable_overdrive() -> anyhow::Result<String> {
Ok(message)
}

pub fn disable_overdrive() -> anyhow::Result<String> {
if Path::new(MODULE_CONF_PATH).exists() {
fs::remove_file(MODULE_CONF_PATH).context("Could not remove module config file")?;
match regenerate_initramfs() {
Ok(initramfs_type) => Ok(format!(
"Initramfs was successfully regenerated (detected type {initramfs_type:?})"
)),
Err(err) => Ok(format!("{err:#}")),
}
} else {
Err(anyhow!(
"Overclocking was not enabled through LACT (file at {MODULE_CONF_PATH} does not exist)"
))
}
}

fn read_current_mask() -> anyhow::Result<u64> {
let ppfeaturemask = fs::read_to_string(PP_FEATURE_MASK_PATH)?;
let ppfeaturemask = ppfeaturemask
Expand Down
11 changes: 9 additions & 2 deletions lact-gui/src/app/header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::DeviceListEntry;
use lact_client::schema::{DeviceListEntry, SystemInfo};
use pango::EllipsizeMode;

#[derive(Clone)]
Expand All @@ -11,7 +11,7 @@ pub struct Header {
}

impl Header {
pub fn new() -> Self {
pub fn new(system_info: &SystemInfo) -> Self {
let container = HeaderBar::new();
container.set_show_title_buttons(true);

Expand All @@ -27,6 +27,13 @@ impl Header {
Some("app.generate-debug-snapshot"),
);

if system_info.amdgpu_overdrive_enabled == Some(true) {
menu.append(
Some("Disable overclocking support"),
Some("app.disable-overdrive"),
)
}

let menu_button = MenuButton::builder()
.icon_name("open-menu-symbolic")
.menu_model(&menu)
Expand Down
55 changes: 46 additions & 9 deletions lact-gui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ impl App {
#[cfg(not(feature = "adw"))]
let application = Application::new(Some(APP_ID), ApplicationFlags::default());

let header = Header::new();
let system_info_buf = daemon_client
.get_system_info()
.expect("Could not fetch system info");
let system_info = system_info_buf.inner().expect("Invalid system info buffer");

let header = Header::new(&system_info);
let window = ApplicationWindow::builder()
.title("LACT")
.default_width(600)
.default_height(820)
.icon_name(APP_ID)
.build();

window.set_titlebar(Some(&header.container));

let system_info_buf = daemon_client
.get_system_info()
.expect("Could not fetch system info");
let system_info = system_info_buf.inner().expect("Invalid system info buffer");

if system_info.version != GUI_VERSION {
let err = anyhow!("Version mismatch between GUI and daemon ({GUI_VERSION} vs {})! Make sure you have restarted the service if you have updated LACT.", system_info.version);
show_error(&window, err);
}

window.set_titlebar(Some(&header.container));

let root_stack = RootStack::new(system_info, daemon_client.embedded);

header.set_switcher_stack(&root_stack.container);
Expand Down Expand Up @@ -173,7 +173,13 @@ impl App {
}))
.build();

app.application.add_action_entries([snapshot_action]);
let disable_overdive_action = ActionEntry::builder("disable-overdrive")
.activate(clone!(@strong app => move |_, _, _| {
app.disable_overclocking()
}))
.build();

app.application.add_action_entries([snapshot_action, disable_overdive_action]);

app.start_stats_update_loop(current_gpu_id);

Expand Down Expand Up @@ -557,6 +563,37 @@ impl App {
}));
}

fn disable_overclocking(&self) {
let dialog = MessageDialog::builder()
.title("Disable Overclocking")
.use_markup(true)
.text("The overclocking functionality in the driver will now be turned off. (Note: the LACT window might hang)")
.message_type(MessageType::Info)
.buttons(ButtonsType::Ok)
.transient_for(&self.window)
.build();

dialog.run_async(clone!(@strong self as app => move |diag, _| {
diag.hide();
match app.daemon_client.disable_overdrive().and_then(|buffer| buffer.inner()) {
Ok(msg) => {
let success_dialog = MessageDialog::builder()
.title("Success")
.text(format!("Overclocking successfully disabled. A system reboot is required to apply the changes.\nSystem message: {msg}"))
.message_type(MessageType::Info)
.buttons(ButtonsType::Ok)
.build();
success_dialog.run_async(move |diag, _| {
diag.hide();
});
}
Err(err) => {
show_error(&app.window, err);
}
}
}));
}

fn ask_confirmation(&self, gpu_id: String, mut delay: u64) {
let text = confirmation_text(delay);
let dialog = MessageDialog::builder()
Expand Down
1 change: 1 addition & 0 deletions lact-schema/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub enum Request<'a> {
states: Vec<u8>,
},
EnableOverdrive,
DisableOverdrive,
GenerateSnapshot,
ConfirmPendingConfig(ConfirmCommand),
}
Expand Down

0 comments on commit 292c94a

Please sign in to comment.