diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-11-24 09:37:08 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-11-25 08:38:44 -0500 |
commit | 2a1ff812c40be982e4dd7a44159462fb25bebdf3 (patch) | |
tree | c06bc8ea559be6345c1fec3c10ba5f8a2a0dc205 /tools/perf/util/annotate.c | |
parent | 75b49202d87c142a646e37edb466462ea6fbe0fb (diff) |
perf annotate: Introduce alternative method of keeping instructions table
Some arches may want to dynamically populate the table using regular
expressions on the instruction names to associate them with a set of
parsing/formatting/etc functions (struct ins_ops), so provide a fallback
for when the ins__find() method fails.
That fall back will be able to resize the arch->instructions, setting
arch->nr_instructions appropriately, helper functions to associate an
ins_ops to an instruction name, growing the arch->instructions if needed
and resorting it are provided, all the arch specific callback needs to
do is to decide if the missing instruction should be added to
arch->instructions with a ins_ops association.
Reviewed-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Chris Riyder <chris.ryder@arm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Markus Trippelsdorf <markus@trippelsdorf.de>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Pawel Moll <pawel.moll@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Taeung Song <treeze.taeung@gmail.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-auu13yradxf7g5dgtpnzt97a@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate.c')
-rw-r--r-- | tools/perf/util/annotate.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index b48a39be071b..026915a7dac8 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -29,12 +29,15 @@ const char *objdump_path; | |||
29 | static regex_t file_lineno; | 29 | static regex_t file_lineno; |
30 | 30 | ||
31 | static struct ins_ops *ins__find(struct arch *arch, const char *name); | 31 | static struct ins_ops *ins__find(struct arch *arch, const char *name); |
32 | static void ins__sort(struct arch *arch); | ||
32 | static int disasm_line__parse(char *line, const char **namep, char **rawp); | 33 | static int disasm_line__parse(char *line, const char **namep, char **rawp); |
33 | 34 | ||
34 | struct arch { | 35 | struct arch { |
35 | const char *name; | 36 | const char *name; |
36 | struct ins *instructions; | 37 | struct ins *instructions; |
37 | size_t nr_instructions; | 38 | size_t nr_instructions; |
39 | size_t nr_instructions_allocated; | ||
40 | struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const char *name); | ||
38 | bool sorted_instructions; | 41 | bool sorted_instructions; |
39 | struct { | 42 | struct { |
40 | char comment_char; | 43 | char comment_char; |
@@ -50,6 +53,54 @@ static struct ins_ops nop_ops; | |||
50 | static struct ins_ops lock_ops; | 53 | static struct ins_ops lock_ops; |
51 | static struct ins_ops ret_ops; | 54 | static struct ins_ops ret_ops; |
52 | 55 | ||
56 | static int arch__grow_instructions(struct arch *arch) | ||
57 | { | ||
58 | struct ins *new_instructions; | ||
59 | size_t new_nr_allocated; | ||
60 | |||
61 | if (arch->nr_instructions_allocated == 0 && arch->instructions) | ||
62 | goto grow_from_non_allocated_table; | ||
63 | |||
64 | new_nr_allocated = arch->nr_instructions_allocated + 128; | ||
65 | new_instructions = realloc(arch->instructions, new_nr_allocated * sizeof(struct ins)); | ||
66 | if (new_instructions == NULL) | ||
67 | return -1; | ||
68 | |||
69 | out_update_instructions: | ||
70 | arch->instructions = new_instructions; | ||
71 | arch->nr_instructions_allocated = new_nr_allocated; | ||
72 | return 0; | ||
73 | |||
74 | grow_from_non_allocated_table: | ||
75 | new_nr_allocated = arch->nr_instructions + 128; | ||
76 | new_instructions = calloc(new_nr_allocated, sizeof(struct ins)); | ||
77 | if (new_instructions == NULL) | ||
78 | return -1; | ||
79 | |||
80 | memcpy(new_instructions, arch->instructions, arch->nr_instructions); | ||
81 | goto out_update_instructions; | ||
82 | } | ||
83 | |||
84 | static __maybe_unused int arch__associate_ins_ops(struct arch* arch, const char *name, struct ins_ops *ops) | ||
85 | { | ||
86 | struct ins *ins; | ||
87 | |||
88 | if (arch->nr_instructions == arch->nr_instructions_allocated && | ||
89 | arch__grow_instructions(arch)) | ||
90 | return -1; | ||
91 | |||
92 | ins = &arch->instructions[arch->nr_instructions]; | ||
93 | ins->name = strdup(name); | ||
94 | if (!ins->name) | ||
95 | return -1; | ||
96 | |||
97 | ins->ops = ops; | ||
98 | arch->nr_instructions++; | ||
99 | |||
100 | ins__sort(arch); | ||
101 | return 0; | ||
102 | } | ||
103 | |||
53 | #include "arch/arm/annotate/instructions.c" | 104 | #include "arch/arm/annotate/instructions.c" |
54 | #include "arch/x86/annotate/instructions.c" | 105 | #include "arch/x86/annotate/instructions.c" |
55 | 106 | ||
@@ -419,7 +470,7 @@ static void ins__sort(struct arch *arch) | |||
419 | qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); | 470 | qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); |
420 | } | 471 | } |
421 | 472 | ||
422 | static struct ins_ops *ins__find(struct arch *arch, const char *name) | 473 | static struct ins_ops *__ins__find(struct arch *arch, const char *name) |
423 | { | 474 | { |
424 | struct ins *ins; | 475 | struct ins *ins; |
425 | const int nmemb = arch->nr_instructions; | 476 | const int nmemb = arch->nr_instructions; |
@@ -433,6 +484,16 @@ static struct ins_ops *ins__find(struct arch *arch, const char *name) | |||
433 | return ins ? ins->ops : NULL; | 484 | return ins ? ins->ops : NULL; |
434 | } | 485 | } |
435 | 486 | ||
487 | static struct ins_ops *ins__find(struct arch *arch, const char *name) | ||
488 | { | ||
489 | struct ins_ops *ops = __ins__find(arch, name); | ||
490 | |||
491 | if (!ops && arch->associate_instruction_ops) | ||
492 | ops = arch->associate_instruction_ops(arch, name); | ||
493 | |||
494 | return ops; | ||
495 | } | ||
496 | |||
436 | static int arch__key_cmp(const void *name, const void *archp) | 497 | static int arch__key_cmp(const void *name, const void *archp) |
437 | { | 498 | { |
438 | const struct arch *arch = archp; | 499 | const struct arch *arch = archp; |