Re: [PATCH v2 bpf-next 1/2] bpftool: introduce "prog profile" command

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

 





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@xxxxxx>
---
  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
[.....]



[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