On Wed, Jan 3, 2024 at 6:13 AM Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx> wrote: > > On Fri, Dec 22, 2023 at 3:31 AM Yafang Shao <laoar.shao@xxxxxxxxx> wrote: > > > > Add three new kfuncs for bpf_iter_cpumask. > > - bpf_iter_cpumask_new > > - bpf_iter_cpumask_next > > - bpf_iter_cpumask_destroy > > > > These new kfuncs facilitate the iteration of percpu data, such as > > runqueues, psi_cgroup_cpu, and more. > > > > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx> > > --- > > kernel/bpf/cpumask.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 48 insertions(+) > > > > diff --git a/kernel/bpf/cpumask.c b/kernel/bpf/cpumask.c > > index 2e73533..4ae07a4 100644 > > --- a/kernel/bpf/cpumask.c > > +++ b/kernel/bpf/cpumask.c > > @@ -422,6 +422,51 @@ __bpf_kfunc u32 bpf_cpumask_weight(const struct cpumask *cpumask) > > return cpumask_weight(cpumask); > > } > > > > +struct bpf_iter_cpumask { > > + __u64 __opaque[2]; > > +} __aligned(8); > > + > > +struct bpf_iter_cpumask_kern { > > + struct cpumask *mask; > > + int *cpu; > > +} __aligned(8); > > + > > +__bpf_kfunc u32 bpf_iter_cpumask_new(struct bpf_iter_cpumask *it, struct cpumask *mask) > > +{ > > + struct bpf_iter_cpumask_kern *kit = (void *)it; > > + > > + kit->cpu = bpf_mem_alloc(&bpf_global_ma, sizeof(*kit->cpu)); > > why dynamic memory allocation of 4 bytes?... just have `int cpu;` > field in bpf_iter_cpumask_kern? Will do it. Thanks for your suggestion. -- Regards Yafang