mirror of
https://github.com/RGBCube/watt
synced 2025-08-02 10:57:47 +00:00
Compare commits
No commits in common. "3c82679ada8d4ec0f00b8198fbb4eb34352da409" and "496f5a7f35615a92f3629d142f4aa379ab486ba5" have entirely different histories.
3c82679ada
...
496f5a7f35
6 changed files with 89 additions and 39 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# Taken from https://github.com/cull-os/carcass.
|
||||||
|
# Modified to have 2 space indents and 80 line width.
|
||||||
|
|
||||||
# float_literal_trailing_zero = "Always" # TODO: Warning for some reason?
|
# float_literal_trailing_zero = "Always" # TODO: Warning for some reason?
|
||||||
condense_wildcard_suffixes = true
|
condense_wildcard_suffixes = true
|
||||||
doc_comment_code_block_width = 80
|
doc_comment_code_block_width = 80
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Taken from https://github.com/cull-os/carcass.
|
||||||
|
|
||||||
[formatting]
|
[formatting]
|
||||||
align_entries = true
|
align_entries = true
|
||||||
column_width = 100
|
column_width = 100
|
||||||
|
|
57
build.rs
Normal file
57
build.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
use std::{
|
||||||
|
env,
|
||||||
|
fs,
|
||||||
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
|
||||||
|
const MULTICALL_NAMES: &[&str] = &["cpu", "power"];
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
|
println!("cargo:rerun-if-changed=target");
|
||||||
|
|
||||||
|
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
|
||||||
|
let target = out_dir
|
||||||
|
.parent() // target/debug/build/<pkg>-<hash>/out
|
||||||
|
.and_then(|p| p.parent()) // target/debug/build/<pkg>-<hash>
|
||||||
|
.and_then(|p| p.parent()) // target/debug/
|
||||||
|
.ok_or("failed to find target directory")?;
|
||||||
|
|
||||||
|
let main_binary_name = env::var("CARGO_PKG_NAME")?;
|
||||||
|
|
||||||
|
let main_binary_path = target.join(&main_binary_name);
|
||||||
|
|
||||||
|
let mut errored = false;
|
||||||
|
|
||||||
|
for name in MULTICALL_NAMES {
|
||||||
|
let hardlink_path = target.join(name);
|
||||||
|
|
||||||
|
if hardlink_path.exists() {
|
||||||
|
if hardlink_path.is_dir() {
|
||||||
|
fs::remove_dir_all(&hardlink_path)?;
|
||||||
|
} else {
|
||||||
|
fs::remove_file(&hardlink_path)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(error) = fs::hard_link(&main_binary_path, &hardlink_path) {
|
||||||
|
println!(
|
||||||
|
"cargo:warning=failed to create hard link '{path}': {error}",
|
||||||
|
path = hardlink_path.display(),
|
||||||
|
);
|
||||||
|
errored = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if errored {
|
||||||
|
println!(
|
||||||
|
"cargo:warning=this often happens because the target binary isn't built \
|
||||||
|
yet, try running `cargo build` again"
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"cargo:warning=keep in mind that this is for development purposes only"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
55
config.toml
55
config.toml
|
@ -5,27 +5,28 @@
|
||||||
|
|
||||||
# Emergency thermal protection (highest priority).
|
# Emergency thermal protection (highest priority).
|
||||||
[[rule]]
|
[[rule]]
|
||||||
if = { value = "$cpu-temperature", is-more-than = 85.0 }
|
|
||||||
priority = 100
|
|
||||||
|
|
||||||
cpu.energy-performance-preference = "power"
|
cpu.energy-performance-preference = "power"
|
||||||
cpu.frequency-mhz-maximum = 2000
|
cpu.frequency-mhz-maximum = 2000
|
||||||
cpu.governor = "powersave"
|
cpu.governor = "powersave"
|
||||||
cpu.turbo = false
|
cpu.turbo = false
|
||||||
|
if = { value = "$cpu-temperature", is-more-than = 85.0 }
|
||||||
|
priority = 100
|
||||||
|
|
||||||
# Critical battery preservation.
|
# Critical battery preservation.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
if.all = [ "?discharging", { value = "%power-supply-charge", is-less-than = 0.3 } ]
|
|
||||||
priority = 90
|
|
||||||
|
|
||||||
cpu.energy-performance-preference = "power"
|
cpu.energy-performance-preference = "power"
|
||||||
cpu.frequency-mhz-maximum = 800 # More aggressive below critical threshold.
|
cpu.frequency-mhz-maximum = 800 # More aggressive below critical threshold.
|
||||||
cpu.governor = "powersave"
|
cpu.governor = "powersave"
|
||||||
cpu.turbo = false
|
cpu.turbo = false
|
||||||
|
if.all = [ "?discharging", { value = "%power-supply-charge", is-less-than = 0.3 } ]
|
||||||
power.platform-profile = "low-power"
|
power.platform-profile = "low-power"
|
||||||
|
priority = 90
|
||||||
|
|
||||||
# High performance mode for sustained high load.
|
# High performance mode for sustained high load.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
|
cpu.energy-performance-preference = "performance"
|
||||||
|
cpu.governor = "performance"
|
||||||
|
cpu.turbo = true
|
||||||
if.all = [
|
if.all = [
|
||||||
{ value = "%cpu-usage", is-more-than = 0.8 },
|
{ value = "%cpu-usage", is-more-than = 0.8 },
|
||||||
{ value = "$cpu-idle-seconds", is-less-than = 30.0 },
|
{ value = "$cpu-idle-seconds", is-less-than = 30.0 },
|
||||||
|
@ -33,12 +34,12 @@ if.all = [
|
||||||
]
|
]
|
||||||
priority = 80
|
priority = 80
|
||||||
|
|
||||||
cpu.energy-performance-preference = "performance"
|
|
||||||
cpu.governor = "performance"
|
|
||||||
cpu.turbo = true
|
|
||||||
|
|
||||||
# Performance mode when not discharging.
|
# Performance mode when not discharging.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
|
cpu.energy-performance-bias = "balance_performance"
|
||||||
|
cpu.energy-performance-preference = "performance"
|
||||||
|
cpu.governor = "performance"
|
||||||
|
cpu.turbo = true
|
||||||
if.all = [
|
if.all = [
|
||||||
{ not = "?discharging" },
|
{ not = "?discharging" },
|
||||||
{ value = "%cpu-usage", is-more-than = 0.1 },
|
{ value = "%cpu-usage", is-more-than = 0.1 },
|
||||||
|
@ -46,66 +47,56 @@ if.all = [
|
||||||
]
|
]
|
||||||
priority = 70
|
priority = 70
|
||||||
|
|
||||||
cpu.energy-performance-bias = "balance_performance"
|
|
||||||
cpu.energy-performance-preference = "performance"
|
|
||||||
cpu.governor = "performance"
|
|
||||||
cpu.turbo = true
|
|
||||||
|
|
||||||
# Moderate performance for medium load.
|
# Moderate performance for medium load.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
|
cpu.energy-performance-preference = "balance_performance"
|
||||||
|
cpu.governor = "schedutil"
|
||||||
if.all = [
|
if.all = [
|
||||||
{ value = "%cpu-usage", is-more-than = 0.4 },
|
{ value = "%cpu-usage", is-more-than = 0.4 },
|
||||||
{ value = "%cpu-usage", is-less-than = 0.8 },
|
{ value = "%cpu-usage", is-less-than = 0.8 },
|
||||||
]
|
]
|
||||||
priority = 60
|
priority = 60
|
||||||
|
|
||||||
cpu.energy-performance-preference = "balance_performance"
|
|
||||||
cpu.governor = "schedutil"
|
|
||||||
|
|
||||||
# Power saving during low activity.
|
# Power saving during low activity.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
|
cpu.energy-performance-preference = "power"
|
||||||
|
cpu.governor = "powersave"
|
||||||
|
cpu.turbo = false
|
||||||
if.all = [
|
if.all = [
|
||||||
{ value = "%cpu-usage", is-less-than = 0.2 },
|
{ value = "%cpu-usage", is-less-than = 0.2 },
|
||||||
{ value = "$cpu-idle-seconds", is-more-than = 60.0 },
|
{ value = "$cpu-idle-seconds", is-more-than = 60.0 },
|
||||||
]
|
]
|
||||||
priority = 50
|
priority = 50
|
||||||
|
|
||||||
cpu.energy-performance-preference = "power"
|
|
||||||
cpu.governor = "powersave"
|
|
||||||
cpu.turbo = false
|
|
||||||
|
|
||||||
# Extended idle power optimization.
|
# Extended idle power optimization.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
if = { value = "$cpu-idle-seconds", is-more-than = 300.0 }
|
|
||||||
priority = 40
|
|
||||||
|
|
||||||
cpu.energy-performance-preference = "power"
|
cpu.energy-performance-preference = "power"
|
||||||
cpu.frequency-mhz-maximum = 1600
|
cpu.frequency-mhz-maximum = 1600
|
||||||
cpu.governor = "powersave"
|
cpu.governor = "powersave"
|
||||||
cpu.turbo = false
|
cpu.turbo = false
|
||||||
|
if = { value = "$cpu-idle-seconds", is-more-than = 300.0 }
|
||||||
|
priority = 40
|
||||||
|
|
||||||
# Battery conservation when discharging.
|
# Battery conservation when discharging.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
if.all = [ "?discharging", { value = "%power-supply-charge", is-less-than = 0.5 } ]
|
|
||||||
priority = 30
|
|
||||||
|
|
||||||
cpu.energy-performance-preference = "power"
|
cpu.energy-performance-preference = "power"
|
||||||
cpu.frequency-mhz-maximum = 2000
|
cpu.frequency-mhz-maximum = 2000
|
||||||
cpu.governor = "powersave"
|
cpu.governor = "powersave"
|
||||||
cpu.turbo = false
|
cpu.turbo = false
|
||||||
|
if.all = [ "?discharging", { value = "%power-supply-charge", is-less-than = 0.5 } ]
|
||||||
power.platform-profile = "low-power"
|
power.platform-profile = "low-power"
|
||||||
|
priority = 30
|
||||||
|
|
||||||
# General battery mode.
|
# General battery mode.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
if = "?discharging"
|
|
||||||
priority = 20
|
|
||||||
|
|
||||||
cpu.energy-performance-bias = "balance_power"
|
cpu.energy-performance-bias = "balance_power"
|
||||||
cpu.energy-performance-preference = "power"
|
cpu.energy-performance-preference = "power"
|
||||||
cpu.frequency-mhz-maximum = 1800
|
cpu.frequency-mhz-maximum = 1800
|
||||||
cpu.frequency-mhz-minimum = 200
|
cpu.frequency-mhz-minimum = 200
|
||||||
cpu.governor = "powersave"
|
cpu.governor = "powersave"
|
||||||
cpu.turbo = false
|
cpu.turbo = false
|
||||||
|
if = "?discharging"
|
||||||
|
priority = 20
|
||||||
|
|
||||||
# Balanced performance for general use. Default fallback rule.
|
# Balanced performance for general use. Default fallback rule.
|
||||||
[[rule]]
|
[[rule]]
|
||||||
|
|
|
@ -227,13 +227,10 @@ impl PowerSupply {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for model name that indicates a peripheral
|
// Check for model name that indicates a peripheral
|
||||||
if let Some(model_name) = fs::read(self.path.join("model_name"))
|
if let Some(model) = fs::read(self.path.join("model_name"))
|
||||||
.with_context(|| format!("failed to read the model name of {self}"))?
|
.with_context(|| format!("failed to read the model name of {self}"))?
|
||||||
{
|
{
|
||||||
let model_name_lower = model_name.to_lowercase();
|
if model.contains("bluetooth") || model.contains("wireless") {
|
||||||
if model_name_lower.contains("bluetooth")
|
|
||||||
|| model_name_lower.contains("wireless")
|
|
||||||
{
|
|
||||||
break 'is_from_peripheral true;
|
break 'is_from_peripheral true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,8 +295,8 @@ impl System {
|
||||||
"stripped content is a valid number, taking it as the core number"
|
"stripped content is a valid number, taking it as the core number"
|
||||||
);
|
);
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"it is fine if this number doesn't seem accurate due to CPU binning, see a more detailed explanation at: https://rgbcu.be/blog/why-cores"
|
"it is fine if this number doesn't seem accurate due to CPU binning, see a more detailed explanation at: https://rgbcu.be/blog/why-cores"
|
||||||
);
|
);
|
||||||
|
|
||||||
let Some(temperature_mc) =
|
let Some(temperature_mc) =
|
||||||
fs::read_n::<i64>(&input_path).with_context(|| {
|
fs::read_n::<i64>(&input_path).with_context(|| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue