// SPDX-License-Identifier: GPL-2.0 /* * scx_perfprobe - samples per-CPU rq->scx.cpuperf_target (the value * schedutil consumes). Kprobes sched_tick and overwrites this CPU's * bucket on every tick (~1000/s at HZ=1000). */ #include char _license[] SEC("license") = "GPL"; #define K2_MAX_CPUS 128 struct { __uint(type, BPF_MAP_TYPE_ARRAY); __uint(max_entries, K2_MAX_CPUS); __type(key, u32); __type(value, u64); } targets SEC(".maps"); /* per-CPU sched_tick hits: tells whether a CPU is really running ticks */ struct { __uint(type, BPF_MAP_TYPE_ARRAY); __uint(max_entries, K2_MAX_CPUS); __type(key, u32); __type(value, u64); } tickcnt SEC(".maps"); SEC("kprobe/sched_tick") int BPF_KPROBE(k2_sample_tick) { struct rq *rq = bpf_this_cpu_ptr(&runqueues); /* map value is u64: read the target into a u64 so we don't pass * a u32 address as an 8-byte value */ u64 t = rq->scx.cpuperf_target; u32 cpu = bpf_get_smp_processor_id(); if (cpu < K2_MAX_CPUS) bpf_map_update_elem(&targets, &cpu, &t, BPF_ANY); return 0; }