From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Chris Riyder <chris.ryder@arm.com>,
David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
Kim Phillips <kim.phillips@arm.com>,
Markus Trippelsdorf <markus@trippelsdorf.de>,
Masami Hiramatsu <mhiramat@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
"Naveen N . Rao" <naveen.n.rao@linux.vnet.ibm.com>,
Pawel Moll <pawel.moll@arm.com>,
Peter Zijlstra <peterz@infradead.org>,
Russell King <rmk+kernel@arm.linux.org.uk>,
Taeung Song <treeze.taeung@gmail.com>,
Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 02/12] perf annotate: Introduce alternative method of keeping instructions table
Date: Fri, 25 Nov 2016 12:12:17 -0300 [thread overview]
Message-ID: <1480086747-2393-3-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1480086747-2393-1-git-send-email-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
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>
---
tools/perf/util/annotate.c | 63 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)
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;
static regex_t file_lineno;
static struct ins_ops *ins__find(struct arch *arch, const char *name);
+static void ins__sort(struct arch *arch);
static int disasm_line__parse(char *line, const char **namep, char **rawp);
struct arch {
const char *name;
struct ins *instructions;
size_t nr_instructions;
+ size_t nr_instructions_allocated;
+ struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const char *name);
bool sorted_instructions;
struct {
char comment_char;
@@ -50,6 +53,54 @@ static struct ins_ops nop_ops;
static struct ins_ops lock_ops;
static struct ins_ops ret_ops;
+static int arch__grow_instructions(struct arch *arch)
+{
+ struct ins *new_instructions;
+ size_t new_nr_allocated;
+
+ if (arch->nr_instructions_allocated == 0 && arch->instructions)
+ goto grow_from_non_allocated_table;
+
+ new_nr_allocated = arch->nr_instructions_allocated + 128;
+ new_instructions = realloc(arch->instructions, new_nr_allocated * sizeof(struct ins));
+ if (new_instructions == NULL)
+ return -1;
+
+out_update_instructions:
+ arch->instructions = new_instructions;
+ arch->nr_instructions_allocated = new_nr_allocated;
+ return 0;
+
+grow_from_non_allocated_table:
+ new_nr_allocated = arch->nr_instructions + 128;
+ new_instructions = calloc(new_nr_allocated, sizeof(struct ins));
+ if (new_instructions == NULL)
+ return -1;
+
+ memcpy(new_instructions, arch->instructions, arch->nr_instructions);
+ goto out_update_instructions;
+}
+
+static __maybe_unused int arch__associate_ins_ops(struct arch* arch, const char *name, struct ins_ops *ops)
+{
+ struct ins *ins;
+
+ if (arch->nr_instructions == arch->nr_instructions_allocated &&
+ arch__grow_instructions(arch))
+ return -1;
+
+ ins = &arch->instructions[arch->nr_instructions];
+ ins->name = strdup(name);
+ if (!ins->name)
+ return -1;
+
+ ins->ops = ops;
+ arch->nr_instructions++;
+
+ ins__sort(arch);
+ return 0;
+}
+
#include "arch/arm/annotate/instructions.c"
#include "arch/x86/annotate/instructions.c"
@@ -419,7 +470,7 @@ static void ins__sort(struct arch *arch)
qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp);
}
-static struct ins_ops *ins__find(struct arch *arch, const char *name)
+static struct ins_ops *__ins__find(struct arch *arch, const char *name)
{
struct ins *ins;
const int nmemb = arch->nr_instructions;
@@ -433,6 +484,16 @@ static struct ins_ops *ins__find(struct arch *arch, const char *name)
return ins ? ins->ops : NULL;
}
+static struct ins_ops *ins__find(struct arch *arch, const char *name)
+{
+ struct ins_ops *ops = __ins__find(arch, name);
+
+ if (!ops && arch->associate_instruction_ops)
+ ops = arch->associate_instruction_ops(arch, name);
+
+ return ops;
+}
+
static int arch__key_cmp(const void *name, const void *archp)
{
const struct arch *arch = archp;
--
2.7.4
next prev parent reply other threads:[~2016-11-25 15:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-25 15:12 [GIT PULL 00/12] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 01/12] perf annotate: Remove duplicate 'name' field from disasm_line Arnaldo Carvalho de Melo
2016-11-25 15:12 ` Arnaldo Carvalho de Melo [this message]
2016-11-25 15:12 ` [PATCH 03/12] perf annotate: Allow arches to have a init routine and a priv area Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 04/12] perf annotate: Improve support for ARM Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 05/12] perf annotate: Initial PowerPC support Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 06/12] perf callchain: Add option to skip ignore symbol when printing callchains Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 07/12] perf sched timehist: Mark schedule function in callchains Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 08/12] perf sched timehist: Enlarge max stack depth by 2 Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 09/12] perf tools: Fix kernel version error in ubuntu Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 10/12] perf record: Fix segfault when running with suid and kptr_restrict is 1 Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 11/12] perf tools: Add missing struct definition in probe_event.h Arnaldo Carvalho de Melo
2016-11-25 15:12 ` [PATCH 12/12] tools lib bpf: Fix maps resolution Arnaldo Carvalho de Melo
2016-11-25 17:14 ` [GIT PULL 00/12] perf/core improvements and fixes Ingo Molnar
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=1480086747-2393-3-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=chris.ryder@arm.com \
--cc=dsahern@gmail.com \
--cc=jolsa@kernel.org \
--cc=kim.phillips@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markus@trippelsdorf.de \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=pawel.moll@arm.com \
--cc=peterz@infradead.org \
--cc=rmk+kernel@arm.linux.org.uk \
--cc=treeze.taeung@gmail.com \
--cc=wangnan0@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).