All of lore.kernel.org
 help / color / mirror / Atom feed
From: Feng Zhou <zhoufeng.zf@bytedance.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@kernel.org>,
	Dave Marchevsky <davemarchevsky@fb.com>,
	Joanne Koong <joannekoong@fb.com>,
	Geliang Tang <geliang.tang@suse.com>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	duanxiongchun@bytedance.com,
	Muchun Song <songmuchun@bytedance.com>,
	Dongdong Wang <wangdongdong.6@bytedance.com>,
	Cong Wang <cong.wang@bytedance.com>,
	zhouchengming@bytedance.com, Yosry Ahmed <yosryahmed@google.com>
Subject: Re: [External] Re: [PATCH bpf-next] selftests/bpf: fix some bugs in map_lookup_percpu_elem testcase
Date: Thu, 19 May 2022 15:31:29 +0800	[thread overview]
Message-ID: <da615af0-8dfb-9487-8b41-61e48d68c1d7@bytedance.com> (raw)
In-Reply-To: <CAEf4BzabT5xdscH8jgTbAVhj415k=1MziKmAXTi6yfeo1DTBRw@mail.gmail.com>

在 2022/5/19 下午12:38, Andrii Nakryiko 写道:
> On Wed, May 18, 2022 at 8:27 PM Feng Zhou <zhoufeng.zf@bytedance.com> wrote:
>> 在 2022/5/19 上午8:17, Andrii Nakryiko 写道:
>>> On Sun, May 15, 2022 at 7:25 PM Feng zhou <zhoufeng.zf@bytedance.com> wrote:
>>>> From: Feng Zhou <zhoufeng.zf@bytedance.com>
>>>>
>>>> comments from Andrii Nakryiko, details in here:
>>>> https://lore.kernel.org/lkml/20220511093854.411-1-zhoufeng.zf@bytedance.com/T/
>>>>
>>>> use /* */ instead of //
>>>> use libbpf_num_possible_cpus() instead of sysconf(_SC_NPROCESSORS_ONLN)
>>>> use 8 bytes for value size
>>>> fix memory leak
>>>> use ASSERT_EQ instead of ASSERT_OK
>>>> add bpf_loop to fetch values on each possible CPU
>>>>
>>>> Fixes: ed7c13776e20c74486b0939a3c1de984c5efb6aa ("selftests/bpf: add test case for bpf_map_lookup_percpu_elem")
>>>> Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
>>>> ---
>>>>    .../bpf/prog_tests/map_lookup_percpu_elem.c   | 49 +++++++++------
>>>>    .../bpf/progs/test_map_lookup_percpu_elem.c   | 61 ++++++++++++-------
>>>>    2 files changed, 70 insertions(+), 40 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/bpf/prog_tests/map_lookup_percpu_elem.c b/tools/testing/selftests/bpf/prog_tests/map_lookup_percpu_elem.c
>>>> index 58b24c2112b0..89ca170f1c25 100644
>>>> --- a/tools/testing/selftests/bpf/prog_tests/map_lookup_percpu_elem.c
>>>> +++ b/tools/testing/selftests/bpf/prog_tests/map_lookup_percpu_elem.c
>>>> @@ -1,30 +1,39 @@
>>>> -// SPDX-License-Identifier: GPL-2.0
>>>> -// Copyright (c) 2022 Bytedance
>>>> +/* SPDX-License-Identifier: GPL-2.0 */
>>> heh, so for SPDX license comment the rule is to use // in .c files :)
>>> so keep SPDX as // and all others as /* */
>> will do. Thanks.
>>
>>>> +/* Copyright (c) 2022 Bytedance */
>>>>
>>>>    #include <test_progs.h>
>>>>
>>>>    #include "test_map_lookup_percpu_elem.skel.h"
>>>>
>>>> -#define TEST_VALUE  1
>>>> -
>>>>    void test_map_lookup_percpu_elem(void)
>>>>    {
>>>>           struct test_map_lookup_percpu_elem *skel;
>>>> -       int key = 0, ret;
>>>> -       int nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
>>>> -       int *buf;
>>>> +       __u64 key = 0, sum;
>>>> +       int ret, i;
>>>> +       int nr_cpus = libbpf_num_possible_cpus();
>>>> +       __u64 *buf;
>>>>
>>>> -       buf = (int *)malloc(nr_cpus*sizeof(int));
>>>> +       buf = (__u64 *)malloc(nr_cpus*sizeof(__u64));
>>> no need for casting
>> casting means no '(__u64 *)'?
>> just like this:
>> 'buf = malloc(nr_cpus * sizeof(__u64));'
>>
> yes, in C you don't need to explicitly cast void * to other pointer types

Ok, Thanks.

>
>>>>           if (!ASSERT_OK_PTR(buf, "malloc"))
>>>>                   return;
>>>> -       memset(buf, 0, nr_cpus*sizeof(int));
>>>> -       buf[0] = TEST_VALUE;
>>>>
>>>> -       skel = test_map_lookup_percpu_elem__open_and_load();
>>>> -       if (!ASSERT_OK_PTR(skel, "test_map_lookup_percpu_elem__open_and_load"))
>>>> -               return;
>>>> +       for (i=0; i<nr_cpus; i++)
>>> spaces between operators
>> will do. Thanks.
>>
>>>> +               buf[i] = i;
>>>> +       sum = (nr_cpus-1)*nr_cpus/2;
>>> same, please follow kernel code style
>> will do. Thanks.
>>
>>>> +
>>>> +       skel = test_map_lookup_percpu_elem__open();
>>>> +       if (!ASSERT_OK_PTR(skel, "test_map_lookup_percpu_elem__open"))
>>>> +               goto exit;
>>>> +
>>> nit: keep it simple, init skel to NULL and use single cleanup goto
>>> label that will destroy skel unconditionally (it deals with NULL just
>>> fine)
>> will do. Thanks.
>>
>>>> +       skel->rodata->nr_cpus = nr_cpus;
>>>> +
>>>> +       ret = test_map_lookup_percpu_elem__load(skel);
>>>> +       if (!ASSERT_OK(ret, "test_map_lookup_percpu_elem__load"))
>>>> +               goto cleanup;
>>>> +
>>>>           ret = test_map_lookup_percpu_elem__attach(skel);
>>>> -       ASSERT_OK(ret, "test_map_lookup_percpu_elem__attach");
>>>> +       if (!ASSERT_OK(ret, "test_map_lookup_percpu_elem__attach"))
>>>> +               goto cleanup;
>>>>
>>>>           ret = bpf_map_update_elem(bpf_map__fd(skel->maps.percpu_array_map), &key, buf, 0);
>>>>           ASSERT_OK(ret, "percpu_array_map update");
>>> [...]
>>


      reply	other threads:[~2022-05-19  7:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16  2:24 [PATCH bpf-next] selftests/bpf: fix some bugs in map_lookup_percpu_elem testcase Feng zhou
2022-05-17  3:09 ` Yonghong Song
2022-05-17  7:05   ` [External] " Feng Zhou
2022-05-19  0:17 ` Andrii Nakryiko
2022-05-19  3:26   ` [External] " Feng Zhou
2022-05-19  4:38     ` Andrii Nakryiko
2022-05-19  7:31       ` Feng Zhou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=da615af0-8dfb-9487-8b41-61e48d68c1d7@bytedance.com \
    --to=zhoufeng.zf@bytedance.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cong.wang@bytedance.com \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=duanxiongchun@bytedance.com \
    --cc=geliang.tang@suse.com \
    --cc=joannekoong@fb.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=songmuchun@bytedance.com \
    --cc=wangdongdong.6@bytedance.com \
    --cc=yhs@fb.com \
    --cc=yosryahmed@google.com \
    --cc=zhouchengming@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.