This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from sched-ext/kfuncs_syscall
scx: Allow calling scx kfuncs from BPF_PROG_TYPE_SYSCALL
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* A scheduler that validates that we can invoke sched_ext kfuncs in | ||
* BPF_PROG_TYPE_SYSCALL programs. | ||
* | ||
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. | ||
* Copyright (c) 2024 David Vernet <[email protected]> | ||
*/ | ||
|
||
#include <scx/common.bpf.h> | ||
|
||
UEI_DEFINE(uei); | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
SEC("syscall") | ||
int BPF_PROG(prog_run_syscall) | ||
{ | ||
scx_bpf_exit(0xdeadbeef, "Exited from PROG_RUN"); | ||
return 0; | ||
} | ||
|
||
void BPF_STRUCT_OPS(prog_run_exit, struct scx_exit_info *ei) | ||
{ | ||
UEI_RECORD(uei, ei); | ||
} | ||
|
||
SEC(".struct_ops.link") | ||
struct sched_ext_ops prog_run_ops = { | ||
.exit = prog_run_exit, | ||
.name = "prog_run", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. | ||
* Copyright (c) 2024 David Vernet <[email protected]> | ||
*/ | ||
#include <bpf/bpf.h> | ||
#include <sched.h> | ||
#include <scx/common.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
#include "prog_run.bpf.skel.h" | ||
#include "scx_test.h" | ||
|
||
static enum scx_test_status setup(void **ctx) | ||
{ | ||
struct prog_run *skel; | ||
|
||
skel = prog_run__open_and_load(); | ||
if (!skel) { | ||
SCX_ERR("Failed to open and load skel"); | ||
return SCX_TEST_FAIL; | ||
} | ||
*ctx = skel; | ||
|
||
return SCX_TEST_PASS; | ||
} | ||
|
||
static enum scx_test_status run(void *ctx) | ||
{ | ||
struct prog_run *skel = ctx; | ||
struct bpf_link *link; | ||
int prog_fd, err = 0; | ||
|
||
prog_fd = bpf_program__fd(skel->progs.prog_run_syscall); | ||
if (prog_fd < 0) { | ||
SCX_ERR("Failed to get BPF_PROG_RUN prog"); | ||
return SCX_TEST_FAIL; | ||
} | ||
|
||
LIBBPF_OPTS(bpf_test_run_opts, topts); | ||
|
||
link = bpf_map__attach_struct_ops(skel->maps.prog_run_ops); | ||
if (!link) { | ||
SCX_ERR("Failed to attach scheduler"); | ||
close(prog_fd); | ||
return SCX_TEST_FAIL; | ||
} | ||
|
||
//err = bpf_prog_test_run_opts(prog_fd, &topts); | ||
SCX_EQ(err, 0); | ||
|
||
/* Assumes uei.kind is written last */ | ||
while (skel->data->uei.kind == SCX_EXIT_NONE) | ||
sched_yield(); | ||
|
||
SCX_EQ(skel->data->uei.kind, SCX_EXIT_UNREG_BPF); | ||
SCX_EQ(skel->data->uei.exit_code, 0xdeadbeef); | ||
close(prog_fd); | ||
bpf_link__destroy(link); | ||
|
||
return SCX_TEST_PASS; | ||
} | ||
|
||
static void cleanup(void *ctx) | ||
{ | ||
struct prog_run *skel = ctx; | ||
|
||
prog_run__destroy(skel); | ||
} | ||
|
||
struct scx_test prog_run = { | ||
.name = "prog_run", | ||
.description = "Verify we can call into a scheduler with BPF_PROG_RUN, and invoke kfuncs", | ||
.setup = setup, | ||
.run = run, | ||
.cleanup = cleanup, | ||
}; | ||
REGISTER_SCX_TEST(&prog_run) |