Conversation
05fde51 to
17191cb
Compare
17191cb to
f8e4b86
Compare
|
@ananthb Thank you for the PR! One comment, otherwise LGTM. Out of curiosity: Why are we using Fedora instead of Alpine? Alpine is much more lightweight and builds significantly faster, particularly when cross-compiling (i.e. when the whole build container runs in software emulation). Fedora is not a blocker, I'm just curious. |
|
@t-lo literally just what I was running on the laptop when I wrote it. I'll take a crack at getting this compiling on Alpine. Shouldn't be hard. |
f8e4b86 to
e84cf62
Compare
|
Using an alpine base image now. |
|
Hmmm, that doesn't seem to work. I've built a test sysext and ran it: Then, in the VM: It seems to be dynamically linked: Can we produce statically linked Rust binaries? I tried a bit myself using but that ran into linker issues. I'm not too knowledgeable with Rust, sorry. |
Add the scx repository to enable running sched-ext/scx userspace schedulers. Signed-off-by: Ananth Bhaskararaman <antsub@gmail.com>
|
Can you give it a shot now? |
t-lo
left a comment
There was a problem hiding this comment.
Not quite there but getting in shape.
| zlib-dev \ | ||
| zstd-dev \ |
There was a problem hiding this comment.
| zlib-dev \ | |
| zstd-dev \ | |
| zlib-dev \ | |
| zlib-static \ | |
| zstd-dev \ | |
| zstd-static \ |
We can add the static libraries here so we don't need to check later.
| export RUSTFLAGS="-C target-feature=+crt-static" | ||
| export PKG_CONFIG_ALL_STATIC=1 | ||
| export LIBBPF_SYS_STATIC=1 | ||
| export RUSTFLAGS="${RUSTFLAGS} -C link-arg=-lzstd" |
There was a problem hiding this comment.
| export RUSTFLAGS="-C target-feature=+crt-static" | |
| export PKG_CONFIG_ALL_STATIC=1 | |
| export LIBBPF_SYS_STATIC=1 | |
| export RUSTFLAGS="${RUSTFLAGS} -C link-arg=-lzstd" | |
| TARGET="$(echo "${target}" | tr a-z- A-Z_)" | |
| export CARGO_TARGET_${TARGET}_RUSTFLAGS="-C target-feature=+crt-static -lz -lzstd -lpthread -L /usr/lib -C link-arg=-Wl,-static" | |
| export CARGO_TARGET_${TARGET}_PKG_CONFIG_ALL_STATIC=1 | |
| export CARGO_TARGET_${TARGET}_LIBBPF_SYS_STATIC=1 |
Since we're cross-compiling (via CARGO_BUILD_TARGET=... above) we need to use CARGO_TARGET_... env variable names (as per https://github.com/cross-rs/cross/wiki/Configuration#cargo-configuration). Also, we can link host libraries directly (via -L /usr/lib) since we're using the host target (host: line in rustc info).
| # Verify binaries are fully static (no NEEDED entries). | ||
| for bin in target/release/scx_*; do | ||
| if [ -x "${bin}" ]; then | ||
| needed="$(scanelf --needed --nobanner -F '%N' "${bin}")" | ||
| if [ -n "${needed}" ]; then | ||
| echo "ERROR: ${bin} is not fully static (NEEDED: ${needed})" | ||
| exit 1 | ||
| fi | ||
| fi | ||
| done |
There was a problem hiding this comment.
| # Verify binaries are fully static (no NEEDED entries). | |
| for bin in target/release/scx_*; do | |
| if [ -x "${bin}" ]; then | |
| needed="$(scanelf --needed --nobanner -F '%N' "${bin}")" | |
| if [ -n "${needed}" ]; then | |
| echo "ERROR: ${bin} is not fully static (NEEDED: ${needed})" | |
| exit 1 | |
| fi | |
| fi | |
| done |
I think we can drop this; we've verified in the PR review that cargo / rustc are actually building static binaries.
| # Ensure libz static is available for fully static linking. | ||
| if [ ! -f /usr/lib/libz.a ] && [ ! -f /lib/libz.a ] && [ ! -f /usr/local/lib/libz.a ]; then | ||
| zlib_version="1.3.1" | ||
| workdir="/tmp/zlib-${zlib_version}" | ||
| zlib_url="https://zlib.net/zlib-${zlib_version}.tar.gz" | ||
| if ! curl -fsSL "${zlib_url}" -o /tmp/zlib.tar.gz; then | ||
| curl -fsSL "https://zlib.net/fossils/zlib-${zlib_version}.tar.gz" -o /tmp/zlib.tar.gz | ||
| fi | ||
| tar -C /tmp -xf /tmp/zlib.tar.gz | ||
| cd "${workdir}" | ||
| ./configure --static | ||
| make -j"$(nproc)" | ||
| make install | ||
| cd /opt/scx | ||
| export LIBRARY_PATH="/usr/local/lib:${LIBRARY_PATH:-}" | ||
| export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH:-}" | ||
| fi | ||
|
|
||
| # Ensure libzstd static is available for libelf static linking. | ||
| if [ ! -f /usr/lib/libzstd.a ] && [ ! -f /lib/libzstd.a ] && [ ! -f /usr/local/lib/libzstd.a ]; then | ||
| zstd_version="1.5.7" | ||
| workdir="/tmp/zstd-${zstd_version}" | ||
| curl -fsSL "https://github.com/facebook/zstd/releases/download/v${zstd_version}/zstd-${zstd_version}.tar.gz" -o /tmp/zstd.tar.gz | ||
| tar -C /tmp -xf /tmp/zstd.tar.gz | ||
| cd "${workdir}" | ||
| make -j"$(nproc)" | ||
| make install PREFIX=/usr/local | ||
| cd /opt/scx | ||
| export LIBRARY_PATH="/usr/local/lib:${LIBRARY_PATH:-}" | ||
| export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH:-}" | ||
| fi |
There was a problem hiding this comment.
| # Ensure libz static is available for fully static linking. | |
| if [ ! -f /usr/lib/libz.a ] && [ ! -f /lib/libz.a ] && [ ! -f /usr/local/lib/libz.a ]; then | |
| zlib_version="1.3.1" | |
| workdir="/tmp/zlib-${zlib_version}" | |
| zlib_url="https://zlib.net/zlib-${zlib_version}.tar.gz" | |
| if ! curl -fsSL "${zlib_url}" -o /tmp/zlib.tar.gz; then | |
| curl -fsSL "https://zlib.net/fossils/zlib-${zlib_version}.tar.gz" -o /tmp/zlib.tar.gz | |
| fi | |
| tar -C /tmp -xf /tmp/zlib.tar.gz | |
| cd "${workdir}" | |
| ./configure --static | |
| make -j"$(nproc)" | |
| make install | |
| cd /opt/scx | |
| export LIBRARY_PATH="/usr/local/lib:${LIBRARY_PATH:-}" | |
| export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH:-}" | |
| fi | |
| # Ensure libzstd static is available for libelf static linking. | |
| if [ ! -f /usr/lib/libzstd.a ] && [ ! -f /lib/libzstd.a ] && [ ! -f /usr/local/lib/libzstd.a ]; then | |
| zstd_version="1.5.7" | |
| workdir="/tmp/zstd-${zstd_version}" | |
| curl -fsSL "https://github.com/facebook/zstd/releases/download/v${zstd_version}/zstd-${zstd_version}.tar.gz" -o /tmp/zstd.tar.gz | |
| tar -C /tmp -xf /tmp/zstd.tar.gz | |
| cd "${workdir}" | |
| make -j"$(nproc)" | |
| make install PREFIX=/usr/local | |
| cd /opt/scx | |
| export LIBRARY_PATH="/usr/local/lib:${LIBRARY_PATH:-}" | |
| export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH:-}" | |
| fi |
Not needed anymore as we're directly installing the static versions of our lib dependencies via apk.
|
|
||
| # Install binaries (only executables, not .d dependency files) | ||
| mkdir -p /install_root/usr/bin | ||
| find target/release -maxdepth 1 -name 'scx_*' -type f -executable -exec cp {} /install_root/usr/bin/ \; |
There was a problem hiding this comment.
| find target/release -maxdepth 1 -name 'scx_*' -type f -executable -exec cp {} /install_root/usr/bin/ \; | |
| find "target/${target}/release" -maxdepth 1 -name 'scx*' -type f -executable -exec cp \{\} /install_root/usr/bin/ \; |
We're cross-compiling, so build output would to go a sub-directory, e.g. target/x86_64-alpine-linux-musl/release for x86.
Also, if we drop the _ in our filter (scx_* => scx*) we'd also get scxtop and scxcash (tool for cache usage) which I think could be desirable?
| - `scx_rusty` - multi-domain BPF + user space hybrid scheduler | ||
| - `scx_rustland` - BPF + user space rust scheduler | ||
| - `scx_simple` - simple scheduler for demonstration purposes | ||
|
|
There was a problem hiding this comment.
| - scx_beerland | |
| - scx_flash | |
| - scx_layered | |
| - scx_rlfifo | |
| - scx_wd40 | |
| - scx_chaos | |
| - scx_cosmos | |
| - scx_mitosis | |
| - scx_p2dq | |
| - scx_tickless | |
| Tools include: | |
| - `scxtop` - top-like utility for scheduler telemetry | |
| - `scxcash` - Cache usage analyser | |
Full list of schedulers (as of 1.0.10). Feel free to add short descriptions 😉
| # scx_rusty - multi-domain BPF + user space hybrid scheduler | ||
| # scx_rustland - BPF + user space rust scheduler | ||
| # scx_simple - simple scheduler for demonstration purposes | ||
| # |
There was a problem hiding this comment.
| # | |
| # scx_beerland | |
| # scx_flash | |
| # scx_layered | |
| # scx_rlfifo | |
| # scx_wd40 | |
| # scx_chaos | |
| # scx_cosmos | |
| # scx_mitosis | |
| # scx_p2dq | |
| # scx_tickless | |
| # |
|
Your new approach of cross-compiling looks great! It wasn't using the correct Great work, keep pushing! |
|
Yep I got a basic compile going with podman but I stopped short of actually running it. I'm on NixOS so getting the shell right was more work than I had time for. I can give it another shot this weekend! |
Run userspace schedulers with sched-ext/scx
Add the scx repository to run sched-ext/scx userspace schedulers.
sched-ext is a Kernel subsystem that allows running task schedulers
in userspace. This repository adds a host of userspace schedulers and
tooling to load, run, and unload them.
How to use
TODO
Testing done
[Describe the testing you have done before submitting this PR. Please include both the commands you issued as well as the output you got.]
changelog/directory (user-facing change, bug fix, security fix, update)/bootand/usrsize, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.