Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
likewhatevs committed Sep 12, 2024
1 parent 5a703bf commit a036ed2
Show file tree
Hide file tree
Showing 15 changed files with 596 additions and 303 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/caching-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
- run: sudo apt update
- run: sudo apt install -y git --no-install-recommends
# get latest head commit of sched_ext for-next
- run: echo "SCHED_EXT_KERNEL_COMMIT=$(git ls-remote https://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git heads/for-next | awk '{print $1}')" >> $GITHUB_ENV

- run: echo "SCHED_EXT_KERNEL_COMMIT=21f4c19" >> $GITHUB_ENV
- uses: actions/checkout@v4

# use cached kernel if available, create after job if not
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
name: Clone Kernel
# Get the latest sched-ext enabled kernel directly from the korg
# for-next branch
run: git clone --single-branch -b for-next --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git linux
run: git clone --single-branch -b sched_ext https://github.com/sched-ext/sched_ext.git linux && cd linux && git checkout ${{ env.SCHED_EXT_KERNEL_COMMIT }}

# guard rail because we are caching
- if: ${{ steps.cache-kernel.outputs.cache-hit != 'true' }}
Expand All @@ -66,7 +66,7 @@ jobs:

- if: ${{ steps.cache-kernel.outputs.cache-hit != 'true' }}
# Build a minimal kernel (with sched-ext enabled) using virtme-ng
run: cd linux && vng -v --build --config ../.github/workflows/sched-ext.config
run: cd linux && find . -type f -exec sed -i 's/-Werror/-Wno-error/g' {} \; && vng -v --build --config ../.github/workflows/sched-ext.config

- if: ${{ steps.cache-kernel.outputs.cache-hit != 'true' }}
# Generate kernel headers
Expand All @@ -77,7 +77,8 @@ jobs:
needs: build-kernel
strategy:
matrix:
scheduler: [ scx_bpfland, scx_lavd, scx_layered, scx_rlfifo, scx_rustland, scx_rusty ]
scheduler: [ scx_layered, scx_rusty ]
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install-deps-action
Expand All @@ -93,7 +94,7 @@ jobs:
run: cargo install virtiofsd && sudo cp -a ~/.cargo/bin/virtiofsd /usr/lib/

# get latest head commit of sched_ext for-next
- run: echo "SCHED_EXT_KERNEL_COMMIT=$(git ls-remote https://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git heads/for-next | awk '{print $1}')" >> $GITHUB_ENV
- run: echo "SCHED_EXT_KERNEL_COMMIT=21f4c19" >> $GITHUB_ENV

# use cached kernel if available, create after job if not
- name: Cache Kernel
Expand Down Expand Up @@ -153,7 +154,7 @@ jobs:
run: cargo install virtiofsd && sudo cp -a ~/.cargo/bin/virtiofsd /usr/lib/

# get latest head commit of sched_ext for-next
- run: echo "SCHED_EXT_KERNEL_COMMIT=$(git ls-remote https://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git heads/for-next | awk '{print $1}')" >> $GITHUB_ENV
- run: echo "SCHED_EXT_KERNEL_COMMIT=21f4c19" >> $GITHUB_ENV
# cache bzImage alone for rust tests
- name: Cache bzImage
id: cache-bzImage
Expand Down Expand Up @@ -182,7 +183,7 @@ jobs:
needs: build-kernel
strategy:
matrix:
scheduler: [ scx_bpfland, scx_lavd, scx_layered, scx_rlfifo, scx_rustland, scx_rusty ]
scheduler: [ scx_layered, scx_rusty ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install-deps-action
Expand All @@ -198,7 +199,7 @@ jobs:
run: cargo install virtiofsd && sudo cp -a ~/.cargo/bin/virtiofsd /usr/lib/

# get latest head commit of sched_ext for-next
- run: echo "SCHED_EXT_KERNEL_COMMIT=$(git ls-remote https://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git heads/for-next | awk '{print $1}')" >> $GITHUB_ENV
- run: echo "SCHED_EXT_KERNEL_COMMIT=21f4c19" >> $GITHUB_ENV
# cache bzImage alone for rust tests
- name: Cache bzImage
id: cache-bzImage
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ libbpf/
*.gitignore
PKGBUILD
target
local-linux-checkout
.cache

16 changes: 16 additions & 0 deletions local-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -euxo pipefail

SCHED="$1"
REPO_ROOT="$(git rev-parse --show-toplevel)"

cd ./local-linux-checkout || exit 1
vng -v --memory 10G --cpu 8 --build --config "${REPO_ROOT}/.github/workflows/sched-ext.config"
cd $OLDPWD || exit 1
meson setup build -Dkernel=./local-linux-checkout -Dkernel_headers=./local-linux-checkout/usr/include -Denable_stress=true
ln -sf "${REPO_ROOT}/local-linux-checkout" "${REPO_ROOT}/build/local-linux-checkout"
meson compile -C build "$SCHED"
meson compile -C build test_sched_"$SCHED"
meson compile -C build stress_tests_"$SCHED"

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));
}
}
38 changes: 19 additions & 19 deletions rust/scx_utils/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ macro_rules! unwrap_or_break {
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?");
}
// if let Ok(false) | Err(_) = struct_has_field("sched_ext_ops", "dump") {
// bail!("sched_ext_ops.dump() missing, kernel too old?");
// }
Ok(())
}

Expand All @@ -187,21 +187,21 @@ macro_rules! scx_ops_open {
};

let ops = skel.struct_ops.[<$ops _mut>]();
let path = std::path::Path::new("/sys/kernel/sched_ext/hotplug_seq");

let val = match std::fs::read_to_string(&path) {
Ok(val) => val,
Err(_) => {
break 'block Err(anyhow::anyhow!("Failed to open or read file {:?}", path));
}
};

ops.hotplug_seq = match val.trim().parse::<u64>() {
Ok(parsed) => parsed,
Err(_) => {
break 'block Err(anyhow::anyhow!("Failed to parse hotplug seq {}", val));
}
};
// let path = std::path::Path::new("/sys/kernel/sched_ext/hotplug_seq");

// let val = match std::fs::read_to_string(&path) {
// Ok(val) => val,
// Err(_) => {
// break 'block Err(anyhow::anyhow!("Failed to open or read file {:?}", path));
// }
// };

// ops.hotplug_seq = match val.trim().parse::<u64>() {
// Ok(parsed) => parsed,
// Err(_) => {
// break 'block Err(anyhow::anyhow!("Failed to parse hotplug seq {}", val));
// }
// };

let result : Result<OpenBpfSkel<'_>, anyhow::Error> = Ok(skel);
result
Expand All @@ -218,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
16 changes: 8 additions & 8 deletions rust/scx_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ pub use bpf_builder::BpfBuilder;
mod builder;
pub use builder::Builder;

mod user_exit_info;
pub use user_exit_info::ScxConsts;
pub use user_exit_info::ScxExitKind;
pub use user_exit_info::UeiDumpPtr;
pub use user_exit_info::UserExitInfo;
pub use user_exit_info::SCX_ECODE_ACT_RESTART;
pub use user_exit_info::SCX_ECODE_RSN_HOTPLUG;
pub use user_exit_info::UEI_DUMP_PTR_MUTEX;
// mod user_exit_info;
// // pub use user_exit_info::ScxConsts;
// // pub use user_exit_info::ScxExitKind;
// pub use user_exit_info::UeiDumpPtr;
// pub use user_exit_info::UserExitInfo;
// pub use user_exit_info::SCX_ECODE_ACT_RESTART;
// pub use user_exit_info::SCX_ECODE_RSN_HOTPLUG;
// pub use user_exit_info::UEI_DUMP_PTR_MUTEX;

pub mod build_id;
pub mod compat;
Expand Down
92 changes: 92 additions & 0 deletions scheds/include/scx/compat.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,97 @@
__ret; \
})

/*
* %SCX_KICK_IDLE is a later addition. To support both before and after, use
* %__COMPAT_SCX_KICK_IDLE which becomes 0 on kernels which don't support it.
* Users can use %SCX_KICK_IDLE directly in the future.
*/
#define __COMPAT_SCX_KICK_IDLE \
__COMPAT_ENUM_OR_ZERO(enum scx_kick_flags, SCX_KICK_IDLE)

/*
* scx_switch_all() was replaced by %SCX_OPS_SWITCH_PARTIAL. See
* %__COMPAT_SCX_OPS_SWITCH_PARTIAL in compat.h. This can be dropped in the
* future.
*/
void scx_bpf_switch_all(void) __ksym __weak;

static inline void __COMPAT_scx_bpf_switch_all(void)
{
scx_bpf_switch_all();
}

/*
* scx_bpf_exit() is a new addition. Fall back to scx_bpf_error() if
* unavailable. Users can use scx_bpf_exit() directly in the future.
*/
#define __COMPAT_scx_bpf_exit(code, fmt, args...) \
({ \
if (bpf_ksym_exists(scx_bpf_exit_bstr)) \
scx_bpf_exit((code), fmt, ##args); \
else \
scx_bpf_error(fmt, ##args); \
})

/*
* scx_bpf_dump() is a new addition. Ignore if unavailable. Users can use
* scx_bpf_dump() directly in the future.
*/
#define __COMPAT_scx_bpf_dump(fmt, args...) \
({ \
if (bpf_ksym_exists(scx_bpf_dump_bstr)) \
scx_bpf_dump(fmt, ##args); \
})

/*
* scx_bpf_nr_cpu_ids(), scx_bpf_get_possible/online_cpumask() are new. No good
* way to noop these kfuncs. Provide a test macro. Users can assume existence in
* the future.
*/
#define __COMPAT_HAS_CPUMASKS \
bpf_ksym_exists(scx_bpf_nr_cpu_ids)

/*
* cpuperf is new. The followings become noop on older kernels. Callers can be
* updated to call cpuperf kfuncs directly in the future.
*/
static inline u32 __COMPAT_scx_bpf_cpuperf_cap(s32 cpu)
{
if (bpf_ksym_exists(scx_bpf_cpuperf_cap))
return scx_bpf_cpuperf_cap(cpu);
else
return 1024;
}

static inline u32 __COMPAT_scx_bpf_cpuperf_cur(s32 cpu)
{
if (bpf_ksym_exists(scx_bpf_cpuperf_cur))
return scx_bpf_cpuperf_cur(cpu);
else
return 1024;
}

static inline void __COMPAT_scx_bpf_cpuperf_set(s32 cpu, u32 perf)
{
if (bpf_ksym_exists(scx_bpf_cpuperf_set))
return scx_bpf_cpuperf_set(cpu, perf);
}

/*
* Iteration and scx_bpf_consume_task() are new. The following become noop on
* older kernels. The users can switch to bpf_for_each(scx_dsq) and directly
* call scx_bpf_consume_task() in the future.
*/
#define __COMPAT_DSQ_FOR_EACH(p, dsq_id, flags) \
if (bpf_ksym_exists(bpf_iter_scx_dsq_new)) \
bpf_for_each(scx_dsq, (p), (dsq_id), (flags))

static inline bool __COMPAT_scx_bpf_consume_task(struct bpf_iter_scx_dsq *it,
struct task_struct *p)
{
return false;
}

/*
* Define sched_ext_ops. This may be expanded to define multiple variants for
* backward compatibility. See compat.h::SCX_OPS_LOAD/ATTACH().
Expand All @@ -26,3 +117,4 @@
};

#endif /* __SCX_COMPAT_BPF_H */

4 changes: 2 additions & 2 deletions scheds/include/scx/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ static inline long scx_hotplug_seq(void)
#define SCX_OPS_OPEN(__ops_name, __scx_name) ({ \
struct __scx_name *__skel; \
\
SCX_BUG_ON(!__COMPAT_struct_has_field("sched_ext_ops", "dump"), \
"sched_ext_ops.dump() missing, kernel too old?"); \
/* SCX_BUG_ON(!__COMPAT_struct_has_field("sched_ext_ops", "dump"), */ \
/* "sched_ext_ops.dump() missing, kernel too old?"); */ \
\
__skel = __scx_name##__open(); \
SCX_BUG_ON(!__skel, "Could not open " #__scx_name); \
Expand Down
Loading

0 comments on commit a036ed2

Please sign in to comment.