Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1403989

[PATCH 09/11] perf annotate: Sort list of recognised instructions

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 09/11] perf annotate: Sort list of recognised instructions
Date 2016-05-20 00:30 +0200
Message-ID <rAEC6-5K2-23@gated-at.bofh.it> (permalink)
References <rAEC5-5K2-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Chris Ryder <chris.ryder@arm.com>

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>
---
 tools/perf/util/annotate.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 3d9f2ca2ed2d..7e5a1e8874ce 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -354,9 +354,6 @@ static struct ins_ops nop_ops = {
 	.scnprintf = nop__scnprintf,
 };
 
-/*
- * Must be sorted by name!
- */
 static struct ins instructions[] = {
 	{ .name = "add",   .ops  = &mov_ops, },
 	{ .name = "addl",  .ops  = &mov_ops, },
@@ -449,18 +446,39 @@ static struct ins instructions[] = {
 	{ .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;
 
 	return strcmp(name, ins->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);
+
+	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__cmp);
+	return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__key_cmp);
 }
 
 int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym)
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 04/11] perf top: Use machine->kptr_restrict_warned Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 02/11] perf machine: Do not bail out if not managing to read ref reloc symbol Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 10/11] perf trace: Only auto set call-graph to "dwarf" when syscalls are being traced Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 03/11] perf trace: Warn when trying to resolve kernel addresses with kptr_restrict=1 Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 09/11] perf annotate: Sort list of recognised instructions Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 08/11] perf annotate: Fix identification of ARM blt and bls instructions Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 06/11] perf callchain: Stop validating callchains by the max_stack sysctl Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 01/11] perf tools: Find vdso supporting cross-platform analysis Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 07/11] perf tools: Fix usage of max_stack sysctl Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 11/11] perf tools: Set buildid dir under symfs when --symfs is provided Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  [PATCH 05/11] perf trace: Fix exit_group() formatting Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 00:30 +0200
  Re: [GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-20 17:10 +0200
    Re: [GIT PULL 00/11] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-05-20 19:40 +0200

csiph-web