scx: init at 1.0.5 (#351746)

This commit is contained in:
Masum Reza 2024-10-29 10:30:13 +05:30 committed by GitHub
commit 9147b2d18f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 8396 additions and 0 deletions

View File

@ -0,0 +1,74 @@
{
lib,
callPackage,
pkg-config,
rustPlatform,
llvmPackages,
elfutils,
zlib,
fetchFromGitHub,
}:
let
versionInfo = lib.importJSON ./version.json;
mkScxScheduler =
packageType:
args@{ schedulerName, ... }:
(if packageType == "rust" then rustPlatform.buildRustPackage else llvmPackages.stdenv.mkDerivation)
(
args
// {
pname = "${schedulerName}";
version = args.version or versionInfo.scx.version;
src = args.src or fetchFromGitHub {
owner = "sched-ext";
repo = "scx";
rev = "refs/tags/v${versionInfo.scx.version}";
inherit (versionInfo.scx) hash;
};
nativeBuildInputs = [
pkg-config
llvmPackages.clang
] ++ (args.nativeBuildInputs or [ ]);
buildInputs = [
elfutils
zlib
] ++ (args.buildInputs or [ ]);
env.LIBCLANG_PATH = args.env.LIBCLANG_PATH or "${llvmPackages.libclang.lib}/lib";
# Needs to be disabled in BPF builds
hardeningDisable = [
"zerocallusedregs"
] ++ (args.hardeningDisable or [ ]);
meta = args.meta // {
description = args.meta.description or "";
longDescription =
(args.meta.longDescription or "")
+ ''
\n\nSched-ext schedulers are only available on supported kernels
(6.12 and above or any kernel with the scx patchset applied).'';
homepage = args.meta.homepage or "https://github.com/sched-ext/scx";
license = args.meta.license or lib.licenses.gpl2Only;
platforms = args.meta.platforms or lib.platforms.linux;
maintainers = (args.meta.maintainers or [ ]) ++ (with lib.maintainers; [ johnrtitor ]);
};
}
);
schedulers = lib.mergeAttrsList [
{ bpfland = import ./scx_bpfland; }
{ lavd = import ./scx_lavd; }
{ layered = import ./scx_layered; }
{ rlfifo = import ./scx_rlfifo; }
{ rustland = import ./scx_rustland; }
{ csheds = import ./scx_csheds.nix; }
];
in
(lib.mapAttrs (name: scheduler: callPackage scheduler { inherit mkScxScheduler; }) schedulers)
// {
inherit mkScxScheduler;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
{
stdenv,
lib,
mkScxScheduler,
}:
mkScxScheduler "rust" rec {
schedulerName = "scx_bpfland";
cargoRoot = "scheds/rust/scx_bpfland";
cargoLock.lockFile = ./Cargo.lock;
postPatch = ''
rm Cargo.toml Cargo.lock
ln -fs ${./Cargo.lock} scheds/rust/scx_bpfland/Cargo.lock
'';
preBuild = ''
cd scheds/rust/scx_bpfland
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/${stdenv.targetPlatform.config}/release/scx_bpfland $out/bin/
runHook postInstall
'';
meta = {
description = "Sched-ext Rust userspace scheduler";
longDescription = ''
Vruntime-based Sched-ext scheduler that prioritizes interactive workloads. This
scheduler is derived from scx_rustland, but it is fully implemented in BPF. It
has a minimal user-space Rust part to process command line options, collect metrics
and log out scheduling statistics. The BPF part makes all the scheduling decisions.
'';
mainProgram = "scx_bpfland";
};
}

View File

@ -0,0 +1,106 @@
{
stdenv,
lib,
mkScxScheduler,
fetchFromGitHub,
writeShellScript,
bash,
meson,
ninja,
jq,
bpftools,
elfutils,
zlib,
libbpf,
}:
let
versionInfo = lib.importJSON ./version.json;
# scx needs a specific commit of bpftool
# can be found in meson.build of scx src
# grep 'bpftool_commit =' ./meson.build
bpftools_src = fetchFromGitHub {
owner = "libbpf";
repo = "bpftool";
inherit (versionInfo.bpftool) rev hash;
fetchSubmodules = true;
};
# scx needs a specific commit of bpftool
# this imitates the fetch_bpftool script in src/meson-scripts
fetchBpftool = writeShellScript "fetch_bpftool" ''
[ "$2" == '${bpftools_src.rev}' ] || exit 1
cd "$1"
cp --no-preserve=mode,owner -r "${bpftools_src}/" ./bpftool
'';
# Fixes a bug with the meson build script where it specifies
# /bin/bash twice in the script
misbehaviorBash = writeShellScript "bash" ''
shift 1
exec ${lib.getExe bash} "$@"
'';
# Won't build with stable libbpf, so use the latest commit
libbpf-git = libbpf.overrideAttrs (oldAttrs: {
src = fetchFromGitHub {
owner = "libbpf";
repo = "libbpf";
inherit (versionInfo.libbpf) rev hash;
fetchSubmodules = true;
};
});
in
mkScxScheduler "c" rec {
schedulerName = "scx_csheds";
postPatch = ''
rm meson-scripts/fetch_bpftool
patchShebangs ./meson-scripts
cp ${fetchBpftool} meson-scripts/fetch_bpftool
substituteInPlace meson.build \
--replace-fail '[build_bpftool' "['${misbehaviorBash}', build_bpftool"
'';
nativeBuildInputs = [
meson
ninja
jq
] ++ bpftools.buildInputs ++ bpftools.nativeBuildInputs;
buildInputs = [
elfutils
zlib
libbpf-git
];
mesonFlags = [
(lib.mapAttrsToList lib.mesonEnable {
"systemd" = false;
"openrc" = false;
"libbpf_a" = false;
# not for nix
"libalpm" = false;
})
(lib.mapAttrsToList lib.mesonBool {
# needed libs are already fetched as FOD
"offline" = true;
# rust schedulers are built seperately
"enable_rust" = false;
})
];
hardeningDisable = [
"stackprotector"
];
meta = {
description = "Sched-ext C userspace schedulers";
longDescription = ''
This includes C based schedulers such as scx_central,
scx_flatcg, scx_pair, scx_qmap, scx_simple, scx_userland.
'';
};
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
{
stdenv,
lib,
mkScxScheduler,
}:
mkScxScheduler "rust" rec {
schedulerName = "scx_lavd";
cargoRoot = "scheds/rust/scx_lavd";
cargoLock.lockFile = ./Cargo.lock;
postPatch = ''
rm Cargo.toml Cargo.lock
ln -fs ${./Cargo.lock} scheds/rust/scx_lavd/Cargo.lock
'';
preBuild = ''
cd scheds/rust/scx_lavd
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/${stdenv.targetPlatform.config}/release/scx_lavd $out/bin/
runHook postInstall
'';
meta = {
description = "Sched-ext Rust userspace scheduler";
longDescription = ''
BPF scheduler that implements an LAVD (Latency-criticality Aware Virtual Deadline)
scheduling algorithm. typical use case involves highly interactive applications,
such as gaming, which requires high throughput and low tail latencies.
'';
mainProgram = "scx_lavd";
};
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
{
stdenv,
lib,
mkScxScheduler,
}:
mkScxScheduler "rust" rec {
schedulerName = "scx_layered";
cargoRoot = "scheds/rust/scx_layered";
cargoLock.lockFile = ./Cargo.lock;
postPatch = ''
rm Cargo.toml Cargo.lock
ln -fs ${./Cargo.lock} scheds/rust/scx_layered/Cargo.lock
'';
preBuild = ''
cd scheds/rust/scx_layered
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/${stdenv.targetPlatform.config}/release/scx_layered $out/bin/
runHook postInstall
'';
meta = {
description = "Sched-ext Rust userspace scheduler";
longDescription = ''
Highly configurable multi-layer BPF/userspace hybrid scheduler.
It is designed to be highly customizable, and can be targeted for specific applications.
'';
mainProgram = "scx_layered";
};
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
{
stdenv,
lib,
mkScxScheduler,
}:
mkScxScheduler "rust" rec {
schedulerName = "scx_rlfifo";
cargoRoot = "scheds/rust/scx_rlfifo";
cargoLock.lockFile = ./Cargo.lock;
postPatch = ''
rm Cargo.toml Cargo.lock
ln -fs ${./Cargo.lock} scheds/rust/scx_rlfifo/Cargo.lock
'';
preBuild = ''
cd scheds/rust/scx_rlfifo
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/${stdenv.targetPlatform.config}/release/scx_rlfifo $out/bin/
runHook postInstall
'';
meta = {
description = "Sched-ext Rust userspace scheduler";
longDescription = ''
scx_rlfifo is a simple FIFO scheduler runs in user-space, based on
the scx_rustland_core framework. Not a production ready scheduler.
'';
mainProgram = "scx_rlfifo";
};
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
{
stdenv,
lib,
mkScxScheduler,
}:
mkScxScheduler "rust" rec {
schedulerName = "scx_rustland";
cargoRoot = "scheds/rust/scx_rustland";
cargoLock.lockFile = ./Cargo.lock;
postPatch = ''
rm Cargo.toml Cargo.lock
ln -fs ${./Cargo.lock} scheds/rust/scx_rustland/Cargo.lock
'';
preBuild = ''
cd scheds/rust/scx_rustland
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/${stdenv.targetPlatform.config}/release/scx_rustland $out/bin/
runHook postInstall
'';
meta = {
description = "Sched-ext Rust userspace scheduler";
longDescription = ''
Made of a BPF component (scx_rustland_core) that implements the low level sched-ext functionalities
and a user-space counterpart (scheduler), written in Rust, that implements the actual scheduling policy.
It is designed to prioritize interactive workloads over background CPU-intensive workloads. Typical use
case involves low-latency interactive applications, such as gaming, video conferencing and live streaming.
'';
mainProgram = "scx_rustland";
};
}

View File

@ -0,0 +1,51 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p coreutils moreutils curl jq nix-prefetch-git cargo gnugrep gawk
# shellcheck shell=bash
set -euo pipefail
srcJson="$(realpath "./pkgs/os-specific/linux/scx/version.json")"
srcFolder="$(dirname "$srcJson")"
localVer=$(jq -r .version <$srcJson)
latestVer=$(curl -s https://api.github.com/repos/sched-ext/scx/releases/latest | jq -r .tag_name | sed 's/v//g')
if [ "$localVer" == "$latestVer" ]; then
exit 0
fi
latestHash=$(nix-prefetch-git https://github.com/sched-ext/scx.git --rev refs/tags/v$latestVer --quiet | jq -r .hash)
tmp=$(mktemp -d)
trap 'rm -rf -- "${tmp}"' EXIT
git clone --depth 1 --branch "v$latestVer" https://github.com/sched-ext/scx.git "$tmp/scx"
pushd "$tmp/scx"
bpftoolRev=$(grep 'bpftool_commit =' ./meson.build | awk -F"'" '{print $2}')
bpftoolHash=$(nix-prefetch-git https://github.com/libbpf/bpftool.git --rev $bpftoolRev --fetch-submodules --quiet | jq -r .hash)
libbpfRev=$(curl -s "https://api.github.com/repos/libbpf/libbpf/commits/master" | jq -r '.sha')
libbpfHash=$(nix-prefetch-git https://github.com/libbpf/libbpf.git --rev $libbpfRev --fetch-submodules --quiet | jq -r .hash)
jq \
--arg latestVer "$latestVer" --arg latestHash "$latestHash" \
--arg bpftoolRev "$bpftoolRev" --arg bpftoolHash "$bpftoolHash" \
--arg libbpfRev "$libbpfRev" --arg libbpfHash "$libbpfHash" \
".scx.version = \$latestVer | .scx.hash = \$latestHash |\
.bpftool.rev = \$bpftoolRev | .bpftool.hash = \$bpftoolHash |\
.libbpf.rev = \$libbpfRev | .libbpf.hash = \$libbpfHash" \
"$srcJson" | sponge $srcJson
rm -f Cargo.toml Cargo.lock
pushd scheds/rust
for scheduler in bpfland lavd layered rlfifo rustland; do
pushd "scx_$scheduler"
cargo generate-lockfile
cp Cargo.lock "$srcFolder/scx_$scheduler/Cargo.lock"
popd
done

View File

@ -0,0 +1,14 @@
{
"scx": {
"version": "1.0.5",
"hash": "sha256-nb2bzEanPPWTUhMmGw/8/bwOkdgNmwoZX2lMFq5Av5Q="
},
"bpftool": {
"rev": "77a72987353fcae8ce330fd87d4c7afb7677a169",
"hash": "sha256-pItTVewlXgB97AC/WH9rW9J/eYSe2ZdBkJaAgGnDeUU="
},
"libbpf": {
"rev": "09b9e83102eb8ab9e540d36b4559c55f3bcdb95d",
"hash": "sha256-0PadA9OppNGmgSTLi8sXrh3syxPVkqrnTkBr8cyp+Ug="
}
}

View File

@ -31228,6 +31228,8 @@ with pkgs;
scudcloud = callPackage ../applications/networking/instant-messengers/scudcloud { };
scx = recurseIntoAttrs (callPackage ../os-specific/linux/scx { });
shod = callPackage ../applications/window-managers/shod { };
shogun = callPackage ../applications/science/machine-learning/shogun {