Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1505012 > unrolled thread

[GIT PULL 00/52] New Tool: perf c2c

Started byArnaldo Carvalho de Melo <acme@kernel.org>
First post2016-10-20 17:20 +0200
Last post2016-10-24 11:50 +0200
Articles 20 on this page of 28 — 6 participants

Back to article view | Back to linux.kernel


Contents

  [GIT PULL 00/52] New Tool: perf c2c Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 16/52] perf c2c report: Add hitm related dimension keys Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 29/52] perf c2c report: Add 'node' sort key Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 26/52] perf c2c report: Add 'pid' sort key Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 02/52] perf c2c: Introduce c2c_add_stats function Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 45/52] perf c2c report: Recalc width of global sort entries Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 30/52] perf c2c report: Add stats related sort keys Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 27/52] perf c2c report: Add 'tid' sort key Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 50/52] perf c2c: Add man page and credits Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 31/52] perf c2c report: Add 'cpucnt' sort key Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 19/52] perf c2c report: Add llc and remote loads related dimension keys Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 39/52] perf c2c report: Add shared cachelines stats stdio output Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 10/52] perf c2c report: Add cacheline hists processing Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 23/52] perf c2c report: Add hitm percent sort key Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 05/52] perf c2c: Add report subcommand Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 04/52] perf c2c: Add record subcommand Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    [PATCH 15/52] perf c2c report: Add 'iaddr' dimension key Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-20 17:20 +0200
    Re: [GIT PULL 00/52] New Tool: perf c2c Kim Phillips <kim.phillips@arm.com> - 2016-10-21 01:10 +0200
      [PATCH] perf c2c report: Properly check data presence in rb_tree loop Jiri Olsa <jolsa@redhat.com> - 2016-10-21 02:20 +0200
        Re: [PATCH] perf c2c report: Properly check data presence in  rb_tree loop Kim Phillips <kim.phillips@arm.com> - 2016-10-21 21:30 +0200
        [tip:perf/core] perf c2c report: Add main TUI browser tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-10-22 11:00 +0200
      Re: [GIT PULL 00/52] New Tool: perf c2c Jiri Olsa <jolsa@redhat.com> - 2016-10-21 02:30 +0200
    Re: [GIT PULL 00/52] New Tool: perf c2c Ingo Molnar <mingo@kernel.org> - 2016-10-22 10:30 +0200
      Re: [GIT PULL 00/52] New Tool: perf c2c Jiri Olsa <jolsa@redhat.com> - 2016-10-23 13:10 +0200
        Re: [GIT PULL 00/52] New Tool: perf c2c Andi Kleen <andi@firstfloor.org> - 2016-10-24 01:50 +0200
          Re: [GIT PULL 00/52] New Tool: perf c2c Jiri Olsa <jolsa@redhat.com> - 2016-10-24 08:40 +0200
        Re: [GIT PULL 00/52] New Tool: perf c2c Ingo Molnar <mingo@kernel.org> - 2016-10-24 11:30 +0200
          Re: [GIT PULL 00/52] New Tool: perf c2c Jiri Olsa <jolsa@redhat.com> - 2016-10-24 11:50 +0200

Page 1 of 2  [1] 2  Next page →


#1505012 — [GIT PULL 00/52] New Tool: perf c2c

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[GIT PULL 00/52] New Tool: perf c2c
Message-ID<sun8J-Pf-5@gated-at.bofh.it>
Hi Ingo,

	Please consider pulling into tip/perf/core,

Thanks,

- Arnaldo

The following changes since commit 10b37cb59fa1e61fec1386f324615e0e8202cd87:

  Merge tag 'perf-vendor_events-for-mingo-20161018' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2016-10-19 15:22:26 +0200)

are available in the git repository at:

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

for you to fetch changes up to 535bbde62701b2bb298063e9dfa007e8a1ff95d1:

  perf c2c report: Add --show-all option (2016-10-19 13:18:31 -0300)

----------------------------------------------------------------
- The 'perf c2c' tool provides means for Shared Data C2C/HITM analysis.

  It allows you to track down cacheline contention. The tool is based
  on x86's load latency and precise store facility events provided by
  Intel CPUs.

  It was tested by Joe Mario and has proven to be useful, finding some
  cacheline contentions. Joe also wrote a blog about c2c tool with
  examples:

    https://joemario.github.io/blog/2016/09/01/c2c-blog/

  Excerpt of the content on this site:

  ---
    At a high level, “perf c2c” will show you:

    * The cachelines where false sharing was detected.
    * The readers and writers to those cachelines, and the offsets where those accesses occurred.
    * The pid, tid, instruction addr, function name, binary object name for those readers and writers.
    * The source file and line number for each reader and writer.
    * The average load latency for the loads to those cachelines.
    * Which numa nodes the samples a cacheline came from and which CPUs were involved.

    Using perf c2c is similar to using the Linux perf tool today.
    First collect data with “perf c2c record” Then generate a report output with “perf c2c report”
  ---

  There one finds extensive details on using the tool, with tips on
  reducing the volume of samples while still capturing enough to do
  its job. (Dick Fowles, Joe Mario, Don Zickus, Jiri Olsa)

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

----------------------------------------------------------------
Jiri Olsa (52):
      perf c2c: Introduce c2c_decode_stats function
      perf c2c: Introduce c2c_add_stats function
      perf c2c: Add c2c command
      perf c2c: Add record subcommand
      perf c2c: Add report subcommand
      perf c2c report: Add dimension support
      perf c2c report: Add sort_entry dimension support
      perf c2c report: Fallback to standard dimensions
      perf c2c report: Add sample processing
      perf c2c report: Add cacheline hists processing
      perf c2c report: Decode c2c_stats for hist entries
      perf c2c report: Add header macros
      perf c2c report: Add 'dcacheline' dimension key
      perf c2c report: Add 'offset' dimension key
      perf c2c report: Add 'iaddr' dimension key
      perf c2c report: Add hitm related dimension keys
      perf c2c report: Add stores related dimension keys
      perf c2c report: Add loads related dimension keys
      perf c2c report: Add llc and remote loads related dimension keys
      perf c2c report: Add llc load miss dimension key
      perf c2c report: Add total record sort key
      perf c2c report: Add total loads sort key
      perf c2c report: Add hitm percent sort key
      perf c2c report: Add hitm/store percent related sort keys
      perf c2c report: Add dram related sort keys
      perf c2c report: Add 'pid' sort key
      perf c2c report: Add 'tid' sort key
      perf c2c report: Add 'symbol' and 'dso' sort keys
      perf c2c report: Add 'node' sort key
      perf c2c report: Add stats related sort keys
      perf c2c report: Add 'cpucnt' sort key
      perf c2c report: Add src line sort key
      perf c2c report: Setup number of header lines for hists
      perf c2c report: Set final resort fields
      perf c2c report: Add stdio output support
      perf c2c report: Add main TUI browser
      perf c2c report: Add TUI cacheline browser
      perf c2c report: Add global stats stdio output
      perf c2c report: Add shared cachelines stats stdio output
      perf c2c report: Add c2c related stats stdio output
      perf c2c report: Allow to report callchains
      perf c2c report: Limit the cachelines table entries
      perf c2c report: Add support to choose local HITMs
      perf c2c report: Allow to set cacheline sort fields
      perf c2c report: Recalc width of global sort entries
      perf c2c report: Add cacheline index entry
      perf c2c report: Add support to manage symbol name length
      perf c2c report: Iterate node display in browser
      perf c2c report: Add help windows
      perf c2c: Add man page and credits
      perf c2c report: Add --no-source option
      perf c2c report: Add --show-all option

 tools/perf/Build                      |    1 +
 tools/perf/Documentation/perf-c2c.txt |  282 ++++
 tools/perf/builtin-c2c.c              | 2754 +++++++++++++++++++++++++++++++++
 tools/perf/builtin.h                  |    1 +
 tools/perf/perf.c                     |    1 +
 tools/perf/ui/browsers/hists.c        |    2 +-
 tools/perf/ui/browsers/hists.h        |    1 +
 tools/perf/util/hist.c                |    1 +
 tools/perf/util/hist.h                |    1 +
 tools/perf/util/mem-events.c          |  128 ++
 tools/perf/util/mem-events.h          |   37 +
 tools/perf/util/sort.c                |    2 +-
 tools/perf/util/sort.h                |    1 +
 13 files changed, 3210 insertions(+), 2 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-c2c.txt
 create mode 100644 tools/perf/builtin-c2c.c

[toc] | [next] | [standalone]


#1505013 — [PATCH 16/52] perf c2c report: Add hitm related dimension keys

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 16/52] perf c2c report: Add hitm related dimension keys
Message-ID<sunir-T1-41@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Adding 5 hitm related dimension key wrappers.

First 3 are to be displayed in the main cachelines overall output:

  tot_hitm, lcl_hitm, rmt_hitm

The latter 2 are to be displayed within single cacheline output:

  cl_rmt_hitm, cl_lcl_hitm

They all display bare numbers of remote/local/total HITMs for cacheline
or its related offsets.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-iju5239xa5heqqben65g1u7e@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index bb9d01874836..039e7369dc6c 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -349,6 +349,70 @@ iaddr_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
 	return sort__iaddr_cmp(left, right);
 }
 
+static int
+tot_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+	       struct hist_entry *he)
+{
+	struct c2c_hist_entry *c2c_he;
+	int width = c2c_width(fmt, hpp, he->hists);
+	unsigned int tot_hitm;
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+	tot_hitm = c2c_he->stats.lcl_hitm + c2c_he->stats.rmt_hitm;
+
+	return scnprintf(hpp->buf, hpp->size, "%*u", width, tot_hitm);
+}
+
+static int64_t
+tot_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
+	     struct hist_entry *left, struct hist_entry *right)
+{
+	struct c2c_hist_entry *c2c_left;
+	struct c2c_hist_entry *c2c_right;
+	unsigned int tot_hitm_left;
+	unsigned int tot_hitm_right;
+
+	c2c_left  = container_of(left, struct c2c_hist_entry, he);
+	c2c_right = container_of(right, struct c2c_hist_entry, he);
+
+	tot_hitm_left  = c2c_left->stats.lcl_hitm + c2c_left->stats.rmt_hitm;
+	tot_hitm_right = c2c_right->stats.lcl_hitm + c2c_right->stats.rmt_hitm;
+
+	return tot_hitm_left - tot_hitm_right;
+}
+
+#define STAT_FN_ENTRY(__f)					\
+static int							\
+__f ## _entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,	\
+	      struct hist_entry *he)				\
+{								\
+	struct c2c_hist_entry *c2c_he;				\
+	int width = c2c_width(fmt, hpp, he->hists);		\
+								\
+	c2c_he = container_of(he, struct c2c_hist_entry, he);	\
+	return scnprintf(hpp->buf, hpp->size, "%*u", width,	\
+			 c2c_he->stats.__f);			\
+}
+
+#define STAT_FN_CMP(__f)						\
+static int64_t								\
+__f ## _cmp(struct perf_hpp_fmt *fmt __maybe_unused,			\
+	    struct hist_entry *left, struct hist_entry *right)		\
+{									\
+	struct c2c_hist_entry *c2c_left, *c2c_right;			\
+									\
+	c2c_left  = container_of(left, struct c2c_hist_entry, he);	\
+	c2c_right = container_of(right, struct c2c_hist_entry, he);	\
+	return c2c_left->stats.__f - c2c_right->stats.__f;		\
+}
+
+#define STAT_FN(__f)		\
+	STAT_FN_ENTRY(__f)	\
+	STAT_FN_CMP(__f)
+
+STAT_FN(rmt_hitm)
+STAT_FN(lcl_hitm)
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -408,10 +472,55 @@ static struct c2c_dimension dim_iaddr = {
 	.width		= 18,
 };
 
+static struct c2c_dimension dim_tot_hitm = {
+	.header		= HEADER_SPAN("----- LLC Load Hitm -----", "Total", 2),
+	.name		= "tot_hitm",
+	.cmp		= tot_hitm_cmp,
+	.entry		= tot_hitm_entry,
+	.width		= 7,
+};
+
+static struct c2c_dimension dim_lcl_hitm = {
+	.header		= HEADER_SPAN_LOW("Lcl"),
+	.name		= "lcl_hitm",
+	.cmp		= lcl_hitm_cmp,
+	.entry		= lcl_hitm_entry,
+	.width		= 7,
+};
+
+static struct c2c_dimension dim_rmt_hitm = {
+	.header		= HEADER_SPAN_LOW("Rmt"),
+	.name		= "rmt_hitm",
+	.cmp		= rmt_hitm_cmp,
+	.entry		= rmt_hitm_entry,
+	.width		= 7,
+};
+
+static struct c2c_dimension dim_cl_rmt_hitm = {
+	.header		= HEADER_SPAN("----- HITM -----", "Rmt", 1),
+	.name		= "cl_rmt_hitm",
+	.cmp		= rmt_hitm_cmp,
+	.entry		= rmt_hitm_entry,
+	.width		= 7,
+};
+
+static struct c2c_dimension dim_cl_lcl_hitm = {
+	.header		= HEADER_SPAN_LOW("Lcl"),
+	.name		= "cl_lcl_hitm",
+	.cmp		= lcl_hitm_cmp,
+	.entry		= lcl_hitm_entry,
+	.width		= 7,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
 	&dim_iaddr,
+	&dim_tot_hitm,
+	&dim_lcl_hitm,
+	&dim_rmt_hitm,
+	&dim_cl_lcl_hitm,
+	&dim_cl_rmt_hitm,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505015 — [PATCH 29/52] perf c2c report: Add 'node' sort key

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 29/52] perf c2c report: Add 'node' sort key
Message-ID<sunir-T1-45@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

It is to be displayed in the single cacheline output:

  node

It displays nodes hits related to cacheline accesses.

The node filed comes in 3 flavors:
  - node IDs separated by ','
  - node IDs with stats for each ID, in following format:
      Node{cpus %hitms %stores}
  - node IDs with list of affected CPUs in following format:
      Node{cpu list}

User can switch the flavor with -N option (-NN,-NNN).
It will be available in TUI to switch this with 'n' key.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-6742e6g0r7n63y5wc4rrgxx5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 219 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index ffd41744886e..ca2f37479e6d 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1,6 +1,7 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/stringify.h>
+#include <asm/bug.h>
 #include "util.h"
 #include "debug.h"
 #include "builtin.h"
@@ -22,6 +23,8 @@ struct c2c_hists {
 struct c2c_hist_entry {
 	struct c2c_hists	*hists;
 	struct c2c_stats	 stats;
+	unsigned long		*cpuset;
+	struct c2c_stats	*node_stats;
 	/*
 	 * must be at the end,
 	 * because of its callchain dynamic entry
@@ -32,6 +35,12 @@ struct c2c_hist_entry {
 struct perf_c2c {
 	struct perf_tool	tool;
 	struct c2c_hists	hists;
+
+	unsigned long		**nodes;
+	int			 nodes_cnt;
+	int			 cpus_cnt;
+	int			*cpu2node;
+	int			 node_info;
 };
 
 static struct perf_c2c c2c;
@@ -44,6 +53,14 @@ static void *c2c_he_zalloc(size_t size)
 	if (!c2c_he)
 		return NULL;
 
+	c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
+	if (!c2c_he->cpuset)
+		return NULL;
+
+	c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
+	if (!c2c_he->node_stats)
+		return NULL;
+
 	return &c2c_he->he;
 }
 
@@ -57,6 +74,8 @@ static void c2c_he_free(void *he)
 		free(c2c_he->hists);
 	}
 
+	free(c2c_he->cpuset);
+	free(c2c_he->node_stats);
 	free(c2c_he);
 }
 
@@ -93,6 +112,16 @@ he__get_c2c_hists(struct hist_entry *he,
 	return hists;
 }
 
+static void c2c_he__set_cpu(struct c2c_hist_entry *c2c_he,
+			    struct perf_sample *sample)
+{
+	if (WARN_ONCE(sample->cpu == (unsigned int) -1,
+		      "WARNING: no sample cpu value"))
+		return;
+
+	set_bit(sample->cpu, c2c_he->cpuset);
+}
+
 static int process_sample_event(struct perf_tool *tool __maybe_unused,
 				union perf_event *event,
 				struct perf_sample *sample,
@@ -133,10 +162,23 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	c2c_add_stats(&c2c_he->stats, &stats);
 	c2c_add_stats(&c2c_hists->stats, &stats);
 
+	c2c_he__set_cpu(c2c_he, sample);
+
 	hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
 	ret = hist_entry__append_callchain(he, sample);
 
 	if (!ret) {
+		/*
+		 * There's already been warning about missing
+		 * sample's cpu value. Let's account all to
+		 * node 0 in this case, without any further
+		 * warning.
+		 *
+		 * Doing node stats only for single callchain data.
+		 */
+		int cpu = sample->cpu == (unsigned int) -1 ? 0 : sample->cpu;
+		int node = c2c.cpu2node[cpu];
+
 		mi = mi_dup;
 
 		mi_dup = memdup(mi, sizeof(*mi));
@@ -156,6 +198,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 		c2c_he = container_of(he, struct c2c_hist_entry, he);
 		c2c_add_stats(&c2c_he->stats, &stats);
 		c2c_add_stats(&c2c_hists->stats, &stats);
+		c2c_add_stats(&c2c_he->node_stats[node], &stats);
+
+		c2c_he__set_cpu(c2c_he, sample);
 
 		hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
 		ret = hist_entry__append_callchain(he, sample);
@@ -826,6 +871,97 @@ pid_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
 	return left->thread->pid_ - right->thread->pid_;
 }
 
+static int64_t
+empty_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
+	  struct hist_entry *left __maybe_unused,
+	  struct hist_entry *right __maybe_unused)
+{
+	return 0;
+}
+
+static int
+node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
+	   struct hist_entry *he)
+{
+	struct c2c_hist_entry *c2c_he;
+	bool first = true;
+	int node;
+	int ret = 0;
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+
+	for (node = 0; node < c2c.nodes_cnt; node++) {
+		DECLARE_BITMAP(set, c2c.cpus_cnt);
+
+		bitmap_zero(set, c2c.cpus_cnt);
+		bitmap_and(set, c2c_he->cpuset, c2c.nodes[node], c2c.cpus_cnt);
+
+		if (!bitmap_weight(set, c2c.cpus_cnt)) {
+			if (c2c.node_info == 1) {
+				ret = scnprintf(hpp->buf, hpp->size, "%21s", " ");
+				advance_hpp(hpp, ret);
+			}
+			continue;
+		}
+
+		if (!first) {
+			ret = scnprintf(hpp->buf, hpp->size, " ");
+			advance_hpp(hpp, ret);
+		}
+
+		switch (c2c.node_info) {
+		case 0:
+			ret = scnprintf(hpp->buf, hpp->size, "%2d", node);
+			advance_hpp(hpp, ret);
+			break;
+		case 1:
+		{
+			int num = bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt);
+			struct c2c_stats *stats = &c2c_he->node_stats[node];
+
+			ret = scnprintf(hpp->buf, hpp->size, "%2d{%2d ", node, num);
+			advance_hpp(hpp, ret);
+
+
+			if (c2c_he->stats.rmt_hitm > 0) {
+				ret = scnprintf(hpp->buf, hpp->size, "%5.1f%% ",
+						percent(stats->rmt_hitm, c2c_he->stats.rmt_hitm));
+			} else {
+				ret = scnprintf(hpp->buf, hpp->size, "%6s ", "n/a");
+			}
+
+			advance_hpp(hpp, ret);
+
+			if (c2c_he->stats.store > 0) {
+				ret = scnprintf(hpp->buf, hpp->size, "%5.1f%%}",
+						percent(stats->store, c2c_he->stats.store));
+			} else {
+				ret = scnprintf(hpp->buf, hpp->size, "%6s}", "n/a");
+			}
+
+			advance_hpp(hpp, ret);
+			break;
+		}
+		case 2:
+			ret = scnprintf(hpp->buf, hpp->size, "%2d{", node);
+			advance_hpp(hpp, ret);
+
+			ret = bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size);
+			advance_hpp(hpp, ret);
+
+			ret = scnprintf(hpp->buf, hpp->size, "}");
+			advance_hpp(hpp, ret);
+			break;
+		default:
+			break;
+		}
+
+		first = false;
+	}
+
+	return 0;
+}
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -1115,6 +1251,19 @@ static struct c2c_dimension dim_dso = {
 	.se		= &sort_dso,
 };
 
+static struct c2c_header header_node[3] = {
+	HEADER_LOW("Node"),
+	HEADER_LOW("Node{cpus %hitms %stores}"),
+	HEADER_LOW("Node{cpu list}"),
+};
+
+static struct c2c_dimension dim_node = {
+	.name		= "node",
+	.cmp		= empty_cmp,
+	.entry		= node_entry,
+	.width		= 4,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
@@ -1148,6 +1297,7 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_tid,
 	&dim_symbol,
 	&dim_dso,
+	&dim_node,
 	NULL,
 };
 
@@ -1374,6 +1524,68 @@ static int resort_cl_cb(struct hist_entry *he)
 	return 0;
 }
 
+static void setup_nodes_header(void)
+{
+	dim_node.header = header_node[c2c.node_info];
+}
+
+static int setup_nodes(struct perf_session *session)
+{
+	struct numa_node *n;
+	unsigned long **nodes;
+	int node, cpu;
+	int *cpu2node;
+
+	if (c2c.node_info > 2)
+		c2c.node_info = 2;
+
+	c2c.nodes_cnt = session->header.env.nr_numa_nodes;
+	c2c.cpus_cnt  = session->header.env.nr_cpus_online;
+
+	n = session->header.env.numa_nodes;
+	if (!n)
+		return -EINVAL;
+
+	nodes = zalloc(sizeof(unsigned long *) * c2c.nodes_cnt);
+	if (!nodes)
+		return -ENOMEM;
+
+	c2c.nodes = nodes;
+
+	cpu2node = zalloc(sizeof(int) * c2c.cpus_cnt);
+	if (!cpu2node)
+		return -ENOMEM;
+
+	for (cpu = 0; cpu < c2c.cpus_cnt; cpu++)
+		cpu2node[cpu] = -1;
+
+	c2c.cpu2node = cpu2node;
+
+	for (node = 0; node < c2c.nodes_cnt; node++) {
+		struct cpu_map *map = n[node].map;
+		unsigned long *set;
+
+		set = bitmap_alloc(c2c.cpus_cnt);
+		if (!set)
+			return -ENOMEM;
+
+		for (cpu = 0; cpu < map->nr; cpu++) {
+			set_bit(map->map[cpu], set);
+
+			if (WARN_ONCE(cpu2node[map->map[cpu]] != -1, "node/cpu topology bug"))
+				return -EINVAL;
+
+			cpu2node[map->map[cpu]] = node;
+		}
+
+		nodes[node] = set;
+	}
+
+	setup_nodes_header();
+	return 0;
+}
+
+
 static int perf_c2c__report(int argc, const char **argv)
 {
 	struct perf_session *session;
@@ -1388,6 +1600,8 @@ static int perf_c2c__report(int argc, const char **argv)
 		 "be more verbose (show counter open errors, etc)"),
 	OPT_STRING('i', "input", &input_name, "file",
 		   "the input file to process"),
+	OPT_INCR('N', "node-info", &c2c.node_info,
+		 "show extra node info in report (repeat for more info)"),
 	OPT_END()
 	};
 	int err = 0;
@@ -1413,6 +1627,11 @@ static int perf_c2c__report(int argc, const char **argv)
 		pr_debug("No memory for session\n");
 		goto out;
 	}
+	err = setup_nodes(session);
+	if (err) {
+		pr_err("Failed setup nodes\n");
+		goto out;
+	}
 
 	if (symbol__init(&session->header.env) < 0)
 		goto out_session;
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505016 — [PATCH 26/52] perf c2c report: Add 'pid' sort key

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 26/52] perf c2c report: Add 'pid' sort key
Message-ID<sunir-T1-49@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

It is to be displayed in the single cacheline output:

  pid

We currently don't have a single 'pid' sort/display entry, which would
output just pid number, hence adding it into c2c code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-3o23qrspxc99b04ci1swlzr6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index c718d8b553ce..4795713ad211 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -810,6 +810,22 @@ percent_stores_l1miss_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
 STAT_FN(lcl_dram)
 STAT_FN(rmt_dram)
 
+static int
+pid_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+	  struct hist_entry *he)
+{
+	int width = c2c_width(fmt, hpp, he->hists);
+
+	return scnprintf(hpp->buf, hpp->size, "%*d", width, he->thread->pid_);
+}
+
+static int64_t
+pid_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
+	struct hist_entry *left, struct hist_entry *right)
+{
+	return left->thread->pid_ - right->thread->pid_;
+}
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -1074,6 +1090,14 @@ static struct c2c_dimension dim_dram_rmt = {
 	.width		= 8,
 };
 
+static struct c2c_dimension dim_pid = {
+	.header		= HEADER_LOW("Pid"),
+	.name		= "pid",
+	.cmp		= pid_cmp,
+	.entry		= pid_entry,
+	.width		= 7,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
@@ -1103,6 +1127,7 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_percent_stores_l1miss,
 	&dim_dram_lcl,
 	&dim_dram_rmt,
+	&dim_pid,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505017 — [PATCH 02/52] perf c2c: Introduce c2c_add_stats function

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 02/52] perf c2c: Introduce c2c_add_stats function
Message-ID<sunir-T1-51@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Introducing c2c_add_stats function helper to cumulate c2c_stats.

Original-patch-by: Dick Fowles <rfowles@redhat.com>
Original-patch-by: Don Zickus <dzickus@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1474558645-19956-4-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/mem-events.c | 30 ++++++++++++++++++++++++++++++
 tools/perf/util/mem-events.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 502fcee91973..e50773286ef6 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -366,3 +366,33 @@ int c2c_decode_stats(struct c2c_stats *stats, struct mem_info *mi)
 #undef P
 	return err;
 }
+
+void c2c_add_stats(struct c2c_stats *stats, struct c2c_stats *add)
+{
+	stats->nr_entries	+= add->nr_entries;
+
+	stats->locks		+= add->locks;
+	stats->store		+= add->store;
+	stats->st_uncache	+= add->st_uncache;
+	stats->st_noadrs	+= add->st_noadrs;
+	stats->st_l1hit		+= add->st_l1hit;
+	stats->st_l1miss	+= add->st_l1miss;
+	stats->load		+= add->load;
+	stats->ld_excl		+= add->ld_excl;
+	stats->ld_shared	+= add->ld_shared;
+	stats->ld_uncache	+= add->ld_uncache;
+	stats->ld_io		+= add->ld_io;
+	stats->ld_miss		+= add->ld_miss;
+	stats->ld_noadrs	+= add->ld_noadrs;
+	stats->ld_fbhit		+= add->ld_fbhit;
+	stats->ld_l1hit		+= add->ld_l1hit;
+	stats->ld_l2hit		+= add->ld_l2hit;
+	stats->ld_llchit	+= add->ld_llchit;
+	stats->lcl_hitm		+= add->lcl_hitm;
+	stats->rmt_hitm		+= add->rmt_hitm;
+	stats->rmt_hit		+= add->rmt_hit;
+	stats->lcl_dram		+= add->lcl_dram;
+	stats->rmt_dram		+= add->rmt_dram;
+	stats->nomap		+= add->nomap;
+	stats->noparse		+= add->noparse;
+}
diff --git a/tools/perf/util/mem-events.h b/tools/perf/util/mem-events.h
index e111a2a2b18f..faf80403b519 100644
--- a/tools/perf/util/mem-events.h
+++ b/tools/perf/util/mem-events.h
@@ -68,5 +68,6 @@ struct c2c_stats {
 
 struct hist_entry;
 int c2c_decode_stats(struct c2c_stats *stats, struct mem_info *mi);
+void c2c_add_stats(struct c2c_stats *stats, struct c2c_stats *add);
 
 #endif /* __PERF_MEM_EVENTS_H */
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505018 — [PATCH 45/52] perf c2c report: Recalc width of global sort entries

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 45/52] perf c2c report: Recalc width of global sort entries
Message-ID<sunir-T1-63@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Using resort callbacks to compute the columns' width.

Computing only the global ones, c2c entries have fixed width only.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-zyayvq2u3dzyf3y7i9jza0lw@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 2f3e430ddde0..473dae1baed8 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1728,11 +1728,21 @@ static inline int valid_hitm_or_store(struct hist_entry *he)
 	return has_hitm || c2c_he->stats.store;
 }
 
+static void calc_width(struct hist_entry *he)
+{
+	struct c2c_hists *c2c_hists;
+
+	c2c_hists = container_of(he->hists, struct c2c_hists, hists);
+	hists__calc_col_len(&c2c_hists->hists, he);
+}
+
 static int filter_cb(struct hist_entry *he)
 {
 	if (c2c.show_src && !he->srcline)
 		he->srcline = hist_entry__get_srcline(he);
 
+	calc_width(he);
+
 	if (!valid_hitm_or_store(he))
 		he->filtered = HIST_FILTER__C2C;
 
@@ -1748,6 +1758,8 @@ static int resort_cl_cb(struct hist_entry *he)
 	c2c_he = container_of(he, struct c2c_hist_entry, he);
 	c2c_hists = c2c_he->hists;
 
+	calc_width(he);
+
 	if (display && c2c_hists) {
 		c2c_hists__reinit(c2c_hists, c2c.cl_output, c2c.cl_resort);
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505019 — [PATCH 30/52] perf c2c report: Add stats related sort keys

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 30/52] perf c2c report: Add stats related sort keys
Message-ID<sunir-T1-65@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

It is to be displayed in the single cacheline output:

  median, mean_rmt, mean_lcl, mean_load, stddev

It displays statistics hits related to cacheline accesses.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-m1r4uc9lcykf1jhpvwk2gkj8@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index ca2f37479e6d..043344a720bf 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -20,11 +20,20 @@ struct c2c_hists {
 	struct c2c_stats	stats;
 };
 
+struct compute_stats {
+	struct stats		 lcl_hitm;
+	struct stats		 rmt_hitm;
+	struct stats		 load;
+};
+
 struct c2c_hist_entry {
 	struct c2c_hists	*hists;
 	struct c2c_stats	 stats;
 	unsigned long		*cpuset;
 	struct c2c_stats	*node_stats;
+
+	struct compute_stats	 cstats;
+
 	/*
 	 * must be at the end,
 	 * because of its callchain dynamic entry
@@ -61,6 +70,10 @@ static void *c2c_he_zalloc(size_t size)
 	if (!c2c_he->node_stats)
 		return NULL;
 
+	init_stats(&c2c_he->cstats.lcl_hitm);
+	init_stats(&c2c_he->cstats.rmt_hitm);
+	init_stats(&c2c_he->cstats.load);
+
 	return &c2c_he->he;
 }
 
@@ -122,6 +135,20 @@ static void c2c_he__set_cpu(struct c2c_hist_entry *c2c_he,
 	set_bit(sample->cpu, c2c_he->cpuset);
 }
 
+static void compute_stats(struct c2c_hist_entry *c2c_he,
+			  struct c2c_stats *stats,
+			  u64 weight)
+{
+	struct compute_stats *cstats = &c2c_he->cstats;
+
+	if (stats->rmt_hitm)
+		update_stats(&cstats->rmt_hitm, weight);
+	else if (stats->lcl_hitm)
+		update_stats(&cstats->lcl_hitm, weight);
+	else if (stats->load)
+		update_stats(&cstats->load, weight);
+}
+
 static int process_sample_event(struct perf_tool *tool __maybe_unused,
 				union perf_event *event,
 				struct perf_sample *sample,
@@ -200,6 +227,8 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 		c2c_add_stats(&c2c_hists->stats, &stats);
 		c2c_add_stats(&c2c_he->node_stats[node], &stats);
 
+		compute_stats(c2c_he, &stats, sample->weight);
+
 		c2c_he__set_cpu(c2c_he, sample);
 
 		hists__inc_nr_samples(&c2c_hists->hists, he->filtered);
@@ -962,6 +991,30 @@ node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
 	return 0;
 }
 
+static int
+mean_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+	   struct hist_entry *he, double mean)
+{
+	int width = c2c_width(fmt, hpp, he->hists);
+	char buf[10];
+
+	scnprintf(buf, 10, "%6.0f", mean);
+	return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
+}
+
+#define MEAN_ENTRY(__func, __val)						\
+static int									\
+__func(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, struct hist_entry *he)	\
+{										\
+	struct c2c_hist_entry *c2c_he;						\
+	c2c_he = container_of(he, struct c2c_hist_entry, he);			\
+	return mean_entry(fmt, hpp, he, avg_stats(&c2c_he->cstats.__val));	\
+}
+
+MEAN_ENTRY(mean_rmt_entry,  rmt_hitm);
+MEAN_ENTRY(mean_lcl_entry,  lcl_hitm);
+MEAN_ENTRY(mean_load_entry, load);
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -1264,6 +1317,30 @@ static struct c2c_dimension dim_node = {
 	.width		= 4,
 };
 
+static struct c2c_dimension dim_mean_rmt = {
+	.header		= HEADER_SPAN("---------- cycles ----------", "rmt hitm", 2),
+	.name		= "mean_rmt",
+	.cmp		= empty_cmp,
+	.entry		= mean_rmt_entry,
+	.width		= 8,
+};
+
+static struct c2c_dimension dim_mean_lcl = {
+	.header		= HEADER_SPAN_LOW("lcl hitm"),
+	.name		= "mean_lcl",
+	.cmp		= empty_cmp,
+	.entry		= mean_lcl_entry,
+	.width		= 8,
+};
+
+static struct c2c_dimension dim_mean_load = {
+	.header		= HEADER_SPAN_LOW("load"),
+	.name		= "mean_load",
+	.cmp		= empty_cmp,
+	.entry		= mean_load_entry,
+	.width		= 8,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
@@ -1298,6 +1375,9 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_symbol,
 	&dim_dso,
 	&dim_node,
+	&dim_mean_rmt,
+	&dim_mean_lcl,
+	&dim_mean_load,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505020 — [PATCH 27/52] perf c2c report: Add 'tid' sort key

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 27/52] perf c2c report: Add 'tid' sort key
Message-ID<sunir-T1-55@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

It is to be displayed in the single cacheline output:

  tid

It's a wrapper for global sort_thread sort entry with c2c specific
header.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-fr0socae5skzvz5qbkl85prn@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 4795713ad211..77810a30a4cc 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1098,6 +1098,12 @@ static struct c2c_dimension dim_pid = {
 	.width		= 7,
 };
 
+static struct c2c_dimension dim_tid = {
+	.header		= HEADER_LOW("Tid"),
+	.name		= "tid",
+	.se		= &sort_thread,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
@@ -1128,6 +1134,7 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_dram_lcl,
 	&dim_dram_rmt,
 	&dim_pid,
+	&dim_tid,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505022 — [PATCH 50/52] perf c2c: Add man page and credits

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 50/52] perf c2c: Add man page and credits
Message-ID<sunir-T1-61@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Add man page for c2c command and credits to builtin-c2c.c file.

Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-twbp391v8v9f5idp584hlfov@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-c2c.txt | 276 ++++++++++++++++++++++++++++++++++
 tools/perf/builtin-c2c.c              |  11 ++
 2 files changed, 287 insertions(+)
 create mode 100644 tools/perf/Documentation/perf-c2c.txt

diff --git a/tools/perf/Documentation/perf-c2c.txt b/tools/perf/Documentation/perf-c2c.txt
new file mode 100644
index 000000000000..ba2f4de399c3
--- /dev/null
+++ b/tools/perf/Documentation/perf-c2c.txt
@@ -0,0 +1,276 @@
+perf-c2c(1)
+===========
+
+NAME
+----
+perf-c2c - Shared Data C2C/HITM Analyzer.
+
+SYNOPSIS
+--------
+[verse]
+'perf c2c record' [<options>] <command>
+'perf c2c record' [<options>] -- [<record command options>] <command>
+'perf c2c report' [<options>]
+
+DESCRIPTION
+-----------
+C2C stands for Cache To Cache.
+
+The perf c2c tool provides means for Shared Data C2C/HITM analysis. It allows
+you to track down the cacheline contentions.
+
+The tool is based on x86's load latency and precise store facility events
+provided by Intel CPUs. These events provide:
+  - memory address of the access
+  - type of the access (load and store details)
+  - latency (in cycles) of the load access
+
+The c2c tool provide means to record this data and report back access details
+for cachelines with highest contention - highest number of HITM accesses.
+
+The basic workflow with this tool follows the standard record/report phase.
+User uses the record command to record events data and report command to
+display it.
+
+
+RECORD OPTIONS
+--------------
+-e::
+--event=::
+	Select the PMU event. Use 'perf mem record -e list'
+	to list available events.
+
+-v::
+--verbose::
+	Be more verbose (show counter open errors, etc).
+
+-l::
+--ldlat::
+	Configure mem-loads latency.
+
+-k::
+--all-kernel::
+	Configure all used events to run in kernel space.
+
+-u::
+--all-user::
+	Configure all used events to run in user space.
+
+REPORT OPTIONS
+--------------
+-k::
+--vmlinux=<file>::
+	vmlinux pathname
+
+-v::
+--verbose::
+	Be more verbose (show counter open errors, etc).
+
+-i::
+--input::
+	Specify the input file to process.
+
+-N::
+--node-info::
+	Show extra node info in report (see NODE INFO section)
+
+-c::
+--coalesce::
+	Specify sorintg fields for single cacheline display.
+	Following fields are available: tid,pid,iaddr,dso
+	(see COALESCE)
+
+-g::
+--call-graph::
+	Setup callchains parameters.
+	Please refer to perf-report man page for details.
+
+--stdio::
+	Force the stdio output (see STDIO OUTPUT)
+
+--stats::
+	Display only statistic tables and force stdio mode.
+
+--full-symbols::
+	Display full length of symbols.
+
+C2C RECORD
+----------
+The perf c2c record command setup options related to HITM cacheline analysis
+and calls standard perf record command.
+
+Following perf record options are configured by default:
+(check perf record man page for details)
+
+  -W,-d,--sample-cpu
+
+Unless specified otherwise with '-e' option, following events are monitored by
+default:
+
+  cpu/mem-loads,ldlat=30/P
+  cpu/mem-stores/P
+
+User can pass any 'perf record' option behind '--' mark, like (to enable
+callchains and system wide monitoring):
+
+  $ perf c2c record -- -g -a
+
+Please check RECORD OPTIONS section for specific c2c record options.
+
+C2C REPORT
+----------
+The perf c2c report command displays shared data analysis.  It comes in two
+display modes: stdio and tui (default).
+
+The report command workflow is following:
+  - sort all the data based on the cacheline address
+  - store access details for each cacheline
+  - sort all cachelines based on user settings
+  - display data
+
+In general perf report output consist of 2 basic views:
+  1) most expensive cachelines list
+  2) offsets details for each cacheline
+
+For each cacheline in the 1) list we display following data:
+(Both stdio and TUI modes follow the same fields output)
+
+  Index
+  - zero based index to identify the cacheline
+
+  Cacheline
+  - cacheline address (hex number)
+
+  Total records
+  - sum of all cachelines accesses
+
+  Rmt/Lcl Hitm
+  - cacheline percentage of all Remote/Local HITM accesses
+
+  LLC Load Hitm - Total, Lcl, Rmt
+  - count of Total/Local/Remote load HITMs
+
+  Store Reference - Total, L1Hit, L1Miss
+    Total - all store accesses
+    L1Hit - store accesses that hit L1
+    L1Hit - store accesses that missed L1
+
+  Load Dram
+  - count of local and remote DRAM accesses
+
+  LLC Ld Miss
+  - count of all accesses that missed LLC
+
+  Total Loads
+  - sum of all load accesses
+
+  Core Load Hit - FB, L1, L2
+  - count of load hits in FB (Fill Buffer), L1 and L2 cache
+
+  LLC Load Hit - Llc, Rmt
+  - count of LLC and Remote load hits
+
+For each offset in the 2) list we display following data:
+
+  HITM - Rmt, Lcl
+  - % of Remote/Local HITM accesses for given offset within cacheline
+
+  Store Refs - L1 Hit, L1 Miss
+  - % of store accesses that hit/missed L1 for given offset within cacheline
+
+  Data address - Offset
+  - offset address
+
+  Pid
+  - pid of the process responsible for the accesses
+
+  Tid
+  - tid of the process responsible for the accesses
+
+  Code address
+  - code address responsible for the accesses
+
+  cycles - rmt hitm, lcl hitm, load
+    - sum of cycles for given accesses - Remote/Local HITM and generic load
+
+  cpu cnt
+    - number of cpus that participated on the access
+
+  Symbol
+    - code symbol related to the 'Code address' value
+
+  Shared Object
+    - shared object name related to the 'Code address' value
+
+  Source:Line
+    - source information related to the 'Code address' value
+
+  Node
+    - nodes participating on the access (see NODE INFO section)
+
+NODE INFO
+---------
+The 'Node' field displays nodes that accesses given cacheline
+offset. Its output comes in 3 flavors:
+  - node IDs separated by ','
+  - node IDs with stats for each ID, in following format:
+      Node{cpus %hitms %stores}
+  - node IDs with list of affected CPUs in following format:
+      Node{cpu list}
+
+User can switch between above flavors with -N option or
+use 'n' key to interactively switch in TUI mode.
+
+COALESCE
+--------
+User can specify how to sort offsets for cacheline.
+
+Following fields are available and governs the final
+output fields set for caheline offsets output:
+
+  tid   - coalesced by process TIDs
+  pid   - coalesced by process PIDs
+  iaddr - coalesced by code address, following fields are displayed:
+             Code address, Code symbol, Shared Object, Source line
+  dso   - coalesced by shared object
+
+By default the coalescing is setup with 'pid,tid,iaddr'.
+
+STDIO OUTPUT
+------------
+The stdio output displays data on standard output.
+
+Following tables are displayed:
+  Trace Event Information
+  - overall statistics of memory accesses
+
+  Global Shared Cache Line Event Information
+  - overall statistics on shared cachelines
+
+  Shared Data Cache Line Table
+  - list of most expensive cachelines
+
+  Shared Cache Line Distribution Pareto
+  - list of all accessed offsets for each cacheline
+
+TUI OUTPUT
+----------
+The TUI output provides interactive interface to navigate
+through cachelines list and to display offset details.
+
+For details please refer to the help window by pressing '?' key.
+
+CREDITS
+-------
+Although Don Zickus, Dick Fowles and Joe Mario worked together
+to get this implemented, we got lots of early help from Arnaldo
+Carvalho de Melo, Stephane Eranian, Jiri Olsa and Andi Kleen.
+
+C2C BLOG
+--------
+Check Joe's blog on c2c tool for detailed use case explanation:
+  https://joemario.github.io/blog/2016/09/01/c2c-blog/
+
+SEE ALSO
+--------
+linkperf:perf-record[1], linkperf:perf-mem[1]
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 3fc18264d4d1..73973da00b31 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1,3 +1,14 @@
+/*
+ * This is rewrite of original c2c tool introduced in here:
+ *   http://lwn.net/Articles/588866/
+ *
+ * The original tool was changed to fit in current perf state.
+ *
+ * Original authors:
+ *   Don Zickus <dzickus@redhat.com>
+ *   Dick Fowles <fowles@inreach.com>
+ *   Joe Mario <jmario@redhat.com>
+ */
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/stringify.h>
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505023 — [PATCH 31/52] perf c2c report: Add 'cpucnt' sort key

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 31/52] perf c2c report: Add 'cpucnt' sort key
Message-ID<sunis-T1-73@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

It is to be displayed in the single cacheline output:

  cpucnt

It displays number of distinct cpus that hit cacheline.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-ib2kdwam52fby9u2k3ij6lhm@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 043344a720bf..2a1e883580a1 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1015,6 +1015,20 @@ MEAN_ENTRY(mean_rmt_entry,  rmt_hitm);
 MEAN_ENTRY(mean_lcl_entry,  lcl_hitm);
 MEAN_ENTRY(mean_load_entry, load);
 
+static int
+cpucnt_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
+	     struct hist_entry *he)
+{
+	struct c2c_hist_entry *c2c_he;
+	int width = c2c_width(fmt, hpp, he->hists);
+	char buf[10];
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+
+	scnprintf(buf, 10, "%d", bitmap_weight(c2c_he->cpuset, c2c.cpus_cnt));
+	return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
+}
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -1341,6 +1355,14 @@ static struct c2c_dimension dim_mean_load = {
 	.width		= 8,
 };
 
+static struct c2c_dimension dim_cpucnt = {
+	.header		= HEADER_BOTH("cpu", "cnt"),
+	.name		= "cpucnt",
+	.cmp		= empty_cmp,
+	.entry		= cpucnt_entry,
+	.width		= 8,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
@@ -1378,6 +1400,7 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_mean_rmt,
 	&dim_mean_lcl,
 	&dim_mean_load,
+	&dim_cpucnt,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505024 — [PATCH 19/52] perf c2c report: Add llc and remote loads related dimension keys

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 19/52] perf c2c report: Add llc and remote loads related dimension keys
Message-ID<sunir-T1-59@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Add 2 LLC load related dimension key wrappers.

They are to be displayed in the main cachelines overall output:

  ld_lclhit, ld_rmthit

They display bare numbers of LLC and remote loads for cacheline.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-ahjg0voaufefboemjuj9yefh@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 2b9d24fdcaee..6b601836b031 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -418,6 +418,8 @@ STAT_FN(st_l1miss)
 STAT_FN(ld_fbhit)
 STAT_FN(ld_l1hit)
 STAT_FN(ld_l2hit)
+STAT_FN(ld_llchit)
+STAT_FN(rmt_hit)
 
 #define HEADER_LOW(__h)			\
 	{				\
@@ -582,6 +584,22 @@ static struct c2c_dimension dim_ld_l2hit = {
 	.width		= 7,
 };
 
+static struct c2c_dimension dim_ld_llchit = {
+	.header		= HEADER_SPAN("-- LLC Load Hit --", "Llc", 1),
+	.name		= "ld_lclhit",
+	.cmp		= ld_llchit_cmp,
+	.entry		= ld_llchit_entry,
+	.width		= 8,
+};
+
+static struct c2c_dimension dim_ld_rmthit = {
+	.header		= HEADER_SPAN_LOW("Rmt"),
+	.name		= "ld_rmthit",
+	.cmp		= rmt_hit_cmp,
+	.entry		= rmt_hit_entry,
+	.width		= 8,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
@@ -599,6 +617,8 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_ld_fbhit,
 	&dim_ld_l1hit,
 	&dim_ld_l2hit,
+	&dim_ld_llchit,
+	&dim_ld_rmthit,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505025 — [PATCH 39/52] perf c2c report: Add shared cachelines stats stdio output

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 39/52] perf c2c report: Add shared cachelines stats stdio output
Message-ID<sunis-T1-75@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Display global shared cachelines related stats table as part of the
stdio output or when --stats option is speicified:

  $ perf c2c report --stats
  ...
  =================================================
      Global Shared Cache Line Event Information
  =================================================
    Total Shared Cache Lines          :       1384
    Load HITs on shared lines         :       5995
    Fill Buffer Hits on shared lines  :       1726
    L1D hits on shared lines          :       1943
    L2D hits on shared lines          :          0
    LLC hits on shared lines          :       1360
    Locked Access on shared lines     :       1993
    Store HITs on shared lines        :       1504
    Store L1D hits on shared lines    :       1446
    Total Merged records              :       3527

Original-patch-by: Dick Fowles <rfowles@redhat.com>
Original-patch-by: Don Zickus <dzickus@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-p0gty8ctbdzisrniwqxhqmhq@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index d365902acf61..7bbb969f284a 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -56,6 +56,10 @@ struct perf_c2c {
 	bool			 show_src;
 	bool			 use_stdio;
 	bool			 stats_only;
+
+	/* HITM shared clines stats */
+	struct c2c_stats	hitm_stats;
+	int			shared_clines;
 };
 
 static struct perf_c2c c2c;
@@ -1732,6 +1736,39 @@ static int setup_nodes(struct perf_session *session)
 	return 0;
 }
 
+#define HAS_HITMS(__h) ((__h)->stats.lcl_hitm || (__h)->stats.rmt_hitm)
+
+static int resort_hitm_cb(struct hist_entry *he)
+{
+	struct c2c_hist_entry *c2c_he;
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+
+	if (HAS_HITMS(c2c_he)) {
+		c2c.shared_clines++;
+		c2c_add_stats(&c2c.hitm_stats, &c2c_he->stats);
+	}
+
+	return 0;
+}
+
+static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb)
+{
+	struct rb_node *next = rb_first(&hists->entries);
+	int ret = 0;
+
+	while (next) {
+		struct hist_entry *he;
+
+		he = rb_entry(next, struct hist_entry, rb_node);
+		ret = cb(he);
+		if (ret)
+			break;
+		next = rb_next(&he->rb_node);
+	}
+
+	return ret;
+}
+
 static void print_c2c__display_stats(FILE *out)
 {
 	int llc_misses;
@@ -1777,6 +1814,26 @@ static void print_c2c__display_stats(FILE *out)
 	fprintf(out, "  Unable to parse data source       : %10d\n", stats->noparse);
 }
 
+static void print_shared_cacheline_info(FILE *out)
+{
+	struct c2c_stats *stats = &c2c.hitm_stats;
+	int hitm_cnt = stats->lcl_hitm + stats->rmt_hitm;
+
+	fprintf(out, "=================================================\n");
+	fprintf(out, "    Global Shared Cache Line Event Information   \n");
+	fprintf(out, "=================================================\n");
+	fprintf(out, "  Total Shared Cache Lines          : %10d\n", c2c.shared_clines);
+	fprintf(out, "  Load HITs on shared lines         : %10d\n", stats->load);
+	fprintf(out, "  Fill Buffer Hits on shared lines  : %10d\n", stats->ld_fbhit);
+	fprintf(out, "  L1D hits on shared lines          : %10d\n", stats->ld_l1hit);
+	fprintf(out, "  L2D hits on shared lines          : %10d\n", stats->ld_l2hit);
+	fprintf(out, "  LLC hits on shared lines          : %10d\n", stats->ld_llchit + stats->lcl_hitm);
+	fprintf(out, "  Locked Access on shared lines     : %10d\n", stats->locks);
+	fprintf(out, "  Store HITs on shared lines        : %10d\n", stats->store);
+	fprintf(out, "  Store L1D hits on shared lines    : %10d\n", stats->st_l1hit);
+	fprintf(out, "  Total Merged records              : %10d\n", hitm_cnt + stats->store);
+}
+
 static void print_cacheline(struct c2c_hists *c2c_hists,
 			    struct hist_entry *he_cl,
 			    struct perf_hpp_list *hpp_list,
@@ -1841,6 +1898,8 @@ static void perf_c2c__hists_fprintf(FILE *out)
 	setup_pager();
 
 	print_c2c__display_stats(out);
+	fprintf(out, "\n");
+	print_shared_cacheline_info(out);
 
 	if (c2c.stats_only)
 		return;
@@ -2131,7 +2190,8 @@ static int perf_c2c__report(int argc, const char **argv)
 	ui_progress__init(&prog, c2c.hists.hists.nr_entries, "Sorting...");
 
 	hists__collapse_resort(&c2c.hists.hists, NULL);
-	hists__output_resort_cb(&c2c.hists.hists, &prog, resort_cl_cb);
+	hists__output_resort_cb(&c2c.hists.hists, &prog, resort_hitm_cb);
+	hists__iterate_cb(&c2c.hists.hists, resort_cl_cb);
 
 	ui_progress__finish();
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505026 — [PATCH 10/52] perf c2c report: Add cacheline hists processing

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 10/52] perf c2c report: Add cacheline hists processing
Message-ID<sunir-T1-69@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Store cacheline related entries in nested hist object for each cacheline
data. Nested entries are sorted by 'offset' within related cacheline.

We will allow specific sort keys to be configured for nested cacheline
data entries in following patches.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1474558645-19956-18-git-send-email-jolsa@kernel.org
[ he__get_hists() should return NULL when c2c_hists__init() fails ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 92 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 86 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 29fb9573e292..df413b564361 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -61,6 +61,34 @@ static struct hist_entry_ops c2c_entry_ops = {
 	.free	= c2c_he_free,
 };
 
+static int c2c_hists__init(struct c2c_hists *hists,
+			   const char *sort);
+
+static struct hists*
+he__get_hists(struct hist_entry *he,
+	      const char *sort)
+{
+	struct c2c_hist_entry *c2c_he;
+	struct c2c_hists *hists;
+	int ret;
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+	if (c2c_he->hists)
+		return &c2c_he->hists->hists;
+
+	hists = c2c_he->hists = zalloc(sizeof(*hists));
+	if (!hists)
+		return NULL;
+
+	ret = c2c_hists__init(hists, sort);
+	if (ret) {
+		free(hists);
+		return NULL;
+	}
+
+	return &hists->hists;
+}
+
 static int process_sample_event(struct perf_tool *tool __maybe_unused,
 				union perf_event *event,
 				struct perf_sample *sample,
@@ -70,7 +98,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	struct hists *hists = &c2c.hists.hists;
 	struct hist_entry *he;
 	struct addr_location al;
-	struct mem_info *mi;
+	struct mem_info *mi, *mi_dup;
 	int ret;
 
 	if (machine__resolve(machine, &al, sample) < 0) {
@@ -83,19 +111,50 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	if (mi == NULL)
 		return -ENOMEM;
 
+	mi_dup = memdup(mi, sizeof(*mi));
+	if (!mi_dup)
+		goto free_mi;
+
 	he = hists__add_entry_ops(hists, &c2c_entry_ops,
 				  &al, NULL, NULL, mi,
 				  sample, true);
-	if (he == NULL) {
-		free(mi);
-		return -ENOMEM;
-	}
+	if (he == NULL)
+		goto free_mi_dup;
 
 	hists__inc_nr_samples(hists, he->filtered);
 	ret = hist_entry__append_callchain(he, sample);
 
+	if (!ret) {
+		mi = mi_dup;
+
+		mi_dup = memdup(mi, sizeof(*mi));
+		if (!mi_dup)
+			goto free_mi;
+
+		hists = he__get_hists(he, "offset");
+		if (!hists)
+			goto free_mi_dup;
+
+		he = hists__add_entry_ops(hists, &c2c_entry_ops,
+					  &al, NULL, NULL, mi,
+					  sample, true);
+		if (he == NULL)
+			goto free_mi_dup;
+
+		hists__inc_nr_samples(hists, he->filtered);
+		ret = hist_entry__append_callchain(he, sample);
+	}
+
+out:
 	addr_location__put(&al);
 	return ret;
+
+free_mi_dup:
+	free(mi_dup);
+free_mi:
+	free(mi);
+	ret = -ENOMEM;
+	goto out;
 }
 
 static struct perf_c2c c2c = {
@@ -400,6 +459,27 @@ static int c2c_hists__reinit(struct c2c_hists *c2c_hists,
 	return hpp_list__parse(&c2c_hists->list, output, sort);
 }
 
+static int filter_cb(struct hist_entry *he __maybe_unused)
+{
+	return 0;
+}
+
+static int resort_cl_cb(struct hist_entry *he)
+{
+	struct c2c_hist_entry *c2c_he;
+	struct c2c_hists *c2c_hists;
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+	c2c_hists = c2c_he->hists;
+
+	if (c2c_hists) {
+		hists__collapse_resort(&c2c_hists->hists, NULL);
+		hists__output_resort_cb(&c2c_hists->hists, NULL, filter_cb);
+	}
+
+	return 0;
+}
+
 static int perf_c2c__report(int argc, const char **argv)
 {
 	struct perf_session *session;
@@ -458,7 +538,7 @@ static int perf_c2c__report(int argc, const char **argv)
 	ui_progress__init(&prog, c2c.hists.hists.nr_entries, "Sorting...");
 
 	hists__collapse_resort(&c2c.hists.hists, NULL);
-	hists__output_resort(&c2c.hists.hists, &prog);
+	hists__output_resort_cb(&c2c.hists.hists, &prog, resort_cl_cb);
 
 	ui_progress__finish();
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505027 — [PATCH 23/52] perf c2c report: Add hitm percent sort key

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 23/52] perf c2c report: Add hitm percent sort key
Message-ID<sunir-T1-71@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

It is to be displayed in the main cachelines overall output:

  percent_hitm

It displays HITMs percentage for cacheline.

It counts remote HITMs at the moment, but it is changed later to support
local as well, based on the sort configuration.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-czd17qsh5u5z0yc1estz9l2y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 2411fe025bc7..dd356d88285c 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -565,6 +565,87 @@ tot_loads_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
 	return tot_recs_left - tot_recs_right;
 }
 
+typedef double (get_percent_cb)(struct c2c_hist_entry *);
+
+static int
+percent_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+	      struct hist_entry *he, get_percent_cb get_percent)
+{
+	struct c2c_hist_entry *c2c_he;
+	int width = c2c_width(fmt, hpp, he->hists);
+	double per;
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+	per = get_percent(c2c_he);
+
+	return hpp_color_scnprintf(hpp, "%*.2f%%", width - 1, per);
+}
+
+static double percent_hitm(struct c2c_hist_entry *c2c_he)
+{
+	struct c2c_hists *hists;
+	struct c2c_stats *stats;
+	struct c2c_stats *total;
+	int tot, st;
+	double p;
+
+	hists = container_of(c2c_he->he.hists, struct c2c_hists, hists);
+	stats = &c2c_he->stats;
+	total = &hists->stats;
+
+	st  = stats->rmt_hitm;
+	tot = total->rmt_hitm;
+
+	p = tot ? (double) st / tot : 0;
+
+	return 100 * p;
+}
+
+#define PERC_STR(__s, __v)				\
+({							\
+	scnprintf(__s, sizeof(__s), "%.2F%%", __v);	\
+	__s;						\
+})
+
+static int
+percent_hitm_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+		   struct hist_entry *he)
+{
+	struct c2c_hist_entry *c2c_he;
+	int width = c2c_width(fmt, hpp, he->hists);
+	char buf[10];
+	double per;
+
+	c2c_he = container_of(he, struct c2c_hist_entry, he);
+	per = percent_hitm(c2c_he);
+	return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per));
+}
+
+static int
+percent_hitm_color(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+		   struct hist_entry *he)
+{
+	return percent_color(fmt, hpp, he, percent_hitm);
+}
+
+static int64_t
+percent_hitm_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
+		 struct hist_entry *left, struct hist_entry *right)
+{
+	struct c2c_hist_entry *c2c_left;
+	struct c2c_hist_entry *c2c_right;
+	double per_left;
+	double per_right;
+
+	c2c_left  = container_of(left, struct c2c_hist_entry, he);
+	c2c_right = container_of(right, struct c2c_hist_entry, he);
+
+	per_left  = percent_hitm(c2c_left);
+	per_right = percent_hitm(c2c_right);
+
+	return per_left - per_right;
+}
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -768,6 +849,15 @@ static struct c2c_dimension dim_tot_loads = {
 	.width		= 7,
 };
 
+static struct c2c_dimension dim_percent_hitm = {
+	.header		= HEADER_LOW("%hitm"),
+	.name		= "percent_hitm",
+	.cmp		= percent_hitm_cmp,
+	.entry		= percent_hitm_entry,
+	.color		= percent_hitm_color,
+	.width		= 7,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
@@ -790,6 +880,7 @@ static struct c2c_dimension *dimensions[] = {
 	&dim_ld_llcmiss,
 	&dim_tot_recs,
 	&dim_tot_loads,
+	&dim_percent_hitm,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505028 — [PATCH 05/52] perf c2c: Add report subcommand

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 05/52] perf c2c: Add report subcommand
Message-ID<sunis-T1-77@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Adding c2c report subcommand. It reads the perf.data and displays shared
data analysis.

This patch adds report basic wirings. It gets fully implemented in
following patches.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1474558645-19956-13-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 58924c67f818..3fac3a294bdd 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -5,12 +5,74 @@
 #include "builtin.h"
 #include <subcmd/parse-options.h>
 #include "mem-events.h"
+#include "session.h"
+#include "hist.h"
+#include "tool.h"
+#include "data.h"
+
+struct perf_c2c {
+	struct perf_tool tool;
+};
+
+static struct perf_c2c c2c;
 
 static const char * const c2c_usage[] = {
-	"perf c2c",
+	"perf c2c {record|report}",
 	NULL
 };
 
+static const char * const __usage_report[] = {
+	"perf c2c report",
+	NULL
+};
+
+static const char * const *report_c2c_usage = __usage_report;
+
+static int perf_c2c__report(int argc, const char **argv)
+{
+	struct perf_session *session;
+	struct perf_data_file file = {
+		.mode = PERF_DATA_MODE_READ,
+	};
+	const struct option c2c_options[] = {
+	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
+		   "file", "vmlinux pathname"),
+	OPT_INCR('v', "verbose", &verbose,
+		 "be more verbose (show counter open errors, etc)"),
+	OPT_STRING('i', "input", &input_name, "file",
+		   "the input file to process"),
+	OPT_END()
+	};
+	int err = 0;
+
+	argc = parse_options(argc, argv, c2c_options, report_c2c_usage,
+			     PARSE_OPT_STOP_AT_NON_OPTION);
+	if (!argc)
+		usage_with_options(report_c2c_usage, c2c_options);
+
+	file.path = input_name;
+
+	session = perf_session__new(&file, 0, &c2c.tool);
+	if (session == NULL) {
+		pr_debug("No memory for session\n");
+		goto out;
+	}
+
+	if (symbol__init(&session->header.env) < 0)
+		goto out_session;
+
+	/* No pipe support at the moment. */
+	if (perf_data_file__is_pipe(session->file)) {
+		pr_debug("No pipe support at the moment.\n");
+		goto out_session;
+	}
+
+out_session:
+	perf_session__delete(session);
+out:
+	return err;
+}
+
 static int parse_record_events(const struct option *opt __maybe_unused,
 			       const char *str, int unset __maybe_unused)
 {
@@ -129,6 +191,8 @@ int cmd_c2c(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	if (!strncmp(argv[0], "rec", 3)) {
 		return perf_c2c__record(argc, argv);
+	} else if (!strncmp(argv[0], "rep", 3)) {
+		return perf_c2c__report(argc, argv);
 	} else {
 		usage_with_options(c2c_usage, c2c_options);
 	}
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505029 — [PATCH 04/52] perf c2c: Add record subcommand

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 04/52] perf c2c: Add record subcommand
Message-ID<sunis-T1-79@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

Adding c2c record subcommand. It setups options related to HITM
cacheline analysis and calls standard perf record command.

  $ sudo perf c2c record -v -- -a
  calling: record -W -d --sample-cpu -e cpu/mem-loads,ldlat=30/P -e cpu/mem-stores/P -a
  ...

It produces perf.data, which is to be reported by perf c2c report, that
comes in following patches.

Details are described in the man page, which is added in one of the
following patches.

Committer notes:

Testing it:

  # perf c2c record -a sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 5.050 MB perf.data (412 samples) ]
  # ls -la perf.data
  -rw-------. 1 root root 5301752 Oct  4 13:32 perf.data
  # perf evlist
  cpu/mem-loads,ldlat=30/P
  cpu/mem-stores/P
  # perf evlist -v
  cpu/mem-loads,ldlat=30/P: type: 4, size: 112, config: 0x1cd, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ADDR|ID|CPU|PERIOD|DATA_SRC|WEIGHT, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, mmap_data: 1, sample_id_all: 1, mmap2: 1, comm_exec: 1, { bp_addr, config1 }: 0x1f
  cpu/mem-stores/P: type: 4, size: 112, config: 0x82d0, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|ADDR|ID|CPU|PERIOD|DATA_SRC|WEIGHT, read_format: ID, disabled: 1, inherit: 1, freq: 1, precise_ip: 3, sample_id_all: 1
  #
  # perf report --stdio
  <SNIP>
  # Total Lost Samples: 14
  # Samples: 216  of event 'cpu/mem-loads,ldlat=30/P'
  # Event count (approx.): 15207
  # Overhead  Symbol                                 Shared Object
  # ........  .....................................  ............................
      10.32%  [k] update_blocked_averages            [kernel.vmlinux]
       3.43%  [.] 0x00000000001a2122                 qemu-system-x86_64 (deleted)
       2.52%  [k] enqueue_entity                     [kernel.vmlinux]
       1.88%  [.] g_main_context_query               libglib-2.0.so.0.4800.2
       1.86%  [k] __schedule                         [kernel.vmlinux]
  <SNIP>
  # Samples: 196  of event 'cpu/mem-stores/P'
  # Event count (approx.): 14771346
  # Overhead  Symbol                               Shared Object
  # ........  ...................................  ............................
      13.91%  [k] intel_idle                       [kernel.vmlinux]
       3.02%  [.] 0x00000000022f06ea               chrome
       2.94%  [.] 0x00000000001a1b4c               qemu-system-x86_64 (deleted)
       2.94%  [.] 0x000000000019d8e4               qemu-system-x86_64 (deleted)
       2.38%  [.] 0x00000000001a1c52               qemu-system-x86_64 (deleted)
  <SNIP>

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1474558645-19956-12-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 8252ed0ba5d0..58924c67f818 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -4,12 +4,116 @@
 #include "debug.h"
 #include "builtin.h"
 #include <subcmd/parse-options.h>
+#include "mem-events.h"
 
 static const char * const c2c_usage[] = {
 	"perf c2c",
 	NULL
 };
 
+static int parse_record_events(const struct option *opt __maybe_unused,
+			       const char *str, int unset __maybe_unused)
+{
+	bool *event_set = (bool *) opt->value;
+
+	*event_set = true;
+	return perf_mem_events__parse(str);
+}
+
+
+static const char * const __usage_record[] = {
+	"perf c2c record [<options>] [<command>]",
+	"perf c2c record [<options>] -- <command> [<options>]",
+	NULL
+};
+
+static const char * const *record_mem_usage = __usage_record;
+
+static int perf_c2c__record(int argc, const char **argv)
+{
+	int rec_argc, i = 0, j;
+	const char **rec_argv;
+	int ret;
+	bool all_user = false, all_kernel = false;
+	bool event_set = false;
+	struct option options[] = {
+	OPT_CALLBACK('e', "event", &event_set, "event",
+		     "event selector. Use 'perf mem record -e list' to list available events",
+		     parse_record_events),
+	OPT_INCR('v', "verbose", &verbose,
+		 "be more verbose (show counter open errors, etc)"),
+	OPT_BOOLEAN('u', "all-user", &all_user, "collect only user level data"),
+	OPT_BOOLEAN('k', "all-kernel", &all_kernel, "collect only kernel level data"),
+	OPT_UINTEGER('l', "ldlat", &perf_mem_events__loads_ldlat, "setup mem-loads latency"),
+	OPT_END()
+	};
+
+	if (perf_mem_events__init()) {
+		pr_err("failed: memory events not supported\n");
+		return -1;
+	}
+
+	argc = parse_options(argc, argv, options, record_mem_usage,
+			     PARSE_OPT_KEEP_UNKNOWN);
+
+	rec_argc = argc + 10; /* max number of arguments */
+	rec_argv = calloc(rec_argc + 1, sizeof(char *));
+	if (!rec_argv)
+		return -1;
+
+	rec_argv[i++] = "record";
+
+	if (!event_set) {
+		perf_mem_events[PERF_MEM_EVENTS__LOAD].record  = true;
+		perf_mem_events[PERF_MEM_EVENTS__STORE].record = true;
+	}
+
+	if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record)
+		rec_argv[i++] = "-W";
+
+	rec_argv[i++] = "-d";
+	rec_argv[i++] = "--sample-cpu";
+
+	for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
+		if (!perf_mem_events[j].record)
+			continue;
+
+		if (!perf_mem_events[j].supported) {
+			pr_err("failed: event '%s' not supported\n",
+			       perf_mem_events[j].name);
+			return -1;
+		}
+
+		rec_argv[i++] = "-e";
+		rec_argv[i++] = perf_mem_events__name(j);
+	};
+
+	if (all_user)
+		rec_argv[i++] = "--all-user";
+
+	if (all_kernel)
+		rec_argv[i++] = "--all-kernel";
+
+	for (j = 0; j < argc; j++, i++)
+		rec_argv[i] = argv[j];
+
+	if (verbose > 0) {
+		pr_debug("calling: ");
+
+		j = 0;
+
+		while (rec_argv[j]) {
+			pr_debug("%s ", rec_argv[j]);
+			j++;
+		}
+		pr_debug("\n");
+	}
+
+	ret = cmd_record(i, rec_argv, NULL);
+	free(rec_argv);
+	return ret;
+}
+
 int cmd_c2c(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	const struct option c2c_options[] = {
@@ -19,5 +123,15 @@ int cmd_c2c(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	argc = parse_options(argc, argv, c2c_options, c2c_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
+
+	if (!argc)
+		usage_with_options(c2c_usage, c2c_options);
+
+	if (!strncmp(argv[0], "rec", 3)) {
+		return perf_c2c__record(argc, argv);
+	} else {
+		usage_with_options(c2c_usage, c2c_options);
+	}
+
 	return 0;
 }
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505030 — [PATCH 15/52] perf c2c report: Add 'iaddr' dimension key

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-20 17:20 +0200
Subject[PATCH 15/52] perf c2c report: Add 'iaddr' dimension key
Message-ID<sunis-T1-81@gated-at.bofh.it>
In reply to#1505012
From: Jiri Olsa <jolsa@kernel.org>

It displays the code address (as hex number) responsible for the
accesses.

Using c2c wrapper to standard 'symbol_iaddr' object to define own header
and simple (just address) code address output.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-rhshygbst6kr75kju0muwt5x@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-c2c.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 01d541fd7022..bb9d01874836 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -328,6 +328,27 @@ offset_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
 	return (int64_t)(r - l);
 }
 
+static int
+iaddr_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
+	    struct hist_entry *he)
+{
+	uint64_t addr = 0;
+	int width = c2c_width(fmt, hpp, he->hists);
+	char buf[20];
+
+	if (he->mem_info)
+		addr = he->mem_info->iaddr.addr;
+
+	return scnprintf(hpp->buf, hpp->size, "%*s", width, HEX_STR(buf, addr));
+}
+
+static int64_t
+iaddr_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
+	  struct hist_entry *left, struct hist_entry *right)
+{
+	return sort__iaddr_cmp(left, right);
+}
+
 #define HEADER_LOW(__h)			\
 	{				\
 		.line[1] = {		\
@@ -379,9 +400,18 @@ static struct c2c_dimension dim_offset = {
 	.width		= 18,
 };
 
+static struct c2c_dimension dim_iaddr = {
+	.header		= HEADER_LOW("Code address"),
+	.name		= "iaddr",
+	.cmp		= iaddr_cmp,
+	.entry		= iaddr_entry,
+	.width		= 18,
+};
+
 static struct c2c_dimension *dimensions[] = {
 	&dim_dcacheline,
 	&dim_offset,
+	&dim_iaddr,
 	NULL,
 };
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1505319

FromKim Phillips <kim.phillips@arm.com>
Date2016-10-21 01:10 +0200
Message-ID<suuDg-5F6-11@gated-at.bofh.it>
In reply to#1505012
On Thu, 20 Oct 2016 12:03:44 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-c2c-for-mingo-20161020

Running this as a normal user may not be the best thing to do, but I'm
pretty sure the TUI c2c report shouldn't sigsegv:

-----

$ tools/perf/perf c2c record -e ldlat-loads lat_mem_rd 16 4096
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,
check /proc/sys/kernel/kptr_restrict.

Samples in kernel functions may not be resolved if a suitable vmlinux
file is not found in the buildid cache or in the vmlinux path.

Samples in kernel modules won't be resolved at all.

If some relocation was applied (e.g. kexec) symbols may be misresolved
even with a suitable vmlinux or kallsyms file.

Couldn't record kernel reference relocation symbol
Symbol resolution may be skewed if relocation was used (e.g. kexec).
Check /proc/kallsyms permission or run as root.
"stride=4096
0.00391 1.224
0.00586 1.220
0.00781 1.229
0.01172 1.230
0.01562 1.222
0.02344 1.225
0.03125 1.234
0.04688 3.659
0.06250 3.673
0.09375 3.683
0.12500 3.693
0.18750 5.803
0.25000 7.223
0.37500 12.460
0.50000 13.308
0.75000 13.759
1.00000 13.712
1.50000 12.916
2.00000 12.508
3.00000 12.245
4.00000 12.474
6.00000 27.549
8.00000 65.141
12.00000 79.808
16.00000 84.384

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.008 MB perf.data ]

$ tools/perf/perf c2c report --stdio
=================================================
            Trace Event Information              
=================================================
  Total records                     :          0
  Locked Load/Store Operations      :          0
  Load Operations                   :          0
  Loads - uncacheable               :          0
  Loads - IO                        :          0
  Loads - Miss                      :          0
  Loads - no mapping                :          0
  Load Fill Buffer Hit              :          0
  Load L1D hit                      :          0
  Load L2D hit                      :          0
  Load LLC hit                      :          0
  Load Local HITM                   :          0
  Load Remote HITM                  :          0
  Load Remote HIT                   :          0
  Load Local DRAM                   :          0
  Load Remote DRAM                  :          0
  Load MESI State Exclusive         :          0
  Load MESI State Shared            :          0
  Load LLC Misses                   :          0
  LLC Misses to Local DRAM          :       -nan%
  LLC Misses to Remote DRAM         :       -nan%
  LLC Misses to Remote cache (HIT)  :       -nan%
  LLC Misses to Remote cache (HITM) :       -nan%
  Store Operations                  :          0
  Store - uncacheable               :          0
  Store - no mapping                :          0
  Store L1D Hit                     :          0
  Store L1D Miss                    :          0
  No Page Map Rejects               :          0
  Unable to parse data source       :          0

=================================================
    Global Shared Cache Line Event Information   
=================================================
  Total Shared Cache Lines          :          0
  Load HITs on shared lines         :          0
  Fill Buffer Hits on shared lines  :          0
  L1D hits on shared lines          :          0
  L2D hits on shared lines          :          0
  LLC hits on shared lines          :          0
  Locked Access on shared lines     :          0
  Store HITs on shared lines        :          0
  Store L1D hits on shared lines    :          0
  Total Merged records              :          0

=================================================
                 c2c details                     
=================================================
  Events                            : cpu/mem-loads,ldlat=30/P:u
  Cachelines sort on                : Remote HITMs
  Cacheline data grouping           : offset,pid,tid,iaddr

=================================================
           Shared Data Cache Line Table          
=================================================
#
#                              Total      Rmt  ----- LLC Load Hitm -----  ---- Store Reference ----  --- Load Dram ----      LLC    T
# Index           Cacheline  records     Hitm    Total      Lcl      Rmt    Total    L1Hit   L1Miss       Lcl       Rmt  Ld Miss    L
# .....  ..................  .......  .......  .......  .......  .......  .......  .......  .......  ........  ........  .......  ...
#

=================================================
      Shared Cache Line Distribution Pareto      
=================================================
#

$ tools/perf/perf c2c report
perf: Segmentation fault
-------- backtrace --------
tools/perf/perf[0x56504b]
/lib/x86_64-linux-gnu/libc.so.6(+0x354a0)[0x7facb45794a0]
tools/perf/perf(cmd_c2c+0x13bc)[0x45b2fc]
tools/perf/perf[0x48df61]
tools/perf/perf(main+0x6f6)[0x4249b6]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7facb4564830]
tools/perf/perf(_start+0x29)[0x424aa9]
[0x0]

$ gdb tools/perf/perf
...
(gdb) run c2c report
...
 Program received signal SIGSEGV, Segmentation fault.
                                                   c2c_browser__update_nr_entries (hb=<optimized out>, hb=<optimized out>) at builtin-c2c.c:2142
2142				nr_entries++;
(gdb) bt
#0  c2c_browser__update_nr_entries (hb=<optimized out>, hb=<optimized out>) at builtin-c2c.c:2142
#1  perf_c2c__hists_browse (hists=0x8b2d90 <c2c+240>) at builtin-c2c.c:2287
#2  perf_c2c_display (session=0x205b1a0) at builtin-c2c.c:2316
#3  perf_c2c__report (argv=<optimized out>, argc=<optimized out>) at builtin-c2c.c:2621
#4  cmd_c2c (argc=<optimized out>, argv=<optimized out>, prefix=<optimized out>) at builtin-c2c.c:2748
#5  0x000000000048df61 in run_builtin (p=p@entry=0x8be168 <commands+72>, argc=argc@entry=2, argv=argv@entry=0x7fffffffddb0)
    at perf.c:358
#6  0x00000000004249b6 in handle_internal_command (argv=0x7fffffffddb0, argc=2) at perf.c:420
#7  run_argv (argv=0x7fffffffdb40, argcp=0x7fffffffdb4c) at perf.c:466
#8  main (argc=2, argv=0x7fffffffddb0) at perf.c:610
(gdb) 

All the above work fine when run under sudo.

Here are some other details, in case they matter:

$ uname -r
4.7.9+
$ dmesg | grep Perf
[    0.112348] Performance Events: PEBS fmt3+, 32-deep LBR, Skylake events, full-width counters, Intel PMU driver.
$ make -C tools/perf clean  >& /dev/null  ; make -C tools/perf |& grep -i warn
Warning: x86_64's syscall_64.tbl differs from kernel
Warning: tools/include/uapi/linux/bpf.h differs from kernel
Warning: tools/arch/x86/lib/memcpy_64.S differs from kernel
Warning: tools/arch/x86/lib/memset_64.S differs from kernel
Warning: tools/arch/arm/include/uapi/asm/kvm.h differs from kernel
Warning: tools/include/uapi/asm-generic/mman-common.h differs from kernel
$ tools/perf/perf config -l
buildid.dir=/dev/null
$ tools/perf/perf mem record -e list
ldlat-loads  : available
ldlat-stores : available
$ 

Thanks,

Kim

[toc] | [prev] | [next] | [standalone]


#1505349 — [PATCH] perf c2c report: Properly check data presence in rb_tree loop

FromJiri Olsa <jolsa@redhat.com>
Date2016-10-21 02:20 +0200
Subject[PATCH] perf c2c report: Properly check data presence in rb_tree loop
Message-ID<suvIZ-6lN-11@gated-at.bofh.it>
In reply to#1505319
On Thu, Oct 20, 2016 at 06:02:24PM -0500, Kim Phillips wrote:

SNIP

> (gdb) bt
> #0  c2c_browser__update_nr_entries (hb=<optimized out>, hb=<optimized out>) at builtin-c2c.c:2142
> #1  perf_c2c__hists_browse (hists=0x8b2d90 <c2c+240>) at builtin-c2c.c:2287
> #2  perf_c2c_display (session=0x205b1a0) at builtin-c2c.c:2316
> #3  perf_c2c__report (argv=<optimized out>, argc=<optimized out>) at builtin-c2c.c:2621
> #4  cmd_c2c (argc=<optimized out>, argv=<optimized out>, prefix=<optimized out>) at builtin-c2c.c:2748
> #5  0x000000000048df61 in run_builtin (p=p@entry=0x8be168 <commands+72>, argc=argc@entry=2, argv=argv@entry=0x7fffffffddb0)
>     at perf.c:358
> #6  0x00000000004249b6 in handle_internal_command (argv=0x7fffffffddb0, argc=2) at perf.c:420
> #7  run_argv (argv=0x7fffffffdb40, argcp=0x7fffffffdb4c) at perf.c:466
> #8  main (argc=2, argv=0x7fffffffddb0) at perf.c:610
> (gdb) 
> 
> All the above work fine when run under sudo.

ugh, stupid mistake.. attached patch fixes that for me

thanks,
jirka


---
Kim reported crash when there's no data stored. In this case
the TUI code crashes in c2c_browser__update_nr_entries, because
we dont check the initial rb_tree node for NULL.

Adding the missing check.

Reported-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-c2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index dc4f0636dfa1..c6d0dda594d9 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2135,14 +2135,14 @@ static void c2c_browser__update_nr_entries(struct hist_browser *hb)
 	u64 nr_entries = 0;
 	struct rb_node *nd = rb_first(&hb->hists->entries);
 
-	do {
+	while (nd) {
 		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
 
 		if (!he->filtered)
 			nr_entries++;
 
 		nd = rb_next(nd);
-	} while (nd);
+	}
 
 	hb->nr_non_filtered_entries = nr_entries;
 }
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1506247 — Re: [PATCH] perf c2c report: Properly check data presence in rb_tree loop

FromKim Phillips <kim.phillips@arm.com>
Date2016-10-21 21:30 +0200
SubjectRe: [PATCH] perf c2c report: Properly check data presence in rb_tree loop
Message-ID<suNFT-1vW-7@gated-at.bofh.it>
In reply to#1505349
On Fri, 21 Oct 2016 02:17:06 +0200
Jiri Olsa <jolsa@redhat.com> wrote:

> On Thu, Oct 20, 2016 at 06:02:24PM -0500, Kim Phillips wrote:
> 
> SNIP
> 
> > (gdb) bt
> > #0  c2c_browser__update_nr_entries (hb=<optimized out>, hb=<optimized out>) at builtin-c2c.c:2142
> > #1  perf_c2c__hists_browse (hists=0x8b2d90 <c2c+240>) at builtin-c2c.c:2287
> > #2  perf_c2c_display (session=0x205b1a0) at builtin-c2c.c:2316
> > #3  perf_c2c__report (argv=<optimized out>, argc=<optimized out>) at builtin-c2c.c:2621
> > #4  cmd_c2c (argc=<optimized out>, argv=<optimized out>, prefix=<optimized out>) at builtin-c2c.c:2748
> > #5  0x000000000048df61 in run_builtin (p=p@entry=0x8be168 <commands+72>, argc=argc@entry=2, argv=argv@entry=0x7fffffffddb0)
> >     at perf.c:358
> > #6  0x00000000004249b6 in handle_internal_command (argv=0x7fffffffddb0, argc=2) at perf.c:420
> > #7  run_argv (argv=0x7fffffffdb40, argcp=0x7fffffffdb4c) at perf.c:466
> > #8  main (argc=2, argv=0x7fffffffddb0) at perf.c:610
> > (gdb) 
> > 
> > All the above work fine when run under sudo.
> 
> ugh, stupid mistake.. attached patch fixes that for me

I see it's been merged here now:

https://git.kernel.org/cgit/linux/kernel/git/acme/linux.git/commit/?h=perf/c2c&id=5a1a99cd2e4e15571a74f65facf05f806d5303fd

and the updated perf-c2c-for-mingo-20161021 works, so thanks all.

Kim

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | linux.kernel


csiph-web