Skip to content

Commit 7e4c149

Browse files
Chris Ryderacmel
authored andcommitted
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 <[email protected]> Acked-by: Pawel Moll <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Link: http://lkml.kernel.org/r/4268febaf32f47f322c166fb2fe98cfec7041e11.1463676839.git.chris.ryder@arm.com Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 58c0400 commit 7e4c149

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

tools/perf/util/annotate.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,6 @@ static struct ins_ops nop_ops = {
354354
.scnprintf = nop__scnprintf,
355355
};
356356

357-
/*
358-
* Must be sorted by name!
359-
*/
360357
static struct ins instructions[] = {
361358
{ .name = "add", .ops = &mov_ops, },
362359
{ .name = "addl", .ops = &mov_ops, },
@@ -449,18 +446,39 @@ static struct ins instructions[] = {
449446
{ .name = "xbeginq", .ops = &jump_ops, },
450447
};
451448

452-
static int ins__cmp(const void *name, const void *insp)
449+
static int ins__key_cmp(const void *name, const void *insp)
453450
{
454451
const struct ins *ins = insp;
455452

456453
return strcmp(name, ins->name);
457454
}
458455

456+
static int ins__cmp(const void *a, const void *b)
457+
{
458+
const struct ins *ia = a;
459+
const struct ins *ib = b;
460+
461+
return strcmp(ia->name, ib->name);
462+
}
463+
464+
static void ins__sort(void)
465+
{
466+
const int nmemb = ARRAY_SIZE(instructions);
467+
468+
qsort(instructions, nmemb, sizeof(struct ins), ins__cmp);
469+
}
470+
459471
static struct ins *ins__find(const char *name)
460472
{
461473
const int nmemb = ARRAY_SIZE(instructions);
474+
static bool sorted;
475+
476+
if (!sorted) {
477+
ins__sort();
478+
sorted = true;
479+
}
462480

463-
return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__cmp);
481+
return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__key_cmp);
464482
}
465483

466484
int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym)

0 commit comments

Comments
 (0)