wip: config

This commit is contained in:
2026-03-06 20:11:13 +00:00
parent af791ad1e9
commit d7e1e578a6
5 changed files with 36 additions and 22 deletions

View File

@@ -65,10 +65,7 @@
# Inherit inputs from checks.
checks = self.checks.${system};
# Additional dev-shell environment variables can be set directly
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
# Extra inputs can be added here; cargo and rustc are provided by default.
RUST_LOG = "debug";
packages = [
# pkgs.ripgrep
];

View File

@@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
use toml::Table;
use toml::map::Map;
#[derive(Serialize, Deserialize)]
pub struct Config {

View File

@@ -22,12 +22,25 @@ pub struct CpuCore {
}
#[derive(Debug, Clone, Copy)]
enum CoreType {
pub enum CoreType {
P, // Performence
E, // Efficent
L, // Low power
}
impl TryFrom<String> for CoreType {
type Error = &'static str;
fn try_from(value: String) -> Result<Self, Self::Error> {
match value.as_str() {
"E" => Ok(CoreType::E),
"P" => Ok(CoreType::P),
"L" => Ok(CoreType::L),
_ => Err(""),
}
}
}
impl CpuCore {
fn determine_core_type() -> Result<CoreType, ()> {
if !(CpuCore::is_atomic()?) {

View File

@@ -1,11 +1,11 @@
use clap::Parser;
use raw_cpuid::*;
use std::path::PathBuf;
use tracing::{debug, info, warn};
use tracing::{debug, error, info, warn};
use crate::{
config::Config,
cpu::{Cpu, CpuCore},
cpu::{CoreType, Cpu, CpuCore},
};
mod config;
mod cpu;
@@ -19,40 +19,45 @@ struct Args {
}
fn main() {
tracing_subscriber::fmt::init();
let args = Args::parse();
let mut custom_cpu: Option<Cpu> = None;
if let Some(config) = args.config {
let config_buf = std::fs::read(config).unwrap();
let config_par: Config = toml::from_slice(&config_buf).unwrap();
if let Some(comp) = config_par.cpu.comp {
warn!("Using custom cpu topo loaded from config!");
let custom_topo: Vec<CpuCore> = Vec::new();
let mut custom_topo: Vec<CpuCore> = Vec::new();
for x in comp {
custom_topo.push(CpuCore {
id: x.0.parse().unwrap(),
core_type: {
match x.1 {
toml::Value::String(y) => match y.as_str() {
"P" => {}
"E" => {}
"L" => {}
_ => {
unreachable!()
toml::Value::String(y) => {
if let Ok(ParsedCoreType) = CoreType::try_from(y.clone()) {
ParsedCoreType
} else {
error!("Couldn't parse {:?} as CoreType", y);
unreachable!("");
}
},
}
_ => {
unreachable!()
unreachable!("")
}
}
},
})
}
custom_cpu = Some(Cpu { cores: custom_topo });
}
Cpu { cores: vec![] };
}
tracing_subscriber::fmt::init();
let cpu = cpu::Cpu::new();
let mut cpu: Cpu;
if custom_cpu.is_none() {
cpu = cpu::Cpu::new();
} else {
cpu = custom_cpu.unwrap();
};
debug!("{cpu:?}");
}

View File

@@ -1,4 +1,4 @@
[cpu]
comp = {
"0" = {type = E}
"0" = "E"
}