1. 19 Aug, 2024 18 commits
    • Ian Rogers's avatar
      perf inject: Combine different mmap and mmap2 functions · 048a7a93
      Ian Rogers authored
      There are repipe, build ID and JIT dump variants of the mmap and mmap2
      repipe functions. The organization doesn't allow JIT dump to work with
      build ID injection and the structure is less than clear. Combine the
      function and enable the different behaviors based on ifs.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-9-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      048a7a93
    • Ian Rogers's avatar
      perf inject: Combine build_ids and build_id_all into enum · 0ed4c8c3
      Ian Rogers authored
      It is clearer to have a single enum that determines how build ids are
      injected, it also allows for future extension.
      
      Set the header build ID feature whether lazy or all are generated,
      previously only the lazy case would set it.
      
      Allow parsing of known build IDs for either the lazy or all cases.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-8-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0ed4c8c3
    • Ian Rogers's avatar
      perf test: Expand pipe/inject test · a8656614
      Ian Rogers authored
      Test recording of call-graphs and injecting --build-all. Add/expand
      trap handler.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a8656614
    • Ian Rogers's avatar
      perf evsel: Constify evsel__id_hdr_size() argument · 63c89dc5
      Ian Rogers authored
      Allows evsel__id_hdr_size() to be used when the evsel is const.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-6-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      63c89dc5
    • Ian Rogers's avatar
      perf dso: Constify dso_id · e4bb4caa
      Ian Rogers authored
      The passed dso_id is copied and so is never an out argument. Remove
      its mutability.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e4bb4caa
    • Ian Rogers's avatar
      perf jit: Constify filename argument · 0847c193
      Ian Rogers authored
      Make it clearer the argument is just being used as a string.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0847c193
    • Ian Rogers's avatar
      perf map: API clean up · a0310736
      Ian Rogers authored
      map__init() is only used internally so make it static. Assume memory is
      zero initialized, which will better support adding fields to struct
      map in the future and was already the case for map__new2.
      
      To reduce complexity, change set_priv and set_erange_warned to not take
      a value to assign as they always assign true.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a0310736
    • Ian Rogers's avatar
      perf synthetic-events: Avoid unnecessary memset · 2aebebb8
      Ian Rogers authored
      Make sure the memset of a synthesized event only zeros the necessary
      tracing data part of the event, as a full event can be over 4kb in
      size.
      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: Anne Macedo <retpolanne@posteo.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Casey Chen <cachen@purestorage.com>
      Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
      Cc: Colin Ian King <colin.i.king@gmail.com>
      Cc: Dominique Martinet <asmadeus@codewreck.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@linaro.org>
      Cc: Jann Horn <jannh@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sun Haiyong <sunhaiyong@loongson.cn>
      Cc: Weilin Wang <weilin.wang@intel.com>
      Cc: Yang Jihong <yangjihong1@huawei.com>
      Cc: Yunseong Kim <yskelg@gmail.com>
      Cc: Ze Gao <zegao2021@gmail.com>
      Link: https://lore.kernel.org/r/20240817064442.2152089-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2aebebb8
    • Xu Yang's avatar
      perf python: Fix the build on 32-bit arm by including missing "util/sample.h" · 2518e132
      Xu Yang authored
      The 32-bit arm build system will complain:
      
        tools/perf/util/python.c:75:28: error: field ‘sample’ has incomplete type
           75 |         struct perf_sample sample;
      
      However, arm64 build system doesn't complain this.
      
      The root cause is arm64 define "HAVE_KVM_STAT_SUPPORT := 1" in
      tools/perf/arch/arm64/Makefile, but arm arch doesn't define this.  This
      will lead to kvm-stat.h include other header files on arm64 build
      system, especially "util/sample.h" for util/python.c.
      
      This will try to directly include "util/sample.h" for "util/python.c" to
      avoid such build issue on arm platform.
      Signed-off-by: default avatarXu Yang <xu.yang_2@nxp.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>
      Cc: imx@lists.linux.dev
      Link: https://lore.kernel.org/r/20240819023403.201324-1-xu.yang_2@nxp.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2518e132
    • Namhyung Kim's avatar
      perf annotate-data: Update type stat at the end of find_data_type_die() · 023aceec
      Namhyung Kim authored
      After trying all possibilities with DWARF and instruction tracking.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-10-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      023aceec
    • Namhyung Kim's avatar
      perf annotate-data: Check variables in every scope · ba883370
      Namhyung Kim authored
      Sometimes it matches a variable in the inner scope but it fails because
      the actual access can be on a different type.  Let's try variables in
      every scope and choose the best one using is_better_type().
      
      I have an example with update_blocked_averages(), at first it found a
      variable (__mptr) but it's a void pointer.  So it moved on to the upper
      scope and found another variable (cfs_rq).
      
        $ perf --debug type-profile annotate --data-type --stdio
        ...
        -----------------------------------------------------------
        find data type for 0x140(reg14) at update_blocked_averages+0x2db
        CU for kernel/sched/fair.c (die:0x12dd892)
        frame base: cfa=1 fbreg=7
        found "__mptr" (die: 0x13022f1) in scope=4/4 (die: 0x13022e8) failed: no/void pointer
         variable location: base=reg14, offset=0x140
         type='void*' size=0x8 (die:0x12dd8f9)
        found "cfs_rq" (die: 0x1301721) in scope=3/4 (die: 0x130171c) type_offset=0x140
         variable location: reg14
         type='struct cfs_rq' size=0x1c0 (die:0x12e37e5)
        final type: type='struct cfs_rq' size=0x1c0 (die:0x12e37e5)
      
      IIUC the scope is like below:
        1: update_blocked_averages
        2:   __update_blocked_fair
        3:     for_each_leaf_cfs_rq_safe
        4:       list_entry -> (container_of)
      
      The container_of is implemented like:
      
        #define container_of(ptr, type, member) ({				\
        	void *__mptr = (void *)(ptr);					\
        	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
        		      __same_type(*(ptr), void),			\
        		      "pointer type mismatch in container_of()");	\
        	((type *)(__mptr - offsetof(type, member))); })
      
      That's why we see the __mptr variable first but it failed since it has
      no type information.
      
      Then for_each_leaf_cfs_rq_safe() is defined as
      
        #define for_each_leaf_cfs_rq_safe(rq, cfs_rq, pos)			\
        	list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list,	\
        				 leaf_cfs_rq_list)
      
      Note that the access was 0x140(r14).  And the cfs_rq has
      leaf_cfs_rq_list at the 0x140.  So it converts the list_head pointer to
      a pointer to struct cfs_rq here.
      
        $ pahole --hex -C cfs_rq vmlinux | grep 140
        struct cfs_rq 	struct list_head           leaf_cfs_rq_list;     /* 0x140  0x10 */
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-9-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ba883370
    • Namhyung Kim's avatar
      perf annotate-data: Add is_better_type() helper · c663451f
      Namhyung Kim authored
      Sometimes more than one variables are located in the same register or a
      stack slot.  Or it can overwrite existing information with others.  I
      found this is not helpful in some cases so it needs to update the type
      information from the variable only if it's better.
      
      But it's hard to know which one is better, so we needs heuristics. :)
      
      As it deals with memory accesses, the location should have a pointer or
      something similar (like array or reference).  So if it had an integer
      type and a variable is a pointer, we can take the variable's type to
      resolve the target of the access.
      
      If it has a pointer type and a variable with the same location has a
      different pointer type, it'll take one with bigger target type.  This
      can be useful when the target type embeds a smaller type (like list
      header or RB-tree node) at the beginning so their location is same.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-8-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      c663451f
    • Namhyung Kim's avatar
      perf annotate-data: Add is_pointer_type() helper · 98d1f1dc
      Namhyung Kim authored
      It treats pointers and arrays in the same way.  Let's add the helper and
      use it when it checks if it needs a pointer.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-7-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      98d1f1dc
    • Namhyung Kim's avatar
      perf annotate-data: Change return type of find_data_type_block() · 69e2c784
      Namhyung Kim authored
      So that it can return enum variable_match_type to be propagated to the
      find_data_type_die().  Also update the debug message to show the result
      of the check_matching_type().
      
        chk [dd] reg0 offset=0 ok=1 kind=1  : Good!
      or
        chk [177] reg4 offset=0x138 ok=0 kind=0 cfa : no type information
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-6-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      69e2c784
    • Namhyung Kim's avatar
      perf annotate-data: Add variable_state_str() · 653185d8
      Namhyung Kim authored
      So that it can show a proper debug message in the right place.  The
      check_variable() is used in other places which don't want to print the
      message.
      
        $ perf --debug type-profile annotate --data-type
      
      Before:
        -----------------------------------------------------------
        find data type for 0x140(reg14) at update_blocked_averages+0x2db
        CU for kernel/sched/fair.c (die:0x12dd892)
        frame base: cfa=1 fbreg=7
        no pointer or no type                                         <<<--- removed
        check variable "__mptr" failed (die: 0x13022f1)
         variable location: base=reg14, offset=0x140
         type='void*' size=0x8 (die:0x12dd8f9)
      
      After:
        -----------------------------------------------------------
        find data type for 0x140(reg14) at update_blocked_averages+0x2db
        CU for kernel/sched/fair.c (die:0x12dd892)
        frame base: cfa=1 fbreg=7
        found "__mptr" (die: 0x13022f1) in scope=4/4 (die: 0x13022e8) failed: no/void pointer  <<<--- here
         variable location: base=reg14, offset=0x140
         type='void*' size=0x8 (die:0x12dd8f9)
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-5-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      653185d8
    • Namhyung Kim's avatar
      perf annotate-data: Add 'enum type_match_result' · 976862f8
      Namhyung Kim authored
      And let check_variable() return the enum value so that callers can know
      what was the problem.  This will be used by the later patch to update
      the statistics correctly and print the error message in a right place.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-4-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      976862f8
    • Namhyung Kim's avatar
      perf annotate-data: Fix off-by-one in location range check · 3ab0b8b2
      Namhyung Kim authored
      The location list will have entries with half-open addressing like
      [start, end) which means it doesn't include the end address.  So it
      should skip entries at the end address and match to the next entry.
      
      An example location list looks like this (from readelf -wo):
      
          00237876 ffffffff8110d32b (base address)
          0023787f v000000000000000 v000000000000002 views at 00237868 for:
                   ffffffff8110d32b ffffffff8110d4eb (DW_OP_reg3 (rbx))     <<<--- 1
          00237885 v000000000000002 v000000000000000 views at 0023786a for:
                   ffffffff8110d4eb ffffffff8110d50b (DW_OP_reg14 (r14))    <<<--- 2
          0023788c v000000000000000 v000000000000001 views at 0023786c for:
                   ffffffff8110d50b ffffffff8110d7c4 (DW_OP_reg3 (rbx))
          00237893 v000000000000000 v000000000000000 views at 0023786e for:
                   ffffffff8110d806 ffffffff8110d854 (DW_OP_reg3 (rbx))
          0023789a v000000000000000 v000000000000000 views at 00237870 for:
                   ffffffff8110d876 ffffffff8110d88e (DW_OP_reg3 (rbx))
      
      The first entry at 0023787f has [8110d32b, 8110d4eb) (omitting the
      ffffffff at the beginning), and the second one has [8110d4eb, 8110d50b).
      
      Fixes: 2bc3cf57 ("perf annotate-data: Improve debug message with location info")
      Reviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3ab0b8b2
    • Namhyung Kim's avatar
      perf dwarf-aux: Check allowed location expressions when collecting variables · e8bb03ed
      Namhyung Kim authored
      It missed to call check_allowed_ops() in __die_collect_vars_cb() so it
      can take variables with complex location expression incorrectly.
      
      For example, I found some variable has this expression.
      
          015d8df8 ffffffff81aacfb3 (base address)
          015d8e01 v000000000000004 v000000000000000 views at 015d8df2 for:
                   ffffffff81aacfb3 ffffffff81aacfd2 (DW_OP_fbreg: -176; DW_OP_deref;
      						DW_OP_plus_uconst: 332; DW_OP_deref_size: 4;
      						DW_OP_lit1; DW_OP_shra; DW_OP_const1u: 64;
      						DW_OP_minus; DW_OP_stack_value)
          015d8e14 v000000000000000 v000000000000000 views at 015d8df4 for:
                   ffffffff81aacfd2 ffffffff81aacfd7 (DW_OP_reg3 (rbx))
          015d8e19 v000000000000000 v000000000000000 views at 015d8df6 for:
                   ffffffff81aacfd7 ffffffff81aad020 (DW_OP_fbreg: -176; DW_OP_deref;
      						DW_OP_plus_uconst: 332; DW_OP_deref_size: 4;
      						DW_OP_lit1; DW_OP_shra; DW_OP_const1u: 64;
      						DW_OP_minus; DW_OP_stack_value)
          015d8e2c <End of list>
      
      It looks like '((int *)(-176(%rbp) + 332) >> 1) - 64' but the current
      code thought it's just -176(%rbp) and processed the variable incorrectly.
      It should reject such a complex expression if check_allowed_ops()
      doesn't like it. :)
      
      Fixes: 932dcc2c ("perf dwarf-aux: Add die_collect_vars()")
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20240816235840.2754937-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e8bb03ed
  2. 16 Aug, 2024 22 commits