License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-17 18:23:08 +00:00
|
|
|
#include <inttypes.h>
|
2017-04-19 23:57:47 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2013-01-24 15:10:38 +00:00
|
|
|
#include "builtin.h"
|
|
|
|
|
2015-12-15 15:39:39 +00:00
|
|
|
#include <subcmd/parse-options.h>
|
2020-11-06 09:48:51 +00:00
|
|
|
#include "util/auxtrace.h"
|
2013-01-24 15:10:38 +00:00
|
|
|
#include "util/trace-event.h"
|
|
|
|
#include "util/tool.h"
|
|
|
|
#include "util/session.h"
|
2013-10-15 14:27:32 +00:00
|
|
|
#include "util/data.h"
|
2019-08-30 18:09:54 +00:00
|
|
|
#include "util/map_symbol.h"
|
2016-02-15 08:34:34 +00:00
|
|
|
#include "util/mem-events.h"
|
2016-02-15 08:34:35 +00:00
|
|
|
#include "util/debug.h"
|
2019-08-30 14:11:01 +00:00
|
|
|
#include "util/dso.h"
|
2019-01-27 12:42:37 +00:00
|
|
|
#include "util/map.h"
|
2017-04-20 00:34:35 +00:00
|
|
|
#include "util/symbol.h"
|
2023-05-27 07:22:03 +00:00
|
|
|
#include "util/pmus.h"
|
2022-10-26 20:24:27 +00:00
|
|
|
#include "util/sample.h"
|
2024-07-31 23:55:04 +00:00
|
|
|
#include "util/sort.h"
|
2022-03-25 09:20:32 +00:00
|
|
|
#include "util/string2.h"
|
2023-04-10 16:25:10 +00:00
|
|
|
#include "util/util.h"
|
2019-08-22 07:20:49 +00:00
|
|
|
#include <linux/err.h>
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2014-12-17 15:23:55 +00:00
|
|
|
#define MEM_OPERATION_LOAD 0x1
|
|
|
|
#define MEM_OPERATION_STORE 0x2
|
2013-01-24 15:10:38 +00:00
|
|
|
|
|
|
|
struct perf_mem {
|
|
|
|
struct perf_tool tool;
|
2024-07-31 23:55:04 +00:00
|
|
|
const char *input_name;
|
|
|
|
const char *sort_key;
|
2013-01-24 15:10:38 +00:00
|
|
|
bool hide_unresolved;
|
|
|
|
bool dump_raw;
|
perf mem: Support using -f to override perf.data file ownership
Enable perf mem to use perf.data when it is not owned by current user or
root.
Example:
# perf mem -t load record ls
# chown Yunlong.Song:Yunlong.Song perf.data
# ls -al perf.data
-rw------- 1 Yunlong.Song Yunlong.Song 16392 Apr 2 14:34 perf.data
# id
uid=0(root) gid=0(root) groups=0(root),64(pkcs11)
Before this patch:
# perf mem -D report
File perf.data not owned by current user or root (use -f to override)
# perf mem -D -f report
Error: unknown switch `f'
usage: perf mem [<options>] {record|report}
-t, --type <type> memory operations(load,store) Default load,store
-D, --dump-raw-samples
dump raw samples in ASCII
-U, --hide-unresolved
Only display entries resolved to a symbol
-i, --input <file> input file name
-C, --cpu <cpu> list of cpus to profile
-x, --field-separator <separator>
separator for columns, no spaces will be added
between columns '.' is reserved.
As shown above, the -f option does not work at all.
After this patch:
# perf mem -D report
File perf.data not owned by current user or root (use -f to override)
# perf mem -D -f report
# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL
39095 39095 0xffffffff81127e40 0x016ffff887f45148338 8 0x68100142
/proc/kcore:perf_event_aux
39095 39095 0xffffffff8100a3fe 0xffff89007f8cb7d0 6 0x68100142
/proc/kcore:native_sched_clock
39095 39095 0xffffffff81309139 0xffff88bf44c9ded8 6 0x68100142
/proc/kcore:acpi_map_lookup
39095 39095 0xffffffff810f8c4c 0xffff89007f8ccd88 6 0x68100142
/proc/kcore:rcu_nmi_exit
39095 39095 0xffffffff81136346 0xffff88fea995dd50 6 0x68100142
/proc/kcore:unlock_page
39095 39095 0xffffffff812a64a2 0xffff88fea995dcc8 6 0x68100142
/proc/kcore:half_md4_transform
39095 39095 0x7f0cf877c7e9 0x25dfb94 6 0x68100142
/lib64/libc-2.19.so:__readdir64
39095 39095 0x7f0cf87575a3 0x7f0cf9163731 6 0x68100142
/lib64/libc-2.19.so:__strcoll_l
39095 39095 0xffffffff8116910e 0xffffea01c1bfbd50 23 0x68100242
/proc/kcore:page_remove_rmap
As shown above, the -f option really works now.
Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1427982439-27388-7-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-02 13:47:15 +00:00
|
|
|
bool force;
|
2017-08-29 17:11:10 +00:00
|
|
|
bool phys_addr;
|
perf mem: Support data page size
Add option --data-page-size in "perf mem" to record/report data page
size.
Here are some examples:
# perf mem --phys-data --data-page-size report -D
# PID, TID, IP, ADDR, PHYS ADDR, DATA PAGE SIZE, LOCAL WEIGHT, DSRC, SYMBOL
20134 20134 0xffffffffb5bd2fd0 0x016ffff9a274e96a308 0x000000044e96a308 4K 1168 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:perf_ctx_unlock
20134 20134 0xffffffffb63f645c 0xffffffffb752b814 0xcfb52b814 2M 225 0x26a100142 /lib/modules/4.18.0-rc7+/build/vmlinux:_raw_spin_lock
20134 20134 0xffffffffb660300c 0xfffffe00016b8bb0 0x0 4K 0 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:__x86_indirect_thunk_rax
#
# perf mem --phys-data --data-page-size report --stdio
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 5K of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 281234
# Sort order :
# mem,sym,dso,symbol_daddr,dso_daddr,tlb,locked,phys_daddr,data_page_size
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol Data Object TLB access Locked Data Physical Address Data Page Size
# ........ ....... ............. ............................ ................ ...................... ........... ............ ...... ...................... ..............
28.54% 1826 L1 or L1 hit [k] __x86_indirect_thunk_rax [kernel.vmlinux] [k] 0xffffb0df31b0ff28 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
6.02% 256 L1 or L1 hit [.] touch_buffer dtlb [.] 0x00007ffd50109da8 [stack] L1 or L2 hit No [.] 0x000000042454ada8 4K
3.23% 5 L1 or L1 hit [k] clear_huge_page [kernel.vmlinux] [k] 0xffff9a2753b8ce60 [unknown] L1 or L2 hit No [k] 0x0000000453b8ce60 2M
2.98% 4 L1 or L1 hit [k] clear_page_erms [kernel.vmlinux] [k] 0xffffb0df31b0fd00 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210105195752.43489-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-05 19:57:48 +00:00
|
|
|
bool data_page_size;
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
bool all_kernel;
|
|
|
|
bool all_user;
|
2024-07-31 23:55:05 +00:00
|
|
|
bool data_type;
|
2014-12-17 16:53:27 +00:00
|
|
|
int operation;
|
2013-01-24 15:10:38 +00:00
|
|
|
const char *cpu_list;
|
|
|
|
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
|
|
|
|
};
|
|
|
|
|
2016-02-15 08:34:35 +00:00
|
|
|
static int parse_record_events(const struct option *opt,
|
|
|
|
const char *str, int unset __maybe_unused)
|
|
|
|
{
|
2024-09-05 17:07:37 +00:00
|
|
|
struct perf_mem *mem = (struct perf_mem *)opt->value;
|
2024-01-23 18:50:31 +00:00
|
|
|
struct perf_pmu *pmu;
|
|
|
|
|
|
|
|
pmu = perf_mem_events_find_pmu();
|
|
|
|
if (!pmu) {
|
|
|
|
pr_err("failed: there is no PMU that supports perf mem\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2016-02-15 08:34:35 +00:00
|
|
|
|
2020-05-07 22:06:04 +00:00
|
|
|
if (!strcmp(str, "list")) {
|
2024-01-23 18:50:31 +00:00
|
|
|
perf_pmu__mem_events_list(pmu);
|
2020-05-07 22:06:04 +00:00
|
|
|
exit(0);
|
2016-02-15 08:34:35 +00:00
|
|
|
}
|
2024-01-23 18:50:31 +00:00
|
|
|
if (perf_pmu__mem_events_parse(pmu, str))
|
2020-05-07 22:06:04 +00:00
|
|
|
exit(-1);
|
2016-02-15 08:34:35 +00:00
|
|
|
|
2020-05-07 22:06:04 +00:00
|
|
|
mem->operation = 0;
|
|
|
|
return 0;
|
2016-02-15 08:34:35 +00:00
|
|
|
}
|
|
|
|
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
static int __cmd_record(int argc, const char **argv, struct perf_mem *mem,
|
|
|
|
const struct option *options)
|
2013-01-24 15:10:38 +00:00
|
|
|
{
|
2024-01-23 18:50:35 +00:00
|
|
|
int rec_argc, i = 0, j;
|
2021-05-27 00:16:08 +00:00
|
|
|
int start, end;
|
2013-01-24 15:10:38 +00:00
|
|
|
const char **rec_argv;
|
|
|
|
int ret;
|
2020-11-06 09:48:46 +00:00
|
|
|
struct perf_mem_event *e;
|
2024-01-23 18:50:31 +00:00
|
|
|
struct perf_pmu *pmu;
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
const char * const record_usage[] = {
|
|
|
|
"perf mem record [<options>] [<command>]",
|
|
|
|
"perf mem record [<options>] -- <command> [<options>]",
|
|
|
|
NULL
|
2016-02-15 08:34:35 +00:00
|
|
|
};
|
|
|
|
|
2024-01-23 18:50:31 +00:00
|
|
|
pmu = perf_mem_events_find_pmu();
|
|
|
|
if (!pmu) {
|
|
|
|
pr_err("failed: no PMU supports the memory events\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-09-05 17:07:35 +00:00
|
|
|
if (perf_pmu__mem_events_init()) {
|
2020-11-06 09:48:49 +00:00
|
|
|
pr_err("failed: memory events not supported\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
argc = parse_options(argc, argv, options, record_usage,
|
2018-04-06 20:38:09 +00:00
|
|
|
PARSE_OPT_KEEP_UNKNOWN);
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2023-05-27 07:21:59 +00:00
|
|
|
/* Max number of arguments multiplied by number of PMUs that can support them. */
|
2024-01-23 18:50:36 +00:00
|
|
|
rec_argc = argc + 9 * (perf_pmu__mem_events_num_mem_pmus(pmu) + 1);
|
2021-05-27 00:16:07 +00:00
|
|
|
|
2022-10-04 20:02:11 +00:00
|
|
|
if (mem->cpu_list)
|
|
|
|
rec_argc += 2;
|
|
|
|
|
2013-01-24 15:10:38 +00:00
|
|
|
rec_argv = calloc(rec_argc + 1, sizeof(char *));
|
|
|
|
if (!rec_argv)
|
|
|
|
return -1;
|
|
|
|
|
2014-12-17 15:23:55 +00:00
|
|
|
rec_argv[i++] = "record";
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2024-01-23 18:50:31 +00:00
|
|
|
e = perf_pmu__mem_events_ptr(pmu, PERF_MEM_EVENTS__LOAD_STORE);
|
perf mem: Support new memory event PERF_MEM_EVENTS__LOAD_STORE
On the architectures with perf memory profiling, two types of hardware
events have been supported: load and store; if want to profile memory
for both load and store operations, the tool will use these two events
at the same time, the usage is:
# perf mem record -t load,store -- uname
But this cannot be applied for AUX tracing event, the same PMU event can
be used to only trace memory load, or only memory store, or trace for
both memory load and store.
This patch introduces a new event PERF_MEM_EVENTS__LOAD_STORE, which is
used to support the event which can record both memory load and store
operations.
When user specifies memory operation type as 'load,store', or doesn't
set type so use 'load,store' as default, if the arch supports the event
PERF_MEM_EVENTS__LOAD_STORE, the tool will convert the required
operations to this single event; otherwise, if the arch doesn't support
PERF_MEM_EVENTS__LOAD_STORE, the tool rolls back to enable both events
PERF_MEM_EVENTS__LOAD and PERF_MEM_EVENTS__STORE, which keeps the same
behaviour with before.
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20201106094853.21082-4-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-11-06 09:48:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The load and store operations are required, use the event
|
|
|
|
* PERF_MEM_EVENTS__LOAD_STORE if it is supported.
|
|
|
|
*/
|
|
|
|
if (e->tag &&
|
|
|
|
(mem->operation & MEM_OPERATION_LOAD) &&
|
|
|
|
(mem->operation & MEM_OPERATION_STORE)) {
|
perf mem: Fix missed p-core mem events on ADL and RPL
The p-core mem events are missed when launching 'perf mem record' on ADL
and RPL.
root@number:~# perf mem record sleep 1
Memory events are enabled on a subset of CPUs: 16-27
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.032 MB perf.data ]
root@number:~# perf evlist
cpu_atom/mem-loads,ldlat=30/P
cpu_atom/mem-stores/P
dummy:u
A variable 'record' in the 'struct perf_mem_event' is to indicate
whether a mem event in a mem_events[] should be recorded. The current
code only configure the variable for the first eligible PMU.
It's good enough for a non-hybrid machine or a hybrid machine which has
the same mem_events[].
However, if a different mem_events[] is used for different PMUs on a
hybrid machine, e.g., ADL or RPL, the 'record' for the second PMU never
get a chance to be set.
The mem_events[] of the second PMU are always ignored.
'perf mem' doesn't support the per-PMU configuration now. A per-PMU
mem_events[] 'record' variable doesn't make sense. Make it global.
That could also avoid searching for the per-PMU mem_events[] via
perf_pmu__mem_events_ptr every time.
Committer testing:
root@number:~# perf evlist -g
cpu_atom/mem-loads,ldlat=30/P
cpu_atom/mem-stores/P
{cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}
cpu_core/mem-stores/P
dummy:u
root@number:~#
The :S for '{cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}' is
not being added by 'perf evlist -g', to be checked.
Fixes: abbdd79b786e036e ("perf mem: Clean up perf_mem_events__name()")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Closes: https://lore.kernel.org/lkml/Zthu81fA3kLC2CS2@x1/
Link: https://lore.kernel.org/r/20240905170737.4070743-2-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-09-05 17:07:36 +00:00
|
|
|
perf_mem_record[PERF_MEM_EVENTS__LOAD_STORE] = true;
|
2022-10-06 15:39:42 +00:00
|
|
|
rec_argv[i++] = "-W";
|
perf mem: Support new memory event PERF_MEM_EVENTS__LOAD_STORE
On the architectures with perf memory profiling, two types of hardware
events have been supported: load and store; if want to profile memory
for both load and store operations, the tool will use these two events
at the same time, the usage is:
# perf mem record -t load,store -- uname
But this cannot be applied for AUX tracing event, the same PMU event can
be used to only trace memory load, or only memory store, or trace for
both memory load and store.
This patch introduces a new event PERF_MEM_EVENTS__LOAD_STORE, which is
used to support the event which can record both memory load and store
operations.
When user specifies memory operation type as 'load,store', or doesn't
set type so use 'load,store' as default, if the arch supports the event
PERF_MEM_EVENTS__LOAD_STORE, the tool will convert the required
operations to this single event; otherwise, if the arch doesn't support
PERF_MEM_EVENTS__LOAD_STORE, the tool rolls back to enable both events
PERF_MEM_EVENTS__LOAD and PERF_MEM_EVENTS__STORE, which keeps the same
behaviour with before.
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20201106094853.21082-4-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-11-06 09:48:47 +00:00
|
|
|
} else {
|
perf mem: Fix missed p-core mem events on ADL and RPL
The p-core mem events are missed when launching 'perf mem record' on ADL
and RPL.
root@number:~# perf mem record sleep 1
Memory events are enabled on a subset of CPUs: 16-27
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.032 MB perf.data ]
root@number:~# perf evlist
cpu_atom/mem-loads,ldlat=30/P
cpu_atom/mem-stores/P
dummy:u
A variable 'record' in the 'struct perf_mem_event' is to indicate
whether a mem event in a mem_events[] should be recorded. The current
code only configure the variable for the first eligible PMU.
It's good enough for a non-hybrid machine or a hybrid machine which has
the same mem_events[].
However, if a different mem_events[] is used for different PMUs on a
hybrid machine, e.g., ADL or RPL, the 'record' for the second PMU never
get a chance to be set.
The mem_events[] of the second PMU are always ignored.
'perf mem' doesn't support the per-PMU configuration now. A per-PMU
mem_events[] 'record' variable doesn't make sense. Make it global.
That could also avoid searching for the per-PMU mem_events[] via
perf_pmu__mem_events_ptr every time.
Committer testing:
root@number:~# perf evlist -g
cpu_atom/mem-loads,ldlat=30/P
cpu_atom/mem-stores/P
{cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}
cpu_core/mem-stores/P
dummy:u
root@number:~#
The :S for '{cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}' is
not being added by 'perf evlist -g', to be checked.
Fixes: abbdd79b786e036e ("perf mem: Clean up perf_mem_events__name()")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Closes: https://lore.kernel.org/lkml/Zthu81fA3kLC2CS2@x1/
Link: https://lore.kernel.org/r/20240905170737.4070743-2-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-09-05 17:07:36 +00:00
|
|
|
if (mem->operation & MEM_OPERATION_LOAD)
|
|
|
|
perf_mem_record[PERF_MEM_EVENTS__LOAD] = true;
|
|
|
|
|
|
|
|
if (mem->operation & MEM_OPERATION_STORE)
|
|
|
|
perf_mem_record[PERF_MEM_EVENTS__STORE] = true;
|
2020-11-06 09:48:46 +00:00
|
|
|
}
|
2016-08-11 08:50:57 +00:00
|
|
|
|
perf mem: Fix missed p-core mem events on ADL and RPL
The p-core mem events are missed when launching 'perf mem record' on ADL
and RPL.
root@number:~# perf mem record sleep 1
Memory events are enabled on a subset of CPUs: 16-27
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.032 MB perf.data ]
root@number:~# perf evlist
cpu_atom/mem-loads,ldlat=30/P
cpu_atom/mem-stores/P
dummy:u
A variable 'record' in the 'struct perf_mem_event' is to indicate
whether a mem event in a mem_events[] should be recorded. The current
code only configure the variable for the first eligible PMU.
It's good enough for a non-hybrid machine or a hybrid machine which has
the same mem_events[].
However, if a different mem_events[] is used for different PMUs on a
hybrid machine, e.g., ADL or RPL, the 'record' for the second PMU never
get a chance to be set.
The mem_events[] of the second PMU are always ignored.
'perf mem' doesn't support the per-PMU configuration now. A per-PMU
mem_events[] 'record' variable doesn't make sense. Make it global.
That could also avoid searching for the per-PMU mem_events[] via
perf_pmu__mem_events_ptr every time.
Committer testing:
root@number:~# perf evlist -g
cpu_atom/mem-loads,ldlat=30/P
cpu_atom/mem-stores/P
{cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}
cpu_core/mem-stores/P
dummy:u
root@number:~#
The :S for '{cpu_core/mem-loads-aux/,cpu_core/mem-loads,ldlat=30/}' is
not being added by 'perf evlist -g', to be checked.
Fixes: abbdd79b786e036e ("perf mem: Clean up perf_mem_events__name()")
Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Closes: https://lore.kernel.org/lkml/Zthu81fA3kLC2CS2@x1/
Link: https://lore.kernel.org/r/20240905170737.4070743-2-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-09-05 17:07:36 +00:00
|
|
|
if (perf_mem_record[PERF_MEM_EVENTS__LOAD])
|
2014-12-17 15:23:55 +00:00
|
|
|
rec_argv[i++] = "-W";
|
|
|
|
|
|
|
|
rec_argv[i++] = "-d";
|
|
|
|
|
2017-08-29 17:11:10 +00:00
|
|
|
if (mem->phys_addr)
|
|
|
|
rec_argv[i++] = "--phys-data";
|
|
|
|
|
perf mem: Support data page size
Add option --data-page-size in "perf mem" to record/report data page
size.
Here are some examples:
# perf mem --phys-data --data-page-size report -D
# PID, TID, IP, ADDR, PHYS ADDR, DATA PAGE SIZE, LOCAL WEIGHT, DSRC, SYMBOL
20134 20134 0xffffffffb5bd2fd0 0x016ffff9a274e96a308 0x000000044e96a308 4K 1168 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:perf_ctx_unlock
20134 20134 0xffffffffb63f645c 0xffffffffb752b814 0xcfb52b814 2M 225 0x26a100142 /lib/modules/4.18.0-rc7+/build/vmlinux:_raw_spin_lock
20134 20134 0xffffffffb660300c 0xfffffe00016b8bb0 0x0 4K 0 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:__x86_indirect_thunk_rax
#
# perf mem --phys-data --data-page-size report --stdio
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 5K of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 281234
# Sort order :
# mem,sym,dso,symbol_daddr,dso_daddr,tlb,locked,phys_daddr,data_page_size
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol Data Object TLB access Locked Data Physical Address Data Page Size
# ........ ....... ............. ............................ ................ ...................... ........... ............ ...... ...................... ..............
28.54% 1826 L1 or L1 hit [k] __x86_indirect_thunk_rax [kernel.vmlinux] [k] 0xffffb0df31b0ff28 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
6.02% 256 L1 or L1 hit [.] touch_buffer dtlb [.] 0x00007ffd50109da8 [stack] L1 or L2 hit No [.] 0x000000042454ada8 4K
3.23% 5 L1 or L1 hit [k] clear_huge_page [kernel.vmlinux] [k] 0xffff9a2753b8ce60 [unknown] L1 or L2 hit No [k] 0x0000000453b8ce60 2M
2.98% 4 L1 or L1 hit [k] clear_page_erms [kernel.vmlinux] [k] 0xffffb0df31b0fd00 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210105195752.43489-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-05 19:57:48 +00:00
|
|
|
if (mem->data_page_size)
|
|
|
|
rec_argv[i++] = "--data-page-size";
|
|
|
|
|
2021-05-27 00:16:08 +00:00
|
|
|
start = i;
|
2024-01-23 18:50:35 +00:00
|
|
|
ret = perf_mem_events__record_args(rec_argv, &i);
|
2021-05-27 00:16:07 +00:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
2021-05-27 00:16:08 +00:00
|
|
|
end = i;
|
2013-01-24 15:10:38 +00:00
|
|
|
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
if (mem->all_user)
|
2016-03-24 12:52:16 +00:00
|
|
|
rec_argv[i++] = "--all-user";
|
|
|
|
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
if (mem->all_kernel)
|
2016-03-24 12:52:16 +00:00
|
|
|
rec_argv[i++] = "--all-kernel";
|
|
|
|
|
2022-10-04 20:02:11 +00:00
|
|
|
if (mem->cpu_list) {
|
|
|
|
rec_argv[i++] = "-C";
|
|
|
|
rec_argv[i++] = mem->cpu_list;
|
|
|
|
}
|
|
|
|
|
2016-02-15 08:34:35 +00:00
|
|
|
for (j = 0; j < argc; j++, i++)
|
2013-01-24 15:10:38 +00:00
|
|
|
rec_argv[i] = argv[j];
|
|
|
|
|
2016-02-15 08:34:35 +00:00
|
|
|
if (verbose > 0) {
|
|
|
|
pr_debug("calling: record ");
|
|
|
|
|
2021-05-27 00:16:08 +00:00
|
|
|
for (j = start; j < end; j++)
|
2016-02-15 08:34:35 +00:00
|
|
|
pr_debug("%s ", rec_argv[j]);
|
2021-05-27 00:16:08 +00:00
|
|
|
|
2016-02-15 08:34:35 +00:00
|
|
|
pr_debug("\n");
|
|
|
|
}
|
|
|
|
|
2017-03-27 14:47:20 +00:00
|
|
|
ret = cmd_record(i, rec_argv);
|
2021-05-27 00:16:07 +00:00
|
|
|
out:
|
2013-01-24 15:10:38 +00:00
|
|
|
free(rec_argv);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2024-08-12 20:46:55 +00:00
|
|
|
dump_raw_samples(const struct perf_tool *tool,
|
2013-01-24 15:10:38 +00:00
|
|
|
union perf_event *event,
|
|
|
|
struct perf_sample *sample,
|
|
|
|
struct machine *machine)
|
|
|
|
{
|
|
|
|
struct perf_mem *mem = container_of(tool, struct perf_mem, tool);
|
|
|
|
struct addr_location al;
|
2021-01-05 19:57:47 +00:00
|
|
|
const char *fmt, *field_sep;
|
perf mem: Support data page size
Add option --data-page-size in "perf mem" to record/report data page
size.
Here are some examples:
# perf mem --phys-data --data-page-size report -D
# PID, TID, IP, ADDR, PHYS ADDR, DATA PAGE SIZE, LOCAL WEIGHT, DSRC, SYMBOL
20134 20134 0xffffffffb5bd2fd0 0x016ffff9a274e96a308 0x000000044e96a308 4K 1168 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:perf_ctx_unlock
20134 20134 0xffffffffb63f645c 0xffffffffb752b814 0xcfb52b814 2M 225 0x26a100142 /lib/modules/4.18.0-rc7+/build/vmlinux:_raw_spin_lock
20134 20134 0xffffffffb660300c 0xfffffe00016b8bb0 0x0 4K 0 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:__x86_indirect_thunk_rax
#
# perf mem --phys-data --data-page-size report --stdio
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 5K of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 281234
# Sort order :
# mem,sym,dso,symbol_daddr,dso_daddr,tlb,locked,phys_daddr,data_page_size
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol Data Object TLB access Locked Data Physical Address Data Page Size
# ........ ....... ............. ............................ ................ ...................... ........... ............ ...... ...................... ..............
28.54% 1826 L1 or L1 hit [k] __x86_indirect_thunk_rax [kernel.vmlinux] [k] 0xffffb0df31b0ff28 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
6.02% 256 L1 or L1 hit [.] touch_buffer dtlb [.] 0x00007ffd50109da8 [stack] L1 or L2 hit No [.] 0x000000042454ada8 4K
3.23% 5 L1 or L1 hit [k] clear_huge_page [kernel.vmlinux] [k] 0xffff9a2753b8ce60 [unknown] L1 or L2 hit No [k] 0x0000000453b8ce60 2M
2.98% 4 L1 or L1 hit [k] clear_page_erms [kernel.vmlinux] [k] 0xffffb0df31b0fd00 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210105195752.43489-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-05 19:57:48 +00:00
|
|
|
char str[PAGE_SIZE_NAME_LEN];
|
2023-03-20 21:22:35 +00:00
|
|
|
struct dso *dso = NULL;
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2023-06-08 23:28:03 +00:00
|
|
|
addr_location__init(&al);
|
2016-03-22 21:39:09 +00:00
|
|
|
if (machine__resolve(machine, &al, sample) < 0) {
|
2013-01-24 15:10:38 +00:00
|
|
|
fprintf(stderr, "problem processing %d event, skipping it.\n",
|
|
|
|
event->header.type);
|
2023-06-08 23:28:03 +00:00
|
|
|
addr_location__exit(&al);
|
2013-01-24 15:10:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (al.filtered || (mem->hide_unresolved && al.sym == NULL))
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
goto out_put;
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2023-03-20 21:22:35 +00:00
|
|
|
if (al.map != NULL) {
|
|
|
|
dso = map__dso(al.map);
|
|
|
|
if (dso)
|
2024-05-04 21:38:01 +00:00
|
|
|
dso__set_hit(dso);
|
2023-03-20 21:22:35 +00:00
|
|
|
}
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2021-01-05 19:57:47 +00:00
|
|
|
field_sep = symbol_conf.field_sep;
|
|
|
|
if (field_sep) {
|
|
|
|
fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s";
|
2013-01-24 15:10:38 +00:00
|
|
|
} else {
|
2021-01-05 19:57:47 +00:00
|
|
|
fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64"%s";
|
|
|
|
symbol_conf.field_sep = " ";
|
|
|
|
}
|
|
|
|
printf(fmt,
|
|
|
|
sample->pid,
|
|
|
|
symbol_conf.field_sep,
|
|
|
|
sample->tid,
|
|
|
|
symbol_conf.field_sep,
|
|
|
|
sample->ip,
|
|
|
|
symbol_conf.field_sep,
|
|
|
|
sample->addr,
|
|
|
|
symbol_conf.field_sep);
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2021-01-05 19:57:47 +00:00
|
|
|
if (mem->phys_addr) {
|
|
|
|
printf("0x%016"PRIx64"%s",
|
|
|
|
sample->phys_addr,
|
|
|
|
symbol_conf.field_sep);
|
2017-08-29 17:11:10 +00:00
|
|
|
}
|
2021-01-05 19:57:47 +00:00
|
|
|
|
perf mem: Support data page size
Add option --data-page-size in "perf mem" to record/report data page
size.
Here are some examples:
# perf mem --phys-data --data-page-size report -D
# PID, TID, IP, ADDR, PHYS ADDR, DATA PAGE SIZE, LOCAL WEIGHT, DSRC, SYMBOL
20134 20134 0xffffffffb5bd2fd0 0x016ffff9a274e96a308 0x000000044e96a308 4K 1168 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:perf_ctx_unlock
20134 20134 0xffffffffb63f645c 0xffffffffb752b814 0xcfb52b814 2M 225 0x26a100142 /lib/modules/4.18.0-rc7+/build/vmlinux:_raw_spin_lock
20134 20134 0xffffffffb660300c 0xfffffe00016b8bb0 0x0 4K 0 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:__x86_indirect_thunk_rax
#
# perf mem --phys-data --data-page-size report --stdio
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 5K of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 281234
# Sort order :
# mem,sym,dso,symbol_daddr,dso_daddr,tlb,locked,phys_daddr,data_page_size
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol Data Object TLB access Locked Data Physical Address Data Page Size
# ........ ....... ............. ............................ ................ ...................... ........... ............ ...... ...................... ..............
28.54% 1826 L1 or L1 hit [k] __x86_indirect_thunk_rax [kernel.vmlinux] [k] 0xffffb0df31b0ff28 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
6.02% 256 L1 or L1 hit [.] touch_buffer dtlb [.] 0x00007ffd50109da8 [stack] L1 or L2 hit No [.] 0x000000042454ada8 4K
3.23% 5 L1 or L1 hit [k] clear_huge_page [kernel.vmlinux] [k] 0xffff9a2753b8ce60 [unknown] L1 or L2 hit No [k] 0x0000000453b8ce60 2M
2.98% 4 L1 or L1 hit [k] clear_page_erms [kernel.vmlinux] [k] 0xffffb0df31b0fd00 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210105195752.43489-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-05 19:57:48 +00:00
|
|
|
if (mem->data_page_size) {
|
|
|
|
printf("%s%s",
|
|
|
|
get_page_size_name(sample->data_page_size, str),
|
|
|
|
symbol_conf.field_sep);
|
|
|
|
}
|
|
|
|
|
2021-01-05 19:57:47 +00:00
|
|
|
if (field_sep)
|
|
|
|
fmt = "%"PRIu64"%s0x%"PRIx64"%s%s:%s\n";
|
|
|
|
else
|
|
|
|
fmt = "%5"PRIu64"%s0x%06"PRIx64"%s%s:%s\n";
|
|
|
|
|
|
|
|
printf(fmt,
|
|
|
|
sample->weight,
|
|
|
|
symbol_conf.field_sep,
|
|
|
|
sample->data_src,
|
|
|
|
symbol_conf.field_sep,
|
2024-05-04 21:38:01 +00:00
|
|
|
dso ? dso__long_name(dso) : "???",
|
2021-01-05 19:57:47 +00:00
|
|
|
al.sym ? al.sym->name : "???");
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-06 23:43:22 +00:00
|
|
|
out_put:
|
2023-06-08 23:28:03 +00:00
|
|
|
addr_location__exit(&al);
|
2013-01-24 15:10:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-08-12 20:46:55 +00:00
|
|
|
static int process_sample_event(const struct perf_tool *tool,
|
2013-01-24 15:10:38 +00:00
|
|
|
union perf_event *event,
|
|
|
|
struct perf_sample *sample,
|
2019-07-21 11:23:51 +00:00
|
|
|
struct evsel *evsel __maybe_unused,
|
2013-01-24 15:10:38 +00:00
|
|
|
struct machine *machine)
|
|
|
|
{
|
2013-12-19 20:00:45 +00:00
|
|
|
return dump_raw_samples(tool, event, sample, machine);
|
2013-01-24 15:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int report_raw_events(struct perf_mem *mem)
|
|
|
|
{
|
2020-11-06 09:48:51 +00:00
|
|
|
struct itrace_synth_opts itrace_synth_opts = {
|
|
|
|
.set = true,
|
|
|
|
.mem = true, /* Only enable memory event */
|
|
|
|
.default_no_sample = true,
|
|
|
|
};
|
|
|
|
|
2017-01-23 21:07:59 +00:00
|
|
|
struct perf_data data = {
|
2019-02-21 09:41:30 +00:00
|
|
|
.path = input_name,
|
|
|
|
.mode = PERF_DATA_MODE_READ,
|
|
|
|
.force = mem->force,
|
2013-10-15 14:27:32 +00:00
|
|
|
};
|
2013-01-24 15:10:38 +00:00
|
|
|
int ret;
|
2024-08-12 20:47:11 +00:00
|
|
|
struct perf_session *session;
|
|
|
|
|
|
|
|
perf_tool__init(&mem->tool, /*ordered_events=*/true);
|
|
|
|
mem->tool.sample = process_sample_event;
|
|
|
|
mem->tool.mmap = perf_event__process_mmap;
|
|
|
|
mem->tool.mmap2 = perf_event__process_mmap2;
|
|
|
|
mem->tool.comm = perf_event__process_comm;
|
|
|
|
mem->tool.lost = perf_event__process_lost;
|
|
|
|
mem->tool.fork = perf_event__process_fork;
|
|
|
|
mem->tool.attr = perf_event__process_attr;
|
|
|
|
mem->tool.build_id = perf_event__process_build_id;
|
|
|
|
mem->tool.namespaces = perf_event__process_namespaces;
|
|
|
|
mem->tool.auxtrace_info = perf_event__process_auxtrace_info;
|
|
|
|
mem->tool.auxtrace = perf_event__process_auxtrace;
|
|
|
|
mem->tool.auxtrace_error = perf_event__process_auxtrace_error;
|
|
|
|
|
|
|
|
session = perf_session__new(&data, &mem->tool);
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2019-08-22 07:20:49 +00:00
|
|
|
if (IS_ERR(session))
|
|
|
|
return PTR_ERR(session);
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2020-11-06 09:48:51 +00:00
|
|
|
session->itrace_synth_opts = &itrace_synth_opts;
|
|
|
|
|
2013-01-24 15:10:38 +00:00
|
|
|
if (mem->cpu_list) {
|
|
|
|
ret = perf_session__cpu_bitmap(session, mem->cpu_list,
|
|
|
|
mem->cpu_bitmap);
|
2015-07-01 12:08:19 +00:00
|
|
|
if (ret < 0)
|
2013-01-24 15:10:38 +00:00
|
|
|
goto out_delete;
|
|
|
|
}
|
|
|
|
|
2015-07-01 12:08:19 +00:00
|
|
|
ret = symbol__init(&session->header.env);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_delete;
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2021-01-05 19:57:47 +00:00
|
|
|
printf("# PID, TID, IP, ADDR, ");
|
|
|
|
|
2017-08-29 17:11:10 +00:00
|
|
|
if (mem->phys_addr)
|
2021-01-05 19:57:47 +00:00
|
|
|
printf("PHYS ADDR, ");
|
|
|
|
|
perf mem: Support data page size
Add option --data-page-size in "perf mem" to record/report data page
size.
Here are some examples:
# perf mem --phys-data --data-page-size report -D
# PID, TID, IP, ADDR, PHYS ADDR, DATA PAGE SIZE, LOCAL WEIGHT, DSRC, SYMBOL
20134 20134 0xffffffffb5bd2fd0 0x016ffff9a274e96a308 0x000000044e96a308 4K 1168 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:perf_ctx_unlock
20134 20134 0xffffffffb63f645c 0xffffffffb752b814 0xcfb52b814 2M 225 0x26a100142 /lib/modules/4.18.0-rc7+/build/vmlinux:_raw_spin_lock
20134 20134 0xffffffffb660300c 0xfffffe00016b8bb0 0x0 4K 0 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:__x86_indirect_thunk_rax
#
# perf mem --phys-data --data-page-size report --stdio
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 5K of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 281234
# Sort order :
# mem,sym,dso,symbol_daddr,dso_daddr,tlb,locked,phys_daddr,data_page_size
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol Data Object TLB access Locked Data Physical Address Data Page Size
# ........ ....... ............. ............................ ................ ...................... ........... ............ ...... ...................... ..............
28.54% 1826 L1 or L1 hit [k] __x86_indirect_thunk_rax [kernel.vmlinux] [k] 0xffffb0df31b0ff28 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
6.02% 256 L1 or L1 hit [.] touch_buffer dtlb [.] 0x00007ffd50109da8 [stack] L1 or L2 hit No [.] 0x000000042454ada8 4K
3.23% 5 L1 or L1 hit [k] clear_huge_page [kernel.vmlinux] [k] 0xffff9a2753b8ce60 [unknown] L1 or L2 hit No [k] 0x0000000453b8ce60 2M
2.98% 4 L1 or L1 hit [k] clear_page_erms [kernel.vmlinux] [k] 0xffffb0df31b0fd00 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210105195752.43489-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-05 19:57:48 +00:00
|
|
|
if (mem->data_page_size)
|
|
|
|
printf("DATA PAGE SIZE, ");
|
|
|
|
|
2021-01-05 19:57:47 +00:00
|
|
|
printf("LOCAL WEIGHT, DSRC, SYMBOL\n");
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2015-07-01 12:08:19 +00:00
|
|
|
ret = perf_session__process_events(session);
|
2013-01-24 15:10:38 +00:00
|
|
|
|
|
|
|
out_delete:
|
|
|
|
perf_session__delete(session);
|
2015-07-01 12:08:19 +00:00
|
|
|
return ret;
|
2013-01-24 15:10:38 +00:00
|
|
|
}
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
|
2020-12-16 18:57:59 +00:00
|
|
|
static char *get_sort_order(struct perf_mem *mem)
|
|
|
|
{
|
perf mem: Support data page size
Add option --data-page-size in "perf mem" to record/report data page
size.
Here are some examples:
# perf mem --phys-data --data-page-size report -D
# PID, TID, IP, ADDR, PHYS ADDR, DATA PAGE SIZE, LOCAL WEIGHT, DSRC, SYMBOL
20134 20134 0xffffffffb5bd2fd0 0x016ffff9a274e96a308 0x000000044e96a308 4K 1168 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:perf_ctx_unlock
20134 20134 0xffffffffb63f645c 0xffffffffb752b814 0xcfb52b814 2M 225 0x26a100142 /lib/modules/4.18.0-rc7+/build/vmlinux:_raw_spin_lock
20134 20134 0xffffffffb660300c 0xfffffe00016b8bb0 0x0 4K 0 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:__x86_indirect_thunk_rax
#
# perf mem --phys-data --data-page-size report --stdio
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 5K of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 281234
# Sort order :
# mem,sym,dso,symbol_daddr,dso_daddr,tlb,locked,phys_daddr,data_page_size
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol Data Object TLB access Locked Data Physical Address Data Page Size
# ........ ....... ............. ............................ ................ ...................... ........... ............ ...... ...................... ..............
28.54% 1826 L1 or L1 hit [k] __x86_indirect_thunk_rax [kernel.vmlinux] [k] 0xffffb0df31b0ff28 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
6.02% 256 L1 or L1 hit [.] touch_buffer dtlb [.] 0x00007ffd50109da8 [stack] L1 or L2 hit No [.] 0x000000042454ada8 4K
3.23% 5 L1 or L1 hit [k] clear_huge_page [kernel.vmlinux] [k] 0xffff9a2753b8ce60 [unknown] L1 or L2 hit No [k] 0x0000000453b8ce60 2M
2.98% 4 L1 or L1 hit [k] clear_page_erms [kernel.vmlinux] [k] 0xffffb0df31b0fd00 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210105195752.43489-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-05 19:57:48 +00:00
|
|
|
bool has_extra_options = (mem->phys_addr | mem->data_page_size) ? true : false;
|
2020-12-16 18:57:59 +00:00
|
|
|
char sort[128];
|
|
|
|
|
2024-07-31 23:55:04 +00:00
|
|
|
if (mem->sort_key)
|
|
|
|
scnprintf(sort, sizeof(sort), "--sort=%s", mem->sort_key);
|
2024-07-31 23:55:05 +00:00
|
|
|
else if (mem->data_type)
|
|
|
|
strcpy(sort, "--sort=mem,snoop,tlb,type");
|
2020-12-16 18:57:59 +00:00
|
|
|
/*
|
|
|
|
* there is no weight (cost) associated with stores, so don't print
|
|
|
|
* the column
|
|
|
|
*/
|
2024-07-31 23:55:04 +00:00
|
|
|
else if (!(mem->operation & MEM_OPERATION_LOAD)) {
|
2020-12-16 18:57:59 +00:00
|
|
|
strcpy(sort, "--sort=mem,sym,dso,symbol_daddr,"
|
|
|
|
"dso_daddr,tlb,locked");
|
|
|
|
} else if (has_extra_options) {
|
|
|
|
strcpy(sort, "--sort=local_weight,mem,sym,dso,symbol_daddr,"
|
perf tools: Support data block and addr block
Two new data source fields, to indicate the block reasons of a load
instruction, are introduced on the Intel Sapphire Rapids server. The
fields can be used by the memory profiling.
Add a new sort function, SORT_MEM_BLOCKED, for the two fields.
For the previous platforms or the block reason is unknown, print "N/A"
for the block reason.
Add blocked as a default mem sort key for perf report and perf mem
report.
Committer testing:
So in machines without this capability we get a "N/A" filling the new "Blocked"
column:
$ perf mem record ls
arch certs CREDITS Documentation include ipc Kconfig lib MAINTAINERS mm samples security usr block
COPYING crypto drivers fs init Kbuild kernel LICENSES Makefile net README scripts sound tools
virt
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.008 MB perf.data (17 samples) ]
$
$ perf mem report --stdio
# To display the perf.data header info, please use --header/--header-only options.
#
# Total Lost Samples: 0
#
# Samples: 6 of event 'cpu/mem-loads,ldlat=30/Pu'
# Total weight : 1381
# Sort order : local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked,blocked
#
# Overhead Samples Local Weight Memory access Symbol Shared Object Data Symbol Data Object Snoop TLB access Locked Blocked
# ........ ....... ............ .................... ....................... ............. ...................... ............ ..... ............ ...... .......
#
32.87% 1 454 Local RAM or RAM hit [.] _dl_relocate_object ld-2.31.so [.] 0x00007fe91cef3078 libc-2.31.so Hit L1 or L2 hit No N/A
25.56% 1 353 LFB or LFB hit [.] strcmp ld-2.31.so [.] 0x00005586973855ca ls None L1 or L2 hit No N/A
22.59% 1 312 LFB or LFB hit [.] _dl_cache_libcmp ld-2.31.so [.] 0x00007fe91d0e3b18 ld.so.cache None L1 or L2 hit No N/A
8.47% 1 117 LFB or LFB hit [.] _dl_relocate_object ld-2.31.so [.] 0x00007fe91ceee570 libc-2.31.so None L1 or L2 hit No N/A
6.88% 1 95 LFB or LFB hit [.] _dl_relocate_object ld-2.31.so [.] 0x00007fe91ceed490 libc-2.31.so None L1 or L2 hit No N/A
3.62% 1 50 LFB or LFB hit [.] _dl_cache_libcmp ld-2.31.so [.] 0x00007fe91d0ebe60 ld.so.cache None L1 or L2 hit No N/A
# Samples: 11 of event 'cpu/mem-stores/Pu'
# Total weight : 11
# Sort order : local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked,blocked
#
# Overhead Samples Local Weight Memory access Symbol Shared Object Data Symbol Data Object Snoop TLB access Locked Blocked
# ........ ....... ............ ............. ....................... ............. ...................... ........... ..... .......... ...... .......
#
9.09% 1 0 L1 hit [.] __strcoll_l libc-2.31.so [.] 0x00007fffe5648fc8 [stack] N/A N/A N/A N/A
9.09% 1 0 L1 hit [.] _dl_lookup_symbol_x ld-2.31.so [.] 0x00007fffe56490b8 [stack] N/A N/A N/A N/A
9.09% 1 0 L1 hit [.] _dl_name_match_p ld-2.31.so [.] 0x00007fffe56487d8 [stack] N/A N/A N/A N/A
9.09% 1 0 L1 hit [.] _dl_start ld-2.31.so [.] start_time+0x0 ld-2.31.so N/A N/A N/A N/A
9.09% 1 0 L1 hit [.] _dl_sysdep_start ld-2.31.so [.] 0x00007fffe56494b8 [stack] N/A N/A N/A N/A
9.09% 1 0 L1 hit [.] do_lookup_x ld-2.31.so [.] 0x00007fffe5648ff8 [stack] N/A N/A N/A N/A
9.09% 1 0 L1 hit [.] do_lookup_x ld-2.31.so [.] 0x00007fffe5649064 [stack] N/A N/A N/A N/A
9.09% 1 0 L1 hit [.] do_lookup_x ld-2.31.so [.] 0x00007fffe5649130 [stack] N/A N/A N/A N/A
9.09% 1 0 L1 miss [.] _dl_start ld-2.31.so [.] _rtld_global+0xaf8 ld-2.31.so N/A N/A N/A N/A
9.09% 1 0 L1 miss [.] _dl_start ld-2.31.so [.] _rtld_global+0xc28 ld-2.31.so N/A N/A N/A N/A
9.09% 1 0 L1 miss [.] _dl_start ld-2.31.so [.] 0x00007fffe56495b8 [stack] N/A N/A N/A N/A
# (Tip: Show user configuration overrides: perf config --user --list)
$
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/1612296553-21962-4-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-02-02 20:09:07 +00:00
|
|
|
"dso_daddr,snoop,tlb,locked,blocked");
|
2020-12-16 18:57:59 +00:00
|
|
|
} else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (mem->phys_addr)
|
|
|
|
strcat(sort, ",phys_daddr");
|
|
|
|
|
perf mem: Support data page size
Add option --data-page-size in "perf mem" to record/report data page
size.
Here are some examples:
# perf mem --phys-data --data-page-size report -D
# PID, TID, IP, ADDR, PHYS ADDR, DATA PAGE SIZE, LOCAL WEIGHT, DSRC, SYMBOL
20134 20134 0xffffffffb5bd2fd0 0x016ffff9a274e96a308 0x000000044e96a308 4K 1168 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:perf_ctx_unlock
20134 20134 0xffffffffb63f645c 0xffffffffb752b814 0xcfb52b814 2M 225 0x26a100142 /lib/modules/4.18.0-rc7+/build/vmlinux:_raw_spin_lock
20134 20134 0xffffffffb660300c 0xfffffe00016b8bb0 0x0 4K 0 0x5080144 /lib/modules/4.18.0-rc7+/build/vmlinux:__x86_indirect_thunk_rax
#
# perf mem --phys-data --data-page-size report --stdio
# To display the perf.data header info, please use
# --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 5K of event 'cpu/mem-loads,ldlat=30/P'
# Total weight : 281234
# Sort order :
# mem,sym,dso,symbol_daddr,dso_daddr,tlb,locked,phys_daddr,data_page_size
#
# Overhead Samples Memory access Symbol Shared Object Data Symbol Data Object TLB access Locked Data Physical Address Data Page Size
# ........ ....... ............. ............................ ................ ...................... ........... ............ ...... ...................... ..............
28.54% 1826 L1 or L1 hit [k] __x86_indirect_thunk_rax [kernel.vmlinux] [k] 0xffffb0df31b0ff28 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
6.02% 256 L1 or L1 hit [.] touch_buffer dtlb [.] 0x00007ffd50109da8 [stack] L1 or L2 hit No [.] 0x000000042454ada8 4K
3.23% 5 L1 or L1 hit [k] clear_huge_page [kernel.vmlinux] [k] 0xffff9a2753b8ce60 [unknown] L1 or L2 hit No [k] 0x0000000453b8ce60 2M
2.98% 4 L1 or L1 hit [k] clear_page_erms [kernel.vmlinux] [k] 0xffffb0df31b0fd00 [unknown] L1 or L2 hit No [k] 0x0000000000000000 4K
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Stephane Eranian <eranian@google.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210105195752.43489-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-05 19:57:48 +00:00
|
|
|
if (mem->data_page_size)
|
|
|
|
strcat(sort, ",data_page_size");
|
|
|
|
|
2024-07-31 23:55:05 +00:00
|
|
|
/* make sure it has 'type' sort key even -s option is used */
|
|
|
|
if (mem->data_type && !strstr(sort, "type"))
|
|
|
|
strcat(sort, ",type");
|
|
|
|
|
2020-12-16 18:57:59 +00:00
|
|
|
return strdup(sort);
|
|
|
|
}
|
2013-01-24 15:10:38 +00:00
|
|
|
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
static int __cmd_report(int argc, const char **argv, struct perf_mem *mem,
|
|
|
|
const struct option *options)
|
2013-01-24 15:10:38 +00:00
|
|
|
{
|
|
|
|
const char **rep_argv;
|
|
|
|
int ret, i = 0, j, rep_argc;
|
2020-12-16 18:57:59 +00:00
|
|
|
char *new_sort_order;
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
const char * const report_usage[] = {
|
|
|
|
"perf mem report [<options>]",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, options, report_usage,
|
|
|
|
PARSE_OPT_KEEP_UNKNOWN);
|
2013-01-24 15:10:38 +00:00
|
|
|
|
|
|
|
if (mem->dump_raw)
|
|
|
|
return report_raw_events(mem);
|
|
|
|
|
|
|
|
rep_argc = argc + 3;
|
|
|
|
rep_argv = calloc(rep_argc + 1, sizeof(char *));
|
|
|
|
if (!rep_argv)
|
|
|
|
return -1;
|
|
|
|
|
2014-12-17 15:23:55 +00:00
|
|
|
rep_argv[i++] = "report";
|
|
|
|
rep_argv[i++] = "--mem-mode";
|
|
|
|
rep_argv[i++] = "-n"; /* display number of samples */
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2020-12-16 18:57:59 +00:00
|
|
|
new_sort_order = get_sort_order(mem);
|
|
|
|
if (new_sort_order)
|
|
|
|
rep_argv[i++] = new_sort_order;
|
2013-01-24 15:10:38 +00:00
|
|
|
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
for (j = 0; j < argc; j++, i++)
|
2013-01-24 15:10:38 +00:00
|
|
|
rep_argv[i] = argv[j];
|
|
|
|
|
2017-03-27 14:47:20 +00:00
|
|
|
ret = cmd_report(i, rep_argv);
|
2024-07-31 23:55:01 +00:00
|
|
|
free(new_sort_order);
|
2013-01-24 15:10:38 +00:00
|
|
|
free(rep_argv);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-17 15:23:55 +00:00
|
|
|
struct mem_mode {
|
|
|
|
const char *name;
|
|
|
|
int mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MEM_OPT(n, m) \
|
|
|
|
{ .name = n, .mode = (m) }
|
|
|
|
|
|
|
|
#define MEM_END { .name = NULL }
|
|
|
|
|
|
|
|
static const struct mem_mode mem_modes[]={
|
|
|
|
MEM_OPT("load", MEM_OPERATION_LOAD),
|
|
|
|
MEM_OPT("store", MEM_OPERATION_STORE),
|
|
|
|
MEM_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_mem_ops(const struct option *opt, const char *str, int unset)
|
|
|
|
{
|
|
|
|
int *mode = (int *)opt->value;
|
|
|
|
const struct mem_mode *m;
|
|
|
|
char *s, *os = NULL, *p;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (unset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* str may be NULL in case no arg is passed to -t */
|
|
|
|
if (str) {
|
|
|
|
/* because str is read-only */
|
|
|
|
s = os = strdup(str);
|
|
|
|
if (!s)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* reset mode */
|
|
|
|
*mode = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
p = strchr(s, ',');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
for (m = mem_modes; m->name; m++) {
|
|
|
|
if (!strcasecmp(s, m->name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!m->name) {
|
|
|
|
fprintf(stderr, "unknown sampling op %s,"
|
|
|
|
" check man page\n", s);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mode |= m->mode;
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
|
|
|
|
s = p + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
if (*mode == 0)
|
|
|
|
*mode = MEM_OPERATION_LOAD;
|
|
|
|
error:
|
|
|
|
free(os);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-27 14:47:20 +00:00
|
|
|
int cmd_mem(int argc, const char **argv)
|
2013-01-24 15:10:38 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
struct perf_mem mem = {
|
|
|
|
.input_name = "perf.data",
|
2014-12-17 16:53:27 +00:00
|
|
|
/*
|
|
|
|
* default to both load an store sampling
|
|
|
|
*/
|
|
|
|
.operation = MEM_OPERATION_LOAD | MEM_OPERATION_STORE,
|
2013-01-24 15:10:38 +00:00
|
|
|
};
|
2024-07-31 23:55:04 +00:00
|
|
|
char *sort_order_help = sort_help("sort by key(s):", SORT_MODE__MEMORY);
|
2013-01-24 15:10:38 +00:00
|
|
|
const struct option mem_options[] = {
|
2014-12-17 16:53:27 +00:00
|
|
|
OPT_CALLBACK('t', "type", &mem.operation,
|
2014-12-17 15:23:55 +00:00
|
|
|
"type", "memory operations(load,store) Default load,store",
|
|
|
|
parse_mem_ops),
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
OPT_STRING('C', "cpu", &mem.cpu_list, "cpu",
|
|
|
|
"list of cpus to profile"),
|
|
|
|
OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"),
|
|
|
|
OPT_INCR('v', "verbose", &verbose,
|
|
|
|
"be more verbose (show counter open errors, etc)"),
|
|
|
|
OPT_BOOLEAN('p', "phys-data", &mem.phys_addr, "Record/Report sample physical addresses"),
|
|
|
|
OPT_BOOLEAN(0, "data-page-size", &mem.data_page_size, "Record/Report sample data address page size"),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const struct option record_options[] = {
|
|
|
|
OPT_CALLBACK('e', "event", &mem, "event",
|
|
|
|
"event selector. use 'perf mem record -e list' to list available events",
|
|
|
|
parse_record_events),
|
|
|
|
OPT_UINTEGER(0, "ldlat", &perf_mem_events__loads_ldlat, "mem-loads latency"),
|
|
|
|
OPT_BOOLEAN('U', "all-user", &mem.all_user, "collect only user level data"),
|
|
|
|
OPT_BOOLEAN('K', "all-kernel", &mem.all_kernel, "collect only kernel level data"),
|
|
|
|
OPT_PARENT(mem_options)
|
|
|
|
};
|
|
|
|
const struct option report_options[] = {
|
2013-01-24 15:10:38 +00:00
|
|
|
OPT_BOOLEAN('D', "dump-raw-samples", &mem.dump_raw,
|
|
|
|
"dump raw samples in ASCII"),
|
|
|
|
OPT_BOOLEAN('U', "hide-unresolved", &mem.hide_unresolved,
|
|
|
|
"Only display entries resolved to a symbol"),
|
|
|
|
OPT_STRING('i', "input", &input_name, "file",
|
|
|
|
"input file name"),
|
2015-03-20 02:57:52 +00:00
|
|
|
OPT_STRING_NOEMPTY('x', "field-separator", &symbol_conf.field_sep,
|
2013-01-24 15:10:38 +00:00
|
|
|
"separator",
|
|
|
|
"separator for columns, no spaces will be added"
|
|
|
|
" between columns '.' is reserved."),
|
2024-07-31 23:55:04 +00:00
|
|
|
OPT_STRING('s', "sort", &mem.sort_key, "key[,key2...]",
|
|
|
|
sort_order_help),
|
2024-07-31 23:55:05 +00:00
|
|
|
OPT_BOOLEAN('T', "type-profile", &mem.data_type,
|
|
|
|
"Show data-type profile result"),
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
OPT_PARENT(mem_options)
|
2013-01-24 15:10:38 +00:00
|
|
|
};
|
2014-03-15 03:17:52 +00:00
|
|
|
const char *const mem_subcommands[] = { "record", "report", NULL };
|
|
|
|
const char *mem_usage[] = {
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
mem_usage, PARSE_OPT_STOP_AT_NON_OPTION);
|
2013-01-24 15:10:38 +00:00
|
|
|
|
2014-12-17 16:53:27 +00:00
|
|
|
if (!argc || !(strncmp(argv[0], "rec", 3) || mem.operation))
|
2013-01-24 15:10:38 +00:00
|
|
|
usage_with_options(mem_usage, mem_options);
|
|
|
|
|
|
|
|
if (!mem.input_name || !strlen(mem.input_name)) {
|
|
|
|
if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
|
|
|
|
mem.input_name = "-";
|
|
|
|
else
|
|
|
|
mem.input_name = "perf.data";
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:20:32 +00:00
|
|
|
if (strlen(argv[0]) > 2 && strstarts("record", argv[0]))
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
return __cmd_record(argc, argv, &mem, record_options);
|
2022-03-25 09:20:32 +00:00
|
|
|
else if (strlen(argv[0]) > 2 && strstarts("report", argv[0]))
|
perf mem: Rework command option handling
Split the common option and ones for record or report. Otherwise -U in
the record option cannot be used because it clashes with in the common
(or report) option. Also rename report_events() to __cmd_report() to
follow the convention and to be sync with the record part.
Also set the flag PARSE_OPT_STOP_AT_NON_OPTION for the common option so
that it can show the help message in the subcommand like below:
$ perf mem record -h
Usage: perf mem record [<options>] [<command>]
or: perf mem record [<options>] -- <command> [<options>]
-C, --cpu <cpu> list of cpus to profile
-e, --event <event> event selector. use 'perf mem record -e list' to list available events
-f, --force don't complain, do it
-K, --all-kernel collect only kernel level data
-p, --phys-data Record/Report sample physical addresses
-t, --type <type> memory operations(load,store) Default load,store
-U, --all-user collect only user level data
-v, --verbose be more verbose (show counter open errors, etc)
--data-page-size Record/Report sample data address page size
--ldlat <n> mem-loads latency
Cc: Aditya Gupta <adityag@linux.ibm.com>
Signed-off-by: Namhyung 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>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240731235505.710436-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-07-31 23:55:02 +00:00
|
|
|
return __cmd_report(argc, argv, &mem, report_options);
|
2013-01-24 15:10:38 +00:00
|
|
|
else
|
|
|
|
usage_with_options(mem_usage, mem_options);
|
|
|
|
|
libsubcmd: Don't free the usage string
Currently, commands which depend on 'parse_options_subcommand()' don't
show the usage string, and instead show '(null)'
$ ./perf sched
Usage: (null)
-D, --dump-raw-trace dump raw trace in ASCII
-f, --force don't complain, do it
-i, --input <file> input file name
-v, --verbose be more verbose (show symbol address, etc)
'parse_options_subcommand()' is generally expected to initialise the usage
string, with information in the passed 'subcommands[]' array
This behaviour was changed in:
230a7a71f92212e7 ("libsubcmd: Fix parse-options memory leak")
Where the generated usage string is deallocated, and usage[0] string is
reassigned as NULL.
As discussed in [1], free the allocated usage string in the main
function itself, and don't reset usage string to NULL in
parse_options_subcommand
With this change, the behaviour is restored.
$ ./perf sched
Usage: perf sched [<options>] {record|latency|map|replay|script|timehist}
-D, --dump-raw-trace dump raw trace in ASCII
-f, --force don't complain, do it
-i, --input <file> input file name
-v, --verbose be more verbose (show symbol address, etc)
[1]: https://lore.kernel.org/linux-perf-users/htq5vhx6piet4nuq2mmhk7fs2bhfykv52dbppwxmo3s7du2odf@styd27tioc6e/
Fixes: 230a7a71f92212e7 ("libsubcmd: Fix parse-options memory leak")
Suggested-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Aditya Gupta <adityag@linux.ibm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.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: Kajol Jain <kjain@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240904061836.55873-2-adityag@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-09-04 06:18:30 +00:00
|
|
|
/* free usage string allocated by parse_options_subcommand */
|
|
|
|
free((void *)mem_usage[0]);
|
|
|
|
|
2013-01-24 15:10:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|