From: Yafang Shao <laoar.shao@gmail.com>
To: Quentin Monnet <quentin@isovalent.com>
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
yhs@fb.com, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org, rostedt@goodmis.org,
mhiramat@kernel.org, bpf@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
Jiri Olsa <olsajiri@gmail.com>
Subject: Re: [PATCH v3 bpf-next 09/10] bpftool: Add perf event names
Date: Tue, 13 Jun 2023 23:01:17 +0800 [thread overview]
Message-ID: <CALOAHbAnXi5gRnxHH4-G+T6fVhRm=gsYR6_u0d5GRY8zFftwSg@mail.gmail.com> (raw)
In-Reply-To: <1cd688c3-f633-8ae7-97bb-8e899545118e@isovalent.com>
On Tue, Jun 13, 2023 at 9:42 PM Quentin Monnet <quentin@isovalent.com> wrote:
>
> 2023-06-12 15:16 UTC+0000 ~ Yafang Shao <laoar.shao@gmail.com>
> > Add new functions and macros to get perf event names. These names are
> > copied from tool/perf/util/{parse-events,evsel}.c, so that in the future we
> > will have a good chance to use the same code.
> >
> > Suggested-by: Jiri Olsa <olsajiri@gmail.com>
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > ---
> > tools/bpf/bpftool/perf.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++
> > tools/bpf/bpftool/perf.h | 11 +++++
>
> Although the names are deceiving, I think these should all be moved to
> link.c and link.h, where we'll actually use them, or to some other file
> with a new name. File perf.c is for implementing "bpftool perf ...".
Got it. Will move them into link.c.
>
> > 2 files changed, 118 insertions(+)
> > create mode 100644 tools/bpf/bpftool/perf.h
> >
> > diff --git a/tools/bpf/bpftool/perf.c b/tools/bpf/bpftool/perf.c
> > index 9174344..fbdf88c 100644
> > --- a/tools/bpf/bpftool/perf.c
> > +++ b/tools/bpf/bpftool/perf.c
> > @@ -18,6 +18,113 @@
> > #include <bpf/bpf.h>
> >
> > #include "main.h"
> > +#include "perf.h"
> > +
> > +static const char *perf_type_name[PERF_TYPE_MAX] = {
> > + [PERF_TYPE_HARDWARE] = "hardware",
> > + [PERF_TYPE_SOFTWARE] = "software",
> > + [PERF_TYPE_TRACEPOINT] = "tracepoint",
> > + [PERF_TYPE_HW_CACHE] = "hw-cache",
> > + [PERF_TYPE_RAW] = "raw",
> > + [PERF_TYPE_BREAKPOINT] = "breakpoint",
> > +};
> > +
> > +const char *event_symbols_hw[PERF_COUNT_HW_MAX] = {
> > + [PERF_COUNT_HW_CPU_CYCLES] = "cpu-cycles",
> > + [PERF_COUNT_HW_INSTRUCTIONS] = "instructions",
> > + [PERF_COUNT_HW_CACHE_REFERENCES] = "cache-references",
> > + [PERF_COUNT_HW_CACHE_MISSES] = "cache-misses",
> > + [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "branch-instructions",
> > + [PERF_COUNT_HW_BRANCH_MISSES] = "branch-misses",
> > + [PERF_COUNT_HW_BUS_CYCLES] = "bus-cycles",
> > + [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = "stalled-cycles-frontend",
> > + [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = "stalled-cycles-backend",
> > + [PERF_COUNT_HW_REF_CPU_CYCLES] = "ref-cycles",
> > +};
> > +
> > +const char *event_symbols_sw[PERF_COUNT_SW_MAX] = {
> > + [PERF_COUNT_SW_CPU_CLOCK] = "cpu-clock",
> > + [PERF_COUNT_SW_TASK_CLOCK] = "task-clock",
> > + [PERF_COUNT_SW_PAGE_FAULTS] = "page-faults",
> > + [PERF_COUNT_SW_CONTEXT_SWITCHES] = "context-switches",
> > + [PERF_COUNT_SW_CPU_MIGRATIONS] = "cpu-migrations",
> > + [PERF_COUNT_SW_PAGE_FAULTS_MIN] = "minor-faults",
> > + [PERF_COUNT_SW_PAGE_FAULTS_MAJ] = "major-faults",
> > + [PERF_COUNT_SW_ALIGNMENT_FAULTS] = "alignment-faults",
> > + [PERF_COUNT_SW_EMULATION_FAULTS] = "emulation-faults",
> > + [PERF_COUNT_SW_DUMMY] = "dummy",
> > + [PERF_COUNT_SW_BPF_OUTPUT] = "bpf-output",
> > + [PERF_COUNT_SW_CGROUP_SWITCHES] = "cgroup-switches",
> > +};
> > +
> > +const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX] = {
> > + [PERF_COUNT_HW_CACHE_L1D] = "L1-dcache",
> > + [PERF_COUNT_HW_CACHE_L1I] = "L1-icache",
> > + [PERF_COUNT_HW_CACHE_LL] = "LLC",
> > + [PERF_COUNT_HW_CACHE_DTLB] = "dTLB",
> > + [PERF_COUNT_HW_CACHE_ITLB] = "iTLB",
> > + [PERF_COUNT_HW_CACHE_BPU] = "branch",
> > + [PERF_COUNT_HW_CACHE_NODE] = "node",
> > +};
> > +
> > +const char *evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX] = {
> > + [PERF_COUNT_HW_CACHE_OP_READ] = "load",
> > + [PERF_COUNT_HW_CACHE_OP_WRITE] = "store",
> > + [PERF_COUNT_HW_CACHE_OP_PREFETCH] = "prefetch",
> > +};
> > +
> > +const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
> > + [PERF_COUNT_HW_CACHE_RESULT_ACCESS] = "refs",
> > + [PERF_COUNT_HW_CACHE_RESULT_MISS] = "misses",
> > +};
> > +
> > +const char *perf_type_str(enum perf_type_id t)
> > +{
> > + if (t < 0 || t >= ARRAY_SIZE(perf_type_name))
> > + return NULL;
> > +
> > + return perf_type_name[t];
> > +}
> > +
> > +const char *perf_hw_str(enum perf_hw_id t)
> > +{
> > + if (t < 0 || t >= ARRAY_SIZE(event_symbols_hw))
> > + return NULL;
> > +
> > + return event_symbols_hw[t];
> > +}
> > +
> > +const char *perf_hw_cache_str(enum perf_hw_cache_id t)
> > +{
> > + if (t < 0 || t >= ARRAY_SIZE(evsel__hw_cache))
> > + return NULL;
> > +
> > + return evsel__hw_cache[t];
> > +}
> > +
> > +const char *perf_hw_cache_op_str(enum perf_hw_cache_op_id t)
> > +{
> > + if (t < 0 || t >= ARRAY_SIZE(evsel__hw_cache_op))
> > + return NULL;
> > +
> > + return evsel__hw_cache_op[t];
> > +}
> > +
> > +const char *perf_hw_cache_op_result_str(enum perf_hw_cache_op_result_id t)
> > +{
> > + if (t < 0 || t >= ARRAY_SIZE(evsel__hw_cache_result))
> > + return NULL;
> > +
> > + return evsel__hw_cache_result[t];
> > +}
> > +
> > +const char *perf_sw_str(enum perf_sw_ids t)
> > +{
> > + if (t < 0 || t >= ARRAY_SIZE(event_symbols_sw))
> > + return NULL;
> > +
> > + return event_symbols_sw[t];
> > +}
> >
> > /* 0: undecided, 1: supported, 2: not supported */
> > static int perf_query_supported;
> > diff --git a/tools/bpf/bpftool/perf.h b/tools/bpf/bpftool/perf.h
> > new file mode 100644
> > index 0000000..3fd7e42
> > --- /dev/null
> > +++ b/tools/bpf/bpftool/perf.h
> > @@ -0,0 +1,11 @@
> > +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
> > +/* Copyright (C) 2023 Yafang Shao <laoar.shao@gmail.com> */
> > +
> > +#include <linux/perf_event.h>
> > +
> > +const char *perf_type_str(enum perf_type_id t);
> > +const char *perf_hw_str(enum perf_hw_id t);
> > +const char *perf_hw_cache_str(enum perf_hw_cache_id t);
> > +const char *perf_hw_cache_op_str(enum perf_hw_cache_op_id t);
> > +const char *perf_hw_cache_op_result_str(enum perf_hw_cache_op_result_id t);
> > +const char *perf_sw_str(enum perf_sw_ids t);
>
> I'm not sure we need all these API functions if we keep the arrays in
> bpftool. I'd probably have just a generic one and pass it the name of
> the relevant array in argument. Although I've got no objection with the
> current form if it helps unifying the code with perf in the future.
>
Sure, I will use a generic one instead.
--
Regards
Yafang
next prev parent reply other threads:[~2023-06-13 15:02 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-12 15:15 [PATCH v3 bpf-next 00/10] bpf: Support ->fill_link_info for kprobe_multi and perf_event links Yafang Shao
2023-06-12 15:15 ` [PATCH v3 bpf-next 01/10] bpf: Support ->fill_link_info for kprobe_multi Yafang Shao
2023-06-15 8:29 ` Jiri Olsa
2023-06-15 12:09 ` Yafang Shao
2023-06-16 17:24 ` Andrii Nakryiko
2023-06-17 2:48 ` Yafang Shao
2023-06-12 15:16 ` [PATCH v3 bpf-next 02/10] bpftool: Dump the kernel symbol's module name Yafang Shao
2023-06-13 13:41 ` Quentin Monnet
2023-06-13 14:56 ` Yafang Shao
2023-06-16 17:25 ` Andrii Nakryiko
2023-06-17 2:55 ` Yafang Shao
2023-06-12 15:16 ` [PATCH v3 bpf-next 03/10] bpftool: Show probed function in kprobe_multi link info Yafang Shao
2023-06-13 13:41 ` Quentin Monnet
2023-06-13 14:59 ` Yafang Shao
2023-06-13 22:36 ` Kui-Feng Lee
2023-06-14 2:42 ` Yafang Shao
2023-06-14 8:33 ` Quentin Monnet
2023-06-16 17:30 ` Andrii Nakryiko
2023-06-17 3:08 ` Yafang Shao
2023-06-20 17:17 ` Andrii Nakryiko
2023-06-21 1:29 ` Yafang Shao
2023-06-12 15:16 ` [PATCH v3 bpf-next 04/10] bpf: Protect probed address based on kptr_restrict setting Yafang Shao
2023-06-12 15:16 ` [PATCH v3 bpf-next 05/10] bpf: Clear the probe_addr for uprobe Yafang Shao
2023-06-12 17:22 ` Yonghong Song
2023-06-12 15:16 ` [PATCH v3 bpf-next 06/10] bpf: Expose symbol's respective address Yafang Shao
2023-06-12 15:16 ` [PATCH v3 bpf-next 07/10] bpf: Add a common helper bpf_copy_to_user() Yafang Shao
2023-06-12 15:16 ` [PATCH v3 bpf-next 08/10] bpf: Support ->fill_link_info for perf_event Yafang Shao
2023-06-12 17:36 ` Yonghong Song
2023-06-13 2:47 ` Yafang Shao
2023-06-14 2:34 ` Kui-Feng Lee
2023-06-14 2:45 ` Yafang Shao
2023-06-16 20:36 ` Andrii Nakryiko
2023-06-17 3:13 ` Yafang Shao
2023-06-15 10:21 ` Jiri Olsa
2023-06-15 12:10 ` Yafang Shao
2023-06-12 15:16 ` [PATCH v3 bpf-next 09/10] bpftool: Add perf event names Yafang Shao
2023-06-13 13:41 ` Quentin Monnet
2023-06-13 15:01 ` Yafang Shao [this message]
2023-06-15 10:23 ` Jiri Olsa
2023-06-12 15:16 ` [PATCH v3 bpf-next 10/10] bpftool: Show probed function in perf_event link info Yafang Shao
2023-06-13 13:42 ` Quentin Monnet
2023-06-13 15:11 ` Yafang Shao
2023-06-16 20:41 ` Andrii Nakryiko
2023-06-17 3:20 ` Yafang Shao
2023-06-17 3:29 ` Yafang Shao
2023-06-15 10:04 ` [PATCH v3 bpf-next 00/10] bpf: Support ->fill_link_info for kprobe_multi and perf_event links Jiri Olsa
2023-06-15 12:09 ` Yafang Shao
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='CALOAHbAnXi5gRnxHH4-G+T6fVhRm=gsYR6_u0d5GRY8zFftwSg@mail.gmail.com' \
--to=laoar.shao@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mhiramat@kernel.org \
--cc=olsajiri@gmail.com \
--cc=quentin@isovalent.com \
--cc=rostedt@goodmis.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@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).