blob: 624291756454f8e4d2e151f1e7ad31268b67d1a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
mod bpf_skel;
use benchmark::BenchmarkScheduler;
pub use bpf_skel::*;
pub mod bpf_intf;
mod benchmark;
mod e_core_selector;
mod energy;
mod freq;
mod model;
mod scheduler;
mod socket;
#[rustfmt::skip]
mod bpf;
use anyhow::Result;
use burn::tensor::Tensor;
use clap::{Arg, ArgAction, Command};
use scheduler::Scheduler;
use std::mem::MaybeUninit;
type Pid = i32;
fn main() -> Result<()> {
let matches = Command::new("Energy User Space Scheduler")
.arg(
Arg::new("mock")
.short('m')
.long("mock")
.help("Use this flag if to activate kernel module mocking")
.action(ArgAction::SetTrue)
.required(false),
)
.arg(
Arg::new("benchmark")
.short('b')
.long("benchmark")
.help("Use this flag to enable benckmarking mode")
.action(ArgAction::SetTrue)
.required(false),
)
.arg(
Arg::new("power_cap")
.long("energy_cap")
.help("Set a power cap for the processor")
.required(false)
.value_name("power in watts"),
)
.arg(
Arg::new("log_energy")
.long("log_energy")
.help("Provide one or more PIDs to log their process tress energy")
.num_args(1..)
.required(false),
)
.get_matches();
let power_cap = *matches.get_one::<u64>("power_cap").unwrap_or(&u64::MAX);
let use_mocking = matches.get_flag("mock");
let benchmark = matches.get_flag("benchmark");
let pids_to_monitor: Vec<Pid> = matches
.get_many::<String>("log_energy")
.unwrap_or_default()
.map(|v| v.parse::<Pid>().unwrap())
.collect();
// Initialize and load the scheduler.
let mut open_object = MaybeUninit::uninit();
let log_path = "/tmp/logs.csv";
if benchmark {
let mut sched = BenchmarkScheduler::init(&mut open_object, log_path)?;
sched.run()?;
return Ok(());
}
loop {
let mut sched =
Scheduler::init(&mut open_object, use_mocking, power_cap, &pids_to_monitor)?;
if !sched.run()?.should_restart() {
break;
}
}
Ok(())
}
|