1*a5db7817SDavid Vernet /* SPDX-License-Identifier: GPL-2.0 */ 2*a5db7817SDavid Vernet /* 3*a5db7817SDavid Vernet * Create and destroy DSQs in a loop. 4*a5db7817SDavid Vernet * 5*a5db7817SDavid Vernet * Copyright (c) 2024 Meta Platforms, Inc. and affiliates. 6*a5db7817SDavid Vernet * Copyright (c) 2024 David Vernet <dvernet@meta.com> 7*a5db7817SDavid Vernet */ 8*a5db7817SDavid Vernet 9*a5db7817SDavid Vernet #include <scx/common.bpf.h> 10*a5db7817SDavid Vernet 11*a5db7817SDavid Vernet char _license[] SEC("license") = "GPL"; 12*a5db7817SDavid Vernet 13*a5db7817SDavid Vernet void BPF_STRUCT_OPS(create_dsq_exit_task, struct task_struct *p, 14*a5db7817SDavid Vernet struct scx_exit_task_args *args) 15*a5db7817SDavid Vernet { 16*a5db7817SDavid Vernet scx_bpf_destroy_dsq(p->pid); 17*a5db7817SDavid Vernet } 18*a5db7817SDavid Vernet 19*a5db7817SDavid Vernet s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init_task, struct task_struct *p, 20*a5db7817SDavid Vernet struct scx_init_task_args *args) 21*a5db7817SDavid Vernet { 22*a5db7817SDavid Vernet s32 err; 23*a5db7817SDavid Vernet 24*a5db7817SDavid Vernet err = scx_bpf_create_dsq(p->pid, -1); 25*a5db7817SDavid Vernet if (err) 26*a5db7817SDavid Vernet scx_bpf_error("Failed to create DSQ for %s[%d]", 27*a5db7817SDavid Vernet p->comm, p->pid); 28*a5db7817SDavid Vernet 29*a5db7817SDavid Vernet return err; 30*a5db7817SDavid Vernet } 31*a5db7817SDavid Vernet 32*a5db7817SDavid Vernet s32 BPF_STRUCT_OPS_SLEEPABLE(create_dsq_init) 33*a5db7817SDavid Vernet { 34*a5db7817SDavid Vernet u32 i; 35*a5db7817SDavid Vernet s32 err; 36*a5db7817SDavid Vernet 37*a5db7817SDavid Vernet bpf_for(i, 0, 1024) { 38*a5db7817SDavid Vernet err = scx_bpf_create_dsq(i, -1); 39*a5db7817SDavid Vernet if (err) { 40*a5db7817SDavid Vernet scx_bpf_error("Failed to create DSQ %d", i); 41*a5db7817SDavid Vernet return 0; 42*a5db7817SDavid Vernet } 43*a5db7817SDavid Vernet } 44*a5db7817SDavid Vernet 45*a5db7817SDavid Vernet bpf_for(i, 0, 1024) { 46*a5db7817SDavid Vernet scx_bpf_destroy_dsq(i); 47*a5db7817SDavid Vernet } 48*a5db7817SDavid Vernet 49*a5db7817SDavid Vernet return 0; 50*a5db7817SDavid Vernet } 51*a5db7817SDavid Vernet 52*a5db7817SDavid Vernet SEC(".struct_ops.link") 53*a5db7817SDavid Vernet struct sched_ext_ops create_dsq_ops = { 54*a5db7817SDavid Vernet .init_task = create_dsq_init_task, 55*a5db7817SDavid Vernet .exit_task = create_dsq_exit_task, 56*a5db7817SDavid Vernet .init = create_dsq_init, 57*a5db7817SDavid Vernet .name = "create_dsq", 58*a5db7817SDavid Vernet }; 59