Skip to content

Commit

Permalink
enable ide's etc. to work on bpf.c files (sched-ext#668)
Browse files Browse the repository at this point in the history
* enable ide's etc. to work on the bpf.c files
this makes it so that clangd and ide tools which use clangd
can work on the bpf.c code.

nothing should actually be changed outside of that ide/editor
environment, all the changes are ifdef'ed on LSP which is set
in the added .clangd file.

* move intf include out of both sides of ifdef toggle
  • Loading branch information
likewhatevs committed Oct 4, 2024
1 parent 7d16154 commit 67d682e
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-DLSP, -Wno-missing-declarations, -Wno-typedef-redefinition, -Wno-ignored-attributes, -xc]
6 changes: 6 additions & 0 deletions rust/scx_rustland_core/assets/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#ifdef LSP
#define __bpf__
#include "../../../../scheds/include/scx/common.bpf.h"
#else
#include <scx/common.bpf.h>
#endif

#include "intf.h"

char _license[] SEC("license") = "GPL";
Expand Down
6 changes: 6 additions & 0 deletions scheds/include/scx/common.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
#ifndef __SCX_COMMON_BPF_H
#define __SCX_COMMON_BPF_H

#ifdef LSP
#define __bpf__
#include "../vmlinux/vmlinux.h"
#else
#include "vmlinux.h"
#endif

#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <asm-generic/errno.h>
Expand Down
4 changes: 4 additions & 0 deletions scheds/include/scx/user_exit_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ struct user_exit_info {

#ifdef __bpf__

#ifdef LSP
#include "../vmlinux/vmlinux.h"
#else
#include "vmlinux.h"
#endif
#include <bpf/bpf_core_read.h>

#define UEI_DEFINE(__name) \
Expand Down
5 changes: 5 additions & 0 deletions scheds/rust/scx_layered/src/bpf/intf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ typedef unsigned u32;
typedef unsigned long long u64;
#endif

#ifdef LSP
#define __bpf__
#include "../../../../include/scx/ravg.bpf.h"
#else
#include <scx/ravg.bpf.h>
#endif

enum consts {
MAX_CPUS_SHIFT = 9,
Expand Down
7 changes: 7 additions & 0 deletions scheds/rust/scx_layered/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* Copyright (c) Meta Platforms, Inc. and affiliates. */
#ifdef LSP
#define __bpf__
#include "../../../../include/scx/common.bpf.h"
#include "../../../../include/scx/ravg_impl.bpf.h"
#else
#include <scx/common.bpf.h>
#include <scx/ravg_impl.bpf.h>
#endif

#include "intf.h"

#include <errno.h>
Expand Down
5 changes: 5 additions & 0 deletions scheds/rust/scx_mitosis/src/bpf/intf.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ typedef unsigned int u32;
typedef _Bool bool;
#endif

#ifdef LSP
#define __bpf__
#include "../../../../include/scx/ravg.bpf.h"
#else
#include <scx/ravg.bpf.h>
#endif

enum consts {
MAX_CPUS_SHIFT = 9,
Expand Down
9 changes: 9 additions & 0 deletions scheds/rust/scx_mitosis/src/bpf/mitosis.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@
* Each cell has an associated DSQ which it uses for vtime scheduling of the
* cgroups belonging to the cell.
*/

#include "intf.h"

#ifdef LSP
#define __bpf__
#include "../../../../include/scx/common.bpf.h"
#include "../../../../include/scx/ravg_impl.bpf.h"
#else
#include <scx/common.bpf.h>
#include <scx/ravg_impl.bpf.h>
#endif


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

Expand Down
5 changes: 5 additions & 0 deletions scheds/rust/scx_rusty/src/bpf/intf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ typedef unsigned int u32;
typedef unsigned long long u64;
#endif

#ifdef LSP
#define __bpf__
#include "../../../../include/scx/ravg.bpf.h"
#else
#include <scx/ravg.bpf.h>
#endif

enum consts {
MAX_CPUS = 512,
Expand Down
8 changes: 8 additions & 0 deletions scheds/rust/scx_rusty/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@
* task weight, dom mask and current dom in the task_data map and executes the
* load balance based on userspace populating the lb_data map.
*/

#ifdef LSP
#define __bpf__
#include "../../../../include/scx/common.bpf.h"
#include "../../../../include/scx/ravg_impl.bpf.h"
#else
#include <scx/common.bpf.h>
#include <scx/ravg_impl.bpf.h>
#endif

#include "intf.h"

#include <errno.h>
Expand Down

0 comments on commit 67d682e

Please sign in to comment.