[tip:perf/core] perf evsel: Add a backpointer to the evlist a evsel is in
Commit-ID: d49e4695077278ee3016cd242967de23072ec331 Gitweb: http://git.kernel.org/tip/d49e4695077278ee3016cd242967de23072ec331 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 27 Aug 2015 08:07:40 -0400 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 28 Aug 2015 14:53:49 -0300 perf evsel: Add a backpointer to the evlist a evsel is in So that functions that deal primarily with an evsel to access information that concerns the whole evlist it is in. Cc: Adrian Hunter Cc: Andi Kleen Cc: Andy Lutomirski Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1440677263-21954-5-git-send-email-kan.li...@intel.com Signed-off-by: Kan Liang Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 2 ++ tools/perf/util/evsel.c | 2 ++ tools/perf/util/evsel.h | 4 3 files changed, 8 insertions(+) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index e9a5d43..8d00039 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -98,6 +98,7 @@ static void perf_evlist__purge(struct perf_evlist *evlist) evlist__for_each_safe(evlist, n, pos) { list_del_init(>node); + pos->evlist = NULL; perf_evsel__delete(pos); } @@ -125,6 +126,7 @@ void perf_evlist__delete(struct perf_evlist *evlist) void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry) { + entry->evlist = evlist; list_add_tail(>node, >entries); entry->idx = evlist->nr_entries; entry->tracking = !entry->idx; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index b096ef7..bac25f4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -206,6 +206,7 @@ void perf_evsel__init(struct perf_evsel *evsel, evsel->leader = evsel; evsel->unit= ""; evsel->scale = 1.0; + evsel->evlist = NULL; INIT_LIST_HEAD(>node); INIT_LIST_HEAD(>config_terms); perf_evsel__object.init(evsel); @@ -1026,6 +1027,7 @@ void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads) void perf_evsel__exit(struct perf_evsel *evsel) { assert(list_empty(>node)); + assert(evsel->evlist == NULL); perf_evsel__free_fd(evsel); perf_evsel__free_id(evsel); perf_evsel__free_config_terms(evsel); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 93ac6b1..298e6bb 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -60,6 +60,9 @@ struct perf_evsel_config_term { /** struct perf_evsel - event selector * + * @evlist - evlist this evsel is in, if it is in one. + * @node - To insert it into evlist->entries or in other list_heads, say in + * the event parsing routines. * @name - Can be set to retain the original event name passed by the user, * so that when showing results in tools such as 'perf stat', we * show the name used, not some alias. @@ -73,6 +76,7 @@ struct perf_evsel_config_term { */ struct perf_evsel { struct list_headnode; + struct perf_evlist *evlist; struct perf_event_attr attr; char*filter; struct xyarray *fd; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf trace: Add read/write to the file group
Commit-ID: cf2f33a4e54096f90652cca3511fd6a456ea5abe Gitweb: http://git.kernel.org/tip/cf2f33a4e54096f90652cca3511fd6a456ea5abe Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 4 Sep 2015 13:22:06 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 4 Sep 2015 13:22:06 -0300 perf trace: Add read/write to the file group Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-l6812iuai3g486z3mn8uf...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/trace/strace/groups/file | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/trace/strace/groups/file b/tools/perf/trace/strace/groups/file index 62378a8..722e25d 100644 --- a/tools/perf/trace/strace/groups/file +++ b/tools/perf/trace/strace/groups/file @@ -9,6 +9,7 @@ mkdir open openat quotactl +read readlink rename rmdir @@ -16,3 +17,4 @@ stat statfs symlink unlink +write -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf evsel: Remove forward declaration of ' struct perf_evlist'
Commit-ID: 8168caded331a19302593a591f070136cb3a31c8 Gitweb: http://git.kernel.org/tip/8168caded331a19302593a591f070136cb3a31c8 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 9 Sep 2015 12:38:17 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:22 -0300 perf evsel: Remove forward declaration of 'struct perf_evlist' We have no use for it in evsel.h. Tested-by: Wang Nan Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-um03yjrgyi3bj1hzqiqs4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 298e6bb..f164a14 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -129,7 +129,6 @@ union u64_swap { struct cpu_map; struct target; struct thread_map; -struct perf_evlist; struct record_opts; static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf env: Rename some leftovers from rename to perf_env
Commit-ID: eebd0bfca5cb83f6e1ef0d872a16d45af0422114 Gitweb: http://git.kernel.org/tip/eebd0bfca5cb83f6e1ef0d872a16d45af0422114 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 8 Sep 2015 15:52:20 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:20 -0300 perf env: Rename some leftovers from rename to perf_env In ce80d3bef9ff ("perf tools: Rename perf_session_env to perf_env") we forgot to rename a few functions to the "perf_env" prefix, do it now. Tested-by: Wang Nan Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-b3ui3z6ock89z1814pu2e...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/common.c | 10 -- tools/perf/arch/common.h | 4 ++-- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/ui/browsers/hists.c | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c index b00dfd92..e83c8ce 100644 --- a/tools/perf/arch/common.c +++ b/tools/perf/arch/common.c @@ -128,9 +128,8 @@ static const char *normalize_arch(char *arch) return arch; } -static int perf_session_env__lookup_binutils_path(struct perf_env *env, - const char *name, - const char **path) +static int perf_env__lookup_binutils_path(struct perf_env *env, + const char *name, const char **path) { int idx; const char *arch, *cross_env; @@ -206,7 +205,7 @@ out_error: return -1; } -int perf_session_env__lookup_objdump(struct perf_env *env) +int perf_env__lookup_objdump(struct perf_env *env) { /* * For live mode, env->arch will be NULL and we can use @@ -215,6 +214,5 @@ int perf_session_env__lookup_objdump(struct perf_env *env) if (env->arch == NULL) return 0; - return perf_session_env__lookup_binutils_path(env, "objdump", - _path); + return perf_env__lookup_binutils_path(env, "objdump", _path); } diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h index 20176df..7529cfb 100644 --- a/tools/perf/arch/common.h +++ b/tools/perf/arch/common.h @@ -1,10 +1,10 @@ #ifndef ARCH_PERF_COMMON_H #define ARCH_PERF_COMMON_H -#include "../util/session.h" +#include "../util/env.h" extern const char *objdump_path; -int perf_session_env__lookup_objdump(struct perf_env *env); +int perf_env__lookup_objdump(struct perf_env *env); #endif /* ARCH_PERF_COMMON_H */ diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 8edc205..2bf9b3f 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -211,7 +211,7 @@ static int __cmd_annotate(struct perf_annotate *ann) } if (!objdump_path) { - ret = perf_session_env__lookup_objdump(>header.env); + ret = perf_env__lookup_objdump(>header.env); if (ret) goto out; } diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 8c465c8..e5ca684 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -952,7 +952,7 @@ static int __cmd_top(struct perf_top *top) machines__set_symbol_filter(>session->machines, symbol_filter); if (!objdump_path) { - ret = perf_session_env__lookup_objdump(>session->header.env); + ret = perf_env__lookup_objdump(>session->header.env); if (ret) goto out_delete; } diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index cf86f2d..17d6c6d 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -1437,7 +1437,7 @@ do_annotate(struct hist_browser *browser, struct popup_action *act) struct hist_entry *he; int err; - if (!objdump_path && perf_session_env__lookup_objdump(browser->env)) + if (!objdump_path && perf_env__lookup_objdump(browser->env)) return 0; notes = symbol__annotation(act->ms.sym); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf env: Adopt perf_header__set_cmdline
Commit-ID: b699869285c4f6949f281ea57ac35ea9b9c6f467 Gitweb: http://git.kernel.org/tip/b699869285c4f6949f281ea57ac35ea9b9c6f467 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 8 Sep 2015 16:58:20 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:21 -0300 perf env: Adopt perf_header__set_cmdline Move this from two globals to perf_env global, that eventually will be just perf_header->env or something else, to ease the refactoring series, leave it as a global and go on reading more of its fields, not as part of the header writing process but as a perf_env init one that will be used for perf.data-less situations. Tested-by: Wang Nan Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-2j78tdf8zn1ci0y6ji15b...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/env.c | 39 tools/perf/util/env.h | 4 tools/perf/util/header.c| 44 + tools/perf/util/parse-options.c | 2 +- 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 0b3e1b2..ca1e33a 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -1,6 +1,8 @@ #include "env.h" #include "util.h" +struct perf_env perf_env; + void perf_env__exit(struct perf_env *env) { zfree(>hostname); @@ -17,3 +19,40 @@ void perf_env__exit(struct perf_env *env) zfree(>pmu_mappings); zfree(>cpu); } + +int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) +{ + int i; + + /* +* If env->cmdline_argv has already been set, do not override it. This allows +* a command to set the cmdline, parse args and then call another +* builtin function that implements a command -- e.g, cmd_kvm calling +* cmd_record. +*/ + if (env->cmdline_argv != NULL) + return 0; + + /* do not include NULL termination */ + env->cmdline_argv = calloc(argc, sizeof(char *)); + if (env->cmdline_argv == NULL) + goto out_enomem; + + /* +* Must copy argv contents because it gets moved around during option +* parsing: +*/ + for (i = 0; i < argc ; i++) { + env->cmdline_argv[i] = argv[i]; + if (env->cmdline_argv[i] == NULL) + goto out_free; + } + + env->nr_cmdline = argc; + + return 0; +out_free: + zfree(>cmdline_argv); +out_enomem: + return -ENOMEM; +} diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index b137051..70124d9 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -32,6 +32,10 @@ struct perf_env { struct cpu_topology_map *cpu; }; +extern struct perf_env perf_env; + void perf_env__exit(struct perf_env *env); +int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]); + #endif /* __PERF_ENV_H */ diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 8fd7b7d..151b831 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -24,9 +24,6 @@ #include "build-id.h" #include "data.h" -static u32 header_argc; -static const char **header_argv; - /* * magic2 = "PERFILE2" * must be a numerical value to let the endianness @@ -138,37 +135,6 @@ static char *do_read_string(int fd, struct perf_header *ph) return NULL; } -int -perf_header__set_cmdline(int argc, const char **argv) -{ - int i; - - /* -* If header_argv has already been set, do not override it. -* This allows a command to set the cmdline, parse args and -* then call another builtin function that implements a -* command -- e.g, cmd_kvm calling cmd_record. -*/ - if (header_argv) - return 0; - - header_argc = (u32)argc; - - /* do not include NULL termination */ - header_argv = calloc(argc, sizeof(char *)); - if (!header_argv) - return -ENOMEM; - - /* -* must copy argv contents because it gets moved -* around during option parsing -*/ - for (i = 0; i < argc ; i++) - header_argv[i] = argv[i]; - - return 0; -} - static int write_tracing_data(int fd, struct perf_header *h __maybe_unused, struct perf_evlist *evlist) { @@ -405,8 +371,8 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused, { char buf[MAXPATHLEN]; char proc[32]; - u32 i, n; - int ret; +
[tip:perf/core] perf hists browser: Fixup the "cpu" column width calculation
Commit-ID: a4978eca684a3b471f3da862f427e419283e93a3 Gitweb: http://git.kernel.org/tip/a4978eca684a3b471f3da862f427e419283e93a3 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 9 Sep 2015 12:14:00 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:22 -0300 perf hists browser: Fixup the "cpu" column width calculation Since we were not setting it to at least 3 chars ('CPU'), it was being reset to zero when recalculating the columns width when refreshing the screen, in 'perf top'. Fix it. Tested-by: Wang Nan Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-iqcdnkkqm6sew06x01fbi...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/hist.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 08b6cd9..48d5906 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -144,6 +144,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); } + hists__new_col_len(hists, HISTC_CPU, 3); hists__new_col_len(hists, HISTC_MEM_LOCKED, 6); hists__new_col_len(hists, HISTC_MEM_TLB, 22); hists__new_col_len(hists, HISTC_MEM_SNOOP, 12); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf env: Move perf_env out of header.h and session.c into separate object
Commit-ID: f0ce888c064e07c73a103822f2ad8e77649fd107 Gitweb: http://git.kernel.org/tip/f0ce888c064e07c73a103822f2ad8e77649fd107 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 8 Sep 2015 13:30:00 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:19 -0300 perf env: Move perf_env out of header.h and session.c into separate object Since it can be used separately from 'perf_session' and 'perf_header', move it to separate include file and object, next csets will try to move a perf_env__init() routine. Tested-by: Wang Nan Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-ff2rw99tsn670y1b6gxbw...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/Build | 1 + tools/perf/util/env.c | 19 +++ tools/perf/util/env.h | 37 + tools/perf/util/header.h | 33 + tools/perf/util/session.c | 20 +--- 5 files changed, 59 insertions(+), 51 deletions(-) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 349bc96..4bc7a9a 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -5,6 +5,7 @@ libperf-y += build-id.o libperf-y += config.o libperf-y += ctype.o libperf-y += db-export.o +libperf-y += env.o libperf-y += environment.o libperf-y += event.o libperf-y += evlist.o diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c new file mode 100644 index 000..0b3e1b2 --- /dev/null +++ b/tools/perf/util/env.c @@ -0,0 +1,19 @@ +#include "env.h" +#include "util.h" + +void perf_env__exit(struct perf_env *env) +{ + zfree(>hostname); + zfree(>os_release); + zfree(>version); + zfree(>arch); + zfree(>cpu_desc); + zfree(>cpuid); + zfree(>cmdline); + zfree(>cmdline_argv); + zfree(>sibling_cores); + zfree(>sibling_threads); + zfree(>numa_nodes); + zfree(>pmu_mappings); + zfree(>cpu); +} diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h new file mode 100644 index 000..b137051 --- /dev/null +++ b/tools/perf/util/env.h @@ -0,0 +1,37 @@ +#ifndef __PERF_ENV_H +#define __PERF_ENV_H + +struct cpu_topology_map { + int socket_id; + int core_id; +}; + +struct perf_env { + char*hostname; + char*os_release; + char*version; + char*arch; + int nr_cpus_online; + int nr_cpus_avail; + char*cpu_desc; + char*cpuid; + unsigned long long total_mem; + + int nr_cmdline; + int nr_sibling_cores; + int nr_sibling_threads; + int nr_numa_nodes; + int nr_pmu_mappings; + int nr_groups; + char*cmdline; + const char **cmdline_argv; + char*sibling_cores; + char*sibling_threads; + char*numa_nodes; + char*pmu_mappings; + struct cpu_topology_map *cpu; +}; + +void perf_env__exit(struct perf_env *env); + +#endif /* __PERF_ENV_H */ diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 975d803..05f27cb 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -7,7 +7,7 @@ #include #include #include "event.h" - +#include "env.h" enum { HEADER_RESERVED = 0,/* always cleared */ @@ -66,37 +66,6 @@ struct perf_header; int perf_file_header__read(struct perf_file_header *header, struct perf_header *ph, int fd); -struct cpu_topology_map { - int socket_id; - int core_id; -}; - -struct perf_env { - char*hostname; - char*os_release; - char*version; - char*arch; - int nr_cpus_online; - int nr_cpus_avail; - char*cpu_desc; - char*cpuid; - unsigned long long total_mem; - - int nr_cmdline; - int nr_sibling_cores; - int nr_sibling_threads; - int nr_numa_nodes; - int nr_pmu_mappings; - int nr_groups; - char
[tip:perf/core] perf cpu_map: Use sysfs__read_int in get_{core, socket}_id()
Commit-ID: 5d8cf721cb13be92e96f22846e5bcd31040d4d0b Gitweb: http://git.kernel.org/tip/5d8cf721cb13be92e96f22846e5bcd31040d4d0b Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 11 Sep 2015 10:49:45 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:27 -0300 perf cpu_map: Use sysfs__read_int in get_{core,socket}_id() We have the tools/lib/ sysfs__read_int() for that, avoid code duplication. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-fqg6vt5ku72pbf54ljg6t...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cpumap.c | 46 ++ 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index a05d76a..c51c29f 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -225,28 +225,20 @@ void cpu_map__put(struct cpu_map *map) cpu_map__delete(map); } -int cpu_map__get_socket_id(int cpu) +static int cpu__get_topology_int(int cpu, const char *name, int *value) { - FILE *fp; - const char *mnt; char path[PATH_MAX]; - int socket_id, ret; - - mnt = sysfs__mountpoint(); - if (!mnt) - return -1; snprintf(path, PATH_MAX, - "%s/devices/system/cpu/cpu%d/topology/physical_package_id", - mnt, cpu); + "devices/system/cpu/cpu%d/topology/%s", cpu, name); - fp = fopen(path, "r"); - if (!fp) - return -1; - ret = fscanf(fp, "%d", _id); - fclose(fp); + return sysfs__read_int(path, value); +} - return ret == 1 ? socket_id : -1; +int cpu_map__get_socket_id(int cpu) +{ + int value, ret = cpu__get_topology_int(cpu, "physical_package_id", ); + return ret ?: value; } int cpu_map__get_socket(struct cpu_map *map, int idx) @@ -299,26 +291,8 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, int cpu_map__get_core_id(int cpu) { - FILE *fp; - const char *mnt; - char path[PATH_MAX]; - int core_id, ret; - - mnt = sysfs__mountpoint(); - if (!mnt) - return -1; - - snprintf(path, PATH_MAX, - "%s/devices/system/cpu/cpu%d/topology/core_id", - mnt, cpu); - - fp = fopen(path, "r"); - if (!fp) - return -1; - ret = fscanf(fp, "%d", _id); - fclose(fp); - - return ret == 1 ? core_id : -1; + int value, ret = cpu__get_topology_int(cpu, "core_id", ); + return ret ?: value; } int cpu_map__get_core(struct cpu_map *map, int idx) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf env: Introduce read_cpu_topology_map() method
Commit-ID: aa36ddd7afbb0a3db216c1391e28cd6d80ed1706 Gitweb: http://git.kernel.org/tip/aa36ddd7afbb0a3db216c1391e28cd6d80ed1706 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 9 Sep 2015 10:37:01 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:28 -0300 perf env: Introduce read_cpu_topology_map() method Out of the code to write the cpu topology map in the perf.data file header. Now if one needs the CPU topology map for the running machine, one needs to call perf_env__read_cpu_topology_map(perf_env) and the info will be stored in perf_env.cpu. For now we're using a global perf_env variable, that will have its contents freed after we run a builtin. v2: Check perf_env__read_cpu_topology_map() return in write_cpu_topology() (Kan Liang) Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/r/1441828225-667-5-git-send-email-a...@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/perf.c| 2 ++ tools/perf/util/env.c| 28 tools/perf/util/env.h| 2 ++ tools/perf/util/header.c | 28 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index f2fc019..1fded92 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -8,6 +8,7 @@ */ #include "builtin.h" +#include "util/env.h" #include "util/exec_cmd.h" #include "util/cache.h" #include "util/quote.h" @@ -369,6 +370,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) status = p->fn(argc, argv, prefix); exit_browser(status); + perf_env__exit(_env); if (status) return status & 0xff; diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ca1e33a..6af4f7c 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -1,3 +1,4 @@ +#include "cpumap.h" #include "env.h" #include "util.h" @@ -56,3 +57,30 @@ out_free: out_enomem: return -ENOMEM; } + +int perf_env__read_cpu_topology_map(struct perf_env *env) +{ + int cpu, nr_cpus; + + if (env->cpu != NULL) + return 0; + + if (env->nr_cpus_avail == 0) + env->nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF); + + nr_cpus = env->nr_cpus_avail; + if (nr_cpus == -1) + return -EINVAL; + + env->cpu = calloc(nr_cpus, sizeof(env->cpu[0])); + if (env->cpu == NULL) + return -ENOMEM; + + for (cpu = 0; cpu < nr_cpus; ++cpu) { + env->cpu[cpu].core_id = cpu_map__get_core_id(cpu); + env->cpu[cpu].socket_id = cpu_map__get_socket_id(cpu); + } + + env->nr_cpus_avail = nr_cpus; + return 0; +} diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index d0d1a96..0132b95 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -39,4 +39,6 @@ void perf_env__exit(struct perf_env *env); int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]); +int perf_env__read_cpu_topology_map(struct perf_env *env); + #endif /* __PERF_ENV_H */ diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index f307b17..46ec6c5 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -415,8 +415,6 @@ struct cpu_topo { u32 thread_sib; char **core_siblings; char **thread_siblings; - int *core_id; - int *phy_pkg_id; }; static int build_cpu_topo(struct cpu_topo *tp, int cpu) @@ -479,9 +477,6 @@ try_threads: } ret = 0; done: - tp->core_id[cpu] = cpu_map__get_core_id(cpu); - tp->phy_pkg_id[cpu] = cpu_map__get_socket_id(cpu); - if(fp) fclose(fp); free(buf); @@ -509,7 +504,7 @@ static struct cpu_topo *build_cpu_topology(void) struct cpu_topo *tp; void *addr; u32 nr, i; - size_t sz, sz_id; + size_t sz; long ncpus; int ret = -1; @@ -520,9 +515,8 @@ static struct cpu_topo *build_cpu_topology(void) nr = (u32)(ncpus & UINT_MAX); sz = nr * sizeof(char *); - sz_id = nr * sizeof(int); - addr = calloc(1, sizeof(*tp) + 2 * sz + 2 * sz_id); + addr = calloc(1, sizeof(*tp) + 2 * sz); if (!addr) return NULL; @@ -532,10 +526,6 @@ static struct cpu_topo *build_cpu_topology(void) tp->core_siblings = addr; addr += sz; tp->thread_siblings = addr; - addr += sz; - tp->core_id = addr; - addr += sz_id; - tp->phy_pkg_id = addr; for (i = 0; i < nr; i++) {
[tip:perf/core] tools lib api fs: Introduce sysfs__read_{int,ull} ()
Commit-ID: 2d729f6a8ac3edbf68de7239fab96c9736946af5 Gitweb: http://git.kernel.org/tip/2d729f6a8ac3edbf68de7239fab96c9736946af5 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 10 Sep 2015 11:58:50 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:25 -0300 tools lib api fs: Introduce sysfs__read_{int,ull}() To read either an int or an unsigned long long value from the given file. E.g.: $ cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq 320 $ ./sysfs__read_ull devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq=320 $ Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-4a12m4d5k8m4qgc1vguoc...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/api/fs/fs.c | 45 + tools/lib/api/fs/fs.h | 4 2 files changed, 49 insertions(+) diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index 7915093..732dbef5 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -281,6 +282,50 @@ int filename__read_int(const char *filename, int *value) return err; } +int filename__read_ull(const char *filename, unsigned long long *value) +{ + char line[64]; + int fd = open(filename, O_RDONLY), err = -1; + + if (fd < 0) + return -1; + + if (read(fd, line, sizeof(line)) > 0) { + *value = strtoull(line, NULL, 10); + if (*value != ULLONG_MAX) + err = 0; + } + + close(fd); + return err; +} + +int sysfs__read_ull(const char *entry, unsigned long long *value) +{ + char path[PATH_MAX]; + const char *sysfs = sysfs__mountpoint(); + + if (!sysfs) + return -1; + + snprintf(path, sizeof(path), "%s/%s", sysfs, entry); + + return filename__read_ull(path, value); +} + +int sysfs__read_int(const char *entry, int *value) +{ + char path[PATH_MAX]; + const char *sysfs = sysfs__mountpoint(); + + if (!sysfs) + return -1; + + snprintf(path, sizeof(path), "%s/%s", sysfs, entry); + + return filename__read_int(path, value); +} + int sysctl__read_int(const char *sysctl, int *value) { char path[PATH_MAX]; diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h index f654bcb..d024a7f 100644 --- a/tools/lib/api/fs/fs.h +++ b/tools/lib/api/fs/fs.h @@ -25,5 +25,9 @@ FS(tracefs) int filename__read_int(const char *filename, int *value); +int filename__read_ull(const char *filename, unsigned long long *value); + int sysctl__read_int(const char *sysctl, int *value); +int sysfs__read_int(const char *entry, int *value); +int sysfs__read_ull(const char *entry, unsigned long long *value); #endif /* __API_FS__ */ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] tools lib api cpu: Introduce cpu.[ch] to obtain cpu related information
Commit-ID: 09f6acf2eacad3a0f9a4b9f77e0b021f0cb45780 Gitweb: http://git.kernel.org/tip/09f6acf2eacad3a0f9a4b9f77e0b021f0cb45780 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 10 Sep 2015 12:20:14 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:26 -0300 tools lib api cpu: Introduce cpu.[ch] to obtain cpu related information E.g.: $ ./cpu__get_max_freq 320 It does that, as Kan's patch does, by looking at these files: $ cat /sys/devices/system/cpu/online 0-3 $ ./sysfs__read_ull devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq=320 $ I.e. find out the first online CPU, then read its cpufreq info. But do it in tools/lib/api/, so that other tools/ living code can use it, not just perf. Based-on-a-patch-by: Kan Liang Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-915v4cvxqplaub8qco66b...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/api/Build | 1 + tools/lib/api/cpu.c | 18 ++ tools/lib/api/cpu.h | 6 ++ 3 files changed, 25 insertions(+) diff --git a/tools/lib/api/Build b/tools/lib/api/Build index 3653965..e8b8a23 100644 --- a/tools/lib/api/Build +++ b/tools/lib/api/Build @@ -1,2 +1,3 @@ libapi-y += fd/ libapi-y += fs/ +libapi-y += cpu.o diff --git a/tools/lib/api/cpu.c b/tools/lib/api/cpu.c new file mode 100644 index 000..8c64893 --- /dev/null +++ b/tools/lib/api/cpu.c @@ -0,0 +1,18 @@ +#include + +#include "cpu.h" +#include "fs/fs.h" + +int cpu__get_max_freq(unsigned long long *freq) +{ + char entry[PATH_MAX]; + int cpu; + + if (sysfs__read_int("devices/system/cpu/online", ) < 0) + return -1; + + snprintf(entry, sizeof(entry), +"devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu); + + return sysfs__read_ull(entry, freq); +} diff --git a/tools/lib/api/cpu.h b/tools/lib/api/cpu.h new file mode 100644 index 000..81e9d39 --- /dev/null +++ b/tools/lib/api/cpu.h @@ -0,0 +1,6 @@ +#ifndef __API_CPU__ +#define __API_CPU__ + +int cpu__get_max_freq(unsigned long long *freq); + +#endif /* __API_CPU__ */ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf machine: Add pointer to sample's environment
Commit-ID: 4cde998d205894705b534878122631142a3eefe4 Gitweb: http://git.kernel.org/tip/4cde998d205894705b534878122631142a3eefe4 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 9 Sep 2015 12:25:00 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Sep 2015 12:50:29 -0300 perf machine: Add pointer to sample's environment The 'struct machine' represents the machine where the samples were/are being collected, and we also have a 'struct perf_env' with extra details about such machine, that we were collecting at 'perf.data' creation time but we also needed when no perf.data file is being used, such as in 'perf top'. So, get those structs closer together, as they provide a bigger picture of the sample's environment. In 'perf session', when the file argument is NULL, we can assume that the tool is sampling the running machine, so point machine->env to the global put in place in previous patches, while set it to the perf_header.env one when reading from a file. This paves the way for machine->env to be used in perf_event__preprocess_sample to populate addr_location.socket. Tested-by: Wang Nan Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-2ajotl0khscutm68exict...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/header.c | 1 + tools/perf/util/machine.c | 1 + tools/perf/util/machine.h | 1 + tools/perf/util/session.c | 2 ++ 4 files changed, 5 insertions(+) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 46ec6c5..6d8fa54 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2564,6 +2564,7 @@ int perf_session__read_header(struct perf_session *session) return -ENOMEM; session->evlist->env = >env; + session->machines.host.env = >env; if (perf_data_file__is_pipe(file)) return perf_header__read_pipe(session); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 6309f7c..fd1efea 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -35,6 +35,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) machine->last_match = NULL; machine->vdso_info = NULL; + machine->env = NULL; machine->pid = pid; diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index ea5cb4a..9dfc428 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -34,6 +34,7 @@ struct machine { struct list_head dead_threads; struct thread *last_match; struct vdso_info *vdso_info; + struct perf_env *env; struct dsos dsos; struct map_groups kmaps; struct map*vmlinux_maps[MAP__NR_TYPES]; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 728cb11..d1a43a3 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -138,6 +138,8 @@ struct perf_session *perf_session__new(struct perf_data_file *file, perf_session__set_id_hdr_size(session); perf_session__set_comm_exec(session); } + } else { + session->machines.host.env = _env; } if (!file || perf_data_file__is_write(file)) { -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/urgent] tools build: Add test for presence of numa_num_possible_cpus() in libnuma
Commit-ID: f8ac8606fd3cd72183de8eec2b151ff05040c70f Gitweb: http://git.kernel.org/tip/f8ac8606fd3cd72183de8eec2b151ff05040c70f Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 17 Sep 2015 12:20:28 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 17 Sep 2015 13:14:35 -0300 tools build: Add test for presence of numa_num_possible_cpus() in libnuma The existing numa test checks only if numa.h and numa_available() are present, but that can be satisfied with an old libnuma that is not enough for the 'perf bench numa' entry, so add a test to check for that: [acme@rhel5 linux]$ make NO_AUXTRACE=1 NO_LIBPERL=1 -C tools/perf O=/tmp/build/perf install-bin make: Entering directory `/home/acme/git/linux/tools/perf' BUILD: Doing 'make -j2' parallel build Auto-detecting system features: ...libelf: [ on ] ... libnuma: [ on ] ...numa_num_possible_cpus: [ OFF ] ... libperl: [ on ] config/Makefile:577: Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8 INSTALL binaries This fixes the build on old systems such as RHEL/CentOS 5.11. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: "Naveen N. Rao" Cc: Peter Zijlstra Cc: Srikar Dronamraju Cc: Stephane Eranian Cc: Victor Kamensky Cc: Vinson Lee Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-zqriqkezppi2de2iyjin1...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Makefile.feature | 2 ++ tools/build/feature/Makefile | 4 tools/build/feature/test-all.c| 5 + tools/build/feature/test-numa_num_possible_cpus.c | 6 ++ tools/perf/config/Makefile| 11 --- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 2975632..9702420 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -41,6 +41,7 @@ FEATURE_TESTS ?= \ libelf-getphdrnum \ libelf-mmap \ libnuma \ + numa_num_possible_cpus \ libperl \ libpython \ libpython-version \ @@ -61,6 +62,7 @@ FEATURE_DISPLAY ?=\ libbfd \ libelf \ libnuma \ + numa_num_possible_cpus \ libperl \ libpython \ libslang\ diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 74ca420..e13a42b 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -19,6 +19,7 @@ FILES=\ test-libelf-getphdrnum.bin \ test-libelf-mmap.bin\ test-libnuma.bin\ + test-numa_num_possible_cpus.bin \ test-libperl.bin\ test-libpython.bin \ test-libpython-version.bin \ @@ -87,6 +88,9 @@ test-libelf-getphdrnum.bin: test-libnuma.bin: $(BUILD) -lnuma +test-numa_num_possible_cpus.bin: + $(BUILD) -lnuma + test-libunwind.bin: $(BUILD) -lelf diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 84689a6..7a8cdba 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -77,6 +77,10 @@ # include "test-libnuma.c" #undef main +#define main main_test_numa_num_possible_cpus +# include "test-numa_num_possible_cpus.c" +#undef main + #define main main_test_timerfd # include "test-timerfd.c" #undef main @@ -136,6 +140,7 @@ int main(int argc, char *argv[]) main_test_libbfd(); main_test_backtrace(); main_test_libnuma(); + main_test_numa_num_possible_cpus(); main_test_timerfd(); main_test_stackprotector_all(); main_test_libdw_dwarf_unwind(); diff --git a/tools/build/feature/test-numa_num_possible_cpus.c b/tools/build/feature/test-numa_num_possible_cpus.c new file mode 100644 index 000..2606e94 --- /dev/null +++ b/tools/build/feature/test-numa_num_possible_cpus.c @@ -0,0 +1,6 @@ +#include + +int main(void) +{ + return numa_num_possible_cpus(); +} diff --git
[tip:perf/urgent] Revert "perf symbols: Fix mismatched declarations for elf_getphdrnum"
Commit-ID: 179f36dde3cec0f9f05a757b68f6a58e4edbcc95 Gitweb: http://git.kernel.org/tip/179f36dde3cec0f9f05a757b68f6a58e4edbcc95 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 17 Sep 2015 11:30:20 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 17 Sep 2015 13:10:05 -0300 Revert "perf symbols: Fix mismatched declarations for elf_getphdrnum" This reverts commit f785f2357673d520a0b7b468973cdd197f336494. We have a test to check if elf_getphdrnum() is present, so, if it fails, we'll get: [acme@rhel5 linux]$ cat /tmp/build/perf/feature/test-libelf-getphdrnum.make.output cc1: warnings being treated as errors test-libelf-getphdrnum.c: In function ‘main’: test-libelf-getphdrnum.c:7: warning: implicit declaration of function ‘elf_getphdrnum’ [acme@rhel5 linux]$ And this block will not be compiled: #ifndef HAVE_ELF_GETPHDRNUM_SUPPORT static int elf_getphdrnum(Elf *elf, size_t *dst) ... #endif So, if elf_getphdrnum() is being defined somewhere, there is a problem with the test that is not detecting that function, go fix it. Reported-by: Vinson Lee Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: "Naveen N. Rao" Cc: Peter Zijlstra Cc: Srikar Dronamraju Cc: Stephane Eranian Cc: Victor Kamensky Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-qn459fal6acvcvm50i8zx...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/symbol-elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 53bb5f5..f78ea3d 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -38,7 +38,7 @@ static inline char *bfd_demangle(void __maybe_unused *v, #endif #ifndef HAVE_ELF_GETPHDRNUM_SUPPORT -int elf_getphdrnum(Elf *elf, size_t *dst) +static int elf_getphdrnum(Elf *elf, size_t *dst) { GElf_Ehdr gehdr; GElf_Ehdr *ehdr; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/urgent] tools build: Add test for presence of __get_cpuid() gcc builtin
Commit-ID: b0063dbfb031a7c728ed0d9533257e8329292cf1 Gitweb: http://git.kernel.org/tip/b0063dbfb031a7c728ed0d9533257e8329292cf1 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 17 Sep 2015 12:54:30 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 17 Sep 2015 13:14:35 -0300 tools build: Add test for presence of __get_cpuid() gcc builtin The auxtrace code needed by Intel PT uses the __get_cpuid() gcc builtin, that is not present in old systems, breaking the build. Add a test to check for that builtin and disable AUXTRACE in those systems. [acme@rhel5 linux]$ make NO_LIBPERL=1 -C tools/perf O=/tmp/build/perf install-bin make: Entering directory `/home/acme/git/linux/tools/perf' BUILD: Doing 'make -j2' parallel build Auto-detecting system features: ... lzma: [ on ] ... get_cpuid: [ OFF ] config/Makefile:630: Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc MKDIR/tmp/build/perf/util/ This fixes the build on old systems such as RHEL/CentOS 5.11. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: "Naveen N. Rao" Cc: Peter Zijlstra Cc: Srikar Dronamraju Cc: Stephane Eranian Cc: Victor Kamensky Cc: Vinson Lee Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-d4puslul0jltoodzpx9r4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Makefile.feature | 6 -- tools/build/feature/Makefile | 6 +- tools/build/feature/test-all.c | 5 + tools/build/feature/test-get_cpuid.c | 7 +++ tools/perf/config/Makefile | 9 +++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 9702420..c8fe6d1 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -52,7 +52,8 @@ FEATURE_TESTS ?= \ timerfd \ libdw-dwarf-unwind \ zlib\ - lzma + lzma\ + get_cpuid FEATURE_DISPLAY ?= \ dwarf \ @@ -69,7 +70,8 @@ FEATURE_DISPLAY ?=\ libunwind \ libdw-dwarf-unwind \ zlib\ - lzma + lzma\ + get_cpuid # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. # If in the future we need per-feature checks/flags for features not diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index e13a42b..e43a297 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -35,7 +35,8 @@ FILES=\ test-compile-x32.bin\ test-zlib.bin \ test-lzma.bin \ - test-bpf.bin + test-bpf.bin\ + test-get_cpuid.bin CC := $(CROSS_COMPILE)gcc -MD PKG_CONFIG := $(CROSS_COMPILE)pkg-config @@ -166,6 +167,9 @@ test-zlib.bin: test-lzma.bin: $(BUILD) -llzma +test-get_cpuid.bin: + $(BUILD) + test-bpf.bin: $(BUILD) diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 7a8cdba..33cf6f2 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -121,6 +121,10 @@ # include "test-lzma.c" #undef main +#define main main_test_get_cpuid +# include "test-get_cpuid.c" +#undef main + int main(int argc, char *argv[]) { main_test_libpython(); @@ -148,6 +152,7 @@ int main(int argc, char *argv[]) main_test_zlib(); main_test_pthread_attr_setaffinity_np(); main_test_lzma(); + main_test_get_cpuid(); return 0; } diff --git a/tools/build/feature/test-get_cpuid.c b/tools/build/feature/test-get_cpuid.c new file mode 100644 index 000..d7a2c40 --- /dev/null +++ b/tools/build/feature/test-get_cpuid.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; + return __get_cpuid(0x15, , , , ); +} diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index 053e65b..38a0853 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile @@ -626,8 +626,13 @@ ifdef LIBBABELTRACE endif ifndef NO_AUXTRACE - $(call detected,CONFIG_AUXTRACE) - CFLAGS += -DHAVE_AUXTRACE_SUPPORT + ifeq
[tip:perf/urgent] perf header: Fixup reading of HEADER_NRCPUS feature
Commit-ID: caa470475d9b59eeff093ae650800d34612c4379 Gitweb: http://git.kernel.org/tip/caa470475d9b59eeff093ae650800d34612c4379 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 11 Sep 2015 12:36:12 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Sun, 13 Sep 2015 11:41:34 -0300 perf header: Fixup reading of HEADER_NRCPUS feature The original patch introducing this header wrote the number of CPUs available and online in one order and then swapped those values when reading, fix it. Before: # perf record usleep 1 # perf report --header-only | grep 'nrcpus \(online\|avail\)' # nrcpus online : 4 # nrcpus avail : 4 # echo 0 > /sys/devices/system/cpu/cpu2/online # perf record usleep 1 # perf report --header-only | grep 'nrcpus \(online\|avail\)' # nrcpus online : 4 # nrcpus avail : 3 # echo 0 > /sys/devices/system/cpu/cpu1/online # perf record usleep 1 # perf report --header-only | grep 'nrcpus \(online\|avail\)' # nrcpus online : 4 # nrcpus avail : 2 After the fix, bringing back the CPUs online: # perf report --header-only | grep 'nrcpus \(online\|avail\)' # nrcpus online : 2 # nrcpus avail : 4 # echo 1 > /sys/devices/system/cpu/cpu2/online # perf record usleep 1 # perf report --header-only | grep 'nrcpus \(online\|avail\)' # nrcpus online : 3 # nrcpus avail : 4 # echo 1 > /sys/devices/system/cpu/cpu1/online # perf record usleep 1 # perf report --header-only | grep 'nrcpus \(online\|avail\)' # nrcpus online : 4 # nrcpus avail : 4 Acked-by: Namhyung Kim Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Stephane Eranian Cc: Wang Nan Fixes: fbe96f29ce4b ("perf tools: Make perf.data more self-descriptive (v8)") Link: http://lkml.kernel.org/r/20150911153323.gp23...@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/header.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 4181454..fce6634 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1438,7 +1438,7 @@ static int process_nrcpus(struct perf_file_section *section __maybe_unused, if (ph->needs_swap) nr = bswap_32(nr); - ph->env.nr_cpus_online = nr; + ph->env.nr_cpus_avail = nr; ret = readn(fd, , sizeof(nr)); if (ret != sizeof(nr)) @@ -1447,7 +1447,7 @@ static int process_nrcpus(struct perf_file_section *section __maybe_unused, if (ph->needs_swap) nr = bswap_32(nr); - ph->env.nr_cpus_avail = nr; + ph->env.nr_cpus_online = nr; return 0; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf tools: Use __map__is_kernel() when synthesizing kernel module mmap records
Commit-ID: ab9c2bdc8947482057b81258c0128952763661cb Gitweb: http://git.kernel.org/tip/ab9c2bdc8947482057b81258c0128952763661cb Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 23 Sep 2015 15:45:20 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 28 Sep 2015 15:50:54 -0300 perf tools: Use __map__is_kernel() when synthesizing kernel module mmap records Equivalent and removes one more case of using dso->kernel. # perf record -a usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.768 MB perf.data (30 samples) ] Before: [root@zoo ~]# perf script --show-task --show-mmap | head -3 swapper 0 [0] 0.0: PERF_RECORD_MMAP -1/0: [0x8100(0x1f00) @ 0x8100]: x [kernel.kallsyms]_text swapper 0 [0] 0.0: PERF_RECORD_MMAP -1/0: [0xa000(0xa000) @ 0]: x /lib/modules/4.3.0-rc1+/kernel/drivers/acpi/video.ko swapper 0 [0] 0.0: PERF_RECORD_MMAP -1/0: [0xa000a000(0x5000) @ 0]: x /lib/modules/4.3.0-rc1+/kernel/drivers/i2c/algos/i2c-algo-bit.ko # # perf script --show-task --show-mmap | head -3 swapper 0 [0] 0.0: PERF_RECORD_MMAP -1/0: [0x8100(0x1f00) @ 0x8100]: x [kernel.kallsyms]_text swapper 0 [0] 0.0: PERF_RECORD_MMAP -1/0: [0xa000(0xa000) @ 0]: x /lib/modules/4.3.0-rc1+/kernel/drivers/acpi/video.ko swapper 0 [0] 0.0: PERF_RECORD_MMAP -1/0: [0xa000a000(0x5000) @ 0]: x /lib/modules/4.3.0-rc1+/kernel/drivers/i2c/algos/i2c-algo-bit.ko # Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-b65xe578dwq22mzmmj5y9...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 6214ad4..b1bb348 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -378,7 +378,7 @@ int perf_event__synthesize_modules(struct perf_tool *tool, for (pos = maps__first(maps); pos; pos = map__next(pos)) { size_t size; - if (pos->dso->kernel) + if (__map__is_kernel(pos)) continue; size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf hists browser: Use the map to determine if a DSO is being used as a kernel
Commit-ID: 045b80dd03403b8e61a29460987c231317ebfbd4 Gitweb: http://git.kernel.org/tip/045b80dd03403b8e61a29460987c231317ebfbd4 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 23 Sep 2015 15:38:55 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 28 Sep 2015 15:50:54 -0300 perf hists browser: Use the map to determine if a DSO is being used as a kernel The map is what should say if an ELF (or some other format) image is being used for some particular purpose, as a kernel, host or guest. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-zufousvfar0710p4qj71c...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/hists.c | 24 ++-- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index e1f28f4..a4e9b37 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -1527,7 +1527,7 @@ add_thread_opt(struct hist_browser *browser, struct popup_action *act, static int do_zoom_dso(struct hist_browser *browser, struct popup_action *act) { - struct dso *dso = act->dso; + struct map *map = act->ms.map; if (browser->hists->dso_filter) { pstack__remove(browser->pstack, >hists->dso_filter); @@ -1535,11 +1535,11 @@ do_zoom_dso(struct hist_browser *browser, struct popup_action *act) browser->hists->dso_filter = NULL; ui_helpline__pop(); } else { - if (dso == NULL) + if (map == NULL) return 0; ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", - dso->kernel ? "the Kernel" : dso->short_name); - browser->hists->dso_filter = dso; + __map__is_kernel(map) ? "the Kernel" : map->dso->short_name); + browser->hists->dso_filter = map->dso; perf_hpp__set_elide(HISTC_DSO, true); pstack__push(browser->pstack, >hists->dso_filter); } @@ -1551,17 +1551,18 @@ do_zoom_dso(struct hist_browser *browser, struct popup_action *act) static int add_dso_opt(struct hist_browser *browser, struct popup_action *act, - char **optstr, struct dso *dso) + char **optstr, struct map *map) { - if (dso == NULL) + if (map == NULL) return 0; if (asprintf(optstr, "Zoom %s %s DSO", browser->hists->dso_filter ? "out of" : "into", -dso->kernel ? "the Kernel" : dso->short_name) < 0) +__map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0) return 0; - act->dso = dso; + act->ms.map = map; + act->dso = map->dso; act->fn = do_zoom_dso; return 1; } @@ -1814,6 +1815,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, while (1) { struct thread *thread = NULL; struct dso *dso = NULL; + struct map *map = NULL; int choice = 0; int socked_id = -1; @@ -1823,7 +1825,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, if (browser->he_selection != NULL) { thread = hist_browser__selected_thread(browser); - dso = browser->selection->map ? browser->selection->map->dso : NULL; + map = browser->selection->map; + if (map) + dso = map->dso; socked_id = browser->he_selection->socket; } switch (key) { @@ -2014,7 +2018,7 @@ skip_annotation: nr_options += add_thread_opt(browser, [nr_options], [nr_options], thread); nr_options += add_dso_opt(browser, [nr_options], - [nr_options], dso); + [nr_options], map); nr_options += add_map_opt(browser, [nr_options], [nr_options], browser->selection ? -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf top: Filter symbols based on __map__is_kernel(map)
Commit-ID: cfc5acd4c80b875d2f739d6a93562034aee5563f Gitweb: http://git.kernel.org/tip/cfc5acd4c80b875d2f739d6a93562034aee5563f Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 23 Sep 2015 15:15:54 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 28 Sep 2015 15:50:53 -0300 perf top: Filter symbols based on __map__is_kernel(map) Instead of using dso->kernel, this is equivalent at the moment, and helps in reducing the accesses to dso->kernel. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-1pc2v63iphtifovw3bv0b...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-top.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index bdaf44f..38d4d6c 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -655,7 +655,7 @@ static int symbol_filter(struct map *map, struct symbol *sym) { const char *name = sym->name; - if (!map->dso->kernel) + if (!__map__is_kernel(map)) return 0; /* * ppc64 uses function descriptors and appends a '.' to the -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf maps: Introduce maps__find_symbol_by_name()
Commit-ID: b7f9ff5654d53fa47e0b5ff20f834f3e7a611846 Gitweb: http://git.kernel.org/tip/b7f9ff5654d53fa47e0b5ff20f834f3e7a611846 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 29 Sep 2015 17:34:46 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 Sep 2015 18:34:25 -0300 perf maps: Introduce maps__find_symbol_by_name() Out of map_groups__find_symbol_by_name(), so that we can turn this later one first into a call to maps__find_symbol_by_name(MAP__FUNCTION) + MAP__VARIABLE, and then to just one call, we'll merge MAP__FUNCTION with MAP__VARIABLE maps, to simplify the code. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-pvkar0jacqn92g148u9sq...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/map.c | 19 +-- tools/perf/util/map.h | 2 ++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index b1c475d..622c2c9 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -553,13 +553,9 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg, return NULL; } -struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg, - enum map_type type, - const char *name, - struct map **mapp, - symbol_filter_t filter) +struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, +struct map **mapp, symbol_filter_t filter) { - struct maps *maps = >maps[type]; struct symbol *sym; struct rb_node *nd; @@ -583,6 +579,17 @@ out: return sym; } +struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg, + enum map_type type, + const char *name, + struct map **mapp, + symbol_filter_t filter) +{ + struct symbol *sym = maps__find_symbol_by_name(>maps[type], name, mapp, filter); + + return sym; +} + int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter) { if (ams->addr < ams->map->start || ams->addr >= ams->map->end) { diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 57829e8..7309d64 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -190,6 +190,8 @@ void maps__remove(struct maps *maps, struct map *map); struct map *maps__find(struct maps *maps, u64 addr); struct map *maps__first(struct maps *maps); struct map *map__next(struct map *map); +struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, + struct map **mapp, symbol_filter_t filter); void map_groups__init(struct map_groups *mg, struct machine *machine); void map_groups__exit(struct map_groups *mg); int map_groups__clone(struct map_groups *mg, -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf tools: By default use the most precise " cycles" hw counter available
Commit-ID: 7f8d1ade1b19f684ed3a7c4fb1dc5d347127b438 Gitweb: http://git.kernel.org/tip/7f8d1ade1b19f684ed3a7c4fb1dc5d347127b438 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Sep 2015 17:49:49 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 Sep 2015 18:34:39 -0300 perf tools: By default use the most precise "cycles" hw counter available If the user doesn't specify any event, try the most precise "cycles" available, i.e. start by "cycles:ppp" and go on removing "p" till it works. E.g. $ perf record usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.017 MB perf.data (11 samples) ] $ perf evlist cycles:pp $ perf evlist -v cycles:pp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 2, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 $ grep 'model name' /proc/cpuinfo | head -1 model name: Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz $ When 'cycles' appears explicitely is specified this will not be tried, i.e. the user has full control of the level of precision to be used: $ perf record -e cycles usleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.016 MB perf.data (9 samples) ] $ perf evlist cycles $ perf evlist -v cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 $ Cc: Adrian Hunter Cc: Borislav Petkov Cc: Chandler Carruth Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: https://www.youtube.com/watch?v=nXaxk27zwlk Link: http://lkml.kernel.org/n/tip-b1ywebmt22pi78vjxau01...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 22 +++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 8954622..e7e195d 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -205,6 +205,20 @@ void perf_evlist__set_leader(struct perf_evlist *evlist) } } +static void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr) +{ + attr->precise_ip = 3; + + while (attr->precise_ip != 0) { + int fd = sys_perf_event_open(attr, 0, -1, -1, 0); + if (fd != -1) { + close(fd); + break; + } + --attr->precise_ip; + } +} + int perf_evlist__add_default(struct perf_evlist *evlist) { struct perf_event_attr attr = { @@ -215,13 +229,15 @@ int perf_evlist__add_default(struct perf_evlist *evlist) event_attr_init(); + perf_event_attr__set_max_precise_ip(); + evsel = perf_evsel__new(); if (evsel == NULL) goto error; - /* use strdup() because free(evsel) assumes name is allocated */ - evsel->name = strdup("cycles"); - if (!evsel->name) + /* use asprintf() because free(evsel) assumes name is allocated */ + if (asprintf(>name, "cycles%.*s", +attr.precise_ip ? attr.precise_ip + 1 : 0, ":ppp") < 0) goto error_free; perf_evlist__add(evlist, evsel); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf machine: Use machine__kernel_map() thoroughly
Commit-ID: 77e65977495cd6f6fcfacd8c16bdd9c8c18a1d72 Gitweb: http://git.kernel.org/tip/77e65977495cd6f6fcfacd8c16bdd9c8c18a1d72 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Sep 2015 11:08:58 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 Sep 2015 18:34:28 -0300 perf machine: Use machine__kernel_map() thoroughly In places where we were using its open coded equivalent. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-khkdugcdoqy3tkszm3jdx...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/util/event.c | 7 +++ tools/perf/util/machine.c | 23 --- tools/perf/util/map.c | 2 +- tools/perf/util/probe-event.c | 7 --- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 23b1faa..b122c4e 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -329,7 +329,7 @@ static int build_alloc_func_list(void) return -EINVAL; } - kernel_map = machine->vmlinux_maps[MAP__FUNCTION]; + kernel_map = machine__kernel_map(machine, MAP__FUNCTION) if (map__load(kernel_map, NULL) < 0) { pr_err("cannot load kernel map\n"); return -ENOENT; diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 37c9f51..7962605 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -387,7 +387,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, static void report__warn_kptr_restrict(const struct report *rep) { - struct map *kernel_map = rep->session->machines.host.vmlinux_maps[MAP__FUNCTION]; + struct map *kernel_map = machine__kernel_map(>session->machines.host, MAP__FUNCTION); struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL; if (kernel_map == NULL || diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 2d21183..47017a8 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -473,7 +473,7 @@ static int do_test_code_reading(bool try_kcore) symbol_conf.kallsyms_name = "/proc/kallsyms"; /* Load kernel map */ - map = machine->vmlinux_maps[MAP__FUNCTION]; + map = machine__kernel_map(machine, MAP__FUNCTION); ret = map__load(map, NULL); if (ret < 0) { pr_debug("map__load failed\n"); diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index b1bb348..281ab7f 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -649,12 +649,12 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, size_t size; const char *mmap_name; char name_buff[PATH_MAX]; - struct map *map; + struct map *map = machine__kernel_map(machine, MAP__FUNCTION); struct kmap *kmap; int err; union perf_event *event; - if (machine->vmlinux_maps[0] == NULL) + if (map == NULL) return -1; /* @@ -680,7 +680,6 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL; } - map = machine->vmlinux_maps[MAP__FUNCTION]; kmap = map__kmap(map); size = snprintf(event->mmap.filename, sizeof(event->mmap.filename), "%s%s", mmap_name, kmap->ref_reloc_sym->name) + 1; @@ -1008,7 +1007,7 @@ int perf_event__preprocess_sample(const union perf_event *event, * it now. */ if (cpumode == PERF_RECORD_MISC_KERNEL && - machine->vmlinux_maps[MAP__FUNCTION] == NULL) + machine__kernel_map(machine, MAP__FUNCTION) == NULL) machine__create_kernel_maps(machine); thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index fd1efea..d71b7dc 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -625,7 +625,7 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp) { int i; size_t printed = 0; - struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso; + struct dso *kdso = machine__kernel_map(machine, MAP__FUNCTION)->dso; if (kdso->has_build_id) { char filename[PATH_MAX]; @@ -741,6 +741,7 @@ int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel) for (type = 0; type < MAP__NR_TYPES; ++type) { struct kmap
[tip:perf/core] perf machine: Add method for common kernel_map( FUNCTION) operation
Commit-ID: a5e813c68649366aaa3f785772b00ea6ccad7b8d Gitweb: http://git.kernel.org/tip/a5e813c68649366aaa3f785772b00ea6ccad7b8d Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Sep 2015 11:54:04 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 Sep 2015 18:34:29 -0300 perf machine: Add method for common kernel_map(FUNCTION) operation And it is also a step in the direction of killing the separation of data and text maps in map_groups. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-rrds86kb3wx5wk8v38v56...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 4 ++-- tools/perf/util/event.c | 4 ++-- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/machine.c | 15 +++ tools/perf/util/machine.h | 8 +++- tools/perf/util/map.c | 2 +- tools/perf/util/probe-event.c | 4 ++-- 10 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index b122c4e..93ce665 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -329,7 +329,7 @@ static int build_alloc_func_list(void) return -EINVAL; } - kernel_map = machine__kernel_map(machine, MAP__FUNCTION) + kernel_map = machine__kernel_map(machine); if (map__load(kernel_map, NULL) < 0) { pr_err("cannot load kernel map\n"); return -ENOENT; diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 7962605..b562363 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -387,7 +387,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, static void report__warn_kptr_restrict(const struct report *rep) { - struct map *kernel_map = machine__kernel_map(>session->machines.host, MAP__FUNCTION); + struct map *kernel_map = machine__kernel_map(>session->machines.host); struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL; if (kernel_map == NULL || diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 47017a8..49b1959 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -473,7 +473,7 @@ static int do_test_code_reading(bool try_kcore) symbol_conf.kallsyms_name = "/proc/kallsyms"; /* Load kernel map */ - map = machine__kernel_map(machine, MAP__FUNCTION); + map = machine__kernel_map(machine); ret = map__load(map, NULL); if (ret < 0) { pr_debug("map__load failed\n"); diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c index b34c5fc..d677e01 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -68,7 +68,7 @@ int test__vmlinux_matches_kallsyms(void) * to see if the running kernel was relocated by checking if it has the * same value in the vmlinux file we load. */ - kallsyms_map = machine__kernel_map(, type); + kallsyms_map = machine__kernel_map(); /* * Step 5: @@ -80,7 +80,7 @@ int test__vmlinux_matches_kallsyms(void) goto out; } - vmlinux_map = machine__kernel_map(, type); + vmlinux_map = machine__kernel_map(); /* * Step 6: diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 281ab7f..cb98b5a 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -649,7 +649,7 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, size_t size; const char *mmap_name; char name_buff[PATH_MAX]; - struct map *map = machine__kernel_map(machine, MAP__FUNCTION); + struct map *map = machine__kernel_map(machine); struct kmap *kmap; int err; union perf_event *event; @@ -1007,7 +1007,7 @@ int perf_event__preprocess_sample(const union perf_event *event, * it now. */ if (cpumode == PERF_RECORD_MISC_KERNEL && - machine__kernel_map(machine, MAP__FUNCTION) == NULL) + machine__kernel_map(machine) == NULL) machine__create_kernel_maps(machine); thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al); diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 03ff072..97f963a 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -1268,7 +1268,7 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64
[tip:perf/core] tools lib symbol: Introduce kallsyms2elf_type
Commit-ID: f845086a8ed49e657a750f87f85966d75c8a9645 Gitweb: http://git.kernel.org/tip/f845086a8ed49e657a750f87f85966d75c8a9645 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Sep 2015 13:02:08 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 Sep 2015 18:34:31 -0300 tools lib symbol: Introduce kallsyms2elf_type Map 't', 'T' (text, local, global), 'w' and 'W' (weak text, local, global) as STT_FUNC, and the rest as STT_OBJECT Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-sbwcixulpc5v1xuxn3xvm...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/symbol/kallsyms.c | 6 ++ tools/lib/symbol/kallsyms.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/tools/lib/symbol/kallsyms.c b/tools/lib/symbol/kallsyms.c index 18bc271..5e43107 100644 --- a/tools/lib/symbol/kallsyms.c +++ b/tools/lib/symbol/kallsyms.c @@ -2,6 +2,12 @@ #include #include +u8 kallsyms2elf_type(char type) +{ + type = tolower(type); + return (type == 't' || type == 'w') ? STT_FUNC : STT_OBJECT; +} + int kallsyms__parse(const char *filename, void *arg, int (*process_symbol)(void *arg, const char *name, char type, u64 start)) diff --git a/tools/lib/symbol/kallsyms.h b/tools/lib/symbol/kallsyms.h index bb86c5b7..4071316 100644 --- a/tools/lib/symbol/kallsyms.h +++ b/tools/lib/symbol/kallsyms.h @@ -17,6 +17,8 @@ static inline u8 kallsyms2elf_binding(char type) return isupper(type) ? STB_GLOBAL : STB_LOCAL; } +u8 kallsyms2elf_type(char type); + int kallsyms__parse(const char *filename, void *arg, int (*process_symbol)(void *arg, const char *name, char type, u64 start)); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] tools lib symbol: Rename kallsyms2elf_type to kallsyms2elf_binding
Commit-ID: 8e947f1e84fd1588f66e5f2ea69c80647de72cd4 Gitweb: http://git.kernel.org/tip/8e947f1e84fd1588f66e5f2ea69c80647de72cd4 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Sep 2015 12:42:07 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 Sep 2015 18:34:30 -0300 tools lib symbol: Rename kallsyms2elf_type to kallsyms2elf_binding It is about binding, not type, we have just a letter in kallsyms that should map both for the ELF type (STT_FUNC, etc) and to the ELF symbol binding (STB_WEAK, STB_GLOBAL, etc), so rename it now before introducing kallsyms2_elf_type() Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-uu5vj343ms1q2wm55690o...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/symbol/kallsyms.h | 2 +- tools/perf/util/symbol.c| 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/symbol/kallsyms.h b/tools/lib/symbol/kallsyms.h index 6084f5e..bb86c5b7 100644 --- a/tools/lib/symbol/kallsyms.h +++ b/tools/lib/symbol/kallsyms.h @@ -9,7 +9,7 @@ #define KSYM_NAME_LEN 256 #endif -static inline u8 kallsyms2elf_type(char type) +static inline u8 kallsyms2elf_binding(char type) { if (type == 'W') return STB_WEAK; diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 1f97ffb..bcda43b 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -624,7 +624,7 @@ static int map__process_kallsym_symbol(void *arg, const char *name, * symbols, setting length to 0, and rely on * symbols__fixup_end() to fix it up. */ - sym = symbol__new(start, 0, kallsyms2elf_type(type), name); + sym = symbol__new(start, 0, kallsyms2elf_binding(type), name); if (sym == NULL) return -ENOMEM; /* -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf list: Remove blank lines, headers when piping output
Commit-ID: dfc431cbdc3a3c0556f1cd462d724d107cc15a9e Gitweb: http://git.kernel.org/tip/dfc431cbdc3a3c0556f1cd462d724d107cc15a9e Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Sep 2015 17:13:26 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 30 Sep 2015 18:34:38 -0300 perf list: Remove blank lines, headers when piping output So that one can, for instance, use it with wc -l: # perf list *:*write* | wc -l 60 Or to look for the "bio" tracepoints, without 'perf list' headers: # perf list *:*bio* | head block:block_bio_backmerge [Tracepoint event] block:block_bio_bounce [Tracepoint event] block:block_bio_complete [Tracepoint event] block:block_bio_frontmerge [Tracepoint event] block:block_bio_queue [Tracepoint event] block:block_bio_remap [Tracepoint event] # Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-ts7sc0x8u4io4cifzkup4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-list.c | 2 +- tools/perf/util/parse-events.c | 13 +++-- tools/perf/util/pmu.c | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index af5bd05..6024140 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -36,7 +36,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) setup_pager(); - if (!raw_dump) + if (!raw_dump && pager_in_use()) printf("\nList of pre-defined events (to be used in -e):\n\n"); if (argc == 0) { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index c1c64fb..5d0cfce 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1534,7 +1534,7 @@ restart: printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[PERF_TYPE_TRACEPOINT]); } - if (evt_num) + if (evt_num && pager_in_use()) printf("\n"); out_free: @@ -1690,7 +1690,7 @@ restart: printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[PERF_TYPE_HW_CACHE]); } - if (evt_num) + if (evt_num && pager_in_use()) printf("\n"); out_free: @@ -1763,7 +1763,7 @@ restart: } printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[type]); } - if (evt_num) + if (evt_num && pager_in_use()) printf("\n"); out_free: @@ -1804,13 +1804,14 @@ void print_events(const char *event_glob, bool name_only) printf(" %-50s [%s]\n", "cpu/t1=v1[,t2=v2,t3 ...]/modifier", event_type_descriptors[PERF_TYPE_RAW]); - printf(" (see 'man perf-list' on how to encode it)\n"); - printf("\n"); + if (pager_in_use()) + printf(" (see 'man perf-list' on how to encode it)\n\n"); printf(" %-50s [%s]\n", "mem:[/len][:access]", event_type_descriptors[PERF_TYPE_BREAKPOINT]); - printf("\n"); + if (pager_in_use()) + printf("\n"); } print_tracepoint_events(NULL, NULL, name_only); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ac42c97..41a356b 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1026,7 +1026,7 @@ void print_pmu_events(const char *event_glob, bool name_only) printf(" %-50s [Kernel PMU event]\n", aliases[j]); printed++; } - if (printed) + if (printed && pager_in_use()) printf("\n"); out_free: for (j = 0; j < len; j++) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf list: Do event name substring search as last resort when no events found
Commit-ID: dbc67409fa912ba063dfa956af0543af1258fc97 Gitweb: http://git.kernel.org/tip/dbc67409fa912ba063dfa956af0543af1258fc97 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 1 Oct 2015 12:12:22 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 1 Oct 2015 12:12:22 -0300 perf list: Do event name substring search as last resort when no events found Before: # perf list _alloc_ | head -10 # After: # perf list _alloc_ | head -10 ext4:ext4_alloc_da_blocks [Tracepoint event] ext4:ext4_get_implied_cluster_alloc_exit [Tracepoint event] kmem:kmem_cache_alloc_node [Tracepoint event] kmem:mm_page_alloc_extfrag [Tracepoint event] kmem:mm_page_alloc_zone_locked [Tracepoint event] xen:xen_mmu_alloc_ptpage [Tracepoint event] # And it works for all types of events: # perf list br List of pre-defined events (to be used in -e): branch-instructions OR branches[Hardware event] branch-misses [Hardware event] branch-load-misses [Hardware cache event] branch-loads [Hardware cache event] branch-instructions OR cpu/branch-instructions/[Kernel PMU event] branch-misses OR cpu/branch-misses/[Kernel PMU event] filelock:break_lease_block [Tracepoint event] filelock:break_lease_noblock [Tracepoint event] filelock:break_lease_unblock [Tracepoint event] syscalls:sys_enter_brk [Tracepoint event] syscalls:sys_exit_brk [Tracepoint event] # Suggested-by: Ingo Molnar Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-qieivl18jdemoaghgndj3...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-list.txt | 2 ++ tools/perf/builtin-list.c | 18 -- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt index bada893..ad60c6e 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt @@ -125,6 +125,8 @@ To limit the list use: . If none of the above is matched, it will apply the supplied glob to all events, printing the ones that match. +. As a last resort, it will do a substring search in all event names. + One or more types can be used at the same time, listing the events for the types specified. diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 6024140..bf679e2 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -45,6 +45,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) } for (i = 0; i < argc; ++i) { + char *sep, *s; + if (strcmp(argv[i], "tracepoint") == 0) print_tracepoint_events(NULL, NULL, raw_dump); else if (strcmp(argv[i], "hw") == 0 || @@ -60,8 +62,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) print_hwcache_events(NULL, raw_dump); else if (strcmp(argv[i], "pmu") == 0) print_pmu_events(NULL, raw_dump); - else { - char *sep = strchr(argv[i], ':'), *s; + else if ((sep = strchr(argv[i], ':')) != NULL) { int sep_idx; if (sep == NULL) { @@ -76,6 +77,19 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) s[sep_idx] = '\0'; print_tracepoint_events(s, s + sep_idx + 1, raw_dump); free(s); + } else { + if (asprintf(, "*%s*", argv[i]) < 0) { + printf("Critical: Not enough memory! Trying to continue...\n"); + continue; + } + print_symbol_events(s, PERF_TYPE_HARDWARE, + event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump); + print_symbol_events(s, PERF_TYPE_SOFTWARE, + event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); + print_hwcache_events(s, raw_dump); +
[tip:perf/core] perf list: Honour 'event_glob' whem printing selectable PMUs
Commit-ID: fa52ceabc2a3e70431a82bca2bc547a15eaf19df Gitweb: http://git.kernel.org/tip/fa52ceabc2a3e70431a82bca2bc547a15eaf19df Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 2 Oct 2015 15:28:16 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 2 Oct 2015 15:28:16 -0300 perf list: Honour 'event_glob' whem printing selectable PMUs Some PMUs, like the 'intel_bts' one can be used as an event name, i.e.: $ perf record -e intel_bts:// usleep 1 Is a valid event name. But the code printing such PMUs was not honouring the 'event_glob' parameter, so the following line was always appearing: $ intel_bts//[Kernel PMU event] Fix it: $ [acme@felicio linux]$ perf list data List of pre-defined events (to be used in -e): uncore_imc/data_reads/ [Kernel PMU event] uncore_imc/data_writes/[Kernel PMU event] $ Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-ajb71858n7q7ao77b8pyy...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/pmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 41a356b..e4b173d 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1008,7 +1008,8 @@ void print_pmu_events(const char *event_glob, bool name_only) goto out_enomem; j++; } - if (pmu->selectable) { + if (pmu->selectable && + (event_glob == NULL || strglobmatch(pmu->name, event_glob))) { char *s; if (asprintf(, "%s//", pmu->name) < 0) goto out_enomem; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/urgent] perf probe: Use existing routine to look for a kernel module by dso->short_name
Commit-ID: 266fa2b22294909ddf6e7d2f8acfe07adf9fd978 Gitweb: http://git.kernel.org/tip/266fa2b22294909ddf6e7d2f8acfe07adf9fd978 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 24 Sep 2015 11:24:18 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 25 Sep 2015 10:41:31 -0300 perf probe: Use existing routine to look for a kernel module by dso->short_name We have map_groups__find_by_name() to look at the list of modules that are in place for a given machine, so use it instead of traversing the machine dso list, which also includes DSOs for userspace. When merging the user and kernel DSO lists a bug was introduced where 'perf probe' stopped being able to add probes to modules using its short name: # perf probe -m usbnet --add usbnet_start_xmit usbnet_start_xmit is out of .text, skip it. Error: Failed to add events. # With this fix it works again: # perf probe -m usbnet --add usbnet_start_xmit Added new event: probe:usbnet_start_xmit (on usbnet_start_xmit in usbnet) You can now use it in all perf tools, such as: perf record -e probe:usbnet_start_xmit -aR sleep 1 # Reported-by: Wang Nan Acked-by: Masami Hiramatsu Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Fixes: 3d39ac538629 ("perf machine: No need to have two DSOs lists") Link: http://lkml.kernel.org/r/20150924015008.ge1...@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/probe-event.c | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index eb5f18b..c6f9af7 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -270,12 +270,13 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso) int ret = 0; if (module) { - list_for_each_entry(dso, _machine->dsos.head, node) { - if (!dso->kernel) - continue; - if (strncmp(dso->short_name + 1, module, - dso->short_name_len - 2) == 0) - goto found; + char module_name[128]; + + snprintf(module_name, sizeof(module_name), "[%s]", module); + map = map_groups__find_by_name(_machine->kmaps, MAP__FUNCTION, module_name); + if (map) { + dso = map->dso; + goto found; } pr_debug("Failed to find module %s.\n", module); return -ENOENT; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] tools build: Fixup feature detection display function name
Commit-ID: 6076e2a47cccfb3d48a8d165853c0b799c563df7 Gitweb: http://git.kernel.org/tip/6076e2a47cccfb3d48a8d165853c0b799c563df7 Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 21 Sep 2015 11:49:51 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 22 Sep 2015 10:44:19 -0300 tools build: Fixup feature detection display function name Cut'n'paste mistake, it should eval the name of the function defined right next to it, in the next line, fix it. Before: $ make -C tools/lib/bpf/ make: Entering directory '/home/git/linux/tools/lib/bpf' Auto-detecting system features: ...libelf: [ on ] ... libelf-getphdrnum: [ on ] ... libelf-mmap: [ on ] ... bpf: [ on ] After: $ make -C tools/lib/bpf/ make: Entering directory '/home/git/linux/tools/lib/bpf' Auto-detecting system features: ...libelf: [ on ] ... libelf-getphdrnum: [ OFF ] ... libelf-mmap: [ OFF ] ... bpf: [ on ] Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Cc: pi3or...@163.com Fixes: 58d4f00ff13f ("perf build: Fix feature_check name clash") Link: http://lkml.kernel.org/n/tip-dzu1c4sruukgfq5d5b1c4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Makefile.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index c8fe6d1..690d561 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -140,7 +140,7 @@ ifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)") feature_display := 1 endif -feature_display_check = $(eval $(feature_check_code)) +feature_display_check = $(eval $(feature_check_display_code)) define feature_display_check_code ifneq ($(feature-$(1)), 1) feature_display := 1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] tools build: Allow setting the feature detection user
Commit-ID: 13e96db61c1c32cd4c8102a95129bb7677cc746d Gitweb: http://git.kernel.org/tip/13e96db61c1c32cd4c8102a95129bb7677cc746d Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 21 Sep 2015 12:24:47 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 22 Sep 2015 10:47:04 -0300 tools build: Allow setting the feature detection user We will use the tools/build/ autodetection in the eBPF patchkit and it is currently sharing the output directory with perf, that also uses the feature detection logic. As we keep state in the output directory, so that we can avoid running all the tests again, we need to have different filenames for the files used in this state, allow doing that via the FEATURE_USER variable, to be set alongside the existing FEATURE_{TEST,DISPLAY} variables. v2: Fix comment describing the FEATURE_DUMP filename to make sure where it is created, precisely at $(OUTPUT)FEATURE-DUMP$(FEATURE_USER). Pointed out by Jiri. Acked-by: Jiri Olsa Cc: Alexei Starovoitov Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Cc: pi3or...@163.com Link: http://lkml.kernel.org/n/tip-fdbev0vrn3x6idqc3ajbn...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Makefile.feature | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 690d561..72817e4 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -121,8 +121,9 @@ define feature_print_text_code MSG = $(shell printf '...%30s: %s' $(1) $(2)) endef +FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER) FEATURE_DUMP := $(foreach feat,$(FEATURE_DISPLAY),feature-$(feat)($(feature-$(feat -FEATURE_DUMP_FILE := $(shell touch $(OUTPUT)FEATURE-DUMP; cat $(OUTPUT)FEATURE-DUMP) +FEATURE_DUMP_FILE := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME)) ifeq ($(dwarf-post-unwind),1) FEATURE_DUMP += dwarf-post-unwind($(dwarf-post-unwind-text)) @@ -131,12 +132,12 @@ endif # The $(feature_display) controls the default detection message # output. It's set if: # - detected features differes from stored features from -# last build (in FEATURE-DUMP file) +# last build (in $(FEATURE_DUMP_FILENAME) file) # - one of the $(FEATURE_DISPLAY) is not detected # - VF is enabled ifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)") - $(shell echo "$(FEATURE_DUMP)" > $(OUTPUT)FEATURE-DUMP) + $(shell echo "$(FEATURE_DUMP)" > $(FEATURE_DUMP_FILENAME)) feature_display := 1 endif -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] tools lib bpf: Use FEATURE_USER to allow building in the same dir as perf
Commit-ID: 65f041bee7838e2a91dbbc0a917d9291adbb3484 Gitweb: http://git.kernel.org/tip/65f041bee7838e2a91dbbc0a917d9291adbb3484 Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 21 Sep 2015 17:25:27 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 22 Sep 2015 10:47:05 -0300 tools lib bpf: Use FEATURE_USER to allow building in the same dir as perf When building tools/lib/bpf as part of the tools/perf/ build process, which will happend when we introduce a patch wiring that up, we end up stomping on the feature detection caching mechanism, that uses a file in the output directory (O=) that is shared by libbpf and perf to check if something changed from one build to another that requires redoing the feature detection process. By using the recently introduced FEATURE_USER tools/build/ knob, we can avoid that: Before, every make invokation would run the feature detection: $ make O=/tmp/build/perf -C tools/perf make: Entering directory '/home/git/linux/tools/perf' Auto-detecting system features: ... dwarf: [ on ] ... glibc: [ on ] ... get_cpuid: [ on ] ... bpf: [ on ] GEN perf-archive GEN perf-with-kcore Auto-detecting system features: ...libelf: [ on ] ... bpf: [ on ] After: $ make O=/tmp/build/perf -C tools/perf make: Entering directory '/home/git/linux/tools/perf' BUILD: Doing 'make -j4' parallel build make: Leaving directory '/home/git/linux/tools/perf' $ Because we now have two different feature detection state files: $ ls -la /tmp/build/perf/FEATURE-DUMP* -rw-rw-r--. 1 acme acme 338 Sep 21 17:25 /tmp/build/perf/FEATURE-DUMP -rw-rw-r--. 1 acme acme 33 Sep 21 17:25 /tmp/build/perf/FEATURE-DUMP.libbpf $ Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Cc: pi3or...@163.com Fixes: 1b76c13e4b36 ("bpf tools: Introduce 'bpf' library and add bpf feature check") Link: http://lkml.kernel.org/n/tip-s6ev9wfqy7pvvs58emys2...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index 604c120..e630f9f 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -64,6 +64,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree))) #$(info Determined 'srctree' to be $(srctree)) endif +FEATURE_USER = .libbpf FEATURE_TESTS = libelf libelf-getphdrnum libelf-mmap bpf FEATURE_DISPLAY = libelf bpf -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] tools lib bpf: Fix up FEATURE_{TESTS, DISPLAY} usage
Commit-ID: 20517cd9c5930c9ef580082d23073842e92249ad Gitweb: http://git.kernel.org/tip/20517cd9c5930c9ef580082d23073842e92249ad Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 21 Sep 2015 17:00:27 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 22 Sep 2015 10:47:01 -0300 tools lib bpf: Fix up FEATURE_{TESTS,DISPLAY} usage When libbpf was introduced it wrongly asked for the "libelf" and "bpf" feature tests to be performed (via FEATURE_TESTS), while asking that "libbpf", "libelf-mmap", "libelf-getphdrnum" and "bpf" to have the result of its respective tests to be displayed (via FEATURE_DISPLAY). Due to another recently bug fixed in the tools/build/ infrastructure ("tools build: Fixup feature detection display function name") the results for the entries in the FEATURE_DISPLAY, for this case, were appearing as all succeeding, when two of them (the ones only on the DISPLAY) were not even being performed. Before: $ make -C tools/lib/bpf/ make: Entering directory '/home/git/linux/tools/lib/bpf' Auto-detecting system features: ...libelf: [ on ] ... libelf-getphdrnum: [ OFF ] ... libelf-mmap: [ OFF ] ... bpf: [ on ] After, with FEATURE_TESTS == FEATURE_DISPLAY: Auto-detecting system features: ...libelf: [ on ] ... libelf-getphdrnum: [ on ] ... libelf-mmap: [ on ] ... bpf: [ on ] I just inverted, so that it tests the four features but displays just the libelf and mmap ones, to make it more compact. So it becomes: $ make -C tools/lib/bpf/ make: Entering directory '/home/git/linux/tools/lib/bpf' Auto-detecting system features: ...libelf: [ on ] ... bpf: [ on ] Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Cc: pi3or...@163.com Fixes: 1b76c13e4b36 ("bpf tools: Introduce 'bpf' library and add bpf feature check") Link: http://lkml.kernel.org/n/tip-y4bd59e6j9rzzojiyeqrg...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index f68d23a..604c120 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -64,8 +64,8 @@ srctree := $(patsubst %/,%,$(dir $(srctree))) #$(info Determined 'srctree' to be $(srctree)) endif -FEATURE_DISPLAY = libelf libelf-getphdrnum libelf-mmap bpf -FEATURE_TESTS = libelf bpf +FEATURE_TESTS = libelf libelf-getphdrnum libelf-mmap bpf +FEATURE_DISPLAY = libelf bpf INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf thread: Fix reference count initial state
Commit-ID: abd828688407eb86044f1bc9e5133c55d7597596 Gitweb: http://git.kernel.org/tip/abd828688407eb86044f1bc9e5133c55d7597596 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 11 Dec 2015 19:11:23 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Dec 2015 12:08:55 -0300 perf thread: Fix reference count initial state We should always return from thread__new(), the constructor, with the object with a reference count of one, so that: struct thread *thread = thread__new(); thread__put(thread); Will call thread__delete(). If any reference is made to that 'thread' variable, it better use thread__get(thread) to hold a reference. We were returning with thread->refcnt set to zero, fix it and some cases where thread__delete() was being called, which were not a problem because just one reference was being used, now that we set it to 1, use thread__put() instead. Reported-by: Masami Hiramatsu Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-4b9mkuk66to4ecckpmpvq...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/intel-pt.c | 4 ++-- tools/perf/util/machine.c | 19 --- tools/perf/util/thread.c | 10 -- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 97f963a..81a2eb7 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -1744,7 +1744,7 @@ static void intel_pt_free(struct perf_session *session) auxtrace_heap__free(>heap); intel_pt_free_events(session); session->auxtrace = NULL; - thread__delete(pt->unknown_thread); + thread__put(pt->unknown_thread); free(pt); } @@ -2153,7 +2153,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, return 0; err_delete_thread: - thread__delete(pt->unknown_thread); + thread__zput(pt->unknown_thread); err_free_queues: intel_pt_log_disable(); auxtrace_queues__free(>queues); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 1407d51..ad79297 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -352,13 +352,18 @@ static void machine__update_thread_pid(struct machine *machine, } th->mg = map_groups__get(leader->mg); - +out_put: + thread__put(leader); return; - out_err: pr_err("Failed to join map groups for %d:%d\n", th->pid_, th->tid); + goto out_put; } +/* + * Caller must eventually drop thread->refcnt returned with a successfull + * lookup/new thread inserted. + */ static struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid, bool create) @@ -376,7 +381,7 @@ static struct thread *machine__findnew_thread(struct machine *machine, if (th != NULL) { if (th->tid == tid) { machine__update_thread_pid(machine, th, pid); - return th; + return thread__get(th); } machine->last_match = NULL; @@ -389,7 +394,7 @@ static struct thread *machine__findnew_thread(struct machine *machine, if (th->tid == tid) { machine->last_match = th; machine__update_thread_pid(machine, th, pid); - return th; + return thread__get(th); } if (tid < th->tid) @@ -417,7 +422,7 @@ static struct thread *machine__findnew_thread(struct machine *machine, if (thread__init_map_groups(th, machine)) { rb_erase_init(>rb_node, >threads); RB_CLEAR_NODE(>rb_node); - thread__delete(th); + thread__put(th); return NULL; } /* @@ -441,7 +446,7 @@ struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, struct thread *th; pthread_rwlock_wrlock(>threads_lock); - th = thread__get(__machine__findnew_thread(machine, pid, tid)); + th = __machine__findnew_thread(machine, pid, tid); pthread_rwlock_unlock(>threads_lock); return th; } @@ -451,7 +456,7 @@ struct thread *machine__find_thread(struct machine *machine, pid_t pid, { struct thread *th; pthread_rwlock_rdlock(>threads_lock); - th = thread__get(machine__findnew_thread(machine, pid, tid, false)); + th = machine__findnew_thread(machine, pid, tid, false);
[tip:perf/core] perf test: Dump the stack when test segfaults when in verbose mode
Commit-ID: b6847d2c2a50e96680e233ce4b2784981b6f309e Gitweb: http://git.kernel.org/tip/b6847d2c2a50e96680e233ce4b2784981b6f309e Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 11 Dec 2015 19:06:53 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Dec 2015 12:08:55 -0300 perf test: Dump the stack when test segfaults when in verbose mode E.g.: # perf test 26 26: Test mmap thread lookup : FAILED! # perf test -v 26 26: Test mmap thread lookup : --- start --- test child forked, pid 9269 tid = 9269, map = 0x7ff99ff0c000 tid = 9270, map = 0x7ff99ff0b000 tid = 9271, map = 0x7ff99ff0a000 tid = 9272, map = 0x7ff99ff09000 perf: Segmentation fault Obtained 13 stack frames. perf(sighandler_dump_stack+0x41) [0x4e3541] /lib64/libc.so.6(+0x34960) [0x7ff99d5f6960] perf(thread__put+0x5b) [0x4c6f6b] perf(machine__process_event+0x14e) [0x4bd37e] perf(perf_event__synthesize_threads+0x3aa) [0x48678a] perf(test__mmap_thread_lookup+0x20a) [0x474e0a] perf() [0x460d56] perf(cmd_test+0x589) [0x461319] perf() [0x47c641] perf(main+0x617) [0x422317] /lib64/libc.so.6(__libc_start_main+0xf0) [0x7ff99d5e1fe0] perf() [0x422429] [(nil)] test child interrupted end Test mmap thread lookup: FAILED! # Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-sypazzsl4ptctrmlyi2zc...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/builtin-test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 2b1ade1..fa98406 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -236,6 +236,9 @@ static int run_test(struct test *test, int subtest) dup2(STDOUT_FILENO, STDERR_FILENO); close(nullfd); } + } else { + signal(SIGSEGV, sighandler_dump_stack); + signal(SIGFPE, sighandler_dump_stack); } err = test->func(subtest); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf list: Add support for PERF_COUNT_SW_BPF_OUT
Commit-ID: d643b5aba84884de96d2ea4a902f8b0d9cf4b1b0 Gitweb: http://git.kernel.org/tip/d643b5aba84884de96d2ea4a902f8b0d9cf4b1b0 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 27 Nov 2015 15:54:33 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 16 Dec 2015 16:43:10 -0300 perf list: Add support for PERF_COUNT_SW_BPF_OUT When PERF_COUNT_SW_BPF_OUTPUT was added to the kernel we should've added it to tools/perf, where it is used just to list events. This ended up causing a segfault in commands like "perf list stall". Fix it by adding that new software counter. A patch to robustify perf to not segfault when the next counter gets added in the kernel will follow this one. Reported-by: Ingo Molnar Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-uya354upi3eprsey6mi59...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 4 1 file changed, 4 insertions(+) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index e48d9da..40ae92a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -124,6 +124,10 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { .symbol = "dummy", .alias = "", }, + [PERF_COUNT_SW_BPF_OUTPUT] = { + .symbol = "bpf-output", + .alias = "", + }, }; #define __PERF_EVENT_FIELD(config, name) \ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf list: Robustify event printing routine
Commit-ID: fb202539e61b14bc63ac29af10fe5d758ecd880a Gitweb: http://git.kernel.org/tip/fb202539e61b14bc63ac29af10fe5d758ecd880a Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 27 Nov 2015 16:04:58 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 16 Dec 2015 16:43:10 -0300 perf list: Robustify event printing routine When a43eec304259 ("bpf: introduce bpf_perf_event_output() helper") added PERF_COUNT_SW_BPF_OUTPUT we ended up with a new entry in the event_symbols_sw array that wasn't initialized, thus set to NULL, fix print_symbol_events() to check for that case so that we don't crash if this happens again. (gdb) bt #0 __match_glob (ignore_space=false, pat=, str=) at util/string.c:198 #1 strglobmatch (str=, pat=pat@entry=0x7fffe61d "stall") at util/string.c:252 #2 0x004993a5 in print_symbol_events (type=1, syms=0x872880 , max=11, name_only=false, event_glob=0x7fffe61d "stall") at util/parse-events.c:1615 #3 print_events (event_glob=event_glob@entry=0x7fffe61d "stall", name_only=false) at util/parse-events.c:1675 #4 0x0042c79e in cmd_list (argc=1, argv=0x7fffe390, prefix=) at builtin-list.c:68 #5 0x004788a5 in run_builtin (p=p@entry=0x871758 , argc=argc@entry=2, argv=argv@entry=0x7fffe390) at perf.c:370 #6 0x00420ab0 in handle_internal_command (argv=0x7fffe390, argc=2) at perf.c:429 #7 run_argv (argv=0x7fffe110, argcp=0x7fffe11c) at perf.c:473 #8 main (argc=2, argv=0x7fffe390) at perf.c:588 (gdb) p event_symbols_sw[PERF_COUNT_SW_BPF_OUTPUT] $4 = {symbol = 0x0, alias = 0x0} (gdb) A patch to robustify perf to not segfault when the next counter gets added in the kernel will follow this one. Reported-by: Ingo Molnar Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-57wysblcjfrseb0zg5u7e...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 40ae92a..6fc8cd7 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1883,7 +1883,7 @@ restart: for (i = 0; i < max; i++, syms++) { - if (event_glob != NULL && + if (event_glob != NULL && syms->symbol != NULL && !(strglobmatch(syms->symbol, event_glob) || (syms->alias && strglobmatch(syms->alias, event_glob continue; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf tools: Use same signal handling strategy as 'record'
Commit-ID: 9daddf66a37708ec7182a7058f159166d12c9812 Gitweb: http://git.kernel.org/tip/9daddf66a37708ec7182a7058f159166d12c9812 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 11 Dec 2015 16:43:57 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 14 Dec 2015 12:08:55 -0300 perf tools: Use same signal handling strategy as 'record' I.e. don't exit with the signal number, instead set the signal handler to the default one and then raise it again. Noticed while trying to dump the stack at segfaults in the 'perf test' forked process used to run each test, that inspects signal info at each test. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-5x5r176wnoqxi5p6id05w...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 07da970..aff0cfd 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -352,7 +352,8 @@ void sighandler_dump_stack(int sig) { psignal(sig, "perf"); dump_stack(); - exit(sig); + signal(sig, SIG_DFL); + raise(sig); } int parse_nsec_time(const char *str, u64 *ptime) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf top: Do show usage message when failing to create cpu/thread maps
Commit-ID: f8a5c0b24b8b1e77a0812b0c8251db0afc0524b7 Gitweb: http://git.kernel.org/tip/f8a5c0b24b8b1e77a0812b0c8251db0afc0524b7 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 10 Dec 2015 14:48:45 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 10 Dec 2015 15:47:47 -0300 perf top: Do show usage message when failing to create cpu/thread maps This is necessary to get rid of the browser dependency from usage_with_options() and its friends. Because we validate the targets which are used to create the cpu/thread maps and inform the user about any override performed via the chosen UI, we don't need to call the usage routine for that. Cc: David Ahern Cc: Jiri Olsa Cc: Josh Poimboeuf Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/n/tip-slu7lj7buzpwgop1vo9la...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-top.c | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 7e2e72e..84fd636 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1279,8 +1279,11 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) if (target__none(target)) target->system_wide = true; - if (perf_evlist__create_maps(top.evlist, target) < 0) - usage_with_options(top_usage, options); + if (perf_evlist__create_maps(top.evlist, target) < 0) { + ui__error("Couldn't create thread/CPU maps: %s\n", + errno == ENOENT ? "No such process" : strerror_r(errno, errbuf, sizeof(errbuf))); + goto out_delete_evlist; + } if (!top.evlist->nr_entries && perf_evlist__add_default(top.evlist) < 0) { -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] Revert "perf tools: Improve setting of gcc debug option"
Commit-ID: 8488335c039ff4917754332763e21c01a81435b4 Gitweb: http://git.kernel.org/tip/8488335c039ff4917754332763e21c01a81435b4 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 8 Dec 2015 16:51:24 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 10 Dec 2015 16:09:40 -0300 Revert "perf tools: Improve setting of gcc debug option" This reverts commit e8b7ea4356fdd3c4de5478f3418eb84f8dce2b61. Martin created a gcc PR: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68836 Reported-by: Jiri Olsa Acked-by: Ingo Molnar Cc: David Ahern Cc: Martin Liska Cc: Namhyung Kim , Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20151202164827.ga21...@krava.brq.redhat.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/config/Makefile | 2 -- tools/perf/config/utilities.mak | 19 --- 2 files changed, 21 deletions(-) diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index 6eb9a95..a552417 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile @@ -135,8 +135,6 @@ endif ifeq ($(DEBUG),0) CFLAGS += -O6 -else - CFLAGS += $(call cc-option,-Og,-O0) endif ifdef PARSER_DEBUG diff --git a/tools/perf/config/utilities.mak b/tools/perf/config/utilities.mak index 0ebef09..c16ce83 100644 --- a/tools/perf/config/utilities.mak +++ b/tools/perf/config/utilities.mak @@ -177,22 +177,3 @@ $(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2))) endef _ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2))) _gea_err = $(if $(1),$(error Please set '$(1)' appropriately)) - -# try-run -# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) -# Exit code chooses option. "$$TMP" is can be used as temporary file and -# is automatically cleaned up. -try-run = $(shell set -e; \ - TMP="$(TMPOUT)..tmp"; \ - TMPO="$(TMPOUT)..o";\ - if ($(1)) >/dev/null 2>&1; \ - then echo "$(2)"; \ - else echo "$(3)"; \ - fi; \ - rm -f "$$TMP" "$$TMPO") - -# cc-option -# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) - -cc-option = $(call try-run,\ - $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf list: Add support for PERF_COUNT_SW_BPF_OUT
Commit-ID: bae9cc41105b9edd74d68a9636be2ba240e74b9e Gitweb: http://git.kernel.org/tip/bae9cc41105b9edd74d68a9636be2ba240e74b9e Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 27 Nov 2015 15:54:33 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 27 Nov 2015 16:03:46 -0300 perf list: Add support for PERF_COUNT_SW_BPF_OUT When PERF_COUNT_SW_BPF_OUTPUT was added to the kernel we should've added it to tools/perf, where it is used just to list events. This ended up causing a segfault in commands like "perf list stall". Fix it by adding that new software counter. A patch to robustify perf to not segfault when the next counter gets added in the kernel will follow this one. Reported-by: Ingo Molnar Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-uya354upi3eprsey6mi59...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 4 1 file changed, 4 insertions(+) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index e48d9da..40ae92a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -124,6 +124,10 @@ struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { .symbol = "dummy", .alias = "", }, + [PERF_COUNT_SW_BPF_OUTPUT] = { + .symbol = "bpf-output", + .alias = "", + }, }; #define __PERF_EVENT_FIELD(config, name) \ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf list: Robustify event printing routine
Commit-ID: e37df6c76cb19971f1228bfaff504d8a3ea6f748 Gitweb: http://git.kernel.org/tip/e37df6c76cb19971f1228bfaff504d8a3ea6f748 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 27 Nov 2015 16:04:58 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 27 Nov 2015 16:04:58 -0300 perf list: Robustify event printing routine When a43eec304259 ("bpf: introduce bpf_perf_event_output() helper") added PERF_COUNT_SW_BPF_OUTPUT we ended up with a new entry in the event_symbols_sw array that wasn't initialized, thus set to NULL, fix print_symbol_events() to check for that case so that we don't crash if this happens again. (gdb) bt #0 __match_glob (ignore_space=false, pat=, str=) at util/string.c:198 #1 strglobmatch (str=, pat=pat@entry=0x7fffe61d "stall") at util/string.c:252 #2 0x004993a5 in print_symbol_events (type=1, syms=0x872880 , max=11, name_only=false, event_glob=0x7fffe61d "stall") at util/parse-events.c:1615 #3 print_events (event_glob=event_glob@entry=0x7fffe61d "stall", name_only=false) at util/parse-events.c:1675 #4 0x0042c79e in cmd_list (argc=1, argv=0x7fffe390, prefix=) at builtin-list.c:68 #5 0x004788a5 in run_builtin (p=p@entry=0x871758 , argc=argc@entry=2, argv=argv@entry=0x7fffe390) at perf.c:370 #6 0x00420ab0 in handle_internal_command (argv=0x7fffe390, argc=2) at perf.c:429 #7 run_argv (argv=0x7fffe110, argcp=0x7fffe11c) at perf.c:473 #8 main (argc=2, argv=0x7fffe390) at perf.c:588 (gdb) p event_symbols_sw[PERF_COUNT_SW_BPF_OUTPUT] $4 = {symbol = 0x0, alias = 0x0} (gdb) A patch to robustify perf to not segfault when the next counter gets added in the kernel will follow this one. Reported-by: Ingo Molnar Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-57wysblcjfrseb0zg5u7e...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 40ae92a..6fc8cd7 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1883,7 +1883,7 @@ restart: for (i = 0; i < max; i++, syms++) { - if (event_glob != NULL && + if (event_glob != NULL && syms->symbol != NULL && !(strglobmatch(syms->symbol, event_glob) || (syms->alias && strglobmatch(syms->alias, event_glob continue; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] perf test: Fix build of BPF and LLVM on older glibc libraries
Commit-ID: 916d4092a1d2d7bb50630497be71ee4c4c2807fa Gitweb: http://git.kernel.org/tip/916d4092a1d2d7bb50630497be71ee4c4c2807fa Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 18 Nov 2015 17:38:49 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 18 Nov 2015 17:38:49 -0300 perf test: Fix build of BPF and LLVM on older glibc libraries $ rpm -q glibc glibc-2.12-1.166.el6_7.1.x86_64 CC /tmp/build/perf/tests/llvm.o cc1: warnings being treated as errors tests/llvm.c: In function ‘test_llvm__fetch_bpf_obj’: tests/llvm.c:53: error: declaration of ‘index’ shadows a global declaration /usr/include/string.h:489: error: shadowed declaration is here CC /tmp/build/perf/tests/bpf.o cc1: warnings being treated as errors tests/bpf.c: In function ‘__test__bpf’: tests/bpf.c:149: error: declaration of ‘index’ shadows a global declaration /usr/include/string.h:489: error: shadowed declaration is here Cc: He Kuang Cc: Jiri Olsa Cc: Namhyung Kim Cc: pi3or...@163.com Cc: Wang Nan Cc: Zefan Li Fixes: b31de018a628 ("perf test: Enhance the LLVM test: update basic BPF test program") Fixes: ba1fae431e74 ("perf test: Add 'perf test BPF'") Link: http://lkml.kernel.org/n/tip-akpo4r750oya2phxoh9e3...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/bpf.c | 14 +++--- tools/perf/tests/llvm.c | 8 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c index ec16f78..6ebfdee 100644 --- a/tools/perf/tests/bpf.c +++ b/tools/perf/tests/bpf.c @@ -146,7 +146,7 @@ prepare_bpf(void *obj_buf, size_t obj_buf_sz, const char *name) return obj; } -static int __test__bpf(int index) +static int __test__bpf(int idx) { int ret; void *obj_buf; @@ -154,27 +154,27 @@ static int __test__bpf(int index) struct bpf_object *obj; ret = test_llvm__fetch_bpf_obj(_buf, _buf_sz, - bpf_testcase_table[index].prog_id, + bpf_testcase_table[idx].prog_id, true); if (ret != TEST_OK || !obj_buf || !obj_buf_sz) { pr_debug("Unable to get BPF object, %s\n", -bpf_testcase_table[index].msg_compile_fail); - if (index == 0) +bpf_testcase_table[idx].msg_compile_fail); + if (idx == 0) return TEST_SKIP; else return TEST_FAIL; } obj = prepare_bpf(obj_buf, obj_buf_sz, - bpf_testcase_table[index].name); + bpf_testcase_table[idx].name); if (!obj) { ret = TEST_FAIL; goto out; } ret = do_test(obj, - bpf_testcase_table[index].target_func, - bpf_testcase_table[index].expect_result); + bpf_testcase_table[idx].target_func, + bpf_testcase_table[idx].expect_result); out: bpf__clear(); return ret; diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c index bc4cf50..366e38b 100644 --- a/tools/perf/tests/llvm.c +++ b/tools/perf/tests/llvm.c @@ -50,7 +50,7 @@ static struct { int test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz, -enum test_llvm__testcase index, +enum test_llvm__testcase idx, bool force) { const char *source; @@ -59,11 +59,11 @@ test_llvm__fetch_bpf_obj(void **p_obj_buf, char *tmpl_new = NULL, *clang_opt_new = NULL; int err, old_verbose, ret = TEST_FAIL; - if (index >= __LLVM_TESTCASE_MAX) + if (idx >= __LLVM_TESTCASE_MAX) return TEST_FAIL; - source = bpf_source_table[index].source; - desc = bpf_source_table[index].desc; + source = bpf_source_table[idx].source; + desc = bpf_source_table[idx].desc; perf_config(perf_config_cb, NULL); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[tip:perf/core] tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c
Commit-ID: 4ddd32741da87657113d964588ce13ee64b34820 Gitweb: http://git.kernel.org/tip/4ddd32741da87657113d964588ce13ee64b34820 Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 16 Nov 2015 11:36:29 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 18 Nov 2015 17:51:02 -0300 tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c That will contain more string functions with counterparts, sometimes verbatim copies, in the kernel. Acked-by: Wang Nan Cc: Adrian Hunter Cc: Alexey Dobriyan Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-rah6g97kn21vfgmlramor...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/include/linux/string.h | 9 + tools/lib/string.c | 19 +++ tools/perf/MANIFEST| 2 ++ tools/perf/util/Build | 6 ++ tools/perf/util/include/linux/string.h | 3 --- tools/perf/util/string.c | 16 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h new file mode 100644 index 000..f3a6db6 --- /dev/null +++ b/tools/include/linux/string.h @@ -0,0 +1,9 @@ +#ifndef _TOOLS_LINUX_STRING_H_ +#define _TOOLS_LINUX_STRING_H_ + + +#include/* for size_t */ + +void *memdup(const void *src, size_t len); + +#endif /* _LINUX_STRING_H_ */ diff --git a/tools/lib/string.c b/tools/lib/string.c new file mode 100644 index 000..ecfd43a --- /dev/null +++ b/tools/lib/string.c @@ -0,0 +1,19 @@ +#include +#include +#include + +/** + * memdup - duplicate region of memory + * + * @src: memory region to duplicate + * @len: memory region length + */ +void *memdup(const void *src, size_t len) +{ + void *p = malloc(len); + + if (p) + memcpy(p, src, len); + + return p; +} diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST index 39c38cb..2562eac 100644 --- a/tools/perf/MANIFEST +++ b/tools/perf/MANIFEST @@ -22,6 +22,7 @@ tools/lib/api tools/lib/bpf tools/lib/hweight.c tools/lib/rbtree.c +tools/lib/string.c tools/lib/symbol/kallsyms.c tools/lib/symbol/kallsyms.h tools/lib/util/find_next_bit.c @@ -50,6 +51,7 @@ tools/include/linux/log2.h tools/include/linux/poison.h tools/include/linux/rbtree.h tools/include/linux/rbtree_augmented.h +tools/include/linux/string.h tools/include/linux/types.h tools/include/linux/err.h include/asm-generic/bitops/arch_hweight.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 591b3fe..e231690 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -21,6 +21,7 @@ libperf-y += parse-events.o libperf-y += perf_regs.o libperf-y += path.o libperf-y += rbtree.o +libperf-y += libstring.o libperf-y += bitmap.o libperf-y += hweight.o libperf-y += run-command.o @@ -138,6 +139,7 @@ $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_rbtree.o+= -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" +CFLAGS_libstring.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" CFLAGS_parse-events.o += -Wno-redundant-decls @@ -153,6 +155,10 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) +$(OUTPUT)util/libstring.o: ../lib/string.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c) + $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) diff --git a/tools/perf/util/include/linux/string.h b/tools/perf/util/include/linux/string.h deleted file mode 100644 index 6f19c54..000 --- a/tools/perf/util/include/linux/string.h +++ /dev/null @@ -1,3 +0,0 @@ -#include - -void *memdup(const void *src, size_t len); diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index fc8781d..7f7e072 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c @@ -342,22 +342,6 @@ char *rtrim(char *s) return s; } -/** - * memdup - duplicate region of memory - * @src: memory region to duplicate - * @len: memory region length - */ -void *memdup(const void *src, size_t len) -{ - void *p; - - p = malloc(len); - if (p) - memcpy(p, src, len); - - return p; -} - char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) { /* -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo
[tip:perf/core] perf tests: Pass the subtest index to each test routine
Commit-ID: 721a1f53df6aad3ea941f5fe95519d0d8e02bd65 Gitweb: http://git.kernel.org/tip/721a1f53df6aad3ea941f5fe95519d0d8e02bd65 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 19 Nov 2015 12:01:48 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 19 Nov 2015 13:19:15 -0300 perf tests: Pass the subtest index to each test routine Some tests have sub-tests we want to run, so allow passing this. Wang tried to avoid having to touch all tests, but then, having the test.func in an anonymous union makes the build fail on older compilers, like the one in RHEL6, where: test a = { .func = foo, }; fails. To fix it leave the func pointer in the main structure and pass the subtest index to all tests, end result function is the same, but we have just one function pointer, not two, with and without the subtest index as an argument. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-5genj0ficwdmelpoqlds0...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/x86/include/arch-tests.h | 8 +-- tools/perf/arch/x86/tests/insn-x86.c | 2 +- tools/perf/arch/x86/tests/intel-cqm.c| 2 +- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +- tools/perf/arch/x86/tests/rdpmc.c| 2 +- tools/perf/tests/attr.c | 2 +- tools/perf/tests/bp_signal.c | 2 +- tools/perf/tests/bp_signal_overflow.c| 2 +- tools/perf/tests/bpf.c | 2 +- tools/perf/tests/builtin-test.c | 6 +-- tools/perf/tests/code-reading.c | 2 +- tools/perf/tests/dso-data.c | 6 +-- tools/perf/tests/dwarf-unwind.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 2 +- tools/perf/tests/evsel-tp-sched.c| 2 +- tools/perf/tests/fdarray.c | 4 +- tools/perf/tests/hists_cumulate.c| 2 +- tools/perf/tests/hists_filter.c | 2 +- tools/perf/tests/hists_link.c| 2 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/kmod-path.c | 2 +- tools/perf/tests/llvm.c | 2 +- tools/perf/tests/mmap-basic.c| 2 +- tools/perf/tests/mmap-thread-lookup.c| 2 +- tools/perf/tests/openat-syscall-all-cpus.c | 2 +- tools/perf/tests/openat-syscall-tp-fields.c | 2 +- tools/perf/tests/openat-syscall.c| 2 +- tools/perf/tests/parse-events.c | 2 +- tools/perf/tests/parse-no-sample-id-all.c| 2 +- tools/perf/tests/perf-record.c | 2 +- tools/perf/tests/pmu.c | 2 +- tools/perf/tests/python-use.c| 3 +- tools/perf/tests/sample-parsing.c| 2 +- tools/perf/tests/sw-clock.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 2 +- tools/perf/tests/tests.h | 78 ++-- tools/perf/tests/thread-map.c| 2 +- tools/perf/tests/thread-mg-share.c | 2 +- tools/perf/tests/topology.c | 2 +- tools/perf/tests/vmlinux-kallsyms.c | 2 +- 42 files changed, 89 insertions(+), 88 deletions(-) diff --git a/tools/perf/arch/x86/include/arch-tests.h b/tools/perf/arch/x86/include/arch-tests.h index 7ed00f4..b48de2f 100644 --- a/tools/perf/arch/x86/include/arch-tests.h +++ b/tools/perf/arch/x86/include/arch-tests.h @@ -2,10 +2,10 @@ #define ARCH_TESTS_H /* Tests */ -int test__rdpmc(void); -int test__perf_time_to_tsc(void); -int test__insn_x86(void); -int test__intel_cqm_count_nmi_context(void); +int test__rdpmc(int subtest); +int test__perf_time_to_tsc(int subtest); +int test__insn_x86(int subtest); +int test__intel_cqm_count_nmi_context(int subtest); #ifdef HAVE_DWARF_UNWIND_SUPPORT struct thread; diff --git a/tools/perf/arch/x86/tests/insn-x86.c b/tools/perf/arch/x86/tests/insn-x86.c index b6115df..08d9b2b 100644 --- a/tools/perf/arch/x86/tests/insn-x86.c +++ b/tools/perf/arch/x86/tests/insn-x86.c @@ -171,7 +171,7 @@ static int test_data_set(struct test_data *dat_set, int x86_64) * verbose (-v) option to see all the instructions and whether or not they * decoded successfuly. */ -int test__insn_x86(void) +int test__insn_x86(int subtest __maybe_unused) { int ret = 0; diff --git a/tools/perf/arch/x86/tests/intel-cqm.c b/tools/perf/arch/x86/tests/intel-cqm.c index d28c1b6..94e0cb7 100644 --- a/tools/perf/arch/x86/tests/intel-cqm.c +++ b/tools/perf/arch/x86/tests/intel-cqm.c @@ -33,7 +33,7 @@ static pid_t spawn(void) * the last read counter value to avoid
[tip:perf/core] perf evsel: Provide way to extract integer value from format_field
Commit-ID: 90525176d71995ffde2d0c532f2758304c666a08 Gitweb: http://git.kernel.org/tip/90525176d71995ffde2d0c532f2758304c666a08 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 31 May 2016 12:47:46 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 3 Jun 2016 14:53:46 -0300 perf evsel: Provide way to extract integer value from format_field Out of perf_evsel__intval(), that requires passing the variable name, that will then be searched in the list of tracepoint variables for the given evsel. In cases such as syscall file descriptor ("fd") tracking, this is wasteful, we need just to use perf_evsel__field() and cache the format_field. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-r6f89jx9j5nkx037d0nav...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 25 +++-- tools/perf/util/evsel.h | 2 ++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8d30cbd..f4f01b2 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2251,17 +2251,11 @@ void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample, return sample->raw_data + offset; } -u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, - const char *name) +u64 format_field__intval(struct format_field *field, struct perf_sample *sample, +bool needs_swap) { - struct format_field *field = perf_evsel__field(evsel, name); - void *ptr; u64 value; - - if (!field) - return 0; - - ptr = sample->raw_data + field->offset; + void *ptr = sample->raw_data + field->offset; switch (field->size) { case 1: @@ -2279,7 +2273,7 @@ u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, return 0; } - if (!evsel->needs_swap) + if (!needs_swap) return value; switch (field->size) { @@ -2296,6 +2290,17 @@ u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, return 0; } +u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, + const char *name) +{ + struct format_field *field = perf_evsel__field(evsel, name); + + if (!field) + return 0; + + return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; +} + bool perf_evsel__fallback(struct perf_evsel *evsel, int err, char *msg, size_t msgsize) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 028412b..828ddd1 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -261,6 +261,8 @@ static inline char *perf_evsel__strval(struct perf_evsel *evsel, struct format_field; +u64 format_field__intval(struct format_field *field, struct perf_sample *sample, bool needs_swap); + struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name); #define perf_evsel__match(evsel, t, c) \
[tip:perf/core] tools lib bpf: Remove _get_ from non-refcount method names
Commit-ID: a7fe0450b0142d0eb4a543840a43e22682debf25 Gitweb: http://git.kernel.org/tip/a7fe0450b0142d0eb4a543840a43e22682debf25 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 3 Jun 2016 12:22:51 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 6 Jun 2016 18:19:25 -0300 tools lib bpf: Remove _get_ from non-refcount method names The use of this term is not warranted here, we use it in the kernel sources and in tools/ for refcounting, so, for consistency, rename them. Acked-bu: Wang Nan Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-4ya1ot2e2fkrz48ws9ebi...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 16 +--- tools/lib/bpf/libbpf.h | 6 +++--- tools/perf/util/bpf-loader.c | 4 ++-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 57924db..0412182 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1186,20 +1186,14 @@ bpf_object__next(struct bpf_object *prev) return next; } -const char * -bpf_object__get_name(struct bpf_object *obj) +const char *bpf_object__name(struct bpf_object *obj) { - if (!obj) - return ERR_PTR(-EINVAL); - return obj->path; + return obj ? obj->path : ERR_PTR(-EINVAL); } -unsigned int -bpf_object__get_kversion(struct bpf_object *obj) +unsigned int bpf_object__kversion(struct bpf_object *obj) { - if (!obj) - return 0; - return obj->kern_version; + return obj ? obj->kern_version : 0; } struct bpf_program * @@ -1375,7 +1369,7 @@ bpf_map__next(struct bpf_map *prev, struct bpf_object *obj) } struct bpf_map * -bpf_object__get_map_by_name(struct bpf_object *obj, const char *name) +bpf_object__find_map_by_name(struct bpf_object *obj, const char *name) { struct bpf_map *pos; diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index cb838d0..ea65775 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -55,8 +55,8 @@ void bpf_object__close(struct bpf_object *object); /* Load/unload object into/from kernel */ int bpf_object__load(struct bpf_object *obj); int bpf_object__unload(struct bpf_object *obj); -const char *bpf_object__get_name(struct bpf_object *obj); -unsigned int bpf_object__get_kversion(struct bpf_object *obj); +const char *bpf_object__name(struct bpf_object *obj); +unsigned int bpf_object__kversion(struct bpf_object *obj); struct bpf_object *bpf_object__next(struct bpf_object *prev); #define bpf_object__for_each_safe(pos, tmp)\ @@ -171,7 +171,7 @@ struct bpf_map_def { */ struct bpf_map; struct bpf_map * -bpf_object__get_map_by_name(struct bpf_object *obj, const char *name); +bpf_object__find_map_by_name(struct bpf_object *obj, const char *name); struct bpf_map * bpf_map__next(struct bpf_map *map, struct bpf_object *obj); diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 12e6ef4..c19010e 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -1137,7 +1137,7 @@ bpf__obj_config_map(struct bpf_object *obj, goto out; } - map = bpf_object__get_map_by_name(obj, map_name); + map = bpf_object__find_map_by_name(obj, map_name); if (!map) { pr_debug("ERROR: Map %s doesn't exist\n", map_name); err = -BPF_LOADER_ERRNO__OBJCONF_MAP_NOTEXIST; @@ -1662,7 +1662,7 @@ int bpf__strerror_load(struct bpf_object *obj, { bpf__strerror_head(err, buf, size); case LIBBPF_ERRNO__KVER: { - unsigned int obj_kver = bpf_object__get_kversion(obj); + unsigned int obj_kver = bpf_object__kversion(obj); unsigned int real_kver; if (fetch_kernel_version(_kver, NULL, 0)) {
[tip:perf/core] tools lib bpf: Make bpf_program__get_private() use IS_ERR()
Commit-ID: be834ffbd15ea9d73ba96fdbdcb1012add7e3bdf Gitweb: http://git.kernel.org/tip/be834ffbd15ea9d73ba96fdbdcb1012add7e3bdf Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 3 Jun 2016 12:36:39 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 6 Jun 2016 18:19:34 -0300 tools lib bpf: Make bpf_program__get_private() use IS_ERR() For consistency with bpf_map__priv() and elsewhere. Acked-by: Wang Nan Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-x17nk5mrazkf45z0l0ahl...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 5 ++--- tools/lib/bpf/libbpf.h | 3 +-- tools/perf/util/bpf-loader.c | 27 --- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 0412182..7eb7fb2 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1230,10 +1230,9 @@ int bpf_program__set_private(struct bpf_program *prog, return 0; } -int bpf_program__get_private(struct bpf_program *prog, void **ppriv) +void *bpf_program__priv(struct bpf_program *prog) { - *ppriv = prog->priv; - return 0; + return prog ? prog->priv : ERR_PTR(-EINVAL); } const char *bpf_program__title(struct bpf_program *prog, bool needs_copy) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index ea65775..372cecb 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -81,8 +81,7 @@ typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, int bpf_program__set_private(struct bpf_program *prog, void *priv, bpf_program_clear_priv_t clear_priv); -int bpf_program__get_private(struct bpf_program *prog, -void **ppriv); +void *bpf_program__priv(struct bpf_program *prog); const char *bpf_program__title(struct bpf_program *prog, bool needs_copy); diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index c19010e..1907d53 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -380,15 +380,14 @@ preproc_gen_prologue(struct bpf_program *prog, int n, struct bpf_insn *orig_insns, int orig_insns_cnt, struct bpf_prog_prep_result *res) { + struct bpf_prog_priv *priv = bpf_program__priv(prog); struct probe_trace_event *tev; struct perf_probe_event *pev; - struct bpf_prog_priv *priv; struct bpf_insn *buf; size_t prologue_cnt = 0; int i, err; - err = bpf_program__get_private(prog, (void **)); - if (err || !priv) + if (IS_ERR(priv) || !priv) goto errout; pev = >pev; @@ -535,13 +534,12 @@ static int map_prologue(struct perf_probe_event *pev, int *mapping, static int hook_load_preprocessor(struct bpf_program *prog) { + struct bpf_prog_priv *priv = bpf_program__priv(prog); struct perf_probe_event *pev; - struct bpf_prog_priv *priv; bool need_prologue = false; int err, i; - err = bpf_program__get_private(prog, (void **)); - if (err || !priv) { + if (IS_ERR(priv) || !priv) { pr_debug("Internal error when hook preprocessor\n"); return -BPF_LOADER_ERRNO__INTERNAL; } @@ -607,9 +605,11 @@ int bpf__probe(struct bpf_object *obj) if (err) goto out; - err = bpf_program__get_private(prog, (void **)); - if (err || !priv) + priv = bpf_program__priv(prog); + if (IS_ERR(priv) || !priv) { + err = PTR_ERR(priv); goto out; + } pev = >pev; err = convert_perf_probe_events(pev, 1); @@ -645,13 +645,12 @@ int bpf__unprobe(struct bpf_object *obj) { int err, ret = 0; struct bpf_program *prog; - struct bpf_prog_priv *priv; bpf_object__for_each_program(prog, obj) { + struct bpf_prog_priv *priv = bpf_program__priv(prog); int i; - err = bpf_program__get_private(prog, (void **)); - if (err || !priv) + if (IS_ERR(priv) || !priv) continue; for (i = 0; i < priv->pev.ntevs; i++) { @@ -702,14 +701,12 @@ int bpf__foreach_tev(struct bpf_object *obj, int err; bpf_object__for_each_program(prog, obj) { + struct bpf_prog_priv *priv = bpf_program__priv(prog); struct probe_trace_event *tev; struct perf_probe_event *pev; - struct bpf_prog_priv *priv; int i, fd; -
[tip:perf/core] tools lib bpf: Rename set_private() to set_priv()
Commit-ID: edb13ed47c1a196eca4b669b7c20d26b27260813 Gitweb: http://git.kernel.org/tip/edb13ed47c1a196eca4b669b7c20d26b27260813 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 3 Jun 2016 12:38:21 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 6 Jun 2016 18:19:49 -0300 tools lib bpf: Rename set_private() to set_priv() For consistency with class__priv() elsewhere, and with the callback typedef for clearing those areas (e.g. bpf_map_clear_priv_t). Acked-by: Wang Nan Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-rnbiyv27ohw8xppsgx0el...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 9 - tools/lib/bpf/libbpf.h | 8 tools/perf/util/bpf-loader.c | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7eb7fb2..462e526 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1218,9 +1218,8 @@ bpf_program__next(struct bpf_program *prev, struct bpf_object *obj) return >programs[idx]; } -int bpf_program__set_private(struct bpf_program *prog, -void *priv, -bpf_program_clear_priv_t clear_priv) +int bpf_program__set_priv(struct bpf_program *prog, void *priv, + bpf_program_clear_priv_t clear_priv) { if (prog->priv && prog->clear_priv) prog->clear_priv(prog, prog->priv); @@ -1319,8 +1318,8 @@ const char *bpf_map__name(struct bpf_map *map) return map ? map->name : NULL; } -int bpf_map__set_private(struct bpf_map *map, void *priv, -bpf_map_clear_priv_t clear_priv) +int bpf_map__set_priv(struct bpf_map *map, void *priv, +bpf_map_clear_priv_t clear_priv) { if (!map) return -EINVAL; diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 372cecb..722f46b 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -78,8 +78,8 @@ struct bpf_program *bpf_program__next(struct bpf_program *prog, typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, void *); -int bpf_program__set_private(struct bpf_program *prog, void *priv, -bpf_program_clear_priv_t clear_priv); +int bpf_program__set_priv(struct bpf_program *prog, void *priv, + bpf_program_clear_priv_t clear_priv); void *bpf_program__priv(struct bpf_program *prog); @@ -184,8 +184,8 @@ const struct bpf_map_def *bpf_map__def(struct bpf_map *map); const char *bpf_map__name(struct bpf_map *map); typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); -int bpf_map__set_private(struct bpf_map *map, void *priv, -bpf_map_clear_priv_t clear_priv); +int bpf_map__set_priv(struct bpf_map *map, void *priv, + bpf_map_clear_priv_t clear_priv); void *bpf_map__priv(struct bpf_map *map); #endif diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 1907d53..dcc8845 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -339,7 +339,7 @@ config_bpf_program(struct bpf_program *prog) } pr_debug("bpf: config '%s' is ok\n", config_str); - err = bpf_program__set_private(prog, priv, clear_prog_priv); + err = bpf_program__set_priv(prog, priv, clear_prog_priv); if (err) { pr_debug("Failed to set priv for program '%s'\n", config_str); goto errout; @@ -910,7 +910,7 @@ bpf_map__add_op(struct bpf_map *map, struct bpf_map_op *op) } INIT_LIST_HEAD(>ops_list); - if (bpf_map__set_private(map, priv, bpf_map_priv__clear)) { + if (bpf_map__set_priv(map, priv, bpf_map_priv__clear)) { free(priv); return -BPF_LOADER_ERRNO__INTERNAL; } @@ -1515,7 +1515,7 @@ int bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused) if (!priv) return -ENOMEM; - err = bpf_map__set_private(map, priv, bpf_map_priv__clear); + err = bpf_map__set_priv(map, priv, bpf_map_priv__clear); if (err) { bpf_map_priv__clear(map, priv); return err;
[tip:perf/core] tools lib bpf: Rename bpf_map__get_name() to bpf_map__name()
Commit-ID: 009ad5d5945697a887f0c1b2d581503d92dcde6f Gitweb: http://git.kernel.org/tip/009ad5d5945697a887f0c1b2d581503d92dcde6f Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 2 Jun 2016 11:02:05 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 6 Jun 2016 18:18:44 -0300 tools lib bpf: Rename bpf_map__get_name() to bpf_map__name() For consistency, leaving "get" for reference counting. Acked-by: Wang Nan Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-crnflv84ejyhpba933ec7...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 6 ++ tools/lib/bpf/libbpf.h | 2 +- tools/perf/util/bpf-loader.c | 18 ++ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 9bba1a9..4dc617b 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1328,11 +1328,9 @@ int bpf_map__get_def(struct bpf_map *map, struct bpf_map_def *pdef) return 0; } -const char *bpf_map__get_name(struct bpf_map *map) +const char *bpf_map__name(struct bpf_map *map) { - if (!map) - return NULL; - return map->name; + return map ? map->name : NULL; } int bpf_map__set_private(struct bpf_map *map, void *priv, diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 916abf9..f8fbba4 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -182,7 +182,7 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj); int bpf_map__get_fd(struct bpf_map *map); int bpf_map__get_def(struct bpf_map *map, struct bpf_map_def *pdef); -const char *bpf_map__get_name(struct bpf_map *map); +const char *bpf_map__name(struct bpf_map *map); typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); int bpf_map__set_private(struct bpf_map *map, void *priv, diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index e9a034e..c819eb8 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -897,10 +897,9 @@ bpf_map_priv__clone(struct bpf_map_priv *priv) static int bpf_map__add_op(struct bpf_map *map, struct bpf_map_op *op) { + const char *map_name = bpf_map__name(map); struct bpf_map_priv *priv = bpf_map__priv(map); - const char *map_name; - map_name = bpf_map__get_name(map); if (IS_ERR(priv)) { pr_debug("Failed to get private from map %s\n", map_name); return PTR_ERR(priv); @@ -948,11 +947,9 @@ __bpf_map__config_value(struct bpf_map *map, { struct bpf_map_def def; struct bpf_map_op *op; - const char *map_name; + const char *map_name = bpf_map__name(map); int err; - map_name = bpf_map__get_name(map); - err = bpf_map__get_def(map, ); if (err) { pr_debug("Unable to get map definition from '%s'\n", @@ -1014,10 +1011,9 @@ __bpf_map__config_event(struct bpf_map *map, struct perf_evsel *evsel; struct bpf_map_def def; struct bpf_map_op *op; - const char *map_name; + const char *map_name = bpf_map__name(map); int err; - map_name = bpf_map__get_name(map); evsel = perf_evlist__find_evsel_by_str(evlist, term->val.str); if (!evsel) { pr_debug("Event (for '%s') '%s' doesn't exist\n", @@ -1259,13 +1255,11 @@ bpf_map_config_foreach_key(struct bpf_map *map, void *arg) { int err, map_fd; - const char *name; struct bpf_map_op *op; struct bpf_map_def def; + const char *name = bpf_map__name(map); struct bpf_map_priv *priv = bpf_map__priv(map); - name = bpf_map__get_name(map); - if (IS_ERR(priv)) { pr_debug("ERROR: failed to get private from map %s\n", name); return -BPF_LOADER_ERRNO__INTERNAL; @@ -1472,9 +1466,9 @@ int bpf__apply_obj_config(void) #define bpf__for_each_stdout_map(pos, obj, objtmp) \ bpf__for_each_map(pos, obj, objtmp) \ - if (bpf_map__get_name(pos) && \ + if (bpf_map__name(pos) && \ (strcmp("__bpf_stdout__", \ - bpf_map__get_name(pos)) == 0)) + bpf_map__name(pos)) == 0)) int bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused) {
[tip:perf/core] tools lib bpf: Use IS_ERR() reporting macros with bpf_map__get_def()
Commit-ID: 53897a78ca6d4bd64e8c17d76cfec65d237f9447 Gitweb: http://git.kernel.org/tip/53897a78ca6d4bd64e8c17d76cfec65d237f9447 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 2 Jun 2016 14:21:06 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 6 Jun 2016 18:18:55 -0300 tools lib bpf: Use IS_ERR() reporting macros with bpf_map__get_def() And for consistency, rename it to bpf_map__def(), leaving "get" for reference counting. Also make it return a const pointer, as suggested by Wang. Acked-by: Wang Nan Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-mer00xqkiho0ymg66b5i9...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 8 ++- tools/lib/bpf/libbpf.h | 2 +- tools/perf/util/bpf-loader.c | 52 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4dc617b..215be67 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1319,13 +1319,9 @@ int bpf_map__get_fd(struct bpf_map *map) return map->fd; } -int bpf_map__get_def(struct bpf_map *map, struct bpf_map_def *pdef) +const struct bpf_map_def *bpf_map__def(struct bpf_map *map) { - if (!map || !pdef) - return -EINVAL; - - *pdef = map->def; - return 0; + return map ? >def : ERR_PTR(-EINVAL); } const char *bpf_map__name(struct bpf_map *map) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index f8fbba4..bad5bac 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -181,7 +181,7 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj); (pos) = bpf_map__next((pos), (obj))) int bpf_map__get_fd(struct bpf_map *map); -int bpf_map__get_def(struct bpf_map *map, struct bpf_map_def *pdef); +const struct bpf_map_def *bpf_map__def(struct bpf_map *map); const char *bpf_map__name(struct bpf_map *map); typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index c819eb8..73c1e7c 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -945,28 +945,26 @@ static int __bpf_map__config_value(struct bpf_map *map, struct parse_events_term *term) { - struct bpf_map_def def; struct bpf_map_op *op; const char *map_name = bpf_map__name(map); - int err; + const struct bpf_map_def *def = bpf_map__def(map); - err = bpf_map__get_def(map, ); - if (err) { + if (IS_ERR(def)) { pr_debug("Unable to get map definition from '%s'\n", map_name); return -BPF_LOADER_ERRNO__INTERNAL; } - if (def.type != BPF_MAP_TYPE_ARRAY) { + if (def->type != BPF_MAP_TYPE_ARRAY) { pr_debug("Map %s type is not BPF_MAP_TYPE_ARRAY\n", map_name); return -BPF_LOADER_ERRNO__OBJCONF_MAP_TYPE; } - if (def.key_size < sizeof(unsigned int)) { + if (def->key_size < sizeof(unsigned int)) { pr_debug("Map %s has incorrect key size\n", map_name); return -BPF_LOADER_ERRNO__OBJCONF_MAP_KEYSIZE; } - switch (def.value_size) { + switch (def->value_size) { case 1: case 2: case 4: @@ -1009,10 +1007,9 @@ __bpf_map__config_event(struct bpf_map *map, struct perf_evlist *evlist) { struct perf_evsel *evsel; - struct bpf_map_def def; + const struct bpf_map_def *def; struct bpf_map_op *op; const char *map_name = bpf_map__name(map); - int err; evsel = perf_evlist__find_evsel_by_str(evlist, term->val.str); if (!evsel) { @@ -1021,18 +1018,18 @@ __bpf_map__config_event(struct bpf_map *map, return -BPF_LOADER_ERRNO__OBJCONF_MAP_NOEVT; } - err = bpf_map__get_def(map, ); - if (err) { + def = bpf_map__def(map); + if (IS_ERR(def)) { pr_debug("Unable to get map definition from '%s'\n", map_name); - return err; + return PTR_ERR(def); } /* * No need to check key_size and value_size: * kernel has already checked them. */ - if (def.type != BPF_MAP_TYPE_PERF_EVENT_ARRAY) { + if (def->type != BPF_MAP_TYPE_PERF_EVENT_ARRAY) { pr_debug("Map %s type is not BPF_MAP_TYPE_PERF_EVENT_ARRAY\n", map_name); return -BPF_LOADER_ERRNO__OBJCONF_MAP_TYPE; @@ -1081,9 +1078,8 @@
[tip:perf/core] tools lib bpf: Use IS_ERR() reporting macros with bpf_map__get_private()
Commit-ID: b4cbfa5670414a567a8a3b368047538f522eff6a Gitweb: http://git.kernel.org/tip/b4cbfa5670414a567a8a3b368047538f522eff6a Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 2 Jun 2016 10:51:59 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 6 Jun 2016 18:18:30 -0300 tools lib bpf: Use IS_ERR() reporting macros with bpf_map__get_private() To try to, over time, consistently use the IS_ERR() interface instead of using two return values, i.e. the integer return value for an error and the pointer address to return the bpf_map->priv pointer. Also rename it to bpf__priv(), to leave the "get" term for reference counting. Noticed while working on using BPF for collecting non-integer syscall argument payloads (struct sockaddr in calls such as connect(), for instance), where we need to use BPF maps and thus generalise bpf__setup_stdout() to connect bpf_output events with maps in a bpf proggie. Acked-by: Wang Nan Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-saypxyd6ptrct379jqgxx...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 9 ++--- tools/lib/bpf/libbpf.h | 2 +- tools/perf/util/bpf-loader.c | 23 +-- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7e543c3..9bba1a9 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1351,14 +1351,9 @@ int bpf_map__set_private(struct bpf_map *map, void *priv, return 0; } -int bpf_map__get_private(struct bpf_map *map, void **ppriv) +void *bpf_map__priv(struct bpf_map *map) { - if (!map) - return -EINVAL; - - if (ppriv) - *ppriv = map->priv; - return 0; + return map ? map->priv : ERR_PTR(-EINVAL); } struct bpf_map * diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index a51594c..916abf9 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -187,6 +187,6 @@ const char *bpf_map__get_name(struct bpf_map *map); typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); int bpf_map__set_private(struct bpf_map *map, void *priv, bpf_map_clear_priv_t clear_priv); -int bpf_map__get_private(struct bpf_map *map, void **ppriv); +void *bpf_map__priv(struct bpf_map *map); #endif diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 493307d..e9a034e 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -897,15 +897,13 @@ bpf_map_priv__clone(struct bpf_map_priv *priv) static int bpf_map__add_op(struct bpf_map *map, struct bpf_map_op *op) { - struct bpf_map_priv *priv; + struct bpf_map_priv *priv = bpf_map__priv(map); const char *map_name; - int err; map_name = bpf_map__get_name(map); - err = bpf_map__get_private(map, (void **)); - if (err) { + if (IS_ERR(priv)) { pr_debug("Failed to get private from map %s\n", map_name); - return err; + return PTR_ERR(priv); } if (!priv) { @@ -1264,12 +1262,11 @@ bpf_map_config_foreach_key(struct bpf_map *map, const char *name; struct bpf_map_op *op; struct bpf_map_def def; - struct bpf_map_priv *priv; + struct bpf_map_priv *priv = bpf_map__priv(map); name = bpf_map__get_name(map); - err = bpf_map__get_private(map, (void **)); - if (err) { + if (IS_ERR(priv)) { pr_debug("ERROR: failed to get private from map %s\n", name); return -BPF_LOADER_ERRNO__INTERNAL; } @@ -1489,10 +1486,9 @@ int bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused) bool need_init = false; bpf__for_each_stdout_map(map, obj, tmp) { - struct bpf_map_priv *priv; + struct bpf_map_priv *priv = bpf_map__priv(map); - err = bpf_map__get_private(map, (void **)); - if (err) + if (IS_ERR(priv)) return -BPF_LOADER_ERRNO__INTERNAL; /* @@ -1520,10 +1516,9 @@ int bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused) } bpf__for_each_stdout_map(map, obj, tmp) { - struct bpf_map_priv *priv; + struct bpf_map_priv *priv = bpf_map__priv(map); - err = bpf_map__get_private(map, (void **)); - if (err) + if (IS_ERR(priv)) return -BPF_LOADER_ERRNO__INTERNAL; if (priv) continue;
[tip:perf/core] tools lib bpf: Rename bpf_map__get_fd() to bpf_map__fd()
Commit-ID: 6e009e65a1e5202313fdaccde3bcb94272989eba Gitweb: http://git.kernel.org/tip/6e009e65a1e5202313fdaccde3bcb94272989eba Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 3 Jun 2016 12:15:52 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 6 Jun 2016 18:19:15 -0300 tools lib bpf: Rename bpf_map__get_fd() to bpf_map__fd() For consistency, leaving "get" for reference counting. Acked-by: Wang Nan Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-msy8sxfz9th6gl2xjeci2...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 7 ++- tools/lib/bpf/libbpf.h | 2 +- tools/perf/util/bpf-loader.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 215be67..57924db 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1311,12 +1311,9 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n) return fd; } -int bpf_map__get_fd(struct bpf_map *map) +int bpf_map__fd(struct bpf_map *map) { - if (!map) - return -EINVAL; - - return map->fd; + return map ? map->fd : -EINVAL; } const struct bpf_map_def *bpf_map__def(struct bpf_map *map) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index bad5bac..cb838d0 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -180,7 +180,7 @@ bpf_map__next(struct bpf_map *map, struct bpf_object *obj); (pos) != NULL; \ (pos) = bpf_map__next((pos), (obj))) -int bpf_map__get_fd(struct bpf_map *map); +int bpf_map__fd(struct bpf_map *map); const struct bpf_map_def *bpf_map__def(struct bpf_map *map); const char *bpf_map__name(struct bpf_map *map); diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 73c1e7c..12e6ef4 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -1270,7 +1270,7 @@ bpf_map_config_foreach_key(struct bpf_map *map, pr_debug("ERROR: failed to get definition from map %s\n", name); return -BPF_LOADER_ERRNO__INTERNAL; } - map_fd = bpf_map__get_fd(map); + map_fd = bpf_map__fd(map); if (map_fd < 0) { pr_debug("ERROR: failed to get fd from map %s\n", name); return map_fd;
[tip:perf/core] perf core: Per event callchain limit
Commit-ID: 97c79a38cd454602645f0470ffb444b3b75ce574 Gitweb: http://git.kernel.org/tip/97c79a38cd454602645f0470ffb444b3b75ce574 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 28 Apr 2016 13:16:33 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 30 May 2016 12:41:44 -0300 perf core: Per event callchain limit Additionally to being able to control the system wide maximum depth via /proc/sys/kernel/perf_event_max_stack, now we are able to ask for different depths per event, using perf_event_attr.sample_max_stack for that. This uses an u16 hole at the end of perf_event_attr, that, when perf_event_attr.sample_type has the PERF_SAMPLE_CALLCHAIN, if sample_max_stack is zero, means use perf_event_max_stack, otherwise it'll be bounds checked under callchain_mutex. Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: David Ahern Cc: Frederic Weisbecker Cc: He Kuang Cc: Jiri Olsa Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Milian Wolff Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: Wang Nan Cc: Zefan Li Link: http://lkml.kernel.org/n/tip-kolmn1yo40p7jhswxwrc7...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- include/linux/perf_event.h | 2 +- include/uapi/linux/perf_event.h | 6 +- kernel/bpf/stackmap.c | 2 +- kernel/events/callchain.c | 14 -- kernel/events/core.c| 5 - 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 6b87be9..0e43355 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1076,7 +1076,7 @@ extern void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct extern struct perf_callchain_entry * get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, u32 max_stack, bool crosstask, bool add_mark); -extern int get_callchain_buffers(void); +extern int get_callchain_buffers(int max_stack); extern void put_callchain_buffers(void); extern int sysctl_perf_event_max_stack; diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 36ce552..c66a485 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -276,6 +276,9 @@ enum perf_event_read_format { /* * Hardware event_id to monitor via a performance monitoring event: + * + * @sample_max_stack: Max number of frame pointers in a callchain, + * should be < /proc/sys/kernel/perf_event_max_stack */ struct perf_event_attr { @@ -385,7 +388,8 @@ struct perf_event_attr { * Wakeup watermark for AUX area */ __u32 aux_watermark; - __u32 __reserved_2; /* align to __u64 */ + __u16 sample_max_stack; + __u16 __reserved_2; /* align to __u64 */ }; #define perf_flags(attr) (*(&(attr)->read_format + 1)) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index a82d760..f1de5c1 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -99,7 +99,7 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr) if (err) goto free_smap; - err = get_callchain_buffers(); + err = get_callchain_buffers(sysctl_perf_event_max_stack); if (err) goto free_smap; diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c index 179ef46..e9fdb52 100644 --- a/kernel/events/callchain.c +++ b/kernel/events/callchain.c @@ -104,7 +104,7 @@ fail: return -ENOMEM; } -int get_callchain_buffers(void) +int get_callchain_buffers(int event_max_stack) { int err = 0; int count; @@ -121,6 +121,15 @@ int get_callchain_buffers(void) /* If the allocation failed, give up */ if (!callchain_cpus_entries) err = -ENOMEM; + /* +* If requesting per event more than the global cap, +* return a different error to help userspace figure +* this out. +* +* And also do it here so that we have _mutex held. +*/ + if (event_max_stack > sysctl_perf_event_max_stack) + err = -EOVERFLOW; goto exit; } @@ -174,11 +183,12 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) bool user = !event->attr.exclude_callchain_user;
[tip:perf/core] perf evsel: Fix write_backwards fallback
Commit-ID: 7da36e94e7fad768ca8640b61ed1f49b284e1dc5 Gitweb: http://git.kernel.org/tip/7da36e94e7fad768ca8640b61ed1f49b284e1dc5 Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 20 Jun 2016 10:47:18 + Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 21 Jun 2016 13:18:35 -0300 perf evsel: Fix write_backwards fallback Commit b90dc17a5d14 "perf evsel: Add overwrite attribute and check write_backward" misunderstood the 'order' should be obeyed in __perf_evsel__open. But the way this was done for attr.write_backwards was buggy, as we need to check features in the inverse order of their introduction to the kernel, so that a newer tool checks first the newest perf_event_attr fields, detecting that the older kernel doesn't have support for them. Also, we can avoid calling sys_perf_event_open() if we have already detected the missing of write_backward. Cc: He Kuang Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: pi3or...@163.com Fixes: b90dc17a5d14 ("perf evsel: Add overwrite attribute and check write_backward") Link: http://lkml.kernel.org/r/1466419645-75551-2-git-send-email-wangn...@huawei.com Link: http://lkml.kernel.org/r/20160616214724.gi13...@kernel.org Signed-off-by: Wang Nan Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 23 ++- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9b2e3e6..1d8f2bb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1389,8 +1389,11 @@ fallback_missing_features: if (perf_missing_features.lbr_flags) evsel->attr.branch_sample_type &= ~(PERF_SAMPLE_BRANCH_NO_FLAGS | PERF_SAMPLE_BRANCH_NO_CYCLES); - if (perf_missing_features.write_backward) + if (perf_missing_features.write_backward) { + if (evsel->overwrite) + return -EINVAL; evsel->attr.write_backward = false; + } retry_sample_id: if (perf_missing_features.sample_id_all) evsel->attr.sample_id_all = 0; @@ -1453,12 +1456,6 @@ retry_open: err = -EINVAL; goto out_close; } - - if (evsel->overwrite && - perf_missing_features.write_backward) { - err = -EINVAL; - goto out_close; - } } } @@ -1496,7 +1493,10 @@ try_fallback: * Must probe features in the order they were added to the * perf_event_attr interface. */ - if (!perf_missing_features.clockid_wrong && evsel->attr.use_clockid) { + if (!perf_missing_features.write_backward && evsel->attr.write_backward) { + perf_missing_features.write_backward = true; + goto fallback_missing_features; + } else if (!perf_missing_features.clockid_wrong && evsel->attr.use_clockid) { perf_missing_features.clockid_wrong = true; goto fallback_missing_features; } else if (!perf_missing_features.clockid && evsel->attr.use_clockid) { @@ -1521,12 +1521,7 @@ try_fallback: PERF_SAMPLE_BRANCH_NO_FLAGS))) { perf_missing_features.lbr_flags = true; goto fallback_missing_features; - } else if (!perf_missing_features.write_backward && - evsel->attr.write_backward) { - perf_missing_features.write_backward = true; - goto fallback_missing_features; } - out_close: do { while (--thread >= 0) { @@ -2409,6 +2404,8 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, "We found oprofile daemon running, please stop it and try again."); break; case EINVAL: + if (evsel->overwrite && perf_missing_features.write_backward) + return scnprintf(msg, size, "Reading from overwrite event is not supported by this kernel."); if (perf_missing_features.clockid) return scnprintf(msg, size, "clockid feature not supported."); if (perf_missing_features.clockid_wrong)
[tip:perf/core] perf tools: Remove some unused functions
Commit-ID: 814b3f5127248db90e5d9983668a44eec7b45c02 Gitweb: http://git.kernel.org/tip/814b3f5127248db90e5d9983668a44eec7b45c02 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 16 Jun 2016 17:10:46 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 21 Jun 2016 13:18:33 -0300 perf tools: Remove some unused functions Probably are there since the beginning, taken from git but never used. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-lr65jeefffjeaywoapps9...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cache.h | 4 --- tools/perf/util/config.c | 2 +- tools/perf/util/path.c | 65 +--- 3 files changed, 2 insertions(+), 69 deletions(-) diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 0d814bb..f260040 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h @@ -32,7 +32,6 @@ int perf_config_int(const char *, const char *); u64 perf_config_u64(const char *, const char *); int perf_config_bool(const char *, const char *); int config_error_nonbool(const char *); -const char *perf_config_dirname(const char *, const char *); const char *perf_etc_perfconfig(void); char *alias_lookup(const char *alias); @@ -45,9 +44,6 @@ static inline int is_absolute_path(const char *path) return path[0] == '/'; } -char *strip_path_suffix(const char *path, const char *suffix); - char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2))); -char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); #endif /* __PERF_CACHE_H */ diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 31e09a4..d15c592 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -372,7 +372,7 @@ int perf_config_bool(const char *name, const char *value) return !!perf_config_bool_or_int(name, value, ); } -const char *perf_config_dirname(const char *name, const char *value) +static const char *perf_config_dirname(const char *name, const char *value) { if (!name) return NULL; diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index 3bf6bf8..cff8bf0 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c @@ -14,14 +14,8 @@ static char bad_path[] = "/bad-path/"; /* - * Two hacks: + * One hack: */ - -static const char *get_perf_dir(void) -{ - return "."; -} - static char *get_pathname(void) { static char pathname_array[4][PATH_MAX]; @@ -54,60 +48,3 @@ char *mkpath(const char *fmt, ...) return bad_path; return cleanup_path(pathname); } - -char *perf_path(const char *fmt, ...) -{ - const char *perf_dir = get_perf_dir(); - char *pathname = get_pathname(); - va_list args; - unsigned len; - - len = strlen(perf_dir); - if (len > PATH_MAX-100) - return bad_path; - memcpy(pathname, perf_dir, len); - if (len && perf_dir[len-1] != '/') - pathname[len++] = '/'; - va_start(args, fmt); - len += vsnprintf(pathname + len, PATH_MAX - len, fmt, args); - va_end(args); - if (len >= PATH_MAX) - return bad_path; - return cleanup_path(pathname); -} - -/* strip arbitrary amount of directory separators at end of path */ -static inline int chomp_trailing_dir_sep(const char *path, int len) -{ - while (len && is_dir_sep(path[len - 1])) - len--; - return len; -} - -/* - * If path ends with suffix (complete path components), returns the - * part before suffix (sans trailing directory separators). - * Otherwise returns NULL. - */ -char *strip_path_suffix(const char *path, const char *suffix) -{ - int path_len = strlen(path), suffix_len = strlen(suffix); - - while (suffix_len) { - if (!path_len) - return NULL; - - if (is_dir_sep(path[path_len - 1])) { - if (!is_dir_sep(suffix[suffix_len - 1])) - return NULL; - path_len = chomp_trailing_dir_sep(path, path_len); - suffix_len = chomp_trailing_dir_sep(suffix, suffix_len); - } - else if (path[--path_len] != suffix[--suffix_len]) - return NULL; - } - - if (path_len && !is_dir_sep(path[path_len - 1])) - return NULL; - return strndup(path, chomp_trailing_dir_sep(path, path_len)); -}
[tip:perf/core] perf tools: Remove --perf-dir and --work-dir
Commit-ID: e861964a26b786d349add4db4825597ec65b5780 Gitweb: http://git.kernel.org/tip/e861964a26b786d349add4db4825597ec65b5780 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 16 Jun 2016 17:36:22 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 21 Jun 2016 13:18:34 -0300 perf tools: Remove --perf-dir and --work-dir Completely unused in perf, carried along all this time from the initial copy of git infrastructure, ditch'em. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-wtiln26gyqndprmkl0kds...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/perf.c | 36 tools/perf/util/cache.h | 5 - 2 files changed, 41 deletions(-) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 15982ce..634bf7c 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -139,8 +139,6 @@ struct option options[] = { OPT_ARGUMENT("html-path", "html-path"), OPT_ARGUMENT("paginate", "paginate"), OPT_ARGUMENT("no-pager", "no-pager"), - OPT_ARGUMENT("perf-dir", "perf-dir"), - OPT_ARGUMENT("work-tree", "work-tree"), OPT_ARGUMENT("debugfs-dir", "debugfs-dir"), OPT_ARGUMENT("buildid-dir", "buildid-dir"), OPT_ARGUMENT("list-cmds", "list-cmds"), @@ -200,35 +198,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) use_pager = 0; if (envchanged) *envchanged = 1; - } else if (!strcmp(cmd, "--perf-dir")) { - if (*argc < 2) { - fprintf(stderr, "No directory given for --perf-dir.\n"); - usage(perf_usage_string); - } - setenv(PERF_DIR_ENVIRONMENT, (*argv)[1], 1); - if (envchanged) - *envchanged = 1; - (*argv)++; - (*argc)--; - handled++; - } else if (!prefixcmp(cmd, CMD_PERF_DIR)) { - setenv(PERF_DIR_ENVIRONMENT, cmd + strlen(CMD_PERF_DIR), 1); - if (envchanged) - *envchanged = 1; - } else if (!strcmp(cmd, "--work-tree")) { - if (*argc < 2) { - fprintf(stderr, "No directory given for --work-tree.\n"); - usage(perf_usage_string); - } - setenv(PERF_WORK_TREE_ENVIRONMENT, (*argv)[1], 1); - if (envchanged) - *envchanged = 1; - (*argv)++; - (*argc)--; - } else if (!prefixcmp(cmd, CMD_WORK_TREE)) { - setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + strlen(CMD_WORK_TREE), 1); - if (envchanged) - *envchanged = 1; } else if (!strcmp(cmd, "--debugfs-dir")) { if (*argc < 2) { fprintf(stderr, "No directory given for --debugfs-dir.\n"); @@ -363,11 +332,6 @@ const char perf_version_string[] = PERF_VERSION; #define RUN_SETUP (1<<0) #define USE_PAGER (1<<1) -/* - * require working tree to be present -- anything uses this needs - * RUN_SETUP for reading from the configuration file. - */ -#define NEED_WORK_TREE (1<<2) static int run_builtin(struct cmd_struct *p, int argc, const char **argv) { diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index f260040..369f382 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h @@ -11,14 +11,9 @@ #include #define CMD_EXEC_PATH "--exec-path" -#define CMD_PERF_DIR "--perf-dir=" -#define CMD_WORK_TREE "--work-tree=" #define CMD_DEBUGFS_DIR "--debugfs-dir=" -#define PERF_DIR_ENVIRONMENT "PERF_DIR" -#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE" #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" -#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" #define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
[tip:perf/core] perf script stackcollapse: Remove reference to the perl interpreter
Commit-ID: dd4629d46c3121b82e6a552c94cda6dcccfc38c6 Gitweb: http://git.kernel.org/tip/dd4629d46c3121b82e6a552c94cda6dcccfc38c6 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 21 Jun 2016 17:33:20 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 22 Jun 2016 09:56:34 -0300 perf script stackcollapse: Remove reference to the perl interpreter It is ignored and this is actually a python script, not a perl one. Reported-by: Brendan Gregg Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Paolo Bonzini Link: http://lkml.kernel.org/n/tip-0w4bpbqd79v3sl34jvpr1...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/scripts/python/stackcollapse.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py index a2dfcda..5a605f7 100755 --- a/tools/perf/scripts/python/stackcollapse.py +++ b/tools/perf/scripts/python/stackcollapse.py @@ -1,5 +1,3 @@ -#!/usr/bin/perl -w -# # stackcollapse.py - format perf samples with one line per distinct call stack # # This script's output has two space-separated fields. The first is a semicolon
[tip:perf/core] perf tests time-to-tsc: No need to disable an event before deleting it
Commit-ID: 61b3f66a3f99bb8a6a5145b1c2bd7eb98bf64748 Gitweb: http://git.kernel.org/tip/61b3f66a3f99bb8a6a5145b1c2bd7eb98bf64748 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 22 Jun 2016 10:10:52 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 22 Jun 2016 10:10:52 -0300 perf tests time-to-tsc: No need to disable an event before deleting it Because at the destructor we will call close() and that will do the disable. And we destructors can accept NULL, just like free(), so no need to check it. Cc: Adrian Hunter Cc: Peter Zijlstra Cc: Jiri Olsa Link: http://lkml.kernel.org/n/tip-i98mcyfkkjh5qp62dle27...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/x86/tests/perf-time-to-tsc.c | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c b/tools/perf/arch/x86/tests/perf-time-to-tsc.c index d4aa567..5c76cc8 100644 --- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c +++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c @@ -154,10 +154,6 @@ next_event: err = 0; out_err: - if (evlist) { - perf_evlist__disable(evlist); - perf_evlist__delete(evlist); - } - + perf_evlist__delete(evlist); return err; }
[tip:perf/core] perf session: Destructors should accept NULL
Commit-ID: e1446551e60a7773c3acf3c55bb9449d70127882 Gitweb: http://git.kernel.org/tip/e1446551e60a7773c3acf3c55bb9449d70127882 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 22 Jun 2016 10:02:16 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 22 Jun 2016 10:02:16 -0300 perf session: Destructors should accept NULL And do nothing, just like free(), to avoid having to test it in callers, usually in error paths. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-dyuupcj0hnoyt96vma8b3...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-buildid-cache.c | 3 +-- tools/perf/builtin-diff.c | 4 +--- tools/perf/builtin-kvm.c | 3 +-- tools/perf/util/session.c | 2 ++ 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index d75bded..2cbec65 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -419,8 +419,7 @@ int cmd_buildid_cache(int argc, const char **argv, pr_warning("Couldn't add %s\n", kcore_filename); out: - if (session) - perf_session__delete(session); + perf_session__delete(session); return ret; } diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 8b6735f..eac0b11 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -756,9 +756,7 @@ static int __cmd_diff(void) out_delete: data__for_each_file(i, d) { - if (d->session) - perf_session__delete(d->session); - + perf_session__delete(d->session); data__free(d); } diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index ad46e91..8f8f90e 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1426,8 +1426,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, err = kvm_events_live_report(kvm); out: - if (kvm->session) - perf_session__delete(kvm->session); + perf_session__delete(kvm->session); kvm->session = NULL; perf_evlist__delete(kvm->evlist); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index dfedf09..43be0c5 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -178,6 +178,8 @@ static void perf_session__delete_threads(struct perf_session *session) void perf_session__delete(struct perf_session *session) { + if (session == NULL) + return; auxtrace__free(session); auxtrace_index__free(>auxtrace_index); perf_session__destroy_kernel_maps(session);
[tip:perf/core] perf machine: Destructors should accept NULL
Commit-ID: 32ca678dcd250f05183cf0c8a9e516545c6068bc Gitweb: http://git.kernel.org/tip/32ca678dcd250f05183cf0c8a9e516545c6068bc Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 22 Jun 2016 10:19:11 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 22 Jun 2016 10:19:11 -0300 perf machine: Destructors should accept NULL And do nothing, just like free(), to avoid having to test it in callers, usually in error paths. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-q42gj3b3znhho9z1mrbo4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 6 -- tools/perf/util/probe-event.c | 6 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index a0c186a..bc2cdbd 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -138,8 +138,10 @@ void machine__exit(struct machine *machine) void machine__delete(struct machine *machine) { - machine__exit(machine); - free(machine); + if (machine) { + machine__exit(machine); + free(machine); + } } void machines__init(struct machines *machines) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 084756c..caad19d 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -102,10 +102,8 @@ out: void exit_probe_symbol_maps(void) { - if (host_machine) { - machine__delete(host_machine); - host_machine = NULL; - } + machine__delete(host_machine); + host_machine = NULL; symbol__exit(); }
[tip:perf/core] perf evlist: Rename for_each() macros to for_each_entry()
Commit-ID: e5cadb93d0839d268a7c4199e0fdef0f94722117 Gitweb: http://git.kernel.org/tip/e5cadb93d0839d268a7c4199e0fdef0f94722117 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 23 Jun 2016 11:26:15 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 23 Jun 2016 11:26:15 -0300 perf evlist: Rename for_each() macros to for_each_entry() To match the semantics for list.h in the kernel, that are used to implement those macros. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Taeung Song Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-qbcjlgj0ffxquxscahbpd...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/x86/util/auxtrace.c | 2 +- tools/perf/arch/x86/util/intel-bts.c| 8 ++--- tools/perf/arch/x86/util/intel-pt.c | 10 +++--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-diff.c | 6 ++-- tools/perf/builtin-evlist.c | 2 +- tools/perf/builtin-inject.c | 8 ++--- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c| 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 10 +++--- tools/perf/builtin-script.c | 12 +++ tools/perf/builtin-stat.c | 22 ++--- tools/perf/builtin-top.c| 8 ++--- tools/perf/builtin-trace.c | 4 +-- tools/perf/tests/backward-ring-buffer.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 2 +- tools/perf/tests/hists_filter.c | 4 +-- tools/perf/tests/hists_link.c | 4 +-- tools/perf/tests/mmap-basic.c | 2 +- tools/perf/tests/parse-events.c | 4 +-- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/ui/browsers/hists.c | 4 +-- tools/perf/ui/gtk/hists.c | 2 +- tools/perf/ui/hist.c| 2 +- tools/perf/util/cgroup.c| 4 +-- tools/perf/util/data-convert-bt.c | 4 +-- tools/perf/util/evlist.c| 56 - tools/perf/util/evlist.h| 40 +++ tools/perf/util/header.c| 18 +-- tools/perf/util/hist.c | 2 +- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 20 ++-- tools/perf/util/jitdump.c | 2 +- tools/perf/util/parse-events.c | 4 +-- tools/perf/util/python.c| 2 +- tools/perf/util/record.c| 8 ++--- tools/perf/util/session.c | 10 +++--- tools/perf/util/sort.c | 8 ++--- tools/perf/util/stat.c | 6 ++-- 40 files changed, 157 insertions(+), 157 deletions(-) diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util/auxtrace.c index 7a78055..cc1d865 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -37,7 +37,7 @@ struct auxtrace_record *auxtrace_record__init_intel(struct perf_evlist *evlist, intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME); if (evlist) { - evlist__for_each(evlist, evsel) { + evlist__for_each_entry(evlist, evsel) { if (intel_pt_pmu && evsel->attr.type == intel_pt_pmu->type) found_pt = true; diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c index 7dc3063..5132775 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -124,7 +124,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, btsr->evlist = evlist; btsr->snapshot_mode = opts->auxtrace_snapshot_mode; - evlist__for_each(evlist, evsel) { + evlist__for_each_entry(evlist, evsel) { if (evsel->attr.type == intel_bts_pmu->type) { if (intel_bts_evsel) { pr_err("There may be only one " INTEL_BTS_PMU_NAME " event\n"); @@ -327,7 +327,7 @@ static int intel_bts_snapshot_start(struct auxtrace_record *itr) container_of(itr, struct intel_bts_recording, itr); struct perf_evsel *evsel; - evlist__for_each(btsr->evlist, evsel) { + evlist__for_each_entry(btsr->evlist, evsel) { if (evsel->attr.type == btsr->intel_bts_pmu->type) return perf_evsel__disable(evsel); } @@ -340,7 +340,7 @@ static int intel_bts_snapshot_finish(struct auxtrace_record *itr) container_of(itr, struct intel_bts_recording, itr); struct perf_evsel
[tip:perf/core] perf tools: Rename strlist_for_each() macros to for_each_entry()
Commit-ID: 602a1f4daa5d107e890fd4f5f558dedf6a0874f3 Gitweb: http://git.kernel.org/tip/602a1f4daa5d107e890fd4f5f558dedf6a0874f3 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 23 Jun 2016 11:31:20 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 23 Jun 2016 11:35:01 -0300 perf tools: Rename strlist_for_each() macros to for_each_entry() To match the semantics for list.h in the kernel, that are the interface we use in them. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Taeung Song Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-0b5i2ki9c3di6706fxpti...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-buildid-cache.c | 10 +- tools/perf/builtin-probe.c | 4 ++-- tools/perf/builtin-trace.c | 2 +- tools/perf/util/probe-event.c | 4 ++-- tools/perf/util/probe-file.c | 8 tools/perf/util/strlist.h | 4 ++-- tools/perf/util/symbol.c | 2 +- tools/perf/util/thread_map.c | 4 ++-- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 2cbec65..76a4d03 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -209,7 +209,7 @@ static int build_id_cache__purge_path(const char *pathname) if (err) goto out; - strlist__for_each(pos, list) { + strlist__for_each_entry(pos, list) { err = build_id_cache__remove_s(pos->s); pr_debug("Removing %s %s: %s\n", pos->s, pathname, err ? "FAIL" : "Ok"); @@ -343,7 +343,7 @@ int cmd_buildid_cache(int argc, const char **argv, if (add_name_list_str) { list = strlist__new(add_name_list_str, NULL); if (list) { - strlist__for_each(pos, list) + strlist__for_each_entry(pos, list) if (build_id_cache__add_file(pos->s)) { if (errno == EEXIST) { pr_debug("%s already in the cache\n", @@ -361,7 +361,7 @@ int cmd_buildid_cache(int argc, const char **argv, if (remove_name_list_str) { list = strlist__new(remove_name_list_str, NULL); if (list) { - strlist__for_each(pos, list) + strlist__for_each_entry(pos, list) if (build_id_cache__remove_file(pos->s)) { if (errno == ENOENT) { pr_debug("%s wasn't in the cache\n", @@ -379,7 +379,7 @@ int cmd_buildid_cache(int argc, const char **argv, if (purge_name_list_str) { list = strlist__new(purge_name_list_str, NULL); if (list) { - strlist__for_each(pos, list) + strlist__for_each_entry(pos, list) if (build_id_cache__purge_path(pos->s)) { if (errno == ENOENT) { pr_debug("%s wasn't in the cache\n", @@ -400,7 +400,7 @@ int cmd_buildid_cache(int argc, const char **argv, if (update_name_list_str) { list = strlist__new(update_name_list_str, NULL); if (list) { - strlist__for_each(pos, list) + strlist__for_each_entry(pos, list) if (build_id_cache__update_file(pos->s)) { if (errno == ENOENT) { pr_debug("%s wasn't in the cache\n", diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 6d7ab431..3426232 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -389,7 +389,7 @@ static int perf_del_probe_events(struct strfilter *filter) ret = probe_file__get_events(kfd, filter, klist); if (ret == 0) { - strlist__for_each(ent, klist) + strlist__for_each_entry(ent, klist) pr_info("Removed event: %s\n", ent->s); ret = probe_file__del_strlist(kfd, klist); @@ -399,7 +399,7 @@ static int perf_del_probe_events(struct strfilter *filter) ret2 = probe_file__get_events(ufd, filter, ulist); if (ret2 == 0) { - strlist__for_each(ent, ulist) + strlist__for_each_entry(ent, ulist) pr_info("Removed event: %s\n", ent->s); ret2 = probe_file__del_strlist(ufd, ulist); diff --git
[tip:perf/core] perf rb_resort: Rename for_each() macros to for_each_entry()
Commit-ID: 98a91837dd1751e730f8265129b376450f41dcfd Gitweb: http://git.kernel.org/tip/98a91837dd1751e730f8265129b376450f41dcfd Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 23 Jun 2016 11:34:10 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 23 Jun 2016 11:35:07 -0300 perf rb_resort: Rename for_each() macros to for_each_entry() To match the semantics for list.h in the kernel, that are the interface we use in them. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Taeung Song Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-iaxuq2yu43mtb504j96q0...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 4 ++-- tools/perf/util/rb_resort.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1ba1341..cf90de8 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2550,7 +2550,7 @@ static size_t thread__dump_stats(struct thread_trace *ttrace, printed += fprintf(fp, " (msec)(msec) (msec)(msec)(%%)\n"); printed += fprintf(fp, " --- - - - - --\n"); - resort_rb__for_each(nd, syscall_stats) { + resort_rb__for_each_entry(nd, syscall_stats) { struct stats *stats = syscall_stats_entry->stats; if (stats) { double min = (double)(stats->min) / NSEC_PER_MSEC; @@ -2627,7 +2627,7 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) return 0; } - resort_rb__for_each(nd, threads) + resort_rb__for_each_entry(nd, threads) printed += trace__fprintf_thread(fp, threads_entry->thread, trace); resort_rb__delete(threads); diff --git a/tools/perf/util/rb_resort.h b/tools/perf/util/rb_resort.h index abc76e3..808cc45 100644 --- a/tools/perf/util/rb_resort.h +++ b/tools/perf/util/rb_resort.h @@ -35,7 +35,7 @@ DEFINE_RB_RESORT_RB(threads, strcmp(a->thread->shortname, struct rb_node *nd; - resort_rb__for_each(nd, threads) { + resort_rb__for_each_entry(nd, threads) { struct thread *t = threads_entry; printf("%s: %d\n", t->shortname, t->tid); } @@ -123,7 +123,7 @@ static void __name##_sorted__init_entry(struct rb_node *nd, \ struct __name##_sorted_entry *__name##_entry; \ struct __name##_sorted *__name = __name##_sorted__new -#define resort_rb__for_each(__nd, __name) \ +#define resort_rb__for_each_entry(__nd, __name) \ for (__nd = rb_first(&__name->entries); \ __name##_entry = rb_entry(__nd, struct __name##_sorted_entry, \ rb_node), __nd; \
[tip:perf/core] perf intlist: Rename for_each() macros to for_each_entry()
Commit-ID: 10daf4d01bad77c6ae862367ad2148a8340d94e6 Gitweb: http://git.kernel.org/tip/10daf4d01bad77c6ae862367ad2148a8340d94e6 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 23 Jun 2016 11:39:19 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 23 Jun 2016 11:39:19 -0300 perf intlist: Rename for_each() macros to for_each_entry() To match the semantics for list.h in the kernel, that are the interface we use in them. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Taeung Song Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-mdp1heu9xjjc12zebh912...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/intlist.h | 8 tools/perf/util/probe-event.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/intlist.h b/tools/perf/util/intlist.h index aa6877d..020b9ca 100644 --- a/tools/perf/util/intlist.h +++ b/tools/perf/util/intlist.h @@ -57,21 +57,21 @@ static inline struct int_node *intlist__next(struct int_node *in) } /** - * intlist_for_each - iterate over a intlist + * intlist__for_each_entry - iterate over a intlist * @pos: the int_node to use as a loop cursor. * @ilist: the intlist for loop. */ -#define intlist__for_each(pos, ilist) \ +#define intlist__for_each_entry(pos, ilist)\ for (pos = intlist__first(ilist); pos; pos = intlist__next(pos)) /** - * intlist_for_each_safe - iterate over a intlist safe against removal of + * intlist__for_each_entry_safe - iterate over a intlist safe against removal of * int_node * @pos: the int_node to use as a loop cursor. * @n: another int_node to use as temporary storage. * @ilist: the intlist for loop. */ -#define intlist__for_each_safe(pos, n, ilist) \ +#define intlist__for_each_entry_safe(pos, n, ilist)\ for (pos = intlist__first(ilist), n = intlist__next(pos); pos;\ pos = n, n = intlist__next(n)) #endif /* __PERF_INTLIST_H */ diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 4f7b3e5..55f41d5 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -896,7 +896,7 @@ static int __show_line_range(struct line_range *lr, const char *module, goto end; } - intlist__for_each(ln, lr->line_list) { + intlist__for_each_entry(ln, lr->line_list) { for (; ln->i > l; l++) { ret = show_one_line(fp, l - lr->offset); if (ret < 0)
[tip:perf/core] perf evlist: Destructors should accept NULL
Commit-ID: 0b04b3dcdfb9aeb0e83c8ca322bf0830ee51ce38 Gitweb: http://git.kernel.org/tip/0b04b3dcdfb9aeb0e83c8ca322bf0830ee51ce38 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 21 Jun 2016 18:15:45 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 22 Jun 2016 10:01:48 -0300 perf evlist: Destructors should accept NULL And do nothing, just like free(), to avoid having to test it in callers, usually in error paths. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-mexbavy0ft387j5w89t36...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-kvm.c | 3 +-- tools/perf/tests/event-times.c| 3 +-- tools/perf/tests/parse-no-sample-id-all.c | 3 +-- tools/perf/util/evlist.c | 3 +++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 6487c06..ad46e91 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1429,8 +1429,7 @@ out: if (kvm->session) perf_session__delete(kvm->session); kvm->session = NULL; - if (kvm->evlist) - perf_evlist__delete(kvm->evlist); + perf_evlist__delete(kvm->evlist); return err; } diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c index 95fb744..9f5698a 100644 --- a/tools/perf/tests/event-times.c +++ b/tools/perf/tests/event-times.c @@ -200,8 +200,7 @@ static int test_times(int (attach)(struct perf_evlist *), count.ena, count.run); out_err: - if (evlist) - perf_evlist__delete(evlist); + perf_evlist__delete(evlist); return !err ? TEST_OK : TEST_FAIL; } diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c index 294c76b..81c6eea 100644 --- a/tools/perf/tests/parse-no-sample-id-all.c +++ b/tools/perf/tests/parse-no-sample-id-all.c @@ -44,8 +44,7 @@ static int process_events(union perf_event **events, size_t count) for (i = 0; i < count && !err; i++) err = process_event(, events[i]); - if (evlist) - perf_evlist__delete(evlist); + perf_evlist__delete(evlist); return err; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 1b918aa..fcb8f1f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -127,6 +127,9 @@ void perf_evlist__exit(struct perf_evlist *evlist) void perf_evlist__delete(struct perf_evlist *evlist) { + if (evlist == NULL) + return; + perf_evlist__munmap(evlist); perf_evlist__close(evlist); cpu_map__put(evlist->cpus);
[tip:perf/core] perf top: Move UI initialization ahead of sort setup
Commit-ID: 3ee60c3b18bd4bf30ea9b70e7542116bb5c205ba Gitweb: http://git.kernel.org/tip/3ee60c3b18bd4bf30ea9b70e7542116bb5c205ba Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 18 Jan 2016 10:24:06 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 3 Feb 2016 12:24:03 -0300 perf top: Move UI initialization ahead of sort setup The ui initialization changes hpp format callbacks, based on the used browser. Thus we need this init being processed before setup_sorting. Replica of a patch by Jiri for 'perf report'. Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1453109064-1026-9-git-send-email-jo...@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-top.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index f1bbe2a..a75de39 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1245,6 +1245,13 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) /* display thread wants entries to be collapsed in a different tree */ sort__need_collapse = 1; + if (top.use_stdio) + use_browser = 0; + else if (top.use_tui) + use_browser = 1; + + setup_browser(false); + if (setup_sorting(top.evlist) < 0) { if (sort_order) parse_options_usage(top_usage, options, "s", 1); @@ -1254,13 +1261,6 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) goto out_delete_evlist; } - if (top.use_stdio) - use_browser = 0; - else if (top.use_tui) - use_browser = 1; - - setup_browser(false); - status = target__validate(target); if (status) { target__strerror(target, status, errbuf, BUFSIZ);
[tip:perf/core] perf build tests: Elide "-f Makefile" from make invokation
Commit-ID: 5978531b296ab7e61abef43f2a1a2d9b92246de1 Gitweb: http://git.kernel.org/tip/5978531b296ab7e61abef43f2a1a2d9b92246de1 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 3 Feb 2016 17:16:32 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 4 Feb 2016 11:27:50 -0300 perf build tests: Elide "-f Makefile" from make invokation Since this is the name that 'make' will look for if no explicit -f file is passed. This in turn makes the output of 'build-test' more compact: Before: $ perf stat make -C tools/perf build-test cd . && make FEATURE_DUMP_COPY=/home/acme/git/linux/tools/perf/BUILD_TEST_FEATURE_DUMP feature-dump make_no_libaudit_O: cd . && make -f Makefile O=/tmp/tmp.tHIa0Kkk2Y DESTDIR=/tmp/tmp.foK7rckkVi NO_LIBAUDIT=1 FEATURES_DUMP=/home/acme/git/linux/tools/perf/BUILD_TEST_FEATURE_DUMP After: $ perf stat make -C tools/perf build-test make_no_libaudit_O: cd . && make O=/tmp/tmp.tHIa0Kkk2Y DESTDIR=/tmp/tmp.foK7rckkVi NO_LIBAUDIT=1 FEATURES_DUMP=/home/acme/git/linux/tools/perf/BUILD_TEST_FEATURE_DUMP Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-m440lb8dkfsywsyah0hti...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/make | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/make b/tools/perf/tests/make index cc72b67..0b70cf1 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make @@ -111,6 +111,9 @@ run := make_pure # disable features detection ifeq ($(MK),Makefile) run += make_clean_all +MAKE_F := $(MAKE) +else +MAKE_F := $(MAKE) -f $(MK) endif run += make_python_perf_so run += make_debug @@ -270,12 +273,12 @@ endif MAKEFLAGS := --no-print-directory -clean := @(cd $(PERF); make -s -f $(MK) $(O_OPT) clean >/dev/null) +clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null) $(run): $(call clean) @TMP_DEST=$$(mktemp -d); \ - cmd="cd $(PERF) && make -f $(MK) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST $($@)"; \ + cmd="cd $(PERF) && $(MAKE_F) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST $($@)"; \ printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ ( eval $$cmd ) >> $@ 2>&1; \ echo " test: $(call test,$@)" >> $@ 2>&1; \ @@ -286,7 +289,7 @@ $(run_O): $(call clean) @TMP_O=$$(mktemp -d); \ TMP_DEST=$$(mktemp -d); \ - cmd="cd $(PERF) && make -f $(MK) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST $($(patsubst %_O,%,$@))"; \ + cmd="cd $(PERF) && $(MAKE_F) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST $($(patsubst %_O,%,$@))"; \ printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ ( eval $$cmd ) >> $@ 2>&1 && \ echo " test: $(call test_O,$@)" >> $@ 2>&1; \
[tip:perf/core] perf build tests: Move the feature related vars to the front of the make cmdline
Commit-ID: 3c7a152b0d1c81b9bac5ab922dc57168046668bf Gitweb: http://git.kernel.org/tip/3c7a152b0d1c81b9bac5ab922dc57168046668bf Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 3 Feb 2016 17:24:11 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 4 Feb 2016 11:27:51 -0300 perf build tests: Move the feature related vars to the front of the make cmdline So that we do less visual searching on the 'make build-test' output to see the feature related variables: After: $ make -C tools/perf build-test make_no_newt_O: cd . && make NO_NEWT=1 FEATURES_DUMP=/home/acme/git/linux/tools/perf/BUILD_TEST_FEATURE_DUMP O=/tmp/tmp.dz55IX DESTDIR=/tmp/tmp.X29xxo make_tags_O: cd . && make tags FEATURES_DUMP=/home/acme/git/linux/tools/perf/BUILD_TEST_FEATURE_DUMP O=/tmp/tmp.6ecLh8 DESTDIR=/tmp/tmp.6vIla578Ho make_util_pmu_bison_o_O: cd . && make util/pmu-bison.o FEATURES_DUMP=/home/acme/git/linux/tools/perf/BUILD_TEST_FEATURE_DUMP O=/tmp/tmp.SVPM2G DESTDIR=/tmp/tmp.C0oAam Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-dx4krgzqa566v1pedrbrc...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/make b/tools/perf/tests/make index 0b70cf1..12dcae7 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make @@ -278,7 +278,7 @@ clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null) $(run): $(call clean) @TMP_DEST=$$(mktemp -d); \ - cmd="cd $(PERF) && $(MAKE_F) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST $($@)"; \ + cmd="cd $(PERF) && $(MAKE_F) $($@) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST"; \ printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ ( eval $$cmd ) >> $@ 2>&1; \ echo " test: $(call test,$@)" >> $@ 2>&1; \ @@ -289,7 +289,7 @@ $(run_O): $(call clean) @TMP_O=$$(mktemp -d); \ TMP_DEST=$$(mktemp -d); \ - cmd="cd $(PERF) && $(MAKE_F) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST $($(patsubst %_O,%,$@))"; \ + cmd="cd $(PERF) && $(MAKE_F) $($(patsubst %_O,%,$@)) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST"; \ printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ ( eval $$cmd ) >> $@ 2>&1 && \ echo " test: $(call test_O,$@)" >> $@ 2>&1; \
[tip:perf/core] perf inject: Make sure mmap records are ordered when injecting build_ids
Commit-ID: 921f3fadbc48c7c3799b415b895297cd476cf7f1 Gitweb: http://git.kernel.org/tip/921f3fadbc48c7c3799b415b895297cd476cf7f1 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 22 Jan 2016 18:41:00 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 5 Feb 2016 09:46:45 -0300 perf inject: Make sure mmap records are ordered when injecting build_ids To make sure the mmap records are ordered correctly and so that the correct especially due to jitted code mmaps. We cannot generate the buildid hit list and inject the jit mmaps (will come right after this patch) in at the same time for now. Signed-off-by: Stephane Eranian Cc: Adrian Hunter Cc: Andi Kleen Cc: Carl Love Cc: David Ahern Cc: Jiri Olsa Cc: John McCutchan Cc: Namhyung Kim Cc: Pawel Moll Cc: Peter Zijlstra Cc: Sonny Rao Cc: Sukadev Bhattiprolu Link: http://lkml.kernel.org/r/1448874143-7269-3-git-send-email-eran...@google.com [ Carved out from a larger patch ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-inject.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 0022e02..6567bae 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -755,6 +755,17 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) if (inject.session == NULL) return -1; + if (inject.build_ids) { + /* +* to make sure the mmap records are ordered correctly +* and so that the correct especially due to jitted code +* mmaps. We cannot generate the buildid hit list and +* inject the jit mmaps at the same time for now. +*/ + inject.tool.ordered_events = true; + inject.tool.ordering_requires_timestamps = true; + } + ret = symbol__init(>header.env); if (ret < 0) goto out_delete;
[tip:perf/core] perf build tests: Do parallell builds with ' build-test'
Commit-ID: be9e49911123516ef883836906269832aec37e01 Gitweb: http://git.kernel.org/tip/be9e49911123516ef883836906269832aec37e01 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 3 Feb 2016 17:28:45 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 4 Feb 2016 15:57:00 -0300 perf build tests: Do parallell builds with 'build-test' Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-jhmnf9g7y9ryqcjql00un...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 67837c6..32a64e6 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -99,7 +99,7 @@ clean: # make -C tools/perf -f tests/make # build-test: - @$(MAKE) SHUF=1 -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile --no-print-directory tarpkg out + @$(MAKE) SHUF=1 -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile SET_PARALLEL=1 --no-print-directory tarpkg out # # All other targets get passed through:
[tip:perf/core] perf tools: Speed up build-tests by reducing the number of builds tested
Commit-ID: a639a623904cc526cebd7679debf86e5c8e5590b Gitweb: http://git.kernel.org/tip/a639a623904cc526cebd7679debf86e5c8e5590b Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 29 Jan 2016 14:49:31 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 29 Jan 2016 16:57:38 -0300 perf tools: Speed up build-tests by reducing the number of builds tested The 'tools/perf/test/make' makefile has in its default, 'all' target builds that will pollute the source code directory, i.e. that will not use O= variable. The 'build-test' should be run as often as possible, preferrably after each non strictly non-code commit, so speed it up by selecting just the O= targets. Furthermore it tests both the Makefile.perf file, that is normally driven by the main Makefile, and the Makefile, reduce the time in half by having just MK=Makefile, the most usual, tested by 'build-test'. Please run: make -C tools/perf -f tests/make from time to time for testing also the in-place build tests. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-jrt9utscsiqkmjy3ccufo...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/perf/Makefile b/tools/perf/Makefile index e4ff0bd..4b68f46 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -75,10 +75,17 @@ clean: $(make) # -# The build-test target is not really parallel, don't print the jobs info: +# The build-test target is not really parallel, don't print the jobs info, +# it also uses only the tests/make targets that don't pollute the source +# repository, i.e. that uses O= or builds the tarpkg outside the source +# repo directories. +# +# For a full test, use: +# +# make -C tools/perf -f tests/make # build-test: - @$(MAKE) SHUF=1 -f tests/make REUSE_FEATURES_DUMP=1 --no-print-directory + @$(MAKE) SHUF=1 -f tests/make REUSE_FEATURES_DUMP=1 MK=Makefile --no-print-directory tarpkg out # # All other targets get passed through:
[tip:perf/core] perf test: Fixup aliases checking in the ' vmlinux matches kallsyms' test
Commit-ID: ab414dcda8fa307388c40a540b35e3c98a9da5ae Gitweb: http://git.kernel.org/tip/ab414dcda8fa307388c40a540b35e3c98a9da5ae Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 25 Jan 2016 18:04:47 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 26 Jan 2016 11:52:52 -0300 perf test: Fixup aliases checking in the 'vmlinux matches kallsyms' test There are cases where looking at just the next and prev entries is not enough, like with: $ readelf -sW /usr/lib/debug/lib/modules/4.3.3-301.fc23.x86_64/vmlinux | grep 81065ec0 4979: 81065ec0 53 FUNC LOCAL DEFAULT 1 try_to_free_pud_page 4980: 81065ec0 53 FUNC LOCAL DEFAULT 1 try_to_free_pte_page 4981: 81065ec0 53 FUNC LOCAL DEFAULT 1 try_to_free_pmd_page So just search by name to see if the symbol is in kallsyms. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-jj1vlljg7ol4i713l60rt...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/vmlinux-kallsyms.c | 24 +--- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c index f0bfc9e..630b0b4 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -110,7 +110,6 @@ int test__vmlinux_matches_kallsyms(int subtest __maybe_unused) */ for (nd = rb_first(_map->dso->symbols[type]); nd; nd = rb_next(nd)) { struct symbol *pair, *first_pair; - bool backwards = true; sym = rb_entry(nd, struct symbol, rb_node); @@ -151,27 +150,14 @@ next_pair: continue; } else { - struct rb_node *nnd; -detour: - nnd = backwards ? rb_prev(>rb_node) : - rb_next(>rb_node); - if (nnd) { - struct symbol *next = rb_entry(nnd, struct symbol, rb_node); - - if (UM(next->start) == mem_start) { - pair = next; + pair = machine__find_kernel_symbol_by_name(, type, sym->name, NULL, NULL); + if (pair) { + if (UM(pair->start) == mem_start) goto next_pair; - } - } - if (backwards) { - backwards = false; - pair = first_pair; - goto detour; + pr_debug("%#" PRIx64 ": diff name v: %s k: %s\n", +mem_start, sym->name, pair->name); } - - pr_debug("%#" PRIx64 ": diff name v: %s k: %s\n", -mem_start, sym->name, pair->name); } } else pr_debug("%#" PRIx64 ": %s not on kallsyms\n",
[tip:perf/core] perf cpumap: Auto initialize cpu__max_{node,cpu}
Commit-ID: 5ac76283b32b116c58e362e99542182ddcfc8262 Gitweb: http://git.kernel.org/tip/5ac76283b32b116c58e362e99542182ddcfc8262 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 26 Jan 2016 15:51:46 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 26 Jan 2016 16:08:36 -0300 perf cpumap: Auto initialize cpu__max_{node,cpu} Since it was always checking if the initialization was done, use that branch to do the initialization if not done already. With this we reduce the number of exported globals from these files. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Kan Liang Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/r/20160125212955.gg22...@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cpumap.c | 30 ++ tools/perf/util/cpumap.h | 32 +++- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index fa93509..9bcf2be 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -8,6 +8,10 @@ #include #include "asm/bug.h" +static int max_cpu_num; +static int max_node_num; +static int *cpunode_map; + static struct cpu_map *cpu_map__default_new(void) { struct cpu_map *cpus; @@ -486,6 +490,32 @@ out: pr_err("Failed to read max nodes, using default of %d\n", max_node_num); } +int cpu__max_node(void) +{ + if (unlikely(!max_node_num)) + set_max_node_num(); + + return max_node_num; +} + +int cpu__max_cpu(void) +{ + if (unlikely(!max_cpu_num)) + set_max_cpu_num(); + + return max_cpu_num; +} + +int cpu__get_node(int cpu) +{ + if (unlikely(cpunode_map == NULL)) { + pr_debug("cpu_map not initialized\n"); + return -1; + } + + return cpunode_map[cpu]; +} + static int init_cpunode_map(void) { int i; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 71c41b9..81a2562 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -57,37 +57,11 @@ static inline bool cpu_map__empty(const struct cpu_map *map) return map ? map->map[0] == -1 : true; } -int max_cpu_num; -int max_node_num; -int *cpunode_map; - int cpu__setup_cpunode_map(void); -static inline int cpu__max_node(void) -{ - if (unlikely(!max_node_num)) - pr_debug("cpu_map not initialized\n"); - - return max_node_num; -} - -static inline int cpu__max_cpu(void) -{ - if (unlikely(!max_cpu_num)) - pr_debug("cpu_map not initialized\n"); - - return max_cpu_num; -} - -static inline int cpu__get_node(int cpu) -{ - if (unlikely(cpunode_map == NULL)) { - pr_debug("cpu_map not initialized\n"); - return -1; - } - - return cpunode_map[cpu]; -} +int cpu__max_node(void); +int cpu__max_cpu(void); +int cpu__get_node(int cpu); int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, int (*f)(struct cpu_map *map, int cpu, void *data),
[tip:perf/core] perf machine: Introduce machine__find_kernel_symbol_by_name()
Commit-ID: 8acd3da03c3f6e4e31472c5c73402b95a5d0f6cb Gitweb: http://git.kernel.org/tip/8acd3da03c3f6e4e31472c5c73402b95a5d0f6cb Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 25 Jan 2016 18:01:57 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 26 Jan 2016 11:52:51 -0300 perf machine: Introduce machine__find_kernel_symbol_by_name() To be used in the 'vmlinux matches kallsyms' 'perf test' entry. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-m56g1853lz2c6nhnqxibq...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.h | 10 ++ 1 file changed, 10 insertions(+) diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 2c2b443..1a3e45b 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -180,6 +180,16 @@ struct symbol *machine__find_kernel_symbol(struct machine *machine, } static inline +struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine, + enum map_type type, const char *name, + struct map **mapp, + symbol_filter_t filter) +{ + return map_groups__find_symbol_by_name(>kmaps, type, name, + mapp, filter); +} + +static inline struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr, struct map **mapp, symbol_filter_t filter)
[tip:perf/core] perf build: Align the names of the build tests:
Commit-ID: 814568db641f6587c1e98a3a85f214cb6a30fe10 Gitweb: http://git.kernel.org/tip/814568db641f6587c1e98a3a85f214cb6a30fe10 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 29 Jan 2016 17:51:04 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 29 Jan 2016 17:51:04 -0300 perf build: Align the names of the build tests: $ make -C tools/perf build-test make[1]: Entering directory `/home/acme/git/linux/tools/perf' make_pure_O: cd . && make -f Makefile O=/tmp/tmp.mPx0Cmik3f DESTDIR=/tmp/tmp.U0SUmVbtJm make_clean_all_O: cd . && make -f Makefile O=/tmp/tmp.Yl5UzhTU7T DESTDIR=/tmp/tmp.fop1E4jdER clean all make_debug_O: cd . && make -f Makefile O=/tmp/tmp.pMn2ozBoXC DESTDIR=/tmp/tmp.azxhDp5sEp DEBUG=1 make_no_libperl_O: cd . && make -f Makefile O=/tmp/tmp.qJPiINMtA7 DESTDIR=/tmp/tmp.KNMrLeGDxZ NO_LIBPERL=1 More needs to be done to make it more compact, i.e. elide the '-f Makefile', remove that 'cd . &&', move the DESTDIR= and O= to the end, as they don't convey that much information besides the fact that they are being set to some random directory just for this build, move the meat, i.e. the meaningful feature disabling bits to the start, etc. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-wir3w3o4f1nmbgcxgnx8c...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/make | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/make b/tools/perf/tests/make index 7f663f4..cc72b67 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make @@ -261,6 +261,8 @@ run := $(shell shuf -e $(run)) run_O := $(shell shuf -e $(run_O)) endif +max_width := $(shell echo $(run_O) | sed 's/ /\n/g' | wc -L) + ifdef DEBUG d := $(info run $(run)) d := $(info run_O $(run_O)) @@ -274,7 +276,7 @@ $(run): $(call clean) @TMP_DEST=$$(mktemp -d); \ cmd="cd $(PERF) && make -f $(MK) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST $($@)"; \ - echo "- $@: $$cmd" && echo $$cmd > $@ && \ + printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ ( eval $$cmd ) >> $@ 2>&1; \ echo " test: $(call test,$@)" >> $@ 2>&1; \ $(call test,$@) && \ @@ -285,7 +287,7 @@ $(run_O): @TMP_O=$$(mktemp -d); \ TMP_DEST=$$(mktemp -d); \ cmd="cd $(PERF) && make -f $(MK) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST $($(patsubst %_O,%,$@))"; \ - echo "- $@: $$cmd" && echo $$cmd > $@ && \ + printf "%*.*s: %s\n" $(max_width) $(max_width) "$@" "$$cmd" && echo $$cmd > $@ && \ ( eval $$cmd ) >> $@ 2>&1 && \ echo " test: $(call test_O,$@)" >> $@ 2>&1; \ $(call test_O,$@) && \
[tip:perf/core] perf help: No need to use strbuf_remove()
Commit-ID: d1130686f463e6feff19196475c3c15b1923c525 Gitweb: http://git.kernel.org/tip/d1130686f463e6feff19196475c3c15b1923c525 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 23 Feb 2016 16:18:37 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 23 Feb 2016 16:18:37 -0300 perf help: No need to use strbuf_remove() It is the only user of this function, just use the strlen() to skip the prefix. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-blao710l5cd5hmwrhy51f...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-help.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 96c1a4c..f4dd2b4 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c @@ -86,8 +86,7 @@ static int check_emacsclient_version(void) return -1; } - strbuf_remove(, 0, strlen("emacsclient")); - version = atoi(buffer.buf); + version = atoi(buffer.buf + strlen("emacsclient")); if (version < 22) { fprintf(stderr,
[tip:perf/core] perf tools: Remove strbuf_{remove,splice}()
Commit-ID: bea2400621836b028d82c3d6a74053921d70dbd7 Gitweb: http://git.kernel.org/tip/bea2400621836b028d82c3d6a74053921d70dbd7 Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 23 Feb 2016 16:21:04 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 23 Feb 2016 16:21:04 -0300 perf tools: Remove strbuf_{remove,splice}() No users, nuke them. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-kfv2wo8xann8t97wdaltt...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/strbuf.c | 24 tools/perf/util/strbuf.h | 2 -- 2 files changed, 26 deletions(-) diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index 25671fa..d3d2792 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c @@ -51,30 +51,6 @@ void strbuf_grow(struct strbuf *sb, size_t extra) ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); } -static void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, - const void *data, size_t dlen) -{ - if (pos + len < pos) - die("you want to use way too much memory"); - if (pos > sb->len) - die("`pos' is too far after the end of the buffer"); - if (pos + len > sb->len) - die("`pos + len' is too far after the end of the buffer"); - - if (dlen >= len) - strbuf_grow(sb, dlen - len); - memmove(sb->buf + pos + dlen, - sb->buf + pos + len, - sb->len - pos - len); - memcpy(sb->buf + pos, data, dlen); - strbuf_setlen(sb, sb->len + dlen - len); -} - -void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) -{ - strbuf_splice(sb, pos, len, NULL, 0); -} - void strbuf_add(struct strbuf *sb, const void *data, size_t len) { strbuf_grow(sb, len); diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h index 529f2f0..7a32c83 100644 --- a/tools/perf/util/strbuf.h +++ b/tools/perf/util/strbuf.h @@ -77,8 +77,6 @@ static inline void strbuf_addch(struct strbuf *sb, int c) { sb->buf[sb->len] = '\0'; } -extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); - extern void strbuf_add(struct strbuf *, const void *, size_t); static inline void strbuf_addstr(struct strbuf *sb, const char *s) { strbuf_add(sb, s, strlen(s));
[tip:perf/core] perf tools: Use asprintf() for simple string formatting/allocation
Commit-ID: 5104ffb229c357d9672344126040721e5dc4cc7b Gitweb: http://git.kernel.org/tip/5104ffb229c357d9672344126040721e5dc4cc7b Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 25 Feb 2016 10:14:50 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 25 Feb 2016 10:14:50 -0300 perf tools: Use asprintf() for simple string formatting/allocation No need to use strbuf there, its just a simple alloc+formatting, which asprintf does just fine. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-6q6cxfhk8c8ypg3tfpo0i...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/perf.c | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 144047c..f632119 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -454,11 +454,12 @@ static void handle_internal_command(int argc, const char **argv) static void execv_dashed_external(const char **argv) { - struct strbuf cmd = STRBUF_INIT; + char *cmd; const char *tmp; int status; - strbuf_addf(, "perf-%s", argv[0]); + if (asprintf(, "perf-%s", argv[0]) < 0) + goto do_die; /* * argv[0] must be the perf command, but the argv array @@ -467,7 +468,7 @@ static void execv_dashed_external(const char **argv) * restore it on error. */ tmp = argv[0]; - argv[0] = cmd.buf; + argv[0] = cmd; /* * if we fail because the command is not found, it is @@ -475,15 +476,16 @@ static void execv_dashed_external(const char **argv) */ status = run_command_v_opt(argv, 0); if (status != -ERR_RUN_COMMAND_EXEC) { - if (IS_RUN_COMMAND_ERR(status)) + if (IS_RUN_COMMAND_ERR(status)) { +do_die: die("unable to run '%s'", argv[0]); + } exit(-status); } errno = ENOENT; /* as if we called execvp */ argv[0] = tmp; - - strbuf_release(); + zfree(); } static int run_argv(int *argcp, const char ***argv)
[tip:perf/core] perf debug: Rename __eprintf(va_list args) to veprintf
Commit-ID: bedbdd4297224efcd7d668198e32fab14b76b98b Gitweb: http://git.kernel.org/tip/bedbdd4297224efcd7d668198e32fab14b76b98b Author: Arnaldo Carvalho de MeloAuthorDate: Tue, 16 Feb 2016 11:48:38 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 16 Feb 2016 17:12:58 -0300 perf debug: Rename __eprintf(va_list args) to veprintf Adhering to the naming convention used when va_args is in a printf like function, e.g. stdio.h. Cc: Jiri Olsa Cc: Adrian Hunter Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-b5l3wt77ct28dcnriguxt...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/debug.c | 15 +-- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 86d9c73..d6c8d2b 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -22,7 +22,7 @@ int debug_ordered_events; static int redirect_to_stderr; int debug_data_convert; -static int _eprintf(int level, int var, const char *fmt, va_list args) +int veprintf(int level, int var, const char *fmt, va_list args) { int ret = 0; @@ -36,24 +36,19 @@ static int _eprintf(int level, int var, const char *fmt, va_list args) return ret; } -int veprintf(int level, int var, const char *fmt, va_list args) -{ - return _eprintf(level, var, fmt, args); -} - int eprintf(int level, int var, const char *fmt, ...) { va_list args; int ret; va_start(args, fmt); - ret = _eprintf(level, var, fmt, args); + ret = veprintf(level, var, fmt, args); va_end(args); return ret; } -static int __eprintf_time(u64 t, const char *fmt, va_list args) +static int veprintf_time(u64 t, const char *fmt, va_list args) { int ret = 0; u64 secs, usecs, nsecs = t; @@ -75,7 +70,7 @@ int eprintf_time(int level, int var, u64 t, const char *fmt, ...) if (var >= level) { va_start(args, fmt); - ret = __eprintf_time(t, fmt, args); + ret = veprintf_time(t, fmt, args); va_end(args); } @@ -91,7 +86,7 @@ void pr_stat(const char *fmt, ...) va_list args; va_start(args, fmt); - _eprintf(1, verbose, fmt, args); + veprintf(1, verbose, fmt, args); va_end(args); eprintf(1, verbose, "\n"); }
[tip:perf/core] perf evlist: Reference count the cpu and thread maps at set_maps()
Commit-ID: a55e5663761366fb883f6f25375dd68bc958b9db Gitweb: http://git.kernel.org/tip/a55e5663761366fb883f6f25375dd68bc958b9db Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 17 Feb 2016 10:57:19 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 18 Feb 2016 10:48:37 -0300 perf evlist: Reference count the cpu and thread maps at set_maps() We were dropping the reference we possibly held but not obtaining one for the new maps, which we will drop at perf_evlist__delete(), fix it. This was caught by Steven Noonan in some of the machines which would produce this output when caught by glibc debug mechanisms: $ sudo perf test 21 21: Test object code reading :*** Error in `perf': corrupted double-linked list: 0x023ffcd0 *** === Backtrace: = /usr/lib/libc.so.6(+0x72055)[0x7f25be0f3055] /usr/lib/libc.so.6(+0x779b6)[0x7f25be0f89b6] /usr/lib/libc.so.6(+0x7a0ed)[0x7f25be0fb0ed] /usr/lib/libc.so.6(__libc_calloc+0xba)[0x7f25be0fceda] perf(parse_events_lex_init_extra+0x38)[0x4cfff8] perf(parse_events+0x55)[0x4a0615] perf(perf_evlist__config+0xcf)[0x4eeb2f] perf[0x479f82] perf(test__code_reading+0x1e)[0x47ad4e] perf(cmd_test+0x5dd)[0x46452d] perf[0x47f4e3] perf(main+0x603)[0x42c723] /usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7f25be0a1610] perf(_start+0x29)[0x42c859] Further investigation using valgrind led to the reference count imbalance fixed in this patch. Reported-and-Tested-by: Steven Noonan Report-Link: http://lkml.kernel.org/r/cakbgbljc2dx5vshxygmqkcd+vwiaqlbhoxa9i7kvrb2-2op...@mail.gmail.com Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Fixes: f30a79b012e5 ("perf tools: Add reference counting for cpu_map object") Link: http://lkml.kernel.org/n/tip-j0u1bdhr47sa511sgg76k...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index d81f13d..a7eb0ea 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1181,12 +1181,12 @@ void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus, */ if (cpus != evlist->cpus) { cpu_map__put(evlist->cpus); - evlist->cpus = cpus; + evlist->cpus = cpu_map__get(cpus); } if (threads != evlist->threads) { thread_map__put(evlist->threads); - evlist->threads = threads; + evlist->threads = thread_map__get(threads); } perf_evlist__propagate_maps(evlist);
[tip:perf/core] perf evlist: Handle -EINVAL for sample_freq > max_sample_rate in strerror_open()
Commit-ID: d9aade7fd27a604bbffd363e6a68416ef51bab88 Gitweb: http://git.kernel.org/tip/d9aade7fd27a604bbffd363e6a68416ef51bab88 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 18 Feb 2016 13:34:09 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 19 Feb 2016 19:12:42 -0300 perf evlist: Handle -EINVAL for sample_freq > max_sample_rate in strerror_open() When running the "code reading" test we get: # perf test -v "code reading" 2>&1 | tail -5 Parsing event 'cycles:u' perf_evlist__open failed test child finished with -1 end Test object code reading: FAILED! # And with -vv we get the errno value, -22, i.e. -EINVAL, but we can do better and handle the case at hand, with this patch it becomes: # perf test -v "code reading" 2>&1 | tail -7 perf_evlist__open() failed! Error: Invalid argument. Hint: Check /proc/sys/kernel/perf_event_max_sample_rate. Hint: The current value is 1000 and 4000 is being requested. test child finished with -1 end Test object code reading: FAILED! # Next patch will make this 'perf test' entry to use perf_evlist__strerror() Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Steven Noonan Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-i31ai6kfefn75eapejjok...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 20 +++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index a7eb0ea..0f57716 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1624,7 +1624,7 @@ size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp) return printed + fprintf(fp, "\n"); } -int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused, +int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size) { int printed, value; @@ -1652,7 +1652,25 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused, "Hint:\tTry: 'sudo sh -c \"echo -1 > /proc/sys/kernel/perf_event_paranoid\"'\n" "Hint:\tThe current value is %d.", value); break; + case EINVAL: { + struct perf_evsel *first = perf_evlist__first(evlist); + int max_freq; + + if (sysctl__read_int("kernel/perf_event_max_sample_rate", _freq) < 0) + goto out_default; + + if (first->attr.sample_freq < (u64)max_freq) + goto out_default; + + printed = scnprintf(buf, size, + "Error:\t%s.\n" + "Hint:\tCheck /proc/sys/kernel/perf_event_max_sample_rate.\n" + "Hint:\tThe current value is %d and %" PRIu64 " is being requested.", + emsg, max_freq, first->attr.sample_freq); + break; + } default: +out_default: scnprintf(buf, size, "%s", emsg); break; }
[tip:perf/core] perf tests: Use perf_evlist__strerror_open() to provide hints about max_freq
Commit-ID: 6880bbf96930ec6f8b40b5b93f21973f3297672a Gitweb: http://git.kernel.org/tip/6880bbf96930ec6f8b40b5b93f21973f3297672a Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 18 Feb 2016 13:40:57 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 19 Feb 2016 19:12:43 -0300 perf tests: Use perf_evlist__strerror_open() to provide hints about max_freq Before: # perf test -v "code reading" 2>&1 | tail -4 perf_evlist__open failed test child finished with -1 end Test object code reading: FAILED! # After: # perf test -v "code reading" 2>&1 | tail -7 perf_evlist__open() failed! Error: Invalid argument. Hint: Check /proc/sys/kernel/perf_event_max_sample_rate. Hint: The current value is 1000 and 4000 is being requested. test child finished with -1 end Test object code reading: FAILED! # Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Steven Noonan Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-ifbx7vmrc38loe6317owz...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/code-reading.c | 8 +++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 313a48c..f84339c 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -559,7 +559,13 @@ static int do_test_code_reading(bool try_kcore) evlist = NULL; continue; } - pr_debug("perf_evlist__open failed\n"); + + if (verbose) { + char errbuf[512]; + perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); + pr_debug("perf_evlist__open() failed!\n%s\n", errbuf); + } + goto out_put; } break;
[tip:perf/core] perf test: Reduce the sample_freq for the ' object code reading' test
Commit-ID: 5243ba76a585a6481c4d7b931e7e3d98900cbdbe Gitweb: http://git.kernel.org/tip/5243ba76a585a6481c4d7b931e7e3d98900cbdbe Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 18 Feb 2016 13:45:25 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 19 Feb 2016 19:12:44 -0300 perf test: Reduce the sample_freq for the 'object code reading' test Using 4 kHz is not necessary and sometimes is more than what was auto-tuned: # dmesg | grep max_sample_rate | tail -2 [ 2499.144373] perf interrupt took too long (2501 > 2500), lowering kernel.perf_event_max_sample_rate to 5 [ 3592.413606] perf interrupt took too long (5069 > 5000), lowering kernel.perf_event_max_sample_rate to 25000 Simulating a auto-tune of 2000 we make the test fail, as reported by Steven Noonan for one of his machines, so reduce it to 500 HZ, it is enough to get a good number of samples for this test: # perf test -v 21 2>&1 | grep '^Reading object code for memory address' | tee /tmp/out | tail -5 Reading object code for memory address: 0x479f40 Reading object code for memory address: 0x7f29b7eea80d Reading object code for memory address: 0x7f29b7eea80d Reading object code for memory address: 0x7f29b7eea800 Reading object code for memory address: 0x813b2f23 [root@jouet ~]# wc -l /tmp/out 40 /tmp/out [root@jouet ~]# For systems that auto-tune below that, the previous patches will tell the user what is happening so that he may either ignore the result of this test or bump /proc/sys/kernel/perf_event_max_sample_rate. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Steven Noonan Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-6kufyy1iprdfzrbtuqgxi...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/code-reading.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index f84339c..afc9ad0 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -439,7 +439,7 @@ static int do_test_code_reading(bool try_kcore) .mmap_pages = UINT_MAX, .user_freq = UINT_MAX, .user_interval = ULLONG_MAX, - .freq= 4000, + .freq= 500, .target = { .uses_mmap = true, },
[tip:perf/core] perf tools: Introduce opt_event_config nonterminal
Commit-ID: 1d55e8ef340dad1ccd5aaf53071de41fc3d8dba4 Gitweb: http://git.kernel.org/tip/1d55e8ef340dad1ccd5aaf53071de41fc3d8dba4 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 19 Feb 2016 18:45:12 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 19 Feb 2016 19:12:50 -0300 perf tools: Introduce opt_event_config nonterminal To remove duplicated code that differs only in using the matching '/a,b,c/' part or NULL if no event configuration is done ('//' or no pair of slashes at all). Will be used by some new targets allowing the configuration of hardware events, etc. Lifted part of the 'opt_event_config' nonterminal from a patch by Wang Nan. Cc: Adrian Hunter Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Cody P Schafer Cc: He Kuang Cc: Jeremie Galarneau Cc: Jiri Olsa Cc: Kirill Smelkov Cc: Li Zefan Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3or...@163.com Link: http://lkml.kernel.org/n/tip-e3xzpx9cqsmwnaguaxyw6...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.y | 47 -- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index c0eac88..ce68746 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -64,6 +64,7 @@ static inc_group_count(struct list_head *list, %type PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT %type value_sym %type event_config +%type opt_event_config %type event_term %type event_pmu %type event_legacy_symbol @@ -222,16 +223,6 @@ PE_NAME '/' event_config '/' $$ = list; } | -PE_NAME '/' '/' -{ - struct parse_events_evlist *data = _data; - struct list_head *list; - - ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(data, list, $1, NULL)); - $$ = list; -} -| PE_KERNEL_PMU_EVENT sep_dc { struct parse_events_evlist *data = _data; @@ -378,7 +369,7 @@ PE_PREFIX_MEM PE_VALUE sep_dc } event_legacy_tracepoint: -tracepoint_name +tracepoint_name opt_event_config { struct parse_events_evlist *data = _data; struct parse_events_error *error = data->error; @@ -389,24 +380,7 @@ tracepoint_name error->idx = @1.first_column; if (parse_events_add_tracepoint(list, >idx, $1.sys, $1.event, - error, NULL)) - return -1; - - $$ = list; -} -| -tracepoint_name '/' event_config '/' -{ - struct parse_events_evlist *data = _data; - struct parse_events_error *error = data->error; - struct list_head *list; - - ALLOC_LIST(list); - if (error) - error->idx = @1.first_column; - - if (parse_events_add_tracepoint(list, >idx, $1.sys, $1.event, - error, $3)) + error, $2)) return -1; $$ = list; @@ -476,6 +450,21 @@ PE_BPF_SOURCE $$ = list; } +opt_event_config: +'/' event_config '/' +{ + $$ = $2; +} +| +'/' '/' +{ + $$ = NULL; +} +| +{ + $$ = NULL; +} + start_terms: event_config { struct parse_events_terms *data = _data;
[tip:perf/core] perf tools: Add comment explaining the repsep_snprintf function
Commit-ID: 37d9bb580aa73c171c51fb93edf67a902bcb186f Gitweb: http://git.kernel.org/tip/37d9bb580aa73c171c51fb93edf67a902bcb186f Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 12 Feb 2016 11:27:51 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 12 Feb 2016 12:52:20 -0300 perf tools: Add comment explaining the repsep_snprintf function Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-4j67nvlfwbnkg85b969ew...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/sort.c | 10 +- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index de620f7..8b54ede 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -28,7 +28,15 @@ int sort__has_socket = 0; intsort__has_thread = 0; enum sort_mode sort__mode = SORT_MODE__NORMAL; - +/* + * Replaces all occurrences of a char used with the: + * + * -t, --field-separator + * + * option, that uses a special separator character and don't pad with spaces, + * replacing all occurances of this separator in symbol names (and other + * output) with a '.' character, that thus it's the only non valid separator. +*/ static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) { int n;
[tip:perf/core] perf tools: Introduce parse_events_terms__purge()
Commit-ID: fc0a2c1d59beac70b8738f4ce14431b798837374 Gitweb: http://git.kernel.org/tip/fc0a2c1d59beac70b8738f4ce14431b798837374 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 12 Feb 2016 16:43:02 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 12 Feb 2016 16:53:19 -0300 perf tools: Introduce parse_events_terms__purge() Purges 'struct parse_event_term' entries from a list_head. Some users need this because they don't allocate space for the list head, it maybe on the stack or embedded into some other struct. Next patch will convert users that need just purging and then the perf_events__free_terms() routine will free the list head as well, finally being renamed to perf_events_terms__delete(). Acked-by: Jiri Olsa Cc: Alexei Starovoitov Cc: He Kuang Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Wang Nan Cc: Zefan Li Cc: pi3or...@163.com Link: http://lkml.kernel.org/n/tip-4w3zl4ifcl0ed0j4bu3tc...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 7 ++- tools/perf/util/parse-events.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 133c8d2..668afdc 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2068,7 +2068,7 @@ int parse_events_term__clone(struct parse_events_term **new, term->err_term, term->err_val); } -void parse_events__free_terms(struct list_head *terms) +void parse_events_terms__purge(struct list_head *terms) { struct parse_events_term *term, *h; @@ -2078,6 +2078,11 @@ void parse_events__free_terms(struct list_head *terms) } } +void parse_events__free_terms(struct list_head *terms) +{ + parse_events_terms__purge(terms); +} + void parse_events_evlist_error(struct parse_events_evlist *data, int idx, const char *str) { diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index f1a6db1..f90a04c 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -116,6 +116,7 @@ int parse_events_term__sym_hw(struct parse_events_term **term, int parse_events_term__clone(struct parse_events_term **new, struct parse_events_term *term); void parse_events__free_terms(struct list_head *terms); +void parse_events_terms__purge(struct list_head *terms); int parse_events__modifier_event(struct list_head *list, char *str, bool add); int parse_events__modifier_group(struct list_head *list, char *event_mod); int parse_events_name(struct list_head *list, char *name);
[tip:perf/core] perf hists: Do column alignment on the format iterator
Commit-ID: 89fee70943232d73e3cc328634e0da253b6de9b5 Gitweb: http://git.kernel.org/tip/89fee70943232d73e3cc328634e0da253b6de9b5 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 11 Feb 2016 17:14:13 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 12 Feb 2016 12:52:25 -0300 perf hists: Do column alignment on the format iterator We were doing column alignment in the format function for each cell, returning a string padded with spaces so that when the next column is printed the cursor is at its column alignment. This ends up needlessly printing trailing spaces, do it at the format iterator, that is where we know if it is needed, i.e. if there is more columns to be printed. This eliminates the need for triming lines when doing a dump using 'P' in the TUI browser and also produces far saner results with things like piping 'perf report' to 'less'. Right now only the formatters for sym->name and the 'locked' column (perf mem report), that are the ones that end up at the end of lines in the default 'perf report', 'perf top' and 'perf mem report' tools, the others will be done in a subsequent patch. In the end the 'width' parameter for the formatters now mean, in 'printf' terms, the 'precision', where before it was the field 'width'. Reported-by: Dave Jones Cc: Jiri Olsa Cc: Namhyung Kim Link: http://lkml.kernel.org/n/tip-s7iwl2gj23w92l6tibnrc...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/hists.c | 27 ++- tools/perf/ui/stdio/hist.c | 1 + tools/perf/util/hist.c | 21 + tools/perf/util/hist.h | 5 + tools/perf/util/sort.c | 13 +++-- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index a5a5390..1819771 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -1061,7 +1061,6 @@ static int hist_browser__show_entry(struct hist_browser *browser, struct hist_entry *entry, unsigned short row) { - char s[256]; int printed = 0; int width = browser->b.width; char folded_sign = ' '; @@ -1086,16 +1085,18 @@ static int hist_browser__show_entry(struct hist_browser *browser, .folded_sign= folded_sign, .current_entry = current_entry, }; - struct perf_hpp hpp = { - .buf= s, - .size = sizeof(s), - .ptr= , - }; int column = 0; hist_browser__gotorc(browser, row, 0); hists__for_each_format(browser->hists, fmt) { + char s[2048]; + struct perf_hpp hpp = { + .buf= s, + .size = sizeof(s), + .ptr= , + }; + if (perf_hpp__should_skip(fmt, entry->hists) || column++ < browser->b.horiz_scroll) continue; @@ -1120,11 +1121,18 @@ static int hist_browser__show_entry(struct hist_browser *browser, } if (fmt->color) { - width -= fmt->color(fmt, , entry); + int ret = fmt->color(fmt, , entry); + hist_entry__snprintf_alignment(entry, , fmt, ret); + /* +* fmt->color() already used ui_browser to +* print the non alignment bits, skip it (+ret): +*/ + ui_browser__printf(>b, "%s", s + ret); } else { - width -= fmt->entry(fmt, , entry); + hist_entry__snprintf_alignment(entry, , fmt, fmt->entry(fmt, , entry)); ui_browser__printf(>b, "%s", s); } + width -= hpp.buf - s; } /* The scroll bar isn't being used */ @@ -1452,9 +1460,10 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser, first = false; ret = fmt->entry(fmt, , he); + ret = hist_entry__snprintf_alignment(he, , fmt, ret); advance_hpp(, ret); } - printed += fprintf(fp, "%s\n", rtrim(s)); + printed += fprintf(fp, "%s\n", s); if (folded_sign == '-') printed += hist_browser__fprintf_callchain(browser, he, fp); diff --git
[tip:perf/core] perf tools: Rename parse_events__free_terms() to parse_events_terms__delete()
Commit-ID: 2146afc6b45b3f1b967f5605d4e6d97dd9e31061 Gitweb: http://git.kernel.org/tip/2146afc6b45b3f1b967f5605d4e6d97dd9e31061 Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 12 Feb 2016 17:09:17 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 12 Feb 2016 17:09:17 -0300 perf tools: Rename parse_events__free_terms() to parse_events_terms__delete() To follow convention used in other tools/perf/ areas. Also remove the need to check if it is NULL before calling the destructor, again, to follow convention that goes back to free(). Cc: Alexei Starovoitov Cc: He Kuang cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Wang Nan Cc: Zefan Li Cc: pi3or...@163.com Link: http://lkml.kernel.org/n/tip-w6owu7rb8a46gvunlinxa...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/util/parse-events.c | 7 --- tools/perf/util/parse-events.h | 2 +- tools/perf/util/parse-events.y | 8 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index 6f7d453..a339517 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -89,7 +89,7 @@ static int intel_pt_parse_terms_with_default(struct list_head *formats, *config = attr.config; out_free: - parse_events__free_terms(terms); + parse_events_terms__delete(terms); return err; } diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index d1b49ec..e5583fd 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1386,8 +1386,7 @@ int parse_events_terms(struct list_head *terms, const char *str) return 0; } - if (data.terms) - parse_events__free_terms(data.terms); + parse_events_terms__delete(data.terms); return ret; } @@ -2078,8 +2077,10 @@ void parse_events_terms__purge(struct list_head *terms) } } -void parse_events__free_terms(struct list_head *terms) +void parse_events_terms__delete(struct list_head *terms) { + if (!terms) + return; parse_events_terms__purge(terms); free(terms); } diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index f90a04c..53628bf 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -115,7 +115,7 @@ int parse_events_term__sym_hw(struct parse_events_term **term, char *config, unsigned idx); int parse_events_term__clone(struct parse_events_term **new, struct parse_events_term *term); -void parse_events__free_terms(struct list_head *terms); +void parse_events_terms__delete(struct list_head *terms); void parse_events_terms__purge(struct list_head *terms); int parse_events__modifier_event(struct list_head *list, char *str, bool add); int parse_events__modifier_group(struct list_head *list, char *event_mod); diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index ad37996..c0eac88 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -218,7 +218,7 @@ PE_NAME '/' event_config '/' ALLOC_LIST(list); ABORT_ON(parse_events_add_pmu(data, list, $1, $3)); - parse_events__free_terms($3); + parse_events_terms__delete($3); $$ = list; } | @@ -246,7 +246,7 @@ PE_KERNEL_PMU_EVENT sep_dc ALLOC_LIST(list); ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); - parse_events__free_terms(head); + parse_events_terms__delete(head); $$ = list; } | @@ -266,7 +266,7 @@ PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc ALLOC_LIST(list); ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); - parse_events__free_terms(head); + parse_events_terms__delete(head); $$ = list; } @@ -285,7 +285,7 @@ value_sym '/' event_config '/' ALLOC_LIST(list); ABORT_ON(parse_events_add_numeric(data, list, type, config, $3)); - parse_events__free_terms($3); + parse_events_terms__delete($3); $$ = list; } |
[tip:perf/core] perf tools: Use perf_event_terms__purge() for non-malloced terms
Commit-ID: 682dc24c2a0f13d5a16ac8f4303671eb8f11519f Gitweb: http://git.kernel.org/tip/682dc24c2a0f13d5a16ac8f4303671eb8f11519f Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 12 Feb 2016 16:48:00 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 12 Feb 2016 16:53:22 -0300 perf tools: Use perf_event_terms__purge() for non-malloced terms In these two cases, a 'perf test' entry and in the PMU code the list_head is on the stack, so we can't use perf_event__free_terms() (soon to be renamed to perf_event_terms__delete()), because it will free the list_head as well. Acked-by: Jiri Olsa Cc: Alexei Starovoitov Cc: He Kuang Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Wang Nan Cc: Zefan Li Cc: pi3or...@163.com Link: http://lkml.kernel.org/n/tip-i956ryjhz97gnnqe8iqe7...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/pmu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index abe8849..6648274 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -1666,7 +1666,7 @@ static int test_term(struct terms_test *t) } ret = t->check(); - parse_events__free_terms(); + parse_events_terms__purge(); return ret; } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 41a9c87..cf59fba 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -354,7 +354,7 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias, list_for_each_entry(term, >terms, list) { ret = parse_events_term__clone(, term); if (ret) { - parse_events__free_terms(); + parse_events_terms__purge(); return ret; } list_add_tail(>list, );
[tip:perf/core] perf tests: Fix build on older systems where ' signal' is reserved
Commit-ID: 1ad826bad5bd0b6ccfb203f78c70302b764df0be Gitweb: http://git.kernel.org/tip/1ad826bad5bd0b6ccfb203f78c70302b764df0be Author: Arnaldo Carvalho de MeloAuthorDate: Fri, 12 Feb 2016 18:30:01 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 15 Feb 2016 17:33:26 -0300 perf tests: Fix build on older systems where 'signal' is reserved fixing the following problems, for instance, on RHEL6.7: CC /tmp/build/perf/tests/bp_signal.o cc1: warnings being treated as errors tests/bp_signal.c: In function ‘__event’: tests/bp_signal.c:106: error: declaration of ‘signal’ shadows a global declaration /usr/include/signal.h:101: error: shadowed declaration is here tests/bp_signal.c: In function ‘bp_event’: tests/bp_signal.c:144: error: declaration of ‘signal’ shadows a global declaration /usr/include/signal.h:101: error: shadowed declaration is here tests/bp_signal.c: In function ‘wp_event’: tests/bp_signal.c:149: error: declaration of ‘signal’ shadows a global declaration /usr/include/signal.h:101: error: shadowed declaration is here mv: cannot stat `/tmp/build/perf/tests/.bp_signal.o.tmp': No such file or directory make[3]: *** [/tmp/build/perf/tests/bp_signal.o] Error 1 make[2]: *** [tests] Error 2 make[1]: *** [/tmp/build/perf/perf-in.o] Error 2 make[1]: *** Waiting for unfinished jobs Reported-by: Vinson Lee Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: He Kuang Cc: Li Zefan Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Wang Nan Cc: Will Deacon Cc: pi3or...@163.com Fixes: 8fd34e1cce18 ("perf test: Improve bp_signal") Link: http://lkml.kernel.org/n/tip-wlpx6tik1b0jirlkw64bv...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/bp_signal.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/tests/bp_signal.c b/tools/perf/tests/bp_signal.c index 1d1bb48..e7664fe 100644 --- a/tools/perf/tests/bp_signal.c +++ b/tools/perf/tests/bp_signal.c @@ -103,7 +103,7 @@ static void sig_handler(int signum __maybe_unused, } } -static int __event(bool is_x, void *addr, int signal) +static int __event(bool is_x, void *addr, int sig) { struct perf_event_attr pe; int fd; @@ -133,7 +133,7 @@ static int __event(bool is_x, void *addr, int signal) } fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC); - fcntl(fd, F_SETSIG, signal); + fcntl(fd, F_SETSIG, sig); fcntl(fd, F_SETOWN, getpid()); ioctl(fd, PERF_EVENT_IOC_RESET, 0); @@ -141,14 +141,14 @@ static int __event(bool is_x, void *addr, int signal) return fd; } -static int bp_event(void *addr, int signal) +static int bp_event(void *addr, int sig) { - return __event(true, addr, signal); + return __event(true, addr, sig); } -static int wp_event(void *addr, int signal) +static int wp_event(void *addr, int sig) { - return __event(false, addr, signal); + return __event(false, addr, sig); } static long long bp_count(int fd)
[tip:perf/core] perf jitdump: DWARF is also needed
Commit-ID: 46dad054a19297af65c417c97cb920aa5bdf7e8c Gitweb: http://git.kernel.org/tip/46dad054a19297af65c417c97cb920aa5bdf7e8c Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 7 Mar 2016 18:48:45 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 9 Mar 2016 10:29:03 -0300 perf jitdump: DWARF is also needed While building on a Docker container for ubuntu and installing package by package one ends up with: MKDIR/tmp/build/util/ CC /tmp/build/util/genelf.o util/genelf.c:22:19: fatal error: dwarf.h: No such file or directory #include ^ compilation terminated. mv: cannot stat '/tmp/build/util/.genelf.o.tmp': No such file or directory Because the jitdump code needs the DWARF related development packages to be installed. So make it dependent on that so that the build can succeed without jitdump support. Cc: Adrian Hunter Cc: Stephane Eranian Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-le498robnmxd40237wej3...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-inject.c | 10 +- tools/perf/util/Build | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index b288577..e219ed4 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -73,7 +73,7 @@ static int perf_event__repipe_oe_synth(struct perf_tool *tool, return perf_event__repipe_synth(tool, event); } -#ifdef HAVE_LIBELF_SUPPORT +#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_DWARF_SUPPORT) static int perf_event__drop_oe(struct perf_tool *tool __maybe_unused, union perf_event *event __maybe_unused, struct ordered_events *oe __maybe_unused) @@ -245,7 +245,7 @@ static int perf_event__repipe_mmap(struct perf_tool *tool, return err; } -#ifdef HAVE_LIBELF_SUPPORT +#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_DWARF_SUPPORT) static int perf_event__jit_repipe_mmap(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, @@ -283,7 +283,7 @@ static int perf_event__repipe_mmap2(struct perf_tool *tool, return err; } -#ifdef HAVE_LIBELF_SUPPORT +#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_DWARF_SUPPORT) static int perf_event__jit_repipe_mmap2(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, @@ -795,7 +795,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) "perf inject []", NULL }; -#ifndef HAVE_LIBELF_SUPPORT +#if !defined(HAVE_LIBELF_SUPPORT) || !defined(HAVE_DWARF_SUPPORT) set_option_nobuild(options, 'j', "jit", "NO_LIBELF=1", true); #endif argc = parse_options(argc, argv, options, inject_usage, 0); @@ -833,7 +833,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) inject.tool.ordered_events = true; inject.tool.ordering_requires_timestamps = true; } -#ifdef HAVE_LIBELF_SUPPORT +#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_DWARF_SUPPORT) if (inject.jit_mode) { inject.tool.mmap2 = perf_event__jit_repipe_mmap2; inject.tool.mmap = perf_event__jit_repipe_mmap; diff --git a/tools/perf/util/Build b/tools/perf/util/Build index df2b690..f130ce2 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -107,9 +107,12 @@ libperf-y += scripting-engines/ libperf-$(CONFIG_ZLIB) += zlib.o libperf-$(CONFIG_LZMA) += lzma.o libperf-y += demangle-java.o + +ifdef CONFIG_DWARF libperf-$(CONFIG_LIBELF) += jitdump.o libperf-$(CONFIG_LIBELF) += genelf.o libperf-$(CONFIG_LIBELF) += genelf_debug.o +endif CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" # avoid compiler warnings in 32-bit mode
[tip:perf/core] perf trace: Pretty print getrandom() args
Commit-ID: 39878d492c049796202b70dc0ef14449cafa3cb4 Gitweb: http://git.kernel.org/tip/39878d492c049796202b70dc0ef14449cafa3cb4 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Mar 2016 20:02:15 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 31 Mar 2016 10:42:23 -0300 perf trace: Pretty print getrandom() args # trace -e getrandom 35622.560 ( 0.023 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 35622.585 ( 0.006 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 35622.594 ( 0.004 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 35627.395 ( 0.010 ms): libvirtd/1353 getrandom(buf: 0x7f7a1bfa35c0, count: 16, flags: NONBLOCK) = 16 35630.940 ( 0.013 ms): fwupd/16120 getrandom(buf: 0x7f63243aa5c0, count: 16, flags: NONBLOCK ) = 16 35718.613 ( 0.015 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 35718.629 ( 0.005 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 35718.637 ( 0.004 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 35719.355 ( 0.010 ms): libvirtd/1353 getrandom(buf: 0x7f7a1bfa35c0, count: 16, flags: NONBLOCK) = 16 35721.042 ( 0.030 ms): fwupd/16120 getrandom(buf: 0x7f63243aa5c0, count: 16, flags: NONBLOCK ) = 16 41090.830 ( 0.012 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 41090.845 ( 0.004 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 41090.851 ( 0.004 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 41091.750 ( 0.010 ms): libvirtd/1353 getrandom(buf: 0x7f7a1bfa35c0, count: 16, flags: NONBLOCK) = 16 41091.823 ( 0.006 ms): fwupd/16120 getrandom(buf: 0x7f63243aa5c0, count: 16, flags: NONBLOCK ) = 16 41122.078 ( 0.053 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 41122.129 ( 0.009 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 41122.139 ( 0.004 ms): systemd-udevd/631 getrandom(buf: 0x55621e3c18f0, count: 16, flags: NONBLOCK) = 16 41124.492 ( 0.007 ms): libvirtd/1353 getrandom(buf: 0x7f7a1bfa35c0, count: 16, flags: NONBLOCK) = 16 41124.470 ( 0.013 ms): fwupd/16120 getrandom(buf: 0x7f63243aa5c0, count: 16, flags: NONBLOCK ) = 16 41590.832 ( 0.014 ms): chrome/5957 getrandom(buf: 0x7fabac7b15b0, count: 16, flags: NONBLOCK ) = 16 41590.884 ( 0.004 ms): chrome/5957 getrandom(buf: 0x7fabac7b15c0, count: 16, flags: NONBLOCK ) = 16 Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-gca0n1p3aca3depey703p...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 26 ++ 1 file changed, 26 insertions(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0c8bcb9..c45c1cf 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -44,6 +44,7 @@ #include #include #include +#include /* For older distros: */ #ifndef MAP_STACK @@ -1045,6 +1046,29 @@ static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size, #define SCA_SECCOMP_FLAGS syscall_arg__scnprintf_seccomp_flags +static size_t syscall_arg__scnprintf_getrandom_flags(char *bf, size_t size, + struct syscall_arg *arg) +{ + int printed = 0, flags = arg->val; + +#defineP_FLAG(n) \ + if (flags & GRND_##n) { \ + printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ + flags &= ~GRND_##n; \ + } + + P_FLAG(RANDOM); + P_FLAG(NONBLOCK); +#undef P_FLAG + + if (flags) + printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); + + return printed; +} + +#define SCA_GETRANDOM_FLAGS syscall_arg__scnprintf_getrandom_flags + #define STRARRAY(arg, name, array) \ .arg_scnprintf = { [arg] = SCA_STRARRAY, }, \ .arg_parm = { [arg] = __##array, } @@ -1137,6 +1161,8 @@ static struct syscall_fmt { { .name = "getdents64", .errmsg = true, .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, { .name = "getitimer", .errmsg = true, STRARRAY(0, which, itimers), }, + { .name = "getrandom", .errmsg = true, + .arg_scnprintf = { [2] = SCA_GETRANDOM_FLAGS, /* flags */ }, }, { .name = "getrlimit", .errmsg = true, STRARRAY(0, resource, rlimit_resources), },
[tip:perf/core] perf trace: Pretty print seccomp() args
Commit-ID: 997bba8cf1875d9715e792c445e1a9c7a4c365e2 Gitweb: http://git.kernel.org/tip/997bba8cf1875d9715e792c445e1a9c7a4c365e2 Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Mar 2016 19:43:32 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 31 Mar 2016 10:42:22 -0300 perf trace: Pretty print seccomp() args E.g: # trace -e seccomp 200.061 (0.009 ms): :2441/2441 seccomp(op: FILTER, flags: TSYNC ) = -1 EFAULT Bad address 200.910 (0.121 ms): :2441/2441 seccomp(op: FILTER, flags: TSYNC, uargs: 0x7fff57479fe0) = 0 Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-t369uckshlwp4evkks4bc...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 47 ++ 1 file changed, 47 insertions(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 6485576..0c8bcb9 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -40,6 +40,10 @@ #include #include #include +#include +#include +#include +#include /* For older distros: */ #ifndef MAP_STACK @@ -1001,6 +1005,46 @@ static const char *tioctls[] = { static DEFINE_STRARRAY_OFFSET(tioctls, 0x5401); #endif /* defined(__i386__) || defined(__x86_64__) */ +static size_t syscall_arg__scnprintf_seccomp_op(char *bf, size_t size, struct syscall_arg *arg) +{ + int op = arg->val; + size_t printed = 0; + + switch (op) { +#defineP_SECCOMP_SET_MODE_OP(n) case SECCOMP_SET_MODE_##n: printed = scnprintf(bf, size, #n); break + P_SECCOMP_SET_MODE_OP(STRICT); + P_SECCOMP_SET_MODE_OP(FILTER); +#undef P_SECCOMP_SET_MODE_OP + default: printed = scnprintf(bf, size, "%#x", op); break; + } + + return printed; +} + +#define SCA_SECCOMP_OP syscall_arg__scnprintf_seccomp_op + +static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size, + struct syscall_arg *arg) +{ + int printed = 0, flags = arg->val; + +#defineP_FLAG(n) \ + if (flags & SECCOMP_FILTER_FLAG_##n) { \ + printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ + flags &= ~SECCOMP_FILTER_FLAG_##n; \ + } + + P_FLAG(TSYNC); +#undef P_FLAG + + if (flags) + printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); + + return printed; +} + +#define SCA_SECCOMP_FLAGS syscall_arg__scnprintf_seccomp_flags + #define STRARRAY(arg, name, array) \ .arg_scnprintf = { [arg] = SCA_STRARRAY, }, \ .arg_parm = { [arg] = __##array, } @@ -1234,6 +1278,9 @@ static struct syscall_fmt { .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, { .name = "rt_tgsigqueueinfo", .errmsg = true, .arg_scnprintf = { [2] = SCA_SIGNUM, /* sig */ }, }, + { .name = "seccomp", .errmsg = true, + .arg_scnprintf = { [0] = SCA_SECCOMP_OP, /* op */ +[1] = SCA_SECCOMP_FLAGS, /* flags */ }, }, { .name = "select", .errmsg = true, .timeout = true, }, { .name = "sendmmsg",.errmsg = true, .arg_scnprintf = { [0] = SCA_FD, /* fd */
[tip:perf/core] perf trace: Do not process PERF_RECORD_LOST twice
Commit-ID: 3ed5ca2efff70e9f589087c2013789572901112d Gitweb: http://git.kernel.org/tip/3ed5ca2efff70e9f589087c2013789572901112d Author: Arnaldo Carvalho de MeloAuthorDate: Wed, 30 Mar 2016 16:51:17 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 31 Mar 2016 10:42:22 -0300 perf trace: Do not process PERF_RECORD_LOST twice We catch this record to provide a visual indication that events are getting lost, then call the default method to allow extra logging shared with the other tools to take place. This extra logging was done twice because we were continuing to the "default" clause where machine__process_event() will end up calling machine__process_lost_event() again, fix it. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-wus2zlhw3qo24ye84ewu4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 93ac724..6485576 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1618,6 +1618,7 @@ static int trace__process_event(struct trace *trace, struct machine *machine, color_fprintf(trace->output, PERF_COLOR_RED, "LOST %" PRIu64 " events!\n", event->lost.lost); ret = machine__process_lost_event(machine, event, sample); + break; default: ret = machine__process_event(machine, event, sample); break;
[tip:perf/core] perf trace: Don't set the base timestamp using events without PERF_SAMPLE_TIME
Commit-ID: 8a07a8094b6b6c3e195885ec31f4bd0be54aafaf Gitweb: http://git.kernel.org/tip/8a07a8094b6b6c3e195885ec31f4bd0be54aafaf Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 31 Mar 2016 15:19:39 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 1 Apr 2016 18:46:25 -0300 perf trace: Don't set the base timestamp using events without PERF_SAMPLE_TIME This was causing bogus values to be shown at the timestamp column: Before: # trace --ev bpf-output/no-inherit,name=evt/ --ev /home/acme/bpf/test_bpf_trace.c/map:channel.event=evt/ usleep 10 94631143.385 ( 0.001 ms): brk( ) = 0x55757000 94631143.398 ( 0.003 ms): mmap(len: 4096, prot: READ|WRITE, flags: PRIVATE|ANONYMOUS, fd: -1) = 0x77ff6000 94631143.406 ( 0.004 ms): access(filename: 0xf7df9e10, mode: R ) = -1 ENOENT No such file or directory 94631143.412 ( 0.004 ms): open(filename: 0xf7df8761, flags: CLOEXEC) = 3 94631143.415 ( 0.002 ms): fstat(fd: 3, statbuf: 0x7fffd6b0 ) = 0 94631143.419 ( 0.003 ms): mmap(len: 106798, prot: READ, flags: PRIVATE, fd: 3) = 0x77fdb000 94631143.420 ( 0.001 ms): close(fd: 3 ) = 0 94631143.432 ( 0.004 ms): open(filename: 0xf7ff6640, flags: CLOEXEC) = 3 After: # trace --ev bpf-output/no-inherit,name=evt/ --ev /home/acme/bpf/test_bpf_trace.c/map:channel.event=evt/ usleep 10 0.022 ( 0.001 ms): brk( ) = 0x55d7668a6000 0.037 ( 0.003 ms): mmap(len: 4096, prot: READ|WRITE, flags: PRIVATE|ANONYMOUS, fd: -1) = 0x7f8fbeb97000 0.123 ( 0.083 ms): access(filename: 0xbe995e10, mode: R ) = -1 ENOENT No such file or directory 0.130 ( 0.004 ms): open(filename: 0xbe994761, flags: CLOEXEC) = 3 0.133 ( 0.002 ms): fstat(fd: 3, statbuf: 0x7fff6487a890 ) = 0 0.138 ( 0.003 ms): mmap(len: 106798, prot: READ, flags: PRIVATE, fd: 3) = 0x7f8fbeb7c000 0.140 ( 0.001 ms): close(fd: 3 ) = 0 0.151 ( 0.004 ms): open(filename: 0xbeb97640, flags: CLOEXEC) = 3 Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-p7m8llv81iv55ekxexdp5...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 13 +++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 99daeed..d309f45 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2401,10 +2401,19 @@ static bool skip_sample(struct trace *trace, struct perf_sample *sample) } static void trace__set_base_time(struct trace *trace, -struct perf_evsel *evsel __maybe_unused, +struct perf_evsel *evsel, struct perf_sample *sample) { - if (trace->base_time == 0 && !trace->full_time) + /* +* BPF events were not setting PERF_SAMPLE_TIME, so be more robust +* and don't use sample->time unconditionally, we may end up having +* some other event in the future without PERF_SAMPLE_TIME for good +* reason, i.e. we may not be interested in its timestamps, just in +* it taking place, picking some piece of information when it +* appears in our event stream (vfs_getname comes to mind). +*/ + if (trace->base_time == 0 && !trace->full_time && + (evsel->attr.sample_type & PERF_SAMPLE_TIME)) trace->base_time = sample->time; }
[tip:perf/core] perf trace: Introduce function to set the base timestamp
Commit-ID: e6001980c61b45ef090e2b4c9c1953ef897cdeb0 Gitweb: http://git.kernel.org/tip/e6001980c61b45ef090e2b4c9c1953ef897cdeb0 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 31 Mar 2016 15:16:28 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 1 Apr 2016 18:46:24 -0300 perf trace: Introduce function to set the base timestamp That is used in both live runs, i.e.: # trace ls As when processing events recorded in a perf.data file: # trace -i perf.data Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-901l6yebnzeqg7z8mbaf4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 16 +++- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index c45c1cf..99daeed 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2400,6 +2400,14 @@ static bool skip_sample(struct trace *trace, struct perf_sample *sample) return false; } +static void trace__set_base_time(struct trace *trace, +struct perf_evsel *evsel __maybe_unused, +struct perf_sample *sample) +{ + if (trace->base_time == 0 && !trace->full_time) + trace->base_time = sample->time; +} + static int trace__process_sample(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample, @@ -2414,8 +2422,7 @@ static int trace__process_sample(struct perf_tool *tool, if (skip_sample(trace, sample)) return 0; - if (!trace->full_time && trace->base_time == 0) - trace->base_time = sample->time; + trace__set_base_time(trace, evsel, sample); if (handler) { ++trace->nr_events; @@ -2553,9 +2560,6 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st const u32 type = event->header.type; struct perf_evsel *evsel; - if (!trace->full_time && trace->base_time == 0) - trace->base_time = sample->time; - if (type != PERF_RECORD_SAMPLE) { trace__process_event(trace, trace->host, event, sample); return; @@ -2567,6 +2571,8 @@ static void trace__handle_event(struct trace *trace, union perf_event *event, st return; } + trace__set_base_time(trace, evsel, sample); + if (evsel->attr.type == PERF_TYPE_TRACEPOINT && sample->raw_data == NULL) { fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
[tip:perf/core] perf trace: Beautify mode_t arguments
Commit-ID: ba2f22cf9989561c08225f0e88078d5562832313 Gitweb: http://git.kernel.org/tip/ba2f22cf9989561c08225f0e88078d5562832313 Author: Arnaldo Carvalho de MeloAuthorDate: Thu, 7 Apr 2016 12:05:51 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 8 Apr 2016 09:58:13 -0300 perf trace: Beautify mode_t arguments When reading the syscall tracepoint /format file, look for arguments of type "mode_t" and attach a beautifier: [root@jouet ~]# cat ~/bin/tp_with_fields_of_type #!/bin/bash grep -w $1 /sys/kernel/tracing/events/syscalls/*/format | sed -r 's%.*sys_enter_(.*)/format.*%\1%g' | paste -d, -s # tp_with_fields_of_type umode_t chmod,creat,fchmodat,fchmod,mkdirat,mkdir,mknodat,mknod,mq_open,openat,open # Testing it: #define S_ISUID 0004000 #define S_ISGID 0002000 #define S_ISVTX 0001000 #define S_IRWXU 700 #define S_IRUSR 400 #define S_IWUSR 200 #define S_IXUSR 100 #define S_IRWXG 070 #define S_IRGRP 040 #define S_IWGRP 020 #define S_IXGRP 010 #define S_IRWXO 007 #define S_IROTH 004 #define S_IWOTH 002 #define S_IXOTH 001 # for mode in 4000 2000 1000 700 400 200 100 70 40 20 10 7 4 2 1 ; do \ echo -n $mode '->' ; trace --no-inherit -e chmod,fchmodat,fchmod chmod $mode x; \ done 4000 -> 0.338 ( 0.012 ms): fchmodat(dfd: CWD, filename: x, mode: ISUID) = 0 2000 -> 0.438 ( 0.015 ms): fchmodat(dfd: CWD, filename: x, mode: ISGID) = 0 1000 -> 0.677 ( 0.040 ms): fchmodat(dfd: CWD, filename: x, mode: ISVTX) = 0 700 -> 0.394 ( 0.013 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXU) = 0 400 -> 0.337 ( 0.010 ms): fchmodat(dfd: CWD, filename: x, mode: IRUSR) = 0 200 -> 0.259 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IWUSR) = 0 100 -> 0.249 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IXUSR) = 0 70 -> 0.266 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXG) = 0 40 -> 0.329 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IRGRP) = 0 20 -> 0.250 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IWGRP) = 0 10 -> 0.259 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IXGRP) = 0 7 -> 0.249 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXO) = 0 4 -> 0.278 ( 0.011 ms): fchmodat(dfd: CWD, filename: x, mode: IROTH) = 0 2 -> 0.276 ( 0.009 ms): fchmodat(dfd: CWD, filename: x, mode: IWOTH) = 0 1 -> 0.250 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: IXOTH) = 0 # # trace --no-inherit -e chmod,fchmodat,fchmod chmod x 0.258 ( 0.011 ms): fchmodat(dfd: CWD, filename: x, mode: IALLUGO) = 0 # trace --no-inherit -e chmod,fchmodat,fchmod chmod 7770 x 0.258 ( 0.008 ms): fchmodat(dfd: CWD, filename: x, mode: ISUID|ISGID|ISVTX|IRWXU|IRWXG) = 0 # trace --no-inherit -e chmod,fchmodat,fchmod chmod 777 x 0.293 ( 0.012 ms): fchmodat(dfd: CWD, filename: x, mode: IRWXUGO # Now lets see if check by using the tracepoint for that specific syscall, instead of raw_syscalls:sys_enter as 'trace' does for its strace fu: # trace --no-inherit --ev syscalls:sys_enter_fchmodat -e fchmodat chmod 666 x 0.255 ( ): syscalls:sys_enter_fchmodat:dfd: 0xff9c, filename: 0x55db32a3f0f0, mode: 0x01b6) 0.268 ( 0.012 ms): fchmodat(dfd: CWD, filename: x, mode: IRUGO|IWUGO ) = 0 # Perfect, 0x1bc == 0666. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-18e8zfgbkj83xo87yoom4...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 3 ++ tools/perf/trace/beauty/mode_t.c | 68 2 files changed, 71 insertions(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 57d4bb4..8440e2b 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1126,6 +1126,7 @@ static size_t syscall_arg__scnprintf_getrandom_flags(char *bf, size_t size, .arg_parm = { [arg] = __##array, } #include "trace/beauty/pid.c" +#include "trace/beauty/mode_t.c" #include "trace/beauty/sched_policy.c" #include "trace/beauty/waitid_options.c" @@ -1767,6 +1768,8 @@ static int syscall__set_arg_fmts(struct syscall *sc) sc->arg_scnprintf[idx] = syscall_arg__scnprintf_hex; else if (strcmp(field->type, "pid_t") == 0) sc->arg_scnprintf[idx] = SCA_PID; + else if (strcmp(field->type, "umode_t") == 0) + sc->arg_scnprintf[idx] = SCA_MODE_T; ++idx; } diff --git a/tools/perf/trace/beauty/mode_t.c b/tools/perf/trace/beauty/mode_t.c new file mode 100644 index 000..930d8fe --- /dev/null +++ b/tools/perf/trace/beauty/mode_t.c @@
[tip:perf/core] perf tools: Allow generating per-arch syscall table arrays
Commit-ID: 5af56fab2b11769e35ce96613d321bcc0f7b84c1 Gitweb: http://git.kernel.org/tip/5af56fab2b11769e35ce96613d321bcc0f7b84c1 Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 4 Apr 2016 17:52:18 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 8 Apr 2016 09:58:14 -0300 perf tools: Allow generating per-arch syscall table arrays Tools should use a mechanism similar to arch/x86/entry/syscalls/ to generate a header file with the definitions for two variables: static const char *syscalltbl_x86_64[] = { [0] = "read", [1] = "write", [324] = "membarrier", [325] = "mlock2", [326] = "copy_file_range", }; static const int syscalltbl_x86_64_max_id = 326; In a per arch file that should then be included in tools/perf/util/syscalltbl.c. First one will be for x86_64. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-02uuamkxgccczdth8koms...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/syscalltbl.c | 89 +++- tools/perf/util/syscalltbl.h | 4 ++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/syscalltbl.c b/tools/perf/util/syscalltbl.c index 1f13e57..eb74a97 100644 --- a/tools/perf/util/syscalltbl.c +++ b/tools/perf/util/syscalltbl.c @@ -14,21 +14,105 @@ */ #include "syscalltbl.h" +#include + +#ifdef HAVE_SYSCALL_TABLE +#include #include -#include +#include "util.h" + +struct syscall { + int id; + const char *name; +}; +static int syscallcmpname(const void *vkey, const void *ventry) +{ + const char *key = vkey; + const struct syscall *entry = ventry; + + return strcmp(key, entry->name); +} + +static int syscallcmp(const void *va, const void *vb) +{ + const struct syscall *a = va, *b = vb; + + return strcmp(a->name, b->name); +} + +static int syscalltbl__init_native(struct syscalltbl *tbl) +{ + int nr_entries = 0, i, j; + struct syscall *entries; + + for (i = 0; i <= syscalltbl_native_max_id; ++i) + if (syscalltbl_native[i]) + ++nr_entries; + + entries = tbl->syscalls.entries = malloc(sizeof(struct syscall) * nr_entries); + if (tbl->syscalls.entries == NULL) + return -1; + + for (i = 0, j = 0; i <= syscalltbl_native_max_id; ++i) { + if (syscalltbl_native[i]) { + entries[j].name = syscalltbl_native[i]; + entries[j].id = i; + ++j; + } + } + + qsort(tbl->syscalls.entries, nr_entries, sizeof(struct syscall), syscallcmp); + tbl->syscalls.nr_entries = nr_entries; + return 0; +} struct syscalltbl *syscalltbl__new(void) { struct syscalltbl *tbl = malloc(sizeof(*tbl)); if (tbl) { - tbl->audit_machine = audit_detect_machine(); + if (syscalltbl__init_native(tbl)) { + free(tbl); + return NULL; + } } return tbl; } void syscalltbl__delete(struct syscalltbl *tbl) { + zfree(>syscalls.entries); + free(tbl); +} + +const char *syscalltbl__name(const struct syscalltbl *tbl __maybe_unused, int id) +{ + return id <= syscalltbl_native_max_id ? syscalltbl_native[id]: NULL; +} + +int syscalltbl__id(struct syscalltbl *tbl, const char *name) +{ + struct syscall *sc = bsearch(name, tbl->syscalls.entries, +tbl->syscalls.nr_entries, sizeof(*sc), +syscallcmpname); + + return sc ? sc->id : -1; +} + +#else /* HAVE_SYSCALL_TABLE */ + +#include + +struct syscalltbl *syscalltbl__new(void) +{ + struct syscalltbl *tbl = malloc(sizeof(*tbl)); + if (tbl) + tbl->audit_machine = audit_detect_machine(); + return tbl; +} + +void syscalltbl__delete(struct syscalltbl *tbl) +{ free(tbl); } @@ -41,3 +125,4 @@ int syscalltbl__id(struct syscalltbl *tbl, const char *name) { return audit_name_to_syscall(name, tbl->audit_machine); } +#endif /* HAVE_SYSCALL_TABLE */ diff --git a/tools/perf/util/syscalltbl.h b/tools/perf/util/syscalltbl.h index 9dee73c..e295151 100644 --- a/tools/perf/util/syscalltbl.h +++ b/tools/perf/util/syscalltbl.h @@ -4,6 +4,10 @@ struct syscalltbl { union { int audit_machine; + struct { + int nr_entries; + void *entries; + } syscalls; }; };
[tip:perf/core] perf trace: Move syscall table id <-> name routines to separate class
Commit-ID: fd0db10268b3729eb466fd726a39ce7d800bb150 Gitweb: http://git.kernel.org/tip/fd0db10268b3729eb466fd726a39ce7d800bb150 Author: Arnaldo Carvalho de MeloAuthorDate: Mon, 4 Apr 2016 13:32:20 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 8 Apr 2016 09:58:13 -0300 perf trace: Move syscall table id <-> name routines to separate class We're using libaudit for doing name to id and id to syscall name translations, but that makes 'perf trace' to have to wait for newer libaudit versions supporting recently added syscalls, such as "userfaultfd" at the time of this changeset. We have all the information right there, in the kernel sources, so move this code to a separate place, wrapped behind functions that will progressively use the kernel source files to extract the syscall table for use in 'perf trace'. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-i38opd09ow25mmyrvfwnb...@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 24 +++- tools/perf/util/Build| 1 + tools/perf/util/syscalltbl.c | 43 +++ tools/perf/util/syscalltbl.h | 16 4 files changed, 71 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 8440e2b..11290b5 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -34,8 +34,9 @@ #include "trace-event.h" #include "util/parse-events.h" #include "util/bpf-loader.h" +#include "syscalltbl.h" -#include +#include /* FIXME: Still needed for audit_errno_to_name */ #include #include #include @@ -114,10 +115,7 @@ struct trace { struct perf_tooltool; - struct { - int machine; - int open_id; - } audit; + struct syscalltbl *sctbl; struct { int max; struct syscall *table; @@ -163,6 +161,7 @@ struct trace { boolforce; boolvfs_getname; int trace_pgfaults; + int open_id; }; struct tp_field { @@ -1780,7 +1779,7 @@ static int trace__read_syscall_info(struct trace *trace, int id) { char tp_name[128]; struct syscall *sc; - const char *name = audit_syscall_to_name(id, trace->audit.machine); + const char *name = syscalltbl__name(trace->sctbl, id); if (name == NULL) return -1; @@ -1855,7 +1854,7 @@ static int trace__validate_ev_qualifier(struct trace *trace) strlist__for_each(pos, trace->ev_qualifier) { const char *sc = pos->s; - int id = audit_name_to_syscall(sc, trace->audit.machine); + int id = syscalltbl__id(trace->sctbl, sc); if (id < 0) { if (err == 0) { @@ -2137,7 +2136,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, ret = perf_evsel__sc_tp_uint(evsel, ret, sample); - if (id == trace->audit.open_id && ret >= 0 && ttrace->filename.pending_open) { + if (id == trace->open_id && ret >= 0 && ttrace->filename.pending_open) { trace__set_fd_pathname(thread, ret, ttrace->filename.name); ttrace->filename.pending_open = false; ++trace->stats.vfs_getname; @@ -3189,10 +3188,6 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) NULL }; struct trace trace = { - .audit = { - .machine = audit_detect_machine(), - .open_id = audit_name_to_syscall("open", trace.audit.machine), - }, .syscalls = { . max = -1, }, @@ -3267,8 +3262,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) signal(SIGFPE, sighandler_dump_stack); trace.evlist = perf_evlist__new(); + trace.sctbl = syscalltbl__new(); - if (trace.evlist == NULL) { + if (trace.evlist == NULL || trace.sctbl == NULL) { pr_err("Not enough memory to run!\n"); err = -ENOMEM; goto out; @@ -3306,6 +3302,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) } } + trace.open_id = syscalltbl__id(trace.sctbl, "open"); + if (ev_qualifier_str != NULL) { const char *s = ev_qualifier_str; struct strlist_config slist_config = { diff --git a/tools/perf/util/Build b/tools/perf/util/Build index