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