Ian Rogers and Namhyung Kim
83c338369a
libperf cpumap: Make index and nr types unsigned
...
The index into the cpumap array and the number of entries within the
array can never be negative, so let's make them unsigned. This is
prompted by reports that gcc 13 with -O6 is giving a
alloc-size-larger-than errors. The change makes the cpumap changes and
then updates the declaration of index variables throughout perf and
libperf to be unsigned. The two things are hard to separate as
compiler warnings about mixing signed and unsigned types breaks the
build.
Reported-by: Chingbin Li <liqb365@163.com >
Closes: https://lore.kernel.org/lkml/20260212025127.841090-1-liqb365@163.com/
Tested-by: Chingbin Li <liqb365@163.com >
Signed-off-by: Ian Rogers <irogers@google.com >
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
2026-04-01 14:50:53 -07:00
Ian Rogers and Arnaldo Carvalho de Melo
ff8548172f
perf evlist: Special map propagation for tool events that read on 1 CPU
...
Tool events like duration_time don't need a perf_cpu_map that contains
all online CPUs.
Having such a perf_cpu_map causes overheads when iterating between
events for CPU affinity.
During parsing mark events that just read on a single CPU map index as
such, then during map propagation set up the evsel's CPUs and thereby
the evlists accordingly.
The setting cannot be done early in parsing as user CPUs are only fully
known when evlist__create_maps is called.
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Andres Freund <andres@anarazel.de >
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com >
Cc: Dr. David Alan Gilbert <linux@treblig.org >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: James Clark <james.clark@linaro.org >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Thomas Falcon <thomas.falcon@intel.com >
Cc: Thomas Richter <tmricht@linux.ibm.com >
Cc: Yang Li <yang.lee@linux.alibaba.com >
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2026-02-10 09:33:28 -03:00
Ian Rogers and Namhyung Kim
9a711ef3bd
libperf evsel: Factor perf_evsel__exit out of perf_evsel__delete
...
This allows the perf_evsel__exit to be called when the struct
perf_evsel is embedded inside another struct, such as struct evsel in
perf.
Reviewed-by: Thomas Falcon <thomas.falcon@intel.com >
Signed-off-by: Ian Rogers <irogers@google.com >
Tested-by: James Clark <james.clark@linaro.org >
Link: https://lore.kernel.org/r/20250719030517.1990983-8-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
2025-07-24 13:41:35 -07:00
Ian Rogers and Namhyung Kim
6d765f5f7e
libperf evsel: Rename own_cpus to pmu_cpus
...
own_cpus is generally the cpumask from the PMU. Rename to pmu_cpus to
try to make this clearer. Variable rename with no other changes.
Reviewed-by: Thomas Falcon <thomas.falcon@intel.com >
Signed-off-by: Ian Rogers <irogers@google.com >
Tested-by: James Clark <james.clark@linaro.org >
Link: https://lore.kernel.org/r/20250719030517.1990983-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
2025-07-24 13:41:35 -07:00
Ian Rogers and Arnaldo Carvalho de Melo
e8399d34d5
libperf cpumap: Hide/reduce scope of MAX_NR_CPUS
...
Avoid redefinition of MAX_NR_CPUS as a global constant, the original
definition is tools/perf/perf.h.
Reviewed-by: Leo Yan <leo.yan@arm.com >
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Ben Gainey <ben.gainey@arm.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: James Clark <james.clark@linaro.org >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Kan Liang <kan.liang@linux.intel.com >
Cc: Kyle Meyer <kyle.meyer@hpe.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Link: https://lore.kernel.org/r/20241206044035.1062032-4-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2024-12-09 17:52:41 -03:00
Kyle Meyer and Arnaldo Carvalho de Melo
9a1e106550
perf: Increase MAX_NR_CPUS to 4096
...
Systems have surpassed 2048 CPUs. Increase MAX_NR_CPUS to 4096.
Bitmaps declared with MAX_NR_CPUS bits will increase from 256B to 512B,
cpus_runtime will increase from 81960B to 163880B, and max_entries will
increase from 8192B to 16384B.
Reviewed-by: Ian Rogers <irogers@google.com >
Reviewed-by: Leo Yan <leo.yan@arm.com >
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com >
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Ben Gainey <ben.gainey@arm.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: James Clark <james.clark@linaro.org >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Kan Liang <kan.liang@linux.intel.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Link: https://lore.kernel.org/r/20241206044035.1062032-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2024-12-09 17:52:41 -03:00
Ben Gainey and Namhyung Kim
80c281fca2
tools/perf: Correctly calculate sample period for inherited SAMPLE_READ values
...
Sample period calculation in deliver_sample_value is updated to
calculate the per-thread period delta for events that are inherit +
PERF_SAMPLE_READ. When the sampling event has this configuration, the
read_format.id is used with the tid from the sample to lookup the
storage of the previously accumulated counter total before calculating
the delta. All existing valid configurations where read_format.value
represents some global value continue to use just the read_format.id to
locate the storage of the previously accumulated total.
perf_sample_id is modified to support tracking per-thread
values, along with the existing global per-id values. In the
per-thread case, values are stored in a hash by tid within the
perf_sample_id, and are dynamically allocated as the number is not known
ahead of time.
Signed-off-by: Ben Gainey <ben.gainey@arm.com >
Cc: james.clark@arm.com
Link: https://lore.kernel.org/r/20241001121505.1009685-2-ben.gainey@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
2024-10-02 14:58:03 -07:00
Ian Rogers and Namhyung Kim
1947b92464
libperf evlist: Avoid out-of-bounds access
...
Parallel testing appears to show a race between allocating and setting
evsel ids. As there is a bounds check on the xyarray it yields a segv
like:
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==484408==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010
==484408==The signal is caused by a WRITE memory access.
==484408==Hint: address points to the zero page.
#0 0x55cef5d4eff4 in perf_evlist__id_hash tools/lib/perf/evlist.c:256
#1 0x55cef5d4f132 in perf_evlist__id_add tools/lib/perf/evlist.c:274
#2 0x55cef5d4f545 in perf_evlist__id_add_fd tools/lib/perf/evlist.c:315
#3 0x55cef5a1923f in store_evsel_ids util/evsel.c:3130
#4 0x55cef5a19400 in evsel__store_ids util/evsel.c:3147
#5 0x55cef5888204 in __run_perf_stat tools/perf/builtin-stat.c:832
#6 0x55cef5888c06 in run_perf_stat tools/perf/builtin-stat.c:960
#7 0x55cef58932db in cmd_stat tools/perf/builtin-stat.c:2878
...
```
Avoid this crash by early exiting the perf_evlist__id_add_fd and
perf_evlist__id_add is the access is out-of-bounds.
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: Yang Jihong <yangjihong1@huawei.com >
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
Link: https://lore.kernel.org/r/20240229070757.796244-1-irogers@google.com
2024-02-29 13:57:02 -08:00
Ian Rogers and Arnaldo Carvalho de Melo
366efbff58
libperf: Lazily allocate/size mmap event copy
...
The event copy in the mmap is used to have storage to read an event. Not
all users of mmaps read the events, such as perf record. The amount of
buffer was also statically set to PERF_SAMPLE_MAX_SIZE rather than the
amount necessary from the header's event size.
Switch to a model where the event_copy is reallocated if too small to
the event's size. This adds the potential for the event to move, so if a
copy of the event pointer were stored it could be broken. All the
current users do:
while(event = perf_mmap__read_event()) { ... }
and so they would be broken due to the event being overwritten if they
had stored the pointer. Manual inspection and address sanitizer testing
also shows the event pointer not being stored.
Signed-off-by: Ian Rogers <irogers@google.com >
Acked-by: Namhyung Kim <namhyung@kernel.org >
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com >
Cc: Changbin Du <changbin.du@huawei.com >
Cc: Colin Ian King <colin.i.king@gmail.com >
Cc: Dmitrii Dolgov <9erthalion6@gmail.com >
Cc: German Gomez <german.gomez@arm.com >
Cc: Guilherme Amadio <amadio@gentoo.org >
Cc: Huacai Chen <chenhuacai@kernel.org >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: James Clark <james.clark@arm.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: K Prateek Nayak <kprateek.nayak@amd.com >
Cc: Kajol Jain <kjain@linux.ibm.com >
Cc: Kan Liang <kan.liang@linux.intel.com >
Cc: Leo Yan <leo.yan@linaro.org >
Cc: Li Dong <lidong@vivo.com >
Cc: Liam Howlett <liam.howlett@oracle.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org >
Cc: Miguel Ojeda <ojeda@kernel.org >
Cc: Ming Wang <wangming01@loongson.cn >
Cc: Nick Terrell <terrelln@fb.com >
Cc: Paolo Bonzini <pbonzini@redhat.com >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Ravi Bangoria <ravi.bangoria@amd.com >
Cc: Sandipan Das <sandipan.das@amd.com >
Cc: Sean Christopherson <seanjc@google.com >
Cc: Steinar H. Gunderson <sesse@google.com >
Cc: Vincent Whitchurch <vincent.whitchurch@axis.com >
Cc: Wenyu Liu <liuwenyu7@huawei.com >
Cc: Yang Jihong <yangjihong1@huawei.com >
Link: https://lore.kernel.org/r/20231127220902.1315692-3-irogers@google.com
[ Replace two lines with equivalent zfree(&map->event_copy) ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-11-30 19:25:19 -03:00
Ian Rogers and Namhyung Kim
78c32f4cb1
libperf rc_check: Add RC_CHK_EQUAL
...
Comparing pointers with reference count checking is tricky to avoid a
SEGV. Add a convenience macro to simplify and use.
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: K Prateek Nayak <kprateek.nayak@amd.com >
Cc: Ravi Bangoria <ravi.bangoria@amd.com >
Cc: Sandipan Das <sandipan.das@amd.com >
Cc: Anshuman Khandual <anshuman.khandual@arm.com >
Cc: German Gomez <german.gomez@arm.com >
Cc: James Clark <james.clark@arm.com >
Cc: Nick Terrell <terrelln@fb.com >
Cc: Sean Christopherson <seanjc@google.com >
Cc: Changbin Du <changbin.du@huawei.com >
Cc: liuwenyu <liuwenyu7@huawei.com >
Cc: Yang Jihong <yangjihong1@huawei.com >
Cc: Masami Hiramatsu <mhiramat@kernel.org >
Cc: Miguel Ojeda <ojeda@kernel.org >
Cc: Song Liu <song@kernel.org >
Cc: Leo Yan <leo.yan@linaro.org >
Cc: Kajol Jain <kjain@linux.ibm.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Kan Liang <kan.liang@linux.intel.com >
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com >
Cc: Yanteng Si <siyanteng@loongson.cn >
Cc: Liam Howlett <liam.howlett@oracle.com >
Cc: Paolo Bonzini <pbonzini@redhat.com >
Link: https://lore.kernel.org/r/20231024222353.3024098-5-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
2023-10-25 13:37:22 -07:00
Ian Rogers and Namhyung Kim
75265320d2
libperf rc_check: Make implicit enabling work for GCC
...
Make the implicit REFCOUNT_CHECKING robust to when building with GCC.
Fixes: 9be6ab181b ("libperf rc_check: Enable implicitly with sanitizers")
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: K Prateek Nayak <kprateek.nayak@amd.com >
Cc: Ravi Bangoria <ravi.bangoria@amd.com >
Cc: Sandipan Das <sandipan.das@amd.com >
Cc: Anshuman Khandual <anshuman.khandual@arm.com >
Cc: German Gomez <german.gomez@arm.com >
Cc: James Clark <james.clark@arm.com >
Cc: Nick Terrell <terrelln@fb.com >
Cc: Sean Christopherson <seanjc@google.com >
Cc: Changbin Du <changbin.du@huawei.com >
Cc: liuwenyu <liuwenyu7@huawei.com >
Cc: Yang Jihong <yangjihong1@huawei.com >
Cc: Masami Hiramatsu <mhiramat@kernel.org >
Cc: Miguel Ojeda <ojeda@kernel.org >
Cc: Song Liu <song@kernel.org >
Cc: Leo Yan <leo.yan@linaro.org >
Cc: Kajol Jain <kjain@linux.ibm.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Kan Liang <kan.liang@linux.intel.com >
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com >
Cc: Yanteng Si <siyanteng@loongson.cn >
Cc: Liam Howlett <liam.howlett@oracle.com >
Cc: Paolo Bonzini <pbonzini@redhat.com >
Link: https://lore.kernel.org/r/20231024222353.3024098-4-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
2023-10-25 13:36:50 -07:00
Yang Jihong and Arnaldo Carvalho de Melo
f6ff1c7604
perf evlist: Add perf_evlist__go_system_wide() helper
...
For dummy events that keep tracking, we may need to modify its cpu_maps.
For example, change the cpu_maps to record sideband events for all CPUS.
Add perf_evlist__go_system_wide() helper to support this scenario.
Signed-off-by: Yang Jihong <yangjihong1@huawei.com >
Acked-by: Adrian Hunter <adrian.hunter@intel.com >
Tested-by: Ravi Bangoria <ravi.bangoria@amd.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Anshuman Khandual <anshuman.khandual@arm.com >
Cc: Ian Rogers <irogers@google.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: James Clark <james.clark@arm.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Kan Liang <kan.liang@linux.intel.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Thomas Richter <tmricht@linux.ibm.com >
Link: https://lore.kernel.org/r/20230904023340.12707-2-yangjihong1@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-09-12 17:31:22 -03:00
Ian Rogers and Arnaldo Carvalho de Melo
ef91871c96
perf evlist: Propagate user CPU maps intersecting core PMU maps
...
The CPU map for a non-core PMU gives a default CPU value for
perf_event_open. For core PMUs the CPU map lists all CPUs the evsel
may be opened on. If there are >1 core PMU, the CPU maps will list the
CPUs for that core PMU, but the user_requested_cpus may contain CPUs
that are invalid for the PMU and cause perf_event_open to fail. To
avoid this, when propagating the CPU map for core PMUs intersect it
with the CPU map of the PMU (the evsel's "own_cpus").
Add comments to __perf_evlist__propagate_maps to explain its somewhat
complex behavior. Fix the related comments for system_wide in struct
perf_evsel.
Reviewed-by: Kan Liang <kan.liang@linux.intel.com >
Signed-off-by: Ian 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: Athira Rajeev <atrajeev@linux.vnet.ibm.com >
Cc: Dmitrii Dolgov <9erthalion6@gmail.com >
Cc: Huacai Chen <chenhuacai@kernel.org >
Cc: Ingo Molnar <mingo@redhat.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: Kajol Jain <kjain@linux.ibm.com >
Cc: Kang Minchul <tegongkang@gmail.com >
Cc: Leo Yan <leo.yan@linaro.org >
Cc: Madhavan Srinivasan <maddy@linux.ibm.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Mike Leach <mike.leach@linaro.org >
Cc: Ming Wang <wangming01@loongson.cn >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Ravi Bangoria <ravi.bangoria@amd.com >
Cc: Rob Herring <robh@kernel.org >
Cc: Sandipan Das <sandipan.das@amd.com >
Cc: Sean Christopherson <seanjc@google.com >
Cc: Suzuki Poulouse <suzuki.poulose@arm.com >
Cc: Thomas Richter <tmricht@linux.ibm.com >
Cc: Will Deacon <will@kernel.org >
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com >
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230527072210.2900565-9-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-05-27 09:38:39 -03:00
Ian Rogers and Arnaldo Carvalho de Melo
1578e63d3a
perf evsel: Add is_pmu_core inorder to interpret own_cpus
...
The behaviour of handling cpu maps varies for core and other PMUs. For
core PMUs the cpu map lists all valid CPUs, whereas for other PMUs the
map is the default CPU. Add a flag in the evsel to indicate if a PMU
is core to help with later interpreting of the cpu maps and populate
it when the evsel is created during parsing. When propagating cpu
maps, core PMUs should intersect the cpu map of the PMU with the user
requested one.
Reviewed-by: Kan Liang <kan.liang@linux.intel.com >
Signed-off-by: Ian 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: Athira Rajeev <atrajeev@linux.vnet.ibm.com >
Cc: Dmitrii Dolgov <9erthalion6@gmail.com >
Cc: Huacai Chen <chenhuacai@kernel.org >
Cc: Ingo Molnar <mingo@redhat.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: Kajol Jain <kjain@linux.ibm.com >
Cc: Kang Minchul <tegongkang@gmail.com >
Cc: Leo Yan <leo.yan@linaro.org >
Cc: Madhavan Srinivasan <maddy@linux.ibm.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Mike Leach <mike.leach@linaro.org >
Cc: Ming Wang <wangming01@loongson.cn >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Ravi Bangoria <ravi.bangoria@amd.com >
Cc: Rob Herring <robh@kernel.org >
Cc: Sandipan Das <sandipan.das@amd.com >
Cc: Sean Christopherson <seanjc@google.com >
Cc: Suzuki Poulouse <suzuki.poulose@arm.com >
Cc: Thomas Richter <tmricht@linux.ibm.com >
Cc: Will Deacon <will@kernel.org >
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com >
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230527072210.2900565-7-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-05-27 09:38:10 -03:00
Ian Rogers and Arnaldo Carvalho de Melo
9be6ab181b
libperf rc_check: Enable implicitly with sanitizers
...
If using leak sanitizer then implicitly enable reference count checking.
Signed-off-by: Ian 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/20230420171812.561603-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-04-20 15:12:02 -03:00
Ian Rogers and Arnaldo Carvalho de Melo
da885a0e5e
perf cpumap: Add reference count checking
...
Enabled when REFCNT_CHECKING is defined. The change adds a memory
allocated pointer that is interposed between the reference counted cpu
map at a get and freed by a put. The pointer replaces the original
perf_cpu_map struct, so use of the perf_cpu_map via APIs remains
unchanged. Any use of the cpu map without the API requires two versions,
handled via the RC_CHK_ACCESS macro.
This change is intended to catch:
- use after put: using a cpumap after you have put it will cause a
segv.
- unbalanced puts: two puts for a get will result in a double free
that can be captured and reported by tools like address sanitizer,
including with the associated stack traces of allocation and frees.
- missing puts: if a put is missing then the get turns into a memory
leak that can be reported by leak sanitizer, including the stack
trace at the point the get occurs.
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Andrew Morton <akpm@linux-foundation.org >
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com >
Cc: Darren Hart <dvhart@infradead.org >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Cc: Dmitriy Vyukov <dvyukov@google.com >
Cc: Eric Dumazet <edumazet@google.com >
Cc: German Gomez <german.gomez@arm.com >
Cc: Hao Luo <haoluo@google.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: James Clark <james.clark@arm.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: John Garry <john.g.garry@oracle.com >
Cc: Kajol Jain <kjain@linux.ibm.com >
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: Masami Hiramatsu <mhiramat@kernel.org >
Cc: Miaoqian Lin <linmq006@gmail.com >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Riccardo Mancini <rickyman7@gmail.com >
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com >
Cc: Song Liu <song@kernel.org >
Cc: Stephen Brennan <stephen.s.brennan@oracle.com >
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org >
Cc: Thomas Gleixner <tglx@linutronix.de >
Cc: Thomas Richter <tmricht@linux.ibm.com >,
Cc: Yury Norov <yury.norov@gmail.com >
Link: https://lore.kernel.org/lkml/20230407230405.2931830-3-irogers@google.com
[ Extracted from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-04-17 16:50:02 -03:00
Ian Rogers and Arnaldo Carvalho de Melo
a9b867f68e
libperf: Add reference count checking macros
...
The macros serve as a way to debug use of a reference counted struct.
The macros add a memory allocated pointer that is interposed between
the reference counted original struct at a get and freed by a put.
The pointer replaces the original struct, so use of the struct name
via APIs remains unchanged.
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Andrew Morton <akpm@linux-foundation.org >
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com >
Cc: Darren Hart <dvhart@infradead.org >
Cc: Davidlohr Bueso <dave@stgolabs.net >
Cc: Dmitriy Vyukov <dvyukov@google.com >
Cc: Eric Dumazet <edumazet@google.com >
Cc: German Gomez <german.gomez@arm.com >
Cc: Hao Luo <haoluo@google.com >
Cc: James Clark <james.clark@arm.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: John Garry <john.g.garry@oracle.com >
Cc: Kajol Jain <kjain@linux.ibm.com >
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: Masami Hiramatsu <mhiramat@kernel.org >
Cc: Miaoqian Lin <linmq006@gmail.com >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: Riccardo Mancini <rickyman7@gmail.com >
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com >
Cc: Song Liu <song@kernel.org >
Cc: Stephane Eranian <eranian@google.com >
Cc: Stephen Brennan <stephen.s.brennan@oracle.com >
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org >
Cc: Thomas Gleixner <tglx@linutronix.de >
Cc: Thomas Richter <tmricht@linux.ibm.com >
Cc: Yury Norov <yury.norov@gmail.com >
Link: http://lore.kernel.org/lkml/20230407230405.2931830-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-04-17 15:53:01 -03:00
Arnaldo Carvalho de Melo
4121234a32
libperf: Add perf_cpu_map__refcnt() interanl accessor to use in the maps test
...
To remove one more direct access to 'struct perf_cpu_map' so that we can
intercept accesses to its instantiations and refcount check it to catch
use after free, etc.
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com >
Cc: Dmitriy Vyukov <dvyukov@google.com >
Cc: Ian Rogers <irogers@google.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Riccardo Mancini <rickyman7@gmail.com >
Cc: Stephane Eranian <eranian@google.com >
Cc: Stephen Brennan <stephen.s.brennan@oracle.com >
Link: https://lore.kernel.org/lkml/ZD1qdYjG+DL6KOfP@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-04-17 15:52:36 -03:00
Arnaldo Carvalho de Melo
b277851417
libperf: Add a perf_cpu_map__set_nr() available as an internal function for tools/perf to use
...
We'll need to reference count check 'struct perf_cpu_map', so wrap
accesses to its internal state to allow intercepting accesses to its
instances.
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com >
Cc: Dmitriy Vyukov <dvyukov@google.com >
Cc: Ian Rogers <irogers@google.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Riccardo Mancini <rickyman7@gmail.com >
Cc: Stephane Eranian <eranian@google.com >
Cc: Stephen Brennan <stephen.s.brennan@oracle.com >
Link: https://lore.kernel.org/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-04-12 14:53:35 -03:00
Ian Rogers and Arnaldo Carvalho de Melo
1f94479edb
libperf: Make perf_cpu_map__alloc() available as an internal function for tools/perf to use
...
We had the open coded equivalent in perf_cpu_map__empty_new(), so reuse
what is in libperf.
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com >
Cc: Dmitriy Vyukov <dvyukov@google.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: Riccardo Mancini <rickyman7@gmail.com >
Cc: Stephane Eranian <eranian@google.com >
Cc: Stephen Brennan <stephen.s.brennan@oracle.com >
Link: https://lore.kernel.org/lkml/20230407230405.2931830-3-irogers@google.com
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-04-12 14:44:24 -03:00
Ian Rogers and Arnaldo Carvalho de Melo
9d2dc632e0
perf evlist: Remove nr_groups
...
Maintaining the number of groups during event parsing is problematic
and since changing to sort/regroup events can only be computed by a
linear pass over the evlist. As the value is generally only used in
tests, rather than hold it in a variable compute it by passing over
the evlist when necessary.
This change highlights that libpfm's counting of groups with a single
entry disagreed with regular event parsing. The libpfm tests are
updated accordingly.
Signed-off-by: Ian Rogers <irogers@google.com >
Cc: Adrian Hunter <adrian.hunter@intel.com >
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com >
Cc: Florian Fischer <florian.fischer@muhq.space >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: James Clark <james.clark@arm.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: John Garry <john.g.garry@oracle.com >
Cc: Kajol Jain <kjain@linux.ibm.com >
Cc: Kan Liang <kan.liang@linux.intel.com >
Cc: Kim Phillips <kim.phillips@amd.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: Ravi Bangoria <ravi.bangoria@amd.com >
Cc: Sean Christopherson <seanjc@google.com >
Cc: Steinar H. Gunderson <sesse@google.com >
Cc: Stephane Eranian <eranian@google.com >
Cc: Suzuki Poulouse <suzuki.poulose@arm.com >
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com >
Link: https://lore.kernel.org/r/20230312021543.3060328-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2023-03-13 17:42:27 -03:00
Namhyung Kim and Arnaldo Carvalho de Melo
7e2450bb75
libperf: Propagate maps only if necessary
...
The current code propagate evsel's cpu map settings to evlist when it's
added to an evlist. But the evlist->all_cpus and each evsel's cpus will
be updated in perf_evlist__set_maps() later. No need to do it before
evlist's cpus are set actually.
In fact it discards this intermediate all_cpus maps at the beginning
of perf_evlist__set_maps(). Let's not do this. It's only needed when
an evsel is added after the evlist cpu/thread maps are set.
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com >
Signed-off-by: Namhyung Kim <namhyung@kernel.org >
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: Leo Yan <leo.yan@linaro.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Link: https://lore.kernel.org/r/20221003204647.1481128-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2022-10-06 08:03:53 -03:00
Adrian Hunter and Arnaldo Carvalho de Melo
b47bb18661
perf tools: Add machine_pid and vcpu to id_index
...
When injecting events from a guest perf.data file, the events will have
separate sample ID numbers. These ID numbers can then be used to determine
which machine an event belongs to. To facilitate that, add machine_pid and
vcpu to id_index records. For backward compatibility, these are added at
the end of the record, and the length of the record is used to determine
if they are present or not.
Note, this is needed because the events from a guest perf.data file contain
the pid/tid of the process running at that time inside the VM not the
pid/tid of the (QEMU) hypervisor thread. So a way is needed to relate
guest events back to the guest machine and VCPU, and using sample ID
numbers for that is relatively simple and convenient.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com >
Cc: Andi Kleen <ak@linux.intel.com >
Cc: Ian Rogers <irogers@google.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Namhyung Kim <namhyung@kernel.org >
Cc: kvm@vger.kernel.org
Link: https://lore.kernel.org/r/20220711093218.10967-11-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2022-07-20 11:07:58 -03:00
Adrian Hunter and Arnaldo Carvalho de Melo
f5fb6d4efe
libperf evsel: Add comments for booleans
...
Add comments for 'system_wide' and 'requires_cpu' booleans
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com >
Acked-by: Ian Rogers <irogers@google.com >
Acked-by: Namhyung Kim <namhyung@kernel.org >
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com >
Cc: Ian Rogers <irogers@google.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Leo Yan <leo.yan@linaro.org >
Link: https://lore.kernel.org/r/20220524075436.29144-14-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2022-05-26 12:36:57 -03:00
Adrian Hunter and Arnaldo Carvalho de Melo
d3345fecf9
perf stat: Add requires_cpu flag for uncore
...
Uncore events require a CPU i.e. it cannot be -1.
The evsel system_wide flag is intended for events that should be on every
CPU, which does not make sense for uncore events because uncore events do
not map one-to-one with CPUs.
These 2 requirements are not exactly the same, so introduce a new flag
'requires_cpu' for the uncore case.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com >
Acked-by: Ian Rogers <irogers@google.com >
Acked-by: Namhyung Kim <namhyung@kernel.org >
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com >
Cc: Jiri Olsa <jolsa@kernel.org >
Cc: Leo Yan <leo.yan@linaro.org >
Link: https://lore.kernel.org/r/20220524075436.29144-13-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com >
2022-05-26 12:36:57 -03:00