Skip to content

Commit e25cc6e

Browse files
committed
Merge branch 'jakehillion/vmlinux-tarball' into version
2 parents 4755c42 + d0cc16d commit e25cc6e

25 files changed

+105
-19
lines changed

.github/include/ci.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,24 @@ async def run_clippy():
261261

262262
async def run_tests():
263263
"""Run the test suite."""
264+
print("Checking that vmlinux.tar.zst is in sync...", flush=True)
265+
266+
with tempfile.TemporaryDirectory() as tempdir:
267+
await run_command(
268+
["tar", "-xf", "rust/scx_utils/vmlinux.tar.zst", "-C", tempdir],
269+
no_capture=True,
270+
)
271+
await run_command(
272+
[
273+
"diff",
274+
"--no-dereference",
275+
"-qr",
276+
"scheds/vmlinux/",
277+
f"{tempdir}/vmlinux/",
278+
],
279+
no_capture=True,
280+
)
281+
264282
print("Running tests...", flush=True)
265283

266284
# Make sure the selftest is built in case the build was not already run.

.github/include/flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@
175175
bpftools
176176
clang
177177
coreutils
178+
diffutils
178179
gcc
179180
git
180181
gnugrep
181182
gnumake
182183
gnused
184+
gnutar
183185
isort
184186
jq
185187
libbpf-git

Cargo.lock

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ export BPF_CFLAGS := -g -O2 -Wall -Wno-compare-distinct-pointer-types \
6060
# ROOT_SRC_DIR is set by the top-level make call for out-of-source builds
6161
export ROOT_SRC_DIR ?= $(CURDIR)
6262
export BPF_INCLUDES := -I$(ROOT_SRC_DIR)/scheds/include \
63-
-I$(ROOT_SRC_DIR)/scheds/include/arch/$(TARGET_ARCH) \
6463
-I$(ROOT_SRC_DIR)/scheds/include/bpf-compat \
6564
-I$(ROOT_SRC_DIR)/scheds/include/lib \
65+
-I$(ROOT_SRC_DIR)/scheds/vmlinux \
66+
-I$(ROOT_SRC_DIR)/scheds/vmlinux/arch/$(TARGET_ARCH) \
6667
$(LIBBPF_CFLAGS)
6768

68-
export CFLAGS := -std=gnu11 -I$(ROOT_SRC_DIR)/scheds/include -I$(SCHED_OBJ_DIR) $(LIBBPF_CFLAGS)
69+
export CFLAGS := -std=gnu11 -I$(ROOT_SRC_DIR)/scheds/include -I$(ROOT_SRC_DIR)/scheds/vmlinux -I$(SCHED_OBJ_DIR) $(LIBBPF_CFLAGS)
6970

7071
export LIBBPF_DEPS := $(LIBBPF_LIBS) -lelf -lz -lzstd
7172
export THREAD_DEPS := -lpthread

meson.build

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,13 @@ endif
277277
# BPF compilation uses the gen_bpf_o generator. The following should be
278278
# passed in as extra_args.
279279
bpf_includes = ['-I', join_paths(meson.current_source_dir(), 'scheds/include'),
280-
'-I', join_paths(meson.current_source_dir(), 'scheds/include/arch/' + arch_dict[cpu]),
281280
'-I', join_paths(meson.current_source_dir(), 'scheds/include/bpf-compat'),
282-
'-I', join_paths(meson.current_source_dir(), 'scheds/include/lib'),]
281+
'-I', join_paths(meson.current_source_dir(), 'scheds/include/lib'),
282+
'-I', join_paths(meson.current_source_dir(), 'scheds/vmlinux'),
283+
'-I', join_paths(meson.current_source_dir(), 'scheds/vmlinux/arch/' + arch_dict[cpu]),]
283284

284285
user_c_dep = [declare_dependency(
285-
include_directories: include_directories('scheds/include'),
286+
include_directories: [include_directories('scheds/include'), include_directories('scheds/vmlinux')],
286287
)]
287288

288289
lib_objs = []

rust/scx_bpf_unittests/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ fn main() {
2323
root_dir.join("lib/scxtest/"),
2424
root_dir.join("scheds/include/"),
2525
root_dir.join("scheds/include/lib"),
26-
root_dir.join("scheds/include/arch/x86/"),
26+
root_dir.join("scheds/vmlinux/"),
27+
root_dir.join("scheds/vmlinux/arch/x86/"),
2728
root_dir.join("scheds/include/bpf-compat/"),
2829
env::var("DEP_BPF_INCLUDE")
2930
.expect("libbpf-sys include must be avaiable")

rust/scx_utils/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ nvml-wrapper = { version = "0.11.0", optional = true }
2222
nvml-wrapper-sys = { version = "0.9.0", optional = true }
2323
paste = "1.0"
2424
regex = "1.11.2"
25+
ruzstd = "0.8.1"
2526
scx_stats = { path = "../scx_stats", version = "1.0.16" }
2627
serde = { version = "1.0.215", features = ["derive"] }
2728
sscanf = "0.4"
@@ -31,22 +32,22 @@ version-compare = "0.1"
3132
zbus = { version = "5.3.1", optional = true }
3233
const_format = "0.2.34"
3334
num = "0.4.3"
35+
tempfile = "3.19.1"
3436
tracing = "0.1"
3537
tracing-subscriber = "0.3"
3638
libc = "0.2.175"
3739
nix = { version = "0.30.1", features = ["resource"] }
3840

39-
[dev-dependencies]
40-
tempfile = "3.19.1"
41-
4241
[build-dependencies]
4342
anyhow = "1.0.65"
4443
bindgen = ">=0.69"
4544
glob = "0.3.2"
4645
lazy_static = "1.5.0"
4746
libbpf-cargo = "=0.26.0-beta.1"
47+
ruzstd = "0.8.1"
4848
sscanf = "0.4"
4949
tar = "0.4"
50+
tempfile = "3.19.1"
5051
vergen = { version = "8.0.0", features = ["cargo", "git", "gitcl"] }
5152
version-compare = "0.1"
5253
walkdir = "2.5"

rust/scx_utils/src/builder.rs

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
use std::{
77
fs::File,
8-
path::{Path, PathBuf},
8+
io::{Read, Seek},
9+
path::PathBuf,
910
};
1011

1112
include!("clang_info.rs");
@@ -26,6 +27,16 @@ impl Builder {
2627

2728
ar.follow_symlinks(false);
2829
ar.append_dir_all(".", BPF_H).unwrap();
30+
31+
let vmlinux_dir = tempfile::tempdir().unwrap();
32+
let mut vmlinux_tar_zst = File::open("vmlinux.tar.zst").unwrap();
33+
let vmlinux_tar = ruzstd::decoding::StreamingDecoder::new(&mut vmlinux_tar_zst).unwrap();
34+
tar::Archive::new(vmlinux_tar)
35+
.unpack(vmlinux_dir.path())
36+
.unwrap();
37+
ar.append_dir_all(".", vmlinux_dir.path().join("vmlinux"))
38+
.unwrap();
39+
2940
ar.finish().unwrap();
3041

3142
for ent in walkdir::WalkDir::new(BPF_H) {
@@ -40,16 +51,43 @@ impl Builder {
4051
let out_dir = env::var("OUT_DIR").unwrap();
4152
let clang = ClangInfo::new().unwrap();
4253
let kernel_target = clang.kernel_target().unwrap();
43-
let vmlinux_h = Path::new(&BPF_H)
44-
.join("arch")
45-
.join(kernel_target)
46-
.join("vmlinux.h")
47-
.to_str()
54+
55+
let mut vmlinux_tar_zst = File::open("vmlinux.tar.zst").unwrap();
56+
57+
let mut vmlinux_h = String::new();
58+
59+
// vmlinux.h is a symlink. dereference it here.
60+
let search: PathBuf = format!("vmlinux/arch/{kernel_target}/vmlinux.h").into();
61+
62+
let mut vmlinux_tar =
63+
ruzstd::decoding::StreamingDecoder::new(&mut vmlinux_tar_zst).unwrap();
64+
let mut archive = tar::Archive::new(&mut vmlinux_tar);
65+
let vmlinux_link_entry = archive
66+
.entries()
67+
.unwrap()
68+
.find(|x| x.as_ref().unwrap().path().unwrap() == search.as_path())
69+
.unwrap()
70+
.unwrap();
71+
72+
let vmlinux_path = PathBuf::from(vmlinux_link_entry.path().unwrap())
73+
.parent()
74+
.unwrap()
75+
.join(vmlinux_link_entry.link_name().unwrap().unwrap());
76+
77+
vmlinux_tar_zst.rewind().unwrap();
78+
let vmlinux_tar = ruzstd::decoding::StreamingDecoder::new(&mut vmlinux_tar_zst).unwrap();
79+
80+
tar::Archive::new(vmlinux_tar)
81+
.entries()
82+
.unwrap()
83+
.find(|x| x.as_ref().unwrap().path().unwrap() == vmlinux_path.as_path())
84+
.unwrap()
4885
.unwrap()
49-
.to_string();
86+
.read_to_string(&mut vmlinux_h)
87+
.unwrap();
5088

5189
let bindings = bindgen::Builder::default()
52-
.header(vmlinux_h)
90+
.header_contents(&search.to_string_lossy(), &vmlinux_h)
5391
.allowlist_type("scx_exit_kind")
5492
.allowlist_type("scx_consts")
5593
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))

rust/scx_utils/vmlinux.tar.zst

1.4 MB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)