1. 31 Jul, 2024 31 commits
    • James Clark's avatar
      perf scripts python cs-etm: Restore first sample log in verbose mode · ae8e4f40
      James Clark authored
      The linked commit moved the early return on the first sample to before
      the verbose log, so move the log earlier too. Now the first sample is
      also logged and not skipped.
      
      Fixes: 2d98dbb4 ("perf scripts python arm-cs-trace-disasm.py: Do not ignore disam first sample")
      Reviewed-by: default avatarLeo Yan <leo.yan@arm.com>
      Signed-off-by: default avatarJames Clark <james.clark@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Benjamin Gray <bgray@linux.ibm.com>
      Cc: coresight@lists.linaro.org
      Cc: gankulkarni@os.amperecomputing.com
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ruidong Tian <tianruidong@linux.alibaba.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Link: https://lore.kernel.org/r/20240723132858.12747-1-james.clark@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ae8e4f40
    • James Clark's avatar
      perf cs-etm: Output 0 instead of 0xdeadbeef when exception packets are flushed · 41947446
      James Clark authored
      Normally exception packets don't directly output a branch sample, but
      if they're the last record in a buffer then they will. Because they
      don't have addresses set we'll see the placeholder value
      CS_ETM_INVAL_ADDR (0xdeadbeef) in the output.
      
      Since commit 6035b680 ("perf cs-etm: Support dummy address value for
      CS_ETM_TRACE_ON packet") we've used 0 as an externally visible "not set"
      address value. For consistency reasons and to not make exceptions look
      like an error, change them to use 0 too.
      
      This is particularly visible when doing userspace only tracing because
      trace is disabled when jumping to the kernel, causing the flush and then
      forcing the last exception packet to be emitted as a branch. With kernel
      trace included, there is no flush so exception packets don't generate
      samples until the next range packet and they'll pick up the correct
      address.
      
      Before:
      
        $ perf record -e cs_etm//u -- stress -i 1 -t 1
        $ perf script -F comm,ip,addr,flags
      
        stress   syscall                    ffffb7eedbc0 => deadbeefdeadbeef
        stress   syscall                    ffffb7f14a14 => deadbeefdeadbeef
        stress   syscall                    ffffb7eedbc0 => deadbeefdeadbeef
      
      After:
      
        stress   syscall                    ffffb7eedbc0 =>                0
        stress   syscall                    ffffb7f14a14 =>                0
        stress   syscall                    ffffb7eedbc0 =>                0
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Leo Yan <leo.yan@arm.com>
      Cc: Leo Yan <leo.yan@linux.dev>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: coresight@lists.linaro.org
      Cc: gankulkarni@os.amperecomputing.com
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20240722152756.59453-2-james.clark@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      41947446
    • Chen Ni's avatar
      perf inject: Convert comma to semicolon · 496cae1b
      Chen Ni authored
      Replace a comma between expression statements by a semicolon.
      Reviewed-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarChen Ni <nichen@iscas.ac.cn>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240716075347.969041-1-nichen@iscas.ac.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      496cae1b
    • Chen Ni's avatar
      perf daemon: Convert comma to semicolon · e60fc19e
      Chen Ni authored
      Replace a comma between expression statements by a semicolon.
      Reviewed-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarChen Ni <nichen@iscas.ac.cn>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240716074340.968909-1-nichen@iscas.ac.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e60fc19e
    • Chen Ni's avatar
      perf annotate: Convert comma to semicolon · 050f2a03
      Chen Ni authored
      Replace a comma between expression statements by a semicolon.
      Reviewed-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarChen Ni <nichen@iscas.ac.cn>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240716073405.968801-1-nichen@iscas.ac.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      050f2a03
    • Kajol Jain's avatar
      perf vendor events power10: Update JSON/events · 42d37fc0
      Kajol Jain authored
      Update JSON/events for power10 platform with additional events.
      
      Also move PM_VECTOR_LD_CMPL event from others.json to frontend.json
      file.
      Reviewed-by: default avatarIan Rogers <irogers@google.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Tested-by: default avatarDisha Goel <disgoel@linux.ibm.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: hbathini@linux.ibm.com
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20240723052154.96202-1-kjain@linux.ibm.com
      [ Remove alternative to ' char that made the build break in some distros with a unicode parsing python error ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      42d37fc0
    • Athira Rajeev's avatar
      perf annotate: Set instruction name to be used with insn-stat when using raw instruction · 2c9db747
      Athira Rajeev authored
      Since the "ins.name" is not set while using raw instruction,
      'perf annotate' with insn-stat gives wrong data:
      
      Result from "./perf annotate --data-type --insn-stat":
      
        Annotate Instruction stats
        total 615, ok 419 (68.1%), bad 196 (31.9%)
      
          Name      :  Good   Bad
          -----------------------------------------------------------
                    :   419   196
      
      This patch sets "dl->ins.name" in arch specific function
      "check_ppc_insn" while initialising "struct disasm_line".
      
      Also update "ins_find" function to pass "struct disasm_line" as a
      parameter so as to set its name field in arch specific call.
      
      With the patch changes:
      
        Annotate Instruction stats
        total 609, ok 446 (73.2%), bad 163 (26.8%)
      
        Name/opcode         :  Good   Bad
        -----------------------------------------------------------
        58                  :   323    80
        32                  :    49    43
        34                  :    33    11
        OP_31_XOP_LDX       :     8    20
        40                  :    23     0
        OP_31_XOP_LWARX     :     5     1
        OP_31_XOP_LWZX      :     2     3
        OP_31_XOP_LDARX     :     3     0
        33                  :     0     2
        OP_31_XOP_LBZX      :     0     1
        OP_31_XOP_LWAX      :     0     1
        OP_31_XOP_LHZX      :     0     1
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-16-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2c9db747
    • Athira Rajeev's avatar
      perf annotate: Add support to use libcapstone in powerpc · c5d60de1
      Athira Rajeev authored
      Now perf uses the capstone library to disassemble the instructions in
      x86. capstone is used (if available) for perf annotate to speed up.
      
      Currently it only supports x86 architecture.
      
      This patch includes changes to enable this in powerpc.
      
      For now, only for data type sort keys, this method is used and only
      binary code (raw instruction) is read. This is because powerpc approach
      to understand instructions and reg fields uses raw instruction.
      
      The "cs_disasm" is currently not enabled. While attempting to do
      cs_disasm, observation is that some of the instructions were not
      identified (ex: extswsli, maddld) and it had to fallback to use objdump.
      
      Hence enabling "cs_disasm" is added in comment section as a TODO for
      powerpc.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-15-atrajeev@linux.vnet.ibm.com
      [ Use dso__nsinfo(dso) as required to match EXTRA_CFLAGS=-DREFCNT_CHECKING=1 build expectations ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c5d60de1
    • Athira Rajeev's avatar
      perf annotate: Use capstone_init and remove open_capstone_handle from disasm.c · f1e9347c
      Athira Rajeev authored
      capstone_init is made availbale for all archs to use and updated to
      enable support for CS_ARCH_PPC as well. Patch removes
      open_capstone_handle and uses capstone_init in all the places.
      
      Committer notes:
      
      Avoid including capstone/capstone.h from print_insn.h to not break the
      build in builtin-script.c due to the namespace clash with libbpf:
      
        /usr/include/capstone/bpf.h:94:14: error: 'bpf_insn' defined as wrong kind of tag
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-14-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f1e9347c
    • Athira Rajeev's avatar
      perf annotate: Make capstone_init non-static so that it can be used during symbol disassemble · 1fe86bc2
      Athira Rajeev authored
      symbol__disassemble_capstone in util/disasm.c calls function
      open_capstone_handle to open/init the capstone.
      
      We already have a capstone_init function in "util/print_insn.c". But
      capstone_init is defined as a static function in util/print_insn.c.
      
      Change this and also add the function in print_insn.h
      
      The open_capstone_handle checks the disassembler_style option from
      annotation_options to decide whether to set CS_OPT_SYNTAX_ATT.
      
      Add that logic in capstone_init also and by default set it to true.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-13-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1fe86bc2
    • Athira Rajeev's avatar
      perf annotate: Update instruction tracking for powerpc · 88444952
      Athira Rajeev authored
      Add instruction tracking function "update_insn_state_powerpc" for
      powerpc. Example sequence in powerpc:
      
        ld      r10,264(r3)
        mr      r31,r3
        <<after some sequence>
        ld      r9,312(r31)
      
      Consider ithe sample is pointing to: "ld r9,312(r31)".
      
      Here the memory reference is hit at "312(r31)" where 312 is the offset
      and r31 is the source register.
      
      Previous instruction sequence shows that register state of r3 is moved
      to r31.
      
      So to identify the data type for r31 access, the previous instruction
      ("mr") needs to be tracked and the state type entry has to be updated.
      
      Current instruction tracking support in perf tools infrastructure is
      specific to x86. Patch adds this support for powerpc as well.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-12-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      88444952
    • Athira Rajeev's avatar
      perf annotate: Add more instructions for instruction tracking · 539bfea3
      Athira Rajeev authored
      Add few more instructions and use opcode as search key
      to find if it is supported by the architecture.
      
      The added ones are: addi, addic, addic., addis, subfic and mulli
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-11-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      539bfea3
    • Athira Rajeev's avatar
      perf annotate: Add some of the arithmetic instructions to support instruction tracking in powerpc · cd0b6f67
      Athira Rajeev authored
      Data-type profiling has the concept of instruction tracking.
      
      Example sequence in powerpc:
      
      	ld      r10,264(r3)
      	mr      r31,r3
      	<<after some sequence>
      	ld      r9,312(r31)
      
      or differently
      
      	lwz	r10,264(r3)
      	add	r31, r3, RB
      	lwz	r9, 0(r31)
      
      If a sample is hit at "lwz r9, 0(r31)", data type of r31 depends
      on previous instruction sequence here. So to track the previous
      instructions, patch adds changes to identify some of the arithmetic
      instructions which are having opcode as 31.
      
      Since memory instructions also has cases with opcode 31, use the bits
      22:30 to filter the arithmetic instructions here.
      
      Also there are instructions with just two operands like "addme", "addze".
      
      This patch adds new instructions ops "arithmetic_ops" to handle this
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-10-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cd0b6f67
    • Athira Rajeev's avatar
      perf annotate: Add support to identify memory instructions of opcode 31 in powerpc · ace7d681
      Athira Rajeev authored
      There are memory instructions in powerpc with opcode as 31.
      Example: "ldx RT,RA,RB" , Its X form is as below:
      
        ______________________________________
        | 31 |  RT  |  RA |  RB |   21     |/|
        --------------------------------------
        0    6     11    16    21         30 31
      
      The opcode for "ldx" is 31. There are other instructions also with
      opcode 31 which are memory insn like ldux, stbx, lwzx, lhaux
      But all instructions with opcode 31 are not memory. Example is add
      instruction: "add RT,RA,RB"
      
      The value in bit 21-30 [ 21 for ldx ] is different for these
      instructions. Patch uses this value to assign instruction ops for these
      cases. The naming convention and value to identify these are picked from
      defines in "arch/powerpc/include/asm/ppc-opcode.h"
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-9-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ace7d681
    • Athira Rajeev's avatar
      perf annotate: Add parse function for memory instructions in powerpc · 1acdad68
      Athira Rajeev authored
      Use the raw instruction code and macros to identify memory instructions,
      extract register fields and also offset.
      
      The implementation addresses the D-form, X-form, DS-form instructions.
      Two main functions are added.
      
      New parse function "load_store__parse" as instruction ops parser for
      memory instructions.
      
      Unlike other parsers (like mov__parse), this one fills in the
      "multi_regs" field for source/target and new added "mem_ref" field. No
      other fields are set because, here there is no need to parse the
      disassembled code and arch specific macros will take care of extracting
      offset and regs which is easier and will be precise.
      
      In powerpc, all instructions with a primary opcode from 32 to 63
      are memory instructions. Update "ins__find" function to have "raw_insn"
      also as a parameter.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-8-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1acdad68
    • Athira Rajeev's avatar
      perf annotate: Update parameters for reg extract functions to use raw instruction on powerpc · 1b4406d2
      Athira Rajeev authored
      Use the raw instruction code and macros to identify memory instructions,
      extract register fields and also offset.
      
      The implementation addresses the D-form, X-form, DS-form instructions.
      
      Adds "mem_ref" field to check whether source/target has memory
      reference.
      
      Add function "get_powerpc_regs" which will set these fields: reg1, reg2,
      offset depending of where it is source or target ops.
      
      Update "parse" callback for "struct ins_ops" to also pass "struct
      disasm_line" as argument. This is needed in parse functions where opcode
      is used to determine whether to set multi_regs and other fields
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-7-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1b4406d2
    • Athira Rajeev's avatar
      perf annotate: Add support to capture and parse raw instruction in powerpc... · 0b971e6b
      Athira Rajeev authored
      perf annotate: Add support to capture and parse raw instruction in powerpc using dso__data_read_offset utility
      
      Add support to capture and parse raw instruction in powerpc.
      Currently, the perf tool infrastructure uses two ways to disassemble
      and understand the instruction. One is objdump and other option is
      via libcapstone.
      
      Currently, the perf tool infrastructure uses "--no-show-raw-insn" option
      with "objdump" while disassemble. Example from powerpc with this option
      for an instruction address is:
      
      Snippet from:
      
        objdump  --start-address=<address> --stop-address=<address>  -d --no-show-raw-insn -C <vmlinux>
      
        c0000000010224b4:	lwz     r10,0(r9)
      
      This line "lwz r10,0(r9)" is parsed to extract instruction name,
      registers names and offset. Also to find whether there is a memory
      reference in the operands, "memory_ref_char" field of objdump is used.
      For x86, "(" is used as memory_ref_char to tackle instructions of the
      form "mov  (%rax), %rcx".
      
      In case of powerpc, not all instructions using "(" are the only memory
      instructions. Example, above instruction can also be of extended form (X
      form) "lwzx r10,0,r19". Inorder to easy identify the instruction category
      and extract the source/target registers, patch adds support to use raw
      instruction for powerpc. Approach used is to read the raw instruction
      directly from the DSO file using "dso__data_read_offset" utility which
      is already implemented in perf infrastructure in "util/dso.c".
      
      Example:
      
      38 01 81 e8     ld      r4,312(r1)
      
      Here "38 01 81 e8" is the raw instruction representation. In powerpc,
      this translates to instruction form: "ld RT,DS(RA)" and binary code
      as:
      
         | 58 |  RT  |  RA |      DS       | |
         -------------------------------------
         0    6     11    16              30 31
      
      Function "symbol__disassemble_dso" is updated to read raw instruction
      directly from DSO using dso__data_read_offset utility. In case of
      above example, this captures:
      line:    38 01 81 e8
      
      The above works well when 'perf report' is invoked with only sort keys
      for data type ie type and typeoff.
      
      Because there is no instruction level annotation needed if only data
      type information is requested for.
      
      For annotating sample, along with type and typeoff sort key, "sym" sort
      key is also needed. And by default invoking just "perf report" uses sort
      key "sym" that displays the symbol information.
      
      With approach changes in powerpc which first reads DSO for raw
      instruction, "perf annotate" and "perf report" + a key breaks since
      it doesn't do the instruction level disassembly.
      
      Snippet of result from 'perf report':
      
        Samples: 1K of event 'mem-loads', 4000 Hz, Event count (approx.): 937238
        do_work  /usr/bin/pmlogger [Percent: local period]
        Percent│        ea230010
               │        3a550010
               │        3a600000
      
               │        38f60001
               │        39490008
               │        42400438
         51.44 │        81290008
               │        7d485378
      
      Here, raw instruction is displayed in the output instead of human
      readable annotated form.
      
      One way to get the appropriate data is to specify "--objdump path", by
      which code annotation will be done. But the default behaviour will be
      changed. To fix this breakage, check if "sym" sort key is set. If so
      fallback and use the libcapstone/objdump way of disassmbling the sample.
      
      With the changes and "perf report"
      
      Samples: 1K of event 'mem-loads', 4000 Hz, Event count (approx.): 937238
      do_work  /usr/bin/pmlogger [Percent: local period]
      Percent│        ld        r17,16(r3)
             │        addi      r18,r21,16
             │        li        r19,0
      
             │ 8b0:   rldicl    r10,r10,63,33
             │        addi      r10,r10,1
             │        mtctr     r10
             │      ↓ b         8e4
             │ 8c0:   addi      r7,r22,1
             │        addi      r10,r9,8
             │      ↓ bdz       d00
       51.44 │        lwz       r9,8(r9)
             │        mr        r8,r10
             │        cmpw      r20,r9
      
      Committer notes:
      
      Just add the extern for 'sort_order' in disasm.c so that we don't end up
      breaking the build due to this type colision with capstone and libbpf:
      
        In file included from /usr/include/capstone/capstone.h:325,
                         from /git/perf-6.10.0/tools/perf/util/print_insn.h:23,
                         from builtin-script.c:38:
        /usr/include/capstone/bpf.h:94:14: error: 'bpf_insn' defined as wrong kind of tag
           94 | typedef enum bpf_insn {
      
      I reported this to the bpf mailing list, see one of the links below.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-6-atrajeev@linux.vnet.ibm.com
      Link: https://lore.kernel.org/bpf/ZqOltPk9VQGgJZAA@x1/T/#uSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0b971e6b
    • Athira Rajeev's avatar
      perf annotate: Add disasm_line__parse() to parse raw instruction for powerpc · 06dd4c5a
      Athira Rajeev authored
      Currently, the perf tool infrastructure uses the disasm_line__parse
      function to parse disassembled line.
      
      Example snippet from objdump:
      
        objdump  --start-address=<address> --stop-address=<address>  -d --no-show-raw-insn -C <vmlinux>
      
        c0000000010224b4:	lwz     r10,0(r9)
      
      This line "lwz r10,0(r9)" is parsed to extract instruction name,
      registers names and offset.
      
      In powerpc, the approach for data type profiling uses raw instruction
      instead of result from objdump to identify the instruction category and
      extract the source/target registers.
      
      Example: 38 01 81 e8     ld      r4,312(r1)
      
      Here "38 01 81 e8" is the raw instruction representation. Add function
      "disasm_line__parse_powerpc" to handle parsing of raw instruction.
      Also update "struct disasm_line" to save the binary code/
      With the change, function captures:
      
      line -> "38 01 81 e8     ld      r4,312(r1)"
      raw instruction "38 01 81 e8"
      
      Raw instruction is used later to extract the reg/offset fields. Macros
      are added to extract opcode and register fields. "struct disasm_line"
      is updated to carry union of "bytes" and "raw_insn" of 32 bit to carry raw
      code (raw).
      
      Function "disasm_line__parse_powerpc fills the raw instruction hex value
      and can use macros to get opcode. There is no changes in existing code
      paths, which parses the disassembled code.  The size of raw instruction
      depends on architecture.
      
      In case of powerpc, the parsing the disasm line needs to handle cases
      for reading binary code directly from DSO as well as parsing the objdump
      result. Hence adding the logic into separate function instead of
      updating "disasm_line__parse".  The architecture using the instruction
      name and present approach is not altered. Since this approach targets
      powerpc, the macro implementation is added for powerpc as of now.
      
      Since the disasm_line__parse is used in other cases (perf annotate) and
      not only data tye profiling, the powerpc callback includes changes to
      work with binary code as well as mnemonic representation.
      
      Also in case if the DSO read fails and libcapstone is not supported, the
      approach fallback to use objdump as option. Hence as option, patch has
      changes to ensure objdump option also works well.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-5-atrajeev@linux.vnet.ibm.com
      [ Add check for strndup() result ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      06dd4c5a
    • Athira Rajeev's avatar
      perf annotate: Update TYPE_STATE_MAX_REGS to include max of regs in powerpc · b1d8d968
      Athira Rajeev authored
      TYPE_STATE_MAX_REGS is arch-dependent. Currently this is defined to be
      16.
      
      While checking if reg is valid using has_reg_type, max value is checked
      using TYPE_STATE_MAX_REGS value.
      
      Define this conditionally for powerpc.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-4-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b1d8d968
    • Athira Rajeev's avatar
      perf annotate: Add "update_insn_state" callback function to handle arch... · 782959ac
      Athira Rajeev authored
      perf annotate: Add "update_insn_state" callback function to handle arch specific instruction tracking
      
      Add "update_insn_state" callback to "struct arch" to handle instruction
      tracking. Currently updating instruction state is handled by static
      function "update_insn_state_x86" which is defined in "annotate-data.c".
      
      Make this as a callback for specific arch and move to archs specific
      file "arch/x86/annotate/instructions.c" . This will help to add helper
      function for other platforms in file:
      "arch/<platform>/annotate/instructions.c" and make changes/updates
      easier.
      
      Define callback "update_insn_state" as part of "struct arch", also make
      some of the debug functions non-static so that it can be referenced from
      other places.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-3-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      782959ac
    • Athira Rajeev's avatar
      perf annotate: Move the data structures related to register type to header file · 1d303dee
      Athira Rajeev authored
      Data type profiling uses instruction tracking by checking each
      instruction and updating the register type state in some data
      structures.
      
      This is useful to find the data type in cases when the register state
      gets transferred from one reg to another.
      
      Example, in x86, "mov" instruction and in powerpc, "mr" instruction.
      
      Currently these structures are defined in annotate-data.c and
      instruction tracking is implemented only for x86.
      
      Move these data structures to "annotate-data.h" header file so that
      other arch implementations can use it in arch specific files as well.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Akanksha J N <akanksha@linux.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Hari Bathini <hbathini@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Segher Boessenkool <segher@kernel.crashing.org>
      Link: https://lore.kernel.org/lkml/20240718084358.72242-2-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1d303dee
    • Ian Rogers's avatar
      perf test: Avoid python leak sanitizer test failures · e293f4b1
      Ian Rogers authored
      Leak sanitizer will report memory leaks from python and the leak
      sanitizer output causes tests to fail. For example:
      
        ```
        $ perf test 98 -v
         98: perf script tests:
        --- start ---
        test child forked, pid 1272962
        DB test
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.046 MB /tmp/perf-test-script.x0EktdCel8/perf.data (8 samples) ]
        call_path_table((1, 0, 0, 0)
        call_path_table((2, 1, 0, 140339508617447)
        call_path_table((3, 2, 2, 0)
        call_path_table((4, 3, 3, 0)
        call_path_table((5, 4, 4, 0)
        call_path_table((6, 5, 5, 0)
        call_path_table((7, 6, 6, 0)
        call_path_table((8, 7, 7, 0)
        call_path_table((9, 8, 8, 0)
        call_path_table((10, 9, 9, 0)
        call_path_table((11, 10, 10, 0)
        call_path_table((12, 11, 11, 0)
        call_path_table((13, 12, 1, 0)
        sample_table((1, 1, 1, 1, 1, 1, 1, 8, -2058824120, 588306954119000, -1, 0, 0, 0, 0, 1, 0, 0, 128933429281, 0, 0, 13, 0, 0, 0, -1, -1))
        sample_table((2, 1, 1, 1, 1, 1, 1, 8, -2058824120, 588306954137053, -1, 0, 0, 0, 0, 1, 0, 0, 128933429281, 0, 0, 13, 0, 0, 0, -1, -1))
        sample_table((3, 1, 1, 1, 1, 1, 1, 8, -2058824120, 588306954140089, -1, 0, 0, 0, 0, 9, 0, 0, 128933429281, 0, 0, 13, 0, 0, 0, -1, -1))
        sample_table((4, 1, 1, 1, 1, 1, 1, 8, -2058824120, 588306954142376, -1, 0, 0, 0, 0, 155, 0, 0, 128933429281, 0, 0, 13, 0, 0, 0, -1, -1))
        sample_table((5, 1, 1, 1, 1, 1, 1, 8, -2058824120, 588306954144045, -1, 0, 0, 0, 0, 2493, 0, 0, 128933429281, 0, 0, 13, 0, 0, 0, -1, -1))
        sample_table((6, 1, 1, 1, 1, 1, 12, 77, -2046828595, 588306954145722, -1, 0, 0, 0, 0, 47555, 0, 0, 128933429281, 0, 0, 13, 0, 0, 0, -1, -1))
        call_path_table((14, 9, 14, 0)
        call_path_table((15, 14, 15, 0)
        call_path_table((16, 15, 0, -1040969624)
        call_path_table((17, 16, 16, 0)
        call_path_table((18, 17, 17, 0)
        call_path_table((19, 18, 18, 0)
        call_path_table((20, 19, 19, 0)
        call_path_table((21, 20, 13, 0)
        sample_table((7, 1, 1, 1, 2, 1, 13, 46, -2053700898, 588306954157436, -1, 0, 0, 0, 0, 964078, 0, 0, 128933429281, 0, 0, 21, 0, 0, 0, -1, -1))
        call_path_table((22, 1, 21, 0)
        call_path_table((23, 22, 22, 0)
        call_path_table((24, 23, 23, 0)
        call_path_table((25, 24, 24, 0)
        call_path_table((26, 25, 25, 0)
        call_path_table((27, 26, 26, 0)
        call_path_table((28, 27, 27, 0)
        call_path_table((29, 28, 28, 0)
        call_path_table((30, 29, 29, 0)
        call_path_table((31, 30, 30, 0)
        call_path_table((32, 31, 31, 0)
        call_path_table((33, 32, 32, 0)
        call_path_table((34, 33, 33, 0)
        call_path_table((35, 34, 20, 0)
        sample_table((8, 1, 1, 1, 2, 1, 20, 49, -2046878127, 588306954378624, -1, 0, 0, 0, 0, 2534317, 0, 0, 128933429281, 0, 0, 35, 0, 0, 0, -1, -1))
      
        =================================================================
        ==1272975==ERROR: LeakSanitizer: detected memory leaks
      
        Direct leak of 13628 byte(s) in 6 object(s) allocated from:
            #0 0x56354f60c092 in malloc (/tmp/perf/perf+0x29c092)
            #1 0x7ff25c7d02e7 in _PyObject_Malloc /build/python3.11/../Objects/obmalloc.c:2003:11
            #2 0x7ff25c7d02e7 in _PyObject_Malloc /build/python3.11/../Objects/obmalloc.c:1996:1
      
        SUMMARY: AddressSanitizer: 13628 byte(s) leaked in 6 allocation(s).
        --- Cleaning up ---
        ---- end(-1) ----
         98: perf script tests                                               : FAILED!
        ```
      
      Disable leak sanitizer when running specific perf+python tests to
      avoid this. This causes the tests to pass when run with leak
      sanitizer.
      Reviewed-by: default avatarAditya Gupta <adityag@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e293f4b1
    • Arnaldo Carvalho de Melo's avatar
      perf trace: Remove arg_fmt->is_enum, we can get that from the BTF type · c3d74713
      Arnaldo Carvalho de Melo authored
      This is to pave the way for other BTF types, i.e. we try to find BTF
      type then use things like btf_is_enum(btf_type) that we cached to find
      the right strtoul and scnprintf routines.
      
      For now only enum is supported, all the other types simple return zero
      for scnprintf which makes it have the same behaviour as when BTF isn't
      available, i.e. fallback to no pretty printing. Ditto for strtoul.
      
        root@x1:~# perf test -v enum
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~# perf test -v enum
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~# perf test -v enum
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~# perf test -v enum
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~# perf test -v enum
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~#
      Signed-off-by: default avatarHoward Chu <howardchu95@gmail.com>
      Tested-by: default avatarHoward Chu <howardchu95@gmail.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Howard Chu <howardchu95@gmail.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/r/20240624181345.124764-9-howardchu95@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c3d74713
    • Arnaldo Carvalho de Melo's avatar
      perf trace: Introduce trace__btf_scnprintf() · 62284329
      Arnaldo Carvalho de Melo authored
      To have a central place that will look at the BTF type and call the
      right scnprintf routine or return zero, meaning BTF pretty printing
      isn't available or not implemented for a specific type.
      Signed-off-by: default avatarHoward Chu <howardchu95@gmail.com>
      Tested-by: default avatarHoward Chu <howardchu95@gmail.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/r/20240624181345.124764-8-howardchu95@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      62284329
    • Howard Chu's avatar
      perf test trace_btf_enum: Add regression test for the BTF augmentation of enums in 'perf trace' · d66763fe
      Howard Chu authored
      Trace landlock_add_rule syscall to see if the output is desirable.
      
      Trace the non-syscall tracepoint 'timer:hrtimer_init' and
      'timer:hrtimer_start', see if the 'mode' argument is augmented,
      the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
      in its name.
      
      Committer testing:
      
        root@x1:~# perf test enum
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~# perf test -v enum
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~# perf trace -e landlock_add_rule perf test -v enum
             0.000 ( 0.010 ms): perf/749827 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffd324171d4, flags: 45) = -1 EINVAL (Invalid argument)
             0.012 ( 0.002 ms): perf/749827 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffd324171e0, flags: 45) = -1 EINVAL (Invalid argument)
           457.821 ( 0.007 ms): perf/749830 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffd4acd31e4, flags: 45) = -1 EINVAL (Invalid argument)
           457.832 ( 0.003 ms): perf/749830 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffd4acd31f0, flags: 45) = -1 EINVAL (Invalid argument)
        124: perf trace enum augmentation tests                              : Ok
        root@x1:~#
      Suggested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Signed-off-by: default avatarHoward Chu <howardchu95@gmail.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/lkml/20240619082042.4173621-6-howardchu95@gmail.com
      Link: https://lore.kernel.org/r/20240624181345.124764-7-howardchu95@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d66763fe
    • Howard Chu's avatar
      perf test: Add landlock workload · 3656e566
      Howard Chu authored
      We'll use it to add a regression test for the BTF augmentation of enum
      arguments for tracepoints in 'perf trace':
      
        root@x1:~# perf trace -e landlock_add_rule perf test -w landlock
             0.000 ( 0.009 ms): perf/747160 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffd8e258594, flags: 45) = -1 EINVAL (Invalid argument)
             0.011 ( 0.002 ms): perf/747160 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffd8e2585a0, flags: 45) = -1 EINVAL (Invalid argument)
        root@x1:~#
      
      Committer notes:
      
      It was agreed on the discussion (see Link below) to shorten then name of
      the workload from 'landlock_add_rule' to 'landlock', and I moved it to a
      separate patch.
      
      Also, to address a build failure from Namhyung, I stopped loading
      linux/landlock.h and instead added the used defines, enums and types to
      make this build in older systems. All we want is to emit the syscall and
      intercept it.
      Suggested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Signed-off-by: default avatarHoward Chu <howardchu95@gmail.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/lkml/CAH0uvohaypdTV6Z7O5QSK+va_qnhZ6BP6oSJ89s1c1E0CjgxDA@mail.gmail.com
      Link: https://lore.kernel.org/r/20240624181345.124764-1-howardchu95@gmail.com
      Link: https://lore.kernel.org/r/20240624181345.124764-6-howardchu95@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3656e566
    • Howard Chu's avatar
      perf trace: Filter enum arguments with enum names · 95586588
      Howard Chu authored
      Before:
      
      perf $ ./perf trace -e timer:hrtimer_start --filter='mode!=HRTIMER_MODE_ABS_PINNED_HARD' --max-events=1
      No resolver (strtoul) for "mode" in "timer:hrtimer_start", can't set filter "(mode!=HRTIMER_MODE_ABS_PINNED_HARD) && (common_pid != 281988)"
      
      After:
      
      perf $ ./perf trace -e timer:hrtimer_start --filter='mode!=HRTIMER_MODE_ABS_PINNED_HARD' --max-events=1
           0.000 :0/0 timer:hrtimer_start(hrtimer: 0xffff9498a6ca5f18, function: 0xffffffffa77a5be0, expires: 12351248764875, softexpires: 12351248764875, mode: HRTIMER_MODE_ABS)
      
      && and ||:
      
      perf $ ./perf trace -e timer:hrtimer_start --filter='mode != HRTIMER_MODE_ABS_PINNED_HARD && mode != HRTIMER_MODE_ABS' --max-events=1
           0.000 Hyprland/534 timer:hrtimer_start(hrtimer: 0xffff9497801a84d0, function: 0xffffffffc04cdbe0, expires: 12639434638458, softexpires: 12639433638458, mode: HRTIMER_MODE_REL)
      
      perf $ ./perf trace -e timer:hrtimer_start --filter='mode == HRTIMER_MODE_REL || mode == HRTIMER_MODE_PINNED' --max-events=1
           0.000 ldlck-test/60639 timer:hrtimer_start(hrtimer: 0xffffb16404ee7bf8, function: 0xffffffffa7790420, expires: 12772614418016, softexpires: 12772614368016, mode: HRTIMER_MODE_REL)
      
      Switching it up, using both enum name and integer value(--filter='mode == HRTIMER_MODE_ABS_PINNED_HARD || mode == 0'):
      
      perf $ ./perf trace -e timer:hrtimer_start --filter='mode == HRTIMER_MODE_ABS_PINNED_HARD || mode == 0' --max-events=3
           0.000 :0/0 timer:hrtimer_start(hrtimer: 0xffff9498a6ca5f18, function: 0xffffffffa77a5be0, expires: 12601748739825, softexpires: 12601748739825, mode: HRTIMER_MODE_ABS_PINNED_HARD)
           0.036 :0/0 timer:hrtimer_start(hrtimer: 0xffff9498a6ca5f18, function: 0xffffffffa77a5be0, expires: 12518758748124, softexpires: 12518758748124, mode: HRTIMER_MODE_ABS_PINNED_HARD)
           0.172 tmux: server/41881 timer:hrtimer_start(hrtimer: 0xffffb164081e7838, function: 0xffffffffa7790420, expires: 12518768255836, softexpires: 12518768205836, mode: HRTIMER_MODE_ABS)
      
      P.S.
      perf $ pahole hrtimer_mode
      enum hrtimer_mode {
              HRTIMER_MODE_ABS             = 0,
              HRTIMER_MODE_REL             = 1,
              HRTIMER_MODE_PINNED          = 2,
              HRTIMER_MODE_SOFT            = 4,
              HRTIMER_MODE_HARD            = 8,
              HRTIMER_MODE_ABS_PINNED      = 2,
              HRTIMER_MODE_REL_PINNED      = 3,
              HRTIMER_MODE_ABS_SOFT        = 4,
              HRTIMER_MODE_REL_SOFT        = 5,
              HRTIMER_MODE_ABS_PINNED_SOFT = 6,
              HRTIMER_MODE_REL_PINNED_SOFT = 7,
              HRTIMER_MODE_ABS_HARD        = 8,
              HRTIMER_MODE_REL_HARD        = 9,
              HRTIMER_MODE_ABS_PINNED_HARD = 10,
              HRTIMER_MODE_REL_PINNED_HARD = 11,
      };
      
      Committer testing:
      
        root@x1:~# perf trace -e timer:hrtimer_start --filter='mode != HRTIMER_MODE_ABS' --max-events=2
             0.000 :0/0 timer:hrtimer_start(hrtimer: 0xffff8d4eff2a5050, function: 0xffffffff9e22ddd0, expires: 241502326000000, softexpires: 241502326000000, mode: HRTIMER_MODE_ABS_PINNED_HARD)
        18446744073709.488 :0/0 timer:hrtimer_start(hrtimer: 0xffff8d4eff425050, function: 0xffffffff9e22ddd0, expires: 241501814000000, softexpires: 241501814000000, mode: HRTIMER_MODE_ABS_PINNED_HARD)
        root@x1:~# perf trace -e timer:hrtimer_start --filter='mode != HRTIMER_MODE_ABS && mode != HRTIMER_MODE_ABS_PINNED_HARD' --max-events=2
             0.000 podman/510644 timer:hrtimer_start(hrtimer: 0xffffa2024f5f7dd0, function: 0xffffffff9e2170c0, expires: 241530497418194, softexpires: 241530497368194, mode: HRTIMER_MODE_REL)
            40.251 gnome-shell/2484 timer:hrtimer_start(hrtimer: 0xffff8d48bda17650, function: 0xffffffffc0661550, expires: 241550528619247, softexpires: 241550527619247, mode: HRTIMER_MODE_REL)
        root@x1:~# perf trace -v -e timer:hrtimer_start --filter='mode != HRTIMER_MODE_ABS && mode != HRTIMER_MODE_ABS_PINNED_HARD && mode != HRTIMER_MODE_REL' --max-events=2
        Using CPUID GenuineIntel-6-BA-3
        vmlinux BTF loaded
        <SNIP>
        0
        0xa
        0x1
        New filter for timer:hrtimer_start: (mode != 0 && mode != 0xa && mode != 0x1) && (common_pid != 524049 && common_pid != 4041)
        mmap size 528384B
        ^Croot@x1:~#
      Suggested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Signed-off-by: default avatarHoward Chu <howardchu95@gmail.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/lkml/ZnCcliuecJABD5FN@x1
      Link: https://lore.kernel.org/r/20240624181345.124764-5-howardchu95@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      95586588
    • Howard Chu's avatar
      perf trace: Augment non-syscall tracepoints with enum arguments with BTF · 607bbdb4
      Howard Chu authored
      Before:
      
      perf $ ./perf trace -e timer:hrtimer_start --max-events=1
           0.000 :0/0 timer:hrtimer_start(hrtimer: 0xffff974466c25f18, function: 0xffffffff89da5be0, expires: 377432432256753, softexpires: 377432432256753, mode: 10)
      
      After:
      
      perf $ ./perf trace -e timer:hrtimer_start --max-events=1
           0.000 :0/0 timer:hrtimer_start(hrtimer: 0xffff9498a6ca5f18, function: 0xffffffffa77a5be0, expires: 4382442895089, softexpires: 4382442895089, mode: HRTIMER_MODE_ABS_PINNED_HARD)
      
      in which HRTIMER_MODE_ABS_PINNED_HARD is:
      
      perf $ pahole hrtimer_mode
      enum hrtimer_mode {
              HRTIMER_MODE_ABS             = 0,
              HRTIMER_MODE_REL             = 1,
              HRTIMER_MODE_PINNED          = 2,
              HRTIMER_MODE_SOFT            = 4,
              HRTIMER_MODE_HARD            = 8,
              HRTIMER_MODE_ABS_PINNED      = 2,
              HRTIMER_MODE_REL_PINNED      = 3,
              HRTIMER_MODE_ABS_SOFT        = 4,
              HRTIMER_MODE_REL_SOFT        = 5,
              HRTIMER_MODE_ABS_PINNED_SOFT = 6,
              HRTIMER_MODE_REL_PINNED_SOFT = 7,
              HRTIMER_MODE_ABS_HARD        = 8,
              HRTIMER_MODE_REL_HARD        = 9,
              HRTIMER_MODE_ABS_PINNED_HARD = 10,
              HRTIMER_MODE_REL_PINNED_HARD = 11,
      };
      
      Can also be tested by
      
      ./perf trace -e pagemap:mm_lru_insertion,timer:hrtimer_start,timer:hrtimer_init,skb:kfree_skb --max-events=10
      
      (Chose these 4 events because they happen quite frequently.)
      
      However some enum arguments may not be contained in vmlinux BTF. To see
      what enum arguments are supported, use:
      
      vmlinux_dir $ bpftool btf dump file /sys/kernel/btf/vmlinux > vmlinux
      
      vmlinux_dir $  while read l; do grep "ENUM '$l'" vmlinux; done < <(grep field:enum /sys/kernel/tracing/events/*/*/format | awk '{print $3}' | sort | uniq) | awk '{print $3}' | sed "s/'\(.*\)'/\1/g"
      dev_pm_qos_req_type
      error_detector
      hrtimer_mode
      i2c_slave_event
      ieee80211_bss_type
      lru_list
      migrate_mode
      nl80211_auth_type
      nl80211_band
      nl80211_iftype
      numa_vmaskip_reason
      pm_qos_req_action
      pwm_polarity
      skb_drop_reason
      thermal_trip_type
      xen_lazy_mode
      xen_mc_extend_args
      xen_mc_flush_reason
      zone_type
      
      And what tracepoints have these enum types as their arguments:
      
      vmlinux_dir $ while read l; do grep "ENUM '$l'" vmlinux; done < <(grep field:enum /sys/kernel/tracing/events/*/*/format | awk '{print $3}' | sort | uniq) | awk '{print $3}' | sed "s/'\(.*\)'/\1/g" > good_enums
      
      vmlinux_dir $ cat good_enums
      dev_pm_qos_req_type
      error_detector
      hrtimer_mode
      i2c_slave_event
      ieee80211_bss_type
      lru_list
      migrate_mode
      nl80211_auth_type
      nl80211_band
      nl80211_iftype
      numa_vmaskip_reason
      pm_qos_req_action
      pwm_polarity
      skb_drop_reason
      thermal_trip_type
      xen_lazy_mode
      xen_mc_extend_args
      xen_mc_flush_reason
      zone_type
      
      vmlinux_dir $ grep -f good_enums -l /sys/kernel/tracing/events/*/*/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_chandef_dfs_required/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_ch_switch_notify/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_ch_switch_started_notify/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_get_bss/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_ibss_joined/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_inform_bss_frame/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_radar_event/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_ready_on_channel_expired/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_ready_on_channel/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_reg_can_beacon/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_return_bss/format
      /sys/kernel/tracing/events/cfg80211/cfg80211_tx_mgmt_expired/format
      /sys/kernel/tracing/events/cfg80211/rdev_add_virtual_intf/format
      /sys/kernel/tracing/events/cfg80211/rdev_auth/format
      /sys/kernel/tracing/events/cfg80211/rdev_change_virtual_intf/format
      /sys/kernel/tracing/events/cfg80211/rdev_channel_switch/format
      /sys/kernel/tracing/events/cfg80211/rdev_connect/format
      /sys/kernel/tracing/events/cfg80211/rdev_inform_bss/format
      /sys/kernel/tracing/events/cfg80211/rdev_libertas_set_mesh_channel/format
      /sys/kernel/tracing/events/cfg80211/rdev_mgmt_tx/format
      /sys/kernel/tracing/events/cfg80211/rdev_remain_on_channel/format
      /sys/kernel/tracing/events/cfg80211/rdev_return_chandef/format
      /sys/kernel/tracing/events/cfg80211/rdev_return_int_survey_info/format
      /sys/kernel/tracing/events/cfg80211/rdev_set_ap_chanwidth/format
      /sys/kernel/tracing/events/cfg80211/rdev_set_monitor_channel/format
      /sys/kernel/tracing/events/cfg80211/rdev_set_radar_background/format
      /sys/kernel/tracing/events/cfg80211/rdev_start_ap/format
      /sys/kernel/tracing/events/cfg80211/rdev_start_radar_detection/format
      /sys/kernel/tracing/events/cfg80211/rdev_tdls_channel_switch/format
      /sys/kernel/tracing/events/compaction/mm_compaction_defer_compaction/format
      /sys/kernel/tracing/events/compaction/mm_compaction_deferred/format
      /sys/kernel/tracing/events/compaction/mm_compaction_defer_reset/format
      /sys/kernel/tracing/events/compaction/mm_compaction_finished/format
      /sys/kernel/tracing/events/compaction/mm_compaction_kcompactd_wake/format
      /sys/kernel/tracing/events/compaction/mm_compaction_suitable/format
      /sys/kernel/tracing/events/compaction/mm_compaction_wakeup_kcompactd/format
      /sys/kernel/tracing/events/error_report/error_report_end/format
      /sys/kernel/tracing/events/i2c_slave/i2c_slave/format
      /sys/kernel/tracing/events/migrate/mm_migrate_pages/format
      /sys/kernel/tracing/events/migrate/mm_migrate_pages_start/format
      /sys/kernel/tracing/events/pagemap/mm_lru_insertion/format
      /sys/kernel/tracing/events/power/dev_pm_qos_add_request/format
      /sys/kernel/tracing/events/power/dev_pm_qos_remove_request/format
      /sys/kernel/tracing/events/power/dev_pm_qos_update_request/format
      /sys/kernel/tracing/events/power/pm_qos_update_flags/format
      /sys/kernel/tracing/events/power/pm_qos_update_target/format
      /sys/kernel/tracing/events/pwm/pwm_apply/format
      /sys/kernel/tracing/events/pwm/pwm_get/format
      /sys/kernel/tracing/events/sched/sched_skip_vma_numa/format
      /sys/kernel/tracing/events/skb/kfree_skb/format
      /sys/kernel/tracing/events/thermal/thermal_zone_trip/format
      /sys/kernel/tracing/events/timer/hrtimer_init/format
      /sys/kernel/tracing/events/timer/hrtimer_start/format
      /sys/kernel/tracing/events/xen/xen_mc_batch/format
      /sys/kernel/tracing/events/xen/xen_mc_extend_args/format
      /sys/kernel/tracing/events/xen/xen_mc_flush_reason/format
      /sys/kernel/tracing/events/xen/xen_mc_issue/format
      
      Committer testing:
      
        root@x1:~# perf trace -e timer:hrtimer_start --max-events=2
             0.000 :0/0 timer:hrtimer_start(hrtimer: 0xffff8d4eff225050, function: 0xffffffff9e22ddd0, expires: 241152380000000, softexpires: 241152380000000, mode: HRTIMER_MODE_ABS)
             0.028 :0/0 timer:hrtimer_start(hrtimer: 0xffff8d4eff225050, function: 0xffffffff9e22ddd0, expires: 241153654000000, softexpires: 241153654000000, mode: HRTIMER_MODE_ABS_PINNED_HARD)
        root@x1:~#
      Suggested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Reviewed-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Signed-off-by: default avatarHoward Chu <howardchu95@gmail.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/lkml/20240615032743.112750-1-howardchu95@gmail.com
      Link: https://lore.kernel.org/r/20240624181345.124764-4-howardchu95@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      607bbdb4
    • Howard Chu's avatar
      perf trace: BTF-based enum pretty printing for syscall args · 45a0c928
      Howard Chu authored
      In this patch, BTF is used to turn enum value to the corresponding
      name. There is only one system call that uses enum value as its
      argument, that is `landlock_add_rule()`.
      
      The vmlinux btf is loaded lazily, when user decided to trace the
      `landlock_add_rule` syscall. But if one decide to run `perf trace`
      without any arguments, the behaviour is to trace `landlock_add_rule`,
      so vmlinux btf will be loaded by default.
      
      The laziest behaviour is to load vmlinux btf when a
      `landlock_add_rule` syscall hits. But I think you could lose some
      samples when loading vmlinux btf at run time, for it can delay the
      handling of other samples. I might need your precious opinions on
      this...
      
      before:
      
      ```
      perf $ ./perf trace -e landlock_add_rule
           0.000 ( 0.008 ms): ldlck-test/438194 landlock_add_rule(rule_type: 2) = -1 EBADFD (File descriptor in bad state)
           0.010 ( 0.001 ms): ldlck-test/438194 landlock_add_rule(rule_type: 1) = -1 EBADFD (File descriptor in bad state)
      ```
      
      after:
      
      ```
      perf $ ./perf trace -e landlock_add_rule
           0.000 ( 0.029 ms): ldlck-test/438194 landlock_add_rule(rule_type: LANDLOCK_RULE_NET_PORT)     = -1 EBADFD (File descriptor in bad state)
           0.036 ( 0.004 ms): ldlck-test/438194 landlock_add_rule(rule_type: LANDLOCK_RULE_PATH_BENEATH) = -1 EBADFD (File descriptor in bad state)
      ```
      
      Committer notes:
      
      Made it build with NO_LIBBPF=1, simplified btf_enum_fprintf(), see [1]
      for the discussion.
      Signed-off-by: default avatarHoward Chu <howardchu95@gmail.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Günther Noack <gnoack@google.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mickaël Salaün <mic@digikod.net>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/lkml/20240613022757.3589783-1-howardchu95@gmail.com
      Link: https://lore.kernel.org/lkml/ZnXAhFflUl_LV1QY@x1 # [1]
      Link: https://lore.kernel.org/r/20240624181345.124764-3-howardchu95@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      45a0c928
    • Linus Torvalds's avatar
      Merge tag 'for-6.11-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux · e4fc196f
      Linus Torvalds authored
      Pull btrfs fixes from David Sterba:
      
       - fix regression in extent map rework when handling insertion of
         overlapping compressed extent
      
       - fix unexpected file length when appending to a file using direct io
         and buffer not faulted in
      
       - in zoned mode, fix accounting of unusable space when flipping
         read-only block group back to read-write
      
       - fix page locking when COWing an inline range, assertion failure found
         by syzbot
      
       - fix calculation of space info in debugging print
      
       - tree-checker, add validation of data reference item
      
       - fix a few -Wmaybe-uninitialized build warnings
      
      * tag 'for-6.11-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
        btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry()
        btrfs: fix corruption after buffer fault in during direct IO append write
        btrfs: zoned: fix zone_unusable accounting on making block group read-write again
        btrfs: do not subtract delalloc from avail bytes
        btrfs: make cow_file_range_inline() honor locked_page on error
        btrfs: fix corrupt read due to bad offset of a compressed extent map
        btrfs: tree-checker: validate dref root and objectid
      e4fc196f
    • Linus Torvalds's avatar
      Merge tag 'perf-tools-fixes-for-v6.11-2024-07-30' of... · e254e0c5
      Linus Torvalds authored
      Merge tag 'perf-tools-fixes-for-v6.11-2024-07-30' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools
      
      Pull perf tools fixes from Namhyung Kim:
       "Some more build fixes and a random crash fix:
      
         - Fix cross-build by setting pkg-config env according to the arch
      
         - Fix static build for missing library dependencies
      
         - Fix Segfault when callchain has no symbols"
      
      * tag 'perf-tools-fixes-for-v6.11-2024-07-30' of git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools:
        perf docs: Document cross compilation
        perf: build: Link lib 'zstd' for static build
        perf: build: Link lib 'lzma' for static build
        perf: build: Only link libebl.a for old libdw
        perf: build: Set Python configuration for cross compilation
        perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
        perf tool: fix dereferencing NULL al->maps
      e254e0c5
  2. 30 Jul, 2024 4 commits
    • Linus Torvalds's avatar
      Merge tag 'chrome-platform-fixes-for-v6.11-rc2' of... · c91a7dee
      Linus Torvalds authored
      Merge tag 'chrome-platform-fixes-for-v6.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux
      
      Pull chrome-platform fix from Tzung-Bi Shih:
       "Fix a race condition that sends multiple host commands at a time"
      
      * tag 'chrome-platform-fixes-for-v6.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
        platform/chrome: cros_ec_proto: Lock device when updating MKBP version
      c91a7dee
    • Linus Torvalds's avatar
      minmax: improve macro expansion and type checking · 22f54687
      Linus Torvalds authored
      This clarifies the rules for min()/max()/clamp() type checking and makes
      them a much more efficient macro expansion.
      
      In particular, we now look at the type and range of the inputs to see
      whether they work together, generating a mask of acceptable comparisons,
      and then just verifying that the inputs have a shared case:
      
       - an expression with a signed type can be used for
          (1) signed comparisons
          (2) unsigned comparisons if it is statically known to have a
              non-negative value
      
       - an expression with an unsigned type can be used for
          (3) unsigned comparison
          (4) signed comparisons if the type is smaller than 'int' and thus
              the C integer promotion rules will make it signed anyway
      
      Here rule (1) and (3) are obvious, and rule (2) is important in order to
      allow obvious trivial constants to be used together with unsigned
      values.
      
      Rule (4) is not necessarily a good idea, but matches what we used to do,
      and we have extant cases of this situation in the kernel.  Notably with
      bcachefs having an expression like
      
      	min(bch2_bucket_sectors_dirty(a), ca->mi.bucket_size)
      
      where bch2_bucket_sectors_dirty() returns an 's64', and
      'ca->mi.bucket_size' is of type 'u16'.
      
      Technically that bcachefs comparison is clearly sensible on a C type
      level, because the 'u16' will go through the normal C integer promotion,
      and become 'int', and then we're comparing two signed values and
      everything looks sane.
      
      However, it's not entirely clear that a 'min(s64,u16)' operation makes a
      lot of conceptual sense, and it's possible that we will remove rule (4).
      After all, the _reason_ we have these complicated type checks is exactly
      that the C type promotion rules are not very intuitive.
      
      But at least for now the rule is in place for backwards compatibility.
      
      Also note that rule (2) existed before, but is hugely relaxed by this
      commit.  It used to be true only for the simplest compile-time
      non-negative integer constants.  The new macro model will allow cases
      where the compiler can trivially see that an expression is non-negative
      even if it isn't necessarily a constant.
      
      For example, the amdgpu driver does
      
      	min_t(size_t, sizeof(fru_info->serial), pia[addr] & 0x3F));
      
      because our old 'min()' macro would see that 'pia[addr] & 0x3F' is of
      type 'int' and clearly not a C constant expression, so doing a 'min()'
      with a 'size_t' is a signedness violation.
      
      Our new 'min()' macro still sees that 'pia[addr] & 0x3F' is of type
      'int', but is smart enough to also see that it is clearly non-negative,
      and thus would allow that case without any complaints.
      
      Cc: Arnd Bergmann <arnd@kernel.org>
      Cc: David Laight <David.Laight@aculab.com>
      Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      22f54687
    • David Sterba's avatar
      btrfs: initialize location to fix -Wmaybe-uninitialized in btrfs_lookup_dentry() · b8e947e9
      David Sterba authored
      Some arch + compiler combinations report a potentially unused variable
      location in btrfs_lookup_dentry(). This is a false alert as the variable
      is passed by value and always valid or there's an error. The compilers
      cannot probably reason about that although btrfs_inode_by_name() is in
      the same file.
      
         >  + /kisskb/src/fs/btrfs/inode.c: error: 'location.objectid' may be used
         +uninitialized in this function [-Werror=maybe-uninitialized]:  => 5603:9
         >  + /kisskb/src/fs/btrfs/inode.c: error: 'location.type' may be used
         +uninitialized in this function [-Werror=maybe-uninitialized]:  => 5674:5
      
         m68k-gcc8/m68k-allmodconfig
         mips-gcc8/mips-allmodconfig
         powerpc-gcc5/powerpc-all{mod,yes}config
         powerpc-gcc5/ppc64_defconfig
      
      Initialize it to zero, this should fix the warnings and won't change the
      behaviour as btrfs_inode_by_name() accepts only a root or inode item
      types, otherwise returns an error.
      Reported-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
      Tested-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
      Link: https://lore.kernel.org/linux-btrfs/bd4e9928-17b3-9257-8ba7-6b7f9bbb639a@linux-m68k.org/Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
      Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
      b8e947e9
    • Patryk Duda's avatar
      platform/chrome: cros_ec_proto: Lock device when updating MKBP version · df615907
      Patryk Duda authored
      The cros_ec_get_host_command_version_mask() function requires that the
      caller must have ec_dev->lock mutex before calling it. This requirement
      was not met and as a result it was possible that two commands were sent
      to the device at the same time.
      
      The problem was observed while using UART backend which doesn't use any
      additional locks, unlike SPI backend which locks the controller until
      response is received.
      
      Fixes: f74c7557 ("platform/chrome: cros_ec_proto: Update version on GET_NEXT_EVENT failure")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPatryk Duda <patrykd@google.com>
      Link: https://lore.kernel.org/r/20240730104425.607083-1-patrykd@google.comSigned-off-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
      df615907
  3. 29 Jul, 2024 5 commits
    • Linus Torvalds's avatar
      profiling: remove stale percpu flip buffer variables · 94ede2a3
      Linus Torvalds authored
      For some reason I didn't see this issue on my arm64 or x86-64 builds,
      but Stephen Rothwell reports that commit 2accfdb7 ("profiling:
      attempt to remove per-cpu profile flip buffer") left these static
      variables around, and the powerpc build is unhappy about them:
      
        kernel/profile.c:52:28: warning: 'cpu_profile_flip' defined but not used [-Wunused-variable]
           52 | static DEFINE_PER_CPU(int, cpu_profile_flip);
              |                            ^~~~~~~~~~~~~~~~
        ..
      
      So remove these stale left-over remnants too.
      
      Fixes: 2accfdb7 ("profiling: attempt to remove per-cpu profile flip buffer")
      Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      94ede2a3
    • Linus Torvalds's avatar
      Merge tag 'for-linus-2024072901' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid · 6b5faec9
      Linus Torvalds authored
      Pull HID fixes from Benjamin Tissoires:
      
       - fixes for HID-BPF after the merge with the bpf tree (Arnd Bergmann
         and Benjamin Tissoires)
      
       - some tool type fix for the Wacom driver (Tatsunosuke Tobita)
      
       - a reorder of the sensor discovery to ensure the HID AMD SFH is
         removed when no sensors are available (Basavaraj Natikar)
      
      * tag 'for-linus-2024072901' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid:
        selftests/hid: add test for attaching multiple time the same struct_ops
        HID: bpf: prevent the same struct_ops to be attached more than once
        selftests/hid: disable struct_ops auto-attach
        selftests/hid: fix bpf_wq new API
        HID: amd_sfh: Move sensor discovery before HID device initialization
        hid: bpf: add BPF_JIT dependency
        HID: wacom: more appropriate tool type categorization
        HID: wacom: Modify pen IDs
      6b5faec9
    • Linus Torvalds's avatar
      Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost · 10826505
      Linus Torvalds authored
      Pull virtio fixes from Michael Tsirkin:
       "The biggest thing here is the adminq change - but it looks like the
        only way to avoid headq blocking causing indefinite stalls.
      
        This fixes three issues:
      
         - Prevent admin commands on one VF blocking another.
      
           This prevents a bad VF from blocking a good one, as well as fixing
           a scalability issue with large # of VFs
      
         - Correctly return error on command failure on octeon. We used to
           treat failed commands as a success.
      
         - Fix modpost warning when building virtio_dma_buf. Harmless, but the
           fix is trivial"
      
      * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
        virtio_pci_modern: remove admin queue serialization lock
        virtio_pci_modern: use completion instead of busy loop to wait on admin cmd result
        virtio_pci_modern: pass cmd as an identification token
        virtio_pci_modern: create admin queue of queried size
        virtio: create admin queues alongside other virtqueues
        virtio_pci: pass vq info as an argument to vp_setup_vq()
        virtio: push out code to vp_avq_index()
        virtio_pci_modern: treat vp_dev->admin_vq.info.vq pointer as static
        virtio_pci: introduce vector allocation fallback for slow path virtqueues
        virtio_pci: pass vector policy enum to vp_find_one_vq_msix()
        virtio_pci: pass vector policy enum to vp_find_vqs_msix()
        virtio_pci: simplify vp_request_msix_vectors() call a bit
        virtio_pci: push out single vq find code to vp_find_one_vq_msix()
        vdpa/octeon_ep: Fix error code in octep_process_mbox()
        virtio: add missing MODULE_DESCRIPTION() macro
      10826505
    • Linus Torvalds's avatar
      task_work: make TWA_NMI_CURRENT handling conditional on IRQ_WORK · cec6937d
      Linus Torvalds authored
      The TWA_NMI_CURRENT handling very much depends on IRQ_WORK, but that
      isn't universally enabled everywhere.
      
      Maybe the IRQ_WORK infrastructure should just be unconditional - x86
      ends up indirectly enabling it through unconditionally enabling
      PERF_EVENTS, for example.  But it also gets enabled by having SMP
      support, or even if you just have PRINTK enabled.
      
      But in the meantime TWA_NMI_CURRENT causes tons of build failures on
      various odd minimal configs.  Which did show up in linux-next, but
      despite that nobody bothered to fix it or even inform me until -rc1 was
      out.
      
      Fixes: 466e4d80 ("task_work: Add TWA_NMI_CURRENT as an additional notify mode")
      Reported-by: default avatarNaresh Kamboju <naresh.kamboju@linaro.org>
      Reported-by: default avatarkernelci.org bot <bot@kernelci.org>
      Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      cec6937d
    • Linus Torvalds's avatar
      profiling: attempt to remove per-cpu profile flip buffer · 2accfdb7
      Linus Torvalds authored
      This is the really old legacy kernel profiling code, which has long
      since been obviated by "real profiling" (ie 'prof' and company), and
      mainly remains as a source of syzbot reports.
      
      There are anecdotal reports that people still use it for boot-time
      profiling, but it's unlikely that such use would care about the old NUMA
      optimizations in this code from 2004 (commit ad02973d: "profile: 512x
      Altix timer interrupt livelock fix" in the BK import archive at [1])
      
      So in order to head off future syzbot reports, let's try to simplify
      this code and get rid of the per-cpu profile buffers that are quite a
      large portion of the complexity footprint of this thing (including CPU
      hotplug callbacks etc).
      
      It's unlikely anybody will actually notice, or possibly, as Thomas put
      it: "Only people who indulge in nostalgia will notice :)".
      
      That said, if it turns out that this code is actually actively used by
      somebody, we can always revert this removal.  Thus the "attempt" in the
      summary line.
      
      [ Note: in a small nod to "the profiling code can cause NUMA problems",
        this also removes the "increment the last entry in the profiling array
        on any unknown hits" logic. That would account any program counter in
        a module to that single counter location, and might exacerbate any
        NUMA cacheline bouncing issues ]
      
      Link: https://lore.kernel.org/all/CAHk-=wgs52BxT4Zjmjz8aNvHWKxf5_ThBY4bYL1Y6CTaNL2dTw@mail.gmail.com/
      Link:  https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git [1]
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2accfdb7