public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] rbtree: Introduce rb_for_each_entry
@ 2010-01-13 13:01 Arnaldo Carvalho de Melo
  2010-01-13 13:01 ` [PATCH 2/3] perf tools: Use rb_for_each_entry Arnaldo Carvalho de Melo
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-01-13 13:01 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Peter Zijlstra,
	Paul Mackerras

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

Similar to list_for_each_entry, helps reducing boilerplate in many
places and makes rbtrees closer to list.h macros.

First conversion will be in the tools/perf.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 include/linux/rbtree.h |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
index 9c29541..044b150 100644
--- a/include/linux/rbtree.h
+++ b/include/linux/rbtree.h
@@ -158,4 +158,16 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
 	*rb_link = node;
 }
 
+/**
+ * rb_for_each_entry - iterate over rbtree of given type
+ * @pos:	the type * to hold the current entry being traversed
+ * @node:	the rb_node to hold the current entry being traversed
+ * @root:	the root for your tree.
+ * @member:	the name of the rb_node within the struct.
+ */
+#define rb_for_each_entry(pos, node, root, member)			\
+	for (node = rb_first(root);					\
+	     node && (pos = rb_entry(node, typeof(*pos), member));	\
+	     node = rb_next(node))
+
 #endif	/* _LINUX_RBTREE_H */
-- 
1.6.2.5


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

* [PATCH 2/3] perf tools: Use rb_for_each_entry
  2010-01-13 13:01 [PATCH 1/3] rbtree: Introduce rb_for_each_entry Arnaldo Carvalho de Melo
@ 2010-01-13 13:01 ` Arnaldo Carvalho de Melo
  2010-01-13 13:01 ` [PATCH 3/3] perf tools: Encode kernel module mappings in perf.data Arnaldo Carvalho de Melo
  2010-01-13 13:16 ` [PATCH 1/3] rbtree: Introduce rb_for_each_entry Peter Zijlstra
  2 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-01-13 13:01 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Peter Zijlstra,
	Paul Mackerras

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

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-annotate.c |   19 ++++++-------------
 tools/perf/builtin-diff.c     |    5 ++---
 tools/perf/builtin-kmem.c     |   12 +++++-------
 tools/perf/builtin-sched.c    |   10 ++--------
 tools/perf/builtin-top.c      |   10 +++-------
 tools/perf/util/symbol.c      |   16 ++++++----------
 6 files changed, 24 insertions(+), 48 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 117bbae..61b644e 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -349,19 +349,12 @@ static void print_summary(const char *filename)
 		return;
 	}
 
-	node = rb_first(&root_sym_ext);
-	while (node) {
-		double percent;
-		const char *color;
-		char *path;
-
-		sym_ext = rb_entry(node, struct sym_ext, node);
-		percent = sym_ext->percent;
-		color = get_percent_color(percent);
-		path = sym_ext->path;
+	rb_for_each_entry(sym_ext, node, &root_sym_ext, node) {
+		double percent = sym_ext->percent;
+		const char *color = get_percent_color(percent);
+		char *path = sym_ext->path;
 
 		color_fprintf(stdout, color, " %7.2f %s", percent, path);
-		node = rb_next(node);
 	}
 }
 
@@ -428,9 +421,9 @@ static void annotate_sym(struct hist_entry *he)
 static void perf_session__find_annotations(struct perf_session *self)
 {
 	struct rb_node *nd;
+	struct hist_entry *he;
 
-	for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) {
-		struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
+	rb_for_each_entry(he, nd, &self->hists, rb_node) {
 		struct sym_priv *priv;
 
 		if (he->sym == NULL)
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 924bfb7..48a1e61 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -143,11 +143,10 @@ static void perf_session__match_hists(struct perf_session *old_session,
 				      struct perf_session *new_session)
 {
 	struct rb_node *nd;
+	struct hist_entry *pos;
 
-	for (nd = rb_first(&new_session->hists); nd; nd = rb_next(nd)) {
-		struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node);
+	rb_for_each_entry(pos, nd, &new_session->hists, rb_node)
 		pos->pair = perf_session__find_hist_entry(old_session, pos);
-	}
 }
 
 static int __cmd_diff(void)
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 88c570c..2d2990d 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -354,21 +354,21 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
 			   int n_lines, int is_caller)
 {
 	struct rb_node *next;
+	struct alloc_stat *data;
 
 	printf("%.102s\n", graph_dotted_line);
 	printf(" %-34s |",  is_caller ? "Callsite": "Alloc Ptr");
 	printf(" Total_alloc/Per | Total_req/Per   | Hit   | Ping-pong | Frag\n");
 	printf("%.102s\n", graph_dotted_line);
 
-	next = rb_first(root);
-
-	while (next && n_lines--) {
-		struct alloc_stat *data = rb_entry(next, struct alloc_stat,
-						   node);
+	rb_for_each_entry(data, next, root, node) {
 		struct symbol *sym = NULL;
 		char buf[BUFSIZ];
 		u64 addr;
 
+		if (n_lines--)
+			break;
+
 		if (is_caller) {
 			addr = data->call_site;
 			if (!raw_ip)
@@ -391,8 +391,6 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
 		       (unsigned long)data->hit,
 		       (unsigned long)data->pingpong,
 		       fragmentation(data->bytes_req, data->bytes_alloc));
-
-		next = rb_next(next);
 	}
 
 	if (n_lines == -1)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 702322f..88be245 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1706,6 +1706,7 @@ static void print_bad_events(void)
 static void __cmd_lat(void)
 {
 	struct rb_node *next;
+	struct work_atoms *work_list;
 
 	setup_pager();
 	read_events();
@@ -1715,15 +1716,8 @@ static void __cmd_lat(void)
 	printf("  Task                  |   Runtime ms  | Switches | Average delay ms | Maximum delay ms | Maximum delay at     |\n");
 	printf(" ---------------------------------------------------------------------------------------------------------------\n");
 
-	next = rb_first(&sorted_atom_root);
-
-	while (next) {
-		struct work_atoms *work_list;
-
-		work_list = rb_entry(next, struct work_atoms, node);
+	rb_for_each_entry(work_list, next, &sorted_atom_root, node)
 		output_lat_thread(work_list);
-		next = rb_next(next);
-	}
 
 	printf(" -----------------------------------------------------------------------------------------\n");
 	printf("  TOTAL:                |%11.3f ms |%9Ld |\n",
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index ddc584b..8f0c837 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -532,8 +532,7 @@ static void print_sym_table(void)
 	/*
 	 * Find the longest symbol name that will be displayed
 	 */
-	for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
-		syme = rb_entry(nd, struct sym_entry, rb_node);
+	rb_for_each_entry(syme, nd, &tmp, rb_node) {
 		if (++printed > print_entries ||
 		    (int)syme->snap_count < count_filter)
 			continue;
@@ -567,13 +566,10 @@ static void print_sym_table(void)
 	printf(" %-*.*s", dso_width, dso_width, graph_line);
 	puts("\n");
 
-	for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
-		struct symbol *sym;
+	rb_for_each_entry(syme, nd, &tmp, rb_node) {
+		struct symbol *sym = sym_entry__symbol(syme);
 		double pcnt;
 
-		syme = rb_entry(nd, struct sym_entry, rb_node);
-		sym = sym_entry__symbol(syme);
-
 		if (++printed > print_entries || (int)syme->snap_count < count_filter)
 			continue;
 
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 8e6627e..85b96ea 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -292,11 +292,10 @@ static void symbols__insert_by_name(struct rb_root *self, struct symbol *sym)
 static void symbols__sort_by_name(struct rb_root *self, struct rb_root *source)
 {
 	struct rb_node *nd;
+	struct symbol *pos;
 
-	for (nd = rb_first(source); nd; nd = rb_next(nd)) {
-		struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
+	rb_for_each_entry(pos, nd, source, rb_node)
 		symbols__insert_by_name(self, pos);
-	}
 }
 
 static struct symbol *symbols__find_by_name(struct rb_root *self, const char *name)
@@ -371,14 +370,13 @@ size_t dso__fprintf_buildid(struct dso *self, FILE *fp)
 size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp)
 {
 	struct rb_node *nd;
+	struct symbol *pos;
 	size_t ret = fprintf(fp, "dso: %s (", self->short_name);
 
 	ret += dso__fprintf_buildid(self, fp);
 	ret += fprintf(fp, ")\n");
-	for (nd = rb_first(&self->symbols[type]); nd; nd = rb_next(nd)) {
-		struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
+	rb_for_each_entry(pos, nd, &self->symbols[type], rb_node)
 		ret += symbol__fprintf(pos, fp);
-	}
 
 	return ret;
 }
@@ -1339,13 +1337,11 @@ struct map *map_groups__find_by_name(struct map_groups *self,
 				     enum map_type type, const char *name)
 {
 	struct rb_node *nd;
+	struct map *map;
 
-	for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
-		struct map *map = rb_entry(nd, struct map, rb_node);
-
+	rb_for_each_entry(map, nd, &self->maps[type], rb_node)
 		if (map->dso && strcmp(map->dso->name, name) == 0)
 			return map;
-	}
 
 	return NULL;
 }
-- 
1.6.2.5


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

* [PATCH 3/3] perf tools: Encode kernel module mappings in perf.data
  2010-01-13 13:01 [PATCH 1/3] rbtree: Introduce rb_for_each_entry Arnaldo Carvalho de Melo
  2010-01-13 13:01 ` [PATCH 2/3] perf tools: Use rb_for_each_entry Arnaldo Carvalho de Melo
@ 2010-01-13 13:01 ` Arnaldo Carvalho de Melo
  2010-01-13 13:16 ` [PATCH 1/3] rbtree: Introduce rb_for_each_entry Peter Zijlstra
  2 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-01-13 13:01 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Peter Zijlstra,
	Paul Mackerras

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

We were always looking at the running machine /proc/modules, even when
processing a perf.data file, which only makes sense when we're doing
'perf record' and 'perf report' on the same machine, and in close
sucession, or if we don't use modules at all, right Peter? ;-)

Now, at 'perf record' time we read /proc/modules, find the long path for
modules, and put them as PERF_MMAP events, just like we did to encode
the reloc reference symbol for vmlinux. Talking about that now it is
encoded in .pgoff, so that we can use .{start,len} to store the address
boundaries for the kernel so that when we reconstruct the kmaps tree we
can do lookups right away, without having to fixup the end of the kernel
maps like we did in the past (and now only in perf record).

One more step in the 'perf archive' direction when we'll finally be able
to collect data in one machine and analyse in another.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-kmem.c   |    5 ++
 tools/perf/builtin-record.c |   11 ++++
 tools/perf/builtin-top.c    |    5 ++
 tools/perf/util/event.c     |  104 ++++++++++++++++++++++++++++++++++-----
 tools/perf/util/event.h     |    2 +
 tools/perf/util/session.c   |    8 ++--
 tools/perf/util/session.h   |    4 ++
 tools/perf/util/symbol.c    |  116 +++++++++++++++++++++++++++++++------------
 tools/perf/util/symbol.h    |    3 +
 tools/perf/util/thread.h    |    4 ++
 10 files changed, 214 insertions(+), 48 deletions(-)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 2d2990d..3e3acc4 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -492,6 +492,11 @@ static int __cmd_kmem(void)
 	if (!perf_session__has_traces(session, "kmem record"))
 		goto out_delete;
 
+	if (perf_session__create_kernel_maps(session) < 0) {
+		pr_err("Problems creating kernel maps\n");
+		return -1;
+	}
+
 	setup_pager();
 	err = perf_session__process_events(session, &event_ops);
 	if (err != 0)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8f88420..c130df2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -465,6 +465,11 @@ static int __cmd_record(int argc, const char **argv)
 		return -1;
 	}
 
+	if (perf_session__create_kernel_maps(session) < 0) {
+		pr_err("Problems creating kernel maps\n");
+		return -1;
+	}
+
 	if (!file_new) {
 		err = perf_header__read(&session->header, output);
 		if (err < 0)
@@ -558,6 +563,12 @@ static int __cmd_record(int argc, const char **argv)
 		return err;
 	}
 
+	err = event__synthesize_modules(process_synthesized_event, session);
+	if (err < 0) {
+		pr_err("Couldn't record kernel reference relocation symbol.\n");
+		return err;
+	}
+
 	if (!system_wide && profile_cpu == -1)
 		event__synthesize_thread(pid, process_synthesized_event,
 					 session);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 8f0c837..4786857 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1161,6 +1161,11 @@ static int __cmd_top(void)
 	if (session == NULL)
 		return -ENOMEM;
 
+	if (perf_session__create_kernel_maps(session) < 0) {
+		pr_err("Problems creating kernel maps\n");
+		return -1;
+	}
+
 	if (target_pid != -1)
 		event__synthesize_thread(target_pid, event__process, session);
 	else
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index bfb3d87..73e8dd9 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -154,6 +154,34 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
 	return 0;
 }
 
+int event__synthesize_modules(event__handler_t process,
+			      struct perf_session *session)
+{
+	struct rb_node *nd;
+	struct map *pos;
+
+	perf_session__for_each_module_map(session, pos, nd) {
+		size_t size = ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
+		event_t ev = {
+			.mmap = {
+				.header = {
+					.type = PERF_RECORD_MMAP,
+					.size = (sizeof(ev.mmap) -
+						 (sizeof(ev.mmap.filename) - size)),
+				},
+				.start = pos->start,
+				.len   = pos->end - pos->start,
+			},
+		};
+
+		memcpy(ev.mmap.filename, pos->dso->long_name,
+		       pos->dso->long_name_len + 1);
+		process(&ev, session);
+	}
+
+	return 0;
+}
+
 int event__synthesize_thread(pid_t pid, event__handler_t process,
 			     struct perf_session *session)
 {
@@ -222,7 +250,9 @@ int event__synthesize_kernel_mmap(event__handler_t process,
 			"[kernel.kallsyms.%s]", symbol_name) + 1;
 	size = ALIGN(size, sizeof(u64));
 	ev.mmap.header.size = (sizeof(ev.mmap) - (sizeof(ev.mmap.filename) - size));
-	ev.mmap.start = args.start;
+	ev.mmap.pgoff = args.start;
+	ev.mmap.start = session->vmlinux_maps[MAP__FUNCTION]->start;
+	ev.mmap.len   = session->vmlinux_maps[MAP__FUNCTION]->end - ev.mmap.start ;
 
 	return process(&ev, session);
 }
@@ -280,7 +310,6 @@ int event__process_mmap(event_t *self, struct perf_session *session)
 {
 	struct thread *thread;
 	struct map *map;
-	static const char kmmap_prefix[] = "[kernel.kallsyms.";
 
 	dump_printf(" %d/%d: [%p(%p) @ %p]: %s\n",
 		    self->mmap.pid, self->mmap.tid,
@@ -289,13 +318,61 @@ int event__process_mmap(event_t *self, struct perf_session *session)
 		    (void *)(long)self->mmap.pgoff,
 		    self->mmap.filename);
 
-	if (self->mmap.pid == 0 &&
-	    memcmp(self->mmap.filename, kmmap_prefix,
-		   sizeof(kmmap_prefix) - 1) == 0) {
-		const char *symbol_name = (self->mmap.filename +
-					   sizeof(kmmap_prefix) - 1);
-		perf_session__set_kallsyms_ref_reloc_sym(session, symbol_name,
-							 self->mmap.start);
+	if (self->mmap.pid == 0) {
+		static const char kmmap_prefix[] = "[kernel.kallsyms.";
+
+		if (self->mmap.filename[0] == '/') {
+			char short_module_name[1024];
+			char *name = strrchr(self->mmap.filename, '/'), *dot;
+
+			if (name == NULL)
+				goto out_problem;
+
+			++name; /* skip / */
+			dot = strrchr(name, '.');
+			if (dot == NULL)
+				goto out_problem;
+
+			snprintf(short_module_name, sizeof(short_module_name),
+				 "[%.*s]", (int)(dot - name), name);
+			strxfrchar(short_module_name, '-', '_');
+
+			map = perf_session__new_module_map(session,
+							   self->mmap.start,
+							   short_module_name);
+			if (map == NULL)
+				goto out_problem;
+
+			name = strdup(self->mmap.filename);
+			if (name == NULL)
+				goto out_problem;
+
+			dso__set_long_name(map->dso, name);
+			map->end = map->start + self->mmap.len;
+		} else if (memcmp(self->mmap.filename, kmmap_prefix,
+				sizeof(kmmap_prefix) - 1) == 0) {
+			const char *symbol_name = (self->mmap.filename +
+						   sizeof(kmmap_prefix) - 1);
+			/*
+			 * Should be there already, from the build-id table in
+			 * the header.
+			 */
+			struct dso *kernel = __dsos__findnew(&dsos__kernel,
+							     "[kernel.kallsyms]");
+			if (kernel == NULL)
+				goto out_problem;
+
+			if (__map_groups__create_kernel_maps(&session->kmaps,
+							     session->vmlinux_maps,
+							     kernel) < 0)
+				goto out_problem;
+
+			session->vmlinux_maps[MAP__FUNCTION]->start = self->mmap.start;
+			session->vmlinux_maps[MAP__FUNCTION]->end   = self->mmap.start + self->mmap.len;
+
+			perf_session__set_kallsyms_ref_reloc_sym(session, symbol_name,
+								 self->mmap.pgoff);
+		}
 		return 0;
 	}
 
@@ -304,10 +381,13 @@ int event__process_mmap(event_t *self, struct perf_session *session)
 		       session->cwd, session->cwdlen);
 
 	if (thread == NULL || map == NULL)
-		dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
-	else
-		thread__insert_map(thread, map);
+		goto out_problem;
+
+	thread__insert_map(thread, map);
+	return 0;
 
+out_problem:
+	dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
 	return 0;
 }
 
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 80356da..50a7132 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -112,6 +112,8 @@ void event__synthesize_threads(event__handler_t process,
 int event__synthesize_kernel_mmap(event__handler_t process,
 				  struct perf_session *session,
 				  const char *symbol_name);
+int event__synthesize_modules(event__handler_t process,
+			      struct perf_session *session);
 
 int event__process_comm(event_t *self, struct perf_session *session);
 int event__process_lost(event_t *self, struct perf_session *session);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 378ac54..fd1c5a3 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -69,9 +69,6 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
 	self->unknown_events = 0;
 	map_groups__init(&self->kmaps);
 
-	if (perf_session__create_kernel_maps(self) < 0)
-		goto out_delete;
-
 	if (mode == O_RDONLY && perf_session__open(self, force) < 0)
 		goto out_delete;
 
@@ -268,8 +265,11 @@ int perf_header__read_build_ids(int input, u64 offset, u64 size)
 			head = &dsos__kernel;
 
 		dso = __dsos__findnew(head, filename);
-		if (dso != NULL)
+		if (dso != NULL) {
 			dso__set_build_id(dso, &bev.build_id);
+			if (head == &dsos__kernel && filename[0] == '[')
+				dso->kernel = 1;
+		}
 
 		offset += bev.header.size;
 	}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index d4a9d20..4446d60 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -69,4 +69,8 @@ int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
 void perf_session__reloc_vmlinux_maps(struct perf_session *self,
 				      u64 unrelocated_addr);
 
+#define perf_session__for_each_module_map(self, pos, nd)		      \
+	rb_for_each_entry(pos, nd, &self->kmaps.maps[MAP__FUNCTION], rb_node) \
+		if (pos->dso->kernel) continue; else
+
 #endif /* __PERF_SESSION_H */
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 85b96ea..9df9833 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -161,7 +161,7 @@ static size_t symbol__fprintf(struct symbol *self, FILE *fp)
 		       self->start, self->end, self->name);
 }
 
-static void dso__set_long_name(struct dso *self, char *name)
+void dso__set_long_name(struct dso *self, char *name)
 {
 	if (name == NULL)
 		return;
@@ -176,7 +176,7 @@ static void dso__set_basename(struct dso *self)
 
 struct dso *dso__new(const char *name)
 {
-	struct dso *self = malloc(sizeof(*self) + strlen(name) + 1);
+	struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1);
 
 	if (self != NULL) {
 		int i;
@@ -498,13 +498,17 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
 
 			*module++ = '\0';
 
-			if (strcmp(self->name, module)) {
+			if (strcmp(curr_map->dso->short_name, module)) {
 				curr_map = map_groups__find_by_name(&session->kmaps, map->type, module);
 				if (curr_map == NULL) {
 					pr_debug("/proc/{kallsyms,modules} "
-					         "inconsistency!\n");
+					         "inconsistency while looking "
+						 "for \"%s\" module!\n", module);
 					return -1;
 				}
+
+				if (curr_map->dso->loaded)
+					goto discard_symbol;
 			}
 			/*
 			 * So that we look just like we get from .ko files,
@@ -1340,12 +1344,32 @@ struct map *map_groups__find_by_name(struct map_groups *self,
 	struct map *map;
 
 	rb_for_each_entry(map, nd, &self->maps[type], rb_node)
-		if (map->dso && strcmp(map->dso->name, name) == 0)
+		if (map->dso && strcmp(map->dso->short_name, name) == 0)
 			return map;
 
 	return NULL;
 }
 
+static int dso__kernel_module_get_build_id(struct dso *self)
+{
+	char filename[PATH_MAX];
+	/*
+	 * kernel module short names are of the form "[module]" and
+	 * we need just "module" here.
+	 */
+	const char *name = self->short_name + 1;
+
+	snprintf(filename, sizeof(filename),
+		 "/sys/module/%.*s/notes/.note.gnu.build-id",
+		 (int)strlen(name - 1), name);
+
+	if (sysfs__read_build_id(filename, self->build_id,
+				 sizeof(self->build_id)) == 0)
+		self->has_build_id = true;
+
+	return 0;
+}
+
 static int perf_session__set_modules_path_dir(struct perf_session *self, char *dirname)
 {
 	struct dirent *dent;
@@ -1391,6 +1415,7 @@ static int perf_session__set_modules_path_dir(struct perf_session *self, char *d
 			if (long_name == NULL)
 				goto failure;
 			dso__set_long_name(map->dso, long_name);
+			dso__kernel_module_get_build_id(map->dso);
 		}
 	}
 
@@ -1433,6 +1458,24 @@ static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
 	return self;
 }
 
+struct map *perf_session__new_module_map(struct perf_session *self, u64 start,
+					 const char *filename)
+{
+	struct map *map;
+	struct dso *dso = __dsos__findnew(&dsos__kernel, filename);
+
+	if (dso == NULL)
+		return NULL;
+
+	map = map__new2(start, dso, MAP__FUNCTION);
+	if (map == NULL)
+		return NULL;
+
+	dso->origin = DSO__ORIG_KMODULE;
+	map_groups__insert(&self->kmaps, map);
+	return map;
+}
+
 static int perf_session__create_module_maps(struct perf_session *self)
 {
 	char *line = NULL;
@@ -1446,7 +1489,6 @@ static int perf_session__create_module_maps(struct perf_session *self)
 	while (!feof(file)) {
 		char name[PATH_MAX];
 		u64 start;
-		struct dso *dso;
 		char *sep;
 		int line_len;
 
@@ -1472,26 +1514,10 @@ static int perf_session__create_module_maps(struct perf_session *self)
 		*sep = '\0';
 
 		snprintf(name, sizeof(name), "[%s]", line);
-		dso = dso__new(name);
-
-		if (dso == NULL)
-			goto out_delete_line;
-
-		map = map__new2(start, dso, MAP__FUNCTION);
-		if (map == NULL) {
-			dso__delete(dso);
+		map = perf_session__new_module_map(self, start, name);
+		if (map == NULL)
 			goto out_delete_line;
-		}
-
-		snprintf(name, sizeof(name),
-			 "/sys/module/%s/notes/.note.gnu.build-id", line);
-		if (sysfs__read_build_id(name, dso->build_id,
-					 sizeof(dso->build_id)) == 0)
-			dso->has_build_id = true;
-
-		dso->origin = DSO__ORIG_KMODULE;
-		map_groups__insert(&self->kmaps, map);
-		dsos__add(&dsos__kernel, dso);
+		dso__kernel_module_get_build_id(map->dso);
 	}
 
 	free(line);
@@ -1569,10 +1595,28 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,
 		}
 	}
 
+	/*
+	 * Say the kernel DSO was created when processing the build-id header table,
+	 * we have a build-id, so check if it is the same as the running kernel,
+	 * using it if it is.
+	 */
+	if (self->has_build_id) {
+		u8 kallsyms_build_id[BUILD_ID_SIZE];
+
+		if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
+					 sizeof(kallsyms_build_id)) == 0)
+
+		is_kallsyms = dso__build_id_equal(self, kallsyms_build_id);
+		if (is_kallsyms)
+			goto do_kallsyms;
+		goto do_vmlinux;
+	}
+
 	is_kallsyms = self->long_name[0] == '[';
 	if (is_kallsyms)
 		goto do_kallsyms;
 
+do_vmlinux:
 	err = dso__load_vmlinux(self, map, session, self->long_name, filter);
 	if (err <= 0) {
 		pr_info("The file %s cannot be used, "
@@ -1690,16 +1734,12 @@ out_delete_kernel_dso:
 	return NULL;
 }
 
-static int map_groups__create_kernel_maps(struct map_groups *self,
-					  struct map *vmlinux_maps[MAP__NR_TYPES],
-					  const char *vmlinux)
+int __map_groups__create_kernel_maps(struct map_groups *self,
+				     struct map *vmlinux_maps[MAP__NR_TYPES],
+				     struct dso *kernel)
 {
-	struct dso *kernel = dsos__create_kernel(vmlinux);
 	enum map_type type;
 
-	if (kernel == NULL)
-		return -1;
-
 	for (type = 0; type < MAP__NR_TYPES; ++type) {
 		vmlinux_maps[type] = map__new2(0, kernel, type);
 		if (vmlinux_maps[type] == NULL)
@@ -1713,6 +1753,18 @@ static int map_groups__create_kernel_maps(struct map_groups *self,
 	return 0;
 }
 
+static int map_groups__create_kernel_maps(struct map_groups *self,
+					  struct map *vmlinux_maps[MAP__NR_TYPES],
+					  const char *vmlinux)
+{
+	struct dso *kernel = dsos__create_kernel(vmlinux);
+
+	if (kernel == NULL)
+		return -1;
+
+	return __map_groups__create_kernel_maps(self, vmlinux_maps, kernel);
+}
+
 static void vmlinux_path__exit(void)
 {
 	while (--vmlinux_path__nr_entries >= 0) {
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index ee0b459..594156e 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -134,6 +134,7 @@ size_t dsos__fprintf_buildid(FILE *fp);
 size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
 size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
 char dso__symtab_origin(const struct dso *self);
+void dso__set_long_name(struct dso *self, char *name);
 void dso__set_build_id(struct dso *self, void *build_id);
 struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
 struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
@@ -151,5 +152,7 @@ bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
 int perf_session__create_kernel_maps(struct perf_session *self);
 
+struct map *perf_session__new_module_map(struct perf_session *self, u64 start,
+					 const char *filename);
 extern struct dso *vdso;
 #endif /* __PERF_SYMBOL */
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index c206f72..c06c135 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -67,4 +67,8 @@ map_groups__find_function(struct map_groups *self, struct perf_session *session,
 
 struct map *map_groups__find_by_name(struct map_groups *self,
 				     enum map_type type, const char *name);
+
+int __map_groups__create_kernel_maps(struct map_groups *self,
+				     struct map *vmlinux_maps[MAP__NR_TYPES],
+				     struct dso *kernel);
 #endif	/* __PERF_THREAD_H */
-- 
1.6.2.5


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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 13:01 [PATCH 1/3] rbtree: Introduce rb_for_each_entry Arnaldo Carvalho de Melo
  2010-01-13 13:01 ` [PATCH 2/3] perf tools: Use rb_for_each_entry Arnaldo Carvalho de Melo
  2010-01-13 13:01 ` [PATCH 3/3] perf tools: Encode kernel module mappings in perf.data Arnaldo Carvalho de Melo
@ 2010-01-13 13:16 ` Peter Zijlstra
  2010-01-13 13:34   ` Frederic Weisbecker
  2 siblings, 1 reply; 13+ messages in thread
From: Peter Zijlstra @ 2010-01-13 13:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, linux-kernel, Arnaldo Carvalho de Melo,
	Frédéric Weisbecker, Mike Galbraith, Paul Mackerras

On Wed, 2010-01-13 at 11:01 -0200, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Similar to list_for_each_entry, helps reducing boilerplate in many
> places and makes rbtrees closer to list.h macros.
> 
> First conversion will be in the tools/perf.

I'm still not sure you really want to do this, it might give people the
impression its a sane thing to do ;-)

> Cc: Frédéric Weisbecker <fweisbec@gmail.com>
> Cc: Mike Galbraith <efault@gmx.de>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Paul Mackerras <paulus@samba.org>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  include/linux/rbtree.h |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
> index 9c29541..044b150 100644
> --- a/include/linux/rbtree.h
> +++ b/include/linux/rbtree.h
> @@ -158,4 +158,16 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
>  	*rb_link = node;
>  }
>  
> +/**
> + * rb_for_each_entry - iterate over rbtree of given type
> + * @pos:	the type * to hold the current entry being traversed
> + * @node:	the rb_node to hold the current entry being traversed
> + * @root:	the root for your tree.
> + * @member:	the name of the rb_node within the struct.
> + */
> +#define rb_for_each_entry(pos, node, root, member)			\
> +	for (node = rb_first(root);					\
> +	     node && (pos = rb_entry(node, typeof(*pos), member));	\
> +	     node = rb_next(node))
> +
>  #endif	/* _LINUX_RBTREE_H */



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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 13:16 ` [PATCH 1/3] rbtree: Introduce rb_for_each_entry Peter Zijlstra
@ 2010-01-13 13:34   ` Frederic Weisbecker
  2010-01-13 13:36     ` Peter Zijlstra
  2010-01-13 13:52     ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 13+ messages in thread
From: Frederic Weisbecker @ 2010-01-13 13:34 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, linux-kernel,
	Arnaldo Carvalho de Melo, Mike Galbraith, Paul Mackerras

On Wed, Jan 13, 2010 at 02:16:09PM +0100, Peter Zijlstra wrote:
> On Wed, 2010-01-13 at 11:01 -0200, Arnaldo Carvalho de Melo wrote:
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > 
> > Similar to list_for_each_entry, helps reducing boilerplate in many
> > places and makes rbtrees closer to list.h macros.
> > 
> > First conversion will be in the tools/perf.
> 
> I'm still not sure you really want to do this, it might give people the
> impression its a sane thing to do ;-)


At least it matches many patterns in perf :)


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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 13:34   ` Frederic Weisbecker
@ 2010-01-13 13:36     ` Peter Zijlstra
  2010-01-13 13:52     ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 13+ messages in thread
From: Peter Zijlstra @ 2010-01-13 13:36 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, linux-kernel,
	Arnaldo Carvalho de Melo, Mike Galbraith, Paul Mackerras

On Wed, 2010-01-13 at 14:34 +0100, Frederic Weisbecker wrote:
> On Wed, Jan 13, 2010 at 02:16:09PM +0100, Peter Zijlstra wrote:
> > On Wed, 2010-01-13 at 11:01 -0200, Arnaldo Carvalho de Melo wrote:
> > > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > 
> > > Similar to list_for_each_entry, helps reducing boilerplate in many
> > > places and makes rbtrees closer to list.h macros.
> > > 
> > > First conversion will be in the tools/perf.
> > 
> > I'm still not sure you really want to do this, it might give people the
> > impression its a sane thing to do ;-)
> 
> 
> At least it matches many patterns in perf :)

Doesn't make it right.


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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 13:34   ` Frederic Weisbecker
  2010-01-13 13:36     ` Peter Zijlstra
@ 2010-01-13 13:52     ` Arnaldo Carvalho de Melo
  2010-01-13 13:58       ` Peter Zijlstra
  1 sibling, 1 reply; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-01-13 13:52 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Peter Zijlstra, Ingo Molnar, linux-kernel, Mike Galbraith,
	Paul Mackerras

Em Wed, Jan 13, 2010 at 02:34:45PM +0100, Frederic Weisbecker escreveu:
> On Wed, Jan 13, 2010 at 02:16:09PM +0100, Peter Zijlstra wrote:
> > On Wed, 2010-01-13 at 11:01 -0200, Arnaldo Carvalho de Melo wrote:
> > > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > 
> > > Similar to list_for_each_entry, helps reducing boilerplate in many
> > > places and makes rbtrees closer to list.h macros.
> > > 
> > > First conversion will be in the tools/perf.
> > 
> > I'm still not sure you really want to do this, it might give people the
> > impression its a sane thing to do ;-)
> 
> At least it matches many patterns in perf :)

What an insane piece of... software! 8-) Whatever, if it makes Peter
happy we can keep it on tools/perf/util/include/linux/rbtree.h, just
after the:

#include "../../../../include/linux/rbtree.h"

;-)

Just like we have list_del_range() in tools/perf/util/include/linux/list.h.

- Arnaldo

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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 13:52     ` Arnaldo Carvalho de Melo
@ 2010-01-13 13:58       ` Peter Zijlstra
  2010-01-13 14:13         ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Zijlstra @ 2010-01-13 13:58 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, Mike Galbraith,
	Paul Mackerras

On Wed, 2010-01-13 at 11:52 -0200, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jan 13, 2010 at 02:34:45PM +0100, Frederic Weisbecker escreveu:
> > On Wed, Jan 13, 2010 at 02:16:09PM +0100, Peter Zijlstra wrote:
> > > On Wed, 2010-01-13 at 11:01 -0200, Arnaldo Carvalho de Melo wrote:
> > > > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > > 
> > > > Similar to list_for_each_entry, helps reducing boilerplate in many
> > > > places and makes rbtrees closer to list.h macros.
> > > > 
> > > > First conversion will be in the tools/perf.
> > > 
> > > I'm still not sure you really want to do this, it might give people the
> > > impression its a sane thing to do ;-)
> > 
> > At least it matches many patterns in perf :)
> 
> What an insane piece of... software! 8-) Whatever, if it makes Peter
> happy we can keep it on tools/perf/util/include/linux/rbtree.h, just
> after the:
> 
> #include "../../../../include/linux/rbtree.h"
> 
> ;-)
> 
> Just like we have list_del_range() in tools/perf/util/include/linux/list.h.

That's not the point, doing a for_each on the rb-trees as we have today
is a O(n log(n)) operation, not something you should want to do often.

Adding a helper promotes the idea that its a sane thing to do, its not.

If you really need it, open coding it isn't hard, but the lack of helper
does make you think and hopefully realize you're doing something funny.




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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 13:58       ` Peter Zijlstra
@ 2010-01-13 14:13         ` Arnaldo Carvalho de Melo
  2010-01-13 14:18           ` Peter Zijlstra
  0 siblings, 1 reply; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-01-13 14:13 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, Mike Galbraith,
	Paul Mackerras

Em Wed, Jan 13, 2010 at 02:58:53PM +0100, Peter Zijlstra escreveu:
> On Wed, 2010-01-13 at 11:52 -0200, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jan 13, 2010 at 02:34:45PM +0100, Frederic Weisbecker escreveu:
> > > At least it matches many patterns in perf :)
> > 
> > What an insane piece of... software! 8-) Whatever, if it makes Peter
> > happy we can keep it on tools/perf/util/include/linux/rbtree.h, just
> > after the:
> > 
> > #include "../../../../include/linux/rbtree.h"
> > 
> > ;-)
> > 
> > Just like we have list_del_range() in tools/perf/util/include/linux/list.h.
> 
> That's not the point, doing a for_each on the rb-trees as we have today
> is a O(n log(n)) operation, not something you should want to do often.
> 
> Adding a helper promotes the idea that its a sane thing to do, its not.
> 
> If you really need it, open coding it isn't hard, but the lack of helper
> does make you think and hopefully realize you're doing something funny.

We need it in several places in the perf tools, to present sorted results, to
dump the maps for debugging purposes, etc.

But I'll go and look at each one of them to see if there is any where it
is used in some stupid way.

- Arnaldo

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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 14:13         ` Arnaldo Carvalho de Melo
@ 2010-01-13 14:18           ` Peter Zijlstra
  2010-01-13 14:22             ` Arnaldo Carvalho de Melo
                               ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Peter Zijlstra @ 2010-01-13 14:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, Mike Galbraith,
	Paul Mackerras

On Wed, 2010-01-13 at 12:13 -0200, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jan 13, 2010 at 02:58:53PM +0100, Peter Zijlstra escreveu:
> > On Wed, 2010-01-13 at 11:52 -0200, Arnaldo Carvalho de Melo wrote:
> > > Em Wed, Jan 13, 2010 at 02:34:45PM +0100, Frederic Weisbecker escreveu:
> > > > At least it matches many patterns in perf :)
> > > 
> > > What an insane piece of... software! 8-) Whatever, if it makes Peter
> > > happy we can keep it on tools/perf/util/include/linux/rbtree.h, just
> > > after the:
> > > 
> > > #include "../../../../include/linux/rbtree.h"
> > > 
> > > ;-)
> > > 
> > > Just like we have list_del_range() in tools/perf/util/include/linux/list.h.
> > 
> > That's not the point, doing a for_each on the rb-trees as we have today
> > is a O(n log(n)) operation, not something you should want to do often.
> > 
> > Adding a helper promotes the idea that its a sane thing to do, its not.
> > 
> > If you really need it, open coding it isn't hard, but the lack of helper
> > does make you think and hopefully realize you're doing something funny.
> 
> We need it in several places in the perf tools, to present sorted results, to
> dump the maps for debugging purposes, etc.
> 
> But I'll go and look at each one of them to see if there is any where it
> is used in some stupid way.

Sure, but again, that's missing the point, adding that helper isn't a
good thing. We have no 64bit division operators in Linux either, for the
very same reason.


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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 14:18           ` Peter Zijlstra
@ 2010-01-13 14:22             ` Arnaldo Carvalho de Melo
  2010-01-13 14:28             ` Frederic Weisbecker
  2010-01-13 15:26             ` Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-01-13 14:22 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, Mike Galbraith,
	Paul Mackerras

Em Wed, Jan 13, 2010 at 03:18:16PM +0100, Peter Zijlstra escreveu:
> On Wed, 2010-01-13 at 12:13 -0200, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jan 13, 2010 at 02:58:53PM +0100, Peter Zijlstra escreveu:
> > > On Wed, 2010-01-13 at 11:52 -0200, Arnaldo Carvalho de Melo wrote:
> > > > Em Wed, Jan 13, 2010 at 02:34:45PM +0100, Frederic Weisbecker escreveu:
> > > > > At least it matches many patterns in perf :)
> > > > 
> > > > What an insane piece of... software! 8-) Whatever, if it makes Peter
> > > > happy we can keep it on tools/perf/util/include/linux/rbtree.h, just
> > > > after the:
> > > > 
> > > > #include "../../../../include/linux/rbtree.h"
> > > > 
> > > > ;-)
> > > > 
> > > > Just like we have list_del_range() in tools/perf/util/include/linux/list.h.
> > > 
> > > That's not the point, doing a for_each on the rb-trees as we have today
> > > is a O(n log(n)) operation, not something you should want to do often.
> > > 
> > > Adding a helper promotes the idea that its a sane thing to do, its not.
> > > 
> > > If you really need it, open coding it isn't hard, but the lack of helper
> > > does make you think and hopefully realize you're doing something funny.
> > 
> > We need it in several places in the perf tools, to present sorted results, to
> > dump the maps for debugging purposes, etc.
> > 
> > But I'll go and look at each one of them to see if there is any where it
> > is used in some stupid way.
> 
> Sure, but again, that's missing the point, adding that helper isn't a
> good thing. We have no 64bit division operators in Linux either, for the
> very same reason.

Ok, lets move forward, I'll remove the helper and resubmit.

- Arnaldo

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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 14:18           ` Peter Zijlstra
  2010-01-13 14:22             ` Arnaldo Carvalho de Melo
@ 2010-01-13 14:28             ` Frederic Weisbecker
  2010-01-13 15:26             ` Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 13+ messages in thread
From: Frederic Weisbecker @ 2010-01-13 14:28 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, linux-kernel,
	Mike Galbraith, Paul Mackerras

On Wed, Jan 13, 2010 at 03:18:16PM +0100, Peter Zijlstra wrote:
> On Wed, 2010-01-13 at 12:13 -0200, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jan 13, 2010 at 02:58:53PM +0100, Peter Zijlstra escreveu:
> > > On Wed, 2010-01-13 at 11:52 -0200, Arnaldo Carvalho de Melo wrote:
> > > > Em Wed, Jan 13, 2010 at 02:34:45PM +0100, Frederic Weisbecker escreveu:
> > > > > At least it matches many patterns in perf :)
> > > > 
> > > > What an insane piece of... software! 8-) Whatever, if it makes Peter
> > > > happy we can keep it on tools/perf/util/include/linux/rbtree.h, just
> > > > after the:
> > > > 
> > > > #include "../../../../include/linux/rbtree.h"
> > > > 
> > > > ;-)
> > > > 
> > > > Just like we have list_del_range() in tools/perf/util/include/linux/list.h.
> > > 
> > > That's not the point, doing a for_each on the rb-trees as we have today
> > > is a O(n log(n)) operation, not something you should want to do often.
> > > 
> > > Adding a helper promotes the idea that its a sane thing to do, its not.
> > > 
> > > If you really need it, open coding it isn't hard, but the lack of helper
> > > does make you think and hopefully realize you're doing something funny.
> > 
> > We need it in several places in the perf tools, to present sorted results, to
> > dump the maps for debugging purposes, etc.
> > 
> > But I'll go and look at each one of them to see if there is any where it
> > is used in some stupid way.
> 
> Sure, but again, that's missing the point, adding that helper isn't a
> good thing. We have no 64bit division operators in Linux either, for the
> very same reason.
> 


I don't understand why this is unsane. Sure it is O(n log(n)), but
that's what is suitable for our use in perf. Shouldn't we simplify
it through a helper just because it's not something sane in most
other cases?

But yeah, such helper inside the kernel wouldn't be sane, as it
wouldn't fit any sane need I guess.


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

* Re: [PATCH 1/3] rbtree: Introduce rb_for_each_entry
  2010-01-13 14:18           ` Peter Zijlstra
  2010-01-13 14:22             ` Arnaldo Carvalho de Melo
  2010-01-13 14:28             ` Frederic Weisbecker
@ 2010-01-13 15:26             ` Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-01-13 15:26 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Frederic Weisbecker, Ingo Molnar, linux-kernel, Mike Galbraith,
	Paul Mackerras

Em Wed, Jan 13, 2010 at 03:18:16PM +0100, Peter Zijlstra escreveu:
> Sure, but again, that's missing the point, adding that helper isn't a
> good thing. We have no 64bit division operators in Linux either, for the
> very same reason.

Ok, resent without it.

- Arnaldo

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

end of thread, other threads:[~2010-01-13 15:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-13 13:01 [PATCH 1/3] rbtree: Introduce rb_for_each_entry Arnaldo Carvalho de Melo
2010-01-13 13:01 ` [PATCH 2/3] perf tools: Use rb_for_each_entry Arnaldo Carvalho de Melo
2010-01-13 13:01 ` [PATCH 3/3] perf tools: Encode kernel module mappings in perf.data Arnaldo Carvalho de Melo
2010-01-13 13:16 ` [PATCH 1/3] rbtree: Introduce rb_for_each_entry Peter Zijlstra
2010-01-13 13:34   ` Frederic Weisbecker
2010-01-13 13:36     ` Peter Zijlstra
2010-01-13 13:52     ` Arnaldo Carvalho de Melo
2010-01-13 13:58       ` Peter Zijlstra
2010-01-13 14:13         ` Arnaldo Carvalho de Melo
2010-01-13 14:18           ` Peter Zijlstra
2010-01-13 14:22             ` Arnaldo Carvalho de Melo
2010-01-13 14:28             ` Frederic Weisbecker
2010-01-13 15:26             ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox