All of lore.kernel.org
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Peter Ziljstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Kajol Jain <kjain@linux.ibm.com>,
	Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH v4 bpf-next 3/3] selftests/bpf: add test for bpf_get_branch_snapshot
Date: Wed, 1 Sep 2021 15:43:59 +0000	[thread overview]
Message-ID: <44C43497-13EC-4F05-B15B-40531D5C3852@fb.com> (raw)
In-Reply-To: <CAEf4BzZrEcZFNSH=YDi_NmT2oqaOhmgQvPv0THXKy4haEzBFvQ@mail.gmail.com>



> On Aug 31, 2021, at 9:08 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> 
> On Tue, Aug 31, 2021 at 7:01 PM Song Liu <songliubraving@fb.com> wrote:
>> 
>> This test uses bpf_get_branch_snapshot from a fexit program. The test uses
>> a target function (bpf_testmod_loop_test) and compares the record against
>> kallsyms. If there isn't enough record matching kallsyms, the test fails.
>> 
>> Signed-off-by: Song Liu <songliubraving@fb.com>
>> ---
> 
> LGTM, few minor nits below
> 
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> 
>> .../selftests/bpf/bpf_testmod/bpf_testmod.c   |  14 ++-
>> .../bpf/prog_tests/get_branch_snapshot.c      | 101 ++++++++++++++++++
>> .../selftests/bpf/progs/get_branch_snapshot.c |  44 ++++++++
>> tools/testing/selftests/bpf/trace_helpers.c   |  37 +++++++
>> tools/testing/selftests/bpf/trace_helpers.h   |   5 +
>> 5 files changed, 200 insertions(+), 1 deletion(-)
>> create mode 100644 tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
>> create mode 100644 tools/testing/selftests/bpf/progs/get_branch_snapshot.c
>> 
> 
> [...]
> 
>> +
>> +void test_get_branch_snapshot(void)
>> +{
>> +       struct get_branch_snapshot *skel = NULL;
>> +       int err;
>> +
>> +       if (create_perf_events()) {
>> +               test__skip();  /* system doesn't support LBR */
>> +               goto cleanup;
>> +       }
>> +
>> +       skel = get_branch_snapshot__open_and_load();
>> +       if (!ASSERT_OK_PTR(skel, "get_branch_snapshot__open_and_load"))
>> +               goto cleanup;
>> +
>> +       err = kallsyms_find("bpf_testmod_loop_test", &skel->bss->address_low);
>> +       if (!ASSERT_OK(err, "kallsyms_find"))
>> +               goto cleanup;
>> +
>> +       err = kallsyms_find_next("bpf_testmod_loop_test", &skel->bss->address_high);
>> +       if (!ASSERT_OK(err, "kallsyms_find_next"))
>> +               goto cleanup;
>> +
>> +       err = get_branch_snapshot__attach(skel);
>> +       if (!ASSERT_OK(err, "get_branch_snapshot__attach"))
>> +               goto cleanup;
>> +
>> +       /* trigger the program */
>> +       system("cat /sys/kernel/bpf_testmod > /dev/null 2>& 1");
> 
> ugh :( see prog_tests/module_attach.c, we can extract and reuse
> trigger_module_test_read() and trigger_module_test_write()

Will fix. 
> 
>> +
>> +       if (skel->bss->total_entries < 16) {
>> +               /* too few entries for the hit/waste test */
>> +               test__skip();
>> +               goto cleanup;
>> +       }
>> +
> 
> [...]
> 
>> +SEC("fexit/bpf_testmod_loop_test")
>> +int BPF_PROG(test1, int n, int ret)
>> +{
>> +       long i;
>> +
>> +       total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0);
>> +       total_entries /= sizeof(struct perf_branch_entry);
>> +
>> +       bpf_printk("total_entries %lu\n", total_entries);
>> +
>> +       for (i = 0; i < PERF_MAX_BRANCH_SNAPSHOT; i++) {
>> +               if (i >= total_entries)
>> +                       break;
>> +               if (in_range(entries[i].from) && in_range(entries[i].to))
>> +                       test1_hits++;
>> +               else if (!test1_hits)
>> +                       wasted_entries++;
>> +               bpf_printk("i %d from %llx to %llx", i, entries[i].from,
>> +                          entries[i].to);
> 
> debug leftovers? this will be polluting trace_pipe unnecessarily; same
> for above total_entries bpf_printk()

Oops.. I added/removed it for every version, but forgot this time. Will fix 
in v5. 

Thanks,
Song


      reply	other threads:[~2021-09-01 15:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01  0:35 [PATCH v4 bpf-next 0/3] bpf: introduce bpf_get_branch_snapshot Song Liu
2021-09-01  0:35 ` [PATCH v4 bpf-next 1/3] perf: enable branch record for software events Song Liu
2021-09-01  0:35 ` [PATCH v4 bpf-next 2/3] bpf: introduce helper bpf_get_branch_snapshot Song Liu
2021-09-01  4:02   ` Andrii Nakryiko
2021-09-01 15:41     ` Song Liu
2021-09-01 19:00       ` Andrii Nakryiko
2021-09-01  0:35 ` [PATCH v4 bpf-next 3/3] selftests/bpf: add test for bpf_get_branch_snapshot Song Liu
2021-09-01  4:08   ` Andrii Nakryiko
2021-09-01 15:43     ` Song Liu [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=44C43497-13EC-4F05-B15B-40531D5C3852@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=acme@kernel.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=kjain@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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.