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 #210 from sched-ext/create_dsq_test
scx: Add a selftest for creating and destroying a DSQ
- Loading branch information
Showing
3 changed files
with
116 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,58 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Create and destroy DSQs in a loop. | ||
* | ||
* 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"; | ||
|
||
void BPF_STRUCT_OPS(create_dsq_exit_task, struct task_struct *p, | ||
struct scx_exit_task_args *args) | ||
{ | ||
scx_bpf_destroy_dsq(p->pid); | ||
} | ||
|
||
s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init_task, struct task_struct *p, | ||
struct scx_init_task_args *args) | ||
{ | ||
s32 err; | ||
|
||
err = scx_bpf_create_dsq(p->pid, -1); | ||
if (err) | ||
scx_bpf_error("Failed to create DSQ for %s[%d]", | ||
p->comm, p->pid); | ||
|
||
return err; | ||
} | ||
|
||
s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init) | ||
{ | ||
u32 i; | ||
s32 err; | ||
|
||
bpf_for(i, 0, 1024) { | ||
err = scx_bpf_create_dsq(i, -1); | ||
if (err) { | ||
scx_bpf_error("Failed to create DSQ %d", i); | ||
return 0; | ||
} | ||
} | ||
|
||
bpf_for(i, 0, 1024) { | ||
scx_bpf_destroy_dsq(i); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
SEC(".struct_ops.link") | ||
struct sched_ext_ops create_dsq_ops = { | ||
.init_task = create_dsq_init_task, | ||
.exit_task = create_dsq_exit_task, | ||
.init = create_dsq_init, | ||
.name = "create_dsq", | ||
}; |
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,57 @@ | ||
/* 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 <sys/wait.h> | ||
#include <unistd.h> | ||
#include "create_dsq.bpf.skel.h" | ||
#include "scx_test.h" | ||
|
||
static enum scx_test_status setup(void **ctx) | ||
{ | ||
struct create_dsq *skel; | ||
|
||
skel = create_dsq__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 create_dsq *skel = ctx; | ||
struct bpf_link *link; | ||
|
||
link = bpf_map__attach_struct_ops(skel->maps.create_dsq_ops); | ||
if (!link) { | ||
SCX_ERR("Failed to attach scheduler"); | ||
return SCX_TEST_FAIL; | ||
} | ||
|
||
bpf_link__destroy(link); | ||
|
||
return SCX_TEST_PASS; | ||
} | ||
|
||
static void cleanup(void *ctx) | ||
{ | ||
struct create_dsq *skel = ctx; | ||
|
||
create_dsq__destroy(skel); | ||
} | ||
|
||
struct scx_test create_dsq = { | ||
.name = "create_dsq", | ||
.description = "Create and destroy a dsq in a loop", | ||
.setup = setup, | ||
.run = run, | ||
.cleanup = cleanup, | ||
}; | ||
REGISTER_SCX_TEST(&create_dsq) |