bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 v5 bpf-next 10/11] bpftool: Add perf event names
Date: Sun, 25 Jun 2023 22:30:13 +0800	[thread overview]
Message-ID: <CALOAHbB19cmkTC8aEXSiq-cncZCnv0jRoJeBiq6kiEtnn+=62Q@mail.gmail.com> (raw)
In-Reply-To: <74aab2b3-db85-abde-5361-f638c272c096@isovalent.com>

On Sat, Jun 24, 2023 at 12:49 AM Quentin Monnet <quentin@isovalent.com> wrote:
>
> 2023-06-23 14:15 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/link.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 67 insertions(+)
> >
> > diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> > index 8461e6d..e5aeee3 100644
> > --- a/tools/bpf/bpftool/link.c
> > +++ b/tools/bpf/bpftool/link.c
> > @@ -5,6 +5,7 @@
> >  #include <linux/err.h>
> >  #include <linux/netfilter.h>
> >  #include <linux/netfilter_arp.h>
> > +#include <linux/perf_event.h>
> >  #include <net/if.h>
> >  #include <stdio.h>
> >  #include <unistd.h>
> > @@ -19,6 +20,72 @@
> >  static struct hashmap *link_table;
> >  static struct dump_data dd = {};
> >
> > +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",
> > +};
>
> These ones (above) are not defined in perf, are they?

Right. Will add an explanation in the commit log in the next version.

>
> > +
> > +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",
> > +};
> > +
> > +#define perf_event_name(array, id) ({                        \
> > +     const char *event_str = NULL;                   \
> > +                                                     \
> > +     if ((id) >= 0 && (id) < ARRAY_SIZE(array))      \
> > +             event_str = array[id];                  \
> > +     event_str;                                      \
> > +})
> > +
> >  static int link_parse_fd(int *argc, char ***argv)
> >  {
> >       int fd;
>
> Reviewed-by: Quentin Monnet <quentin@isovalent.com>



-- 
Regards
Yafang

  reply	other threads:[~2023-06-25 14:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 14:15 [PATCH v5 bpf-next 00/11] bpf: Support ->fill_link_info for kprobe_multi and perf_event links Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 01/11] bpf: Support ->fill_link_info for kprobe_multi Yafang Shao
2023-06-23 21:45   ` Andrii Nakryiko
2023-06-25 14:34     ` Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 02/11] bpftool: Dump the kernel symbol's module name Yafang Shao
2023-06-23 16:48   ` Quentin Monnet
2023-06-23 14:15 ` [PATCH v5 bpf-next 03/11] bpftool: Show kprobe_multi link info Yafang Shao
2023-06-23 16:48   ` Quentin Monnet
2023-06-25 14:29     ` Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 04/11] bpf: Protect probed address based on kptr_restrict setting Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 05/11] bpf: Clear the probe_addr for uprobe Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 06/11] bpf: Expose symbol's respective address Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 07/11] bpf: Add a common helper bpf_copy_to_user() Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 08/11] bpf: Add bpf_perf_link_fill_common() Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 09/11] bpf: Support ->fill_link_info for perf_event Yafang Shao
2023-06-23 21:55   ` Andrii Nakryiko
2023-06-25 14:35     ` Yafang Shao
2023-06-23 14:15 ` [PATCH v5 bpf-next 10/11] bpftool: Add perf event names Yafang Shao
2023-06-23 16:49   ` Quentin Monnet
2023-06-25 14:30     ` Yafang Shao [this message]
2023-06-23 14:15 ` [PATCH v5 bpf-next 11/11] bpftool: Show perf link info Yafang Shao
2023-06-23 16:49   ` Quentin Monnet
2023-06-25 14:31     ` Yafang Shao
2023-06-23 17:13   ` Alexei Starovoitov
2023-06-25 14:32     ` 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='CALOAHbB19cmkTC8aEXSiq-cncZCnv0jRoJeBiq6kiEtnn+=62Q@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).