1. 14 Jun, 2023 17 commits
    • Aboorva Devarajan's avatar
      perf tests test_task_analyzer: Fix shellcheck issues · 9694dfe0
      Aboorva Devarajan authored
      Fixed the following shellcheck issues in test_task_analyzer.sh file:
      
      SC2086: Double quote to prevent globbing and word splitting
      warnings in shell-check.
      Fixes the following shellcheck issues,
      
      SC2086: Double quote to prevent globbing and word splitting
      warnings in shell-check.
      
      Before Patch:
      
      $ shellcheck ./test_task_analyzer.sh  | grep "SC2086" | ...
      In ./test_task_analyzer.sh line 13:
      SC2086: Double quote to prevent globbing and word splitting.
      In ./test_task_analyzer.sh line 24:
      SC2086: Double quote to prevent globbing and word splitting.
      In ./test_task_analyzer.sh line 39:
      SC2086: Double quote to prevent globbing and word splitting.
      
      After Patch:
      $ shellcheck ./test_task_analyzer.sh  | grep -i "SC2086"
      None
      
      perf test result after patch:
      
      PASS: "test_basic"
      PASS: "test_ns_rename"
      PASS: "test_ms_filtertasks_highlight"
      PASS: "test_extended_times_timelimit_limittasks"
      PASS: "test_summary"
      PASS: "test_summaryextended"
      PASS: "test_summaryonly"
      PASS: "test_extended_times_summary_ns"
      PASS: "test_extended_times_summary_ns"
      PASS: "test_csv"
      PASS: "test_csvsummary"
      PASS: "test_csv_extended_times"
      PASS: "test_csvsummary_extended"
      Signed-off-by: default avatarAboorva Devarajan <aboorvad@linux.vnet.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230613164145.50488-10-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9694dfe0
    • Barnali Guha Thakurata's avatar
      perf tests stat_all_metrics: Fix shellcheck warning SC2076 · a6bdb815
      Barnali Guha Thakurata authored
      Fixed shellcheck warning SC2076 in stat_all_metrics.sh.
      
      Before the patch:
      shell$ shellcheck stat_all_metrics.sh
      
      In stat_all_metrics.sh line 9:
        if [[ "$result" =~ "${m:0:50}" ]] || [[ "$result" =~ "<not supported>" ]]
                           ^---------^ SC2076: Don't quote right-hand
      side of =~, it'll match literally rather than as a regex.
      
      In stat_all_metrics.sh line 15:
        if [[ "$result" =~ "${m:0:50}" ]]
                           ^---------^ SC2076: Don't quote right-hand
      side of =~, it'll match literally rather than as a regex.
      
      In stat_all_metrics.sh line 22:
        if [[ "$result" =~ "${m:0:50}" ]]
                           ^---------^ SC2076: Don't quote right-hand
      side of =~, it'll match literally rather than as a regex.
      
      After the patch:
      shell$ shellcheck stat_all_metrics.sh
      shell$
      Signed-off-by: default avatarBarnali Guha Thakurata <barnali@linux.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230613164145.50488-9-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a6bdb815
    • Anushree Mathur's avatar
      perf tests test_arm_coresight: Shellcheck fixes · 0ed4b531
      Anushree Mathur authored
      Fixed the following shellcheck issues in test_arm_coresight.sh file:
      
      In tools/perf/tests/shell/test_arm_coresight.sh line 31:
              trap - exit term int
                     ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                          ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                               ^-^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
      
      In tools/perf/tests/shell/test_arm_coresight.sh line 35:
      trap cleanup_files exit term int
                         ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                              ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                                   ^-^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
      
      In tools/perf/tests/shell/test_arm_coresight.sh line 92:
              if [ $? -eq 0 -a -e "$1/enable_sink" ]; then
                            ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
      
      Fixed above warnings by:
      1)Capitalize signals(INT, TERM, EXIT) to avoid mixed/lower case naming of
      signals.
      2)Expression [p -a q] was not defined,changed it to [p] && [q] to avoid the
      ambiguity as this is older format using -a or -o ,now we use [p] && [q] in
      place of [p -a q] and [p] || [q] in place of [p -o q].
      
      Result after fixing the issues:
      
      shell$ shellcheck -S warning test_arm_coresight.sh
      shell$
      Signed-off-by: default avatarAnushree Mathur <anushree.mathur@linux.vnet.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230613164145.50488-8-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0ed4b531
    • Korrapati Likhitha's avatar
      perf tests stat+csv_output: Fix shellcheck warnings · 9e9d07a7
      Korrapati Likhitha authored
      Running the shellcheck on stat+csv_output resulted in the following
      warning.
      
      Result with shellcheck  without patch:
      =====
      $ shellcheck -S warning stat+csv_output.sh
      
      In stat+csv_output.sh line 23:
               [ $(uname -m) = "s390x" ] && exp='^[6-7]$'
                 ^---------^ SC2046: Quote this to prevent word splitting.
      In stat+csv_output.sh line 51:
      [ $(id -u) != 0 ] && [ $(cat /proc/sys/kernel/perf_event_paranoid) -gt $1 ]
        ^------^ SC2046: Quote this to prevent word splitting.
                             ^-- SC2046: Quote this to prevent word splitting.
      =====
      
      Fixed the warning SC2046 by adding quotes to prevent word splitting.
      
      Result with shellcheck with patch:
      =====
      $ shellcheck -S warning tests/shell/stat+csv_output.sh
      $ ./perf test "stat CSV output linter"
       96: perf stat CSV output linter                                     : Ok
      =====
      Signed-off-by: default avatarKorrapati Likhitha <likhitha@linux.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230613164145.50488-6-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarSathvika Vasireddy <sv@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9e9d07a7
    • Shirisha G's avatar
      perf tests daemon: Address shellcheck warnings · 5bd35dfb
      Shirisha G authored
      Running shellcheck -S on daemon.sh throws below warnings:
      
      Result from shellcheck:
           # shellcheck -S warning daemon.sh
           local line_name=`echo "${line}" | awk 'BEGIN { FS = ":" } ; { print $2 }'`
                 ^-------^ SC2155: Declare and assign separately to avoid masking return values.
      
           trap "echo 'FAILED: Signal caught'; daemon_exit ${config}; exit 1" SIGINT SIGTERM
                                                           ^-------^ SC2064: Use single quotes, otherwise this expands now rather than when signalled.
      
           count=`ls ${base}/session-test/ | grep perf.data | wc -l`
                  ^-- SC2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
      
           if [ ${size} != "OK" -o ${type} != "OK" ]; then
                                ^-- SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
      
      Fixed above warnings by:
         - declaring and assigning local variables separately
         - To fix SC2010, instead of using "ls | grep", used glob to allow non-alphanumeric filenames
         - Used single quotes to prevent expanding.
      
      Result from shellcheck after patch changes:
           $ shellcheck -S warning daemon.sh
           $ echo $?
             0
      Signed-off-by: default avatarShirisha G <shirisha@linux.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230613164145.50488-5-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5bd35dfb
    • Spoorthy S's avatar
      perf tests arm_callgraph_fp: Address shellcheck warnings about signal names... · 1bb17b4c
      Spoorthy S authored
      perf tests arm_callgraph_fp: Address shellcheck warnings about signal names and adding double quotes for expression
      
      Running shellcheck -S on test_arm_calligraph_fp throws warnings SC2086 and SC3049,
      
            $shellcheck -S warning tests/shell/test_arm_callgraph_fp.sh
               rm -f $PERF_DATA
                  : Double quote to prevent globbing and word splitting.
               trap cleanup_files exit term int
                           : In POSIX sh, using lower/mixed case for signal names is undefined.
      
      After fixing the warnings,
      
            $shellcheck tests/shell/test_arm_callgraph_fp.sh
            $ echo $?
            0
      
      To address the POSIX shell warnings added changes to convert Lowercase
      signal names to uppercase in the script and double quoted the
      command substitutions($fix to "$fix") to solve Globbing warnings.
      
      Signed-off-by: Spoorthy S<spoorts2@in.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230613164145.50488-4-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1bb17b4c
    • Disha Goel's avatar
      perf tests stat+json_output: Address shellcheck warnings · b3839ff1
      Disha Goel authored
      Running shellcheck on stat+json_output testcase, generates below warning:
      
      	 [ $(id -u) != 0 ] && [ $(cat /proc/sys/kernel/perf_event_paranoid) -gt $1 ]
                 ^------^ SC2046 (warning): Quote this to prevent word splitting.
                                      ^-- SC2046 (warning): Quote this to prevent word splitting.
      
      Fixed the warning by adding quotes to avoid word splitting.
      
      ShellCheck result with patch:
      	 # shellcheck -S warning stat+json_output.sh
      	 #
      
      perf test result after the change:
      	 94: perf stat JSON output linter : Ok
      Signed-off-by: default avatarDisha Goel <disgoel@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/linux-perf-users/20230613164145.50488-3-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b3839ff1
    • Sourabh Jain's avatar
      perf python scripting: Get rid of unused import in arm-cs-trace-disasm · 75782e82
      Sourabh Jain authored
      The arm-cs-trace-disasm.py script doesn't use the sys library, so remove
      the import.
      
      Report by pylint:
      
        W0611: Unused import sys (unused-import)
      Signed-off-by: default avatarSourabh Jain <sourabhjain@linux.ibm.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/linux-perf-users/20230613164145.50488-2-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Signed-off-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      75782e82
    • Ravi Bangoria's avatar
      perf tool x86: Consolidate is_amd check into single function · 0cd1ca46
      Ravi Bangoria authored
      There are multiple places where x86 specific code determines AMD vs
      Intel arch and acts based on that. Consolidate those checks into a
      single function.
      Signed-off-by: default avatarRavi Bangoria <ravi.bangoria@amd.com>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Ananth Narayan <ananth.narayan@amd.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Santosh Shukla <santosh.shukla@amd.com>
      Link: https://lore.kernel.org/r/20230613095506.547-3-ravi.bangoria@amd.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0cd1ca46
    • Ian Rogers's avatar
      perf parse-events: Avoid string for PE_BP_COLON, PE_BP_SLASH · 6ec9503f
      Ian Rogers authored
      There's no need to read the string ':' or '/' for PE_BP_COLON or
      PE_BP_SLASH and doing so causes parse-events.y to leak memory.
      
      The original patch has a committer note about not using these tokens
      presumably as yacc spotted they were a memory leak because no
      %destructor could be run. Remove the unused token workaround as there
      is now no value associated with these tokens.
      
      Fixes: f0617f52 ("perf parse: Allow config terms with breakpoints")
      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: 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: Rob Herring <robh@kernel.org>
      Link: https://lore.kernel.org/r/20230613182629.1500317-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6ec9503f
    • Kan Liang's avatar
      perf metric: Fix no group check · e4c4e8a5
      Kan Liang authored
      The no group check fails if there is more than one meticgroup in the
      metricgroup_no_group.
      
      The first parameter of the match_metric() should be the string, while
      the substring should be the second parameter.
      
      Fixes: ccc66c60 ("perf metric: JSON flag to not group events if gathering a metric group")
      Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ahmad Yasin <ahmad.yasin@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: https://lore.kernel.org/r/20230607162700.3234712-2-kan.liang@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e4c4e8a5
    • Ian Rogers's avatar
      tools api fs: More thread safety for global filesystem variables · 97d5f2e9
      Ian Rogers authored
      Multiple threads, such as with "perf top", may race to initialize a
      file system path like hugetlbfs. The racy initialization of the path
      leads to at least memory leaks. To avoid this initialize each fs for
      reading the mount point path with pthread_once.
      
      Mounting the file system may also be racy, so introduce a mutex over
      the function. This does mean that the path is being accessed with and
      without a mutex, which is inherently racy but hopefully benign,
      especially as there are fewer callers to fs__mount.
      
      Remove the fs__entries by directly using global variables, this was
      done as no argument like the index can be passed to the init once
      routine.
      
      Issue found and tested with "perf top" and address sanitizer.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230609224004.180988-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      97d5f2e9
    • Ian Rogers's avatar
      perf srcline: Make sentinel reading for binutils addr2line more robust · 8dc26b6f
      Ian Rogers authored
      The addr2line process is sent an address then multiple function,
      filename:line "records" are read. To detect the end of output a ',' is
      sent and for llvm-addr2line a ',' is then read back showing the end of
      addrline's output.
      
      For binutils addr2line the ',' translates to address 0 and we expect the
      bogus filename marker "??:0" (see filename_split) to be sent from
      addr2line.
      
      For some kernels address 0 may have a mapping and so a seemingly valid
      inline output is given and breaking the sentinel discovery:
      
        ```
        $ addr2line -e vmlinux -f -i
        ,
        __per_cpu_start
        ./arch/x86/kernel/cpu/common.c:1850
        ```
      
      To avoid this problem enable the address dumping for addr2line (the -a
      option). If an address of 0x0000000000000000 is read then this is the
      sentinel value working around the problem above.
      
      The filename_split still needs to check for "??:0" as bogus non-zero
      addresses also need handling.
      Reported-by: default avatarChangbin Du <changbin.du@huawei.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarChangbin Du <changbin.du@huawei.com>
      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: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Tom Rix <trix@redhat.com>
      Cc: llvm@lists.linux.dev
      Link: https://lore.kernel.org/r/20230613034817.1356114-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8dc26b6f
    • Ian Rogers's avatar
      perf srcline: Make addr2line configuration failure more verbose · c7a0023a
      Ian Rogers authored
      To aid debugging why it fails. Also, combine the loops for reading a
      line for the llvm/binutils cases.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarChangbin Du <changbin.du@huawei.com>
      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: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Tom Rix <trix@redhat.com>
      Cc: llvm@lists.linux.dev
      Link: https://lore.kernel.org/r/20230613034817.1356114-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c7a0023a
    • Adrian Hunter's avatar
      perf tests: Make x86 new instructions test optional at build time · d436373a
      Adrian Hunter authored
      The "x86 instruction decoder - new instructions" test takes up space but
      is only really useful to developers. Make it optional at build time.
      
      Add variable EXTRA_TESTS which must be defined in order to build perf
      with the test.
      
      Example:
      
        Before:
      
          $ make -C tools/perf clean >/dev/null
          $ make -C tools/perf >/dev/null
          Makefile.config:650: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
          Makefile.config:1149: libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev
            PERF_VERSION = 6.4.rc3.gd15b8c76
          $ readelf -SW tools/perf/perf | grep '\.rela.dyn\|.rodata\|\.data.rel.ro'
            [10] .rela.dyn         RELA            000000000002fcb0 02fcb0 0748b0 18   A  6   0  8
            [18] .rodata           PROGBITS        00000000002eb000 2eb000 6bac00 00   A  0   0 32
            [25] .data.rel.ro      PROGBITS        00000000009ea180 9e9180 04b540 00  WA  0   0 32
      
        After:
      
          $ make -C tools/perf clean >/dev/null
          $ make -C tools/perf >/dev/null
          Makefile.config:650: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
          Makefile.config:1154: libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev
            PERF_VERSION = 6.4.rc3.g4ea9c1569ea4
          $ readelf -SW tools/perf/perf | grep '\.rela.dyn\|.rodata\|\.data.rel.ro'
            [10] .rela.dyn         RELA            000000000002f3c8 02f3c8 036d68 18   A  6   0  8
            [18] .rodata           PROGBITS        00000000002ac000 2ac000 68da80 00   A  0   0 32
            [25] .data.rel.ro      PROGBITS        000000000097d440 97c440 022280 00  WA  0   0 32
      
      Committer notes:
      
      Build with 'make EXTRA_TESTS=1 -C tools/perf O=/tmp/build/perf" and
      reproduced the ELF section size differences.
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/683fea7c-f5e9-fa20-f96b-f6233ed5d2a7@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d436373a
    • Namhyung Kim's avatar
      perf dwarf-aux: Allow unnamed struct/union/enum · 7f911905
      Namhyung Kim authored
      It's possible some struct/union/enum type don't have type name.  Allow
      the empty name after "struct"/"union"/"enum" string rather than fail.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230612234102.3909116-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7f911905
    • Namhyung Kim's avatar
      perf dwarf-aux: Fix off-by-one in die_get_varname() · 3abfcfd8
      Namhyung Kim authored
      The die_get_varname() returns "(unknown_type)" string if it failed to
      find a type for the variable.  But it had a space before the opening
      parenthesis and it made the closing parenthesis cut off due to the
      off-by-one in the string length (14).
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Fixes: 88fd633c ("perf probe: No need to use formatting strbuf method")
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230612234102.3909116-1-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3abfcfd8
  2. 13 Jun, 2023 2 commits
  3. 12 Jun, 2023 21 commits
    • Ian Rogers's avatar
      perf inject: Lazily allocate guest_event event_buf · 892d00fb
      Ian Rogers authored
      The event_buf is 64kb (PERF_SAMPLE_SIZE_MAX) and stack allocated in
      struct perf_inject. It is used for guest events that may not exist in
      a file. Make the array allocation lazy to cut down on the stack usage.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      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/20230527034324.2597593-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      892d00fb
    • Ian Rogers's avatar
      perf inject: Lazily allocate event_copy · d3944f0e
      Ian Rogers authored
      The event_copy is 64kb (PERF_SAMPLE_SIZE_MAX) and stack allocated in
      struct perf_inject. It is used for aux events that may not exist in a
      file. Make the array allocation lazy to cut down on the stack usage.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      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/20230527034324.2597593-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d3944f0e
    • Ian Rogers's avatar
      perf script: Remove some large stack allocations · e590e46b
      Ian Rogers authored
      Some char buffers are stack allocated but in total they come to
      24kb. Avoid Wstack-usage warnings by moving the arrays to being
      dynamically allocated.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      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/20230527034324.2597593-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e590e46b
    • Ian Rogers's avatar
      perf sched: Avoid large stack allocations · 232418a0
      Ian Rogers authored
      Commit 5ded57ac ("perf inject: Remove static variables") moved
      static variables to local, however, in this case 3 MAX_CPUS (4096)
      sized arrays were moved onto the stack making the stack frame quite
      large. Avoid the stack usage by dynamically allocating the arrays.
      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: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      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/20230527034324.2597593-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      232418a0
    • Ian Rogers's avatar
      perf bench sched messaging: Free contexts on exit · e57d7393
      Ian Rogers authored
      Place sender and receiver contexts onto lists so that they may be
      freed on exit. Add missing pthread_attr_destroy. Fixes memory leaks
      reported by leak sanitizer.
      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: André Almeida <andrealmeid@igalia.com>
      Cc: Darren Hart <dvhart@infradead.org>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: https://lore.kernel.org/r/20230611233610.953456-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e57d7393
    • Ian Rogers's avatar
      perf bench futex: Avoid memory leaks from pthread_attr · 8351498d
      Ian Rogers authored
      Remove code sharing the pthread_attr_t and initialize/destroy
      pthread_attr_t when needed. This avoids the same attribute being set
      that leak sanitizer reports as a memory leak.
      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: André Almeida <andrealmeid@igalia.com>
      Cc: Darren Hart <dvhart@infradead.org>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: https://lore.kernel.org/r/20230611233610.953456-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8351498d
    • Ian Rogers's avatar
      perf bench epoll: Fix missing frees/puts on the exit path · e6deda2e
      Ian Rogers authored
      Issues detected by leak sanitizer.
      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: André Almeida <andrealmeid@igalia.com>
      Cc: Darren Hart <dvhart@infradead.org>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: https://lore.kernel.org/r/20230611233610.953456-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e6deda2e
    • Ian Rogers's avatar
      perf help: Ensure clean_cmds is called on all paths · 0f0d1354
      Ian Rogers authored
      Avoid potential memory leaks.
      
      Committer notes:
      
      This is right before calling exit(1), so just to clean up memory leak
      checker detection.
      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: André Almeida <andrealmeid@igalia.com>
      Cc: Darren Hart <dvhart@infradead.org>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: https://lore.kernel.org/r/20230611233610.953456-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0f0d1354
    • Ian Rogers's avatar
      lib subcmd: Avoid memory leak in exclude_cmds · 657a3efe
      Ian Rogers authored
      exclude_cmds will shorten the cmds names array, before doing so free the
      removed entry.
      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: André Almeida <andrealmeid@igalia.com>
      Cc: Darren Hart <dvhart@infradead.org>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: https://lore.kernel.org/r/20230611233610.953456-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      657a3efe
    • James Clark's avatar
      perf cs-etm: Add exception level consistency check · d927ef50
      James Clark authored
      Assert that our own tracking of the exception level matches what
      OpenCSD provides. OpenCSD doesn't distinguish between EL0 and EL1 in the
      memory access callback so the extra tracking was required. But a rough
      assert can still be done.
      Signed-off-by: default avatarJames Clark <james.clark@arm.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: John Garry <john.g.garry@oracle.com>
      Cc: Leo Yan <leo.yan@linaro.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: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230612111403.100613-6-james.clark@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d927ef50
    • James Clark's avatar
      perf cs-etm: Track exception level · 8d3031d3
      James Clark authored
      Currently we assume all trace belongs to the host machine so when
      the decoder should be looking at the guest kernel maps it can crash
      because it looks at the host ones instead.
      
      Avoid one scenario (guest kernel running at EL1) by assigning the
      default guest machine to this trace. For userspace trace it's still not
      possible to determine guest vs host, but the PIDs should help in this
      case.
      
      Committer notes:
      
      Fixed up conflict with:
      
        perf addr_location: Add init/exit/copy functions
      
      That was only on tmp.perf-tools-next.
      Reviewed-by: default avatarLeo Yan <leo.yan@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.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: John Garry <john.g.garry@oracle.com>
      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: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230612111403.100613-5-james.clark@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8d3031d3
    • James Clark's avatar
      perf cs-etm: Make PID format accessible from struct cs_etm_auxtrace · 5414b532
      James Clark authored
      To avoid every user of PID format having to use their own static
      local variable, cache it on initialisation and change the accessor to
      take struct cs_etm_auxtrace.
      Reviewed-by: default avatarLeo Yan <leo.yan@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.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: John Garry <john.g.garry@oracle.com>
      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: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230612111403.100613-4-james.clark@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5414b532
    • James Clark's avatar
      perf cs-etm: Use previous thread for branch sample source IP · d67d8c87
      James Clark authored
      Branch samples currently use the IP of the previous packet as the from
      IP, and the IP of the current packet as the to IP. But it incorrectly
      uses the current thread. In some cases like a jump into a different
      exception level this will attribute to the incorrect process.
      
      Fix it by tracking the previous thread in the same way the previous
      packet is tracked.
      
      Committer notes:
      
      Resolved conflicts with:
      
        perf addr_location: Add init/exit/copy functions
        perf thread: Add accessor functions for thread
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      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: linux-arm-kernel@lists.infradead.org
      Link: http://lore.kernel.org/lkml/20230612111403.100613-3-james.clark@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d67d8c87
    • James Clark's avatar
      perf cs-etm: Only track threads instead of PID and TIDs · 951ccccd
      James Clark authored
      PIDs and TIDs are already contained within the thread struct, so to
      avoid inconsistencies drop the extra members on the etm queue and only
      use the thread struct.
      
      At the same time stop using the 'unknown' thread. In a later commit
      we will be making samples from multiple machines so it will be better
      to use the idle thread of each machine rather than overlapping unknown
      threads. Using the idle thread is also better because kernel addresses
      with a previously unknown thread will now be assigned to a real kernel
      thread.
      
      Committer notes:
      
      Resolved conflicts with:
      
        perf addr_location: Add init/exit/copy functions
        perf thread: Add accessor functions for thread
        perf thread: Remove notion of dead threads
      
      That were present in tmp.perf-tools.next only.
      Reviewed-by: default avatarLeo Yan <leo.yan@linaro.org>
      Reviewed-by: default avatarMike Leach <mike.leach@linaro.org>
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Acked-by: default avatarSuzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      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: linux-arm-kernel@lists.infradead.org
      Link: http://lore.kernel.org/lkml/20230612111403.100613-2-james.clark@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      951ccccd
    • James Clark's avatar
      perf map: Fix double 'struct map' reference free found with -DREFCNT_CHECKING=1 · 0d98a7af
      James Clark authored
      When quitting after running a 'perf report', the refcount checker finds
      some double frees. The issue is that map__put() is called on a function
      argument so it removes the refcount wrapper that someone else was using.
      
      Fix it by only calling map__put() on a reference that is owned by this
      function.
      
      Committer notes:
      
      Narrowed the map_ref scope as suggested by Ian, removed the symbol-elf
      part as it was already fixed by another patch, from Ian.
      Signed-off-by: default avatarJames Clark <james.clark@arm.com>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      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: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230612150424.198914-1-james.clark@arm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0d98a7af
    • Arnaldo Carvalho de Melo's avatar
      perf srcline: Optimize comparision against SRCLINE_UNKNOWN · 922db21d
      Arnaldo Carvalho de Melo authored
      This is a string constant that gets returned and then strcmp() around,
      we can instead just do a pointer comparision.
      
      That requires a new global variable to comply with these warnings from
      some versions of clang and gcc:
      
        41    68.95 fedora:rawhide                : FAIL clang version 16.0.4 (Fedora 16.0.4-1.fc39)
          result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Werror,-Wstring-compare]
                  if (start_line != SRCLINE_UNKNOWN &&
                                 ^  ~~~~~~~~~~~~~~~  41
      
      Ack comments:
      
      Agreed, the strcmps make me nervous as they won't distinguish heap from
      a global meaning we could end up with things like pointers to freed
      memory. The comparison with the global is always going to be same imo.
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Link: https://lore.kernel.org/lkml/ZIcoJytUEz4UgQYR@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      922db21d
    • Ian Rogers's avatar
      perf hist: Fix srcline memory leak · 834631ee
      Ian Rogers authored
      srcline isn't freed if it is SRCLINE_UNKNOWN. Avoid strduping in this
      case as such strdups are redundant and leak memory.
      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: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-27-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      834631ee
    • Ian Rogers's avatar
      perf srcline: Change free_srcline to zfree_srcline · 625db36e
      Ian Rogers authored
      Make use after free more unlikely.
      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: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-26-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      625db36e
    • Ian Rogers's avatar
      perf callchain: Use pthread keys for tls callchain_cursor · 8ab12a20
      Ian Rogers authored
      Pthread keys are more portable than __thread and allow the association
      of a destructor with the key. Use the destructor to clean up TLS
      callchain cursors to aid understanding memory leaks.
      
      Committer notes:
      
      Had to fixup a series of unconverted places and also check for the
      return of get_tls_callchain_cursor() as it may fail and return NULL.
      
      In that unlikely case we now either print something to a file, if the
      caller was expecting to print a callchain, or return an error code to
      state that resolving the callchain isn't possible.
      
      In some cases this was made easier because thread__resolve_callchain()
      already can fail for other reasons, so this new one (cursor == NULL) can
      be added and the callers don't have to explicitely check for this new
      condition.
      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: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-25-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8ab12a20
    • Ian Rogers's avatar
      perf header: Avoid out-of-bounds read · d7ba60a4
      Ian Rogers authored
      intel-pt tests were failing:
      
        -- Test virtual LBR ---
        Linux
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.126 MB /tmp/perf-test-intel-pt-sh.FW57CXnCqQ/test-perf.data ]
        Failed with virtual lbr
        ...
        ```
      
        The root cause is an out-of-bounds read in header (where maxbrstack.py
        is from test_intel_pt.sh):
        ```
        $ perf --no-pager script --itrace=L -s maxbrstack.py
        =================================================================
        ==3907930==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000095a8 at pc 0x563c26c840bb bp 0x7fff43582710 sp 0x7fff43582708
        READ of size 4 at 0x6020000095a8 thread T0
            #0 0x563c26c840ba in process_group_desc util/header.c:2847
            #1 0x563c26c8bc78 in perf_file_section__process util/header.c:4037
            #2 0x563c26c8aa9b in perf_header__process_sections util/header.c:3813
            #3 0x563c26c8d028 in perf_session__read_header util/header.c:4286
            #4 0x563c26cbab29 in perf_session__open util/session.c:113
            #5 0x563c26cbb3d0 in __perf_session__new util/session.c:221
            #6 0x563c26aacb14 in perf_session__new util/session.h:73
            #7 0x563c26acf7f1 in cmd_script tools/perf/builtin-script.c:4212
            #8 0x563c26bb58ff in run_builtin tools/perf/perf.c:323
            #9 0x563c26bb5e70 in handle_internal_command tools/perf/perf.c:377
            #10 0x563c26bb6238 in run_argv tools/perf/perf.c:421
            #11 0x563c26bb67a0 in main tools/perf/perf.c:537
            #12 0x7f34bde46189 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
            #13 0x7f34bde46244 in __libc_start_main_impl ../csu/libc-start.c:381
            #14 0x563c26a33390 in _start (/tmp/perf/perf+0x1eb390)
      
        0x6020000095a8 is located 8 bytes to the right of 16-byte region [0x602000009590,0x6020000095a0)
        allocated by thread T0 here:
            #0 0x7f34beeb83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
            #1 0x563c26c83df8 in process_group_desc util/header.c:2824
            #2 0x563c26c8bc78 in perf_file_section__process util/header.c:4037
            #3 0x563c26c8aa9b in perf_header__process_sections util/header.c:3813
            #4 0x563c26c8d028 in perf_session__read_header util/header.c:4286
            #5 0x563c26cbab29 in perf_session__open util/session.c:113
            #6 0x563c26cbb3d0 in __perf_session__new util/session.c:221
            #7 0x563c26aacb14 in perf_session__new util/session.h:73
            #8 0x563c26acf7f1 in cmd_script tools/perf/builtin-script.c:4212
            #9 0x563c26bb58ff in run_builtin tools/perf/perf.c:323
            #10 0x563c26bb5e70 in handle_internal_command tools/perf/perf.c:377
            #11 0x563c26bb6238 in run_argv tools/perf/perf.c:421
            #12 0x563c26bb67a0 in main tools/perf/perf.c:537
            #13 0x7f34bde46189 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
        ```
      
      Avoid the out-of-bounds read checking for the leader. Leave the 'nr'
      check intact as nr will be 0 or the counting down and evsel be a group
      member.
      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: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/lkml/20230608232823.4027869-24-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d7ba60a4
    • Ian Rogers's avatar
      perf top: Add exit routine for main thread · cddeeeda
      Ian Rogers authored
      Add exit_process_thread that reverses init_process_thread. This avoids
      leak sanitizer reporting memory leaks.
      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: Ali Saidi <alisaidi@amazon.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Brian Robbins <brianrob@linux.microsoft.com>
      Cc: Changbin Du <changbin.du@huawei.com>
      Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
      Cc: Fangrui Song <maskray@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ivan Babrou <ivan@cloudflare.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: K Prateek Nayak <kprateek.nayak@amd.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Sean Christopherson <seanjc@google.com>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Wenyu Liu <liuwenyu7@huawei.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
      Cc: Yuan Can <yuancan@huawei.com>
      Cc: coresight@lists.linaro.org
      Cc: linux-arm-kernel@lists.infradead.org
      Link: https://lore.kernel.org/r/20230608232823.4027869-23-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cddeeeda