wip: process handler
This commit is contained in:
@@ -74,5 +74,6 @@ fn main() {
|
|||||||
};
|
};
|
||||||
debug!("{cpu:?}");
|
debug!("{cpu:?}");
|
||||||
let test_take_core = cpu.get_p_cores(3);
|
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,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use serde::de::Error;
|
||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
use crate::{cpu::Cpu, processes::ProcessList};
|
use crate::{cpu::Cpu, processes::ProcessList};
|
||||||
|
|
||||||
@@ -16,7 +18,7 @@ pub struct ProcessAffinityWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ProcessAffinityWorker {
|
impl ProcessAffinityWorker {
|
||||||
fn new(cpu: Cpu, process_list: ProcessList) -> ProcessAffinityWorker {
|
pub fn new(cpu: Cpu, process_list: ProcessList) -> ProcessAffinityWorker {
|
||||||
let s = System::new();
|
let s = System::new();
|
||||||
ProcessAffinityWorker {
|
ProcessAffinityWorker {
|
||||||
system: s,
|
system: s,
|
||||||
@@ -24,17 +26,31 @@ impl ProcessAffinityWorker {
|
|||||||
process_list,
|
process_list,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn run(&mut self) -> Result<(), ()> {
|
pub fn run(&mut self) {
|
||||||
loop {
|
loop {
|
||||||
|
// TODO add error handling
|
||||||
self.system
|
self.system
|
||||||
.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
|
||||||
for x in &self.process_list.processes {
|
for x in &self.process_list.processes {
|
||||||
let os_string = OsString::from(x.name.clone());
|
let os_string = OsString::from(x.name.clone());
|
||||||
let processes = self.system.processes_by_name(&os_string);
|
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));
|
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)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ProcessList {
|
pub struct ProcessList {
|
||||||
@@ -41,3 +46,24 @@ pub struct CpuAffinityList {
|
|||||||
e: i32,
|
e: i32,
|
||||||
l: 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]
|
[cpu]
|
||||||
comp = {
|
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]
|
[process_management]
|
||||||
polling_rate = 5000
|
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