All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/26] perf/core improvements and fixes
@ 2016-01-26 19:18 Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 01/26] perf pmu: Fix misleadingly indented assignment (whitespace) Arnaldo Carvalho de Melo
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	Alexei Starovoitov, Andi Kleen, Ben Hutchings, Borislav Petkov,
	Brendan Gregg, Daniel Borkmann, David Ahern, David S. Miller,
	Frederic Weisbecker, He Kuang, Jiri Olsa, Kan Liang, Li Zefan,
	Markus Trippelsdorf, Masami Hiramatsu, Mathieu Poirier,
	Matt Fleming, Namhyung Kim, Pekka Enberg, Peter Zijlstra,
	pi3orama, Stephane Eranian, Taeung Song, Wang Nan, Will Deacon,
	Arnaldo Carvalho de Melo

Hi Ingo,

	Please consider pulling, this is on top of the perf-urgent-for-mingo
branch I sent you today.

- Arnaldo

The following changes since commit 3f416f22d1e21709a631189ba169f76fd267b374:

  perf stat: Do not clean event's private stats (2016-01-26 11:15:11 -0300)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo

for you to fetch changes up to 5ac76283b32b116c58e362e99542182ddcfc8262:

  perf cpumap: Auto initialize cpu__max_{node,cpu} (2016-01-26 16:08:36 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

User visible:

- Rename the "colors.code" ~/.perfconfig variable to "colors.jump_arrows",
  as it controls just the that UI element in the annotate browser (Taeung Song)

- Avoid trying to read ELF symtabs from device files, noticed while doing
  memory profiling work (Jiri Olsa)

- Improve context detection when offering options in the hists browser,
  i.e.  some options don't make sense when the browser is not working with
  a perf.data file ('perf top' mode), only in 'perf report' mode, like
  scripting (Namhyung Kim)

Infrastructure:

- Elliminate duplication in the hists browser filter functions, getting the
  common part into a function that receives callbacks for filtering by
  DSO, thread, etc (Namhyung Kim)

- Fix misleadingly indented assignment, found using
  gcc6 -Wmisleading-indentation (Markus Trippelsdorf)

- Handle LLVM relocation oddities in libbpf, introducing a 'perf test' that
  detects such problems and then fixing the problem, so that the test now
  passes (Wang Nan)

- More improvements to the build infrastructure to allow reusing the
  feature detection facilities (Wang Nan)

- Auto initialize the globals needed by cpu__max_{cpu,node}() routines
  (Arnaldo Carvalho de Melo)

Documentation:

- Document the perf sysctls in Documentation/sysctl/kernel.txt (Ben Hutchings)

- Document a bunch more ~/.perfconfig knobs (Taeung Song)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

----------------------------------------------------------------
Arnaldo Carvalho de Melo (3):
      perf machine: Introduce machine__find_kernel_symbol_by_name()
      perf test: Fixup aliases checking in the 'vmlinux matches kallsyms' test
      perf cpumap: Auto initialize cpu__max_{node,cpu}

Ben Hutchings (1):
      perf tools: Document the perf sysctls

Jiri Olsa (2):
      perf symbols: Do not read symbols/data from device files
      perf stat: Making several helper functions static

Markus Trippelsdorf (1):
      perf pmu: Fix misleadingly indented assignment (whitespace)

Namhyung Kim (9):
      perf hists: Remove parent filter check in DSO filter function
      perf hists: Cleanup filtering functions
      perf sort: Provide a way to find out if per-thread bucketing is in place
      perf hists browser: Only 'Zoom into thread' only when sort order has 'pid'
      perf hists browser: Only offer symbol scripting when a symbol is under the cursor
      perf hists browser: Offer 'Zoom into DSO'/'Map details' only when sort order has 'dso'
      perf hists browser: Be a bit more strict about presenting CPU socket zoom
      perf hists browser: Offer non-symbol specific menu options for --sort without 'sym'
      perf hists browser: Skip scripting when perf.data file not available

Taeung Song (6):
      perf annotate: Rename 'colors.code' to 'colors.jump_arrows'
      perf config: Document variables for 'colors' section in man page
      perf config: Document variables for 'tui' and 'gtk' sections in man page
      perf config: Document 'buildid.dir' variable in man page
      perf config: Document variables for 'annotate' section in man page
      perf config: Document 'hist.percentage' variable in man page

Wang Nan (4):
      perf test: Add libbpf relocation checker
      perf bpf: Check relocation target section
      tools build: Allow subprojects select all feature checkers
      perf build: Select all feature checkers for feature-dump

 Documentation/sysctl/kernel.txt               |  13 ++
 tools/build/Makefile.feature                  |  21 ++-
 tools/lib/bpf/libbpf.c                        |  34 +++--
 tools/perf/Documentation/perf-config.txt      | 200 +++++++++++++++++++++++++-
 tools/perf/Documentation/perfconfig.example   |   2 +-
 tools/perf/Makefile.perf                      |  11 +-
 tools/perf/tests/.gitignore                   |   1 +
 tools/perf/tests/Build                        |   9 +-
 tools/perf/tests/bpf-script-test-relocation.c |  50 +++++++
 tools/perf/tests/bpf.c                        |  26 +++-
 tools/perf/tests/llvm.c                       |  17 ++-
 tools/perf/tests/llvm.h                       |   5 +-
 tools/perf/tests/vmlinux-kallsyms.c           |  24 +---
 tools/perf/ui/browser.c                       |   4 +-
 tools/perf/ui/browser.h                       |   2 +-
 tools/perf/ui/browsers/annotate.c             |   2 +-
 tools/perf/ui/browsers/hists.c                |  38 ++---
 tools/perf/util/cpumap.c                      |  30 ++++
 tools/perf/util/cpumap.h                      |  32 +----
 tools/perf/util/dso.c                         |   5 +
 tools/perf/util/evsel.c                       |  15 +-
 tools/perf/util/hist.c                        |  92 ++++--------
 tools/perf/util/machine.h                     |  10 ++
 tools/perf/util/pmu.c                         |   2 +-
 tools/perf/util/sort.c                        |   3 +
 tools/perf/util/sort.h                        |   2 +
 tools/perf/util/stat.c                        |  14 +-
 tools/perf/util/stat.h                        |  10 --
 tools/perf/util/symbol.c                      |   6 +-
 tools/perf/util/util.c                        |  10 ++
 tools/perf/util/util.h                        |   1 +
 31 files changed, 507 insertions(+), 184 deletions(-)
 create mode 100644 tools/perf/tests/bpf-script-test-relocation.c

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 01/26] perf pmu: Fix misleadingly indented assignment (whitespace)
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 02/26] perf symbols: Do not read symbols/data from device files Arnaldo Carvalho de Melo
                   ` (24 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Markus Trippelsdorf, Ben Hutchings, Matt Fleming,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Markus Trippelsdorf <markus@trippelsdorf.de>

One line in perf_pmu__parse_unit() is indented wrongly, leading to a
warning (=> error) from gcc 6:

  util/pmu.c:156:3: error: statement is indented as if it were guarded by... [-Werror=misleading-indentation]

    sret = read(fd, alias->unit, UNIT_MAX_LEN);
    ^~~~

  util/pmu.c:153:2: note: ...this 'if' clause, but it is not
    if (fd == -1)
    ^~

Signed-off-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Fixes: 410136f5dd96 ("tools/perf/stat: Add event unit and scale support")
Link: http://lkml.kernel.org/r/20151214154440.GC1409@x4
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index b597bcc8fc78..41a9c875e492 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -153,7 +153,7 @@ static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *n
 	if (fd == -1)
 		return -1;
 
-		sret = read(fd, alias->unit, UNIT_MAX_LEN);
+	sret = read(fd, alias->unit, UNIT_MAX_LEN);
 	if (sret < 0)
 		goto error;
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 02/26] perf symbols: Do not read symbols/data from device files
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 01/26] perf pmu: Fix misleadingly indented assignment (whitespace) Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 03/26] perf stat: Making several helper functions static Arnaldo Carvalho de Melo
                   ` (23 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Jiri Olsa, David Ahern, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Jiri Olsa <jolsa@kernel.org>

With mem sampling we could get data source within mapped device file.
Processing such sample would block during report phase on trying to read
the device file.

Chacking for device files and skip the processing if it's detected.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1453290995-18485-2-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/dso.c    |  5 +++++
 tools/perf/util/symbol.c |  6 +++++-
 tools/perf/util/util.c   | 10 ++++++++++
 tools/perf/util/util.h   |  1 +
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index e8e9a9dbf5e3..8e6395439ca0 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -52,6 +52,11 @@ int dso__read_binary_type_filename(const struct dso *dso,
 			debuglink--;
 		if (*debuglink == '/')
 			debuglink++;
+
+		ret = -1;
+		if (!is_regular_file(filename))
+			break;
+
 		ret = filename__read_debuglink(filename, debuglink,
 					       size - (debuglink - filename));
 		}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index ab02209a7cf3..90cedfa30e43 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1466,7 +1466,8 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 	 * Read the build id if possible. This is required for
 	 * DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work
 	 */
-	if (filename__read_build_id(dso->long_name, build_id, BUILD_ID_SIZE) > 0)
+	if (is_regular_file(name) &&
+	    filename__read_build_id(dso->long_name, build_id, BUILD_ID_SIZE) > 0)
 		dso__set_build_id(dso, build_id);
 
 	/*
@@ -1487,6 +1488,9 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 						   root_dir, name, PATH_MAX))
 			continue;
 
+		if (!is_regular_file(name))
+			continue;
+
 		/* Name is now the name of the next image to try */
 		if (symsrc__init(ss, dso, name, symtab_type) < 0)
 			continue;
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index ead9509835d2..7a2da7ef556e 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -691,3 +691,13 @@ out:
 
 	return tip;
 }
+
+bool is_regular_file(const char *file)
+{
+	struct stat st;
+
+	if (stat(file, &st))
+		return false;
+
+	return S_ISREG(st.st_mode);
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index fe915e616f9b..61650f05e5c1 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -343,5 +343,6 @@ int fetch_kernel_version(unsigned int *puint,
 #define KVER_PARAM(x)	KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
 
 const char *perf_tip(const char *dirpath);
+bool is_regular_file(const char *file);
 
 #endif /* GIT_COMPAT_UTIL_H */
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 03/26] perf stat: Making several helper functions static
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 01/26] perf pmu: Fix misleadingly indented assignment (whitespace) Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 02/26] perf symbols: Do not read symbols/data from device files Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 04/26] perf hists: Remove parent filter check in DSO filter function Arnaldo Carvalho de Melo
                   ` (22 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Jiri Olsa, David Ahern, Namhyung Kim,
	Peter Zijlstra, Arnaldo Carvalho de Melo

From: Jiri Olsa <jolsa@kernel.org>

There's no need for the following functions to be global:

  perf_evsel__reset_stat_priv
  perf_evsel__alloc_stat_priv
  perf_evsel__free_stat_priv
  perf_evsel__alloc_prev_raw_counts
  perf_evsel__free_prev_raw_counts
  perf_evsel__alloc_stats

They all ended up in util/stat.c, and they no longer need to be called
from outside this object.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1453290995-18485-5-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/stat.c | 14 +++++++-------
 tools/perf/util/stat.h | 10 ----------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 2b58edccd56f..beeed0bd3bee 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -97,7 +97,7 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel)
 	}
 }
 
-void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
+static void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
 {
 	int i;
 	struct perf_stat_evsel *ps = evsel->priv;
@@ -108,7 +108,7 @@ void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
 	perf_stat_evsel_id_init(evsel);
 }
 
-int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
+static int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
 {
 	evsel->priv = zalloc(sizeof(struct perf_stat_evsel));
 	if (evsel->priv == NULL)
@@ -117,13 +117,13 @@ int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
 	return 0;
 }
 
-void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
+static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)
 {
 	zfree(&evsel->priv);
 }
 
-int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
-				      int ncpus, int nthreads)
+static int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
+					     int ncpus, int nthreads)
 {
 	struct perf_counts *counts;
 
@@ -134,13 +134,13 @@ int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
 	return counts ? 0 : -ENOMEM;
 }
 
-void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
+static void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel)
 {
 	perf_counts__delete(evsel->prev_raw_counts);
 	evsel->prev_raw_counts = NULL;
 }
 
-int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw)
+static int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw)
 {
 	int ncpus = perf_evsel__nr_cpus(evsel);
 	int nthreads = thread_map__nr(evsel->threads);
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 086f4e128d63..2af63c9cb59f 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -74,16 +74,6 @@ void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
 void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
 				   double avg, int cpu, enum aggr_mode aggr);
 
-void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
-int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
-void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
-
-int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
-				      int ncpus, int nthreads);
-void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
-
-int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
-
 int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
 void perf_evlist__free_stats(struct perf_evlist *evlist);
 void perf_evlist__reset_stats(struct perf_evlist *evlist);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 04/26] perf hists: Remove parent filter check in DSO filter function
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (2 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 03/26] perf stat: Making several helper functions static Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 05/26] perf hists: Cleanup filtering functions Arnaldo Carvalho de Melo
                   ` (21 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

The --exclude-other option sets HIST_FILTER__PARENT bit and it's only
set when a hist entry was created.  DSO filters don't change this so no
need to have the check in hists__filter_by_dso() IMHO.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1453252521-24398-1-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/hist.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 68a7612019dc..1d8c8eab9daa 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1266,9 +1266,6 @@ void hists__filter_by_dso(struct hists *hists)
 	for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
 		struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
 
-		if (symbol_conf.exclude_other && !h->parent)
-			continue;
-
 		if (hists__filter_entry_by_dso(hists, h))
 			continue;
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 05/26] perf hists: Cleanup filtering functions
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (3 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 04/26] perf hists: Remove parent filter check in DSO filter function Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 06/26] perf tools: Document the perf sysctls Arnaldo Carvalho de Melo
                   ` (20 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

The hists__filter_by_xxx functions share same logic with different
filters.  Factor out the common code into the hists__filter_by_type.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Pekka Enberg <penberg@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1453252521-24398-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/hist.c | 89 ++++++++++++++++----------------------------------
 1 file changed, 29 insertions(+), 60 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 1d8c8eab9daa..81ce0aff69d1 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1254,25 +1254,6 @@ static bool hists__filter_entry_by_dso(struct hists *hists,
 	return false;
 }
 
-void hists__filter_by_dso(struct hists *hists)
-{
-	struct rb_node *nd;
-
-	hists->stats.nr_non_filtered_samples = 0;
-
-	hists__reset_filter_stats(hists);
-	hists__reset_col_len(hists);
-
-	for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
-		struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
-
-		if (hists__filter_entry_by_dso(hists, h))
-			continue;
-
-		hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
-	}
-}
-
 static bool hists__filter_entry_by_thread(struct hists *hists,
 					  struct hist_entry *he)
 {
@@ -1285,25 +1266,6 @@ static bool hists__filter_entry_by_thread(struct hists *hists,
 	return false;
 }
 
-void hists__filter_by_thread(struct hists *hists)
-{
-	struct rb_node *nd;
-
-	hists->stats.nr_non_filtered_samples = 0;
-
-	hists__reset_filter_stats(hists);
-	hists__reset_col_len(hists);
-
-	for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
-		struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
-
-		if (hists__filter_entry_by_thread(hists, h))
-			continue;
-
-		hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
-	}
-}
-
 static bool hists__filter_entry_by_symbol(struct hists *hists,
 					  struct hist_entry *he)
 {
@@ -1317,25 +1279,6 @@ static bool hists__filter_entry_by_symbol(struct hists *hists,
 	return false;
 }
 
-void hists__filter_by_symbol(struct hists *hists)
-{
-	struct rb_node *nd;
-
-	hists->stats.nr_non_filtered_samples = 0;
-
-	hists__reset_filter_stats(hists);
-	hists__reset_col_len(hists);
-
-	for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
-		struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
-
-		if (hists__filter_entry_by_symbol(hists, h))
-			continue;
-
-		hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL);
-	}
-}
-
 static bool hists__filter_entry_by_socket(struct hists *hists,
 					  struct hist_entry *he)
 {
@@ -1348,7 +1291,9 @@ static bool hists__filter_entry_by_socket(struct hists *hists,
 	return false;
 }
 
-void hists__filter_by_socket(struct hists *hists)
+typedef bool (*filter_fn_t)(struct hists *hists, struct hist_entry *he);
+
+static void hists__filter_by_type(struct hists *hists, int type, filter_fn_t filter)
 {
 	struct rb_node *nd;
 
@@ -1360,13 +1305,37 @@ void hists__filter_by_socket(struct hists *hists)
 	for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
 		struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
 
-		if (hists__filter_entry_by_socket(hists, h))
+		if (filter(hists, h))
 			continue;
 
-		hists__remove_entry_filter(hists, h, HIST_FILTER__SOCKET);
+		hists__remove_entry_filter(hists, h, type);
 	}
 }
 
+void hists__filter_by_thread(struct hists *hists)
+{
+	hists__filter_by_type(hists, HIST_FILTER__THREAD,
+			      hists__filter_entry_by_thread);
+}
+
+void hists__filter_by_dso(struct hists *hists)
+{
+	hists__filter_by_type(hists, HIST_FILTER__DSO,
+			      hists__filter_entry_by_dso);
+}
+
+void hists__filter_by_symbol(struct hists *hists)
+{
+	hists__filter_by_type(hists, HIST_FILTER__SYMBOL,
+			      hists__filter_entry_by_symbol);
+}
+
+void hists__filter_by_socket(struct hists *hists)
+{
+	hists__filter_by_type(hists, HIST_FILTER__SOCKET,
+			      hists__filter_entry_by_socket);
+}
+
 void events_stats__inc(struct events_stats *stats, u32 type)
 {
 	++stats->nr_events[0];
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 06/26] perf tools: Document the perf sysctls
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (4 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 05/26] perf hists: Cleanup filtering functions Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 07/26] perf annotate: Rename 'colors.code' to 'colors.jump_arrows' Arnaldo Carvalho de Melo
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Ben Hutchings, Peter Zijlstra, linux-doc,
	Arnaldo Carvalho de Melo

From: Ben Hutchings <ben@decadent.org.uk>

perf_event_paranoid was only documented in source code and a perf error
message.  Copy the documentation from the error message to
Documentation/sysctl/kernel.txt.

perf_cpu_time_max_percent was already documented but missing from the
list at the top, so add it there.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-doc@vger.kernel.org
Link: http://lkml.kernel.org/r/20160119213515.GG2637@decadent.org.uk
[ Remove reference to external Documentation file, provide info inline, as before ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 Documentation/sysctl/kernel.txt | 13 +++++++++++++
 tools/perf/util/evsel.c         | 15 +++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index 73c6b1ef0e84..c803e7300f0b 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -58,6 +58,8 @@ show up in /proc/sys/kernel:
 - panic_on_stackoverflow
 - panic_on_unrecovered_nmi
 - panic_on_warn
+- perf_cpu_time_max_percent
+- perf_event_paranoid
 - pid_max
 - powersave-nap               [ PPC only ]
 - printk
@@ -639,6 +641,17 @@ allowed to execute.
 
 ==============================================================
 
+perf_event_paranoid:
+
+Controls use of the performance events system by unprivileged
+users (without CAP_SYS_ADMIN).  The default value is 1.
+
+ -1: Allow use of (almost) all events by all users
+>=0: Disallow raw tracepoint access by users without CAP_IOC_LOCK
+>=1: Disallow CPU event access by users without CAP_SYS_ADMIN
+>=2: Disallow kernel profiling by users without CAP_SYS_ADMIN
+
+==============================================================
 
 pid_max:
 
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index cdbaf9b51e42..467808680ee4 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2362,12 +2362,15 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
 	case EPERM:
 	case EACCES:
 		return scnprintf(msg, size,
-		 "You may not have permission to collect %sstats.\n"
-		 "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
-		 " -1 - Not paranoid at all\n"
-		 "  0 - Disallow raw tracepoint access for unpriv\n"
-		 "  1 - Disallow cpu events for unpriv\n"
-		 "  2 - Disallow kernel profiling for unpriv",
+		 "You may not have permission to collect %sstats.\n\n"
+		 "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n"
+		 "which controls use of the performance events system by\n"
+		 "unprivileged users (without CAP_SYS_ADMIN).\n\n"
+		 "The default value is 1:\n\n"
+		 "  -1: Allow use of (almost) all events by all users\n"
+		 ">= 0: Disallow raw tracepoint access by users without CAP_IOC_LOCK\n"
+		 ">= 1: Disallow CPU event access by users without CAP_SYS_ADMIN\n"
+		 ">= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN",
 				 target->system_wide ? "system-wide " : "");
 	case ENOENT:
 		return scnprintf(msg, size, "The %s event is not supported.",
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 07/26] perf annotate: Rename 'colors.code' to 'colors.jump_arrows'
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (5 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 06/26] perf tools: Document the perf sysctls Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 08/26] perf config: Document variables for 'colors' section in man page Arnaldo Carvalho de Melo
                   ` (18 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Taeung Song, Jiri Olsa, Namhyung Kim,
	Arnaldo Carvalho de Melo

From: Taeung Song <treeze.taeung@gmail.com>

USe 'jump_arrows' config name instead of 'code' on 'colors' section.
'colors.code' config is only for jump arrows on assembly code listings
i.e.

    │     ┌──jmp    1333
    │     │  xchg   %ax,%ax
    │     │  mov    %r15,%r10
    │     └─→cmp    %r15,%r14

But this config name seems unfit.

 'jump_arrows' is more descriptive than 'code'.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1452240971-25418-1-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-config.txt    | 2 +-
 tools/perf/Documentation/perfconfig.example | 2 +-
 tools/perf/ui/browser.c                     | 4 ++--
 tools/perf/ui/browser.h                     | 2 +-
 tools/perf/ui/browsers/annotate.c           | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index b9ca1e304158..1ee488b9aaf7 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -62,7 +62,7 @@ Given a $HOME/.perfconfig like this:
 		medium = green, default
 		normal = lightgray, default
 		selected = white, lightgray
-		code = blue, default
+		jump_arrows = blue, default
 		addr = magenta, default
 		root = white, blue
 
diff --git a/tools/perf/Documentation/perfconfig.example b/tools/perf/Documentation/perfconfig.example
index 767ea2436e1c..1d8d5bc4cd2d 100644
--- a/tools/perf/Documentation/perfconfig.example
+++ b/tools/perf/Documentation/perfconfig.example
@@ -5,7 +5,7 @@
 	medium = green, lightgray
 	normal = black, lightgray
 	selected = lightgray, magenta
-	code = blue, lightgray
+	jump_arrows = blue, lightgray
 	addr = magenta, lightgray
 
 [tui]
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index d37202121689..af68a9d488bf 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -531,8 +531,8 @@ static struct ui_browser_colorset {
 		.bg	  = "yellow",
 	},
 	{
-		.colorset = HE_COLORSET_CODE,
-		.name	  = "code",
+		.colorset = HE_COLORSET_JUMP_ARROWS,
+		.name	  = "jump_arrows",
 		.fg	  = "blue",
 		.bg	  = "default",
 	},
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index 01781de59532..be3b70eb5fca 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -7,7 +7,7 @@
 #define HE_COLORSET_MEDIUM	51
 #define HE_COLORSET_NORMAL	52
 #define HE_COLORSET_SELECTED	53
-#define HE_COLORSET_CODE	54
+#define HE_COLORSET_JUMP_ARROWS	54
 #define HE_COLORSET_ADDR	55
 #define HE_COLORSET_ROOT	56
 
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 718bd46d47fa..4fc208e82c6f 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -284,7 +284,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
 		to = (u64)btarget->idx;
 	}
 
-	ui_browser__set_color(browser, HE_COLORSET_CODE);
+	ui_browser__set_color(browser, HE_COLORSET_JUMP_ARROWS);
 	__ui_browser__line_arrow(browser, pcnt_width + 2 + ab->addr_width,
 				 from, to);
 }
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 08/26] perf config: Document variables for 'colors' section in man page
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (6 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 07/26] perf annotate: Rename 'colors.code' to 'colors.jump_arrows' Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 09/26] perf config: Document variables for 'tui' and 'gtk' sections " Arnaldo Carvalho de Melo
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Taeung Song, Jiri Olsa, Namhyung Kim,
	Arnaldo Carvalho de Melo

From: Taeung Song <treeze.taeung@gmail.com>

Explain 'colors' section and its variables, used for The variables for
customizing the colors used in the output for the 'report', 'top' and
'annotate' in the TUI, those are:

'top', 'medium', 'normal', 'selected',
'jump_arrows', 'addr' and 'root'.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1452253193-30502-2-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-config.txt | 46 ++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 1ee488b9aaf7..80517823b7e5 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -98,6 +98,52 @@ Given a $HOME/.perfconfig like this:
 		order = caller
 		sort-key = function
 
+Variables
+~~~~~~~~~
+
+colors.*::
+	The variables for customizing the colors used in the output for the
+	'report', 'top' and 'annotate' in the TUI. They should specify the
+	foreground and background colors, separated by a comma, for example:
+
+		medium = green, lightgray
+
+	If you want to use the color configured for you terminal, just leave it
+	as 'default', for example:
+
+		medium = default, lightgray
+
+	Available colors:
+	red, yellow, green, cyan, gray, black, blue,
+	white, default, magenta, lightgray
+
+	colors.top::
+		'top' means a overhead percentage which is more than 5%.
+		And values of this variable specify percentage colors.
+		Basic key values are foreground-color 'red' and
+		background-color 'default'.
+	colors.medium::
+		'medium' means a overhead percentage which has more than 0.5%.
+		Default values are 'green' and 'default'.
+	colors.normal::
+		'normal' means the rest of overhead percentages
+		except 'top', 'medium', 'selected'.
+		Default values are 'lightgray' and 'default'.
+	colors.selected::
+		This selects the colors for the current entry in a list of entries
+		from sub-commands (top, report, annotate).
+		Default values are 'black' and 'lightgray'.
+	colors.jump_arrows::
+		Colors for jump arrows on assembly code listings
+		such as 'jns', 'jmp', 'jane', etc.
+		Default values are 'blue', 'default'.
+	colors.addr::
+		This selects colors for addresses from 'annotate'.
+		Default values are 'magenta', 'default'.
+	colors.root::
+		Colors for headers in the output of a sub-commands (top, report).
+		Default values are 'white', 'blue'.
+
 SEE ALSO
 --------
 linkperf:perf[1]
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 09/26] perf config: Document variables for 'tui' and 'gtk' sections in man page
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (7 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 08/26] perf config: Document variables for 'colors' section in man page Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:18 ` [PATCH 10/26] perf config: Document 'buildid.dir' variable " Arnaldo Carvalho de Melo
                   ` (16 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Taeung Song, Jiri Olsa, Namhyung Kim,
	Arnaldo Carvalho de Melo

From: Taeung Song <treeze.taeung@gmail.com>

Explain 'tui' and 'gtk' sections and these variables.

'top', 'report' and 'annotate'

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1452253193-30502-3-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-config.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 80517823b7e5..ccbdb64696a7 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -144,6 +144,16 @@ colors.*::
 		Colors for headers in the output of a sub-commands (top, report).
 		Default values are 'white', 'blue'.
 
+tui.*, gtk.*::
+	Subcommands that can be configured here are 'top', 'report' and 'annotate'.
+	These values are booleans, for example:
+
+	[tui]
+		top = true
+
+	will make the TUI be the default for the 'top' subcommand. Those will be
+	available if the required libs were detected at tool build time.
+
 SEE ALSO
 --------
 linkperf:perf[1]
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 10/26] perf config: Document 'buildid.dir' variable in man page
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (8 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 09/26] perf config: Document variables for 'tui' and 'gtk' sections " Arnaldo Carvalho de Melo
@ 2016-01-26 19:18 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 11/26] perf config: Document variables for 'annotate' section " Arnaldo Carvalho de Melo
                   ` (15 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Taeung Song, Jiri Olsa, Namhyung Kim,
	Arnaldo Carvalho de Melo

From: Taeung Song <treeze.taeung@gmail.com>

Explain 'buildid.dir' variable.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1452253193-30502-4-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-config.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index ccbdb64696a7..a095f0cabf5e 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -154,6 +154,21 @@ tui.*, gtk.*::
 	will make the TUI be the default for the 'top' subcommand. Those will be
 	available if the required libs were detected at tool build time.
 
+buildid.*::
+	buildid.dir::
+		Each executable and shared library in modern distributions comes with a
+		content based identifier that, if available, will be inserted in a
+		'perf.data' file header to, at analysis time find what is needed to do
+		symbol resolution, code annotation, etc.
+
+		The recording tools also stores a hard link or copy in a per-user
+		directory, $HOME/.debug/, of binaries, shared libraries, /proc/kallsyms
+		and /proc/kcore files to be used at analysis time.
+
+		The buildid.dir variable can be used to either change this directory
+		cache location, or to disable it altogether. If you want to disable it,
+		set buildid.dir to /dev/null. The default is $HOME/.debug
+
 SEE ALSO
 --------
 linkperf:perf[1]
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 11/26] perf config: Document variables for 'annotate' section in man page
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (9 preceding siblings ...)
  2016-01-26 19:18 ` [PATCH 10/26] perf config: Document 'buildid.dir' variable " Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 12/26] perf config: Document 'hist.percentage' variable " Arnaldo Carvalho de Melo
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Taeung Song, Jiri Olsa, Namhyung Kim,
	Arnaldo Carvalho de Melo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=a, Size: 4648 bytes --]

From: Taeung Song <treeze.taeung@gmail.com>

Explain 'annotate' section and its variables.

'hide_src_code', 'use_offset', 'jump_arrows',
'show_linenr', 'show_nr_jump' and 'show_total_period'.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1452253193-30502-5-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-config.txt | 110 +++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index a095f0cabf5e..cb7ca507ec5e 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -169,6 +169,116 @@ buildid.*::
 		cache location, or to disable it altogether. If you want to disable it,
 		set buildid.dir to /dev/null. The default is $HOME/.debug
 
+annotate.*::
+	These options work only for TUI.
+	These are in control of addresses, jump function, source code
+	in lines of assembly code from a specific program.
+
+	annotate.hide_src_code::
+		If a program which is analyzed has source code,
+		this option lets 'annotate' print a list of assembly code with the source code.
+		For example, let's see a part of a program. There're four lines.
+		If this option is 'true', they can be printed
+		without source code from a program as below.
+
+		│        push   %rbp
+		│        mov    %rsp,%rbp
+		│        sub    $0x10,%rsp
+		│        mov    (%rdi),%rdx
+
+		But if this option is 'false', source code of the part
+		can be also printed as below. Default is 'false'.
+
+		│      struct rb_node *rb_next(const struct rb_node *node)
+		│      {
+		│        push   %rbp
+		│        mov    %rsp,%rbp
+		│        sub    $0x10,%rsp
+		│              struct rb_node *parent;
+		│
+		│              if (RB_EMPTY_NODE(node))
+		│        mov    (%rdi),%rdx
+		│              return n;
+
+        annotate.use_offset::
+		Basing on a first address of a loaded function, offset can be used.
+		Instead of using original addresses of assembly code,
+		addresses subtracted from a base address can be printed.
+		Let's illustrate an example.
+		If a base address is 0XFFFFFFFF81624d50 as below,
+
+		ffffffff81624d50 <load0>
+
+		an address on assembly code has a specific absolute address as below
+
+		ffffffff816250b8:│  mov    0x8(%r14),%rdi
+
+		but if use_offset is 'true', an address subtracted from a base address is printed.
+		Default is true. This option is only applied to TUI.
+
+		             368:│  mov    0x8(%r14),%rdi
+
+	annotate.jump_arrows::
+		There can be jump instruction among assembly code.
+		Depending on a boolean value of jump_arrows,
+		arrows can be printed or not which represent
+		where do the instruction jump into as below.
+
+		│     ┌──jmp    1333
+		│     │  xchg   %ax,%ax
+		│1330:│  mov    %r15,%r10
+		│1333:└─→cmp    %r15,%r14
+
+		If jump_arrow is 'false', the arrows isn't printed as below.
+		Default is 'false'.
+
+		│      ↓ jmp    1333
+		│        xchg   %ax,%ax
+		│1330:   mov    %r15,%r10
+		│1333:   cmp    %r15,%r14
+
+        annotate.show_linenr::
+		When showing source code if this option is 'true',
+		line numbers are printed as below.
+
+		│1628         if (type & PERF_SAMPLE_IDENTIFIER) {
+		│     ↓ jne    508
+		│1628                 data->id = *array;
+		│1629                 array++;
+		│1630         }
+
+		However if this option is 'false', they aren't printed as below.
+		Default is 'false'.
+
+		│             if (type & PERF_SAMPLE_IDENTIFIER) {
+		│     ↓ jne    508
+		│                     data->id = *array;
+		│                     array++;
+		│             }
+
+        annotate.show_nr_jumps::
+		Let's see a part of assembly code.
+
+		│1382:   movb   $0x1,-0x270(%rbp)
+
+		If use this, the number of branches jumping to that address can be printed as below.
+		Default is 'false'.
+
+		│1 1382:   movb   $0x1,-0x270(%rbp)
+
+        annotate.show_total_period::
+		To compare two records on an instruction base, with this option
+		provided, display total number of samples that belong to a line
+		in assembly code. If this option is 'true', total periods are printed
+		instead of percent values as below.
+
+		  302 │      mov    %eax,%eax
+
+		But if this option is 'false', percent values for overhead are printed i.e.
+		Default is 'false'.
+
+		99.93 │      mov    %eax,%eax
+
 SEE ALSO
 --------
 linkperf:perf[1]
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 12/26] perf config: Document 'hist.percentage' variable in man page
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (10 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 11/26] perf config: Document variables for 'annotate' section " Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 13/26] perf sort: Provide a way to find out if per-thread bucketing is in place Arnaldo Carvalho de Melo
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Taeung Song, Jiri Olsa, Namhyung Kim,
	Arnaldo Carvalho de Melo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=a, Size: 1456 bytes --]

From: Taeung Song <treeze.taeung@gmail.com>

Explain 'hist.percentage' variable.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1452253193-30502-7-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-config.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index cb7ca507ec5e..74589c68558a 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -279,6 +279,23 @@ annotate.*::
 
 		99.93 │      mov    %eax,%eax
 
+hist.*::
+	hist.percentage::
+		This option control the way to calculate overhead of filtered entries -
+		that means the value of this option is effective only if there's a
+		filter (by comm, dso or symbol name). Suppose a following example:
+
+		       Overhead  Symbols
+		       ........  .......
+		        33.33%     foo
+		        33.33%     bar
+		        33.33%     baz
+
+	       This is an original overhead and we'll filter out the first 'foo'
+	       entry. The value of 'relative' would increase the overhead of 'bar'
+	       and 'baz' to 50.00% for each, while 'absolute' would show their
+	       current overhead (33.33%).
+
 SEE ALSO
 --------
 linkperf:perf[1]
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 13/26] perf sort: Provide a way to find out if per-thread bucketing is in place
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (11 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 12/26] perf config: Document 'hist.percentage' variable " Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 14/26] perf hists browser: Only 'Zoom into thread' only when sort order has 'pid' Arnaldo Carvalho de Melo
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern, Jiri Olsa,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

Now the UI browsers will be able to offer thread related operations only
if the thread is part of the sort order in use, i.e. if hist_entry stats
are all for a single thread.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452960197-5323-9-git-send-email-namhyung@kernel.org
[ Carved out from a  larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/sort.c | 3 +++
 tools/perf/util/sort.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index ec722346e6ff..898e4b0724bf 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -25,6 +25,7 @@ int		sort__has_parent = 0;
 int		sort__has_sym = 0;
 int		sort__has_dso = 0;
 int		sort__has_socket = 0;
+int		sort__has_thread = 0;
 enum sort_mode	sort__mode = SORT_MODE__NORMAL;
 
 
@@ -2136,6 +2137,8 @@ static int sort_dimension__add(const char *tok,
 			sort__has_dso = 1;
 		} else if (sd->entry == &sort_socket) {
 			sort__has_socket = 1;
+		} else if (sd->entry == &sort_thread) {
+			sort__has_thread = 1;
 		}
 
 		return __sort_dimension__add(sd);
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 687bbb124428..09616f03d412 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -35,6 +35,7 @@ extern int sort__need_collapse;
 extern int sort__has_parent;
 extern int sort__has_sym;
 extern int sort__has_socket;
+extern int sort__has_thread;
 extern enum sort_mode sort__mode;
 extern struct sort_entry sort_comm;
 extern struct sort_entry sort_dso;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 14/26] perf hists browser: Only 'Zoom into thread' only when sort order has 'pid'
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (12 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 13/26] perf sort: Provide a way to find out if per-thread bucketing is in place Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 15/26] perf hists browser: Only offer symbol scripting when a symbol is under the cursor Arnaldo Carvalho de Melo
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern, Jiri Olsa,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

We can't offer a zoom into thread when a bucket (struct hist_entry) may
have samples for more than one thread, i.e. when 'pid' is not part of
the sort order, fix it.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452960197-5323-9-git-send-email-namhyung@kernel.org
[ Carved out from a  larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/hists.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 08c09ad755d2..e66b3a30dd9f 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1782,7 +1782,7 @@ static int
 add_thread_opt(struct hist_browser *browser, struct popup_action *act,
 	       char **optstr, struct thread *thread)
 {
-	if (thread == NULL)
+	if (!sort__has_thread || thread == NULL)
 		return 0;
 
 	if (asprintf(optstr, "Zoom %s %s(%d) thread",
@@ -2307,10 +2307,12 @@ skip_annotation:
 					     socked_id);
 		/* perf script support */
 		if (browser->he_selection) {
-			nr_options += add_script_opt(browser,
-						     &actions[nr_options],
-						     &options[nr_options],
-						     thread, NULL);
+			if (sort__has_thread && thread) {
+				nr_options += add_script_opt(browser,
+							     &actions[nr_options],
+							     &options[nr_options],
+							     thread, NULL);
+			}
 			/*
 			 * Note that browser->selection != NULL
 			 * when browser->he_selection is not NULL,
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 15/26] perf hists browser: Only offer symbol scripting when a symbol is under the cursor
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (13 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 14/26] perf hists browser: Only 'Zoom into thread' only when sort order has 'pid' Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 16/26] perf hists browser: Offer 'Zoom into DSO'/'Map details' only when sort order has 'dso' Arnaldo Carvalho de Melo
                   ` (10 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern, Jiri Olsa,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

When this feature was introduced a check was made if there was a
resolved symbol under the cursor, it got lost in commit ea7cd5923309
("perf hists browser: Split popup menu actions - part 2"), reinstate it.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Fixes: ea7cd5923309 ("perf hists browser: Split popup menu actions - part 2")
Link: http://lkml.kernel.org/r/1452960197-5323-9-git-send-email-namhyung@kernel.org
[ Carved out from a  larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/hists.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index e66b3a30dd9f..2801d80c6903 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2322,10 +2322,12 @@ skip_annotation:
 			 *
 			 * See hist_browser__show_entry.
 			 */
-			nr_options += add_script_opt(browser,
-						     &actions[nr_options],
-						     &options[nr_options],
-						     NULL, browser->selection->sym);
+			if (sort__has_sym && browser->selection->sym) {
+				nr_options += add_script_opt(browser,
+							     &actions[nr_options],
+							     &options[nr_options],
+							     NULL, browser->selection->sym);
+			}
 		}
 		nr_options += add_script_opt(browser, &actions[nr_options],
 					     &options[nr_options], NULL, NULL);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 16/26] perf hists browser: Offer 'Zoom into DSO'/'Map details' only when sort order has 'dso'
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (14 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 15/26] perf hists browser: Only offer symbol scripting when a symbol is under the cursor Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 17/26] perf hists browser: Be a bit more strict about presenting CPU socket zoom Arnaldo Carvalho de Melo
                   ` (9 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern, Jiri Olsa,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

We can't offer a zoom into DSO when a bucket (struct hist_entry) may
have samples for more than one DSO, i.e. when 'dso' is not part of
the sort order, ditto for 'Map details', fix it.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452960197-5323-9-git-send-email-namhyung@kernel.org
[ Carved out from a  larger patch, moved check to add_{dso,map}_opt() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/hists.c | 4 ++--
 tools/perf/util/sort.h         | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 2801d80c6903..e892106410a7 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1825,7 +1825,7 @@ static int
 add_dso_opt(struct hist_browser *browser, struct popup_action *act,
 	    char **optstr, struct map *map)
 {
-	if (map == NULL)
+	if (!sort__has_dso || map == NULL)
 		return 0;
 
 	if (asprintf(optstr, "Zoom %s %s DSO",
@@ -1850,7 +1850,7 @@ static int
 add_map_opt(struct hist_browser *browser __maybe_unused,
 	    struct popup_action *act, char **optstr, struct map *map)
 {
-	if (map == NULL)
+	if (!sort__has_dso || map == NULL)
 		return 0;
 
 	if (asprintf(optstr, "Browse map details") < 0)
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 09616f03d412..89a1273fd2da 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -32,6 +32,7 @@ extern const char default_sort_order[];
 extern regex_t ignore_callees_regex;
 extern int have_ignore_callees;
 extern int sort__need_collapse;
+extern int sort__has_dso;
 extern int sort__has_parent;
 extern int sort__has_sym;
 extern int sort__has_socket;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 17/26] perf hists browser: Be a bit more strict about presenting CPU socket zoom
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (15 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 16/26] perf hists browser: Offer 'Zoom into DSO'/'Map details' only when sort order has 'dso' Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 18/26] perf hists browser: Offer non-symbol specific menu options for --sort without 'sym' Arnaldo Carvalho de Melo
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern, Jiri Olsa,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

For consistency with the other sort order checks.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452960197-5323-9-git-send-email-namhyung@kernel.org
[ Carved out from a  larger patch, moved check to add_socket_opt() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/hists.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index e892106410a7..b919582add0f 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1971,7 +1971,7 @@ static int
 add_socket_opt(struct hist_browser *browser, struct popup_action *act,
 	       char **optstr, int socket_id)
 {
-	if (socket_id < 0)
+	if (!sort__has_socket || socket_id < 0)
 		return 0;
 
 	if (asprintf(optstr, "Zoom %s Processor Socket %d",
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 18/26] perf hists browser: Offer non-symbol specific menu options for --sort without 'sym'
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (16 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 17/26] perf hists browser: Be a bit more strict about presenting CPU socket zoom Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 19/26] perf machine: Introduce machine__find_kernel_symbol_by_name() Arnaldo Carvalho de Melo
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern, Jiri Olsa,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

Now that we check more strictly what each of the menu entries need, we
can stop bailing out when 'sym' is not in the --sort order, instead we
let each option be added if what it needs is present.

This way, for instance, we can run scripts on all samples, see DSO map
details when 'dso' is in the --sort provided, etc.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452960197-5323-9-git-send-email-namhyung@kernel.org
[ Carved out from a  larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/hists.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index b919582add0f..d07e6be42ab1 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2263,10 +2263,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 			continue;
 		}
 
-		if (!sort__has_sym)
-			goto add_exit_option;
-
-		if (browser->selection == NULL)
+		if (!sort__has_sym || browser->selection == NULL)
 			goto skip_annotation;
 
 		if (sort__mode == SORT_MODE__BRANCH) {
@@ -2333,7 +2330,6 @@ skip_annotation:
 					     &options[nr_options], NULL, NULL);
 		nr_options += add_switch_opt(browser, &actions[nr_options],
 					     &options[nr_options]);
-add_exit_option:
 		nr_options += add_exit_opt(browser, &actions[nr_options],
 					   &options[nr_options]);
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 19/26] perf machine: Introduce machine__find_kernel_symbol_by_name()
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (17 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 18/26] perf hists browser: Offer non-symbol specific menu options for --sort without 'sym' Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 20/26] perf test: Fixup aliases checking in the 'vmlinux matches kallsyms' test Arnaldo Carvalho de Melo
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	David Ahern, Jiri Olsa, Namhyung Kim, Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

To be used in the 'vmlinux matches kallsyms' 'perf test'  entry.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-m56g1853lz2c6nhnqxibq4jd@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 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 2c2b443df5ba..1a3e45baf97f 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(&machine->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)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 20/26] perf test: Fixup aliases checking in the 'vmlinux matches kallsyms' test
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (18 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 19/26] perf machine: Introduce machine__find_kernel_symbol_by_name() Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 21/26] perf test: Add libbpf relocation checker Arnaldo Carvalho de Melo
                   ` (5 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	David Ahern, Jiri Olsa, Namhyung Kim, Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

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 ffffffff81065ec0
   4979: ffffffff81065ec0 53 FUNC  LOCAL  DEFAULT 1 try_to_free_pud_page
   4980: ffffffff81065ec0 53 FUNC  LOCAL  DEFAULT 1 try_to_free_pte_page
   4981: ffffffff81065ec0 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 <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-jj1vlljg7ol4i713l60rt5ai@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 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 f0bfc9e8fd9f..630b0b409b97 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(&vmlinux_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(&pair->rb_node) :
-						  rb_next(&pair->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(&kallsyms, 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",
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 21/26] perf test: Add libbpf relocation checker
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (19 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 20/26] perf test: Fixup aliases checking in the 'vmlinux matches kallsyms' test Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 22/26] perf bpf: Check relocation target section Arnaldo Carvalho de Melo
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Wang Nan, David S. Miller, Alexei Starovoitov,
	Brendan Gregg, Daniel Borkmann, He Kuang, Jiri Olsa, Li Zefan,
	Masami Hiramatsu, Namhyung Kim, Peter Zijlstra, Will Deacon,
	pi3orama, Arnaldo Carvalho de Melo

From: Wang Nan <wangnan0@huawei.com>

There's a bug in LLVM that it can generate unneeded relocation
information. See [1] and [2]. Libbpf should check the target section of
a relocation symbol.

This patch adds a testcase which references a global variable (BPF
doesn't support global variables). Before fixing libbpf, the new test
case can be loaded into kernel, the global variable acts like the first
map. It is incorrect.

Result:

  # ~/perf test BPF
  37: Test BPF filter                                          :
  37.1: Test basic BPF filtering                               : Ok
  37.2: Test BPF prologue generation                           : Ok
  37.3: Test BPF relocation checker                            : FAILED!

  # ~/perf test -v BPF
  ...
  libbpf: loading object '[bpf_relocation_test]' from buffer
  libbpf: section .strtab, size 126, link 0, flags 0, type=3
  libbpf: section .text, size 0, link 0, flags 6, type=1
  libbpf: section .data, size 0, link 0, flags 3, type=1
  libbpf: section .bss, size 0, link 0, flags 3, type=8
  libbpf: section func=sys_write, size 104, link 0, flags 6, type=1
  libbpf: found program func=sys_write
  libbpf: section .relfunc=sys_write, size 16, link 10, flags 0, type=9
  libbpf: section maps, size 16, link 0, flags 3, type=1
  libbpf: maps in [bpf_relocation_test]: 16 bytes
  libbpf: section license, size 4, link 0, flags 3, type=1
  libbpf: license of [bpf_relocation_test] is GPL
  libbpf: section version, size 4, link 0, flags 3, type=1
  libbpf: kernel version of [bpf_relocation_test] is 40400
  libbpf: section .symtab, size 144, link 1, flags 0, type=2
  libbpf: map 0 is "my_table"
  libbpf: collecting relocating info for: 'func=sys_write'
  libbpf: relocation: insn_idx=7
  Success unexpectedly: libbpf error when dealing with relocation
  test child finished with -1
  ---- end ----
  Test BPF filter subtest 2: FAILED!

[1] https://llvm.org/bugs/show_bug.cgi?id=26243
[2] https://patchwork.ozlabs.org/patch/571385/

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1453715801-7732-2-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.perf                      |  2 +-
 tools/perf/tests/.gitignore                   |  1 +
 tools/perf/tests/Build                        |  9 ++++-
 tools/perf/tests/bpf-script-test-relocation.c | 50 +++++++++++++++++++++++++++
 tools/perf/tests/bpf.c                        | 26 +++++++++++---
 tools/perf/tests/llvm.c                       | 17 ++++++---
 tools/perf/tests/llvm.h                       |  5 ++-
 7 files changed, 98 insertions(+), 12 deletions(-)
 create mode 100644 tools/perf/tests/bpf-script-test-relocation.c

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 5d34815c7ccb..97ce8695199e 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -618,7 +618,7 @@ clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean
 	$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
 	$(call QUIET_CLEAN, core-gen)   $(RM)  *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
 		$(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \
-		$(OUTPUT)tests/llvm-src-{base,kbuild,prologue}.c
+		$(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c
 	$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
 	$(python-clean)
 
diff --git a/tools/perf/tests/.gitignore b/tools/perf/tests/.gitignore
index bf016c439fbd..8cc30e731c73 100644
--- a/tools/perf/tests/.gitignore
+++ b/tools/perf/tests/.gitignore
@@ -1,3 +1,4 @@
 llvm-src-base.c
 llvm-src-kbuild.c
 llvm-src-prologue.c
+llvm-src-relocation.c
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 614899b88b37..1ba628ed049a 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -31,7 +31,7 @@ perf-y += sample-parsing.o
 perf-y += parse-no-sample-id-all.o
 perf-y += kmod-path.o
 perf-y += thread-map.o
-perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o
+perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o llvm-src-relocation.o
 perf-y += bpf.o
 perf-y += topology.o
 perf-y += cpumap.o
@@ -59,6 +59,13 @@ $(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c tests/Build
 	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
 	$(Q)echo ';' >> $@
 
+$(OUTPUT)tests/llvm-src-relocation.c: tests/bpf-script-test-relocation.c tests/Build
+	$(call rule_mkdir)
+	$(Q)echo '#include <tests/llvm.h>' > $@
+	$(Q)echo 'const char test_llvm__bpf_test_relocation[] =' >> $@
+	$(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@
+	$(Q)echo ';' >> $@
+
 ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))
 perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
 endif
diff --git a/tools/perf/tests/bpf-script-test-relocation.c b/tools/perf/tests/bpf-script-test-relocation.c
new file mode 100644
index 000000000000..93af77421816
--- /dev/null
+++ b/tools/perf/tests/bpf-script-test-relocation.c
@@ -0,0 +1,50 @@
+/*
+ * bpf-script-test-relocation.c
+ * Test BPF loader checking relocation
+ */
+#ifndef LINUX_VERSION_CODE
+# error Need LINUX_VERSION_CODE
+# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
+#endif
+#define BPF_ANY 0
+#define BPF_MAP_TYPE_ARRAY 2
+#define BPF_FUNC_map_lookup_elem 1
+#define BPF_FUNC_map_update_elem 2
+
+static void *(*bpf_map_lookup_elem)(void *map, void *key) =
+	(void *) BPF_FUNC_map_lookup_elem;
+static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
+	(void *) BPF_FUNC_map_update_elem;
+
+struct bpf_map_def {
+	unsigned int type;
+	unsigned int key_size;
+	unsigned int value_size;
+	unsigned int max_entries;
+};
+
+#define SEC(NAME) __attribute__((section(NAME), used))
+struct bpf_map_def SEC("maps") my_table = {
+	.type = BPF_MAP_TYPE_ARRAY,
+	.key_size = sizeof(int),
+	.value_size = sizeof(int),
+	.max_entries = 1,
+};
+
+int this_is_a_global_val;
+
+SEC("func=sys_write")
+int bpf_func__sys_write(void *ctx)
+{
+	int key = 0;
+	int value = 0;
+
+	/*
+	 * Incorrect relocation. Should not allow this program be
+	 * loaded into kernel.
+	 */
+	bpf_map_update_elem(&this_is_a_global_val, &key, &value, 0);
+	return 0;
+}
+char _license[] SEC("license") = "GPL";
+int _version SEC("version") = LINUX_VERSION_CODE;
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 33689a0cf821..952ca99aba6b 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -71,6 +71,15 @@ static struct {
 		(NR_ITERS + 1) / 4,
 	},
 #endif
+	{
+		LLVM_TESTCASE_BPF_RELOCATION,
+		"Test BPF relocation checker",
+		"[bpf_relocation_test]",
+		"fix 'perf test LLVM' first",
+		"libbpf error when dealing with relocation",
+		NULL,
+		0,
+	},
 };
 
 static int do_test(struct bpf_object *obj, int (*func)(void),
@@ -190,7 +199,7 @@ static int __test__bpf(int idx)
 
 	ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz,
 				       bpf_testcase_table[idx].prog_id,
-				       true);
+				       true, NULL);
 	if (ret != TEST_OK || !obj_buf || !obj_buf_sz) {
 		pr_debug("Unable to get BPF object, %s\n",
 			 bpf_testcase_table[idx].msg_compile_fail);
@@ -202,14 +211,21 @@ static int __test__bpf(int idx)
 
 	obj = prepare_bpf(obj_buf, obj_buf_sz,
 			  bpf_testcase_table[idx].name);
-	if (!obj) {
+	if ((!!bpf_testcase_table[idx].target_func) != (!!obj)) {
+		if (!obj)
+			pr_debug("Fail to load BPF object: %s\n",
+				 bpf_testcase_table[idx].msg_load_fail);
+		else
+			pr_debug("Success unexpectedly: %s\n",
+				 bpf_testcase_table[idx].msg_load_fail);
 		ret = TEST_FAIL;
 		goto out;
 	}
 
-	ret = do_test(obj,
-		      bpf_testcase_table[idx].target_func,
-		      bpf_testcase_table[idx].expect_result);
+	if (obj)
+		ret = do_test(obj,
+			      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 06f45c1d4256..70edcdfa5672 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -35,6 +35,7 @@ static int test__bpf_parsing(void *obj_buf __maybe_unused,
 static struct {
 	const char *source;
 	const char *desc;
+	bool should_load_fail;
 } bpf_source_table[__LLVM_TESTCASE_MAX] = {
 	[LLVM_TESTCASE_BASE] = {
 		.source = test_llvm__bpf_base_prog,
@@ -48,14 +49,19 @@ static struct {
 		.source = test_llvm__bpf_test_prologue_prog,
 		.desc = "Compile source for BPF prologue generation test",
 	},
+	[LLVM_TESTCASE_BPF_RELOCATION] = {
+		.source = test_llvm__bpf_test_relocation,
+		.desc = "Compile source for BPF relocation test",
+		.should_load_fail = true,
+	},
 };
 
-
 int
 test_llvm__fetch_bpf_obj(void **p_obj_buf,
 			 size_t *p_obj_buf_sz,
 			 enum test_llvm__testcase idx,
-			 bool force)
+			 bool force,
+			 bool *should_load_fail)
 {
 	const char *source;
 	const char *desc;
@@ -68,6 +74,8 @@ test_llvm__fetch_bpf_obj(void **p_obj_buf,
 
 	source = bpf_source_table[idx].source;
 	desc = bpf_source_table[idx].desc;
+	if (should_load_fail)
+		*should_load_fail = bpf_source_table[idx].should_load_fail;
 
 	perf_config(perf_config_cb, NULL);
 
@@ -136,14 +144,15 @@ int test__llvm(int subtest)
 	int ret;
 	void *obj_buf = NULL;
 	size_t obj_buf_sz = 0;
+	bool should_load_fail = false;
 
 	if ((subtest < 0) || (subtest >= __LLVM_TESTCASE_MAX))
 		return TEST_FAIL;
 
 	ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz,
-				       subtest, false);
+				       subtest, false, &should_load_fail);
 
-	if (ret == TEST_OK) {
+	if (ret == TEST_OK && !should_load_fail) {
 		ret = test__bpf_parsing(obj_buf, obj_buf_sz);
 		if (ret != TEST_OK) {
 			pr_debug("Failed to parse test case '%s'\n",
diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h
index 5150b4d6ef50..0eaa604be99d 100644
--- a/tools/perf/tests/llvm.h
+++ b/tools/perf/tests/llvm.h
@@ -7,14 +7,17 @@
 extern const char test_llvm__bpf_base_prog[];
 extern const char test_llvm__bpf_test_kbuild_prog[];
 extern const char test_llvm__bpf_test_prologue_prog[];
+extern const char test_llvm__bpf_test_relocation[];
 
 enum test_llvm__testcase {
 	LLVM_TESTCASE_BASE,
 	LLVM_TESTCASE_KBUILD,
 	LLVM_TESTCASE_BPF_PROLOGUE,
+	LLVM_TESTCASE_BPF_RELOCATION,
 	__LLVM_TESTCASE_MAX,
 };
 
 int test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz,
-			     enum test_llvm__testcase index, bool force);
+			     enum test_llvm__testcase index, bool force,
+			     bool *should_load_fail);
 #endif
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 22/26] perf bpf: Check relocation target section
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (20 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 21/26] perf test: Add libbpf relocation checker Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 23/26] tools build: Allow subprojects select all feature checkers Arnaldo Carvalho de Melo
                   ` (3 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Wang Nan, David S. Miller, Brendan Gregg,
	Daniel Borkmann, He Kuang, Jiri Olsa, Li Zefan, Masami Hiramatsu,
	Namhyung Kim, Peter Zijlstra, Will Deacon, pi3orama,
	Arnaldo Carvalho de Melo

From: Wang Nan <wangnan0@huawei.com>

Libbpf should check the target section before doing relocation to ensure
the relocation is correct. If not, a bug in LLVM causes an error. See
[1].  Also, if an incorrect BPF script uses both global variable and
map, global variable whould be treated as map and be relocated without
error.

This patch saves the id of the map section into obj->efile and compare
target section of a relocation symbol against it during relocation.

Previous patch introduces a test case about this problem.  After this
patch:

  # ~/perf test BPF
  37: Test BPF filter                                          :
  37.1: Test basic BPF filtering                               : Ok
  37.2: Test BPF prologue generation                           : Ok
  37.3: Test BPF relocation checker                            : Ok

  # perf test -v BPF
  ...
  37.3: Test BPF relocation checker                            :
  ...
  libbpf: loading object '[bpf_relocation_test]' from buffer
  libbpf: section .strtab, size 126, link 0, flags 0, type=3
  libbpf: section .text, size 0, link 0, flags 6, type=1
  libbpf: section .data, size 0, link 0, flags 3, type=1
  libbpf: section .bss, size 0, link 0, flags 3, type=8
  libbpf: section func=sys_write, size 104, link 0, flags 6, type=1
  libbpf: found program func=sys_write
  libbpf: section .relfunc=sys_write, size 16, link 10, flags 0, type=9
  libbpf: section maps, size 16, link 0, flags 3, type=1
  libbpf: maps in [bpf_relocation_test]: 16 bytes
  libbpf: section license, size 4, link 0, flags 3, type=1
  libbpf: license of [bpf_relocation_test] is GPL
  libbpf: section version, size 4, link 0, flags 3, type=1
  libbpf: kernel version of [bpf_relocation_test] is 40400
  libbpf: section .symtab, size 144, link 1, flags 0, type=2
  libbpf: map 0 is "my_table"
  libbpf: collecting relocating info for: 'func=sys_write'
  libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522
  bpf: failed to load buffer
  Compile BPF program failed.
  test child finished with 0
  ---- end ----
  Test BPF filter subtest 2: Ok

[1] https://llvm.org/bugs/show_bug.cgi?id=26243

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1453715801-7732-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/bpf/libbpf.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 8334a5a9d5d7..7e543c3102d4 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -201,6 +201,7 @@ struct bpf_object {
 			Elf_Data *data;
 		} *reloc;
 		int nr_reloc;
+		int maps_shndx;
 	} efile;
 	/*
 	 * All loaded bpf_object is linked in a list, which is
@@ -350,6 +351,7 @@ static struct bpf_object *bpf_object__new(const char *path,
 	 */
 	obj->efile.obj_buf = obj_buf;
 	obj->efile.obj_buf_sz = obj_buf_sz;
+	obj->efile.maps_shndx = -1;
 
 	obj->loaded = false;
 
@@ -529,12 +531,12 @@ bpf_object__init_maps(struct bpf_object *obj, void *data,
 }
 
 static int
-bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
+bpf_object__init_maps_name(struct bpf_object *obj)
 {
 	int i;
 	Elf_Data *symbols = obj->efile.symbols;
 
-	if (!symbols || maps_shndx < 0)
+	if (!symbols || obj->efile.maps_shndx < 0)
 		return -EINVAL;
 
 	for (i = 0; i < symbols->d_size / sizeof(GElf_Sym); i++) {
@@ -544,7 +546,7 @@ bpf_object__init_maps_name(struct bpf_object *obj, int maps_shndx)
 
 		if (!gelf_getsym(symbols, i, &sym))
 			continue;
-		if (sym.st_shndx != maps_shndx)
+		if (sym.st_shndx != obj->efile.maps_shndx)
 			continue;
 
 		map_name = elf_strptr(obj->efile.elf,
@@ -572,7 +574,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
 	Elf *elf = obj->efile.elf;
 	GElf_Ehdr *ep = &obj->efile.ehdr;
 	Elf_Scn *scn = NULL;
-	int idx = 0, err = 0, maps_shndx = -1;
+	int idx = 0, err = 0;
 
 	/* Elf is corrupted/truncated, avoid calling elf_strptr. */
 	if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) {
@@ -625,7 +627,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
 		else if (strcmp(name, "maps") == 0) {
 			err = bpf_object__init_maps(obj, data->d_buf,
 						    data->d_size);
-			maps_shndx = idx;
+			obj->efile.maps_shndx = idx;
 		} else if (sh.sh_type == SHT_SYMTAB) {
 			if (obj->efile.symbols) {
 				pr_warning("bpf: multiple SYMTAB in %s\n",
@@ -674,8 +676,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
 		pr_warning("Corrupted ELF file: index of strtab invalid\n");
 		return LIBBPF_ERRNO__FORMAT;
 	}
-	if (maps_shndx >= 0)
-		err = bpf_object__init_maps_name(obj, maps_shndx);
+	if (obj->efile.maps_shndx >= 0)
+		err = bpf_object__init_maps_name(obj);
 out:
 	return err;
 }
@@ -697,7 +699,8 @@ bpf_object__find_prog_by_idx(struct bpf_object *obj, int idx)
 static int
 bpf_program__collect_reloc(struct bpf_program *prog,
 			   size_t nr_maps, GElf_Shdr *shdr,
-			   Elf_Data *data, Elf_Data *symbols)
+			   Elf_Data *data, Elf_Data *symbols,
+			   int maps_shndx)
 {
 	int i, nrels;
 
@@ -724,9 +727,6 @@ bpf_program__collect_reloc(struct bpf_program *prog,
 			return -LIBBPF_ERRNO__FORMAT;
 		}
 
-		insn_idx = rel.r_offset / sizeof(struct bpf_insn);
-		pr_debug("relocation: insn_idx=%u\n", insn_idx);
-
 		if (!gelf_getsym(symbols,
 				 GELF_R_SYM(rel.r_info),
 				 &sym)) {
@@ -735,6 +735,15 @@ bpf_program__collect_reloc(struct bpf_program *prog,
 			return -LIBBPF_ERRNO__FORMAT;
 		}
 
+		if (sym.st_shndx != maps_shndx) {
+			pr_warning("Program '%s' contains non-map related relo data pointing to section %u\n",
+				   prog->section_name, sym.st_shndx);
+			return -LIBBPF_ERRNO__RELOC;
+		}
+
+		insn_idx = rel.r_offset / sizeof(struct bpf_insn);
+		pr_debug("relocation: insn_idx=%u\n", insn_idx);
+
 		if (insns[insn_idx].code != (BPF_LD | BPF_IMM | BPF_DW)) {
 			pr_warning("bpf: relocation: invalid relo for insns[%d].code 0x%x\n",
 				   insn_idx, insns[insn_idx].code);
@@ -863,7 +872,8 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
 
 		err = bpf_program__collect_reloc(prog, nr_maps,
 						 shdr, data,
-						 obj->efile.symbols);
+						 obj->efile.symbols,
+						 obj->efile.maps_shndx);
 		if (err)
 			return err;
 	}
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 23/26] tools build: Allow subprojects select all feature checkers
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (21 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 22/26] perf bpf: Check relocation target section Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 24/26] perf build: Select all feature checkers for feature-dump Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Wang Nan, David S. Miller, Alexei Starovoitov,
	Brendan Gregg, Daniel Borkmann, He Kuang, Jiri Olsa, Li Zefan,
	Masami Hiramatsu, Namhyung Kim, Peter Zijlstra, Will Deacon,
	Arnaldo Carvalho de Melo

From: Wang Nan <wangnan0@huawei.com>

Put feature checkers not in original FEATURE_TESTS to a new list and
allow subproject select all feature checkers by setting FEATURE_TESTS to
'all'.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Link: http://lkml.kernel.org/r/1453715801-7732-4-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/build/Makefile.feature | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 02db3cdff20f..674c47d5f9d1 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -27,7 +27,7 @@ endef
 #   the rule that uses them - an example for that is the 'bionic'
 #   feature check. ]
 #
-FEATURE_TESTS ?=			\
+FEATURE_TESTS_BASIC :=			\
 	backtrace			\
 	dwarf				\
 	fortify-source			\
@@ -56,6 +56,25 @@ FEATURE_TESTS ?=			\
 	get_cpuid			\
 	bpf
 
+# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
+# of all feature tests
+FEATURE_TESTS_EXTRA :=			\
+	bionic				\
+	compile-32			\
+	compile-x32			\
+	cplus-demangle			\
+	hello				\
+	libbabeltrace			\
+	liberty				\
+	liberty-z			\
+	libunwind-debug-frame
+
+FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
+
+ifeq ($(FEATURE_TESTS),all)
+  FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
+endif
+
 FEATURE_DISPLAY ?=			\
 	dwarf				\
 	glibc				\
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 24/26] perf build: Select all feature checkers for feature-dump
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (22 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 23/26] tools build: Allow subprojects select all feature checkers Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 25/26] perf hists browser: Skip scripting when perf.data file not available Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 26/26] perf cpumap: Auto initialize cpu__max_{node,cpu} Arnaldo Carvalho de Melo
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Wang Nan, David S. Miller, Alexei Starovoitov,
	Brendan Gregg, Daniel Borkmann, He Kuang, Jiri Olsa, Li Zefan,
	Masami Hiramatsu, Namhyung Kim, Peter Zijlstra, Will Deacon,
	Arnaldo Carvalho de Melo

From: Wang Nan <wangnan0@huawei.com>

Set FEATURE_TESTS to 'all' so all possible feature checkers are
executed. Without this setting the output feature dump file miss some
feature, for example, liberity. Select all checker so we won't get an
incomplete feature dump file.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Link: http://lkml.kernel.org/r/1453715801-7732-5-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.perf | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 97ce8695199e..0ef3d97d7954 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -165,7 +165,16 @@ ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
 endif
 endif
 
+# Set FEATURE_TESTS to 'all' so all possible feature checkers are executed.
+# Without this setting the output feature dump file misses some features, for
+# example, liberty. Select all checkers so we won't get an incomplete feature
+# dump file.
 ifeq ($(config),1)
+ifdef MAKECMDGOALS
+ifeq ($(filter feature-dump,$(MAKECMDGOALS)),feature-dump)
+FEATURE_TESTS := all
+endif
+endif
 include config/Makefile
 endif
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 25/26] perf hists browser: Skip scripting when perf.data file not available
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (23 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 24/26] perf build: Select all feature checkers for feature-dump Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  2016-01-26 19:19 ` [PATCH 26/26] perf cpumap: Auto initialize cpu__max_{node,cpu} Arnaldo Carvalho de Melo
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Namhyung Kim, Andi Kleen, David Ahern, Jiri Olsa,
	Peter Zijlstra, Stephane Eranian, Wang Nan,
	Arnaldo Carvalho de Melo

From: Namhyung Kim <namhyung@kernel.org>

The script and data-switch context menu are only meaningful when it
deals with a data file.  So add a check so that it cannot be shown when
perf-top is run.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1453555902-18401-4-git-send-email-namhyung@kernel.org
[ Carved out from a  larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/hists.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index d07e6be42ab1..1da30f8aa7a5 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2303,6 +2303,9 @@ skip_annotation:
 					     &options[nr_options],
 					     socked_id);
 		/* perf script support */
+		if (!is_report_browser(hbt))
+			goto skip_scripting;
+
 		if (browser->he_selection) {
 			if (sort__has_thread && thread) {
 				nr_options += add_script_opt(browser,
@@ -2330,6 +2333,7 @@ skip_annotation:
 					     &options[nr_options], NULL, NULL);
 		nr_options += add_switch_opt(browser, &actions[nr_options],
 					     &options[nr_options]);
+skip_scripting:
 		nr_options += add_exit_opt(browser, &actions[nr_options],
 					   &options[nr_options]);
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 26/26] perf cpumap: Auto initialize cpu__max_{node,cpu}
  2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
                   ` (24 preceding siblings ...)
  2016-01-26 19:19 ` [PATCH 25/26] perf hists browser: Skip scripting when perf.data file not available Arnaldo Carvalho de Melo
@ 2016-01-26 19:19 ` Arnaldo Carvalho de Melo
  25 siblings, 0 replies; 27+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-01-26 19:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Adrian Hunter,
	Borislav Petkov, David Ahern, Frederic Weisbecker, Jiri Olsa,
	Kan Liang, Mathieu Poirier, Namhyung Kim, Stephane Eranian,
	Wang Nan

From: Arnaldo Carvalho de Melo <acme@redhat.com>

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 <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20160125212955.GG22501@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 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 fa935093a599..9bcf2bed3a6d 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -8,6 +8,10 @@
 #include <linux/bitmap.h>
 #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 71c41b9efabb..81a2562aaa2b 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),
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2016-01-26 19:30 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-26 19:18 [PATCH 00/26] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 01/26] perf pmu: Fix misleadingly indented assignment (whitespace) Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 02/26] perf symbols: Do not read symbols/data from device files Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 03/26] perf stat: Making several helper functions static Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 04/26] perf hists: Remove parent filter check in DSO filter function Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 05/26] perf hists: Cleanup filtering functions Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 06/26] perf tools: Document the perf sysctls Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 07/26] perf annotate: Rename 'colors.code' to 'colors.jump_arrows' Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 08/26] perf config: Document variables for 'colors' section in man page Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 09/26] perf config: Document variables for 'tui' and 'gtk' sections " Arnaldo Carvalho de Melo
2016-01-26 19:18 ` [PATCH 10/26] perf config: Document 'buildid.dir' variable " Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 11/26] perf config: Document variables for 'annotate' section " Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 12/26] perf config: Document 'hist.percentage' variable " Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 13/26] perf sort: Provide a way to find out if per-thread bucketing is in place Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 14/26] perf hists browser: Only 'Zoom into thread' only when sort order has 'pid' Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 15/26] perf hists browser: Only offer symbol scripting when a symbol is under the cursor Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 16/26] perf hists browser: Offer 'Zoom into DSO'/'Map details' only when sort order has 'dso' Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 17/26] perf hists browser: Be a bit more strict about presenting CPU socket zoom Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 18/26] perf hists browser: Offer non-symbol specific menu options for --sort without 'sym' Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 19/26] perf machine: Introduce machine__find_kernel_symbol_by_name() Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 20/26] perf test: Fixup aliases checking in the 'vmlinux matches kallsyms' test Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 21/26] perf test: Add libbpf relocation checker Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 22/26] perf bpf: Check relocation target section Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 23/26] tools build: Allow subprojects select all feature checkers Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 24/26] perf build: Select all feature checkers for feature-dump Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 25/26] perf hists browser: Skip scripting when perf.data file not available Arnaldo Carvalho de Melo
2016-01-26 19:19 ` [PATCH 26/26] perf cpumap: Auto initialize cpu__max_{node,cpu} Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.