Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

scx: Fix local DSQ comparison in dispatch_to_local_dsq() #219

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/sched/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ dispatch_to_local_dsq(struct rq *rq, struct rq_flags *rf, u64 dsq_id,
}

/* if the destination CPU is idle, wake it up */
if (dsp && p->sched_class > dst_rq->curr->sched_class)
if (dsp && p->sched_class < dst_rq->curr->sched_class)
resched_curr(dst_rq);

dispatch_to_local_dsq_unlock(rq, rf, src_rq, locked_dst_rq);
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/sched_ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ auto-test-targets := \
enq_select_cpu_fails \
ddsp_bogus_dsq_fail \
ddsp_vtimelocal_fail \
dsp_local_on \
exit \
hotplug \
init_enable_count \
Expand Down
65 changes: 65 additions & 0 deletions tools/testing/selftests/sched_ext/dsp_local_on.bpf.c
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,
};
58 changes: 58 additions & 0 deletions tools/testing/selftests/sched_ext/dsp_local_on.c
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)
Loading