42 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * A scheduler that validates the behavior of direct dispatching with a default4 * select_cpu implementation.5 *6 * Copyright (c) 2023 Meta Platforms, Inc. and affiliates.7 * Copyright (c) 2023 David Vernet <dvernet@meta.com>8 * Copyright (c) 2023 Tejun Heo <tj@kernel.org>9 */10 11#include <scx/common.bpf.h>12 13char _license[] SEC("license") = "GPL";14 15s32 BPF_STRUCT_OPS(select_cpu_dispatch_select_cpu, struct task_struct *p,16 s32 prev_cpu, u64 wake_flags)17{18 u64 dsq_id = SCX_DSQ_LOCAL;19 s32 cpu = prev_cpu;20 21 if (scx_bpf_test_and_clear_cpu_idle(cpu))22 goto dispatch;23 24 cpu = scx_bpf_pick_idle_cpu(p->cpus_ptr, 0);25 if (cpu >= 0)26 goto dispatch;27 28 dsq_id = SCX_DSQ_GLOBAL;29 cpu = prev_cpu;30 31dispatch:32 scx_bpf_dispatch(p, dsq_id, SCX_SLICE_DFL, 0);33 return cpu;34}35 36SEC(".struct_ops.link")37struct sched_ext_ops select_cpu_dispatch_ops = {38 .select_cpu = (void *) select_cpu_dispatch_select_cpu,39 .name = "select_cpu_dispatch",40 .timeout_ms = 1000U,41};42