perf: Make code more generic with modern defaults
Subsystems (2)
Ian Rogers
reviewerv5 cover perf: Make code more generic with modern defaults
This patch series combines:
"perf: Default use of build IDs and improvements"
https://lore.kernel.org/lkml/[email protected]/
"Remove global perf_env"
https://lore.kernel.org/lkml/[email protected]/
"Generic weight struct, use env for sort key and header"
https://lore.kernel.org/lkml/[email protected]/
This is done as the last 2 series depend on each other and the cleanups in the 1st have the potential to conflict with them.
"perf: Default use of build IDs and improvements"
Build ID mmap2 events have been available since Linux v5.12 and avoid certain races. Enable these by default as discussed in:
https://lore.kernel.org/linux-perf-users/CAP-5=fXP7jN_QrGUcd55_QH5J-Y-FCaJ6=NaHVtyx0oyNh8_-Q@mail.gmail.com/
The dso_id is used to indentify a DSO that may change by being overwritten. The inode generation isn't present in /proc/pid/maps and so was already only optionally filled in. With build ID mmap events the other major, minor and inode varialbes aren't filled in. Change the dso_id implementation to make optional values explicit, rather than injecting a dso_id we want to improve it during find operations, add the buildid to the dso_id for sorting and so that matching fails when build IDs vary between DSOs.
Mark the callchain for buildids and not just the sample IP, fixing missing DSOs.
Fix sample__for_each_callchain_node to populate the map even when symbols aren't computed.
Other minor bits of build_id clean up.
"Remove global perf_env"
The global perf_env is used to hold host information, but it is also used as a fallback in a number of cases where the information may be bogus. Restructure the code so that the perf_env of the session is accessed. When necessary a locally scoped host perf_env is created and used.
Cleaning up the inconsistency was requested by Kan Liang in:
https://lore.kernel.org/lkml/[email protected]/
"Generic weight struct, use env for sort key and header"
The arch directory is a barrier to cross-platform development as files and behaviors within it are inherently platform specific. Sample parsing should be generic but the PERF_SAMPLE_WEIGHT_STRUCT handling was only present if building for x86 or powerpc. The sort key and headers should be specific to the session that is being executed and not to the machine perf is being run upon. These patches clean this and associated code up.
v5: Drop merged 1st patch. Rebase and fix breakages in new/changed code.
v4: Shorten to "weight3" histogram and sample variable, but comment
its use (Namhyung). Fix evsel__env use in perf trace where no session was present. Assert the session is never passed a NULL host_env when there is no data file and its associated env.
Ian Rogers (23):
perf build-id: Reduce size of "size" variable
perf build-id: Truncate to avoid overflowing the build_id data perf build-id: Change sprintf functions to snprintf perf build-id: Mark DSO in sample callchains
perf build-id: Ensure struct build_id is empty before use perf dso: Move build_id to dso_id
perf jitdump: Directly mark the jitdump DSO
perf record: Make --buildid-mmap the default
perf session: Add accessor for session->header.env perf session: Add an env pointer for the current perf_env perf evlist: Change env variable to session
perf header: Clean up use of perf_env
perf test: Avoid use perf_env
perf session: Add host_env argument to perf_session__new perf top: Make perf_env locally scoped
perf bench synthesize: Avoid use of global perf_env perf machine: Explicitly pass in host perf_env
perf auxtrace: Pass perf_env from session through to mmap read perf trace: Avoid global perf_env with evsel__env perf env: Remove global perf_env
perf sample: Remove arch notion of sample parsing perf test: Move PERF_SAMPLE_WEIGHT_STRUCT parsing to common test perf sort: Use perf_env to set arch sort keys and header
tools/perf/arch/powerpc/util/Build | 1 - tools/perf/arch/powerpc/util/event.c | 60 ------ tools/perf/arch/x86/include/arch-tests.h | 1 - tools/perf/arch/x86/tests/Build | 1 - tools/perf/arch/x86/tests/arch-tests.c | 2 - tools/perf/arch/x86/tests/sample-parsing.c | 125 ------------ tools/perf/arch/x86/util/event.c | 46 ----- tools/perf/bench/inject-buildid.c | 2 +- tools/perf/bench/synthesize.c | 30 +-- tools/perf/builtin-annotate.c | 6 +- tools/perf/builtin-buildid-cache.c | 22 +-- tools/perf/builtin-buildid-list.c | 11 +- tools/perf/builtin-c2c.c | 69 ++++--- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 41 ++-- tools/perf/builtin-kallsyms.c | 21 ++- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 4 +- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-lock.c | 4 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-record.c | 63 ++++--- tools/perf/builtin-report.c | 27 ++- tools/perf/builtin-sched.c | 8 +- tools/perf/builtin-script.c | 18 +- tools/perf/builtin-stat.c | 23 +-- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 58 +++--- tools/perf/builtin-trace.c | 38 ++-- tools/perf/include/perf/perf_dlfilter.h | 2 +- tools/perf/perf.c | 3 - tools/perf/tests/code-reading.c | 6 +- tools/perf/tests/dlfilter-test.c | 51 ++--- tools/perf/tests/dwarf-unwind.c | 10 +- tools/perf/tests/hists_cumulate.c | 8 +- tools/perf/tests/hists_filter.c | 8 +- tools/perf/tests/hists_link.c | 8 +- tools/perf/tests/hists_output.c | 10 +- tools/perf/tests/mmap-thread-lookup.c | 6 +- tools/perf/tests/pe-file-parsing.c | 2 +- tools/perf/tests/sample-parsing.c | 14 ++ tools/perf/tests/sdt.c | 2 +- tools/perf/tests/symbols.c | 12 +- tools/perf/tests/topology.c | 39 ++-- tools/perf/ui/browser.h | 4 +- tools/perf/ui/browsers/header.c | 4 +- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/util/amd-sample-raw.c | 2 +- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/auxtrace.c | 13 +- tools/perf/util/auxtrace.h | 6 +- tools/perf/util/bpf-event.c | 2 +- tools/perf/util/branch.c | 2 +- tools/perf/util/build-id.c | 63 ++++--- tools/perf/util/build-id.h | 8 +- tools/perf/util/data-convert-bt.c | 16 +- tools/perf/util/data-convert-json.c | 36 ++-- tools/perf/util/debug.c | 9 +- tools/perf/util/debuginfo.c | 2 +- tools/perf/util/disasm.c | 2 +- tools/perf/util/dlfilter.c | 2 +- tools/perf/util/dso.c | 111 ++++++----- tools/perf/util/dso.h | 75 ++++---- tools/perf/util/dsos.c | 20 +- tools/perf/util/env.c | 3 +- tools/perf/util/env.h | 2 - tools/perf/util/event.c | 2 +- tools/perf/util/event.h | 5 - tools/perf/util/evlist.h | 2 +- tools/perf/util/evsel.c | 29 ++- tools/perf/util/evsel.h | 1 + tools/perf/util/header.c | 178 ++++++++++-------- tools/perf/util/hist.c | 4 +- tools/perf/util/hist.h | 3 +- tools/perf/util/intel-tpebs.c | 4 +- tools/perf/util/jitdump.c | 21 ++- tools/perf/util/machine.c | 44 ++--- tools/perf/util/machine.h | 6 +- tools/perf/util/map.c | 15 +- tools/perf/util/map.h | 5 +- tools/perf/util/probe-event.c | 8 +- tools/perf/util/probe-file.c | 4 +- tools/perf/util/probe-finder.c | 3 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/sample-raw.c | 7 +- tools/perf/util/sample-raw.h | 2 +- tools/perf/util/sample.h | 6 +- .../scripting-engines/trace-event-python.c | 7 +- tools/perf/util/session.c | 20 +- tools/perf/util/session.h | 9 +- tools/perf/util/sort.c | 95 ++++++---- tools/perf/util/sort.h | 5 +- tools/perf/util/symbol-minimal.c | 2 +- tools/perf/util/symbol.c | 7 +- tools/perf/util/symbol_conf.h | 2 +- tools/perf/util/synthetic-events.c | 54 ++++-- tools/perf/util/tool.c | 2 +- 97 files changed, 919 insertions(+), 893 deletions(-) delete mode 100644 tools/perf/arch/powerpc/util/event.c delete mode 100644 tools/perf/arch/x86/tests/sample-parsing.c
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 1/23 perf build-id: Reduce size of "size" variable
Later clean up of the dso_id to include a build_id will suffer from alignment and size issues. The size can only hold up to a value of BUILD_ID_SIZE (20) and the mmap2 event uses a byte for the value.
--- tools/perf/util/build-id.h | 2 +- tools/perf/util/synthetic-events.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)
tools/perf/util/build-id.h +1 -1
@@ -13,7 +13,7 @@struct build_id {u8 data[BUILD_ID_SIZE ]; -size_t size; +u8 size; };struct dso ;
tools/perf/util/synthetic-events.c +6 -2
@@ -2248,7 +2248,9 @@ int perf_event__synthesize_build_id(const struct perf_tool *tool,memset (&ev,0 , len); - ev.build_id.size =min (bid->size,sizeof (ev.build_id.build_id)); + ev.build_id.size = bid->size; +if (ev.build_id.size >sizeof (ev.build_id.build_id)) + ev.build_id.size =sizeof (ev.build_id.build_id);memcpy (ev.build_id.build_id, bid->data, ev.build_id.size); ev.build_id.header.type =PERF_RECORD_HEADER_BUILD_ID ; ev.build_id.header.misc = misc |PERF_RECORD_MISC_BUILD_ID_SIZE ;
@@ -2308,7 +2310,9 @@ int perf_event__synthesize_mmap2_build_id(const struct perf_tool *tool, ev.mmap2.len = len; ev.mmap2.pgoff = pgoff; - ev.mmap2.build_id_size =min (bid->size,sizeof (ev.mmap2.build_id)); + ev.mmap2.build_id_size = bid->size; +if (ev.mmap2.build_id_size >sizeof (ev.mmap2.build_id)) + ev.build_id.size =sizeof (ev.mmap2.build_id);memcpy (ev.mmap2.build_id, bid->data, ev.mmap2.build_id_size); ev.mmap2.prot = prot;
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 2/23 perf build-id: Truncate to avoid overflowing the build_id data
In reply to Ian RogersWarning when the build_id data would be overflowed would lead to memory corruption, switch to truncation.
--- tools/perf/util/build-id.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/build-id.c +4 -1
@@ -951,7 +951,10 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)void build_id__init (struct build_id *bid,const u8 *data,size_t size) { -WARN_ON (size >BUILD_ID_SIZE ); +if (size >BUILD_ID_SIZE ) { +pr_debug ("Truncating build_id size from %zd\n" , size); + size =BUILD_ID_SIZE ; + }memcpy (bid->data, data, size); bid->size = size; }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 3/23 perf build-id: Change sprintf functions to snprintf
In reply to Ian RogersPass in a size argument rather than implying all build id strings must be SBUILD_ID_SIZE.
--- tools/perf/builtin-buildid-cache.c | 12 +++---- tools/perf/builtin-buildid-list.c | 6 ++-- tools/perf/util/build-id.c | 33 ++++++++----------- tools/perf/util/build-id.h | 6 ++-- tools/perf/util/disasm.c | 2 +- tools/perf/util/dso.c | 4 +-- tools/perf/util/dsos.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/map.c | 2 +- tools/perf/util/probe-file.c | 4 +-- .../scripting-engines/trace-event-python.c | 7 ++-- tools/perf/util/symbol.c | 2 +- 13 files changed, 38 insertions(+), 46 deletions(-)
tools/perf/builtin-buildid-cache.c +6 -6
@@ -31,7 +31,7 @@#include <linux/string.h> #include <linux/err.h> -static int build_id_cache__kcore_buildid (const char *proc_dir,char *sbuildid) +static int build_id_cache__kcore_buildid (const char *proc_dir,char *sbuildid,size_t sbuildid_size) {char root_dir[PATH_MAX ];char *p;
@@ -42,7 +42,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)if (!p)return -1 ; *p ='\0' ; -return sysfs__sprintf_build_id (root_dir, sbuildid); +return sysfs__snprintf_build_id (root_dir, sbuildid, sbuildid_size); }static int build_id_cache__kcore_dir (char *dir,size_t sz)
@@ -128,7 +128,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)return -1 ; *p ='\0' ; -if (build_id_cache__kcore_buildid (from_dir, sbuildid) <0 ) +if (build_id_cache__kcore_buildid (from_dir, sbuildid,sizeof (sbuildid)) <0 )return -1 ; scnprintf(to_dir, sizeof(to_dir), "%s/%s/%s",
@@ -187,7 +187,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)return -1 ; } -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id)); err =build_id_cache__add_s (sbuild_id, filename, nsi, false, false); pr_debug("Adding %s %s: %s\n", sbuild_id, filename,
@@ -211,7 +211,7 @@ static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)return -1 ; } -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id)); err =build_id_cache__remove_s (sbuild_id);pr_debug ("Removing %s %s: %s\n" , sbuild_id, filename, err ?"FAIL" :"Ok" );
@@ -317,7 +317,7 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi) } err =0 ; -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id));if (build_id_cache__cached (sbuild_id)) err =build_id_cache__remove_s (sbuild_id);
tools/perf/builtin-buildid-list.c +3 -3
@@ -31,7 +31,7 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused)memset (bid_buf,0 ,sizeof (bid_buf));if (dso__has_build_id (dso)) -build_id__sprintf (dso__bid_const (dso), bid_buf); +build_id__snprintf (dso__bid_const (dso), bid_buf,sizeof (bid_buf));printf ("%s %16" PRIx64" %16" PRIx64, bid_buf,map__start (map),map__end (map));if (dso_long_name !=NULL )printf (" %s" , dso_long_name);
@@ -57,7 +57,7 @@ static int sysfs__fprintf_build_id(FILE *fp)char sbuild_id[SBUILD_ID_SIZE ];int ret; - ret =sysfs__sprintf_build_id ("/" , sbuild_id); + ret =sysfs__snprintf_build_id ("/" , sbuild_id,sizeof (sbuild_id));if (ret !=sizeof (sbuild_id))return ret <0 ? ret : -EINVAL ;
@@ -69,7 +69,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)char sbuild_id[SBUILD_ID_SIZE ];int ret; - ret =filename__sprintf_build_id (name, sbuild_id); + ret =filename__snprintf_build_id (name, sbuild_id,sizeof (sbuild_id));if (ret !=sizeof (sbuild_id))return ret <0 ? ret : -EINVAL ;
tools/perf/util/build-id.c +13 -20
@@ -67,24 +67,17 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused,return 0 ; } -int build_id__sprintf (const struct build_id *build_id,char *bf) +int build_id__snprintf (const struct build_id *build_id,char *bf,size_t bf_size) { -char *bid = bf; -const u8 *raw = build_id->data; -size_t i; - - bf[0 ] =0x0 ; +size_t offs =0 ; -for (i =0 ; i < build_id->size; ++i) { -sprintf (bid,"%02x" , *raw); - ++raw; - bid +=2 ; - } +for (size_t i =0 ; i < build_id->size && offs < bf_size; ++i) + offs +=snprintf (bf + offs, bf_size - offs,"%02x" , build_id->data[i]); -return (bid - bf) +1 ; +return offs; } -int sysfs__sprintf_build_id (const char *root_dir,char *sbuild_id) +int sysfs__snprintf_build_id (const char *root_dir,char *sbuild_id,size_t sbuild_id_size) {char notes[PATH_MAX ];struct build_id bid;
@@ -99,10 +92,10 @@ int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)if (ret <0 )return ret; -return build_id__sprintf (&bid, sbuild_id); +return build_id__snprintf (&bid, sbuild_id, sbuild_id_size); } -int filename__sprintf_build_id (const char *pathname,char *sbuild_id) +int filename__snprintf_build_id (const char *pathname,char *sbuild_id,size_t sbuild_id_size) {struct build_id bid;int ret;
@@ -111,7 +104,7 @@ int filename__sprintf_build_id(const char *pathname, char *sbuild_id)if (ret <0 )return ret; -return build_id__sprintf (&bid, sbuild_id); +return build_id__snprintf (&bid, sbuild_id, sbuild_id_size); }/* asnprintf consolidates asprintf and snprintf */
@@ -212,9 +205,9 @@ static bool build_id_cache__valid_id(char *sbuild_id)return false;if (!strcmp (pathname,DSO__NAME_KALLSYMS )) - ret =sysfs__sprintf_build_id ("/" , real_sbuild_id); + ret =sysfs__snprintf_build_id ("/" , real_sbuild_id,sizeof (real_sbuild_id));else if (pathname[0 ] =='/' ) - ret =filename__sprintf_build_id (pathname, real_sbuild_id); + ret =filename__snprintf_build_id (pathname, real_sbuild_id,sizeof (real_sbuild_id));else ret = -EINVAL ;/* Should we support other special DSO cache? */ if (ret >=0 )
@@ -243,7 +236,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size,if (!dso__has_build_id (dso))return NULL ; -build_id__sprintf (dso__bid_const (dso), sbuild_id); +build_id__snprintf (dso__bid_const (dso), sbuild_id,sizeof (sbuild_id)); linkname =build_id_cache__linkname (sbuild_id,NULL ,0 );if (!linkname)return NULL ;
@@ -769,7 +762,7 @@ static int build_id_cache__add_b(const struct build_id *bid, {char sbuild_id[SBUILD_ID_SIZE ]; -build_id__sprintf (bid, sbuild_id); +build_id__snprintf (bid, sbuild_id,sizeof (sbuild_id));return __build_id_cache__add_s (sbuild_id, name, nsi, is_kallsyms, is_vdso, proper_name, root_dir);
tools/perf/util/build-id.h +3 -3
@@ -21,10 +21,10 @@ struct feat_fd;struct nsinfo ;void build_id__init (struct build_id *bid,const u8 *data,size_t size); -int build_id__sprintf (const struct build_id *build_id,char *bf); +int build_id__snprintf (const struct build_id *build_id,char *bf,size_t bf_size);bool build_id__is_defined (const struct build_id *bid); -int sysfs__sprintf_build_id (const char *root_dir,char *sbuild_id); -int filename__sprintf_build_id (const char *pathname,char *sbuild_id); +int sysfs__snprintf_build_id (const char *root_dir,char *sbuild_id,size_t sbuild_id_size); +int filename__snprintf_build_id (const char *pathname,char *sbuild_id,size_t sbuild_id_size);char *build_id_cache__kallsyms_path (const char *sbuild_id,char *bf,size_t size);
tools/perf/util/disasm.c +1 -1
@@ -1218,7 +1218,7 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, schar *build_id_msg =NULL ;if (dso__has_build_id (dso)) { -build_id__sprintf (dso__bid (dso), bf +15 ); +build_id__snprintf (dso__bid (dso), bf +15 ,sizeof (bf) -15 ); build_id_msg = bf; } scnprintf(buf, buflen,
tools/perf/util/dso.c +2 -2
@@ -217,7 +217,7 @@ int dso__read_binary_type_filename(const struct dso *dso,break ; } -build_id__sprintf (dso__bid_const (dso), build_id_hex); +build_id__snprintf (dso__bid_const (dso), build_id_hex,sizeof (build_id_hex)); len =__symbol__join_symfs (filename, size,"/usr/lib/debug/.build-id/" );snprintf (filename + len, size - len,"%.2s/%s.debug" , build_id_hex, build_id_hex +2 );
@@ -1704,7 +1704,7 @@ static size_t dso__fprintf_buildid(struct dso *dso, FILE *fp) {char sbuild_id[SBUILD_ID_SIZE ]; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));return fprintf (fp,"%s" , sbuild_id); }
tools/perf/util/dsos.c +1 -1
@@ -373,7 +373,7 @@ static int dsos__fprintf_buildid_cb(struct dso *dso, void *data)if (args->skip && args->skip (dso, args->parm))return 0 ; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id)); args->ret +=fprintf (args->fp,"%-40s %s\n" , sbuild_id,dso__long_name (dso));return 0 ; }
tools/perf/util/event.c +1 -1
@@ -334,7 +334,7 @@ size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp)build_id__init (&bid, event->mmap2.build_id, event->mmap2.build_id_size); -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id)); return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64 " <%s>]: %c%c%c%c %s\n",
tools/perf/util/header.c +1 -1
@@ -2291,7 +2291,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev,free (m.name); } -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));pr_debug ("build id event received for %s: %s [%zu]\n" ,dso__long_name (dso), sbuild_id, size);dso__put (dso);
tools/perf/util/map.c +1 -1
@@ -354,7 +354,7 @@ int map__load(struct map *map)if (dso__has_build_id (dso)) {char sbuild_id[SBUILD_ID_SIZE ]; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));pr_debug ("%s with build id %s not found" , name, sbuild_id); }else pr_debug ("Failed to open %s" , name);
tools/perf/util/probe-file.c +2 -2
@@ -448,10 +448,10 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target,if (!target || !strcmp (target,DSO__NAME_KALLSYMS )) { target =DSO__NAME_KALLSYMS ; is_kallsyms = true; - ret =sysfs__sprintf_build_id ("/" , sbuildid); + ret =sysfs__snprintf_build_id ("/" , sbuildid,sizeof (sbuildid)); }else {nsinfo__mountns_enter (nsi, &nsc); - ret =filename__sprintf_build_id (target, sbuildid); + ret =filename__snprintf_build_id (target, sbuildid,sizeof (sbuildid));nsinfo__mountns_exit (&nsc); }
tools/perf/util/scripting-engines/trace-event-python.c +3 -4
@@ -780,14 +780,13 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al, const char *sym_field, const char *symoff_field, const char *map_pgoff) { - char sbuild_id[SBUILD_ID_SIZE]; - if (al->map) { + char sbuild_id[SBUILD_ID_SIZE];struct dso *dso =map__dso (al->map);pydict_set_item_string_decref (dict, dso_field,_PyUnicode_FromString (dso__name (dso))); -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));pydict_set_item_string_decref (dict, dso_bid_field,_PyUnicode_FromString (sbuild_id)); pydict_set_item_string_decref(dict, dso_map_start,
@@ -1238,7 +1237,7 @@ static int python_export_dso(struct db_export *dbe, struct dso *dso,char sbuild_id[SBUILD_ID_SIZE ];PyObject *t; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id)); t =tuple_new (5 );
tools/perf/util/symbol.c +1 -1
@@ -2151,7 +2151,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map) goto proc_kallsyms; } -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));/* Find kallsyms in build-id cache with kcore */ scnprintf(path, sizeof(path), "%s/%s/%s",
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Namhyung Kim
maintainerRe: [PATCH v5 03/23] perf build-id: Change sprintf functions to snprintf
Quoted 2 lines · Ian Rogers
Pass in a size argument rather than implying all build id strings must be
SBUILD_ID_SIZE.
I got these errors:
CC util/parse-event.outil/probe-event.c: In function '__show_line_range':util/probe-event.c:1093:17: error: implicit declaration of function 'build_id__sprintf'; did you mean 'build_id__snprintf'? [-Wimplicit-function-declaration]
1093 | build_id__sprintf(&bid, sbuild_id);
| ^~~~~~~~~~~~~~~~~
| build_id__snprintf
CC util/parse-finder.o
util/probe-finder.c: In function 'find_probe_point_lazy':
util/probe-finder.c:863:25: error: implicit declaration of function 'build_id__sprintf'; did you mean 'build_id__snprintf'? [-Wimplicit-function-declaration]
863 | build_id__sprintf(&bid, sbuild_id);
| ^~~~~~~~~~~~~~~~~
| build_id__snprintf make[4]: *** [/usr/local/google/home/namhyung/project/linux/tools/build/Makefile.build:86: util/probe-finder.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[4]: *** [/usr/local/google/home/namhyung/project/linux/tools/build/Makefile.build:85: util/probe-event.o] Error 1 make[3]: *** [/usr/local/google/home/namhyung/project/linux/tools/build/Makefile.build:142: util] Error 2 make[2]: *** [Makefile.perf:797: perf-util-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:289: sub-make] Error 2
make: *** [Makefile:76: all] Error 2
Thanks,
Namhyung
Quoted 362 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-buildid-cache.c | 12 +++---- tools/perf/builtin-buildid-list.c | 6 ++-- tools/perf/util/build-id.c | 33 ++++++++----------- tools/perf/util/build-id.h | 6 ++-- tools/perf/util/disasm.c | 2 +- tools/perf/util/dso.c | 4 +-- tools/perf/util/dsos.c | 2 +- tools/perf/util/event.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/map.c | 2 +- tools/perf/util/probe-file.c | 4 +-- .../scripting-engines/trace-event-python.c | 7 ++-- tools/perf/util/symbol.c | 2 +- 13 files changed, 38 insertions(+), 46 deletions(-)tools/perf/builtin-buildid-cache.c +6
-6@@ -31,7 +31,7 @@#include <linux/string.h> #include <linux/err.h> -static int build_id_cache__kcore_buildid (const char *proc_dir,char *sbuildid) +static int build_id_cache__kcore_buildid (const char *proc_dir,char *sbuildid,size_t sbuildid_size) {char root_dir[PATH_MAX ];char *p;@@ -42,7 +42,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)if (!p)return -1 ; *p ='\0' ; -return sysfs__sprintf_build_id (root_dir, sbuildid); +return sysfs__snprintf_build_id (root_dir, sbuildid, sbuildid_size); }static int build_id_cache__kcore_dir (char *dir,size_t sz)@@ -128,7 +128,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)return -1 ; *p ='\0' ; -if (build_id_cache__kcore_buildid (from_dir, sbuildid) <0 ) +if (build_id_cache__kcore_buildid (from_dir, sbuildid,sizeof (sbuildid)) <0 )return -1 ; scnprintf(to_dir, sizeof(to_dir), "%s/%s/%s",@@ -187,7 +187,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)return -1 ; } -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id)); err =build_id_cache__add_s (sbuild_id, filename, nsi, false, false); pr_debug("Adding %s %s: %s\n", sbuild_id, filename,@@ -211,7 +211,7 @@ static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)return -1 ; } -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id)); err =build_id_cache__remove_s (sbuild_id);pr_debug ("Removing %s %s: %s\n" , sbuild_id, filename, err ?"FAIL" :"Ok" );@@ -317,7 +317,7 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi) } err =0 ; -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id));if (build_id_cache__cached (sbuild_id)) err =build_id_cache__remove_s (sbuild_id);tools/perf/builtin-buildid-list.c +3
-3@@ -31,7 +31,7 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused)memset (bid_buf,0 ,sizeof (bid_buf));if (dso__has_build_id (dso)) -build_id__sprintf (dso__bid_const (dso), bid_buf); +build_id__snprintf (dso__bid_const (dso), bid_buf,sizeof (bid_buf));printf ("%s %16" PRIx64" %16" PRIx64, bid_buf,map__start (map),map__end (map));if (dso_long_name !=NULL )printf (" %s" , dso_long_name);@@ -57,7 +57,7 @@ static int sysfs__fprintf_build_id(FILE *fp)char sbuild_id[SBUILD_ID_SIZE ];int ret; - ret =sysfs__sprintf_build_id ("/" , sbuild_id); + ret =sysfs__snprintf_build_id ("/" , sbuild_id,sizeof (sbuild_id));if (ret !=sizeof (sbuild_id))return ret <0 ? ret : -EINVAL ;@@ -69,7 +69,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)char sbuild_id[SBUILD_ID_SIZE ];int ret; - ret =filename__sprintf_build_id (name, sbuild_id); + ret =filename__snprintf_build_id (name, sbuild_id,sizeof (sbuild_id));if (ret !=sizeof (sbuild_id))return ret <0 ? ret : -EINVAL ;tools/perf/util/build-id.c +13
-20@@ -67,24 +67,17 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused,return 0 ; } -int build_id__sprintf (const struct build_id *build_id,char *bf) +int build_id__snprintf (const struct build_id *build_id,char *bf,size_t bf_size) { -char *bid = bf; -const u8 *raw = build_id->data; -size_t i; - - bf[0 ] =0x0 ; +size_t offs =0 ; -for (i =0 ; i < build_id->size; ++i) { -sprintf (bid,"%02x" , *raw); - ++raw; - bid +=2 ; - } +for (size_t i =0 ; i < build_id->size && offs < bf_size; ++i) + offs +=snprintf (bf + offs, bf_size - offs,"%02x" , build_id->data[i]); -return (bid - bf) +1 ; +return offs; } -int sysfs__sprintf_build_id (const char *root_dir,char *sbuild_id) +int sysfs__snprintf_build_id (const char *root_dir,char *sbuild_id,size_t sbuild_id_size) {char notes[PATH_MAX ];struct build_id bid;@@ -99,10 +92,10 @@ int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)if (ret <0 )return ret; -return build_id__sprintf (&bid, sbuild_id); +return build_id__snprintf (&bid, sbuild_id, sbuild_id_size); } -int filename__sprintf_build_id (const char *pathname,char *sbuild_id) +int filename__snprintf_build_id (const char *pathname,char *sbuild_id,size_t sbuild_id_size) {struct build_id bid;int ret;@@ -111,7 +104,7 @@ int filename__sprintf_build_id(const char *pathname, char *sbuild_id)if (ret <0 )return ret; -return build_id__sprintf (&bid, sbuild_id); +return build_id__snprintf (&bid, sbuild_id, sbuild_id_size); }/* asnprintf consolidates asprintf and snprintf */ @@ -212,9 +205,9 @@ static bool build_id_cache__valid_id(char *sbuild_id)return false;if (!strcmp (pathname,DSO__NAME_KALLSYMS )) - ret =sysfs__sprintf_build_id ("/" , real_sbuild_id); + ret =sysfs__snprintf_build_id ("/" , real_sbuild_id,sizeof (real_sbuild_id));else if (pathname[0 ] =='/' ) - ret =filename__sprintf_build_id (pathname, real_sbuild_id); + ret =filename__snprintf_build_id (pathname, real_sbuild_id,sizeof (real_sbuild_id));else ret = -EINVAL ;/* Should we support other special DSO cache? */ if (ret >=0 )@@ -243,7 +236,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size,if (!dso__has_build_id (dso))return NULL ; -build_id__sprintf (dso__bid_const (dso), sbuild_id); +build_id__snprintf (dso__bid_const (dso), sbuild_id,sizeof (sbuild_id)); linkname =build_id_cache__linkname (sbuild_id,NULL ,0 );if (!linkname)return NULL ;@@ -769,7 +762,7 @@ static int build_id_cache__add_b(const struct build_id *bid, {char sbuild_id[SBUILD_ID_SIZE ]; -build_id__sprintf (bid, sbuild_id); +build_id__snprintf (bid, sbuild_id,sizeof (sbuild_id));return __build_id_cache__add_s (sbuild_id, name, nsi, is_kallsyms, is_vdso, proper_name, root_dir);tools/perf/util/build-id.h +3
-3@@ -21,10 +21,10 @@ struct feat_fd;struct nsinfo ;void build_id__init (struct build_id *bid,const u8 *data,size_t size); -int build_id__sprintf (const struct build_id *build_id,char *bf); +int build_id__snprintf (const struct build_id *build_id,char *bf,size_t bf_size);bool build_id__is_defined (const struct build_id *bid); -int sysfs__sprintf_build_id (const char *root_dir,char *sbuild_id); -int filename__sprintf_build_id (const char *pathname,char *sbuild_id); +int sysfs__snprintf_build_id (const char *root_dir,char *sbuild_id,size_t sbuild_id_size); +int filename__snprintf_build_id (const char *pathname,char *sbuild_id,size_t sbuild_id_size);char *build_id_cache__kallsyms_path (const char *sbuild_id,char *bf,size_t size);tools/perf/util/disasm.c +1
-1@@ -1218,7 +1218,7 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, schar *build_id_msg =NULL ;if (dso__has_build_id (dso)) { -build_id__sprintf (dso__bid (dso), bf +15 ); +build_id__snprintf (dso__bid (dso), bf +15 ,sizeof (bf) -15 ); build_id_msg = bf; } scnprintf(buf, buflen,tools/perf/util/dso.c +2
-2@@ -217,7 +217,7 @@ int dso__read_binary_type_filename(const struct dso *dso,break ; } -build_id__sprintf (dso__bid_const (dso), build_id_hex); +build_id__snprintf (dso__bid_const (dso), build_id_hex,sizeof (build_id_hex)); len =__symbol__join_symfs (filename, size,"/usr/lib/debug/.build-id/" );snprintf (filename + len, size - len,"%.2s/%s.debug" , build_id_hex, build_id_hex +2 );@@ -1704,7 +1704,7 @@ static size_t dso__fprintf_buildid(struct dso *dso, FILE *fp) {char sbuild_id[SBUILD_ID_SIZE ]; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));return fprintf (fp,"%s" , sbuild_id); }tools/perf/util/dsos.c +1
-1@@ -373,7 +373,7 @@ static int dsos__fprintf_buildid_cb(struct dso *dso, void *data)if (args->skip && args->skip (dso, args->parm))return 0 ; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id)); args->ret +=fprintf (args->fp,"%-40s %s\n" , sbuild_id,dso__long_name (dso));return 0 ; }tools/perf/util/event.c +1
-1@@ -334,7 +334,7 @@ size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp)build_id__init (&bid, event->mmap2.build_id, event->mmap2.build_id_size); -build_id__sprintf (&bid, sbuild_id); +build_id__snprintf (&bid, sbuild_id,sizeof (sbuild_id)); return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64 " <%s>]: %c%c%c%c %s\n",tools/perf/util/header.c +1
-1@@ -2291,7 +2291,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev,free (m.name); } -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));pr_debug ("build id event received for %s: %s [%zu]\n" ,dso__long_name (dso), sbuild_id, size);dso__put (dso);tools/perf/util/map.c +1
-1@@ -354,7 +354,7 @@ int map__load(struct map *map)if (dso__has_build_id (dso)) {char sbuild_id[SBUILD_ID_SIZE ]; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));pr_debug ("%s with build id %s not found" , name, sbuild_id); }else pr_debug ("Failed to open %s" , name);tools/perf/util/probe-file.c +2
-2@@ -448,10 +448,10 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target,if (!target || !strcmp (target,DSO__NAME_KALLSYMS )) { target =DSO__NAME_KALLSYMS ; is_kallsyms = true; - ret =sysfs__sprintf_build_id ("/" , sbuildid); + ret =sysfs__snprintf_build_id ("/" , sbuildid,sizeof (sbuildid)); }else {nsinfo__mountns_enter (nsi, &nsc); - ret =filename__sprintf_build_id (target, sbuildid); + ret =filename__snprintf_build_id (target, sbuildid,sizeof (sbuildid));nsinfo__mountns_exit (&nsc); }tools/perf/util/scripting-engines/trace-event-python.c +3
-4@@ -780,14 +780,13 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al, const char *sym_field, const char *symoff_field, const char *map_pgoff) { - char sbuild_id[SBUILD_ID_SIZE]; - if (al->map) { + char sbuild_id[SBUILD_ID_SIZE];struct dso *dso =map__dso (al->map);pydict_set_item_string_decref (dict, dso_field,_PyUnicode_FromString (dso__name (dso))); -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));pydict_set_item_string_decref (dict, dso_bid_field,_PyUnicode_FromString (sbuild_id)); pydict_set_item_string_decref(dict, dso_map_start,@@ -1238,7 +1237,7 @@ static int python_export_dso(struct db_export *dbe, struct dso *dso,char sbuild_id[SBUILD_ID_SIZE ];PyObject *t; -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id)); t =tuple_new (5 );tools/perf/util/symbol.c +1
-1@@ -2151,7 +2151,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map) goto proc_kallsyms; } -build_id__sprintf (dso__bid (dso), sbuild_id); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id));/* Find kallsyms in build-id cache with kcore */ scnprintf(path, sizeof(path), "%s/%s/%s",Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 4/23 perf build-id: Mark DSO in sample callchains
In reply to Ian RogersPreviously only the sample IP's map DSO would be marked hit for the purposes of populating the build ID cache. Walk the call chain to mark all IPs and DSOs.
--- tools/perf/util/build-id.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
tools/perf/util/build-id.c +16 -1
@@ -42,10 +42,20 @@static bool no_buildid_cache; +static int mark_dso_hit_callback (struct callchain_cursor_node *node,void *data__maybe_unused ) +{ +struct map *map = node->ms.map; + +if (map) +dso__set_hit (map__dso (map)); + +return 0 ; +} +int build_id__mark_dso_hit (const struct perf_tool *tool__maybe_unused ,union perf_event *event,struct perf_sample *sample, -struct evsel *evsel__maybe_unused , +struct evsel *evsel,struct machine *machine) {struct addr_location al;
@@ -63,6 +73,11 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused,dso__set_hit (map__dso (al.map));addr_location__exit (&al); + +sample__for_each_callchain_node (thread, evsel, sample,PERF_MAX_STACK_DEPTH , +/*symbols=*/ false, mark_dso_hit_callback,/*data=*/ NULL ); + +thread__put (thread);return 0 ; }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 5/23 perf build-id: Ensure struct build_id is empty before use
In reply to Ian RogersIf a build ID is read then not all code paths may ensure it is empty before use. Initialize the build_id to be zero-ed unless there is clear initialization such as a call to build_id__init.
--- tools/perf/bench/inject-buildid.c | 2 +- tools/perf/builtin-buildid-cache.c | 8 ++++---- tools/perf/tests/pe-file-parsing.c | 2 +- tools/perf/tests/sdt.c | 2 +- tools/perf/util/build-id.c | 6 +++--- tools/perf/util/debuginfo.c | 2 +- tools/perf/util/probe-event.c | 3 ++- tools/perf/util/probe-finder.c | 3 ++- tools/perf/util/symbol-minimal.c | 2 +- tools/perf/util/symbol.c | 5 +++-- tools/perf/util/synthetic-events.c | 2 +- 11 files changed, 20 insertions(+), 17 deletions(-)
tools/perf/bench/inject-buildid.c +1 -1
@@ -80,7 +80,7 @@ static int add_dso(const char *fpath, const struct stat *sb __maybe_unused, int typeflag, struct FTW *ftwbuf __maybe_unused) { struct bench_dso *dso = &dsos[nr_dsos]; -struct build_id bid; +struct build_id bid = { .size =0 , };if (typeflag ==FTW_D || typeflag ==FTW_SL )return 0 ;
tools/perf/builtin-buildid-cache.c +4 -4
@@ -175,7 +175,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)static int build_id_cache__add_file (const char *filename,struct nsinfo *nsi) {char sbuild_id[SBUILD_ID_SIZE ]; -struct build_id bid; +struct build_id bid = { .size =0 , };int err;struct nscookie nsc;
@@ -198,7 +198,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)static int build_id_cache__remove_file (const char *filename,struct nsinfo *nsi) {char sbuild_id[SBUILD_ID_SIZE ]; -struct build_id bid; +struct build_id bid = { .size =0 , };struct nscookie nsc;int err;
@@ -275,7 +275,7 @@ static int build_id_cache__purge_all(void)static bool dso__missing_buildid_cache (struct dso *dso,int parm__maybe_unused ) {char filename[PATH_MAX ]; -struct build_id bid; +struct build_id bid = { .size =0 , };if (!dso__build_id_filename (dso, filename,sizeof (filename), false))return true;
@@ -303,7 +303,7 @@ static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *fstatic int build_id_cache__update_file (const char *filename,struct nsinfo *nsi) {char sbuild_id[SBUILD_ID_SIZE ]; -struct build_id bid; +struct build_id bid = { .size =0 , };struct nscookie nsc;int err;
tools/perf/tests/pe-file-parsing.c +1 -1
@@ -24,7 +24,7 @@ static int run_dir(const char *d) {char filename[PATH_MAX ];char debugfile[PATH_MAX ]; -struct build_id bid; +struct build_id bid = { .size =0 , };char debuglink[PATH_MAX ];char expect_build_id[] = {0x5a ,0x0f ,0xd8 ,0x82 ,0xb5 ,0x30 ,0x84 ,0x22 ,
tools/perf/tests/sdt.c +1 -1
@@ -28,7 +28,7 @@ static int target_function(void)static int build_id_cache__add_file (const char *filename) {char sbuild_id[SBUILD_ID_SIZE ]; -struct build_id bid; +struct build_id bid = { .size =0 , };int err; err =filename__read_build_id (filename, &bid);
tools/perf/util/build-id.c +3 -3
@@ -95,7 +95,7 @@ int build_id__snprintf(const struct build_id *build_id, char *bf, size_t bf_sizeint sysfs__snprintf_build_id (const char *root_dir,char *sbuild_id,size_t sbuild_id_size) {char notes[PATH_MAX ]; -struct build_id bid; +struct build_id bid = { .size =0 , };int ret;if (!root_dir)
@@ -112,7 +112,7 @@ int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t sbuilint filename__snprintf_build_id (const char *pathname,char *sbuild_id,size_t sbuild_id_size) { -struct build_id bid; +struct build_id bid = { .size =0 , };int ret; ret =filename__read_build_id (pathname, &bid);
@@ -849,7 +849,7 @@ static int filename__read_build_id_ns(const char *filename,static bool dso__build_id_mismatch (struct dso *dso,const char *name) { -struct build_id bid; +struct build_id bid = { .size =0 , };bool ret = false;mutex_lock (dso__lock (dso));
tools/perf/util/debuginfo.c +1 -1
@@ -103,7 +103,7 @@ struct debuginfo *debuginfo__new(const char *path)char buf[PATH_MAX ], nil ='\0' ;struct dso *dso;struct debuginfo *dinfo =NULL ; -struct build_id bid; +struct build_id bid = { .size =0 };/* Try to open distro debuginfo files */ dso =dso__new (path);
tools/perf/util/probe-event.c +2 -1
@@ -1063,7 +1063,6 @@ static int sprint_line_description(char *sbuf, size_t size, struct line_range *lstatic int __show_line_range (struct line_range *lr,const char *module,bool user) { -struct build_id bid;int l =1 ;struct int_node *ln;struct debuginfo *dinfo;
@@ -1088,6 +1087,8 @@ static int __show_line_range(struct line_range *lr, const char *module, ret = -ENOENT ; }if (dinfo->build_id) { +struct build_id bid; +build_id__init (&bid, dinfo->build_id,BUILD_ID_SIZE );build_id__sprintf (&bid, sbuild_id); }
tools/perf/util/probe-finder.c +2 -1
@@ -848,7 +848,6 @@ static int probe_point_lazy_walker(const char *fname, int lineno,/* Find probe points from lazy pattern */ static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) { -struct build_id bid;char sbuild_id[SBUILD_ID_SIZE ] ="" ;int ret =0 ;char *fpath;
@@ -858,6 +857,8 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) comp_dir =cu_get_comp_dir (&pf->cu_die);if (pf->dbg->build_id) { +struct build_id bid; +build_id__init (&bid, pf->dbg->build_id,BUILD_ID_SIZE );build_id__sprintf (&bid, sbuild_id); }
tools/perf/util/symbol-minimal.c +1 -1
@@ -317,7 +317,7 @@ int dso__load_sym(struct dso *dso, struct map *map __maybe_unused, struct symsrc *runtime_ss __maybe_unused, int kmodule __maybe_unused) { -struct build_id bid; +struct build_id bid = { .size =0 , };int ret; ret =fd__is_64_bit (ss->fd);
tools/perf/util/symbol.c +3 -2
@@ -1812,7 +1812,6 @@ int dso__load(struct dso *dso, struct map *map)struct symsrc *syms_ss =NULL , *runtime_ss =NULL ;bool kmod;bool perfmap; -struct build_id bid;struct nscookie nsc;char newmapname[PATH_MAX ];const char *map_path =dso__long_name (dso);
@@ -1873,6 +1872,8 @@ int dso__load(struct dso *dso, struct map *map)*/ if (!dso__has_build_id (dso) &&is_regular_file (dso__long_name (dso))) { +struct build_id bid = { .size =0 , }; +__symbol__join_symfs (name,PATH_MAX ,dso__long_name (dso));if (filename__read_build_id (name, &bid) >0 )dso__set_build_id (dso, &bid);
@@ -2121,7 +2122,7 @@ static bool filename__readable(const char *file)static char *dso__find_kallsyms (struct dso *dso,struct map *map) { -struct build_id bid; +struct build_id bid = { .size =0 , };char sbuild_id[SBUILD_ID_SIZE ];bool is_host = false;char path[PATH_MAX ];
tools/perf/util/synthetic-events.c +1 -1
@@ -368,7 +368,7 @@ static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event, struct machine *machine, bool is_kernel) { -struct build_id bid; +struct build_id bid = { .size =0 , };struct nsinfo *nsi;struct nscookie nc;struct dso *dso =NULL ;
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 6/23 perf dso: Move build_id to dso_id
In reply to Ian RogersThe dso_id previously contained the major, minor, inode and inode generation information from a mmap2 event - the inode generation would be zero when reading from /proc/pid/maps. The build_id was in the dso. With build ID mmap2 events these fields wouldn't be initialized which would largely mean the special empty case where any dso would match for equality. This isn't desirable as if a dso is replaced we want the comparison to yield a difference.
To support detecting the difference between DSOs based on build_id, move the build_id out of the DSO and into the dso_id. The dso_id is also stored in the DSO so nothing is lost. Capture in the dso_id what parts have been initialized and rename dso_id__inject to dso_id__improve_id so that it is clear the dso_id is being improved upon with additional information. With the build_id in the dso_id, use memcmp to compare for equality.
--- tools/perf/builtin-buildid-list.c | 2 +- tools/perf/builtin-inject.c | 36 ++++---- tools/perf/builtin-report.c | 11 ++- tools/perf/include/perf/perf_dlfilter.h | 2 +- tools/perf/tests/symbols.c | 4 +- tools/perf/util/build-id.c | 4 +- tools/perf/util/dso.c | 109 +++++++++++++----------- tools/perf/util/dso.h | 75 ++++++++-------- tools/perf/util/dsos.c | 18 ++-- tools/perf/util/machine.c | 28 +++--- tools/perf/util/map.c | 13 ++- tools/perf/util/map.h | 5 +- tools/perf/util/sort.c | 27 +++--- tools/perf/util/synthetic-events.c | 18 ++-- 14 files changed, 197 insertions(+), 155 deletions(-)
tools/perf/builtin-buildid-list.c +1 -1
@@ -31,7 +31,7 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused)memset (bid_buf,0 ,sizeof (bid_buf));if (dso__has_build_id (dso)) -build_id__snprintf (dso__bid_const (dso), bid_buf,sizeof (bid_buf)); +build_id__snprintf (dso__bid (dso), bid_buf,sizeof (bid_buf));printf ("%s %16" PRIx64" %16" PRIx64, bid_buf,map__start (map),map__end (map));if (dso_long_name !=NULL )printf (" %s" , dso_long_name);
tools/perf/builtin-inject.c +21 -15
@@ -587,15 +587,17 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool,struct perf_sample *sample, struct machine *machine) { - struct dso_id id; -struct dso_id *dso_id =NULL ; + struct dso_id id = dso_id_empty; -if (!(event->header.misc &PERF_RECORD_MISC_MMAP_BUILD_ID )) { +if (event->header.misc &PERF_RECORD_MISC_MMAP_BUILD_ID ) { +build_id__init (&id.build_id, event->mmap2.build_id, event->mmap2.build_id_size); + }else { id.maj = event->mmap2.maj; id.min = event->mmap2.min; id.ino = event->mmap2.ino; id.ino_generation = event->mmap2.ino_generation; - dso_id = &id; + id.mmap2_valid = true; + id.mmap2_ino_generation_valid = true; } return perf_event__repipe_common_mmap(
@@ -603,7 +605,7 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool, event->mmap2.pid, event->mmap2.tid, event->mmap2.start, event->mmap2.len, event->mmap2.pgoff, event->mmap2.flags, event->mmap2.prot, - event->mmap2.filename, dso_id, + event->mmap2.filename, &id, perf_event__process_mmap2); }
@@ -671,19 +673,20 @@ static int perf_event__repipe_tracing_data(struct perf_session *session,static int dso__read_build_id (struct dso *dso) {struct nscookie nsc; +struct build_id bid = { .size =0 , };if (dso__has_build_id (dso))return 0 ;mutex_lock (dso__lock (dso));nsinfo__mountns_enter (dso__nsinfo (dso), &nsc); -if (filename__read_build_id (dso__long_name (dso),dso__bid (dso)) >0 ) -dso__set_has_build_id (dso); +if (filename__read_build_id (dso__long_name (dso), &bid) >0 ) +dso__set_build_id (dso, &bid);else if (dso__nsinfo (dso)) {char *new_name =dso__filename_with_chroot (dso,dso__long_name (dso)); -if (new_name &&filename__read_build_id (new_name,dso__bid (dso)) >0 ) -dso__set_has_build_id (dso); +if (new_name &&filename__read_build_id (new_name, &bid) >0 ) +dso__set_build_id (dso, &bid);free (new_name); }nsinfo__mountns_exit (&nsc);
@@ -732,23 +735,26 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject, struct dso *dso) {struct str_node *pos; -int bid_len;strlist__for_each_entry (pos, inject->known_build_ids) { +struct build_id bid;const char *build_id, *dso_name; +size_t bid_len; build_id =skip_spaces (pos->s); dso_name =strchr (build_id,' ' ); bid_len = dso_name - pos->s; +if (bid_len >sizeof (bid.data)) + bid_len =sizeof (bid.data); dso_name =skip_spaces (dso_name);if (strcmp (dso__long_name (dso), dso_name))continue ; -for (int ix =0 ;2 * ix +1 < bid_len; ++ix) { -dso__bid (dso)->data[ix] = (hex (build_id[2 * ix]) <<4 | -hex (build_id[2 * ix +1 ])); +for (size_t ix =0 ;2 * ix +1 < bid_len; ++ix) { + bid.data[ix] = (hex (build_id[2 * ix]) <<4 | +hex (build_id[2 * ix +1 ])); } -dso__bid (dso)->size = bid_len /2 ; -dso__set_has_build_id (dso); + bid.size = bid_len /2 ; +dso__set_build_id (dso, &bid);return true; }return false;
tools/perf/builtin-report.c +9 -2
@@ -861,17 +861,24 @@ static int maps__fprintf_task_cb(struct map *map, void *data)struct maps__fprintf_task_args *args = data;const struct dso *dso =map__dso (map);u32 prot =map__prot (map); +const struct dso_id *dso_id =dso__id_const (dso);int ret; +char buf[SBUILD_ID_SIZE ]; + +if (dso_id->mmap2_valid) +snprintf (buf,sizeof (buf),"%" PRIu64, dso_id->ino); +else +build_id__snprintf (&dso_id->build_id, buf,sizeof (buf)); ret =fprintf (args->fp, -"%*s %" PRIx64"-%" PRIx64" %c%c%c%c %08" PRIx64" %" PRIu64" %s\n" , +"%*s %" PRIx64"-%" PRIx64" %c%c%c%c %08" PRIx64" %s %s\n" , args->indent,"" ,map__start (map),map__end (map), prot &PROT_READ ?'r' :'-' , prot &PROT_WRITE ?'w' :'-' , prot &PROT_EXEC ?'x' :'-' ,map__flags (map) ?'s' :'p' ,map__pgoff (map), -dso__id_const (dso)->ino,dso__name (dso)); + buf,dso__name (dso));if (ret <0 )return ret;
tools/perf/include/perf/perf_dlfilter.h +1 -1
@@ -87,7 +87,7 @@ struct perf_dlfilter_al {__u8 is_64_bit;/* Only valid if dso is not NULL */ __u8 is_kernel_ip;/* True if in kernel space */ __u32 buildid_size; -__u8 *buildid; +const __u8 *buildid;/* Below members are only populated by resolve_ip() */ __u8 filtered;/* True if this sample event will be filtered out */ const char *comm;
tools/perf/tests/symbols.c +2 -2
@@ -96,8 +96,8 @@ static int create_map(struct test_info *ti, char *filename, struct map **map_p)dso__put (dso);/* Create a dummy map at 0x100000 */ - *map_p =map__new (ti->machine,0x100000 ,0xffffffff ,0 ,NULL , -PROT_EXEC ,0 ,NULL , filename, ti->thread); + *map_p =map__new (ti->machine,0x100000 ,0xffffffff ,0 , &dso_id_empty, +PROT_EXEC ,/*flags=*/ 0 , filename, ti->thread);if (!*map_p) {pr_debug ("Failed to create map!" );return TEST_FAIL ;
tools/perf/util/build-id.c +2 -2
@@ -251,7 +251,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size,if (!dso__has_build_id (dso))return NULL ; -build_id__snprintf (dso__bid_const (dso), sbuild_id,sizeof (sbuild_id)); +build_id__snprintf (dso__bid (dso), sbuild_id,sizeof (sbuild_id)); linkname =build_id_cache__linkname (sbuild_id,NULL ,0 );if (!linkname)return NULL ;
@@ -334,7 +334,7 @@ static int machine__write_buildid_table_cb(struct dso *dso, void *data) } in_kernel =dso__kernel (dso) ||is_kernel_module (name,PERF_RECORD_MISC_CPUMODE_UNKNOWN ); -return write_buildid (name, name_len,dso__bid (dso), args->machine->pid, +return write_buildid (name, name_len, &dso__id (dso)->build_id, args->machine->pid, in_kernel ? args->kmisc : args->umisc, args->fd); }
tools/perf/util/dso.c +60 -49
180 lines not on this page · raw message
tools/perf/util/dso.h +41 -34
136 lines not on this page · raw message
tools/perf/util/dsos.c +10 -8
@@ -72,6 +72,7 @@ static int dsos__read_build_ids_cb(struct dso *dso, void *data) {struct dsos__read_build_ids_cb_args *args = data;struct nscookie nsc; +struct build_id bid = { .size =0 , };if (args->with_hits && !dso__hit (dso) && !dso__is_vdso (dso))return 0 ;
@@ -80,15 +81,15 @@ static int dsos__read_build_ids_cb(struct dso *dso, void *data)return 0 ; }nsinfo__mountns_enter (dso__nsinfo (dso), &nsc); -if (filename__read_build_id (dso__long_name (dso),dso__bid (dso)) >0 ) { +if (filename__read_build_id (dso__long_name (dso), &bid) >0 ) { +dso__set_build_id (dso, &bid); args->have_build_id = true; -dso__set_has_build_id (dso); }else if (errno ==ENOENT &&dso__nsinfo (dso)) {char *new_name =dso__filename_with_chroot (dso,dso__long_name (dso)); -if (new_name &&filename__read_build_id (new_name,dso__bid (dso)) >0 ) { +if (new_name &&filename__read_build_id (new_name, &bid) >0 ) { +dso__set_build_id (dso, &bid); args->have_build_id = true; -dso__set_has_build_id (dso); }free (new_name); }
@@ -286,7 +287,7 @@ struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short)struct dso *res;down_read (&dsos->lock); - res =__dsos__find_id (dsos, name,NULL , cmp_short,/*write_locked=*/ false); + res =__dsos__find_id (dsos, name, &dso_id_empty, cmp_short,/*write_locked=*/ false);up_read (&dsos->lock);return res; }
@@ -344,8 +345,8 @@ static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name, const {struct dso *dso =__dsos__find_id (dsos, name, id, false,/*write_locked=*/ true); -if (dso &&dso_id__empty (dso__id (dso)) && !dso_id__empty (id)) -__dso__inject_id (dso, id); +if (dso) +__dso__improve_id (dso, id);return dso ? dso :__dsos__addnew_id (dsos, name, id); }
@@ -436,7 +437,8 @@ struct dso *dsos__findnew_module_dso(struct dsos *dsos,down_write (&dsos->lock); - dso =__dsos__find_id (dsos, m->name,NULL ,/*cmp_short=*/ true,/*write_locked=*/ true); + dso =__dsos__find_id (dsos, m->name, &dso_id_empty,/*cmp_short=*/ true, +/*write_locked=*/ true);if (dso) {up_write (&dsos->lock);return dso;
tools/perf/util/machine.c +14 -14
@@ -1731,21 +1731,21 @@ int machine__process_mmap2_event(struct machine *machine, {struct thread *thread;struct map *map; -struct dso_id dso_id = { - .maj = event->mmap2.maj, - .min = event->mmap2.min, - .ino = event->mmap2.ino, - .ino_generation = event->mmap2.ino_generation, - }; -struct build_id __bid, *bid =NULL ; +struct dso_id dso_id = dso_id_empty;int ret =0 ;if (dump_trace)perf_event__fprintf_mmap2 (event, stdout);if (event->header.misc &PERF_RECORD_MISC_MMAP_BUILD_ID ) { - bid = &__bid; -build_id__init (bid, event->mmap2.build_id, event->mmap2.build_id_size); +build_id__init (&dso_id.build_id, event->mmap2.build_id, event->mmap2.build_id_size); + }else { + dso_id.maj = event->mmap2.maj; + dso_id.min = event->mmap2.min; + dso_id.ino = event->mmap2.ino; + dso_id.ino_generation = event->mmap2.ino_generation; + dso_id.mmap2_valid = true; + dso_id.mmap2_ino_generation_valid = true; } if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
@@ -1757,7 +1757,7 @@ int machine__process_mmap2_event(struct machine *machine, };strlcpy (xm.name, event->mmap2.filename,KMAP_NAME_LEN ); - ret =machine__process_kernel_mmap_event (machine, &xm, bid); + ret =machine__process_kernel_mmap_event (machine, &xm, &dso_id.build_id);if (ret <0 ) goto out_problem;return 0 ;
@@ -1771,7 +1771,7 @@ int machine__process_mmap2_event(struct machine *machine, map =map__new (machine, event->mmap2.start, event->mmap2.len, event->mmap2.pgoff, &dso_id, event->mmap2.prot, - event->mmap2.flags, bid, + event->mmap2.flags, event->mmap2.filename, thread);if (map ==NULL )
@@ -1829,8 +1829,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event prot =PROT_EXEC ; map =map__new (machine, event->mmap.start, - event->mmap.len, event->mmap.pgoff, -NULL , prot,0 ,NULL , event->mmap.filename, thread); + event->mmap.len, event->mmap.pgoff, + &dso_id_empty, prot,/*flags=*/ 0 , event->mmap.filename, thread);if (map ==NULL ) goto out_problem_map;
@@ -3192,7 +3192,7 @@ struct dso *machine__findnew_dso_id(struct machine *machine, const char *filenamstruct dso *machine__findnew_dso (struct machine *machine,const char *filename) { -return machine__findnew_dso_id (machine, filename,NULL ); +return machine__findnew_dso_id (machine, filename, &dso_id_empty); }char *machine__resolve_kernel_addr (void *vmachine,unsigned long long *addrp,char **modp)
tools/perf/util/map.c +6 -7
@@ -120,8 +120,8 @@ static void map__init(struct map *map, u64 start, u64 end, u64 pgoff, }struct map *map__new (struct machine *machine,u64 start,u64 len, -u64 pgoff,struct dso_id *id, -u32 prot,u32 flags,struct build_id *bid, +u64 pgoff,const struct dso_id *id, +u32 prot,u32 flags,char *filename,struct thread *thread) {struct map *result;
@@ -132,7 +132,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, map =zalloc (sizeof (*map));if (ADD_RC_CHK (result, map)) {char newfilename[PATH_MAX ]; -struct dso *dso, *header_bid_dso; +struct dso *dso;int anon, no_dso, vdso, android; android =is_android_lib (filename);
@@ -189,16 +189,15 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,dso__set_nsinfo (dso, nsi);mutex_unlock (dso__lock (dso)); -if (build_id__is_defined (bid)) { -dso__set_build_id (dso, bid); - }else { +if (!build_id__is_defined (&id->build_id)) {/* * If the mmap event had no build ID, search for an existing dso from the * build ID header by name. Otherwise only the dso loaded at the time of * reading the header will have the build ID set and all future mmaps will * have it missing. */ - header_bid_dso =dsos__find (&machine->dsos, filename, false); +struct dso *header_bid_dso =dsos__find (&machine->dsos, filename, false); +if (header_bid_dso &&dso__header_build_id (header_bid_dso)) {dso__set_build_id (dso,dso__bid (header_bid_dso));dso__set_header_build_id (dso,1 );
tools/perf/util/map.h +2 -3
@@ -173,11 +173,10 @@ struct thread;__map__for_each_symbol_by_name (map, sym_name, (pos), idx) struct dso_id; -struct build_id ;struct map *map__new (struct machine *machine,u64 start,u64 len, -u64 pgoff,struct dso_id *id,u32 prot,u32 flags, -struct build_id *bid,char *filename,struct thread *thread); +u64 pgoff,const struct dso_id *id,u32 prot,u32 flags, +char *filename,struct thread *thread);struct map *map__new2 (u64 start,struct dso *dso);void map__delete (struct map *map);struct map *map__clone (struct map *map);
tools/perf/util/sort.c +16 -11
@@ -1746,22 +1746,27 @@ sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right)if (rc)return rc;/* -* Addresses with no major/minor numbers are assumed to be +* Addresses with no major/minor numbers or build ID are assumed to be * anonymous in userspace. Sort those on pid then address. * * The kernel and non-zero major/minor mapped areas are * assumed to be unity mapped. Sort those on address. */ +if (left->cpumode !=PERF_RECORD_MISC_KERNEL && (map__flags (l_map) &MAP_SHARED ) ==0 ) { +const struct dso_id *dso_id =dso__id_const (l_dso); -if ((left->cpumode !=PERF_RECORD_MISC_KERNEL ) && - (!(map__flags (l_map) &MAP_SHARED )) && !dso__id (l_dso)->maj && !dso__id (l_dso)->min && - !dso__id (l_dso)->ino && !dso__id (l_dso)->ino_generation) { -/* userspace anonymous */ +if (!dso_id->mmap2_valid) + dso_id =dso__id_const (r_dso); -if (thread__pid (left->thread) >thread__pid (right->thread)) -return -1 ; -if (thread__pid (left->thread) <thread__pid (right->thread)) -return 1 ; +if (!build_id__is_defined (&dso_id->build_id) && + (!dso_id->mmap2_valid || (dso_id->maj ==0 && dso_id->min ==0 ))) { +/* userspace anonymous */ + +if (thread__pid (left->thread) >thread__pid (right->thread)) +return -1 ; +if (thread__pid (left->thread) <thread__pid (right->thread)) +return 1 ; + } } addr:
@@ -1786,6 +1791,7 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf,if (he->mem_info) {struct map *map =mem_info__daddr (he->mem_info)->ms.map;struct dso *dso = map ?map__dso (map) :NULL ; +const struct dso_id *dso_id = dso ?dso__id_const (dso) : &dso_id_empty; addr =cl_address (mem_info__daddr (he->mem_info)->al_addr, chk_double_cl); ms = &mem_info__daddr (he->mem_info)->ms;
@@ -1794,8 +1800,7 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf,if ((he->cpumode !=PERF_RECORD_MISC_KERNEL ) && map && !(map__prot (map) &PROT_EXEC ) && (map__flags (map) &MAP_SHARED ) && - (dso__id (dso)->maj ||dso__id (dso)->min ||dso__id (dso)->ino || -dso__id (dso)->ino_generation)) + (!dso_id->mmap2_valid || (dso_id->maj ==0 && dso_id->min ==0 ))) level ='s' ;else if (!map) level ='X' ;
tools/perf/util/synthetic-events.c +12 -6
@@ -372,7 +372,7 @@ static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event,struct nsinfo *nsi;struct nscookie nc;struct dso *dso =NULL ; -struct dso_id id; +struct dso_id dso_id = dso_id_empty;int rc;if (is_kernel) {
@@ -380,12 +380,18 @@ static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event, goto out; } - id.maj = event->maj; - id.min = event->min; - id.ino = event->ino; - id.ino_generation = event->ino_generation; +if (event->header.misc &PERF_RECORD_MISC_MMAP_BUILD_ID ) { +build_id__init (&dso_id.build_id, event->build_id, event->build_id_size); + }else { + dso_id.maj = event->maj; + dso_id.min = event->min; + dso_id.ino = event->ino; + dso_id.ino_generation = event->ino_generation; + dso_id.mmap2_valid = true; + dso_id.mmap2_ino_generation_valid = true; + }; - dso =dsos__findnew_id (&machine->dsos, event->filename, &id); + dso =dsos__findnew_id (&machine->dsos, event->filename, &dso_id);if (dso &&dso__has_build_id (dso)) { bid = *dso__bid (dso); rc =0 ;
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 7/23 perf jitdump: Directly mark the jitdump DSO
In reply to Ian RogersThe DSO being generated was being accessed through a thread's maps, this is unnecessary as the dso can just be directly found. This avoids problems with passing a NULL evsel which may be inspected to determine properties of a callchain when using the buildid DSO marking code.
--- tools/perf/util/jitdump.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
tools/perf/util/jitdump.c +17 -4
@@ -14,9 +14,9 @@#include <sys/mman.h> #include <linux/stringify.h> -#include "build-id.h" #include "event.h" #include "debug.h" +#include "dso.h" #include "evlist.h" #include "namespaces.h" #include "symbol.h"
@@ -531,9 +531,22 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)/* * mark dso as use to generate buildid in the header */ -if (!ret) -build_id__mark_dso_hit (tool, event, &sample,NULL , jd->machine); - +if (!ret) { +struct dso_id dso_id = { + { + .maj = event->mmap2.maj, + .min = event->mmap2.min, + .ino = event->mmap2.ino, + .ino_generation = event->mmap2.ino_generation, + }, + .mmap2_valid = true, + .mmap2_ino_generation_valid = true, + }; +struct dso *dso =machine__findnew_dso_id (jd->machine, filename, &dso_id); + +if (dso) +dso__set_hit (dso); + } out:perf_sample__exit (&sample);free (event);
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 8/23 perf record: Make --buildid-mmap the default
In reply to Ian RogersSupport for build IDs in mmap2 perf events has been present since Linux v5.12:
https://lore.kernel.org/lkml/[email protected]/
Build ID mmap events don't avoid the need to inject build IDs for DSO touched by samples as the build ID cache is populated by perf record. They can avoid some cases of symbol mis-resolution caused by the file system changing from when a sample occurred and when the DSO is sought. To disable build ID scanning
Unlike the --buildid-mmap option, this doesn't disable the build ID cache but it does disable the processing of samples looking for DSOs to inject build IDs for. To disable the build ID cache the -B (--no-buildid) option should be used.
Making this option the default was raised on the list in:
https://lore.kernel.org/linux-perf-users/CAP-5=fXP7jN_QrGUcd55_QH5J-Y-FCaJ6=NaHVtyx0oyNh8_-Q@mail.gmail.com/
--- tools/perf/builtin-record.c | 33 +++++++++++++++++++----------- tools/perf/util/symbol_conf.h | 2 +- tools/perf/util/synthetic-events.c | 16 +++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-)
tools/perf/builtin-record.c +21 -12
@@ -171,6 +171,7 @@ struct record {bool no_buildid_cache_set;bool buildid_all;bool buildid_mmap; +bool buildid_mmap_set;bool timestamp_filename;bool timestamp_boundary;bool off_cpu;
@@ -1811,6 +1812,7 @@ record__finish_output(struct record *rec) data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); } +/* Buildid scanning disabled or build ID in kernel and synthesized map events. */ if (!rec->no_buildid) {process_buildids (rec);
@@ -3005,6 +3007,8 @@ static int perf_record_config(const char *var, const char *value, void *cb) rec->no_buildid = true; else if (!strcmp(value, "mmap")) rec->buildid_mmap = true; + else if (!strcmp(value, "no-mmap")) + rec->buildid_mmap = false; else return -1;return 0 ;
@@ -3411,6 +3415,7 @@ static struct record record = { .synth = PERF_SYNTH_ALL, .off_cpu_thresh_ns = OFFCPU_THRESH, }, + .buildid_mmap = true, };const char record_callchain_help[] =CALLCHAIN_RECORD_HELP
@@ -3577,8 +3582,8 @@ static struct option __record_options[] = { "file", "vmlinux pathname"),OPT_BOOLEAN (0 ,"buildid-all" , &record.buildid_all,"Record build-id of all DSOs regardless of hits" ), -OPT_BOOLEAN (0 ,"buildid-mmap" , &record.buildid_mmap, -"Record build-id in map events" ), +OPT_BOOLEAN_SET (0 ,"buildid-mmap" , &record.buildid_mmap, &record.buildid_mmap_set, +"Legacy record build-id in map events option which is now the default. Behaves indentically to --no-buildid. Disable with --no-buildid-mmap" ),OPT_BOOLEAN (0 ,"timestamp-filename" , &record.timestamp_filename,"append timestamp to output filename" ), OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
@@ -4108,19 +4113,23 @@ int cmd_record(int argc, const char **argv) record.opts.record_switch_events = true; } +if (!rec->buildid_mmap) { +pr_debug ("Disabling build id in synthesized mmap2 events.\n" ); + symbol_conf.no_buildid_mmap2 = true; + }else if (rec->buildid_mmap_set) { +/* +* Explicitly passing --buildid-mmap disables buildid processing +* and cache generation. +*/ + rec->no_buildid = true; + } +if (rec->buildid_mmap && !perf_can_record_build_id ()) { +pr_warning ("Missing support for build id in kernel mmap events. Disable this warning with --no-buildid-mmap\n" ); + rec->buildid_mmap = false; + }if (rec->buildid_mmap) { -if (!perf_can_record_build_id ()) { -pr_err ("Failed: no support to record build id in mmap events, update your kernel.\n" ); - err = -EINVAL ; - goto out_opts; - } -pr_debug ("Enabling build id in mmap2 events.\n" ); -/* Enable mmap build id synthesizing. */ - symbol_conf.buildid_mmap2 = true;/* Enable perf_event_attr::build_id bit. */ rec->opts.build_id = true; -/* Disable build id cache. */ - rec->no_buildid = true; }if (rec->opts.record_cgroup && !perf_can_record_cgroup ()) {
tools/perf/util/symbol_conf.h +1 -1
@@ -43,7 +43,7 @@ struct symbol_conf { report_individual_block, inline_name, disable_add2line_warn, - buildid_mmap2, + no_buildid_mmap2, guest_code, lazy_load_kernel_maps, keep_exited_threads,
tools/perf/util/synthetic-events.c +8 -8
@@ -532,7 +532,7 @@ int perf_event__synthesize_mmap_events(const struct perf_tool *tool, event->mmap2.pid = tgid; event->mmap2.tid = pid; -if (symbol_conf.buildid_mmap2) +if (!symbol_conf.no_buildid_mmap2)perf_record_mmap2__read_build_id (&event->mmap2, machine, false);if (perf_tool__process_synth_event (tool, event, machine, process) !=0 ) {
@@ -690,7 +690,7 @@ static int perf_event__synthesize_modules_maps_cb(struct map *map, void *data)return 0 ; dso =map__dso (map); -if (symbol_conf.buildid_mmap2) { +if (!symbol_conf.no_buildid_mmap2) { size =PERF_ALIGN (dso__long_name_len (dso) +1 ,sizeof (u64)); event->mmap2.header.type =PERF_RECORD_MMAP2 ; event->mmap2.header.size = (sizeof(event->mmap2) -
@@ -734,9 +734,9 @@ int perf_event__synthesize_modules(const struct perf_tool *tool, perf_event__han .process = process, .machine = machine, }; -size_t size = symbol_conf.buildid_mmap2 - ?sizeof (args.event->mmap2) - :sizeof (args.event->mmap); +size_t size = symbol_conf.no_buildid_mmap2 + ?sizeof (args.event->mmap) + :sizeof (args.event->mmap2); args.event =zalloc (size + machine->id_hdr_size);if (args.event ==NULL ) {
@@ -1124,8 +1124,8 @@ static int __perf_event__synthesize_kernel_mmap(const struct perf_tool *tool, struct machine *machine) {union perf_event *event; -size_t size = symbol_conf.buildid_mmap2 ? -sizeof (event->mmap2) :sizeof (event->mmap); +size_t size = symbol_conf.no_buildid_mmap2 ? +sizeof (event->mmap) :sizeof (event->mmap2);struct map *map =machine__kernel_map (machine);struct kmap *kmap;int err;
@@ -1159,7 +1159,7 @@ static int __perf_event__synthesize_kernel_mmap(const struct perf_tool *tool, event->header.misc =PERF_RECORD_MISC_GUEST_KERNEL ; } -if (symbol_conf.buildid_mmap2) { +if (!symbol_conf.no_buildid_mmap2) { size =snprintf (event->mmap2.filename,sizeof (event->mmap2.filename),"%s%s" , machine->mmap_name, kmap->ref_reloc_sym->name) +1 ; size =PERF_ALIGN (size,sizeof (u64));
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Namhyung Kim
maintainerRe: [PATCH v5 08/23] perf record: Make --buildid-mmap the default
Quoted 9 lines · Ian Rogers
Support for build IDs in mmap2 perf events has been present since Linux v5.12:
https://lore.kernel.org/lkml/[email protected]/
Build ID mmap events don't avoid the need to inject build IDs for DSO touched by samples as the build ID cache is populated by perf record. They can avoid some cases of symbol mis-resolution caused by the file system changing from when a sample occurred and when the DSO is sought. To disable build ID scanning
Quoted 4 lines
Unlike the --buildid-mmap option, this doesn't disable the build ID cache but it does disable the processing of samples looking for DSOs to inject build IDs for. To disable the build ID cache the -B (--no-buildid) option should be used.
I think we need to add a config option to control this behavior later. Let me think about this more.
Quoted 49 lines
Making this option the default was raised on the list in:
https://lore.kernel.org/linux-perf-users/CAP-5=fXP7jN_QrGUcd55_QH5J-Y-FCaJ6=NaHVtyx0oyNh8_-Q@mail.gmail.com/Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-record.c | 33 +++++++++++++++++++----------- tools/perf/util/symbol_conf.h | 2 +- tools/perf/util/synthetic-events.c | 16 +++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-)tools/perf/builtin-record.c +5
-0@@ -171,6 +171,7 @@ struct record {bool no_buildid_cache_set;bool buildid_all;bool buildid_mmap; +bool buildid_mmap_set;bool timestamp_filename;bool timestamp_boundary;bool off_cpu;@@ -1811,6 +1812,7 @@ record__finish_output(struct record *rec) data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); } +/* Buildid scanning disabled or build ID in kernel and synthesized map events. */ if (!rec->no_buildid) {process_buildids (rec);@@ -3005,6 +3007,8 @@ static int perf_record_config(const char *var, const char *value, void *cb) rec->no_buildid = true; else if (!strcmp(value, "mmap")) rec->buildid_mmap = true; + else if (!strcmp(value, "no-mmap")) + rec->buildid_mmap = false; else return -1;return 0 ;@@ -3411,6 +3415,7 @@ static struct record record = { .synth = PERF_SYNTH_ALL, .off_cpu_thresh_ns = OFFCPU_THRESH, }, + .buildid_mmap = true, };const char record_callchain_help[] =CALLCHAIN_RECORD_HELP
tools/perf/builtin-record.c static struct option __record_options[] = { · line 3586
Quoted 7 lines
tools/perf/builtin-record.c +2
-2@@ -3577,8 +3582,8 @@ static struct option __record_options[] = { "file", "vmlinux pathname"),OPT_BOOLEAN (0 ,"buildid-all" , &record.buildid_all,"Record build-id of all DSOs regardless of hits" ), -OPT_BOOLEAN (0 ,"buildid-mmap" , &record.buildid_mmap, - "Record build-id in map events"), +OPT_BOOLEAN_SET (0 ,"buildid-mmap" , &record.buildid_mmap, &record.buildid_mmap_set, + "Legacy record build-id in map events option which is now the default. Behaves indentically to --no-buildid. Disable with --no-buildid-mmap"),
Looks too long. Maybe just like below:
"Record build-id in mmap events and skip build-id processing."
The detailed explanation can go to the documentation.
Quoted 9 lines
tools/perf/builtin-record.c +2
-0OPT_BOOLEAN (0 ,"timestamp-filename" , &record.timestamp_filename,"append timestamp to output filename" ), OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,@@ -4108,19 +4113,23 @@ int cmd_record(int argc, const char **argv) record.opts.record_switch_events = true; } +if (!rec->buildid_mmap) { +pr_debug ("Disabling build id in synthesized mmap2 events.\n" );
tools/perf/builtin-record.c int cmd_record(int argc, const char **argv) · line 4127
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+ symbol_conf.no_buildid_mmap2 = true; + }else if (rec->buildid_mmap_set) { +/* +* Explicitly passing --buildid-mmap disables buildid processing +* and cache generation. +*/ + rec->no_buildid = true; + } +if (rec->buildid_mmap && !perf_can_record_build_id ()) { +pr_warning ("Missing support for build id in kernel mmap events. Disable this warning with --no-buildid-mmap\n" );
This can be in two lines. I can make the changes if you're ok.
Thanks,
Namhyung
Quoted 89 lines
tools/perf/builtin-record.c +2
-10+ rec->buildid_mmap = false; + }if (rec->buildid_mmap) { -if (!perf_can_record_build_id ()) { -pr_err ("Failed: no support to record build id in mmap events, update your kernel.\n" ); - err = -EINVAL ; - goto out_opts; - } -pr_debug ("Enabling build id in mmap2 events.\n" ); -/* Enable mmap build id synthesizing. */ - symbol_conf.buildid_mmap2 = true;/* Enable perf_event_attr::build_id bit. */ rec->opts.build_id = true; -/* Disable build id cache. */ - rec->no_buildid = true; }if (rec->opts.record_cgroup && !perf_can_record_cgroup ()) {tools/perf/util/symbol_conf.h +1
-1@@ -43,7 +43,7 @@ struct symbol_conf { report_individual_block, inline_name, disable_add2line_warn, - buildid_mmap2, + no_buildid_mmap2, guest_code, lazy_load_kernel_maps, keep_exited_threads,tools/perf/util/synthetic-events.c +8
-8@@ -532,7 +532,7 @@ int perf_event__synthesize_mmap_events(const struct perf_tool *tool, event->mmap2.pid = tgid; event->mmap2.tid = pid; -if (symbol_conf.buildid_mmap2) +if (!symbol_conf.no_buildid_mmap2)perf_record_mmap2__read_build_id (&event->mmap2, machine, false);if (perf_tool__process_synth_event (tool, event, machine, process) !=0 ) {@@ -690,7 +690,7 @@ static int perf_event__synthesize_modules_maps_cb(struct map *map, void *data)return 0 ; dso =map__dso (map); -if (symbol_conf.buildid_mmap2) { +if (!symbol_conf.no_buildid_mmap2) { size =PERF_ALIGN (dso__long_name_len (dso) +1 ,sizeof (u64)); event->mmap2.header.type =PERF_RECORD_MMAP2 ; event->mmap2.header.size = (sizeof(event->mmap2) -@@ -734,9 +734,9 @@ int perf_event__synthesize_modules(const struct perf_tool *tool, perf_event__han .process = process, .machine = machine, }; -size_t size = symbol_conf.buildid_mmap2 - ?sizeof (args.event->mmap2) - :sizeof (args.event->mmap); +size_t size = symbol_conf.no_buildid_mmap2 + ?sizeof (args.event->mmap) + :sizeof (args.event->mmap2); args.event =zalloc (size + machine->id_hdr_size);if (args.event ==NULL ) {@@ -1124,8 +1124,8 @@ static int __perf_event__synthesize_kernel_mmap(const struct perf_tool *tool, struct machine *machine) {union perf_event *event; -size_t size = symbol_conf.buildid_mmap2 ? -sizeof (event->mmap2) :sizeof (event->mmap); +size_t size = symbol_conf.no_buildid_mmap2 ? +sizeof (event->mmap) :sizeof (event->mmap2);struct map *map =machine__kernel_map (machine);struct kmap *kmap;int err;@@ -1159,7 +1159,7 @@ static int __perf_event__synthesize_kernel_mmap(const struct perf_tool *tool, event->header.misc =PERF_RECORD_MISC_GUEST_KERNEL ; } -if (symbol_conf.buildid_mmap2) { +if (!symbol_conf.no_buildid_mmap2) { size =snprintf (event->mmap2.filename,sizeof (event->mmap2.filename),"%s%s" , machine->mmap_name, kmap->ref_reloc_sym->name) +1 ; size =PERF_ALIGN (size,sizeof (u64));Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 9/23 perf session: Add accessor for session->header.env
In reply to Ian RogersThe perf_env from the header in the session is frequently accessed, add an accessor function rather than access directly. Cache the value to avoid repeated calls. No behavioral change.
--- tools/perf/builtin-annotate.c | 4 +-- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-c2c.c | 16 ++++++------ tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 4 +-- tools/perf/builtin-kwork.c | 2 +- tools/perf/builtin-lock.c | 4 +-- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-record.c | 22 +++++++++-------- tools/perf/builtin-report.c | 8 +++--- tools/perf/builtin-sched.c | 8 +++--- tools/perf/builtin-script.c | 14 ++++++----- tools/perf/builtin-stat.c | 23 ++++++++--------- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 5 ++-- tools/perf/builtin-trace.c | 2 +- tools/perf/tests/topology.c | 38 +++++++++++++---------------- tools/perf/util/bpf-event.c | 2 +- tools/perf/util/branch.c | 2 +- tools/perf/util/data-convert-bt.c | 16 ++++++------ tools/perf/util/data-convert-json.c | 36 +++++++++++++-------------- tools/perf/util/session.c | 7 +++++- tools/perf/util/session.h | 2 ++ tools/perf/util/tool.c | 2 +- 25 files changed, 120 insertions(+), 107 deletions(-)
tools/perf/builtin-annotate.c +2 -2
@@ -562,7 +562,7 @@ static int __cmd_annotate(struct perf_annotate *ann) }if (!annotate_opts.objdump_path) { - ret =perf_env__lookup_objdump (&session->header.env, + ret =perf_env__lookup_objdump (perf_session__env (session), &annotate_opts.objdump_path);if (ret) goto out;
@@ -896,7 +896,7 @@ int cmd_annotate(int argc, const char **argv) symbol_conf.try_vmlinux_path = true; - ret =symbol__init (&annotate.session->header.env); + ret =symbol__init (perf_session__env (annotate.session));if (ret <0 ) goto out_delete;
tools/perf/builtin-buildid-cache.c +1 -1
@@ -453,7 +453,7 @@ int cmd_buildid_cache(int argc, const char **argv)return PTR_ERR (session); } -if (symbol__init (session ? &session->header.env :NULL ) <0 ) +if (symbol__init (session ?perf_session__env (session) :NULL ) <0 ) goto out;setup_pager ();
tools/perf/builtin-c2c.c +9 -7
@@ -2267,14 +2267,15 @@ static int setup_nodes(struct perf_session *session)int node, idx;struct perf_cpu cpu;int *cpu2node; +struct perf_env *env =perf_session__env (session);if (c2c.node_info >2 ) c2c.node_info =2 ; - c2c.nodes_cnt = session->header.env.nr_numa_nodes; - c2c.cpus_cnt = session->header.env.nr_cpus_avail; + c2c.nodes_cnt = env->nr_numa_nodes; + c2c.cpus_cnt = env->nr_cpus_avail; - n = session->header.env.numa_nodes; + n = env->numa_nodes;if (!n)return -EINVAL ;
@@ -3030,6 +3031,7 @@ static int perf_c2c__report(int argc, const char **argv) };int err =0 ;const char *output_str, *sort_str =NULL ; +struct perf_env *env; argc =parse_options (argc, argv, options, report_c2c_usage,PARSE_OPT_STOP_AT_NON_OPTION );
@@ -3072,14 +3074,14 @@ static int perf_c2c__report(int argc, const char **argv)pr_debug ("Error creating perf session\n" ); goto out; } - + env =perf_session__env (session);/* * Use the 'tot' as default display type if user doesn't specify it; * since Arm64 platform doesn't support HITMs flag, use 'peer' as the * default display type. */ if (!display) { -if (!strcmp (perf_env__arch (&session->header.env),"arm64" )) +if (!strcmp (perf_env__arch (env),"arm64" )) display ="peer" ;else display ="tot" ;
@@ -3109,7 +3111,7 @@ static int perf_c2c__report(int argc, const char **argv) goto out_session; } - err =mem2node__init (&c2c.mem2node, &session->header.env); + err =mem2node__init (&c2c.mem2node, env);if (err) goto out_session;
@@ -3117,7 +3119,7 @@ static int perf_c2c__report(int argc, const char **argv)if (err) goto out_mem2node; -if (symbol__init (&session->header.env) <0 ) +if (symbol__init (env) <0 ) goto out_mem2node;/* No pipe support at the moment. */
tools/perf/builtin-inject.c +1 -1
@@ -2608,7 +2608,7 @@ int cmd_inject(int argc, const char **argv) inject.tool.finished_round = perf_event__drop_oe; }#endif - ret =symbol__init (&inject.session->header.env); + ret =symbol__init (perf_session__env (inject.session));if (ret <0 ) goto out_delete;
tools/perf/builtin-kmem.c +1 -1
@@ -2024,7 +2024,7 @@ int cmd_kmem(int argc, const char **argv) symbol_conf.use_callchain = true; } -symbol__init (&session->header.env); +symbol__init (perf_session__env (session));if (perf_time__parse_str (&ptime, time_str) !=0 ) {pr_err ("Invalid time string\n" );
tools/perf/builtin-kvm.c +2 -2
@@ -1175,7 +1175,7 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm) } cpuid = buf; }else - cpuid = kvm->session->header.env.cpuid; + cpuid =perf_session__env (kvm->session)->cpuid;if (!cpuid) {pr_err ("Failed to look up CPU type\n" );
@@ -1561,7 +1561,7 @@ static int read_events(struct perf_kvm_stat *kvm)return PTR_ERR (kvm->session); } -symbol__init (&kvm->session->header.env); +symbol__init (perf_session__env (kvm->session));if (!perf_session__has_traces (kvm->session,"kvm record" )) { ret = -EINVAL ;
tools/perf/builtin-kwork.c +1 -1
@@ -1804,7 +1804,7 @@ static int perf_kwork__read_events(struct perf_kwork *kwork)return PTR_ERR (session); } -symbol__init (&session->header.env); +symbol__init (perf_session__env (session));if (perf_kwork__check_config (kwork, session) !=0 ) goto out_delete;
tools/perf/builtin-lock.c +2 -2
@@ -1876,7 +1876,7 @@ static int __cmd_report(bool display_info) } symbol_conf.allow_aliases = true; -symbol__init (&session->header.env); +symbol__init (perf_session__env (session));if (!data.is_pipe) {if (!perf_session__has_traces (session,"lock record" ))
@@ -2042,7 +2042,7 @@ static int __cmd_contention(int argc, const char **argv) con.save_callstack = true; symbol_conf.allow_aliases = true; -symbol__init (&session->header.env); +symbol__init (perf_session__env (session));if (use_bpf) { err =target__validate (&target);
tools/perf/builtin-mem.c +1 -1
@@ -304,7 +304,7 @@ static int report_raw_events(struct perf_mem *mem) goto out_delete; } - ret =symbol__init (&session->header.env); + ret =symbol__init (perf_session__env (session));if (ret <0 ) goto out_delete;
tools/perf/builtin-record.c +12 -10
@@ -2203,7 +2203,7 @@ static int record__setup_sb_evlist(struct record *rec) } } -if (evlist__add_bpf_sb_event (rec->sb_evlist, &rec->session->header.env)) { +if (evlist__add_bpf_sb_event (rec->sb_evlist,perf_session__env (rec->session))) {pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." );return -1 ; }
@@ -2222,15 +2222,16 @@ static int record__init_clock(struct record *rec)struct perf_session *session = rec->session;struct timespec ref_clockid;struct timeval ref_tod; +struct perf_env *env =perf_session__env (session);u64 ref;if (!rec->opts.use_clockid)return 0 ;if (rec->opts.use_clockid && rec->opts.clockid_res_ns) - session->header.env.clock.clockid_res_ns = rec->opts.clockid_res_ns; + env->clock.clockid_res_ns = rec->opts.clockid_res_ns; - session->header.env.clock.clockid = rec->opts.clockid; + env->clock.clockid = rec->opts.clockid;if (gettimeofday (&ref_tod,NULL ) !=0 ) {pr_err ("gettimeofday failed, cannot set reference time.\n" );
@@ -2245,12 +2246,12 @@ static int record__init_clock(struct record *rec) ref = (u64 ) ref_tod.tv_sec *NSEC_PER_SEC + (u64 ) ref_tod.tv_usec *NSEC_PER_USEC ; - session->header.env.clock.tod_ns = ref; + env->clock.tod_ns = ref; ref = (u64 ) ref_clockid.tv_sec *NSEC_PER_SEC + (u64 ) ref_clockid.tv_nsec; - session->header.env.clock.clockid_ns = ref; + env->clock.clockid_ns = ref;return 0 ; }
@@ -2396,6 +2397,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)int fd;float ratio =0 ;enum evlist_ctl_cmd cmd =EVLIST_CTL_CMD_UNSUPPORTED ; +struct perf_env *env;atexit (record__sig_exit);signal (SIGCHLD , sig_handler);
@@ -2437,7 +2439,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)pr_err ("Perf session creation failed.\n" );return PTR_ERR (session); } - + env =perf_session__env (session);if (record__threads_enabled (rec)) {if (perf_data__is_pipe (&rec->data)) {pr_err ("Parallel trace streaming is not available in pipe mode.\n" );
@@ -2471,8 +2473,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) }#endif // HAVE_EVENTFD_SUPPORT - session->header.env.comp_type =PERF_COMP_ZSTD ; - session->header.env.comp_level = rec->opts.comp_level; + env->comp_type =PERF_COMP_ZSTD ; + env->comp_level = rec->opts.comp_level;if (rec->opts.kcore && !record__kcore_readable (&session->machines.host)) {
@@ -2525,7 +2527,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) }/* Debug message used by test scripts */ pr_debug3 ("perf record done opening and mmapping events\n" ); - session->header.env.comp_mmap_len = session->evlist->core.mmap_len; + env->comp_mmap_len = session->evlist->core.mmap_len;if (rec->opts.kcore) { err =record__kcore_copy (&session->machines.host, data);
@@ -2855,7 +2857,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)if (rec->session->bytes_transferred && rec->session->bytes_compressed) { ratio = (float )rec->session->bytes_transferred/(float )rec->session->bytes_compressed; - session->header.env.comp_ratio = ratio +0.5 ; + env->comp_ratio = ratio +0.5 ; }if (forks) {
tools/perf/builtin-report.c +4 -4
@@ -447,7 +447,7 @@ static int report__setup_sample_type(struct report *rep) } } -callchain_param_setup (sample_type,perf_env__arch (&rep->session->header.env)); +callchain_param_setup (sample_type,perf_env__arch (perf_session__env (rep->session)));if (rep->stitch_lbr && (callchain_param.record_mode !=CALLCHAIN_LBR )) { ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
@@ -550,7 +550,7 @@ static int evlist__tui_block_hists_browse(struct evlist *evlist, struct report *evlist__for_each_entry (evlist, pos) { ret =report__browse_block_hists (&rep->block_reports[i++].hist, rep->min_percent, pos, - &rep->session->header.env); +perf_session__env (rep->session));if (ret !=0 )return ret; }
@@ -685,7 +685,7 @@ static int report__browse_hists(struct report *rep) } ret =evlist__tui_browse_hists (evlist, help,NULL , rep->min_percent, - &session->header.env, true); +perf_session__env (session), true);/* * Usually "ret" is the last pressed key, and we only * care if the key notifies us to switch data file.
@@ -1842,7 +1842,7 @@ int cmd_report(int argc, const char **argv)annotation_config__init (); } -if (symbol__init (&session->header.env) <0 ) +if (symbol__init (perf_session__env (session)) <0 ) goto error;if (report.time_str) {
tools/perf/builtin-sched.c +5 -3
@@ -1922,7 +1922,7 @@ static int perf_sched__read_events(struct perf_sched *sched)return PTR_ERR (session); } -symbol__init (&session->header.env); +symbol__init (perf_session__env (session));/* prefer sched_waking if it is captured */ if (evlist__find_tracepoint_by_name (session->evlist,"sched:sched_waking" ))
@@ -3236,6 +3236,7 @@ static int perf_sched__timehist(struct perf_sched *sched) };struct perf_session *session; +struct perf_env *env;struct evlist *evlist;int err =-1 ;
@@ -3260,6 +3261,7 @@ static int perf_sched__timehist(struct perf_sched *sched)if (IS_ERR (session))return PTR_ERR (session); + env =perf_session__env (session);if (cpu_list) { err =perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap);if (err <0 )
@@ -3268,7 +3270,7 @@ static int perf_sched__timehist(struct perf_sched *sched) evlist = session->evlist; -symbol__init (&session->header.env); +symbol__init (env);if (perf_time__parse_str (&sched->ptime, sched->time_str) !=0 ) {pr_err ("Invalid time string\n" );
@@ -3305,7 +3307,7 @@ static int perf_sched__timehist(struct perf_sched *sched) goto out;/* pre-allocate struct for per-CPU idle stats */ - sched->max_cpu.cpu = session->header.env.nr_cpus_online; + sched->max_cpu.cpu = env->nr_cpus_online;if (sched->max_cpu.cpu ==0 ) sched->max_cpu.cpu =4 ;if (init_idle_threads (sched->max_cpu.cpu))
tools/perf/builtin-script.c +8 -6
@@ -714,7 +714,7 @@ static int perf_session__check_output_opt(struct perf_session *session) } } -if (tod && !session->header.env.clock.enabled) { +if (tod && !perf_session__env (session)->clock.enabled) {pr_err ("Can't provide 'tod' time, missing clock data. " "Please record with -k/--clockid option.\n" );return -1 ;
@@ -759,7 +759,7 @@ tod_scnprintf(struct perf_script *script, char *buf, int buflen,if (buflen <64 || !script)return buf; - env = &script->session->header.env; + env =perf_session__env (script->session);if (!env->clock.enabled) {scnprintf (buf, buflen,"disabled" );return buf;
@@ -3864,6 +3864,7 @@ int cmd_script(int argc, const char **argv)"perf script [<options>] <top-script> [script-args]" , NULL }; +struct perf_env *env;perf_set_singlethreaded ();
@@ -4110,6 +4111,7 @@ int cmd_script(int argc, const char **argv)if (IS_ERR (session))return PTR_ERR (session); + env =perf_session__env (session);if (header || header_only) { script.tool.show_feat_hdr =SHOW_FEAT_HEADER ;perf_session__fprintf_info (session, stdout, show_full_info);
@@ -4119,17 +4121,17 @@ int cmd_script(int argc, const char **argv)if (show_full_info) script.tool.show_feat_hdr =SHOW_FEAT_HEADER_FULL_INFO ; -if (symbol__init (&session->header.env) <0 ) +if (symbol__init (env) <0 ) goto out_delete;uname (&uts);if (data.is_pipe) {/* Assume pipe_mode indicates native_arch */ native_arch = true; - }else if (session->header.env.arch) { -if (!strcmp (uts.machine, session->header.env.arch)) + }else if (env->arch) { +if (!strcmp (uts.machine, env->arch)) native_arch = true;else if (!strcmp (uts.machine,"x86_64" ) && - !strcmp (session->header.env.arch,"i386" )) + !strcmp (env->arch,"i386" )) native_arch = true; }
tools/perf/builtin-stat.c +12 -11
@@ -1692,48 +1692,48 @@ static struct aggr_cpu_id perf_env__get_global_aggr_by_cpu(struct perf_cpu cpu _static struct aggr_cpu_id perf_stat__get_socket_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_socket_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_socket_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static struct aggr_cpu_id perf_stat__get_die_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_die_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_die_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static struct aggr_cpu_id perf_stat__get_cluster_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_cluster_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_cluster_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static struct aggr_cpu_id perf_stat__get_cache_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_cache_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_cache_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static struct aggr_cpu_id perf_stat__get_core_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_core_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_core_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static struct aggr_cpu_id perf_stat__get_cpu_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_cpu_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_cpu_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static struct aggr_cpu_id perf_stat__get_node_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_node_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_node_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static struct aggr_cpu_id perf_stat__get_global_file (struct perf_stat_config *config__maybe_unused ,struct perf_cpu cpu) { -return perf_env__get_global_aggr_by_cpu (cpu, &perf_stat.session->header.env); +return perf_env__get_global_aggr_by_cpu (cpu,perf_session__env (perf_stat.session)); }static aggr_cpu_id_get_t aggr_mode__get_aggr_file (enum aggr_mode aggr_mode)
@@ -1792,7 +1792,7 @@ static aggr_get_id_t aggr_mode__get_id_file(enum aggr_mode aggr_mode)static int perf_stat_init_aggr_mode_file (struct perf_stat *st) { -struct perf_env *env = &st->session->header.env; +struct perf_env *env =perf_session__env (st->session);aggr_cpu_id_get_t get_id =aggr_mode__get_aggr_file (stat_config.aggr_mode);bool needs_sort = stat_config.aggr_mode !=AGGR_NONE ;
@@ -2113,8 +2113,9 @@ static int process_stat_round_event(struct perf_session *session, {struct perf_record_stat_round *stat_round = &event->stat_round;struct timespec tsh, *ts =NULL ; -const char **argv = session->header.env.cmdline_argv; -int argc = session->header.env.nr_cmdline; +struct perf_env *env =perf_session__env (session); +const char **argv = env->cmdline_argv; +int argc = env->nr_cmdline;process_counters ();
tools/perf/builtin-timechart.c +1 -1
@@ -1618,7 +1618,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)if (IS_ERR (session))return PTR_ERR (session); -symbol__init (&session->header.env); +symbol__init (perf_session__env (session)); (void)perf_header__process_sections(&session->header, perf_data__fd(session->data),
tools/perf/builtin-top.c +3 -2
@@ -647,7 +647,8 @@ static void *display_thread_tui(void *arg) } ret =evlist__tui_browse_hists (top->evlist, help, &hbt, top->min_percent, - &top->session->header.env, !top->record_opts.overwrite); +perf_session__env (top->session), + !top->record_opts.overwrite);if (ret ==K_RELOAD ) { top->zero = true; goto repeat;
@@ -1253,7 +1254,7 @@ static int __cmd_top(struct perf_top *top)int ret;if (!annotate_opts.objdump_path) { - ret =perf_env__lookup_objdump (&top->session->header.env, + ret =perf_env__lookup_objdump (perf_session__env (top->session), &annotate_opts.objdump_path);if (ret)return ret;
tools/perf/builtin-trace.c +1 -1
@@ -4752,7 +4752,7 @@ static int trace__replay(struct trace *trace)if (trace->opts.target.tid) symbol_conf.tid_list_str =strdup (trace->opts.target.tid); -if (symbol__init (&session->header.env) <0 ) +if (symbol__init (perf_session__env (session)) <0 ) goto out; trace->host = &session->machines.host;
tools/perf/tests/topology.c +17 -21
@@ -69,9 +69,11 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)int i;struct aggr_cpu_id id;struct perf_cpu cpu; +struct perf_env *env; session =perf_session__new (&data,NULL );TEST_ASSERT_VAL ("can't get session" , !IS_ERR (session)); + env =perf_session__env (session);cpu__setup_cpunode_map ();/* On platforms with large numbers of CPUs process_cpu_topology()
@@ -95,9 +97,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)* condition is true (see do_core_id_test in header.c). So always * run this test on those platforms. */ -if (!session->header.env.cpu - &&strncmp (session->header.env.arch,"s390" ,4 ) - &&strncmp (session->header.env.arch,"aarch64" ,7 )) +if (!env->cpu &&strncmp (env->arch,"s390" ,4 ) &&strncmp (env->arch,"aarch64" ,7 ))return TEST_SKIP ;/*
@@ -106,20 +106,20 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)* physical_package_id will be set to -1. Hence skip this * test if physical_package_id returns -1 for cpu from perf_cpu_map. */ -if (!strncmp (session->header.env.arch,"ppc64le" ,7 )) { +if (!strncmp (env->arch,"ppc64le" ,7 )) {if (cpu__get_socket_id (perf_cpu_map__cpu (map,0 )) ==-1 )return TEST_SKIP ; } -TEST_ASSERT_VAL ("Session header CPU map not set" , session->header.env.cpu); +TEST_ASSERT_VAL ("Session header CPU map not set" , env->cpu); -for (i =0 ; i < session->header.env.nr_cpus_avail; i++) { +for (i =0 ; i < env->nr_cpus_avail; i++) { cpu.cpu = i;if (!perf_cpu_map__has (map, cpu))continue ;pr_debug ("CPU %d, core %d, socket %d\n" , i, - session->header.env.cpu[i].core_id, - session->header.env.cpu[i].socket_id); + env->cpu[i].core_id, + env->cpu[i].socket_id); }// Test that CPU ID contains socket, die, core and CPU
@@ -129,13 +129,12 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) cpu.cpu == id.cpu.cpu);TEST_ASSERT_VAL ("Cpu map - Core ID doesn't match" , - session->header.env.cpu[cpu.cpu].core_id == id.core); + env->cpu[cpu.cpu].core_id == id.core);TEST_ASSERT_VAL ("Cpu map - Socket ID doesn't match" , - session->header.env.cpu[cpu.cpu].socket_id == - id.socket); + env->cpu[cpu.cpu].socket_id == id.socket);TEST_ASSERT_VAL ("Cpu map - Die ID doesn't match" , - session->header.env.cpu[cpu.cpu].die_id == id.die); + env->cpu[cpu.cpu].die_id == id.die);TEST_ASSERT_VAL ("Cpu map - Node ID is set" , id.node ==-1 );TEST_ASSERT_VAL ("Cpu map - Thread IDX is set" , id.thread_idx ==-1 ); }
@@ -144,14 +143,13 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)perf_cpu_map__for_each_cpu (cpu, i, map) { id =aggr_cpu_id__core (cpu,NULL );TEST_ASSERT_VAL ("Core map - Core ID doesn't match" , - session->header.env.cpu[cpu.cpu].core_id == id.core); + env->cpu[cpu.cpu].core_id == id.core);TEST_ASSERT_VAL ("Core map - Socket ID doesn't match" , - session->header.env.cpu[cpu.cpu].socket_id == - id.socket); + env->cpu[cpu.cpu].socket_id == id.socket);TEST_ASSERT_VAL ("Core map - Die ID doesn't match" , - session->header.env.cpu[cpu.cpu].die_id == id.die); + env->cpu[cpu.cpu].die_id == id.die);TEST_ASSERT_VAL ("Core map - Node ID is set" , id.node ==-1 );TEST_ASSERT_VAL ("Core map - Thread IDX is set" , id.thread_idx ==-1 ); }
@@ -160,11 +158,10 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)perf_cpu_map__for_each_cpu (cpu, i, map) { id =aggr_cpu_id__die (cpu,NULL );TEST_ASSERT_VAL ("Die map - Socket ID doesn't match" , - session->header.env.cpu[cpu.cpu].socket_id == - id.socket); + env->cpu[cpu.cpu].socket_id == id.socket);TEST_ASSERT_VAL ("Die map - Die ID doesn't match" , - session->header.env.cpu[cpu.cpu].die_id == id.die); + env->cpu[cpu.cpu].die_id == id.die);TEST_ASSERT_VAL ("Die map - Node ID is set" , id.node ==-1 );TEST_ASSERT_VAL ("Die map - Core is set" , id.core ==-1 );
@@ -176,8 +173,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)perf_cpu_map__for_each_cpu (cpu, i, map) { id =aggr_cpu_id__socket (cpu,NULL );TEST_ASSERT_VAL ("Socket map - Socket ID doesn't match" , - session->header.env.cpu[cpu.cpu].socket_id == - id.socket); + env->cpu[cpu.cpu].socket_id == id.socket);TEST_ASSERT_VAL ("Socket map - Node ID is set" , id.node ==-1 );TEST_ASSERT_VAL ("Socket map - Die ID is set" , id.die ==-1 );
tools/perf/util/bpf-event.c +1 -1
@@ -549,7 +549,7 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,* for perf-record and perf-report use header.env; * otherwise, use global perf_env. */ - env = session->data ? &session->header.env : &perf_env; + env = session->data ?perf_session__env (session) : &perf_env; arrays =1UL <<PERF_BPIL_JITED_KSYMS ; arrays |=1UL <<PERF_BPIL_JITED_FUNC_LENS ;
tools/perf/util/branch.c +1 -1
@@ -46,7 +46,7 @@ const char *branch_new_type_name(int new_type)"FAULT_DATA" , "FAULT_INST",/* -* TODO: This switch should happen on 'session->header.env.arch' +* TODO: This switch should happen on 'perf_session__env(session)->arch' * instead, because an arm64 platform perf recording could be * opened for analysis on other platforms as well. */
tools/perf/util/data-convert-bt.c +8 -8
@@ -1338,14 +1338,14 @@ static void cleanup_events(struct perf_session *session)static int setup_streams (struct ctf_writer *cw,struct perf_session *session) {struct ctf_stream **stream; -struct perf_header *ph = &session->header; +struct perf_env *env =perf_session__env (session);int ncpus;/* * Try to get the number of cpus used in the data file, * if not present fallback to the MAX_CPUS. */ - ncpus = ph->env.nr_cpus_avail ?:MAX_CPUS ; + ncpus = env->nr_cpus_avail ?:MAX_CPUS ; stream =zalloc (sizeof (*stream) * ncpus);if (!stream) {
@@ -1371,7 +1371,7 @@ static void free_streams(struct ctf_writer *cw)static int ctf_writer__setup_env (struct ctf_writer *cw,struct perf_session *session) { -struct perf_header *header = &session->header; +struct perf_env *env =perf_session__env (session);struct bt_ctf_writer *writer = cw->writer;#define ADD (__n, __v) \
@@ -1380,11 +1380,11 @@ do { \return -1 ; \ }while (0 ) -ADD ("host" , header->env.hostname); +ADD ("host" , env->hostname);ADD ("sysname" ,"Linux" ); -ADD ("release" , header->env.os_release); -ADD ("version" , header->env.version); -ADD ("machine" , header->env.arch); +ADD ("release" , env->os_release); +ADD ("version" , env->version); +ADD ("machine" , env->arch);ADD ("domain" ,"kernel" );ADD ("tracer_name" ,"perf" );
@@ -1401,7 +1401,7 @@ static int ctf_writer__setup_clock(struct ctf_writer *cw,int64_t offset =0 ;if (tod) { -struct perf_env *env = &session->header.env; +struct perf_env *env =perf_session__env (session);if (!env->clock.enabled) { pr_err("Can't provide --tod time, missing clock data. "
tools/perf/util/data-convert-json.c +18 -18
@@ -257,7 +257,8 @@ static int process_sample_event(const struct perf_tool *tool,static void output_headers (struct perf_session *session,struct convert_json *c) {struct stat st; -struct perf_header *header = &session->header; +const struct perf_header *header = &session->header; +const struct perf_env *env =perf_session__env (session);int ret;int fd =perf_data__fd (session->data);int i;
@@ -280,32 +281,32 @@ static void output_headers(struct perf_session *session, struct convert_json *c)output_json_key_format (out, true,2 ,"data-size" ,"%" PRIu64, header->data_size);output_json_key_format (out, true,2 ,"feat-offset" ,"%" PRIu64, header->feat_offset); -output_json_key_string (out, true,2 ,"hostname" , header->env.hostname); -output_json_key_string (out, true,2 ,"os-release" , header->env.os_release); -output_json_key_string (out, true,2 ,"arch" , header->env.arch); +output_json_key_string (out, true,2 ,"hostname" , env->hostname); +output_json_key_string (out, true,2 ,"os-release" , env->os_release); +output_json_key_string (out, true,2 ,"arch" , env->arch); -if (header->env.cpu_desc) -output_json_key_string (out, true,2 ,"cpu-desc" , header->env.cpu_desc); +if (env->cpu_desc) +output_json_key_string (out, true,2 ,"cpu-desc" , env->cpu_desc); -output_json_key_string (out, true,2 ,"cpuid" , header->env.cpuid); -output_json_key_format (out, true,2 ,"nrcpus-online" ,"%u" , header->env.nr_cpus_online); -output_json_key_format (out, true,2 ,"nrcpus-avail" ,"%u" , header->env.nr_cpus_avail); +output_json_key_string (out, true,2 ,"cpuid" , env->cpuid); +output_json_key_format (out, true,2 ,"nrcpus-online" ,"%u" , env->nr_cpus_online); +output_json_key_format (out, true,2 ,"nrcpus-avail" ,"%u" , env->nr_cpus_avail); -if (header->env.clock.enabled) { +if (env->clock.enabled) {output_json_key_format (out, true,2 ,"clockid" , -"%u" , header->env.clock.clockid); +"%u" , env->clock.clockid);output_json_key_format (out, true,2 ,"clock-time" , -"%" PRIu64, header->env.clock.clockid_ns); +"%" PRIu64, env->clock.clockid_ns);output_json_key_format (out, true,2 ,"real-time" , -"%" PRIu64, header->env.clock.tod_ns); +"%" PRIu64, env->clock.tod_ns); } -output_json_key_string (out, true,2 ,"perf-version" , header->env.version); +output_json_key_string (out, true,2 ,"perf-version" , env->version);output_json_key_format (out, true,2 ,"cmdline" ,"[" ); -for (i =0 ; i < header->env.nr_cmdline; i++) { +for (i =0 ; i < env->nr_cmdline; i++) {output_json_delimiters (out, i !=0 ,3 ); -output_json_string (c->out, header->env.cmdline_argv[i]); +output_json_string (c->out, env->cmdline_argv[i]); }output_json_format (out, false,2 ,"]" ); }
@@ -376,8 +377,7 @@ int bt_convert__perf2json(const char *input_name, const char *output_name,fprintf (stderr,"Error creating perf session!\n" ); goto err_fclose; } - -if (symbol__init (&session->header.env) <0 ) { +if (symbol__init (perf_session__env (session)) <0 ) {fprintf (stderr,"Symbol init error!\n" ); goto err_session_delete; }
tools/perf/util/session.c +6 -1
@@ -2558,7 +2558,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, {int i, err =-1 ;struct perf_cpu_map *map; -int nr_cpus =min (session->header.env.nr_cpus_avail,MAX_NR_CPUS ); +int nr_cpus =min (perf_session__env (session)->nr_cpus_avail,MAX_NR_CPUS );struct perf_cpu cpu;for (i =0 ; i <PERF_TYPE_MAX ; ++i) {
@@ -2747,3 +2747,8 @@ int perf_session__dsos_hit_all(struct perf_session *session)return 0 ; } + +struct perf_env *perf_session__env (struct perf_session *session) +{ +return &session->header.env; +}
tools/perf/util/session.h +2 -0
@@ -208,4 +208,6 @@ int perf_event__process_finished_round(const struct perf_tool *tool,union perf_event *event, struct ordered_events *oe); +struct perf_env *perf_session__env (struct perf_session *session); +#endif /* __PERF_SESSION_H */
tools/perf/util/tool.c +1 -1
@@ -20,7 +20,7 @@ static int perf_session__process_compressed_event(struct perf_session *session,void *src;size_t decomp_size, src_size;u64 decomp_last_rem =0 ; -size_t mmap_len, decomp_len = session->header.env.comp_mmap_len; +size_t mmap_len, decomp_len =perf_session__env (session)->comp_mmap_len;struct decomp *decomp, *decomp_last = session->active_decomp->decomp_last;if (decomp_last) {
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 10/23 perf session: Add an env pointer for the current perf_env
In reply to Ian RogersInitialize to &header.env. This will later allow the env value to be changed.
--- tools/perf/util/session.c | 3 ++- tools/perf/util/session.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/session.c +2 -1
@@ -156,6 +156,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, ordered_events__deliver_event, NULL);perf_env__init (&session->header.env); + session->env = &session->header.env;if (data) { ret =perf_data__open (data);if (ret <0 )
@@ -2750,5 +2751,5 @@ int perf_session__dsos_hit_all(struct perf_session *session)struct perf_env *perf_session__env (struct perf_session *session) { -return &session->header.env; +return session->env; }
tools/perf/util/session.h +2 -0
@@ -45,6 +45,8 @@ struct perf_session {struct perf_header header;/** @machines: Machines within the session a host and 0 or more guests. */ struct machines machines; +/** @env: The perf_env being worked with, either from a data file or the host's. */ +struct perf_env *env;/** @evlist: List of evsels/events of the session. */ struct evlist *evlist;/** @auxtrace: callbacks to allow AUX area data decoding. */
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Namhyung Kim
maintainerRe: [PATCH v5 10/23] perf session: Add an env pointer for the current perf_env
Quoted 2 lines · Ian Rogers
Initialize to
&header.env. This will later allow the env value to be changed.
I'm curious when it is changed.
Thanks,
Namhyung
Quoted 42 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/session.c | 3 ++- tools/perf/util/session.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)tools/perf/util/session.c +2
-1@@ -156,6 +156,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, ordered_events__deliver_event, NULL);perf_env__init (&session->header.env); + session->env = &session->header.env;if (data) { ret =perf_data__open (data);if (ret <0 )@@ -2750,5 +2751,5 @@ int perf_session__dsos_hit_all(struct perf_session *session)struct perf_env *perf_session__env (struct perf_session *session) { -return &session->header.env; +return session->env; }tools/perf/util/session.h +2
-0@@ -45,6 +45,8 @@ struct perf_session {struct perf_header header;/** @machines: Machines within the session a host and 0 or more guests. */ struct machines machines; +/** @env: The perf_env being worked with, either from a data file or the host's. */ +struct perf_env *env;/** @evlist: List of evsels/events of the session. */ struct evlist *evlist;/** @auxtrace: callbacks to allow AUX area data decoding. */ Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerRe: [PATCH v5 10/23] perf session: Add an env pointer for the current perf_env
Quoted 6 lines · Namhyung Kim
Quoted 2 lines · Ian Rogers
Initialize to
&header.env. This will later allow the env value to be changed.I'm curious when it is changed.
Thanks for the reviews! I'll dig into them for v6. Looking at this one I don't see a current use of the changed perf_session__env so I suspect we can drop the change. I need to think about the lifetime of header.env, use cases where have >1 env like perf inject (in vs out), perf diff and what's going on with TUI in patch:
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Ian
Quoted 45 lines
Thanks,
NamhyungQuoted 42 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/session.c | 3 ++- tools/perf/util/session.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)tools/perf/util/session.c +2
-1@@ -156,6 +156,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, ordered_events__deliver_event, NULL);perf_env__init (&session->header.env); + session->env = &session->header.env;if (data) { ret =perf_data__open (data);if (ret <0 )@@ -2750,5 +2751,5 @@ int perf_session__dsos_hit_all(struct perf_session *session)struct perf_env *perf_session__env (struct perf_session *session) { -return &session->header.env; +return session->env; }tools/perf/util/session.h +2
-1@@ -45,6 +45,8 @@ struct perf_session {struct perf_header header;/** @machines: Machines within the session a host and 0 or more guests. */ struct machines machines; +/** @env: The perf_env being worked with, either from a data file or the host's. */ +struct perf_env *env;/** @evlist: List of evsels/events of the session. */ struct evlist *evlist;/** @auxtrace: callbacks to allow AUX area data decoding. */ --2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 11/23 perf evlist: Change env variable to session
In reply to Ian RogersThe session holds a perf_env pointer env. In UI code container_of is used to turn the env to a session, but this assumes the session header's env is in use. Rather than a dubious container_of, hold the session in the evlist and derive the env from the session with evsel__env, perf_session__env, etc.
--- tools/perf/builtin-report.c | 6 +++++- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/tests/topology.c | 1 + tools/perf/ui/browser.h | 4 ++-- tools/perf/ui/browsers/header.c | 4 +--- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/util/amd-sample-raw.c | 2 +- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/evlist.h | 2 +- tools/perf/util/evsel.c | 12 +++++++++--- tools/perf/util/evsel.h | 1 + tools/perf/util/header.c | 2 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/sample-raw.c | 7 ++++--- tools/perf/util/sample-raw.h | 2 +- tools/perf/util/session.c | 4 +++- 17 files changed, 35 insertions(+), 22 deletions(-)
tools/perf/builtin-report.c +5 -1
@@ -1274,6 +1274,8 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,union perf_event *event, struct evlist **pevlist) { + struct perf_session *session; +struct perf_env *env;u64 sample_type;int err;
@@ -1286,7 +1288,9 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,* on events sample_type. */ sample_type =evlist__combined_sample_type (*pevlist); -callchain_param_setup (sample_type,perf_env__arch ((*pevlist)->env)); + session = (*pevlist)->session; + env =perf_session__env (session); +callchain_param_setup (sample_type,perf_env__arch (env));return 0 ; }
tools/perf/builtin-script.c +1 -1
@@ -2535,7 +2535,7 @@ static int process_attr(const struct perf_tool *tool, union perf_event *event,* on events sample_type. */ sample_type =evlist__combined_sample_type (evlist); -callchain_param_setup (sample_type,perf_env__arch ((*pevlist)->env)); +callchain_param_setup (sample_type,perf_env__arch (perf_session__env (scr->session)));/* Enable fields for callchain entries */ if (symbol_conf.use_callchain &&
tools/perf/builtin-top.c +1 -1
@@ -1654,7 +1654,6 @@ int cmd_top(int argc, const char **argv)"Couldn't read the cpuid for this machine: %s\n" , str_error_r(errno, errbuf, sizeof(errbuf))); } - top.evlist->env = &perf_env; argc =parse_options (argc, argv, options, top_usage,0 );if (argc)
@@ -1822,6 +1821,7 @@ int cmd_top(int argc, const char **argv)perf_top__update_print_entries (&top);signal (SIGWINCH , winch_sig); } + top.session->env = &perf_env; top.session =perf_session__new (NULL ,NULL );if (IS_ERR (top.session)) {
tools/perf/tests/topology.c +1 -0
@@ -43,6 +43,7 @@ static int session_write_header(char *path) session->evlist =evlist__new_default ();TEST_ASSERT_VAL ("can't get evlist" , session->evlist); + session->evlist->session = session;perf_header__set_feat (&session->header,HEADER_CPU_TOPOLOGY );perf_header__set_feat (&session->header,HEADER_NRCPUS );
tools/perf/ui/browser.h +2 -2
@@ -71,8 +71,8 @@ int ui_browser__help_window(struct ui_browser *browser, const char *text);bool ui_browser__dialog_yesno (struct ui_browser *browser,const char *text);int ui_browser__input_window (const char *title,const char *text,char *input,const char *exit_msg,int delay_sec); -struct perf_env ; -int tui__header_window (struct perf_env *env); +struct perf_session ; +int tui__header_window (struct perf_session *session);void ui_browser__argv_seek (struct ui_browser *browser,off_t offset,int whence);unsigned int ui_browser__argv_refresh (struct ui_browser *browser);
tools/perf/ui/browsers/header.c +1 -3
@@ -93,16 +93,14 @@ static int ui__list_menu(int argc, char * const argv[])return list_menu__run (&menu); } -int tui__header_window (struct perf_env *env) +int tui__header_window (struct perf_session *session) {int i, argc =0 ;char **argv; -struct perf_session *session;char *ptr, *pos;size_t size;FILE *fp =open_memstream (&ptr, &size); - session = container_of(env, struct perf_session, header.env);perf_header__fprintf_info (session, fp, true);fclose (fp);
tools/perf/ui/browsers/hists.c +1 -1
@@ -3233,7 +3233,7 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *hcase 'i' :/* env->arch is NULL for live-mode (i.e. perf top) */ if (env->arch) -tui__header_window (env); +tui__header_window (evsel__session (evsel));continue ;case 'F' : symbol_conf.filter_relative ^=1 ;
tools/perf/util/amd-sample-raw.c +1 -1
@@ -354,7 +354,7 @@ static void parse_cpuid(struct perf_env *env)*/ bool evlist__has_amd_ibs (struct evlist *evlist) { -struct perf_env *env = evlist->env; +struct perf_env *env =perf_session__env (evlist->session);int ret, nr_pmu_mappings =perf_env__nr_pmu_mappings (env);const char *pmu_mapping =perf_env__pmu_mappings (env);char name[sizeof ("ibs_fetch" )];
tools/perf/util/arm-spe.c +1 -1
@@ -856,7 +856,7 @@ static bool arm_spe__synth_ds(struct arm_spe_queue *speq,const char *cpuid;pr_warning_once ("Old SPE metadata, re-record to improve decode accuracy\n" ); - cpuid =perf_env__cpuid (spe->session->evlist->env); + cpuid =perf_env__cpuid (perf_session__env (spe->session)); midr =strtol (cpuid,NULL ,16 ); }else {/* CPU ID is -1 for per-thread mode */
tools/perf/util/evlist.h +1 -1
@@ -70,7 +70,7 @@ struct evlist {struct mmap *overwrite_mmap;struct evsel *selected;struct events_stats stats; -struct perf_env *env; +struct perf_session *session;void (*trace_event_sample_raw)(struct evlist *evlist,union perf_event *event,struct perf_sample *sample);
tools/perf/util/evsel.c +9 -3
@@ -48,6 +48,7 @@#include "record.h" #include "debug.h" #include "trace-event.h" +#include "session.h" #include "stat.h" #include "string2.h" #include "memswap.h"
@@ -3839,11 +3840,16 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target, err, str_error_r(err, sbuf, sizeof(sbuf)), evsel__name(evsel)); } +struct perf_session *evsel__session (struct evsel *evsel) +{ +return evsel && evsel->evlist ? evsel->evlist->session :NULL ; +} +struct perf_env *evsel__env (struct evsel *evsel) { -if (evsel && evsel->evlist && evsel->evlist->env) -return evsel->evlist->env; -return &perf_env; +struct perf_session *session =evsel__session (evsel); + +return session ?perf_session__env (session) : &perf_env; }static int store_evsel_ids (struct evsel *evsel,struct evlist *evlist)
tools/perf/util/evsel.h +1 -0
@@ -537,6 +537,7 @@ static inline bool evsel__is_dummy_event(struct evsel *evsel) (evsel->core.attr.config ==PERF_COUNT_SW_DUMMY ); } +struct perf_session *evsel__session (struct evsel *evsel);struct perf_env *evsel__env (struct evsel *evsel);int evsel__store_ids (struct evsel *evsel,struct evlist *evlist);
tools/perf/util/header.c +1 -1
@@ -4213,7 +4213,7 @@ int perf_session__read_header(struct perf_session *session)if (session->evlist ==NULL )return -ENOMEM ; - session->evlist->env = &header->env; + session->evlist->session = session; session->machines.host.env = &header->env;/*
tools/perf/util/s390-cpumsf.c +1 -1
@@ -1142,7 +1142,7 @@ int s390_cpumsf_process_auxtrace_info(union perf_event *event, sf->machine = &session->machines.host;/* No kvm support */ sf->auxtrace_type = auxtrace_info->type; sf->pmu_type =PERF_TYPE_RAW ; - sf->machine_type =s390_cpumsf_get_type (session->evlist->env->cpuid); + sf->machine_type =s390_cpumsf_get_type (perf_session__env (session)->cpuid); sf->auxtrace.process_event = s390_cpumsf_process_event; sf->auxtrace.process_auxtrace_event = s390_cpumsf_process_auxtrace_event;
tools/perf/util/sample-raw.c +4 -3
@@ -6,15 +6,16 @@#include "env.h" #include "header.h" #include "sample-raw.h" +#include "session.h" /* * Check platform the perf data file was created on and perform platform * specific interpretation. */ -void evlist__init_trace_event_sample_raw (struct evlist *evlist) +void evlist__init_trace_event_sample_raw (struct evlist *evlist,struct perf_env *env) { -const char *arch_pf =perf_env__arch (evlist->env); -const char *cpuid =perf_env__cpuid (evlist->env); +const char *arch_pf =perf_env__arch (env); +const char *cpuid =perf_env__cpuid (env);if (arch_pf && !strcmp ("s390" , arch_pf)) evlist->trace_event_sample_raw = evlist__s390_sample_raw;
tools/perf/util/sample-raw.h +1 -1
@@ -11,5 +11,5 @@ void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event,bool evlist__has_amd_ibs (struct evlist *evlist);void evlist__amd_sample_raw (struct evlist *evlist,union perf_event *event,struct perf_sample *sample); -void evlist__init_trace_event_sample_raw (struct evlist *evlist); +void evlist__init_trace_event_sample_raw (struct evlist *evlist,struct perf_env *env);#endif /* __PERF_EVLIST_H */
tools/perf/util/session.c +3 -1
@@ -178,7 +178,7 @@ struct perf_session *__perf_session__new(struct perf_data *data,perf_session__set_comm_exec (session); } -evlist__init_trace_event_sample_raw (session->evlist); +evlist__init_trace_event_sample_raw (session->evlist, &session->header.env);/* Open the directory data. */ if (data->is_dir) {
@@ -194,6 +194,8 @@ struct perf_session *__perf_session__new(struct perf_data *data, }else { session->machines.host.env = &perf_env; } +if (session->evlist) + session->evlist->session = session; session->machines.host.single_address_space =perf_env__single_address_space (session->machines.host.env);
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Namhyung Kim
maintainerRe: [PATCH v5 11/23] perf evlist: Change env variable to session
Quoted 77 lines · Ian Rogers
The session holds a
perf_envpointer env. In UI codecontainer_ofis used to turn the env to a session, but this assumes the session header's env is in use. Rather than a dubiouscontainer_of, hold the session in the evlist and derive the env from the session withevsel__env,perf_session__env, etc.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-report.c | 6 +++++- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/tests/topology.c | 1 + tools/perf/ui/browser.h | 4 ++-- tools/perf/ui/browsers/header.c | 4 +--- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/util/amd-sample-raw.c | 2 +- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/evlist.h | 2 +- tools/perf/util/evsel.c | 12 +++++++++--- tools/perf/util/evsel.h | 1 + tools/perf/util/header.c | 2 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/sample-raw.c | 7 ++++--- tools/perf/util/sample-raw.h | 2 +- tools/perf/util/session.c | 4 +++- 17 files changed, 35 insertions(+), 22 deletions(-)tools/perf/builtin-report.c +5
-1@@ -1274,6 +1274,8 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,union perf_event *event, struct evlist **pevlist) { + struct perf_session *session; +struct perf_env *env;u64 sample_type;int err;@@ -1286,7 +1288,9 @@ static int process_attr(const struct perf_tool *tool __maybe_unused,* on events sample_type. */ sample_type =evlist__combined_sample_type (*pevlist); -callchain_param_setup (sample_type,perf_env__arch ((*pevlist)->env)); + session = (*pevlist)->session; + env =perf_session__env (session); +callchain_param_setup (sample_type,perf_env__arch (env));return 0 ; }tools/perf/builtin-script.c +1
-1@@ -2535,7 +2535,7 @@ static int process_attr(const struct perf_tool *tool, union perf_event *event,* on events sample_type. */ sample_type =evlist__combined_sample_type (evlist); -callchain_param_setup (sample_type,perf_env__arch ((*pevlist)->env)); +callchain_param_setup (sample_type,perf_env__arch (perf_session__env (scr->session)));/* Enable fields for callchain entries */ if (symbol_conf.use_callchain &&tools/perf/builtin-top.c +0
-1@@ -1654,7 +1654,6 @@ int cmd_top(int argc, const char **argv)"Couldn't read the cpuid for this machine: %s\n" , str_error_r(errno, errbuf, sizeof(errbuf))); } - top.evlist->env = &perf_env; argc =parse_options (argc, argv, options, top_usage,0 );if (argc)
tools/perf/builtin-top.c int cmd_top(int argc, const char **argv) · line 1824
Quoted 4 lines
tools/perf/builtin-top.c +1
-0@@ -1822,6 +1821,7 @@ int cmd_top(int argc, const char **argv)perf_top__update_print_entries (&top);signal (SIGWINCH , winch_sig); } + top.session->env = &perf_env;
Looks like it's accessing top.session before it's created?
Thanks,
Namhyung
Quoted 3 lines
tools/perf/builtin-top.c +0
-0top.session =perf_session__new (NULL ,NULL );if (IS_ERR (top.session)) {
Ian Rogers
reviewerPATCH v5 12/23 perf header: Clean up use of perf_env
In reply to Ian RogersAlways use the perf_env from the feat_fd's perf_header. Cache the value on entry to a function in env and use env-> consistently in the code. Ensure the header is initialized for use in perf_session__do_write_header.
--- tools/perf/util/header.c | 174 ++++++++++++++++++++++----------------- 1 file changed, 98 insertions(+), 76 deletions(-)
tools/perf/util/header.c +98 -76
@@ -557,6 +557,7 @@ static int write_event_desc(struct feat_fd *ff,static int write_cmdline (struct feat_fd *ff,struct evlist *evlist__maybe_unused ) { +struct perf_env *env = &ff->ph->env;char pbuf[MAXPATHLEN ], *buf;int i, ret, n;
@@ -564,7 +565,7 @@ static int write_cmdline(struct feat_fd *ff, buf =perf_exe (pbuf,MAXPATHLEN );/* account for binary path */ - n = perf_env.nr_cmdline +1 ; + n = env->nr_cmdline +1 ; ret =do_write (ff, &n,sizeof (n));if (ret <0 )
@@ -574,8 +575,8 @@ static int write_cmdline(struct feat_fd *ff,if (ret <0 )return ret; -for (i =0 ; i < perf_env.nr_cmdline; i++) { - ret =do_write_string (ff, perf_env.cmdline_argv[i]); +for (i =0 ; i < env->nr_cmdline; i++) { + ret =do_write_string (ff, env->cmdline_argv[i]);if (ret <0 )return ret; }
@@ -586,6 +587,7 @@ static int write_cmdline(struct feat_fd *ff,static int write_cpu_topology (struct feat_fd *ff,struct evlist *evlist__maybe_unused ) { +struct perf_env *env = &ff->ph->env;struct cpu_topology *tp;u32 i;int ret, j;
@@ -613,17 +615,17 @@ static int write_cpu_topology(struct feat_fd *ff,break ; } - ret =perf_env__read_cpu_topology_map (&perf_env); + ret =perf_env__read_cpu_topology_map (env);if (ret <0 ) goto done; -for (j =0 ; j < perf_env.nr_cpus_avail; j++) { - ret =do_write (ff, &perf_env.cpu[j].core_id, -sizeof (perf_env.cpu[j].core_id)); +for (j =0 ; j < env->nr_cpus_avail; j++) { + ret =do_write (ff, &env->cpu[j].core_id, +sizeof (env->cpu[j].core_id));if (ret <0 )return ret; - ret =do_write (ff, &perf_env.cpu[j].socket_id, -sizeof (perf_env.cpu[j].socket_id)); + ret =do_write (ff, &env->cpu[j].socket_id, +sizeof (env->cpu[j].socket_id));if (ret <0 )return ret; }
@@ -641,9 +643,9 @@ static int write_cpu_topology(struct feat_fd *ff, goto done; } -for (j =0 ; j < perf_env.nr_cpus_avail; j++) { - ret =do_write (ff, &perf_env.cpu[j].die_id, -sizeof (perf_env.cpu[j].die_id)); +for (j =0 ; j < env->nr_cpus_avail; j++) { + ret =do_write (ff, &env->cpu[j].die_id, +sizeof (env->cpu[j].die_id));if (ret <0 )return ret; }
@@ -2111,17 +2113,18 @@ static void print_cpu_pmu_caps(struct feat_fd *ff, FILE *fp)static void print_pmu_caps (struct feat_fd *ff,FILE *fp) { +struct perf_env *env = &ff->ph->env;struct pmu_caps *pmu_caps; -for (int i =0 ; i < ff->ph->env.nr_pmus_with_caps; i++) { - pmu_caps = &ff->ph->env.pmu_caps[i]; +for (int i =0 ; i < env->nr_pmus_with_caps; i++) { + pmu_caps = &env->pmu_caps[i];__print_pmu_caps (fp, pmu_caps->nr_caps, pmu_caps->caps, pmu_caps->pmu_name); } -if (strcmp (perf_env__arch (&ff->ph->env),"x86" ) ==0 && -perf_env__has_pmu_mapping (&ff->ph->env,"ibs_op" )) { -char *max_precise =perf_env__find_pmu_cap (&ff->ph->env,"cpu" ,"max_precise" ); +if (strcmp (perf_env__arch (env),"x86" ) ==0 && +perf_env__has_pmu_mapping (env,"ibs_op" )) { +char *max_precise =perf_env__find_pmu_cap (env,"cpu" ,"max_precise" );if (max_precise !=NULL &&atoi (max_precise) ==0 )fprintf (fp,"# AMD systems uses ibs_op// PMU for some precise events, e.g.: cycles:p, see the 'perf list' man page for further details.\n" );
@@ -2130,18 +2133,19 @@ static void print_pmu_caps(struct feat_fd *ff, FILE *fp)static void print_pmu_mappings (struct feat_fd *ff,FILE *fp) { +struct perf_env *env = &ff->ph->env;const char *delimiter ="# pmu mappings: " ;char *str, *tmp;u32 pmu_num;u32 type; - pmu_num = ff->ph->env.nr_pmu_mappings; + pmu_num = env->nr_pmu_mappings;if (!pmu_num) {fprintf (fp,"# pmu mappings: not available\n" );return ; } - str = ff->ph->env.pmu_mappings; + str = env->pmu_mappings;while (pmu_num) { type =strtoul (str, &tmp,0 );
@@ -2223,17 +2227,18 @@ static void memory_node__fprintf(struct memory_node *n,static void print_mem_topology (struct feat_fd *ff,FILE *fp) { +struct perf_env *env = &ff->ph->env;struct memory_node *nodes;int i, nr; - nodes = ff->ph->env.memory_nodes; - nr = ff->ph->env.nr_memory_nodes; + nodes = env->memory_nodes; + nr = env->nr_memory_nodes;fprintf (fp,"# memory nodes (nr %d, block size 0x%llx):\n" , - nr, ff->ph->env.memory_bsize); + nr, env->memory_bsize);for (i =0 ; i < nr; i++) { -memory_node__fprintf (&nodes[i], ff->ph->env.memory_bsize, fp); +memory_node__fprintf (&nodes[i], env->memory_bsize, fp); } }
@@ -2431,6 +2436,7 @@ static int process_build_id(struct feat_fd *ff, void *data __maybe_unused)static int process_nrcpus (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;int ret;u32 nr_cpus_avail, nr_cpus_online;
@@ -2441,20 +2447,21 @@ static int process_nrcpus(struct feat_fd *ff, void *data __maybe_unused) ret =do_read_u32 (ff, &nr_cpus_online);if (ret)return ret; - ff->ph->env.nr_cpus_avail = (int )nr_cpus_avail; - ff->ph->env.nr_cpus_online = (int )nr_cpus_online; + env->nr_cpus_avail = (int )nr_cpus_avail; + env->nr_cpus_online = (int )nr_cpus_online;return 0 ; }static int process_total_mem (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;u64 total_mem;int ret; ret =do_read_u64 (ff, &total_mem);if (ret)return -1 ; - ff->ph->env.total_mem = (unsigned long long )total_mem; + env->total_mem = (unsigned long long )total_mem;return 0 ; }
@@ -2515,13 +2522,14 @@ process_event_desc(struct feat_fd *ff, void *data __maybe_unused)static int process_cmdline (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;char *str, *cmdline =NULL , **argv =NULL ;u32 nr, i, len =0 ;if (do_read_u32 (ff, &nr))return -1 ; - ff->ph->env.nr_cmdline = nr; + env->nr_cmdline = nr; cmdline =zalloc (ff->size + nr +1 );if (!cmdline)
@@ -2541,8 +2549,8 @@ static int process_cmdline(struct feat_fd *ff, void *data __maybe_unused) len +=strlen (str) +1 ;free (str); } - ff->ph->env.cmdline = cmdline; - ff->ph->env.cmdline_argv = (const char **) argv; + env->cmdline = cmdline; + env->cmdline_argv = (const char **) argv;return 0 ; error:
@@ -2556,18 +2564,18 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)u32 nr, i;char *str =NULL ;struct strbuf sb; -int cpu_nr = ff->ph->env.nr_cpus_avail; +struct perf_env *env = &ff->ph->env; +int cpu_nr = env->nr_cpus_avail;u64 size =0 ; -struct perf_header *ph = ff->ph; - ph->env.cpu =calloc (cpu_nr,sizeof (*ph->env.cpu)); -if (!ph->env.cpu) + env->cpu =calloc (cpu_nr,sizeof (*env->cpu)); +if (!env->cpu)return -1 ;if (do_read_u32 (ff, &nr)) goto free_cpu; - ph->env.nr_sibling_cores = nr; + env->nr_sibling_cores = nr; size +=sizeof (u32);if (strbuf_init (&sb,128 ) <0 ) goto free_cpu;
@@ -2583,12 +2591,12 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused) size +=string_size (str);zfree (&str); } - ph->env.sibling_cores =strbuf_detach (&sb,NULL ); + env->sibling_cores =strbuf_detach (&sb,NULL );if (do_read_u32 (ff, &nr))return -1 ; - ph->env.nr_sibling_threads = nr; + env->nr_sibling_threads = nr; size +=sizeof (u32);for (i =0 ; i < nr; i++) {
@@ -2602,14 +2610,14 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused) size +=string_size (str);zfree (&str); } - ph->env.sibling_threads =strbuf_detach (&sb,NULL ); + env->sibling_threads =strbuf_detach (&sb,NULL );/* * The header may be from old perf, * which doesn't include core id and socket id information. */ if (ff->size <= size) { -zfree (&ph->env.cpu); +zfree (&env->cpu);return 0 ; }
@@ -2617,13 +2625,13 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)if (do_read_u32 (ff, &nr)) goto free_cpu; - ph->env.cpu[i].core_id = nr; + env->cpu[i].core_id = nr; size +=sizeof (u32);if (do_read_u32 (ff, &nr)) goto free_cpu; - ph->env.cpu[i].socket_id = nr; + env->cpu[i].socket_id = nr; size +=sizeof (u32); }
@@ -2637,7 +2645,7 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)if (do_read_u32 (ff, &nr))return -1 ; - ph->env.nr_sibling_dies = nr; + env->nr_sibling_dies = nr; size +=sizeof (u32);for (i =0 ; i < nr; i++) {
@@ -2651,13 +2659,13 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused) size +=string_size (str);zfree (&str); } - ph->env.sibling_dies =strbuf_detach (&sb,NULL ); + env->sibling_dies =strbuf_detach (&sb,NULL );for (i =0 ; i < (u32 )cpu_nr; i++) {if (do_read_u32 (ff, &nr)) goto free_cpu; - ph->env.cpu[i].die_id = nr; + env->cpu[i].die_id = nr; }return 0 ;
@@ -2666,12 +2674,13 @@ static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)strbuf_release (&sb);zfree (&str); free_cpu: -zfree (&ph->env.cpu); +zfree (&env->cpu);return -1 ; }static int process_numa_topology (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;struct numa_node *nodes, *n;u32 nr, i;char *str;
@@ -2706,8 +2715,8 @@ static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused)if (!n->map) goto error; } - ff->ph->env.nr_numa_nodes = nr; - ff->ph->env.numa_nodes = nodes; + env->nr_numa_nodes = nr; + env->numa_nodes = nodes;return 0 ; error:
@@ -2717,6 +2726,7 @@ static int process_numa_topology(struct feat_fd *ff, void *data __maybe_unused)static int process_pmu_mappings (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;char *name;u32 pmu_num;u32 type;
@@ -2730,7 +2740,7 @@ static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused)return 0 ; } - ff->ph->env.nr_pmu_mappings = pmu_num; + env->nr_pmu_mappings = pmu_num;if (strbuf_init (&sb,128 ) <0 )return -1 ;
@@ -2749,14 +2759,14 @@ static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused) goto error;if (!strcmp (name,"msr" )) - ff->ph->env.msr_pmu_type = type; + env->msr_pmu_type = type;free (name); pmu_num--; }/* AMD may set it by evlist__has_amd_ibs() from perf_session__new() */ -free (ff->ph->env.pmu_mappings); - ff->ph->env.pmu_mappings =strbuf_detach (&sb,NULL ); +free (env->pmu_mappings); + env->pmu_mappings =strbuf_detach (&sb,NULL );return 0 ; error:
@@ -2766,6 +2776,7 @@ static int process_pmu_mappings(struct feat_fd *ff, void *data __maybe_unused)static int process_group_desc (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;size_t ret =-1 ;u32 i, nr, nr_groups;struct perf_session *session;
@@ -2779,7 +2790,7 @@ static int process_group_desc(struct feat_fd *ff, void *data __maybe_unused)if (do_read_u32 (ff, &nr_groups))return -1 ; - ff->ph->env.nr_groups = nr_groups; + env->nr_groups = nr_groups;if (!nr_groups) {pr_debug ("group desc not available\n" );return 0 ;
@@ -2863,6 +2874,7 @@ static int process_auxtrace(struct feat_fd *ff, void *data __maybe_unused)static int process_cache (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;struct cpu_cache_level *caches;u32 cnt, i, version;
@@ -2903,8 +2915,8 @@ static int process_cache(struct feat_fd *ff, void *data __maybe_unused)#undef _R } - ff->ph->env.caches = caches; - ff->ph->env.caches_cnt = cnt; + env->caches = caches; + env->caches_cnt = cnt;return 0 ; out_free_caches:for (i =0 ; i < cnt; i++) {
@@ -2940,6 +2952,7 @@ static int process_sample_time(struct feat_fd *ff, void *data __maybe_unused)static int process_mem_topology (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;struct memory_node *nodes;u64 version, i, nr, bsize;int ret =-1 ;
@@ -2978,9 +2991,9 @@ static int process_mem_topology(struct feat_fd *ff, nodes[i] = n; } - ff->ph->env.memory_bsize = bsize; - ff->ph->env.memory_nodes = nodes; - ff->ph->env.nr_memory_nodes = nr; + env->memory_bsize = bsize; + env->memory_nodes = nodes; + env->nr_memory_nodes = nr; ret =0 ; out:
@@ -2992,7 +3005,9 @@ static int process_mem_topology(struct feat_fd *ff,static int process_clockid (struct feat_fd *ff,void *data__maybe_unused ) { -if (do_read_u64 (ff, &ff->ph->env.clock.clockid_res_ns)) +struct perf_env *env = &ff->ph->env; + +if (do_read_u64 (ff, &env->clock.clockid_res_ns))return -1 ;return 0 ;
@@ -3001,6 +3016,7 @@ static int process_clockid(struct feat_fd *ff,static int process_clock_data (struct feat_fd *ff,void *_data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;u32 data32;u64 data64;
@@ -3015,26 +3031,27 @@ static int process_clock_data(struct feat_fd *ff,if (do_read_u32 (ff, &data32))return -1 ; - ff->ph->env.clock.clockid = data32; + env->clock.clockid = data32;/* TOD ref time */ if (do_read_u64 (ff, &data64))return -1 ; - ff->ph->env.clock.tod_ns = data64; + env->clock.tod_ns = data64;/* clockid ref time */ if (do_read_u64 (ff, &data64))return -1 ; - ff->ph->env.clock.clockid_ns = data64; - ff->ph->env.clock.enabled = true; + env->clock.clockid_ns = data64; + env->clock.enabled = true;return 0 ; }static int process_hybrid_topology (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;struct hybrid_node *nodes, *n;u32 nr, i;
@@ -3058,8 +3075,8 @@ static int process_hybrid_topology(struct feat_fd *ff, goto error; } - ff->ph->env.nr_hybrid_nodes = nr; - ff->ph->env.hybrid_nodes = nodes; + env->nr_hybrid_nodes = nr; + env->hybrid_nodes = nodes;return 0 ; error:
@@ -3212,19 +3229,21 @@ static int process_bpf_btf(struct feat_fd *ff, void *data __maybe_unused)static int process_compressed (struct feat_fd *ff,void *data__maybe_unused ) { -if (do_read_u32 (ff, &(ff->ph->env.comp_ver))) +struct perf_env *env = &ff->ph->env; + +if (do_read_u32 (ff, &(env->comp_ver)))return -1 ; -if (do_read_u32 (ff, &(ff->ph->env.comp_type))) +if (do_read_u32 (ff, &(env->comp_type)))return -1 ; -if (do_read_u32 (ff, &(ff->ph->env.comp_level))) +if (do_read_u32 (ff, &(env->comp_level)))return -1 ; -if (do_read_u32 (ff, &(ff->ph->env.comp_ratio))) +if (do_read_u32 (ff, &(env->comp_ratio)))return -1 ; -if (do_read_u32 (ff, &(ff->ph->env.comp_mmap_len))) +if (do_read_u32 (ff, &(env->comp_mmap_len)))return -1 ;return 0 ;
@@ -3296,19 +3315,21 @@ static int __process_pmu_caps(struct feat_fd *ff, int *nr_caps,static int process_cpu_pmu_caps (struct feat_fd *ff,void *data__maybe_unused ) { -int ret =__process_pmu_caps (ff, &ff->ph->env.nr_cpu_pmu_caps, - &ff->ph->env.cpu_pmu_caps, - &ff->ph->env.max_branches, - &ff->ph->env.br_cntr_nr, - &ff->ph->env.br_cntr_width); +struct perf_env *env = &ff->ph->env; +int ret =__process_pmu_caps (ff, &env->nr_cpu_pmu_caps, + &env->cpu_pmu_caps, + &env->max_branches, + &env->br_cntr_nr, + &env->br_cntr_width); -if (!ret && !ff->ph->env.cpu_pmu_caps) +if (!ret && !env->cpu_pmu_caps)pr_debug ("cpu pmu capabilities not available\n" );return ret; }static int process_pmu_caps (struct feat_fd *ff,void *data__maybe_unused ) { +struct perf_env *env = &ff->ph->env;struct pmu_caps *pmu_caps;u32 nr_pmu, i;int ret;
@@ -3346,8 +3367,8 @@ static int process_pmu_caps(struct feat_fd *ff, void *data __maybe_unused) } } - ff->ph->env.nr_pmus_with_caps = nr_pmu; - ff->ph->env.pmu_caps = pmu_caps; + env->nr_pmus_with_caps = nr_pmu; + env->pmu_caps = pmu_caps;return 0 ; err:
@@ -3645,6 +3666,7 @@ static int perf_session__do_write_header(struct perf_session *session,struct perf_header *header = &session->header;struct evsel *evsel;struct feat_fd ff = { + .ph = header, .fd = fd, };u64 attr_offset =sizeof (f_header), attr_size =0 ;
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 13/23 perf test: Avoid use perf_env
In reply to Ian RogersThe perf_env global variable holds the host perf_env data but its use is hit and miss. Switch to using local perf_env variables and ensure scoped perf_env__init and perf_env__exit. This loses command line setting of the perf_env, but this doesn't matter for tests. So the perf_env is fully initialized, clear it with memset in perf_env__init.
--- tools/perf/tests/code-reading.c | 5 +++- tools/perf/tests/dlfilter-test.c | 50 ++++++++++++++++++-------------- tools/perf/util/env.c | 1 + 3 files changed, 33 insertions(+), 23 deletions(-)
tools/perf/tests/code-reading.c +4 -1
@@ -651,11 +651,13 @@ static int do_test_code_reading(bool try_kcore)struct dso *dso;const char *events[] = {"cycles" ,"cycles:u" ,"cpu-clock" ,"cpu-clock:u" ,NULL };int evidx =0 ; +struct perf_env host_env; pid =getpid (); machine =machine__new_host (); - machine->env = &perf_env; +perf_env__init (&host_env); + machine->env = &host_env; ret =machine__create_kernel_maps (machine);if (ret <0 ) {
@@ -798,6 +800,7 @@ static int do_test_code_reading(bool try_kcore)perf_cpu_map__put (cpus);perf_thread_map__put (threads);machine__delete (machine); +perf_env__exit (&host_env);return err; }
tools/perf/tests/dlfilter-test.c +28 -22
76 lines not on this page · raw message
tools/perf/util/env.c +1 -0
@@ -271,6 +271,7 @@ void perf_env__exit(struct perf_env *env)void perf_env__init (struct perf_env *env) { +memset (env,0 ,sizeof (*env));#ifdef HAVE_LIBBPF_SUPPORT env->bpf_progs.infos =RB_ROOT ; env->bpf_progs.btfs =RB_ROOT ;
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 14/23 perf session: Add host_env argument to perf_session__new
In reply to Ian RogersWhen creating a perf_session the host perf_env may or may not want to be used. For example, perf top uses a host perf_env while perf inject does not. Add a host_env argument to perf_session__new so that sessions requiring a host perf_env can pass it in. Currently if none is specified the global perf_env variable is used, but this will change in later patches.
--- tools/perf/builtin-inject.c | 3 ++- tools/perf/util/session.c | 5 +++-- tools/perf/util/session.h | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-)
tools/perf/builtin-inject.c +2 -1
@@ -2539,7 +2539,8 @@ int cmd_inject(int argc, const char **argv) inject.tool.bpf_metadata = perf_event__repipe_op2_synth; inject.tool.dont_split_sample_group = true; inject.session =__perf_session__new (&data, &inject.tool, -/*trace_event_repipe=*/ inject.output.is_pipe); +/*trace_event_repipe=*/ inject.output.is_pipe, +/*host_env=*/ NULL );if (IS_ERR (inject.session)) { ret =PTR_ERR (inject.session);
tools/perf/util/session.c +3 -2
@@ -138,7 +138,8 @@ static int ordered_events__deliver_event(struct ordered_events *oe,struct perf_session *__perf_session__new (struct perf_data *data,struct perf_tool *tool, -bool trace_event_repipe) +bool trace_event_repipe, +struct perf_env *host_env) {int ret = -ENOMEM ;struct perf_session *session =zalloc (sizeof (*session));
@@ -192,7 +193,7 @@ struct perf_session *__perf_session__new(struct perf_data *data, symbol_conf.kallsyms_name =perf_data__kallsyms_name (data); } }else { - session->machines.host.env = &perf_env; + session->machines.host.env = host_env ?: &perf_env; }if (session->evlist) session->evlist->session = session;
tools/perf/util/session.h +3 -2
@@ -109,12 +109,13 @@ struct perf_tool;struct perf_session *__perf_session__new (struct perf_data *data,struct perf_tool *tool, -bool trace_event_repipe); +bool trace_event_repipe, +struct perf_env *host_env);static inline struct perf_session *perf_session__new (struct perf_data *data,struct perf_tool *tool) { -return __perf_session__new (data, tool,/*trace_event_repipe=*/ false); +return __perf_session__new (data, tool,/*trace_event_repipe=*/ false,/*host_env=*/ NULL ); }void perf_session__delete (struct perf_session *session);
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 15/23 perf top: Make perf_env locally scoped
In reply to Ian RogersThe use of the global host perf_env variable is potentially inconsistent within the code. Switch perf top to using a locally scoped variable that is generally accessed through the session.
--- tools/perf/builtin-top.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-)
tools/perf/builtin-top.c +27 -12
@@ -1301,7 +1301,7 @@ static int __cmd_top(struct perf_top *top)perf_set_multithreaded ();if (perf_hpp_list.socket) { - ret =perf_env__read_cpu_topology_map (&perf_env); + ret =perf_env__read_cpu_topology_map (perf_session__env (top->session));if (ret <0 ) {char errbuf[BUFSIZ ];const char *err =str_error_r (-ret, errbuf,sizeof (errbuf));
@@ -1624,6 +1624,7 @@ int cmd_top(int argc, const char **argv) NULL };int status =hists__init (); +struct perf_env host_env;if (status <0 )return status;
@@ -1639,12 +1640,17 @@ int cmd_top(int argc, const char **argv) status =perf_config (perf_top_config, &top);if (status) -return status; + goto out_delete_evlist;/* * Since the per arch annotation init routine may need the cpuid, read * it here, since we are not getting this from the perf.data header. */ - status =perf_env__read_cpuid (&perf_env); +perf_env__init (&host_env); + status =perf_env__set_cmdline (&host_env, argc, argv); +if (status) + goto out_delete_evlist; + + status =perf_env__read_cpuid (&host_env);if (status) {/* * Some arches do not provide a get_cpuid(), so just use pr_debug, otherwise
@@ -1661,18 +1667,24 @@ int cmd_top(int argc, const char **argv)if (disassembler_style) { annotate_opts.disassembler_style =strdup (disassembler_style); -if (!annotate_opts.disassembler_style) -return -ENOMEM ; +if (!annotate_opts.disassembler_style) { + status = -ENOMEM ; + goto out_delete_evlist; + } }if (objdump_path) { annotate_opts.objdump_path =strdup (objdump_path); -if (!annotate_opts.objdump_path) -return -ENOMEM ; +if (!annotate_opts.objdump_path) { + status = -ENOMEM ; + goto out_delete_evlist; + } }if (addr2line_path) { symbol_conf.addr2line_path =strdup (addr2line_path); -if (!symbol_conf.addr2line_path) -return -ENOMEM ; +if (!symbol_conf.addr2line_path) { + status = -ENOMEM ; + goto out_delete_evlist; + } } status =symbol__validate_sym_arguments ();
@@ -1821,14 +1833,16 @@ int cmd_top(int argc, const char **argv)perf_top__update_print_entries (&top);signal (SIGWINCH , winch_sig); } - top.session->env = &perf_env; - top.session =perf_session__new (NULL ,NULL ); + top.session =__perf_session__new (/*data=*/ NULL ,/*tool=*/ NULL , +/*trace_event_repipe=*/ false, + &host_env);if (IS_ERR (top.session)) { status =PTR_ERR (top.session); top.session =NULL ; goto out_delete_evlist; } + top.evlist->session = top.session;if (!evlist__needs_bpf_sb_event (top.evlist)) top.record_opts.no_bpf_event = true;
@@ -1843,7 +1857,7 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; } -if (evlist__add_bpf_sb_event (top.sb_evlist, &perf_env)) { +if (evlist__add_bpf_sb_event (top.sb_evlist, &host_env)) {pr_err ("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n." ); status = -EINVAL ; goto out_delete_evlist;
@@ -1865,6 +1879,7 @@ int cmd_top(int argc, const char **argv)evlist__delete (top.evlist);perf_session__delete (top.session);annotation_options__exit (); +perf_env__exit (&host_env);return status; }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 16/23 perf bench synthesize: Avoid use of global perf_env
In reply to Ian RogersThe benchmark doesn't use a data file and so the header perf_env isn't used. Stack allocate a host perf_env for use to avoid the use of the global perf_env.
--- tools/perf/bench/synthesize.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
tools/perf/bench/synthesize.c +19 -11
@@ -114,10 +114,13 @@ static int run_single_threaded(void) .pid = "self", };struct perf_thread_map *threads; +struct perf_env host_env;int err;perf_set_singlethreaded (); - session =perf_session__new (NULL ,NULL ); +perf_env__init (&host_env); + session =__perf_session__new (/*data=*/ NULL ,/*tool=*/ NULL , +/*trace_event_repipe=*/ false, &host_env);if (IS_ERR (session)) {pr_err ("Session creation failed.\n" );return PTR_ERR (session);
@@ -144,6 +147,7 @@ static int run_single_threaded(void)perf_thread_map__put (threads);perf_session__delete (session); +perf_env__exit (&host_env);return err; }
@@ -154,17 +158,21 @@ static int do_run_multi_threaded(struct target *target,u64 runtime_us;unsigned int i;double time_average, time_stddev, event_average, event_stddev; -int err; +int err =0 ;struct stats time_stats, event_stats;struct perf_session *session; +struct perf_env host_env; +perf_env__init (&host_env);init_stats (&time_stats);init_stats (&event_stats);for (i =0 ; i < multi_iterations; i++) { - session =perf_session__new (NULL ,NULL ); -if (IS_ERR (session)) -return PTR_ERR (session); - + session =__perf_session__new (/*data=*/ NULL ,/*tool=*/ NULL , +/*trace_event_repipe=*/ false, &host_env); +if (IS_ERR (session)) { + err =PTR_ERR (session); + goto err_out; + }atomic_set (&event_count,0 );gettimeofday (&start,NULL ); err = __machine__synthesize_threads(&session->machines.host,
@@ -173,10 +181,8 @@ static int do_run_multi_threaded(struct target *target, process_synthesized_event, true, false, nr_threads_synthesize); -if (err) { -perf_session__delete (session); -return err; - } +if (err) + goto err_out;gettimeofday (&end,NULL );timersub (&end, &start, &diff);
@@ -198,7 +204,9 @@ static int do_run_multi_threaded(struct target *target,printf (" Average time per event %.3f usec\n" , time_average / event_average); -return 0 ; +err_out: +perf_env__exit (&host_env); +return err; }static int run_multi_threaded (void )
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Namhyung Kim
maintainerRe: [PATCH v5 16/23] perf bench synthesize: Avoid use of global perf_env
Quoted 18 lines · Ian Rogers
The benchmark doesn't use a data file and so the header
perf_envisn't used. Stack allocate a hostperf_envfor use to avoid the use of the globalperf_env.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/bench/synthesize.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)tools/perf/bench/synthesize.c +1
-0@@ -114,10 +114,13 @@ static int run_single_threaded(void) .pid = "self", };struct perf_thread_map *threads; +struct perf_env host_env;
tools/perf/bench/synthesize.c static int run_single_threaded(void) · line 126
Quoted 10 lines
tools/perf/bench/synthesize.c +3
-1int err;perf_set_singlethreaded (); - session =perf_session__new (NULL ,NULL ); +perf_env__init (&host_env); + session =__perf_session__new (/*data=*/ NULL ,/*tool=*/ NULL , +/*trace_event_repipe=*/ false, &host_env);if (IS_ERR (session)) {pr_err ("Session creation failed.\n" );return PTR_ERR (session);
Missing perf_env__exit() ?
Quoted 36 lines
tools/perf/bench/synthesize.c +10
-5@@ -144,6 +147,7 @@ static int run_single_threaded(void)perf_thread_map__put (threads);perf_session__delete (session); +perf_env__exit (&host_env);return err; }@@ -154,17 +158,21 @@ static int do_run_multi_threaded(struct target *target,u64 runtime_us;unsigned int i;double time_average, time_stddev, event_average, event_stddev; -int err; +int err =0 ;struct stats time_stats, event_stats;struct perf_session *session; +struct perf_env host_env; +perf_env__init (&host_env);init_stats (&time_stats);init_stats (&event_stats);for (i =0 ; i < multi_iterations; i++) { - session =perf_session__new (NULL ,NULL ); -if (IS_ERR (session)) -return PTR_ERR (session); - + session =__perf_session__new (/*data=*/ NULL ,/*tool=*/ NULL , +/*trace_event_repipe=*/ false, &host_env); +if (IS_ERR (session)) { + err =PTR_ERR (session); + goto err_out; + }atomic_set (&event_count,0 );gettimeofday (&start,NULL ); err = __machine__synthesize_threads(&session->machines.host,
tools/perf/bench/synthesize.c static int do_run_multi_threaded(struct target *target, · line 185
Quoted 9 lines
tools/perf/bench/synthesize.c +2
-4@@ -173,10 +181,8 @@ static int do_run_multi_threaded(struct target *target, process_synthesized_event, true, false, nr_threads_synthesize); -if (err) { -perf_session__delete (session); -return err; - } +if (err) + goto err_out;
Missing perf_session__delete() ?
Quoted 17 lines
tools/perf/bench/synthesize.c +3
-1gettimeofday (&end,NULL );timersub (&end, &start, &diff);@@ -198,7 +204,9 @@ static int do_run_multi_threaded(struct target *target,printf (" Average time per event %.3f usec\n" , time_average / event_average); -return 0 ; +err_out: +perf_env__exit (&host_env); +return err; }static int run_multi_threaded (void )Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 17/23 perf machine: Explicitly pass in host perf_env
In reply to Ian RogersWhen creating a machine for the host explicitly pass in a scoped perf_env. This removes a use of the global perf_env.
--- tools/perf/builtin-buildid-list.c | 5 ++++- tools/perf/builtin-kallsyms.c | 21 ++++++++++++++++----- tools/perf/builtin-trace.c | 24 +++++++++++++++++------- tools/perf/tests/code-reading.c | 3 +-- tools/perf/tests/dlfilter-test.c | 3 +-- tools/perf/tests/dwarf-unwind.c | 10 +++++++--- tools/perf/tests/mmap-thread-lookup.c | 6 +++++- tools/perf/tests/symbols.c | 8 +++++++- tools/perf/util/debug.c | 9 ++++++++- tools/perf/util/machine.c | 16 ++++++++-------- tools/perf/util/machine.h | 6 +++--- tools/perf/util/probe-event.c | 5 ++++- 12 files changed, 81 insertions(+), 35 deletions(-)
tools/perf/builtin-buildid-list.c +4 -1
@@ -45,11 +45,14 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused)static void buildid__show_kernel_maps (void ) { +struct perf_env host_env;struct machine *machine; - machine =machine__new_host (); +perf_env__init (&host_env); + machine =machine__new_host (&host_env);machine__for_each_kernel_map (machine, buildid__map_cb,NULL );machine__delete (machine); +perf_env__exit (&host_env); }static int sysfs__fprintf_build_id (FILE *fp)
tools/perf/builtin-kallsyms.c +16 -5
@@ -12,18 +12,28 @@#include <subcmd/parse-options.h> #include "debug.h" #include "dso.h" +#include "env.h" #include "machine.h" #include "map.h" #include "symbol.h" static int __cmd_kallsyms (int argc,const char **argv) { -int i; -struct machine *machine =machine__new_kallsyms (); +int i, err; +struct perf_env host_env; +struct machine *machine =NULL ; + +perf_env__init (&host_env); + err =perf_env__set_cmdline (&host_env, argc, argv); +if (err) + goto out; + + machine =machine__new_kallsyms (&host_env);if (machine ==NULL ) {pr_err ("Couldn't read /proc/kallsyms\n" ); -return -1 ; + err =-1 ; + goto out; }for (i =0 ; i < argc; ++i) {
@@ -42,9 +52,10 @@ static int __cmd_kallsyms(int argc, const char **argv)map__unmap_ip (map, symbol->start),map__unmap_ip (map, symbol->end), symbol->start, symbol->end); } - +out:machine__delete (machine); -return 0 ; +perf_env__exit (&host_env); +return err; }int cmd_kallsyms (int argc,const char **argv)
tools/perf/builtin-trace.c +17 -7
@@ -143,6 +143,7 @@ struct syscall_fmt { };struct trace { +struct perf_env host_env;struct perf_tool tool;struct {/** Sorted sycall numbers used by the trace. */
@@ -1983,17 +1984,24 @@ static char *trace__machine__resolve_kernel_addr(void *vmachine, unsigned long lreturn machine__resolve_kernel_addr (vmachine, addrp, modp); } -static int trace__symbols_init (struct trace *trace,struct evlist *evlist) +static int trace__symbols_init (struct trace *trace,int argc,const char **argv, +struct evlist *evlist) {int err =symbol__init (NULL );if (err)return err; - trace->host =machine__new_host (); -if (trace->host ==NULL ) -return -ENOMEM ; +perf_env__init (&trace->host_env); + err =perf_env__set_cmdline (&trace->host_env, argc, argv); +if (err) + goto out; + trace->host =machine__new_host (&trace->host_env); +if (trace->host ==NULL ) { + err = -ENOMEM ; + goto out; + }thread__set_priv_destructor (thread_trace__delete); err =trace_event__register_resolver (trace->host, trace__machine__resolve_kernel_addr);
@@ -2004,9 +2012,10 @@ static int trace__symbols_init(struct trace *trace, struct evlist *evlist) evlist->core.threads, trace__tool_process, true, false, 1); out: -if (err) +if (err) { +perf_env__exit (&trace->host_env);symbol__exit (); - + }return err; }
@@ -2015,6 +2024,7 @@ static void trace__symbols__exit(struct trace *trace)machine__exit (trace->host); trace->host =NULL ; +perf_env__exit (&trace->host_env);symbol__exit (); }
@@ -4456,7 +4466,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) goto out_delete_evlist; } - err =trace__symbols_init (trace, evlist); + err =trace__symbols_init (trace, argc, argv, evlist);if (err <0 ) {fprintf (trace->output,"Problems initializing symbol libraries!\n" ); goto out_delete_evlist;
tools/perf/tests/code-reading.c +1 -2
@@ -655,9 +655,8 @@ static int do_test_code_reading(bool try_kcore) pid =getpid (); - machine =machine__new_host ();perf_env__init (&host_env); - machine->env = &host_env; + machine =machine__new_host (&host_env); ret =machine__create_kernel_maps (machine);if (ret <0 ) {
tools/perf/tests/dlfilter-test.c +1 -2
@@ -353,9 +353,8 @@ static int test__dlfilter_test(struct test_data *td)return test_result ("Failed to find program symbols" ,TEST_FAIL );pr_debug ("Creating new host machine structure\n" ); - td->machine =machine__new_host ();perf_env__init (&host_env); - td->machine->env = &host_env; + td->machine =machine__new_host (&host_env); td->fd =creat (td->perf_data_file_name,0644 );if (td->fd <0 )
tools/perf/tests/dwarf-unwind.c +7 -3
@@ -7,6 +7,7 @@#include <unistd.h> #include "tests.h" #include "debug.h" +#include "env.h" #include "machine.h" #include "event.h" #include "../util/unwind.h"
@@ -180,6 +181,7 @@ NO_TAIL_CALL_ATTRIBUTE noinline int test_dwarf_unwind__krava_1(struct thread *th noinline int test__dwarf_unwind(struct test_suite *test __maybe_unused,int subtest__maybe_unused ) { +struct perf_env host_env;struct machine *machine;struct thread *thread;int err =-1 ;
@@ -188,15 +190,16 @@ noinline int test__dwarf_unwind(struct test_suite *test __maybe_unused, callchain_param.record_mode =CALLCHAIN_DWARF ; dwarf_callchain_users = true; - machine =machine__new_live (/*kernel_maps=*/ true, pid); +perf_env__init (&host_env); + machine =machine__new_live (&host_env,/*kernel_maps=*/ true, pid);if (!machine) {pr_err ("Could not get machine\n" ); -return -1 ; + goto out; }if (machine__create_kernel_maps (machine)) {pr_err ("Failed to create kernel maps\n" ); -return -1 ; + goto out; }if (verbose >1 )
@@ -213,6 +216,7 @@ noinline int test__dwarf_unwind(struct test_suite *test __maybe_unused, out:machine__delete (machine); +perf_env__exit (&host_env);return err; }
tools/perf/tests/mmap-thread-lookup.c +5 -1
@@ -8,6 +8,7 @@#include <stdlib.h> #include <stdio.h> #include "debug.h" +#include "env.h" #include "event.h" #include "tests.h" #include "machine.h"
@@ -155,6 +156,7 @@ static int synth_process(struct machine *machine)static int mmap_events (synth_cb synth) { +struct perf_env host_env;struct machine *machine;int err, i;
@@ -167,7 +169,8 @@ static int mmap_events(synth_cb synth)*/ TEST_ASSERT_VAL ("failed to create threads" , !threads_create ()); - machine =machine__new_host (); +perf_env__init (&host_env); + machine =machine__new_host (&host_env); dump_trace = verbose >1 ?1 :0 ;
@@ -209,6 +212,7 @@ static int mmap_events(synth_cb synth) }machine__delete (machine); +perf_env__exit (&host_env);return err; }
tools/perf/tests/symbols.c +7 -1
@@ -5,6 +5,7 @@#include <limits.h> #include "debug.h" #include "dso.h" +#include "env.h" #include "machine.h" #include "thread.h" #include "symbol.h"
@@ -13,15 +14,18 @@#include "tests.h" struct test_info { +struct perf_env host_env;struct machine *machine;struct thread *thread; };static int init_test_info (struct test_info *ti) { - ti->machine =machine__new_host (); +perf_env__init (&ti->host_env); + ti->machine =machine__new_host (&ti->host_env);if (!ti->machine) {pr_debug ("machine__new_host() failed!\n" ); +perf_env__exit (&ti->host_env);return TEST_FAIL ; }
@@ -29,6 +33,7 @@ static int init_test_info(struct test_info *ti) ti->thread =machine__findnew_thread (ti->machine,100 ,100 );if (!ti->thread) {pr_debug ("machine__findnew_thread() failed!\n" ); +perf_env__exit (&ti->host_env);return TEST_FAIL ; }
@@ -39,6 +44,7 @@ static void exit_test_info(struct test_info *ti) {thread__put (ti->thread);machine__delete (ti->machine); +perf_env__exit (&ti->host_env); }struct dso_map {
tools/perf/util/debug.c +8 -1
@@ -17,6 +17,7 @@#include "addr_location.h" #include "color.h" #include "debug.h" +#include "env.h" #include "event.h" #include "machine.h" #include "map.h"
@@ -309,8 +310,12 @@ void __dump_stack(FILE *file, void **stackdump, size_t stackdump_size) {/* TODO: async safety. printf, malloc, etc. aren't safe inside a signal handler. */ pid_t pid =getpid (); -struct machine *machine =machine__new_live (/*kernel_maps=*/ false, pid); +struct machine *machine;struct thread *thread =NULL ; +struct perf_env host_env; + +perf_env__init (&host_env); + machine =machine__new_live (&host_env,/*kernel_maps=*/ false, pid);if (machine) thread =machine__find_thread (machine, pid, pid);
@@ -323,6 +328,7 @@ void __dump_stack(FILE *file, void **stackdump, size_t stackdump_size)*/ backtrace_symbols_fd (stackdump, stackdump_size,fileno (file));machine__delete (machine); +perf_env__exit (&host_env); return; }#endif
@@ -349,6 +355,7 @@ void __dump_stack(FILE *file, void **stackdump, size_t stackdump_size) }thread__put (thread);machine__delete (machine); +perf_env__exit (&host_env); }/* Obtain a backtrace and print it to stdout. */
tools/perf/util/machine.c +8 -8
@@ -129,7 +129,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)return 0 ; } -static struct machine *__machine__new_host (bool kernel_maps) +static struct machine *__machine__new_host (struct perf_env *host_env,bool kernel_maps) {struct machine *machine =malloc (sizeof (*machine));
@@ -142,13 +142,13 @@ static struct machine *__machine__new_host(bool kernel_maps)free (machine);return NULL ; } - machine->env = &perf_env; + machine->env = host_env;return machine; } -struct machine *machine__new_host (void ) +struct machine *machine__new_host (struct perf_env *host_env) { -return __machine__new_host (/*kernel_maps=*/ true); +return __machine__new_host (host_env,/*kernel_maps=*/ true); } static int mmap_handler(const struct perf_tool *tool __maybe_unused,
@@ -168,9 +168,9 @@ static int machine__init_live(struct machine *machine, pid_t pid) mmap_handler, machine, true); } -struct machine *machine__new_live (bool kernel_maps,pid_t pid) +struct machine *machine__new_live (struct perf_env *host_env,bool kernel_maps,pid_t pid) { -struct machine *machine =__machine__new_host (kernel_maps); +struct machine *machine =__machine__new_host (host_env, kernel_maps);if (!machine)return NULL ;
@@ -182,9 +182,9 @@ struct machine *machine__new_live(bool kernel_maps, pid_t pid)return machine; } -struct machine *machine__new_kallsyms (void ) +struct machine *machine__new_kallsyms (struct perf_env *host_env) { -struct machine *machine =machine__new_host (); +struct machine *machine =machine__new_host (host_env);/* * FIXME: * 1) We should switch to machine__load_kallsyms(), i.e. not explicitly
tools/perf/util/machine.h +3 -3
@@ -169,9 +169,9 @@ struct thread *machine__findnew_guest_code(struct machine *machine, pid_t pid);void machines__set_id_hdr_size (struct machines *machines,u16 id_hdr_size);void machines__set_comm_exec (struct machines *machines,bool comm_exec); -struct machine *machine__new_host (void ); -struct machine *machine__new_kallsyms (void ); -struct machine *machine__new_live (bool kernel_maps,pid_t pid); +struct machine *machine__new_host (struct perf_env *host_env); +struct machine *machine__new_kallsyms (struct perf_env *host_env); +struct machine *machine__new_live (struct perf_env *host_env,bool kernel_maps,pid_t pid);int machine__init (struct machine *machine,const char *root_dir,pid_t pid);void machine__exit (struct machine *machine);void machine__delete_threads (struct machine *machine);
tools/perf/util/probe-event.c +4 -1
@@ -75,12 +75,14 @@ int e_snprintf(char *str, size_t size, const char *format, ...) }static struct machine *host_machine; +static struct perf_env host_env;/* Initialize symbol maps and path of vmlinux/modules */ int init_probe_symbol_maps (bool user_only) {int ret; +perf_env__init (&host_env); symbol_conf.allow_aliases = true; ret =symbol__init (NULL );if (ret <0 ) {
@@ -94,7 +96,7 @@ int init_probe_symbol_maps(bool user_only)if (symbol_conf.vmlinux_name)pr_debug ("Use vmlinux: %s\n" , symbol_conf.vmlinux_name); - host_machine =machine__new_host (); + host_machine =machine__new_host (&host_env);if (!host_machine) {pr_debug ("machine__new_host() failed.\n" );symbol__exit ();
@@ -111,6 +113,7 @@ void exit_probe_symbol_maps(void)machine__delete (host_machine); host_machine =NULL ;symbol__exit (); +perf_env__exit (&host_env); }static struct ref_reloc_sym *kernel_get_ref_reloc_sym (struct map **pmap)
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 18/23 perf auxtrace: Pass perf_env from session through to mmap read
In reply to Ian Rogers auxtrace_mmap__read and auxtrace_mmap__read_snapshot end up calling evsel__env(NULL) which returns the global perf_env variable for the host. Their only call is in perf record. Rather than use the global variable pass through the perf_env for perf record.
--- tools/perf/builtin-record.c | 8 ++++++-- tools/perf/util/auxtrace.c | 13 +++++++------ tools/perf/util/auxtrace.h | 6 ++++-- 3 files changed, 17 insertions(+), 10 deletions(-)
tools/perf/builtin-record.c +6 -2
@@ -775,7 +775,9 @@ static int record__auxtrace_mmap_read(struct record *rec, {int ret; - ret =auxtrace_mmap__read (map, rec->itr, &rec->tool, + ret =auxtrace_mmap__read (map, rec->itr, +perf_session__env (rec->session), + &rec->tool, record__process_auxtrace);if (ret <0 )return ret;
@@ -791,7 +793,9 @@ static int record__auxtrace_mmap_read_snapshot(struct record *rec, {int ret; - ret =auxtrace_mmap__read_snapshot (map, rec->itr, &rec->tool, + ret =auxtrace_mmap__read_snapshot (map, rec->itr, +perf_session__env (rec->session), + &rec->tool, record__process_auxtrace, rec->opts.auxtrace_snapshot_size);if (ret <0 )
tools/perf/util/auxtrace.c +7 -6
@@ -1890,7 +1890,7 @@ int __weak compat_auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) }static int __auxtrace_mmap__read (struct mmap *map, -struct auxtrace_record *itr, +struct auxtrace_record *itr,struct perf_env *env,const struct perf_tool *tool,process_auxtrace_t fn,bool snapshot,size_t snapshot_size) {
@@ -1900,7 +1900,7 @@ static int __auxtrace_mmap__read(struct mmap *map,size_t size, head_off, old_off, len1, len2, padding;union perf_event ev;void *data1, *data2; -int kernel_is_64_bit =perf_env__kernel_is_64_bit (evsel__env (NULL )); +int kernel_is_64_bit =perf_env__kernel_is_64_bit (env); head =auxtrace_mmap__read_head (mm, kernel_is_64_bit);
@@ -2002,17 +2002,18 @@ static int __auxtrace_mmap__read(struct mmap *map, }int auxtrace_mmap__read (struct mmap *map,struct auxtrace_record *itr, -const struct perf_tool *tool,process_auxtrace_t fn) +struct perf_env *env,const struct perf_tool *tool, +process_auxtrace_t fn) { -return __auxtrace_mmap__read (map, itr, tool, fn, false,0 ); +return __auxtrace_mmap__read (map, itr, env, tool, fn, false,0 ); }int auxtrace_mmap__read_snapshot (struct mmap *map, -struct auxtrace_record *itr, +struct auxtrace_record *itr,struct perf_env *env,const struct perf_tool *tool,process_auxtrace_t fn,size_t snapshot_size) { -return __auxtrace_mmap__read (map, itr, tool, fn, true, snapshot_size); +return __auxtrace_mmap__read (map, itr, env, tool, fn, true, snapshot_size); }/**
tools/perf/util/auxtrace.h +4 -2
@@ -23,6 +23,7 @@ union perf_event;struct perf_session ;struct evlist ;struct evsel ; +struct perf_env ;struct perf_tool ;struct mmap ;struct perf_sample ;
@@ -512,10 +513,11 @@ typedef int (*process_auxtrace_t)(const struct perf_tool *tool, size_t len1, void *data2, size_t len2);int auxtrace_mmap__read (struct mmap *map,struct auxtrace_record *itr, -const struct perf_tool *tool,process_auxtrace_t fn); +struct perf_env *env,const struct perf_tool *tool, +process_auxtrace_t fn);int auxtrace_mmap__read_snapshot (struct mmap *map, -struct auxtrace_record *itr, +struct auxtrace_record *itr,struct perf_env *env,const struct perf_tool *tool,process_auxtrace_t fn,size_t snapshot_size);
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 19/23 perf trace: Avoid global perf_env with evsel__env
In reply to Ian RogersThere is no session in perf trace unless in replay mode, so in host mode no session can be associated with the evlist. If the evsel__env call fails resort to the host_env that's part of the trace. Remove errno_to_name as it becomes a called once 1-line function once the argument is turned into a perf_env, just call perf_env__arch_strerrno directly.
--- tools/perf/builtin-trace.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
tools/perf/builtin-trace.c +3 -9
@@ -2904,13 +2904,6 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *samreturn sample__fprintf_callchain (sample,38 , print_opts,get_tls_callchain_cursor (), symbol_conf.bt_stop_list, trace->output); } -static const char *errno_to_name (struct evsel *evsel,int err) -{ -struct perf_env *env =evsel__env (evsel); - -return perf_env__arch_strerrno (env, err); -} -static int trace__sys_exit (struct trace *trace,struct evsel *evsel,union perf_event *event__maybe_unused ,struct perf_sample *sample)
@@ -2996,8 +2989,9 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel, }else if (ret <0 ) { errno_print: {char bf[STRERR_BUFSIZE ]; -const char *emsg =str_error_r (-ret, bf,sizeof (bf)), - *e =errno_to_name (evsel, -ret); +struct perf_env *env =evsel__env (evsel) ?: &trace->host_env; +const char *emsg =str_error_r (-ret, bf,sizeof (bf)); +const char *e =perf_env__arch_strerrno (env, err);fprintf (trace->output,"-1 %s (%s)" , e, emsg); }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 20/23 perf env: Remove global perf_env
In reply to Ian RogersThe global perf_env was used for the host, but if a perf_env wasn't easy to come by it was used in a lot of places where potentially recorded and host data could be confused. Remove the global variable as now the majority of accesses retrieve the perf_env for the host from the session.
--- tools/perf/perf.c | 3 --- tools/perf/util/bpf-event.c | 2 +- tools/perf/util/env.c | 2 -- tools/perf/util/env.h | 2 -- tools/perf/util/evsel.c | 2 +- tools/perf/util/session.c | 3 ++- 6 files changed, 4 insertions(+), 10 deletions(-)
tools/perf/perf.c +0 -3
@@ -346,12 +346,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) use_pager =1 ;commit_pager_choice (); -perf_env__init (&perf_env); -perf_env__set_cmdline (&perf_env, argc, argv); status = p->fn (argc, argv);perf_config__exit ();exit_browser (status); -perf_env__exit (&perf_env);if (status)return status &0xff ;
tools/perf/util/bpf-event.c +1 -1
@@ -549,7 +549,7 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,* for perf-record and perf-report use header.env; * otherwise, use global perf_env. */ - env = session->data ?perf_session__env (session) : &perf_env; + env =perf_session__env (session); arrays =1UL <<PERF_BPIL_JITED_KSYMS ; arrays |=1UL <<PERF_BPIL_JITED_FUNC_LENS ;
tools/perf/util/env.c +0 -2
@@ -19,8 +19,6 @@#include "strbuf.h" #include "trace/beauty/beauty.h" -struct perf_env perf_env; -#ifdef HAVE_LIBBPF_SUPPORT #include "bpf-event.h" #include "bpf-utils.h"
tools/perf/util/env.h +0 -2
@@ -150,8 +150,6 @@ enum perf_compress_type {struct bpf_prog_info_node ;struct btf_node ; -extern struct perf_env perf_env; -void perf_env__exit (struct perf_env *env);int perf_env__kernel_is_64_bit (struct perf_env *env);
tools/perf/util/evsel.c +1 -1
@@ -3849,7 +3849,7 @@ struct perf_env *evsel__env(struct evsel *evsel) {struct perf_session *session =evsel__session (evsel); -return session ?perf_session__env (session) : &perf_env; +return session ?perf_session__env (session) :NULL ; }static int store_evsel_ids (struct evsel *evsel,struct evlist *evlist)
tools/perf/util/session.c +2 -1
@@ -193,7 +193,8 @@ struct perf_session *__perf_session__new(struct perf_data *data, symbol_conf.kallsyms_name =perf_data__kallsyms_name (data); } }else { - session->machines.host.env = host_env ?: &perf_env; +assert (host_env !=NULL ); + session->machines.host.env = host_env; }if (session->evlist) session->evlist->session = session;
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 21/23 perf sample: Remove arch notion of sample parsing
In reply to Ian RogersBy definition arch sample parsing and synthesis will inhibit certain kinds of cross-platform record then analysis (report, script, etc.). Remove arch_perf_parse_sample_weight and arch_perf_synthesize_sample_weight replacing with a common implementation. Combine perf_sample p_stage_cyc and retire_lat as weight3 to capture the differing uses regardless of compiled for architecture.
--- tools/perf/arch/powerpc/util/event.c | 26 --------------------- tools/perf/arch/x86/tests/sample-parsing.c | 4 ++-- tools/perf/arch/x86/util/event.c | 27 ---------------------- tools/perf/builtin-script.c | 2 +- tools/perf/util/dlfilter.c | 2 +- tools/perf/util/event.h | 2 -- tools/perf/util/evsel.c | 17 ++++++++++---- tools/perf/util/hist.c | 4 ++-- tools/perf/util/hist.h | 3 ++- tools/perf/util/intel-tpebs.c | 4 ++-- tools/perf/util/sample.h | 6 ++--- tools/perf/util/session.c | 2 +- tools/perf/util/sort.c | 7 +++--- tools/perf/util/synthetic-events.c | 10 ++++++-- 14 files changed, 36 insertions(+), 80 deletions(-)
tools/perf/arch/powerpc/util/event.c +0 -26
@@ -11,32 +11,6 @@#include "../../../util/debug.h" #include "../../../util/sample.h" -void arch_perf_parse_sample_weight (struct perf_sample *data, -const __u64 *array,u64 type) -{ -union perf_sample_weight weight; - - weight.full = *array; -if (type &PERF_SAMPLE_WEIGHT ) - data->weight = weight.full; -else { - data->weight = weight.var1_dw; - data->ins_lat = weight.var2_w; - data->p_stage_cyc = weight.var3_w; - } -} - -void arch_perf_synthesize_sample_weight (const struct perf_sample *data, -__u64 *array,u64 type) -{ - *array = data->weight; - -if (type &PERF_SAMPLE_WEIGHT_STRUCT ) { - *array &=0xffffffff ; - *array |= ((u64 )data->ins_lat <<32 ); - } -} -const char *arch_perf_header_entry (const char *se_header) {if (!strcmp (se_header,"Local INSTR Latency" ))
tools/perf/arch/x86/tests/sample-parsing.c +2 -2
@@ -29,7 +29,7 @@ static bool samples_same(const struct perf_sample *s1, {if (type &PERF_SAMPLE_WEIGHT_STRUCT ) {COMP (ins_lat); -COMP (retire_lat); +COMP (weight3); }return true;
@@ -50,7 +50,7 @@ static int do_test(u64 sample_type)struct perf_sample sample = { .weight =101 , .ins_lat =102 , - .retire_lat =103 , + .weight3 =103 , };struct perf_sample sample_out;size_t i, sz, bufsz;
tools/perf/arch/x86/util/event.c +0 -27
@@ -92,33 +92,6 @@ int perf_event__synthesize_extra_kmaps(const struct perf_tool *tool,#endif -void arch_perf_parse_sample_weight (struct perf_sample *data, -const __u64 *array,u64 type) -{ -union perf_sample_weight weight; - - weight.full = *array; -if (type &PERF_SAMPLE_WEIGHT ) - data->weight = weight.full; -else { - data->weight = weight.var1_dw; - data->ins_lat = weight.var2_w; - data->retire_lat = weight.var3_w; - } -} - -void arch_perf_synthesize_sample_weight (const struct perf_sample *data, -__u64 *array,u64 type) -{ - *array = data->weight; - -if (type &PERF_SAMPLE_WEIGHT_STRUCT ) { - *array &=0xffffffff ; - *array |= ((u64 )data->ins_lat <<32 ); - *array |= ((u64 )data->retire_lat <<48 ); - } -} -const char *arch_perf_header_entry (const char *se_header) {if (!strcmp (se_header,"Local Pipeline Stage Cycle" ))
tools/perf/builtin-script.c +1 -1
@@ -2253,7 +2253,7 @@ static void process_event(struct perf_script *script,fprintf (fp,"%16" PRIu16, sample->ins_lat);if (PRINT_FIELD (RETIRE_LAT )) -fprintf (fp,"%16" PRIu16, sample->retire_lat); +fprintf (fp,"%16" PRIu16, sample->weight3);if (PRINT_FIELD (CGROUP )) {const char *cgrp_name;
tools/perf/util/dlfilter.c +1 -1
@@ -513,6 +513,7 @@ int dlfilter__do_filter_event(struct dlfilter *d, d->d_addr_al = &d_addr_al; d_sample.size =sizeof (d_sample); + d_sample.p_stage_cyc = sample->weight3; d_ip_al.size =0 ;/* To indicate d_ip_al is not initialized */ d_addr_al.size =0 ;/* To indicate d_addr_al is not initialized */
@@ -526,7 +527,6 @@ int dlfilter__do_filter_event(struct dlfilter *d,ASSIGN (period);ASSIGN (weight);ASSIGN (ins_lat); -ASSIGN (p_stage_cyc);ASSIGN (transaction);ASSIGN (insn_cnt);ASSIGN (cyc_cnt);
tools/perf/util/event.h +0 -2
@@ -391,8 +391,6 @@ extern unsigned int proc_map_timeout;#define PAGE_SIZE_NAME_LEN 32char *get_page_size_name (u64 size,char *str); -void arch_perf_parse_sample_weight (struct perf_sample *data,const __u64 *array,u64 type); -void arch_perf_synthesize_sample_weight (const struct perf_sample *data,__u64 *array,u64 type);const char *arch_perf_header_entry (const char *se_header);int arch_support_sort_key (const char *sort_key);
tools/perf/util/evsel.c +12 -5
@@ -2847,11 +2847,18 @@ perf_event__check_size(union perf_event *event, unsigned int sample_size)return 0 ; } -void __weak arch_perf_parse_sample_weight (struct perf_sample *data, -const __u64 *array, -u64 type__maybe_unused ) +static void perf_parse_sample_weight (struct perf_sample *data,const __u64 *array,u64 type) { - data->weight = *array; +union perf_sample_weight weight; + + weight.full = *array; +if (type &PERF_SAMPLE_WEIGHT_STRUCT ) { + data->weight = weight.var1_dw; + data->ins_lat = weight.var2_w; + data->weight3 = weight.var3_w; + }else { + data->weight = weight.full; + } }u64 evsel__bitfield_swap_branch_flags (u64 value)
@@ -3237,7 +3244,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event,if (type &PERF_SAMPLE_WEIGHT_TYPE ) {OVERFLOW_CHECK_u64 (array); -arch_perf_parse_sample_weight (data, array, type); +perf_parse_sample_weight (data, array, type); array++; }
tools/perf/util/hist.c +2 -2
@@ -829,7 +829,7 @@ __hists__add_entry(struct hists *hists, .period = sample->period, .weight1 = sample->weight, .weight2 = sample->ins_lat, - .weight3 = sample->p_stage_cyc, + .weight3 = sample->weight3, .latency = al->latency, }, .parent = sym_parent,
@@ -846,7 +846,7 @@ __hists__add_entry(struct hists *hists, .time = hist_time(sample->time), .weight = sample->weight, .ins_lat = sample->ins_lat, - .p_stage_cyc = sample->p_stage_cyc, + .weight3 = sample->weight3, .simd_flags = sample->simd_flags, }, *he = hists__findnew_entry(hists, &entry, al, sample_self);
tools/perf/util/hist.h +2 -1
@@ -255,7 +255,8 @@ struct hist_entry {u64 code_page_size;u64 weight;u64 ins_lat; -u64 p_stage_cyc; +/** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ +u64 weight3;s32 socket;s32 cpu;int parallelism;
tools/perf/util/intel-tpebs.c +2 -2
@@ -210,8 +210,8 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,* latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ - t->last = sample->retire_lat; -update_stats (&t->stats, sample->retire_lat); + t->last = sample->weight3; +update_stats (&t->stats, sample->weight3);mutex_unlock (tpebs_mtx_get ());return 0 ; }
tools/perf/util/sample.h +2 -4
@@ -104,10 +104,8 @@ struct perf_sample {u8 cpumode;u16 misc;u16 ins_lat; -union { -u16 p_stage_cyc; -u16 retire_lat; - }; +/** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ +u16 weight3;bool no_hw_idx;/* No hw_idx collected in branch_stack */ char insn[MAX_INSN ];void *raw_data;
tools/perf/util/session.c +1 -1
@@ -1100,7 +1100,7 @@ static void dump_sample(struct evsel *evsel, union perf_event *event,printf ("... weight: %" PRIu64"" , sample->weight);if (sample_type &PERF_SAMPLE_WEIGHT_STRUCT ) {printf (",0x%" PRIx16"" , sample->ins_lat); -printf (",0x%" PRIx16"" , sample->p_stage_cyc); +printf (",0x%" PRIx16"" , sample->weight3); }printf ("\n" ); }
tools/perf/util/sort.c +3 -4
@@ -1884,21 +1884,20 @@ struct sort_entry sort_global_ins_lat = {static int64_t sort__p_stage_cyc_cmp (struct hist_entry *left,struct hist_entry *right) { -return left->p_stage_cyc - right->p_stage_cyc; +return left->weight3 - right->weight3; }static int hist_entry__global_p_stage_cyc_snprintf (struct hist_entry *he,char *bf,size_t size,unsigned int width) { -return repsep_snprintf (bf, size,"%-*u" , width, - he->p_stage_cyc * he->stat.nr_events); +return repsep_snprintf (bf, size,"%-*u" , width, he->weight3 * he->stat.nr_events); }static int hist_entry__p_stage_cyc_snprintf (struct hist_entry *he,char *bf,size_t size,unsigned int width) { -return repsep_snprintf (bf, size,"%-*u" , width, he->p_stage_cyc); +return repsep_snprintf (bf, size,"%-*u" , width, he->weight3); }struct sort_entry sort_local_p_stage_cyc = {
tools/perf/util/synthetic-events.c +8 -2
@@ -1573,10 +1573,16 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,return result; } -void __weak arch_perf_synthesize_sample_weight (const struct perf_sample *data, +static void perf_synthesize_sample_weight (const struct perf_sample *data,__u64 *array,u64 type__maybe_unused ) { *array = data->weight; + +if (type &PERF_SAMPLE_WEIGHT_STRUCT ) { + *array &=0xffffffff ; + *array |= ((u64 )data->ins_lat <<32 ); + *array |= ((u64 )data->weight3 <<48 ); + } } static __u64 *copy_read_group_values(__u64 *array, __u64 read_format,
@@ -1736,7 +1742,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo }if (type &PERF_SAMPLE_WEIGHT_TYPE ) { -arch_perf_synthesize_sample_weight (sample, array, type); +perf_synthesize_sample_weight (sample, array, type); array++; }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 22/23 perf test: Move PERF_SAMPLE_WEIGHT_STRUCT parsing to common test
In reply to Ian Rogerstest__x86_sample_parsing is identical to test__sample_parsing except it explicitly tested PERF_SAMPLE_WEIGHT_STRUCT. Now the parsing code is common move the PERF_SAMPLE_WEIGHT_STRUCT to the common sample parsing test and remove the x86 version.
--- tools/perf/arch/x86/include/arch-tests.h | 1 - tools/perf/arch/x86/tests/Build | 1 - tools/perf/arch/x86/tests/arch-tests.c | 2 - tools/perf/arch/x86/tests/sample-parsing.c | 125 --------------------- tools/perf/tests/sample-parsing.c | 14 +++ 5 files changed, 14 insertions(+), 129 deletions(-) delete mode 100644 tools/perf/arch/x86/tests/sample-parsing.c
tools/perf/arch/x86/include/arch-tests.h +0 -1
@@ -12,7 +12,6 @@ int test__insn_x86(struct test_suite *test, int subtest);int test__intel_pt_pkt_decoder (struct test_suite *test,int subtest);int test__intel_pt_hybrid_compat (struct test_suite *test,int subtest);int test__bp_modify (struct test_suite *test,int subtest); -int test__x86_sample_parsing (struct test_suite *test,int subtest);int test__amd_ibs_via_core_pmu (struct test_suite *test,int subtest);int test__amd_ibs_period (struct test_suite *test,int subtest);int test__hybrid (struct test_suite *test,int subtest);
tools/perf/arch/x86/tests/Build +0 -1
@@ -2,7 +2,6 @@ perf-test-$(CONFIG_DWARF_UNWIND) += regs_load.o perf-test-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o perf-test-y += arch-tests.o -perf-test-y += sample-parsing.o perf-test-y += hybrid.o perf-test-$(CONFIG_AUXTRACE) += intel-pt-test.o ifeq ($(CONFIG_EXTRA_TESTS),y)
tools/perf/arch/x86/tests/arch-tests.c +0 -2
@@ -23,7 +23,6 @@ struct test_suite suite__intel_pt = {#if defined(__x86_64__)DEFINE_SUITE ("x86 bp modify" , bp_modify);#endif -DEFINE_SUITE ("x86 Sample parsing" , x86_sample_parsing);DEFINE_SUITE ("AMD IBS via core pmu" , amd_ibs_via_core_pmu);DEFINE_SUITE_EXCLUSIVE ("AMD IBS sample period" , amd_ibs_period);static struct test_case hybrid_tests[] = {
@@ -49,7 +48,6 @@ struct test_suite *arch_tests[] = {#if defined(__x86_64__) &suite__bp_modify, #endif - &suite__x86_sample_parsing, &suite__amd_ibs_via_core_pmu, &suite__amd_ibs_period, &suite__hybrid,
tools/perf/arch/x86/tests/sample-parsing.c deleted +0 -125
125 lines not on this page · raw message
tools/perf/tests/sample-parsing.c +14 -0
@@ -152,6 +152,12 @@ static bool samples_same(struct perf_sample *s1,if (type &PERF_SAMPLE_WEIGHT )COMP (weight); +if (type &PERF_SAMPLE_WEIGHT_STRUCT ) { +COMP (weight); +COMP (ins_lat); +COMP (weight3); + } +if (type &PERF_SAMPLE_DATA_SRC )COMP (data_src);
@@ -269,6 +275,8 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) .cgroup = 114, .data_page_size = 115, .code_page_size = 116, + .ins_lat = 117, + .weight3 = 118, .aux_sample = { .size = sizeof(aux_data), .data = (void *)aux_data,
@@ -439,6 +447,12 @@ static int test__sample_parsing(struct test_suite *test __maybe_unused, int subtif (err)return err; } + sample_type = (PERF_SAMPLE_MAX -1 ) & ~PERF_SAMPLE_WEIGHT_STRUCT ; +for (i =0 ; i <ARRAY_SIZE (rf); i++) { + err =do_test (sample_type, sample_regs, rf[i]); +if (err) +return err; + }return 0 ; }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Ian Rogers
reviewerPATCH v5 23/23 perf sort: Use perf_env to set arch sort keys and header
In reply to Ian RogersPreviously arch_support_sort_key and arch_perf_header_entry used a weak symbol to compile as appropriate for x86 and powerpc. A limitation to this is that the handling of a data file could vary in cross-platform development. Change to using the perf_env of the current session to determine the architecture kind and set the sort key and header entries as appropriate.
--- tools/perf/arch/powerpc/util/Build | 1 - tools/perf/arch/powerpc/util/event.c | 34 ---------------- tools/perf/arch/x86/util/event.c | 19 --------- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-c2c.c | 53 +++++++++++++----------- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 22 +++++----- tools/perf/tests/hists_cumulate.c | 8 ++-- tools/perf/tests/hists_filter.c | 8 ++-- tools/perf/tests/hists_link.c | 8 ++-- tools/perf/tests/hists_output.c | 10 ++--- tools/perf/util/event.h | 3 -- tools/perf/util/sort.c | 61 ++++++++++++++++++++-------- tools/perf/util/sort.h | 5 ++- 15 files changed, 107 insertions(+), 131 deletions(-) delete mode 100644 tools/perf/arch/powerpc/util/event.c
tools/perf/arch/powerpc/util/Build +0 -1
@@ -5,7 +5,6 @@ perf-util-y += mem-events.o perf-util-y += pmu.o perf-util-y += sym-handling.o perf-util-y += evsel.o -perf-util-y += event.o perf-util-$(CONFIG_LIBDW) += skip-callchain-idx.o
tools/perf/arch/powerpc/util/event.c deleted +0 -34
@@ -1,34 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <linux/types.h> -#include <linux/string.h> -#include <linux/zalloc.h> - -#include "../../../util/event.h" -#include "../../../util/synthetic-events.h" -#include "../../../util/machine.h" -#include "../../../util/tool.h" -#include "../../../util/map.h" -#include "../../../util/debug.h" -#include "../../../util/sample.h" - -const char *arch_perf_header_entry (const char *se_header) -{ -if (!strcmp (se_header,"Local INSTR Latency" )) -return "Finish Cyc" ; -else if (!strcmp (se_header,"INSTR Latency" )) -return "Global Finish_cyc" ; -else if (!strcmp (se_header,"Local Pipeline Stage Cycle" )) -return "Dispatch Cyc" ; -else if (!strcmp (se_header,"Pipeline Stage Cycle" )) -return "Global Dispatch_cyc" ; -return se_header; -} - -int arch_support_sort_key (const char *sort_key) -{ -if (!strcmp (sort_key,"p_stage_cyc" )) -return 1 ; -if (!strcmp (sort_key,"local_p_stage_cyc" )) -return 1 ; -return 0 ; -}
tools/perf/arch/x86/util/event.c +0 -19
@@ -91,22 +91,3 @@ int perf_event__synthesize_extra_kmaps(const struct perf_tool *tool, }#endif - -const char *arch_perf_header_entry (const char *se_header) -{ -if (!strcmp (se_header,"Local Pipeline Stage Cycle" )) -return "Local Retire Latency" ; -else if (!strcmp (se_header,"Pipeline Stage Cycle" )) -return "Retire Latency" ; - -return se_header; -} - -int arch_support_sort_key (const char *sort_key) -{ -if (!strcmp (sort_key,"p_stage_cyc" )) -return 1 ; -if (!strcmp (sort_key,"local_p_stage_cyc" )) -return 1 ; -return 0 ; -}
tools/perf/builtin-annotate.c +1 -1
@@ -947,7 +947,7 @@ int cmd_annotate(int argc, const char **argv) annotate_opts.show_br_cntr = true; } -if (setup_sorting (NULL ) <0 ) +if (setup_sorting (/*evlist=*/ NULL ,perf_session__env (annotate.session)) <0 )usage_with_options (annotate_usage, options); ret =__cmd_annotate (&annotate);
tools/perf/builtin-c2c.c +30 -23
183 lines not on this page · raw message
tools/perf/builtin-diff.c +1 -1
@@ -2003,7 +2003,7 @@ int cmd_diff(int argc, const char **argv) sort__mode =SORT_MODE__DIFF ; } -if (setup_sorting (NULL ) <0 ) +if (setup_sorting (/*evlist=*/ NULL ,perf_session__env (data__files[0 ].session)) <0 )usage_with_options (diff_usage, options);setup_pager ();
tools/perf/builtin-report.c +1 -1
@@ -1790,7 +1790,7 @@ int cmd_report(int argc, const char **argv) }if ((last_key !=K_SWITCH_INPUT_DATA && last_key !=K_RELOAD ) && - (setup_sorting (session->evlist) <0 )) { + (setup_sorting (session->evlist, &session->header.env) <0 )) {if (sort_order)parse_options_usage (report_usage, options,"s" ,1 );if (field_order)
tools/perf/builtin-top.c +11 -11
@@ -1759,7 +1759,17 @@ int cmd_top(int argc, const char **argv)setup_browser (false); -if (setup_sorting (top.evlist) <0 ) { + top.session =__perf_session__new (/*data=*/ NULL ,/*tool=*/ NULL , +/*trace_event_repipe=*/ false, + &host_env); +if (IS_ERR (top.session)) { + status =PTR_ERR (top.session); + top.session =NULL ; + goto out_delete_evlist; + } + top.evlist->session = top.session; + +if (setup_sorting (top.evlist,perf_session__env (top.session)) <0 ) {if (sort_order)parse_options_usage (top_usage, options,"s" ,1 );if (field_order)
@@ -1834,16 +1844,6 @@ int cmd_top(int argc, const char **argv)signal (SIGWINCH , winch_sig); } - top.session =__perf_session__new (/*data=*/ NULL ,/*tool=*/ NULL , -/*trace_event_repipe=*/ false, - &host_env); -if (IS_ERR (top.session)) { - status =PTR_ERR (top.session); - top.session =NULL ; - goto out_delete_evlist; - } - top.evlist->session = top.session; -if (!evlist__needs_bpf_sb_event (top.evlist)) top.record_opts.no_bpf_event = true;
tools/perf/tests/hists_cumulate.c +4 -4
@@ -295,7 +295,7 @@ static int test1(struct evsel *evsel, struct machine *machine) symbol_conf.cumulate_callchain = false;evsel__reset_sample_bit (evsel,CALLCHAIN ); -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);callchain_register_param (&callchain_param); err =add_hist_entries (hists, machine);
@@ -442,7 +442,7 @@ static int test2(struct evsel *evsel, struct machine *machine) symbol_conf.cumulate_callchain = false;evsel__set_sample_bit (evsel,CALLCHAIN ); -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);callchain_register_param (&callchain_param); err =add_hist_entries (hists, machine);
@@ -500,7 +500,7 @@ static int test3(struct evsel *evsel, struct machine *machine) symbol_conf.cumulate_callchain = true;evsel__reset_sample_bit (evsel,CALLCHAIN ); -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);callchain_register_param (&callchain_param); err =add_hist_entries (hists, machine);
@@ -684,7 +684,7 @@ static int test4(struct evsel *evsel, struct machine *machine) symbol_conf.cumulate_callchain = true;evsel__set_sample_bit (evsel,CALLCHAIN ); -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env); callchain_param = callchain_param_default;callchain_register_param (&callchain_param);
tools/perf/tests/hists_filter.c +4 -4
@@ -131,10 +131,6 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes goto out; err =TEST_FAIL ; -/* default sort order (comm,dso,sym) will be used */ -if (setup_sorting (NULL ) <0 ) - goto out; -machines__init (&machines);/* setup threads/dso/map/symbols also */
@@ -145,6 +141,10 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtesif (verbose >1 )machine__fprintf (machine, stderr); +/* default sort order (comm,dso,sym) will be used */ +if (setup_sorting (evlist, machine->env) <0 ) + goto out; +/* process sample events */ err =add_hist_entries (evlist, machine);if (err <0 )
tools/perf/tests/hists_link.c +4 -4
@@ -303,10 +303,6 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtest goto out; err =TEST_FAIL ; -/* default sort order (comm,dso,sym) will be used */ -if (setup_sorting (NULL ) <0 ) - goto out; -machines__init (&machines);/* setup threads/dso/map/symbols also */
@@ -317,6 +313,10 @@ static int test__hists_link(struct test_suite *test __maybe_unused, int subtestif (verbose >1 )machine__fprintf (machine, stderr); +/* default sort order (comm,dso,sym) will be used */ +if (setup_sorting (evlist, machine->env) <0 ) + goto out; +/* process sample events */ err =add_hist_entries (evlist, machine);if (err <0 )
tools/perf/tests/hists_output.c +5 -5
@@ -146,7 +146,7 @@ static int test1(struct evsel *evsel, struct machine *machine) field_order =NULL ; sort_order =NULL ;/* equivalent to sort_order = "comm,dso,sym" */ -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);/* * expected output:
@@ -248,7 +248,7 @@ static int test2(struct evsel *evsel, struct machine *machine) field_order ="overhead,cpu" ; sort_order ="pid" ; -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);/* * expected output:
@@ -304,7 +304,7 @@ static int test3(struct evsel *evsel, struct machine *machine) field_order ="comm,overhead,dso" ; sort_order =NULL ; -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);/* * expected output:
@@ -378,7 +378,7 @@ static int test4(struct evsel *evsel, struct machine *machine) field_order ="dso,sym,comm,overhead,dso" ; sort_order ="sym" ; -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);/* * expected output:
@@ -480,7 +480,7 @@ static int test5(struct evsel *evsel, struct machine *machine) field_order ="cpu,pid,comm,dso,sym" ; sort_order ="dso,pid" ; -setup_sorting (NULL ); +setup_sorting (/*evlist=*/ NULL , machine->env);/* * expected output:
tools/perf/util/event.h +0 -3
@@ -391,9 +391,6 @@ extern unsigned int proc_map_timeout;#define PAGE_SIZE_NAME_LEN 32char *get_page_size_name (u64 size,char *str); -const char *arch_perf_header_entry (const char *se_header); -int arch_support_sort_key (const char *sort_key); -static inline bool perf_event_header__cpumode_is_guest (u8 cpumode) { return cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
tools/perf/util/sort.c +43 -18
147 lines not on this page · raw message
tools/perf/util/sort.h +3 -2
@@ -6,6 +6,7 @@#include "hist.h" struct option ; +struct perf_env ;extern regex_t parent_regex;extern const char *sort_order;
@@ -130,7 +131,7 @@ extern struct sort_entry sort_thread;struct evlist ;struct tep_handle ; -int setup_sorting (struct evlist *evlist); +int setup_sorting (struct evlist *evlist,struct perf_env *env);int setup_output_field (void );void reset_output_field (void );void sort__setup_elide (FILE *fp);
@@ -145,7 +146,7 @@ bool is_strict_order(const char *order);int hpp_dimension__add_output (unsigned col,bool implicit);void reset_dimensions (void );int sort_dimension__add (struct perf_hpp_list *list,const char *tok, -struct evlist *evlist, +struct evlist *evlist,struct perf_env *env,int level);int output_field_add (struct perf_hpp_list *list,const char *tok,int *level);int64_t
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Namhyung Kim
maintainerRe: [PATCH v5 23/23] perf sort: Use perf_env to set arch sort keys and header
Quoted 9 lines · Ian Rogers
Previously
arch_support_sort_keyandarch_perf_header_entryused a weak symbol to compile as appropriate for x86 and powerpc. A limitation to this is that the handling of a data file could vary in cross-platform development. Change to using theperf_envof the current session to determine the architecture kind and set the sort key and header entries as appropriate.Signed-off-by Ian Rogers <[email protected]>---
[SNIP]
tools/perf/builtin-report.c int cmd_report(int argc, const char **argv) · line 1793
Quoted 10 lines
tools/perf/builtin-report.c +1
-1@@ -1790,7 +1790,7 @@ int cmd_report(int argc, const char **argv) }if ((last_key !=K_SWITCH_INPUT_DATA && last_key !=K_RELOAD ) && - (setup_sorting (session->evlist) <0 )) { + (setup_sorting (session->evlist, &session->header.env) <0 )) {
perf_session__env(session) ?
Thanks,
Namhyung
Quoted 3 lines
tools/perf/builtin-report.c +0
-0if (sort_order)parse_options_usage (report_usage, options,"s" ,1 );if (field_order)