summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 00c0fcc58a436a543bfe8f7f4b3d54bb2b0d390b (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
mod bpf_skel;
use benchmark::BenchmarkScheduler;
pub use bpf_skel::*;
pub mod bpf_intf;

mod benchmark;
mod core_selector;
mod energy;
mod freq;
mod model;
mod scheduler;
mod socket;

#[rustfmt::skip]
#[allow(clippy::unwrap_or_default)]
#[allow(clippy::useless_asref)]
#[allow(clippy::single_match)]
#[allow(clippy::needless_lifetimes)]
mod bpf;

use anyhow::Result;
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("perf")
                .short('p')
                .long("perf")
                .help("Use this flag to switch between the kernel module and perf")
                .action(ArgAction::SetTrue)
                .required(false),
        )
        .arg(
            Arg::new("benchmark")
                .short('b')
                .long("benchmark")
                .help("Enable benchmarking mode.")
                .required(false)
                .action(ArgAction::SetTrue),
        )
        .get_matches();

    let use_perf = matches.get_flag("perf");
    let benchmark = matches.get_flag("benchmark");

    // 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_perf)?;
        if !sched.run()?.should_restart() {
            break;
        }
    }

    Ok(())
}