Re: [PATCH v2 bpf-next 2/2] selftests/bpf: Add selftests for cpumask iter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 11, 2024 at 1:52 AM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> 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.

Thanks for your suggestion.
Will do it.

-- 
Regards
Yafang





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux