wip: process handler
This commit is contained in:
@@ -74,5 +74,6 @@ fn main() {
|
||||
};
|
||||
debug!("{cpu:?}");
|
||||
let test_take_core = cpu.get_p_cores(3);
|
||||
debug!("{test_take_core:?}")
|
||||
debug!("{test_take_core:?}");
|
||||
process_worker::ProcessAffinityWorker::new(cpu, process_list).run();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use serde::de::Error;
|
||||
use sysinfo::System;
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
use crate::{cpu::Cpu, processes::ProcessList};
|
||||
|
||||
@@ -16,7 +18,7 @@ pub struct ProcessAffinityWorker {
|
||||
}
|
||||
|
||||
impl ProcessAffinityWorker {
|
||||
fn new(cpu: Cpu, process_list: ProcessList) -> ProcessAffinityWorker {
|
||||
pub fn new(cpu: Cpu, process_list: ProcessList) -> ProcessAffinityWorker {
|
||||
let s = System::new();
|
||||
ProcessAffinityWorker {
|
||||
system: s,
|
||||
@@ -24,17 +26,31 @@ impl ProcessAffinityWorker {
|
||||
process_list,
|
||||
}
|
||||
}
|
||||
fn run(&mut self) -> Result<(), ()> {
|
||||
pub fn run(&mut self) {
|
||||
loop {
|
||||
// TODO add error handling
|
||||
self.system
|
||||
.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||
for x in &self.process_list.processes {
|
||||
let os_string = OsString::from(x.name.clone());
|
||||
let processes = self.system.processes_by_name(&os_string);
|
||||
for y in processes {
|
||||
info!("Attempting to set cpu affinity for {:?}", x.name.clone());
|
||||
let result = scheduler::set_affinity(
|
||||
y.pid().as_u32().try_into().unwrap(),
|
||||
x.cpu_bounds.to_cpuset(&self.cpu),
|
||||
);
|
||||
match result {
|
||||
Ok(()) => {
|
||||
debug!("Setting cpu affinity for {:?} is ok", x.name.clone())
|
||||
}
|
||||
Err(()) => {
|
||||
error!("unable to set cpu affinity for {:?}..", x.name.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sleep(Duration::from_secs(5));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
use crate::config::Config;
|
||||
use scheduler::CpuSet;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
cpu::{Cpu, CpuCore},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ProcessList {
|
||||
@@ -41,3 +46,24 @@ pub struct CpuAffinityList {
|
||||
e: i32,
|
||||
l: i32,
|
||||
}
|
||||
|
||||
impl CpuAffinityList {
|
||||
pub fn to_cpuset(&self, cpu: &Cpu) -> CpuSet {
|
||||
let mut cpuset = CpuSet::new(cpu.cores.len() + 1);
|
||||
|
||||
let mut all: Vec<CpuCore> = Vec::new();
|
||||
let mut p = cpu.get_p_cores(self.p);
|
||||
let mut e = cpu.get_e_cores(self.e);
|
||||
let mut l = cpu.get_l_cores(self.l);
|
||||
|
||||
all.append(&mut p);
|
||||
all.append(&mut e);
|
||||
all.append(&mut l);
|
||||
|
||||
for x in all {
|
||||
cpuset.set(x.id as usize);
|
||||
}
|
||||
|
||||
cpuset
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
[cpu]
|
||||
comp = {
|
||||
"0" = "E", "1" = "P", "2" = "P", "3" = "P", "4" = "P", "5" = "P"
|
||||
"0" = "E", "1" = "E", "2" = "P", "3" = "P", "4" = "P", "5" = "P"
|
||||
}
|
||||
[process_management]
|
||||
polling_rate = 5000
|
||||
processes = [{process_name = "", topo = {p = 2, l = 2}}]
|
||||
processes = [
|
||||
{process_name = "hyprland", topo = {p = 2, e = 2}},
|
||||
{process_name = "zen", topo = {p=999, e=999}}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user