Skip to content

Commit

Permalink
Add "non-interesting" syscall workload.
Browse files Browse the repository at this point in the history
  • Loading branch information
erthalion committed Jul 4, 2023
1 parent bb53d6e commit 022db9d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ futures = "0.3"
log = "0.4.6"
env_logger = "0.9.0"
config = "0.13.3"
syscalls = "0.6.13"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ workloads:
modelled by Zipf \[3\] or uniform distributions (to cover extreme cases, when
one process has significantly more endpoints than others).

* Syscall based workload to evaluate certain type of edge cases. For now only
one syscall, `getpid` is included, to verify an overhead where normally
Collector doesn't stay in the way, but could be with the vanilla Falco.
Similarly to the process based workload, syscalls are also modelled by a
Poisson process.

Every workload is executed via set of worker processes, that are distributed
among available system CPU cores.

Expand Down
38 changes: 37 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use nix::sys::wait::waitpid;
use nix::unistd::Pid;
use config::Config;
use std::collections::HashMap;
use syscalls::{Sysno, syscall};

use rand::prelude::*;
use rand::{distributions::Alphanumeric, Rng};
Expand All @@ -29,6 +30,7 @@ enum Distribution {
enum Workload {
Endpoints,
Processes,
Syscalls,
}

#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -134,12 +136,44 @@ fn listen_payload(config: WorkerConfig) -> std::io::Result<()> {
Ok(())
}

fn do_syscall(config: WorkerConfig) -> std::io::Result<()> {
match unsafe { syscall!(Sysno::getpid) } {
Ok(_) => {
Ok(())
}
Err(err) => {
warn!("Syscall failed: {}", err);
Ok(())
}
}
}

fn syscalls_payload(config: WorkerConfig) -> std::io::Result<()> {
info!("Process {} from {}: {}-{}",
config.process, config.cpu.id, config.lower, config.upper);

loop {
thread::spawn(move || {
do_syscall(config)
});

let interval: f64 = thread_rng().sample(Exp::new(config.workload.arrival_rate).unwrap());
info!("{}-{}: Interval {}, rounded {}",
config.cpu.id, config.process,
interval, (interval * 1000.0).round() as u64);
thread::sleep(time::Duration::from_millis((interval * 1000.0).round() as u64));
info!("{}-{}: Continue", config.cpu.id, config.process);
}
}

fn main() {
// Retrieve the IDs of all active CPU cores.
let core_ids = core_affinity::get_core_ids().unwrap();
let settings = Config::builder()
// Add in `./Settings.toml`
.add_source(config::File::with_name("/etc/berserker/workload.toml"))
.add_source(config::File::with_name("/etc/berserker/workload.toml")
.required(false))
.add_source(config::File::with_name("workload.toml").required(false))
// Add in settings from the environment (with a prefix of APP)
// Eg.. `WORKLOAD_DEBUG=1 ./target/app` would set the `debug` key
.add_source(config::Environment::with_prefix("WORKLOAD"))
Expand All @@ -156,6 +190,7 @@ fn main() {
let workload = match settings["workload"].as_str() {
"endpoints" => Workload::Endpoints,
"processes" => Workload::Processes,
"syscalls" => Workload::Syscalls,
_ => Workload::Endpoints,
};

Expand Down Expand Up @@ -213,6 +248,7 @@ fn main() {
let _res = match config.workload {
Workload::Endpoints => listen_payload(worker_config),
Workload::Processes => process_payload(worker_config),
Workload::Syscalls => syscalls_payload(worker_config),
};
}
}
Expand Down

0 comments on commit 022db9d

Please sign in to comment.