Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
 1/* SPDX-License-Identifier: GPL-2.0 */
 2/*
 3 * A scheduler that verifies that we do proper counting of init, enable, etc
 4 * callbacks.
 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
15u64 init_task_cnt, exit_task_cnt, enable_cnt, disable_cnt;
16u64 init_fork_cnt, init_transition_cnt;
17
18s32 BPF_STRUCT_OPS_SLEEPABLE(cnt_init_task, struct task_struct *p,
19			     struct scx_init_task_args *args)
20{
21	__sync_fetch_and_add(&init_task_cnt, 1);
22
23	if (args->fork)
24		__sync_fetch_and_add(&init_fork_cnt, 1);
25	else
26		__sync_fetch_and_add(&init_transition_cnt, 1);
27
28	return 0;
29}
30
31void BPF_STRUCT_OPS(cnt_exit_task, struct task_struct *p)
32{
33	__sync_fetch_and_add(&exit_task_cnt, 1);
34}
35
36void BPF_STRUCT_OPS(cnt_enable, struct task_struct *p)
37{
38	__sync_fetch_and_add(&enable_cnt, 1);
39}
40
41void BPF_STRUCT_OPS(cnt_disable, struct task_struct *p)
42{
43	__sync_fetch_and_add(&disable_cnt, 1);
44}
45
46SEC(".struct_ops.link")
47struct sched_ext_ops init_enable_count_ops = {
48	.init_task	= (void *) cnt_init_task,
49	.exit_task	= (void *) cnt_exit_task,
50	.enable		= (void *) cnt_enable,
51	.disable	= (void *) cnt_disable,
52	.name		= "init_enable_count",
53};