-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1070 from CachyOS/feature/scx-loader-lib-crate
scx_loader: provide library crate to be used by other crates
- Loading branch information
Showing
5 changed files
with
163 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// | ||
// Copyright (c) 2024 Vladislav Nepogodin <vnepogodin@cachyos.org> | ||
|
||
// This software may be used and distributed according to the terms of the | ||
// GNU General Public License version 2. | ||
|
||
use crate::SchedMode; | ||
use crate::SupportedSched; | ||
|
||
#[zbus::proxy( | ||
interface = "org.scx.Loader", | ||
default_service = "org.scx.Loader", | ||
default_path = "/org/scx/Loader" | ||
)] | ||
pub trait LoaderClient { | ||
/// Starts the specified scheduler with the given mode. | ||
fn start_scheduler(&self, scx_name: SupportedSched, sched_mode: SchedMode) -> zbus::Result<()>; | ||
|
||
/// Starts the specified scheduler with the provided arguments. | ||
fn start_scheduler_with_args( | ||
&self, | ||
scx_name: SupportedSched, | ||
scx_args: &[String], | ||
) -> zbus::Result<()>; | ||
|
||
/// Stops the currently running scheduler. | ||
fn stop_scheduler(&self) -> zbus::Result<()>; | ||
|
||
/// Method for switching to the specified scheduler with the given mode. | ||
/// This method will stop the currently running scheduler (if any) and | ||
/// then start the new scheduler. | ||
fn switch_scheduler(&self, scx_name: SupportedSched, sched_mode: SchedMode) | ||
-> zbus::Result<()>; | ||
|
||
/// Switches to the specified scheduler with the provided arguments. This | ||
/// method will stop the currently running scheduler (if any) and then | ||
/// start the new scheduler with the given arguments. | ||
fn switch_scheduler_with_args( | ||
&self, | ||
scx_name: SupportedSched, | ||
scx_args: &[String], | ||
) -> zbus::Result<()>; | ||
|
||
/// The name of the currently running scheduler. If no scheduler is active, | ||
/// this property will be set to "unknown". | ||
#[zbus(property)] | ||
fn current_scheduler(&self) -> zbus::Result<String>; | ||
|
||
/// The currently active scheduler mode. Scheduler modes allow you to | ||
/// apply pre-defined configurations to a scheduler that are | ||
/// optimized for different use cases. If no scheduler is active, | ||
/// this property will be set to 0 (Auto). | ||
#[zbus(property)] | ||
fn scheduler_mode(&self) -> zbus::Result<SchedMode>; | ||
|
||
/// A list of the schedulers currently supported by the Scheduler Loader. | ||
/// The names of the supported schedulers will be listed as strings in | ||
/// this array. | ||
#[zbus(property)] | ||
fn supported_schedulers(&self) -> zbus::Result<Vec<String>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// | ||
// Copyright (c) 2024 Vladislav Nepogodin <vnepogodin@cachyos.org> | ||
|
||
// This software may be used and distributed according to the terms of the | ||
// GNU General Public License version 2. | ||
|
||
pub mod config; | ||
pub mod dbus; | ||
|
||
use std::str::FromStr; | ||
|
||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use zvariant::OwnedValue; | ||
use zvariant::Type; | ||
use zvariant::Value; | ||
|
||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Type)] | ||
#[zvariant(signature = "s")] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum SupportedSched { | ||
#[serde(rename = "scx_bpfland")] | ||
Bpfland, | ||
#[serde(rename = "scx_rusty")] | ||
Rusty, | ||
#[serde(rename = "scx_lavd")] | ||
Lavd, | ||
#[serde(rename = "scx_flash")] | ||
Flash, | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize, Type, Value, OwnedValue, PartialEq)] | ||
pub enum SchedMode { | ||
/// Default values for the scheduler | ||
Auto = 0, | ||
/// Applies flags for better gaming experience | ||
Gaming = 1, | ||
/// Applies flags for lower power usage | ||
PowerSave = 2, | ||
/// Starts scheduler in low latency mode | ||
LowLatency = 3, | ||
} | ||
|
||
impl From<&SupportedSched> for &str { | ||
fn from(scx_name: &SupportedSched) -> &'static str { | ||
match scx_name { | ||
SupportedSched::Bpfland => "scx_bpfland", | ||
SupportedSched::Rusty => "scx_rusty", | ||
SupportedSched::Lavd => "scx_lavd", | ||
SupportedSched::Flash => "scx_flash", | ||
} | ||
} | ||
} | ||
|
||
impl From<SupportedSched> for &str { | ||
fn from(scx_name: SupportedSched) -> &'static str { | ||
scx_name.into() | ||
} | ||
} | ||
|
||
impl FromStr for SupportedSched { | ||
type Err = anyhow::Error; | ||
|
||
fn from_str(scx_name: &str) -> anyhow::Result<SupportedSched> { | ||
match scx_name { | ||
"scx_bpfland" => Ok(SupportedSched::Bpfland), | ||
"scx_rusty" => Ok(SupportedSched::Rusty), | ||
"scx_lavd" => Ok(SupportedSched::Lavd), | ||
"scx_flash" => Ok(SupportedSched::Flash), | ||
_ => Err(anyhow::anyhow!("{scx_name} is not supported")), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters