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.
scx: Add selftest for SCX_DSQ_LOCAL_ON dispatching
We should have _some_ test that exercises that codepath. Signed-off-by: David Vernet <[email protected]>
- Loading branch information
Showing
3 changed files
with
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. | ||
* Copyright (c) 2024 David Vernet <[email protected]> | ||
*/ | ||
#include <scx/common.bpf.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
const volatile s32 nr_cpus; | ||
|
||
UEI_DEFINE(uei); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_QUEUE); | ||
__uint(max_entries, 8192); | ||
__type(value, s32); | ||
} queue SEC(".maps"); | ||
|
||
s32 BPF_STRUCT_OPS(dsp_local_on_select_cpu, struct task_struct *p, | ||
s32 prev_cpu, u64 wake_flags) | ||
{ | ||
return prev_cpu; | ||
} | ||
|
||
void BPF_STRUCT_OPS(dsp_local_on_enqueue, struct task_struct *p, | ||
u64 enq_flags) | ||
{ | ||
s32 pid = p->pid; | ||
|
||
if (bpf_map_push_elem(&queue, &pid, 0)) | ||
scx_bpf_error("Failed to enqueue %s[%d]", p->comm, p->pid); | ||
} | ||
|
||
void BPF_STRUCT_OPS(dsp_local_on_dispatch, s32 cpu, struct task_struct *prev) | ||
{ | ||
s32 pid, target; | ||
struct task_struct *p; | ||
|
||
if (bpf_map_pop_elem(&queue, &pid)) | ||
return; | ||
|
||
p = bpf_task_from_pid(pid); | ||
if (!p) | ||
return; | ||
|
||
target = bpf_get_prandom_u32() % nr_cpus; | ||
|
||
scx_bpf_dispatch(p, SCX_DSQ_LOCAL_ON | target, SCX_SLICE_DFL, 0); | ||
bpf_task_release(p); | ||
} | ||
|
||
void BPF_STRUCT_OPS(dsp_local_on_exit, struct scx_exit_info *ei) | ||
{ | ||
UEI_RECORD(uei, ei); | ||
} | ||
|
||
SEC(".struct_ops.link") | ||
struct sched_ext_ops dsp_local_on_ops = { | ||
.select_cpu = dsp_local_on_select_cpu, | ||
.enqueue = dsp_local_on_enqueue, | ||
.dispatch = dsp_local_on_dispatch, | ||
.exit = dsp_local_on_exit, | ||
.name = "dsp_local_on", | ||
.timeout_ms = 1000U, | ||
}; |
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,58 @@ | ||
/* 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 <scx/common.h> | ||
#include <unistd.h> | ||
#include "dsp_local_on.bpf.skel.h" | ||
#include "scx_test.h" | ||
|
||
static enum scx_test_status setup(void **ctx) | ||
{ | ||
struct dsp_local_on *skel; | ||
|
||
skel = dsp_local_on__open(); | ||
SCX_FAIL_IF(!skel, "Failed to open"); | ||
|
||
skel->rodata->nr_cpus = libbpf_num_possible_cpus(); | ||
SCX_FAIL_IF(dsp_local_on__load(skel), "Failed to load skel"); | ||
*ctx = skel; | ||
|
||
return SCX_TEST_PASS; | ||
} | ||
|
||
static enum scx_test_status run(void *ctx) | ||
{ | ||
struct dsp_local_on *skel = ctx; | ||
struct bpf_link *link; | ||
|
||
link = bpf_map__attach_struct_ops(skel->maps.dsp_local_on_ops); | ||
SCX_FAIL_IF(!link, "Failed to attach struct_ops"); | ||
|
||
/* Just sleeping is fine, plenty of scheduling events happening */ | ||
sleep(1); | ||
|
||
SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_ERROR)); | ||
bpf_link__destroy(link); | ||
|
||
return SCX_TEST_PASS; | ||
} | ||
|
||
static void cleanup(void *ctx) | ||
{ | ||
struct dsp_local_on *skel = ctx; | ||
|
||
dsp_local_on__destroy(skel); | ||
} | ||
|
||
struct scx_test dsp_local_on = { | ||
.name = "dsp_local_on", | ||
.description = "Verify we can directly dispatch tasks to a local DSQs " | ||
"from osp.dispatch()", | ||
.setup = setup, | ||
.run = run, | ||
.cleanup = cleanup, | ||
}; | ||
REGISTER_SCX_TEST(&dsp_local_on) |