mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Linux Weekly News <lwn@lwn.net>,
	Jiri Olsa <jolsa@kernel.org>, Andi Kleen <andi@firstfloor.org>,
	David Ahern <dsahern@gmail.com>, Don Zickus <dzickus@redhat.com>,
	Joe Mario <jmario@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 29/52] perf c2c report: Add 'node' sort key
Date: Thu, 20 Oct 2016 12:04:13 -0300	[thread overview]
Message-ID: <1476975876-2522-30-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1476975876-2522-1-git-send-email-acme@kernel.org>

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

  parent reply	other threads:[~2016-10-20 15:10 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-20 15:03 [GIT PULL 00/52] New Tool: perf c2c Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 01/52] perf c2c: Introduce c2c_decode_stats function Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 02/52] perf c2c: Introduce c2c_add_stats function Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 03/52] perf c2c: Add c2c command Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 04/52] perf c2c: Add record subcommand Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 05/52] perf c2c: Add report subcommand Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 06/52] perf c2c report: Add dimension support Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 07/52] perf c2c report: Add sort_entry " Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 08/52] perf c2c report: Fallback to standard dimensions Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 09/52] perf c2c report: Add sample processing Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 10/52] perf c2c report: Add cacheline hists processing Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 11/52] perf c2c report: Decode c2c_stats for hist entries Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 12/52] perf c2c report: Add header macros Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 13/52] perf c2c report: Add 'dcacheline' dimension key Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 14/52] perf c2c report: Add 'offset' " Arnaldo Carvalho de Melo
2016-10-20 15:03 ` [PATCH 15/52] perf c2c report: Add 'iaddr' " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 16/52] perf c2c report: Add hitm related dimension keys Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 17/52] perf c2c report: Add stores " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 18/52] perf c2c report: Add loads " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 19/52] perf c2c report: Add llc and remote " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 20/52] perf c2c report: Add llc load miss dimension key Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 21/52] perf c2c report: Add total record sort key Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 22/52] perf c2c report: Add total loads " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 23/52] perf c2c report: Add hitm percent " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 24/52] perf c2c report: Add hitm/store percent related sort keys Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 25/52] perf c2c report: Add dram " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 26/52] perf c2c report: Add 'pid' sort key Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 27/52] perf c2c report: Add 'tid' " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 28/52] perf c2c report: Add 'symbol' and 'dso' sort keys Arnaldo Carvalho de Melo
2016-10-20 15:04 ` Arnaldo Carvalho de Melo [this message]
2016-10-20 15:04 ` [PATCH 30/52] perf c2c report: Add stats related " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 31/52] perf c2c report: Add 'cpucnt' sort key Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 32/52] perf c2c report: Add src line " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 33/52] perf c2c report: Setup number of header lines for hists Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 34/52] perf c2c report: Set final resort fields Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 35/52] perf c2c report: Add stdio output support Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 36/52] perf c2c report: Add main TUI browser Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 37/52] perf c2c report: Add TUI cacheline browser Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 38/52] perf c2c report: Add global stats stdio output Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 39/52] perf c2c report: Add shared cachelines " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 40/52] perf c2c report: Add c2c related " Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 41/52] perf c2c report: Allow to report callchains Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 42/52] perf c2c report: Limit the cachelines table entries Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 43/52] perf c2c report: Add support to choose local HITMs Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 44/52] perf c2c report: Allow to set cacheline sort fields Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 45/52] perf c2c report: Recalc width of global sort entries Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 46/52] perf c2c report: Add cacheline index entry Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 47/52] perf c2c report: Add support to manage symbol name length Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 48/52] perf c2c report: Iterate node display in browser Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 49/52] perf c2c report: Add help windows Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 50/52] perf c2c: Add man page and credits Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 51/52] perf c2c report: Add --no-source option Arnaldo Carvalho de Melo
2016-10-20 15:04 ` [PATCH 52/52] perf c2c report: Add --show-all option Arnaldo Carvalho de Melo
2016-10-20 23:02 ` [GIT PULL 00/52] New Tool: perf c2c Kim Phillips
2016-10-21  0:17   ` [PATCH] perf c2c report: Properly check data presence in rb_tree loop Jiri Olsa
2016-10-21 19:23     ` Kim Phillips
2016-10-22  8:49     ` [tip:perf/core] perf c2c report: Add main TUI browser tip-bot for Jiri Olsa
2016-10-21  0:21   ` [GIT PULL 00/52] New Tool: perf c2c Jiri Olsa
2016-10-22  8:28 ` Ingo Molnar
2016-10-23 11:05   ` Jiri Olsa
2016-10-23 23:47     ` Andi Kleen
2016-10-24  6:32       ` Jiri Olsa
2016-10-24  9:23     ` Ingo Molnar
2016-10-24  9:42       ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476975876-2522-30-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.com \
    --cc=dzickus@redhat.com \
    --cc=jmario@redhat.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwn@lwn.net \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome