netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Song Liu <songliubraving@fb.com>, <netdev@vger.kernel.org>,
	<bpf@vger.kernel.org>
Cc: <kernel-team@fb.com>, <ast@kernel.org>, <daniel@iogearbox.net>,
	<arnaldo.melo@gmail.com>, <jolsa@kernel.org>
Subject: Re: [PATCH v2 bpf-next 1/2] bpftool: introduce "prog profile" command
Date: Sat, 29 Feb 2020 20:14:29 -0800	[thread overview]
Message-ID: <72fc922e-68be-e63d-0488-b8bd35e7213b@fb.com> (raw)
In-Reply-To: <20200228234058.634044-2-songliubraving@fb.com>



On 2/28/20 3:40 PM, Song Liu wrote:
> With fentry/fexit programs, it is possible to profile BPF program with
> hardware counters. Introduce bpftool "prog profile", which measures key
> metrics of a BPF program.
> 
> bpftool prog profile command creates per-cpu perf events. Then it attaches
> fentry/fexit programs to the target BPF program. The fentry program saves
> perf event value to a map. The fexit program reads the perf event again,
> and calculates the difference, which is the instructions/cycles used by
> the target program.
> 
> Example input and output:
> 
>    ./bpftool prog profile 3 id 337 cycles instructions llc_misses
> 
>          4228 run_cnt
>       3403698 cycles                                              (84.08%)
>       3525294 instructions   #  1.04 insn per cycle               (84.05%)
>            13 llc_misses     #  3.69 LLC misses per million isns  (83.50%)

if run_cnt is 0, the following is the result:

-bash-4.4$ sudo ./bpftool prog profile 3 id 52 cycles instructions 
llc_misses

                  0 run_cnt
                  0 cycles 

                  0 instructions        #     -nan insn per cycle 

                  0 llc_misses          #     -nan LLC misses per 
million isns

-nan is a little bit crypto for user output. maybe just says
   unknown insns per cycle
in the comment?

We can still display "0 cycles" etc. just to make output uniform.

> 
> This command measures cycles and instructions for BPF program with id
> 337 for 3 seconds. The program has triggered 4228 times. The rest of the
> output is similar to perf-stat. In this example, the counters were only
> counting ~84% of the time because of time multiplexing of perf counters.
> 
> Note that, this approach measures cycles and instructions in very small
> increments. So the fentry/fexit programs introduce noticeable errors to
> the measurement results.
> 
> The fentry/fexit programs are generated with BPF skeletons. Therefore, we
> build bpftool twice. The first time _bpftool is built without skeletons.
> Then, _bpftool is used to generate the skeletons. The second time, bpftool
> is built with skeletons.
> 
> Signed-off-by: Song Liu <songliubraving@fb.com>
> ---
>   tools/bpf/bpftool/Makefile                |  18 +
>   tools/bpf/bpftool/prog.c                  | 428 +++++++++++++++++++++-
>   tools/bpf/bpftool/skeleton/profiler.bpf.c | 171 +++++++++
>   tools/bpf/bpftool/skeleton/profiler.h     |  47 +++
>   tools/scripts/Makefile.include            |   1 +
>   5 files changed, 664 insertions(+), 1 deletion(-)
>   create mode 100644 tools/bpf/bpftool/skeleton/profiler.bpf.c
>   create mode 100644 tools/bpf/bpftool/skeleton/profiler.h
[.....]

  parent reply	other threads:[~2020-03-01  4:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28 23:40 [PATCH v2 bpf-next 0/2] bpftool: introduce prog profile Song Liu
2020-02-28 23:40 ` [PATCH v2 bpf-next 1/2] bpftool: introduce "prog profile" command Song Liu
2020-03-01  3:52   ` Yonghong Song
2020-03-01 22:37     ` Song Liu
2020-03-02  3:42       ` Yonghong Song
2020-03-02  4:26         ` Yonghong Song
2020-03-01  4:14   ` Yonghong Song [this message]
2020-03-01 22:37     ` Song Liu
2020-03-02  4:24   ` Yonghong Song
2020-03-03  0:10     ` Song Liu
2020-03-03 13:06       ` Arnaldo Carvalho de Melo
2020-03-02 13:36   ` Quentin Monnet
2020-03-02 16:52     ` Song Liu
2020-02-28 23:40 ` [PATCH v2 bpf-next 2/2] bpftool: Documentation for bpftool prog profile Song Liu
2020-03-02 13:36   ` Quentin Monnet

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=72fc922e-68be-e63d-0488-b8bd35e7213b@fb.com \
    --to=yhs@fb.com \
    --cc=arnaldo.melo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).