On Tue, Jan 9, 2024 at 10:00 PM Yafang Shao <laoar.shao@xxxxxxxxx> wrote: > + > +SEC("iter/cgroup") > +int BPF_PROG(cpu_cgroup, struct bpf_iter_meta *meta, struct cgroup *cgrp) > +{ > + u32 *cpu, nr_running = 0, psi_nr_running = 0, nr_cpus = 0; > + unsigned int tasks[NR_PSI_TASK_COUNTS]; > + struct psi_group_cpu *groupc; > + struct bpf_cpumask *mask; > + struct task_struct *p; > + struct rq *rq; > + > + /* epilogue */ > + if (cgrp == NULL) > + return 0; > + > + mask = bpf_cpumask_create(); > + if (!mask) > + return 1; > + > + p = bpf_task_from_pid(target_pid); > + if (!p) { > + bpf_cpumask_release(mask); > + return 1; > + } > + > + bpf_cpumask_copy(mask, p->cpus_ptr); > + bpf_for_each(cpumask, cpu, &mask->cpumask) { > + rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, *cpu); > + if (!rq) > + continue; > + nr_running += rq->nr_running; > + nr_cpus += 1; > + > + groupc = (struct psi_group_cpu *)bpf_per_cpu_ptr(&system_group_pcpu, *cpu); > + if (!groupc) > + continue; > + bpf_probe_read_kernel(&tasks, sizeof(tasks), &groupc->tasks); > + psi_nr_running += tasks[NR_RUNNING]; > + } Instead of probe_read_kernel (which is not fast) please use bpf_rdonly_cast() and access groups->tasks. array should already be recognized by the verifier, but if not let's fix the verifier instead of fallback to probe_read.