perf annotate: Sort list of recognised instructions

Currently the list of instructions recognised by perf annotate has to be
explicitly written in sorted order. This makes it easy to make mistakes
when adding new instructions. Sort the list of instructions on first
access.

Signed-off-by: Chris Ryder <chris.ryder@arm.com>
Acked-by: Pawel Moll <pawel.moll@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Link: http://lkml.kernel.org/r/4268febaf32f47f322c166fb2fe98cfec7041e11.1463676839.git.chris.ryder@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Chris Ryder 2016-05-19 17:59:46 +01:00 committed by Arnaldo Carvalho de Melo
parent 58c0400176
commit 7e4c149813

View File

@ -354,9 +354,6 @@ static struct ins_ops nop_ops = {
.scnprintf = nop__scnprintf, .scnprintf = nop__scnprintf,
}; };
/*
* Must be sorted by name!
*/
static struct ins instructions[] = { static struct ins instructions[] = {
{ .name = "add", .ops = &mov_ops, }, { .name = "add", .ops = &mov_ops, },
{ .name = "addl", .ops = &mov_ops, }, { .name = "addl", .ops = &mov_ops, },
@ -449,18 +446,39 @@ static struct ins instructions[] = {
{ .name = "xbeginq", .ops = &jump_ops, }, { .name = "xbeginq", .ops = &jump_ops, },
}; };
static int ins__cmp(const void *name, const void *insp) static int ins__key_cmp(const void *name, const void *insp)
{ {
const struct ins *ins = insp; const struct ins *ins = insp;
return strcmp(name, ins->name); return strcmp(name, ins->name);
} }
static struct ins *ins__find(const char *name) static int ins__cmp(const void *a, const void *b)
{
const struct ins *ia = a;
const struct ins *ib = b;
return strcmp(ia->name, ib->name);
}
static void ins__sort(void)
{ {
const int nmemb = ARRAY_SIZE(instructions); const int nmemb = ARRAY_SIZE(instructions);
return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__cmp); qsort(instructions, nmemb, sizeof(struct ins), ins__cmp);
}
static struct ins *ins__find(const char *name)
{
const int nmemb = ARRAY_SIZE(instructions);
static bool sorted;
if (!sorted) {
ins__sort();
sorted = true;
}
return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__key_cmp);
} }
int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym) int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym)