Skip to content

Commit

Permalink
Merge pull request raspberrypi#89 from sched-ext/misc-updates
Browse files Browse the repository at this point in the history
scx: Common include files relocated and more build updates
  • Loading branch information
Byte-Lab authored Dec 4, 2023
2 parents 48b4554 + d6bd20a commit f0566ba
Show file tree
Hide file tree
Showing 35 changed files with 170 additions and 350 deletions.
14 changes: 7 additions & 7 deletions tools/sched_ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ endif

CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS) \
-I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
-I$(TOOLSINCDIR) -I$(APIDIR)
-I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include

CARGOFLAGS := --release --target-dir $(OUTPUT_DIR)
ifneq ($(CARGO_OFFLINE),)
Expand Down Expand Up @@ -122,7 +122,8 @@ endef

BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) \
$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) \
-I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
-I$(CURDIR)/include -I$(CURDIR)/include/bpf-compat \
-I$(INCLUDE_DIR) -I$(APIDIR) \
-I../../include \
$(call get_sys_includes,$(CLANG)) \
-Wall -Wno-compare-distinct-pointer-types \
Expand Down Expand Up @@ -163,8 +164,7 @@ else
$(Q)cp "$(VMLINUX_H)" $@
endif

$(SCXOBJ_DIR)/%.bpf.o: %.bpf.c $(INCLUDE_DIR)/vmlinux.h scx_common.bpf.h \
user_exit_info.h ravg.bpf.h ravg_impl.bpf.h \
$(SCXOBJ_DIR)/%.bpf.o: %.bpf.c $(INCLUDE_DIR)/vmlinux.h include/scx/*.h \
| $(BPFOBJ) $(SCXOBJ_DIR)
$(call msg,CLNG-BPF,,$(notdir $@))
$(Q)$(CLANG) $(BPF_CFLAGS) -target bpf -c $< -o $@
Expand All @@ -179,7 +179,7 @@ $(INCLUDE_DIR)/%.bpf.skel.h: $(SCXOBJ_DIR)/%.bpf.o $(INCLUDE_DIR)/vmlinux.h $(BP
$(Q)$(BPFTOOL) gen skeleton $(<:.o=.linked3.o) name $(subst .bpf.skel.h,,$(sched)) > $@
$(Q)$(BPFTOOL) gen subskeleton $(<:.o=.linked3.o) name $(subst .bpf.skel.h,,$(sched)) > $(@:.skel.h=.subskel.h)

SCX_COMMON_DEPS := scx_common.h user_exit_info.h | $(BINDIR)
SCX_COMMON_DEPS := include/scx/common.h include/scx/user_exit_info.h | $(BINDIR)

################
# C schedulers #
Expand Down Expand Up @@ -216,8 +216,8 @@ $(addsuffix _deps,$(rust-sched-targets)):

$(rust-sched-targets): %: $(INCLUDE_DIR)/vmlinux.h $(SCX_COMMON_DEPS)
$(eval export RUSTFLAGS = -C link-args=-lzstd -C link-args=-lz -C link-args=-lelf -L $(BPFOBJ_DIR))
$(eval export SCX_RUST_CLANG = $(CLANG))
$(eval export SCX_RUST_BPF_CFLAGS= $(BPF_CFLAGS))
$(eval export BPF_CLANG = $(CLANG))
$(eval export BPF_CFLAGS = $(BPF_CFLAGS))
$(eval sched=$(notdir $@))
$(Q)cargo build --manifest-path=$(sched)/Cargo.toml $(CARGOFLAGS)
$(Q)cp $(OUTPUT_DIR)/release/$(sched) $(BINDIR)/$@
Expand Down
1 change: 0 additions & 1 deletion tools/sched_ext/gnu/stubs.h

This file was deleted.

11 changes: 11 additions & 0 deletions tools/sched_ext/include/bpf-compat/gnu/stubs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Dummy gnu/stubs.h. clang can end up including /usr/include/gnu/stubs.h when
* compiling BPF files although its content doesn't play any role. The file in
* turn includes stubs-64.h or stubs-32.h depending on whether __x86_64__ is
* defined. When compiling a BPF source, __x86_64__ isn't set and thus
* stubs-32.h is selected. However, the file is not there if the system doesn't
* have 32bit glibc devel package installed leading to a build failure.
*
* The problem is worked around by making this file available in the include
* search paths before the system one when building BPF.
*/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
82 changes: 0 additions & 82 deletions tools/sched_ext/ravg_read.rs.h

This file was deleted.

2 changes: 1 addition & 1 deletion tools/sched_ext/scx_central.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* Copyright (c) 2022 Tejun Heo <tj@kernel.org>
* Copyright (c) 2022 David Vernet <dvernet@meta.com>
*/
#include "scx_common.bpf.h"
#include <scx/common.bpf.h>

char _license[] SEC("license") = "GPL";

Expand Down
2 changes: 1 addition & 1 deletion tools/sched_ext/scx_central.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <signal.h>
#include <libgen.h>
#include <bpf/bpf.h>
#include "scx_common.h"
#include <scx/common.h>
#include "scx_central.bpf.skel.h"

const char help_fmt[] =
Expand Down
3 changes: 1 addition & 2 deletions tools/sched_ext/scx_flatcg.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
* within by using nested weighted vtime scheduling by default. The
* cgroup-internal scheduling can be switched to FIFO with the -f option.
*/
#include "scx_common.bpf.h"
#include "user_exit_info.h"
#include <scx/common.bpf.h>
#include "scx_flatcg.h"

char _license[] SEC("license") = "GPL";
Expand Down
2 changes: 1 addition & 1 deletion tools/sched_ext/scx_flatcg.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <fcntl.h>
#include <time.h>
#include <bpf/bpf.h>
#include "scx_common.h"
#include <scx/common.h>
#include "scx_flatcg.h"
#include "scx_flatcg.bpf.skel.h"

Expand Down
6 changes: 2 additions & 4 deletions tools/sched_ext/scx_layered/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ ctrlc = { version = "3.1", features = ["termination"] }
fb_procfs = "0.7"
lazy_static = "1.4"
libbpf-rs = "0.21"
libbpf-sys = { version = "1.2.0", features = ["novendor", "static"] }
libc = "0.2"
log = "0.4"
scx_utils = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
simplelog = "0.12"

[build-dependencies]
bindgen = { version = "0.61" }
libbpf-cargo = "0.21"
glob = "0.3"
scx_utils = "0.3"

[features]
enable_backtrace = []
78 changes: 7 additions & 71 deletions tools/sched_ext/scx_layered/build.rs
Original file line number Diff line number Diff line change
@@ -1,77 +1,13 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
extern crate bindgen;

use std::env;
use std::fs::create_dir_all;
use std::path::Path;
use std::path::PathBuf;

use glob::glob;
use libbpf_cargo::SkeletonBuilder;

const HEADER_PATH: &str = "src/bpf/layered.h";

fn bindgen_layered() {
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed={}", HEADER_PATH);

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header(HEADER_PATH)
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");

// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("layered_sys.rs"))
.expect("Couldn't write bindings!");
}

fn gen_bpf_sched(name: &str) {
let bpf_cflags = env::var("SCX_RUST_BPF_CFLAGS").unwrap();
let clang = env::var("SCX_RUST_CLANG").unwrap();
eprintln!("{}", clang);
let outpath = format!("./src/bpf/.output/{}.skel.rs", name);
let skel = Path::new(&outpath);
let src = format!("./src/bpf/{}.bpf.c", name);
let obj = format!("./src/bpf/.output/{}.bpf.o", name);
SkeletonBuilder::new()
.source(src.clone())
.obj(obj)
.clang(clang)
.clang_args(bpf_cflags)
.build_and_generate(skel)
.unwrap();

// Trigger rebuild if any .[hc] files are changed in the directory.
for path in glob("./src/bpf/*.[hc]").unwrap().filter_map(Result::ok) {
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
}
}

fn main() {
bindgen_layered();
// It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton.
// Reasons are because the generated skeleton contains compiler attributes
// that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]`
// trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside
// the path attribute either (see https://github.com/rust-lang/rust/pull/83366).
//
// However, there is hope! When the above feature stabilizes we can clean this
// all up.
create_dir_all("./src/bpf/.output").unwrap();
gen_bpf_sched("layered");
scx_utils::BpfBuilder::new()
.unwrap()
.enable_intf("src/bpf/intf.h", "bpf_intf.rs")
.enable_skel("src/bpf/main.bpf.c", "bpf")
.build()
.unwrap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
#ifndef __LAYERED_H
#define __LAYERED_H
#ifndef __INTF_H
#define __INTF_H

#include <stdbool.h>
#ifndef __kptr
Expand All @@ -18,7 +18,7 @@ typedef unsigned long long u64;
typedef long long s64;
#endif

#include "../../../ravg.bpf.h"
#include <scx/ravg.bpf.h>

enum consts {
MAX_CPUS_SHIFT = 9,
Expand Down Expand Up @@ -97,4 +97,4 @@ struct layer {
unsigned int nr_cpus; // managed from BPF side
};

#endif /* __LAYERED_H */
#endif /* __INTF_H */
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Copyright (c) Meta Platforms, Inc. and affiliates. */
#include "../../../scx_common.bpf.h"
#include "layered.h"
#include <scx/common.bpf.h>
#include <scx/ravg_impl.bpf.h>
#include "intf.h"

#include <errno.h>
#include <stdbool.h>
Expand All @@ -27,7 +28,6 @@ static u32 preempt_cursor;
#define trace(fmt, args...) do { if (debug > 1) bpf_printk(fmt, ##args); } while (0)

#include "util.bpf.c"
#include "../../../ravg_impl.bpf.h"

struct user_exit_info uei;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
#![allow(non_snake_case)]
#![allow(dead_code)]

include!(concat!(env!("OUT_DIR"), "/rusty_sys.rs"));
include!(concat!(env!("OUT_DIR"), "/bpf_intf.rs"));
12 changes: 12 additions & 0 deletions tools/sched_ext/scx_layered/src/bpf_skel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.

// We can't directly include the generated skeleton in main.rs as it may
// contain compiler attributes that can't be `include!()`ed via macro and we
// can't use the `#[path = "..."]` because `concat!(env!("OUT_DIR"),
// "/bpf.skel.rs")` does not work inside the path attribute yet (see
// https://github.com/rust-lang/rust/pull/83366).

include!(concat!(env!("OUT_DIR"), "/bpf_skel.rs"));
Loading

0 comments on commit f0566ba

Please sign in to comment.