Skip to content

Commit

Permalink
start cleaning things up
Browse files Browse the repository at this point in the history
  • Loading branch information
likewhatevs committed Sep 12, 2024
1 parent fb656f5 commit 2621432
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 288 deletions.
2 changes: 1 addition & 1 deletion meson-scripts/test_sched
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
SCHEDS["scx_simple"]=""
SCHEDS["scx_central"]=""
SCHEDS["scx_nest"]=""
SCHEDS["scx_rusty"]=""
SCHEDS["scx_rusty"]="--stats 1"
SCHEDS["scx_rustland"]=""
SCHEDS["scx_bpfland"]=""
SCHEDS["scx_layered"]="--run-example --stats 1"
Expand Down
15 changes: 5 additions & 10 deletions rust/scx_utils/src/bpf_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl BpfBuilder {
}

/// Return `(VER, SHA1)` from which the bulit-in `vmlinux.h` is generated.
pub fn vmlinux_h_ver_sha1() -> (String, String) {
pub fn vmlinux_h_ver_sha1() -> String {
let mut ar = tar::Archive::new(Self::BPF_H_TAR);

for file in ar.entries().unwrap() {
Expand All @@ -378,7 +378,7 @@ impl BpfBuilder {
.to_string_lossy()
.to_string();

return sscanf!(name, "vmlinux-v{String}-g{String}.h").unwrap();
return sscanf!(name, "vmlinux-{String}.h").unwrap();
}

panic!("vmlinux/vmlinux.h not found");
Expand Down Expand Up @@ -586,15 +586,10 @@ mod tests {

#[test]
fn test_vmlinux_h_ver_sha1() {
let (ver, sha1) = super::BpfBuilder::vmlinux_h_ver_sha1();
let ver = super::BpfBuilder::vmlinux_h_ver_sha1();

println!("vmlinux.h: ver={:?} sha1={:?}", &ver, &sha1,);
println!("vmlinux.h: ver={:?}", &ver);

assert!(regex::Regex::new(r"^([1-9][0-9]*\.[1-9][0-9][a-z0-9-]*)$")
.unwrap()
.is_match(&ver));
assert!(regex::Regex::new(r"^[0-9a-z]{12}$")
.unwrap()
.is_match(&sha1));
assert!(regex::Regex::new(r"^[a-f0-9]{7}$").unwrap().is_match(&ver));
}
}
5 changes: 2 additions & 3 deletions rust/scx_utils/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub fn check_min_requirements() -> Result<()> {
// ec7e3b0463e1 ("implement-ops") in https://github.com/sched-ext/sched_ext
// is the current minimum required kernel version.
// if let Ok(false) | Err(_) = struct_has_field("sched_ext_ops", "dump") {
// bail!("sched_ext_ops.dump() missing, kernel too old?");
// bail!("sched_ext_ops.dump() missing, kernel too old?");
// }
Ok(())
}
Expand All @@ -187,7 +187,6 @@ macro_rules! scx_ops_open {
};

let ops = skel.struct_ops.[<$ops _mut>]();
// ahh think this part matters a lot.
// let path = std::path::Path::new("/sys/kernel/sched_ext/hotplug_seq");

// let val = match std::fs::read_to_string(&path) {
Expand Down Expand Up @@ -219,7 +218,7 @@ macro_rules! scx_ops_open {
macro_rules! scx_ops_load {
($skel: expr, $ops: ident, $uei: ident) => { 'block: {
scx_utils::paste! {
// scx_utils::uei_set_size!($skel, $ops, $uei);
//scx_utils::uei_set_size!($skel, $ops, $uei);
$skel.load().context("Failed to load BPF program")
}
}};
Expand Down
56 changes: 28 additions & 28 deletions rust/scx_utils/src/user_exit_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
use crate::bindings;
//use crate::bindings;
use crate::compat;
use anyhow::bail;
use anyhow::Result;
Expand Down Expand Up @@ -120,10 +120,10 @@ macro_rules! uei_report {
#[derive(Debug, Default)]
pub struct UserExitInfo {
r#type: i32,
// exit_code: i64,
// exit_code: i64,
reason: Option<String>,
msg: Option<String>,
// dump: Option<String>,
// dump: Option<String>,
}

impl UserExitInfo {
Expand Down Expand Up @@ -164,24 +164,24 @@ impl UserExitInfo {
.filter(|s| !s.is_empty()),
);

// let dump = if dump_ptr.is_null() {
// None
// } else {
// Some(
// unsafe { CStr::from_ptr(dump_ptr) }
// .to_str()
// .expect("Failed to convert msg to string")
// .to_string(),
// )
// .filter(|s| !s.is_empty())
// };
// let dump = if dump_ptr.is_null() {
// None
// } else {
// Some(
// unsafe { CStr::from_ptr(dump_ptr) }
// .to_str()
// .expect("Failed to convert msg to string")
// .to_string(),
// )
// .filter(|s| !s.is_empty())
// };

Self {
r#type,
// exit_code,
reason,
msg,
// dump,
// dump,
}
}

Expand All @@ -193,22 +193,22 @@ impl UserExitInfo {
return Ok(());
}

// if let Some(dump) = &self.dump {
// eprintln!("\nDEBUG DUMP");
// eprintln!("================================================================================\n");
// eprintln!("{}", dump);
// eprintln!("================================================================================\n");
// }
// if let Some(dump) = &self.dump {
// eprintln!("\nDEBUG DUMP");
// eprintln!("================================================================================\n");
// eprintln!("{}", dump);
// eprintln!("================================================================================\n");
// }

let why = match (&self.reason, &self.msg) {
(Some(reason), None) => format!("EXIT: {}", reason),
(Some(reason), Some(msg)) => format!("EXIT: {} ({})", reason, msg),
_ => "<UNKNOWN>".into(),
};
let why = match (&self.reason, &self.msg) {
(Some(reason), None) => format!("EXIT: {}", reason),
(Some(reason), Some(msg)) => format!("EXIT: {} ({})", reason, msg),
_ => "<UNKNOWN>".into(),
};

if why != "<UNKNOWN>"{
if why != "<UNKNOWN>" {
eprintln!("{}", why);
}
}

// if self.kind <= ScxExitKind::UnregKern as i32 {
// eprintln!("{}", why);
Expand Down
13 changes: 11 additions & 2 deletions scheds/include/scx/user_exit_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum uei_sizes {
};

struct user_exit_info {
int type;
int kind;
// s64 exit_code;
char reason[UEI_REASON_LEN];
char msg[UEI_MSG_LEN];
Expand All @@ -28,6 +28,15 @@ struct user_exit_info {
#include "vmlinux.h"
#include <bpf/bpf_core_read.h>

static inline void uei_record(struct user_exit_info *uei,
const struct scx_exit_info *ei)
{
bpf_probe_read_kernel_str(uei->reason, sizeof(uei->reason), ei->reason);
bpf_probe_read_kernel_str(uei->msg, sizeof(uei->msg), ei->msg);
/* use __sync to force memory barrier */
__sync_val_compare_and_swap(&uei->kind, uei->kind, ei->type);
}

#define UEI_DEFINE(__name) \
char RESIZABLE_ARRAY(data, __name##_dump); \
const volatile u32 __name##_dump_len; \
Expand Down Expand Up @@ -61,7 +70,7 @@ struct user_exit_info {

#define UEI_EXITED(__skel, __uei_name) ({ \
/* use __sync to force memory barrier */ \
__sync_val_compare_and_swap(&(__skel)->data->__uei_name.type, -1, -1); \
__sync_val_compare_and_swap(&(__skel)->data->__uei_name.kind, -1, -1); \
})

#define UEI_REPORT(__skel, __uei_name) ({ \
Expand Down
Loading

0 comments on commit 2621432

Please sign in to comment.