All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] perf tools: Use postorder rbtree iteration when removing symbols
@ 2015-09-19 13:03 Alex Snast
  2015-09-19 13:03 ` [PATCH 2/2] perf tools: Use rb_entry_safe on first / next symbol lookup Alex Snast
  2015-09-20  8:05 ` [PATCH 1/2] perf tools: Use postorder rbtree iteration when removing symbols Ingo Molnar
  0 siblings, 2 replies; 4+ messages in thread
From: Alex Snast @ 2015-09-19 13:03 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ingo Molnar, Peter Zijlstra, linux-kernel, Alex Snast

Avoid using rb_erase when removing symbols as it requires rbtree
rebalancing, instead preform a post order iteration when deleting tree
symbols.

Signed-off-by: Alex Snast <asnast@gmail.com>
---
 tools/include/linux/rbtree.h | 14 ++++++++++++++
 tools/perf/util/symbol.c     | 11 ++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/tools/include/linux/rbtree.h b/tools/include/linux/rbtree.h
index 1125822..14c646d 100644
--- a/tools/include/linux/rbtree.h
+++ b/tools/include/linux/rbtree.h
@@ -90,6 +90,20 @@ static inline void rb_link_node(struct rb_node *node, struct rb_node *parent,
 	   ____ptr ? rb_entry(____ptr, type, member) : NULL; \
 	})
 
+/**
+ * rbtree_postorder_for_each_entry_safe - iterate over rb_root in post order of
+ * given type safe against removal of rb_node entry
+ *
+ * @pos:	the 'type *' to use as a loop cursor.
+ * @n:		another 'type *' to use as temporary storage
+ * @root:	'rb_root *' of the rbtree.
+ * @field:	the name of the rb_node field within 'type'.
+ */
+#define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \
+	for (pos = rb_entry_safe(rb_first_postorder(root), typeof(*pos), field); \
+	     pos && ({ n = rb_entry_safe(rb_next_postorder(&pos->field), \
+			typeof(*pos), field); 1; }); \
+	     pos = n)
 
 /*
  * Handy for checking that we are not deleting an entry that is
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 1f97ffb..8b3608c 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -290,15 +290,12 @@ size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
 
 void symbols__delete(struct rb_root *symbols)
 {
-	struct symbol *pos;
-	struct rb_node *next = rb_first(symbols);
+	struct symbol *pos, *next;
 
-	while (next) {
-		pos = rb_entry(next, struct symbol, rb_node);
-		next = rb_next(&pos->rb_node);
-		rb_erase(&pos->rb_node, symbols);
+	rbtree_postorder_for_each_entry_safe(pos, next, symbols, rb_node)
 		symbol__delete(pos);
-	}
+
+	*symbols = RB_ROOT;
 }
 
 void symbols__insert(struct rb_root *symbols, struct symbol *sym)
-- 
2.1.4


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

end of thread, other threads:[~2015-09-21  7:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-19 13:03 [PATCH 1/2] perf tools: Use postorder rbtree iteration when removing symbols Alex Snast
2015-09-19 13:03 ` [PATCH 2/2] perf tools: Use rb_entry_safe on first / next symbol lookup Alex Snast
2015-09-20  8:05 ` [PATCH 1/2] perf tools: Use postorder rbtree iteration when removing symbols Ingo Molnar
     [not found]   ` <CAMqsXBcZAS6hCh8LdHjFGiji8dwHLQus1xf5OnK7CZEjrbx33w@mail.gmail.com>
2015-09-21  7:17     ` Ingo Molnar

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