1a5db7817SDavid Vernet /* SPDX-License-Identifier: GPL-2.0 */ 2a5db7817SDavid Vernet /* 3a5db7817SDavid Vernet * Copyright (c) 2024 Meta Platforms, Inc. and affiliates. 4a5db7817SDavid Vernet * Copyright (c) 2024 David Vernet <dvernet@meta.com> 5a5db7817SDavid Vernet */ 6a5db7817SDavid Vernet 7a5db7817SDavid Vernet #include <scx/common.bpf.h> 8a5db7817SDavid Vernet 9a5db7817SDavid Vernet char _license[] SEC("license") = "GPL"; 10a5db7817SDavid Vernet 11a5db7817SDavid Vernet #include "hotplug_test.h" 12a5db7817SDavid Vernet 13a5db7817SDavid Vernet UEI_DEFINE(uei); 14a5db7817SDavid Vernet 15a5db7817SDavid Vernet void BPF_STRUCT_OPS(hotplug_exit, struct scx_exit_info *ei) 16a5db7817SDavid Vernet { 17a5db7817SDavid Vernet UEI_RECORD(uei, ei); 18a5db7817SDavid Vernet } 19a5db7817SDavid Vernet 20a5db7817SDavid Vernet static void exit_from_hotplug(s32 cpu, bool onlining) 21a5db7817SDavid Vernet { 22a5db7817SDavid Vernet /* 23a5db7817SDavid Vernet * Ignored, just used to verify that we can invoke blocking kfuncs 24a5db7817SDavid Vernet * from the hotplug path. 25a5db7817SDavid Vernet */ 26a5db7817SDavid Vernet scx_bpf_create_dsq(0, -1); 27a5db7817SDavid Vernet 28a5db7817SDavid Vernet s64 code = SCX_ECODE_ACT_RESTART | HOTPLUG_EXIT_RSN; 29a5db7817SDavid Vernet 30a5db7817SDavid Vernet if (onlining) 31a5db7817SDavid Vernet code |= HOTPLUG_ONLINING; 32a5db7817SDavid Vernet 33a5db7817SDavid Vernet scx_bpf_exit(code, "hotplug event detected (%d going %s)", cpu, 34a5db7817SDavid Vernet onlining ? "online" : "offline"); 35a5db7817SDavid Vernet } 36a5db7817SDavid Vernet 37a5db7817SDavid Vernet void BPF_STRUCT_OPS_SLEEPABLE(hotplug_cpu_online, s32 cpu) 38a5db7817SDavid Vernet { 39a5db7817SDavid Vernet exit_from_hotplug(cpu, true); 40a5db7817SDavid Vernet } 41a5db7817SDavid Vernet 42a5db7817SDavid Vernet void BPF_STRUCT_OPS_SLEEPABLE(hotplug_cpu_offline, s32 cpu) 43a5db7817SDavid Vernet { 44a5db7817SDavid Vernet exit_from_hotplug(cpu, false); 45a5db7817SDavid Vernet } 46a5db7817SDavid Vernet 47a5db7817SDavid Vernet SEC(".struct_ops.link") 48a5db7817SDavid Vernet struct sched_ext_ops hotplug_cb_ops = { 49*4f7f4170SVishal Chourasia .cpu_online = (void *) hotplug_cpu_online, 50*4f7f4170SVishal Chourasia .cpu_offline = (void *) hotplug_cpu_offline, 51*4f7f4170SVishal Chourasia .exit = (void *) hotplug_exit, 52a5db7817SDavid Vernet .name = "hotplug_cbs", 53a5db7817SDavid Vernet .timeout_ms = 1000U, 54a5db7817SDavid Vernet }; 55a5db7817SDavid Vernet 56a5db7817SDavid Vernet SEC(".struct_ops.link") 57a5db7817SDavid Vernet struct sched_ext_ops hotplug_nocb_ops = { 58*4f7f4170SVishal Chourasia .exit = (void *) hotplug_exit, 59a5db7817SDavid Vernet .name = "hotplug_nocbs", 60a5db7817SDavid Vernet .timeout_ms = 1000U, 61a5db7817SDavid Vernet }; 62