Skip to content

Commit 7960981

Browse files
committed
build: switch c scheds to make
Currently we have two build systems: Cargo and Meson. Meson builds the C schedulers and is the only way, but can also drive Cargo providing a bunch of extra parameters. Meson also provides the framework for our current CI stress testing. Add a Makefile based system for building the C schedulers. We lose a lot of knobs in this migration, but that's deliberate - the very large matrix of Meson options was really confusing, and led to weird edge cases that we'd often miss in CI and with local testing. Also add the builds for the C schedulers to the CI for the first time. No real testing other than "it builds" yet. This change does not remove the Meson builds, but that is the direction. Letting them run in parallel for a while as the CI currently still relies on Meson and we should iron out any quirks with the build first. For example, we may need to vendor libbpf in Make like it was in Meson, but let's work that out in tree. All documentation is updated to remove references to Meson according to this plan. Implementation notes: - Only allows out of source builds. In source builds annoy me, and I'd rather we didn't maintain both types. Follows the `O=build` style of Linux but defaults to `build` if absent. - Uses `pkg-config` to find `libbpf`, making it easy to override the path if needed. We may still need to vendor libbpf after we find out how it does on distros. - Only supports calling `make` from the root. I tried to make it easier to call `cd scheds/c; make` but had a lot of trouble with `lib` not being nested under it. - Supports environment variables for the other tools, and these largely line up with our Cargo based build system. Aspirationally we should keep them matching wherever it makes sense. Test plan: - CI ``` jake@rooster:/data/users/jake/repos/scx/ > make install INSTALL_DIR=/tmp/nix-shell.lnmzMH/tmp.zBN35egECj make[2]: Nothing to be done for 'all'. make[2]: Nothing to be done for 'all'. make -C /data/users/jake/repos/scx/scheds/c install Installing schedulers to /tmp/nix-shell.lnmzMH/tmp.zBN35egECj Installing /data/users/jake/repos/scx/build/scheds/c/scx_simple Installing /data/users/jake/repos/scx/build/scheds/c/scx_qmap Installing /data/users/jake/repos/scx/build/scheds/c/scx_central Installing /data/users/jake/repos/scx/build/scheds/c/scx_userland Installing /data/users/jake/repos/scx/build/scheds/c/scx_nest Installing /data/users/jake/repos/scx/build/scheds/c/scx_flatcg Installing /data/users/jake/repos/scx/build/scheds/c/scx_pair Installing /data/users/jake/repos/scx/build/scheds/c/scx_prev Installing /data/users/jake/repos/scx/build/scheds/c/scx_sdt jake@rooster:/data/users/jake/repos/scx/ > ls /tmp/nix-shell.lnmzMH/tmp.zBN35egECj scx_central scx_flatcg scx_nest scx_pair scx_prev scx_qmap scx_sdt scx_simple scx_userland jake@rooster:/data/users/jake/repos/scx/ > sudo /tmp/nix-shell.lnmzMH/tmp.zBN35egECj/scx_central [SEQ 0] total : 19 local: 0 queued: 1 lost: 0 timer : 22 dispatch: 34 mismatch: 13 retry: 0 overflow: 0 [SEQ 1] total : 2285 local: 18 queued: 0 lost: 0 timer : 995 dispatch: 6908 mismatch: 25 retry: 0 overflow: 0 [SEQ 2] total : 2981 local: 61 queued: 0 lost: 0 timer : 1964 dispatch: 9048 mismatch: 29 retry: 0 overflow: 0 ^CEXIT: unregistered from user space ```
1 parent 76984a9 commit 7960981

File tree

8 files changed

+276
-205
lines changed

8 files changed

+276
-205
lines changed

.github/include/ci.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ async def run_build():
227227
"""Build all targets."""
228228
print("Running build...", flush=True)
229229

230+
print("Building C schedulers...", flush=True)
231+
await run_command(["make", "all"], no_capture=True)
232+
print("Building Rust schedulers...", flush=True)
230233
await run_command(["cargo", "build", "--all-targets", "--locked"], no_capture=True)
234+
231235
print("✓ Build completed successfully", flush=True)
232236

233237

.github/include/flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
buildInputs = with pkgs; [
9595
bash
9696
binutils
97+
bpftools
9798
clang
9899
coreutils
99100
elfutils
@@ -102,6 +103,7 @@
102103
glibc
103104
gnumake
104105
jq
106+
libbpf-git
105107
libseccomp
106108
pkg-config
107109
protobuf
@@ -170,6 +172,7 @@
170172
bash
171173
binutils
172174
black
175+
bpftools
173176
clang
174177
coreutils
175178
gcc
@@ -179,6 +182,7 @@
179182
gnused
180183
isort
181184
jq
185+
libbpf-git
182186
libseccomp.lib
183187
llvmPackages.libclang
184188
llvmPackages.libllvm

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ libbpf/
22
*.gitignore
33
PKGBUILD
44
target
5+
build/
56
*.swp
67
.cache/
78
.vscode/

INSTALL.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,23 @@ $ sudo reboot
3838
#### Setting up Dev Environment
3939

4040
```
41-
$ sudo apt install -y build-essential meson cmake cargo rustc clang llvm pkg-config libelf-dev protobuf-compiler libseccomp-dev
41+
$ sudo apt install -y build-essential cmake cargo rustc clang llvm pkg-config libelf-dev protobuf-compiler libseccomp-dev
4242
```
4343

4444
#### Build the scx schedulers from source
4545

4646
```
4747
$ git clone https://github.com/sched-ext/scx.git
4848
$ cd scx
49-
$ meson setup build
50-
$ meson compile -C build
49+
$ make all # Build C schedulers
50+
$ cargo build --release # Build Rust schedulers
5151
```
5252

5353
#### Install the scx schedulers from source
5454

5555
```
56-
$ meson install -C build
56+
$ make install INSTALL_DIR=~/bin # Install C schedulers
57+
$ ls -d scheds/rust/scx_* | xargs -I{} cargo install --path {} # Install Rust schedulers
5758
```
5859

5960
## Arch Linux
@@ -67,7 +68,7 @@ sudo pacman -S scx-scheds
6768
In addition to the packages from the previous step, install the following.
6869

6970
```
70-
$ sudo pacman -Sy meson cargo bpf pahole
71+
$ sudo pacman -Sy cargo bpf pahole
7172
```
7273

7374
## Gentoo Linux

Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Copyright (c) 2024 Meta Platforms, Inc. and affiliates.
4+
5+
# Always require out-of-source builds - default to O=build if not specified
6+
ifeq ("$(origin O)", "command line")
7+
KBUILD_OUTPUT := $(abspath $(O))
8+
else
9+
KBUILD_OUTPUT := $(CURDIR)/build
10+
endif
11+
12+
# Always redirect to out-of-tree build directory unless we're already there
13+
ifneq ($(KBUILD_OUTPUT), $(CURDIR))
14+
# Only redirect if ROOT_SRC_DIR is not set (i.e., we're not already redirected)
15+
ifeq ($(ROOT_SRC_DIR),)
16+
17+
PHONY += _all $(MAKECMDGOALS) sub-make
18+
19+
$(filter-out _all sub-make,$(MAKECMDGOALS)) _all: sub-make
20+
@:
21+
22+
sub-make:
23+
@mkdir -p $(KBUILD_OUTPUT)
24+
@$(MAKE) --no-print-directory -C $(KBUILD_OUTPUT) -f $(CURDIR)/Makefile \
25+
ROOT_SRC_DIR=$(CURDIR) \
26+
LIB_OBJ_DIR=$(KBUILD_OUTPUT)/lib SCHED_OBJ_DIR=$(KBUILD_OUTPUT)/scheds/c \
27+
$(MAKECMDGOALS)
28+
29+
.PHONY: $(PHONY)
30+
31+
# Skip the rest of the makefile when redirecting
32+
skip-makefile := 1
33+
endif
34+
endif
35+
36+
ifeq ($(skip-makefile),)
37+
38+
export BPF_CLANG ?= clang
39+
export BPFTOOL ?= bpftool
40+
41+
ARCH := $(shell uname -m)
42+
ifeq ($(ARCH),x86_64)
43+
TARGET_ARCH := x86
44+
else ifeq ($(ARCH),aarch64)
45+
TARGET_ARCH := arm64
46+
else ifeq ($(ARCH),s390x)
47+
TARGET_ARCH := s390
48+
else
49+
TARGET_ARCH := $(ARCH)
50+
endif
51+
52+
ENDIAN ?= $(shell printf '\1\0' | od -An -t x2 | awk '{print ($$1=="0001"?"little":"big")}')
53+
54+
LIBBPF_CFLAGS := $(shell pkg-config --cflags libbpf)
55+
LIBBPF_LIBS := $(shell pkg-config --libs libbpf)
56+
57+
export BPF_CFLAGS := -g -O2 -Wall -Wno-compare-distinct-pointer-types \
58+
-D__TARGET_ARCH_$(TARGET_ARCH) -mcpu=v3 -m$(ENDIAN)-endian
59+
60+
# ROOT_SRC_DIR is set by the top-level make call for out-of-source builds
61+
export ROOT_SRC_DIR ?= $(CURDIR)
62+
export BPF_INCLUDES := -I$(ROOT_SRC_DIR)/scheds/include \
63+
-I$(ROOT_SRC_DIR)/scheds/include/arch/$(TARGET_ARCH) \
64+
-I$(ROOT_SRC_DIR)/scheds/include/bpf-compat \
65+
-I$(ROOT_SRC_DIR)/scheds/include/lib \
66+
$(LIBBPF_CFLAGS)
67+
68+
export CFLAGS := -std=gnu11 -I$(ROOT_SRC_DIR)/scheds/include -I$(SCHED_OBJ_DIR) $(LIBBPF_CFLAGS)
69+
70+
export LIBBPF_DEPS := $(LIBBPF_LIBS) -lelf -lz -lzstd
71+
export THREAD_DEPS := -lpthread
72+
73+
export OBJ_DIR := $(CURDIR)
74+
ifeq ($(LIB_OBJ_DIR),)
75+
export LIB_OBJ_DIR := $(ROOT_SRC_DIR)/lib
76+
endif
77+
ifeq ($(SCHED_OBJ_DIR),)
78+
export SCHED_OBJ_DIR := $(ROOT_SRC_DIR)/scheds/c
79+
endif
80+
81+
# Scheduler lists for convenience targets
82+
C_SCHEDS := scx_simple scx_qmap scx_central scx_userland scx_nest scx_flatcg scx_pair scx_prev
83+
C_SCHEDS_LIB := scx_sdt
84+
85+
all: lib scheds-c
86+
87+
# Individual scheduler targets
88+
$(C_SCHEDS) $(C_SCHEDS_LIB): lib
89+
@mkdir -p $(SCHED_OBJ_DIR)
90+
@$(MAKE) -C $(ROOT_SRC_DIR)/scheds/c SRC_DIR=$(ROOT_SRC_DIR)/scheds/c $@
91+
92+
$(LIB_OBJ_DIR) $(SCHED_OBJ_DIR):
93+
@mkdir -p $@
94+
95+
lib:
96+
@mkdir -p $(LIB_OBJ_DIR)
97+
@$(MAKE) -C $(ROOT_SRC_DIR)/lib SRC_DIR=$(ROOT_SRC_DIR)/lib
98+
99+
scheds-c: lib
100+
@mkdir -p $(SCHED_OBJ_DIR)
101+
@$(MAKE) -C $(ROOT_SRC_DIR)/scheds/c SRC_DIR=$(ROOT_SRC_DIR)/scheds/c
102+
103+
clean:
104+
$(MAKE) -C $(ROOT_SRC_DIR)/lib clean
105+
$(MAKE) -C $(ROOT_SRC_DIR)/scheds/c clean
106+
107+
install: all
108+
$(MAKE) -C $(ROOT_SRC_DIR)/scheds/c install
109+
110+
.PHONY: all lib scheds-c clean install $(C_SCHEDS) $(C_SCHEDS_LIB)
111+
112+
endif # End of ifeq ($(skip-makefile),)

0 commit comments

Comments
 (0)