Skip to contentSkip to conversation

perf annotate: Remove duplicate 'name' field from disasm_line

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Nov 25, 2016 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  75b49202d87c142a646e37edb466462ea6fbe0fb
Gitweb:     http://git.kernel.org/tip/75b49202d87c142a646e37edb466462ea6fbe0fb
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 24 Nov 2016 11:16:06 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 25 Nov 2016 10:24:16 -0300

perf annotate: Remove duplicate 'name' field from disasm_line

The disasm_line::name field is always equal to ins::name, being used just to locate the instruction's ins_ops from the per-arch instructions table.

Eliminate this duplication, nuking that field and instead make ins__find() return an ins_ops, store it in disasm_line::ins.ops, and keep just in disasm_line::ins.name what was in disasm_line::name, this way we end up not keeping a reference to entries in the per-arch instructions table.

This in turn will help supporting multiple ways to manage the per-arch instructions table, allowing resorting that array, for instance, when the entries will move after references to its addresses were made. The same problem is avoided when one grows the array with realloc.

So architectures simply keeping a constant array will work as well as architectures building the table using regular expressions or other logic that involves resorting the table.

Cc Adrian Hunter <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Chris Riyder <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kim Phillips <[email protected]>
Cc Markus Trippelsdorf <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Naveen N. Rao <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Russell King <[email protected]>
Cc Taeung Song <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/perf/ui/browsers/annotate.c | 18 +++++-----
 tools/perf/util/annotate.c        | 73 ++++++++++++++++++---------------------
 tools/perf/util/annotate.h        | 17 +++++----
 3 files changed, 51 insertions(+), 57 deletions(-)
tools/perf/ui/browsers/annotate.c +9 -9
index e6e9f7d..cee0eee 100644
@@ -213,17 +213,17 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 		ui_browser__write_nstring(browser, bf, printed);
 		if (change_color)
 			ui_browser__set_color(browser, color);
-		if (dl->ins && dl->ins->ops->scnprintf) {
-			if (ins__is_jump(dl->ins)) {
+		if (dl->ins.ops && dl->ins.ops->scnprintf) {
+			if (ins__is_jump(&dl->ins)) {
 				bool fwd = dl->ops.target.offset > (u64)dl->offset;
 
 				ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR :
 								    SLSMG_UARROW_CHAR);
 				SLsmg_write_char(' ');
-			} else if (ins__is_call(dl->ins)) {
+			} else if (ins__is_call(&dl->ins)) {
 				ui_browser__write_graph(browser, SLSMG_RARROW_CHAR);
 				SLsmg_write_char(' ');
-			} else if (ins__is_ret(dl->ins)) {
+			} else if (ins__is_ret(&dl->ins)) {
 				ui_browser__write_graph(browser, SLSMG_LARROW_CHAR);
 				SLsmg_write_char(' ');
 			} else {
@@ -243,7 +243,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 
 static bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym)
 {
-	if (!dl || !dl->ins || !ins__is_jump(dl->ins)
+	if (!dl || !dl->ins.ops || !ins__is_jump(&dl->ins)
 	    || !disasm_line__has_offset(dl)
 	    || dl->ops.target.offset >= symbol__size(sym))
 		return false;
@@ -492,7 +492,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
 	};
 	char title[SYM_TITLE_MAX_SIZE];
 
-	if (!ins__is_call(dl->ins))
+	if (!ins__is_call(&dl->ins))
 		return false;
 
 	if (map_groups__find_ams(&target) ||
@@ -545,7 +545,7 @@ static bool annotate_browser__jump(struct annotate_browser *browser)
 	struct disasm_line *dl = browser->selection;
 	s64 idx;
 
-	if (!ins__is_jump(dl->ins))
+	if (!ins__is_jump(&dl->ins))
 		return false;
 
 	dl = annotate_browser__find_offset(browser, dl->ops.target.offset, &idx);
@@ -841,9 +841,9 @@ show_help:
 				ui_helpline__puts("Huh? No selection. Report to [email protected]");
 			else if (browser->selection->offset == -1)
 				ui_helpline__puts("Actions are only available for assembly lines.");
-			else if (!browser->selection->ins)
+			else if (!browser->selection->ins.ops)
 				goto show_sup_ins;
-			else if (ins__is_ret(browser->selection->ins))
+			else if (ins__is_ret(&browser->selection->ins))
 				goto out;
 			else if (!(annotate_browser__jump(browser) ||
 				     annotate_browser__callq(browser, evsel, hbt))) {
tools/perf/util/annotate.c +34 -39

177 lines not on this page · raw message

tools/perf/util/annotate.h +8 -9
index 8e490b5..87e4cad 100644
@@ -11,7 +11,12 @@
 #include <linux/rbtree.h>
 #include <pthread.h>
 
-struct ins;
+struct ins_ops;
+
+struct ins {
+	const char     *name;
+	struct ins_ops *ops;
+};
 
 struct ins_operands {
 	char	*raw;
@@ -28,7 +33,7 @@ struct ins_operands {
 			u64	addr;
 		} source;
 		struct {
-			struct ins *ins;
+			struct ins	    ins;
 			struct ins_operands *ops;
 		} locked;
 	};
@@ -43,11 +48,6 @@ struct ins_ops {
 			 struct ins_operands *ops);
 };
 
-struct ins {
-	const char     *name;
-	struct ins_ops *ops;
-};
-
 bool ins__is_jump(const struct ins *ins);
 bool ins__is_call(const struct ins *ins);
 bool ins__is_ret(const struct ins *ins);
@@ -59,8 +59,7 @@ struct disasm_line {
 	struct list_head    node;
 	s64		    offset;
 	char		    *line;
-	char		    *name;
-	struct ins	    *ins;
+	struct ins	    ins;
 	int		    line_nr;
 	float		    ipc;
 	u64		    cycles;