wip: config
This commit is contained in:
@@ -65,10 +65,7 @@
|
|||||||
# Inherit inputs from checks.
|
# Inherit inputs from checks.
|
||||||
checks = self.checks.${system};
|
checks = self.checks.${system};
|
||||||
|
|
||||||
# Additional dev-shell environment variables can be set directly
|
RUST_LOG = "debug";
|
||||||
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
|
|
||||||
|
|
||||||
# Extra inputs can be added here; cargo and rustc are provided by default.
|
|
||||||
packages = [
|
packages = [
|
||||||
# pkgs.ripgrep
|
# pkgs.ripgrep
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use toml::Table;
|
use toml::Table;
|
||||||
use toml::map::Map;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|||||||
15
src/cpu.rs
15
src/cpu.rs
@@ -22,12 +22,25 @@ pub struct CpuCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum CoreType {
|
pub enum CoreType {
|
||||||
P, // Performence
|
P, // Performence
|
||||||
E, // Efficent
|
E, // Efficent
|
||||||
L, // Low power
|
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 {
|
impl CpuCore {
|
||||||
fn determine_core_type() -> Result<CoreType, ()> {
|
fn determine_core_type() -> Result<CoreType, ()> {
|
||||||
if !(CpuCore::is_atomic()?) {
|
if !(CpuCore::is_atomic()?) {
|
||||||
|
|||||||
35
src/main.rs
35
src/main.rs
@@ -1,11 +1,11 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use raw_cpuid::*;
|
use raw_cpuid::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
cpu::{Cpu, CpuCore},
|
cpu::{CoreType, Cpu, CpuCore},
|
||||||
};
|
};
|
||||||
mod config;
|
mod config;
|
||||||
mod cpu;
|
mod cpu;
|
||||||
@@ -19,40 +19,45 @@ struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
let mut custom_cpu: Option<Cpu> = None;
|
||||||
|
|
||||||
if let Some(config) = args.config {
|
if let Some(config) = args.config {
|
||||||
let config_buf = std::fs::read(config).unwrap();
|
let config_buf = std::fs::read(config).unwrap();
|
||||||
let config_par: Config = toml::from_slice(&config_buf).unwrap();
|
let config_par: Config = toml::from_slice(&config_buf).unwrap();
|
||||||
if let Some(comp) = config_par.cpu.comp {
|
if let Some(comp) = config_par.cpu.comp {
|
||||||
warn!("Using custom cpu topo loaded from config!");
|
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 {
|
for x in comp {
|
||||||
custom_topo.push(CpuCore {
|
custom_topo.push(CpuCore {
|
||||||
id: x.0.parse().unwrap(),
|
id: x.0.parse().unwrap(),
|
||||||
core_type: {
|
core_type: {
|
||||||
match x.1 {
|
match x.1 {
|
||||||
toml::Value::String(y) => match y.as_str() {
|
toml::Value::String(y) => {
|
||||||
"P" => {}
|
if let Ok(ParsedCoreType) = CoreType::try_from(y.clone()) {
|
||||||
"E" => {}
|
ParsedCoreType
|
||||||
"L" => {}
|
} else {
|
||||||
_ => {
|
error!("Couldn't parse {:?} as CoreType", y);
|
||||||
unreachable!()
|
unreachable!("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
unreachable!()
|
unreachable!("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
custom_cpu = Some(Cpu { cores: custom_topo });
|
||||||
}
|
}
|
||||||
Cpu { cores: vec![] };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing_subscriber::fmt::init();
|
let mut cpu: Cpu;
|
||||||
|
if custom_cpu.is_none() {
|
||||||
let cpu = cpu::Cpu::new();
|
cpu = cpu::Cpu::new();
|
||||||
|
} else {
|
||||||
|
cpu = custom_cpu.unwrap();
|
||||||
|
};
|
||||||
debug!("{cpu:?}");
|
debug!("{cpu:?}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[cpu]
|
[cpu]
|
||||||
comp = {
|
comp = {
|
||||||
"0" = {type = E}
|
"0" = "E"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user