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