forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
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 torvalds#115 from sched-ext/enq_flags
Stash enq_flags when marking for direct dispatch
- Loading branch information
Showing
8 changed files
with
178 additions
and
31 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
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
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,94 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* A scheduler that validates that enqueue flags are properly stored and | ||
* applied at dispatch time when a task is directly dispatched from | ||
* ops.select_cpu(). We validate this by using scx_bpf_dispatch_vtime(), and | ||
* making the test a very basic vtime scheduler. | ||
* | ||
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. | ||
* Copyright (c) 2024 David Vernet <[email protected]> | ||
* Copyright (c) 2024 Tejun Heo <[email protected]> | ||
*/ | ||
|
||
#include <scx/common.bpf.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
volatile bool consumed; | ||
|
||
static u64 vtime_now; | ||
|
||
#define VTIME_DSQ 0 | ||
|
||
static inline bool vtime_before(u64 a, u64 b) | ||
{ | ||
return (s64)(a - b) < 0; | ||
} | ||
|
||
static inline u64 task_vtime(const struct task_struct *p) | ||
{ | ||
u64 vtime = p->scx.dsq_vtime; | ||
|
||
if (vtime_before(vtime, vtime_now - SCX_SLICE_DFL)) | ||
return vtime_now - SCX_SLICE_DFL; | ||
else | ||
return vtime; | ||
} | ||
|
||
s32 BPF_STRUCT_OPS(select_cpu_vtime_select_cpu, struct task_struct *p, | ||
s32 prev_cpu, u64 wake_flags) | ||
{ | ||
s32 cpu; | ||
|
||
cpu = scx_bpf_pick_idle_cpu(p->cpus_ptr, 0); | ||
if (cpu >= 0) | ||
goto ddsp; | ||
|
||
cpu = prev_cpu; | ||
scx_bpf_test_and_clear_cpu_idle(cpu); | ||
ddsp: | ||
scx_bpf_dispatch_vtime(p, VTIME_DSQ, SCX_SLICE_DFL, task_vtime(p), 0); | ||
return cpu; | ||
} | ||
|
||
void BPF_STRUCT_OPS(select_cpu_vtime_dispatch, s32 cpu, struct task_struct *p) | ||
{ | ||
if (scx_bpf_consume(VTIME_DSQ)) | ||
consumed = true; | ||
} | ||
|
||
void BPF_STRUCT_OPS(select_cpu_vtime_running, struct task_struct *p) | ||
{ | ||
if (vtime_before(vtime_now, p->scx.dsq_vtime)) | ||
vtime_now = p->scx.dsq_vtime; | ||
} | ||
|
||
void BPF_STRUCT_OPS(select_cpu_vtime_stopping, struct task_struct *p, | ||
bool runnable) | ||
{ | ||
p->scx.dsq_vtime += (SCX_SLICE_DFL - p->scx.slice) * 100 / p->scx.weight; | ||
} | ||
|
||
void BPF_STRUCT_OPS(select_cpu_vtime_enable, struct task_struct *p) | ||
{ | ||
p->scx.dsq_vtime = vtime_now; | ||
} | ||
|
||
s32 BPF_STRUCT_OPS_SLEEPABLE(select_cpu_vtime_init) | ||
{ | ||
scx_bpf_switch_all(); | ||
|
||
return scx_bpf_create_dsq(VTIME_DSQ, -1); | ||
} | ||
|
||
SEC(".struct_ops.link") | ||
struct sched_ext_ops select_cpu_vtime_ops = { | ||
.select_cpu = select_cpu_vtime_select_cpu, | ||
.dispatch = select_cpu_vtime_dispatch, | ||
.running = select_cpu_vtime_running, | ||
.stopping = select_cpu_vtime_stopping, | ||
.enable = select_cpu_vtime_enable, | ||
.init = select_cpu_vtime_init, | ||
.name = "select_cpu_vtime", | ||
.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,39 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. | ||
* Copyright (c) 2024 David Vernet <[email protected]> | ||
* Copyright (c) 2024 Tejun Heo <[email protected]> | ||
*/ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <libgen.h> | ||
#include <bpf/bpf.h> | ||
#include <scx/common.h> | ||
#include <sys/wait.h> | ||
#include "select_cpu_vtime.bpf.skel.h" | ||
#include "scx_test.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
struct select_cpu_vtime *skel; | ||
struct bpf_link *link; | ||
|
||
libbpf_set_strict_mode(LIBBPF_STRICT_ALL); | ||
|
||
skel = select_cpu_vtime__open_and_load(); | ||
SCX_BUG_ON(!skel, "Failed to open and load skel"); | ||
|
||
SCX_ASSERT(!skel->bss->consumed); | ||
|
||
link = bpf_map__attach_struct_ops(skel->maps.select_cpu_vtime_ops); | ||
SCX_BUG_ON(!link, "Failed to attach struct_ops"); | ||
|
||
sleep(1); | ||
|
||
SCX_ASSERT(skel->bss->consumed); | ||
|
||
bpf_link__destroy(link); | ||
select_cpu_vtime__destroy(skel); | ||
|
||
return 0; | ||
} |