mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changbin Du <changbin.du@huawei.com>
To: Adrian Hunter <adrian.hunter@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>,
	Changbin Du <changbin.du@huawei.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-perf-users@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>,
	Thomas Richter <tmricht@linux.ibm.com>, <changbin.du@gmail.com>
Subject: Re: [PATCH v7 0/5] perf: script: Intro capstone disasm engine to show instruction trace
Date: Sat, 17 Feb 2024 15:29:36 +0800	[thread overview]
Message-ID: <20240217072936.6siuj3pvi6hzx3u6@M910t> (raw)
In-Reply-To: <dcb11888-444a-40d4-9baf-4e2045156726@intel.com>

On Fri, Feb 16, 2024 at 01:20:31PM +0200, Adrian Hunter wrote:
> On 9/02/24 20:49, Namhyung Kim wrote:
> > Hello,
> > 
> > For some reason, I cannot see Changbin's email in my mailbox. :(
> > 
> > On Tue, Feb 6, 2024 at 3:50 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
> >>
> >> On 6/02/24 13:29, Changbin Du wrote:
> >>> This series introduces capstone disassembler engine to print instructions of
> >>> Intel PT trace, which was printed via the XED tool.
> >>>
> >>> The advantages compared to XED tool:
> >>>     * Support arm, arm64, x86-32, x86_64, s390 (more could be supported),
> >>>       xed only for x86_64.
> >>>     * More friendly to read. Immediate address operands are shown as symbol+offs.
> >>>
> >>> Display raw instructions:
> >>>     $ sudo perf record --event intel_pt//u -- ls
> >>>     $ sudo perf script --insn-trace
> >>>                 perf 17423 [000] 423271.557970005:      7f2d95f16217 __GI___ioctl+0x7 (/lib/x86_64-linux-gnu/libc-2.27.so) insn: 48 3d 01 f0 ff ff
> >>>                 perf 17423 [000] 423271.557970005:      7f2d95f1621d __GI___ioctl+0xd (/lib/x86_64-linux-gnu/libc-2.27.so) insn: 73 01
> >>>                 perf 17423 [000] 423271.557970338:      7f2d95f1621f __GI___ioctl+0xf (/lib/x86_64-linux-gnu/libc-2.27.so) insn: c3
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346d7 perf_evsel__enable_cpu+0x97 (/work/linux/tools/perf/perf) insn: 85 c0
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346d9 perf_evsel__enable_cpu+0x99 (/work/linux/tools/perf/perf) insn: 75 12
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346db perf_evsel__enable_cpu+0x9b (/work/linux/tools/perf/perf) insn: 49 8b 84 24 a8 00 00 00
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346e3 perf_evsel__enable_cpu+0xa3 (/work/linux/tools/perf/perf) insn: 48 8b 50 20
> >>>
> >>> Display mnemonic instructions:
> >>>     $ sudo perf script --insn-trace=disasm
> >>>                 perf 17423 [000] 423271.557970005:      7f2d95f16217 __GI___ioctl+0x7 (/lib/x86_64-linux-gnu/libc-2.27.so)            cmpq $-0xfff, %rax
> >>>                 perf 17423 [000] 423271.557970005:      7f2d95f1621d __GI___ioctl+0xd (/lib/x86_64-linux-gnu/libc-2.27.so)            jae __GI___ioctl+0x10
> >>>                 perf 17423 [000] 423271.557970338:      7f2d95f1621f __GI___ioctl+0xf (/lib/x86_64-linux-gnu/libc-2.27.so)            retq
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346d7 perf_evsel__enable_cpu+0x97 (/work/linux/tools/perf/perf)                testl %eax, %eax
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346d9 perf_evsel__enable_cpu+0x99 (/work/linux/tools/perf/perf)                jne perf_evsel__enable_cpu+0xad
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346db perf_evsel__enable_cpu+0x9b (/work/linux/tools/perf/perf)                movq 0xa8(%r12), %rax
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346e3 perf_evsel__enable_cpu+0xa3 (/work/linux/tools/perf/perf)                movq 0x20(%rax), %rdx
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346e7 perf_evsel__enable_cpu+0xa7 (/work/linux/tools/perf/perf)                cmpl %edx, %ebx
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346e9 perf_evsel__enable_cpu+0xa9 (/work/linux/tools/perf/perf)                jl perf_evsel__enable_cpu+0x60
> >>>                 perf 17423 [000] 423271.557970338:      5593ad3346eb perf_evsel__enable_cpu+0xab (/work/linux/tools/perf/perf)                xorl %eax, %eax
> >>>
> >>> v7:
> >>>   - remove redundant space for raw instruction.
> >>>   - rename sample__fprintf_insn() as sample__fprintf_insn_asm() and make it empty if libcapstone is not available.
> >>> v6:
> >>>   - make '-F +disasm' fatal if libcapstone is not supported. (Adrian Hunter)
> >>>   - display with perf version --build-options. (Adrian Hunter)
> >>>   - exclude libcapstone from make_minimal. (Adrian Hunter)
> >>> v5:
> >>>   - fixes and improments suggested by Adrian Hunter
> >>> v4:
> >>>   - rename 'insn_disam' to 'disasm' (Adrian Hunter)
> >>> v3:
> >>>   - fix s390 detection. (Thomas Richter)
> >>> v2:
> >>>   - add a new field 'insn_disam' instead of changing the default output.
> >>>   - preserve the old --xed option.
> >>>
> >>> Changbin Du (5):
> >>>   perf: build: introduce the libcapstone
> >>>   perf: util: use capstone disasm engine to show assembly instructions
> >>>   perf: script: add field 'disasm' to display mnemonic instructions
> >>>   perf: script: add raw|disasm arguments to --insn-trace option
> >>>   perf: script: prefer capstone to XED
> >>>
> >>>  tools/build/Makefile.feature               |   2 +
> >>>  tools/build/feature/Makefile               |   4 +
> >>>  tools/build/feature/test-all.c             |   4 +
> >>>  tools/build/feature/test-libcapstone.c     |  11 ++
> >>>  tools/perf/Documentation/perf-intel-pt.txt |  14 ++-
> >>>  tools/perf/Documentation/perf-script.txt   |  20 +--
> >>>  tools/perf/Makefile.config                 |  21 ++++
> >>>  tools/perf/Makefile.perf                   |   3 +
> >>>  tools/perf/builtin-script.c                |  45 +++++--
> >>>  tools/perf/builtin-version.c               |   1 +
> >>>  tools/perf/tests/make                      |   4 +-
> >>>  tools/perf/ui/browsers/res_sample.c        |   2 +-
> >>>  tools/perf/ui/browsers/scripts.c           |   2 +-
> >>>  tools/perf/util/Build                      |   1 +
> >>>  tools/perf/util/print_insn.c               | 135 +++++++++++++++++++++
> >>>  tools/perf/util/print_insn.h               |  16 +++
> >>>  16 files changed, 258 insertions(+), 27 deletions(-)
> >>>  create mode 100644 tools/build/feature/test-libcapstone.c
> >>>  create mode 100644 tools/perf/util/print_insn.c
> >>>  create mode 100644 tools/perf/util/print_insn.h
> >>>
> >>
> >> For whole patch set:
> >>
> >> Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
> > 
> > Anyway, I see a build failure on Fedora 40.
> > 
> > In file included from /usr/include/capstone/capstone.h:325,
> >                  from util/print_insn.c:29:
> > /usr/include/capstone/bpf.h:94:14: error: 'bpf_insn' defined as wrong
> > kind of tag
> >    94 | typedef enum bpf_insn {
> >       |              ^~~~~~~~
> 
> libcapstone header files seem to trample on other namespaces.
Yes, the tag 'bpf_insn' are both defined by capstone/bpf.h and uapi/linux/bpf.h.

. util/event.h
.. /work/linux/tools/include/uapi/linux/stddef.h
.. /work/linux/tools/perf/libperf/include/perf/event.h
... /work/linux/tools/include/uapi/linux/perf_event.h
.... /usr/include/linux/ioctl.h
..... /usr/include/asm/ioctl.h
...... /usr/include/asm-generic/ioctl.h
.... /usr/include/asm/byteorder.h
..... /usr/include/linux/byteorder/little_endian.h
...... /usr/include/linux/swab.h
....... /work/linux/tools/perf/util/include/asm/swab.h
... /usr/include/linux/limits.h
... /work/linux/tools/include/uapi/linux/bpf.h
.... /work/linux/tools/include/uapi/linux/bpf_common.h


> We might have to wrap the libcapstone API at some point, but
> for now I suggest avoiding including the conflicting headers
> in the same C file.  Below works for me:
> 
> diff --git a/tools/perf/util/print_insn.c b/tools/perf/util/print_insn.c
> index c10ccda529b13..459e0e93d7b1b 100644
> --- a/tools/perf/util/print_insn.c
> +++ b/tools/perf/util/print_insn.c
> @@ -7,7 +7,7 @@
>  #include <string.h>
>  #include <stdbool.h>
>  #include "debug.h"
> -#include "event.h"
> +#include "sample.h"
>  #include "symbol.h"
>  #include "machine.h"
>  #include "thread.h"
> diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> index 0df775b5c1105..df344262eaee0 100644
> --- a/tools/perf/util/thread.h
> +++ b/tools/perf/util/thread.h
> @@ -13,7 +13,6 @@
>  #include <strlist.h>
>  #include <intlist.h>
>  #include "rwsem.h"
> -#include "event.h"
>  #include "callchain.h"
>  #include <internal/rc_check.h>
>
This works for me, too. I'll include this fix and keep Adrian's Reviewed-by.

> 
> 
> 
> 
> 
> 
> 

-- 
Cheers,
Changbin Du

      reply	other threads:[~2024-02-17  7:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 11:29 Changbin Du
2024-02-06 11:29 ` [PATCH v7 1/5] perf: build: introduce the libcapstone Changbin Du
2024-02-06 11:29 ` [PATCH v7 2/5] perf: util: use capstone disasm engine to show assembly instructions Changbin Du
2024-02-06 11:29 ` [PATCH v7 3/5] perf: script: add field 'disasm' to display mnemonic instructions Changbin Du
2024-02-06 11:29 ` [PATCH v7 4/5] perf: script: add raw|disasm arguments to --insn-trace option Changbin Du
2024-02-06 11:29 ` [PATCH v7 5/5] perf: script: prefer capstone to XED Changbin Du
2024-02-06 11:49 ` [PATCH v7 0/5] perf: script: Intro capstone disasm engine to show instruction trace Adrian Hunter
2024-02-09 18:49   ` Namhyung Kim
2024-02-16 11:20     ` Adrian Hunter
2024-02-17  7:29       ` Changbin Du [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=20240217072936.6siuj3pvi6hzx3u6@M910t \
    --to=changbin.du@huawei.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=changbin.du@gmail.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tmricht@linux.ibm.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

all inboxes | Powered by JetHome®