From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752692AbcETRql (ORCPT ); Fri, 20 May 2016 13:46:41 -0400 Received: from terminus.zytor.com ([198.137.202.10]:33690 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752013AbcETRq1 (ORCPT ); Fri, 20 May 2016 13:46:27 -0400 Date: Fri, 20 May 2016 10:45:41 -0700 From: tip-bot for Chris Ryder Message-ID: Cc: peterz@infradead.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, chris.ryder@arm.com, mark.rutland@arm.com, mingo@kernel.org, hpa@zytor.com, acme@redhat.com, alexander.shishkin@linux.intel.com, will.deacon@arm.com, pawel.moll@arm.com Reply-To: acme@redhat.com, alexander.shishkin@linux.intel.com, hpa@zytor.com, mingo@kernel.org, pawel.moll@arm.com, will.deacon@arm.com, peterz@infradead.org, mark.rutland@arm.com, chris.ryder@arm.com, linux-kernel@vger.kernel.org, tglx@linutronix.de In-Reply-To: <4268febaf32f47f322c166fb2fe98cfec7041e11.1463676839.git.chris.ryder@arm.com> References: <4268febaf32f47f322c166fb2fe98cfec7041e11.1463676839.git.chris.ryder@arm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf annotate: Sort list of recognised instructions Git-Commit-ID: 7e4c1498130d7b6c26e6669839af4c7e321c9fec X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7e4c1498130d7b6c26e6669839af4c7e321c9fec Gitweb: http://git.kernel.org/tip/7e4c1498130d7b6c26e6669839af4c7e321c9fec Author: Chris Ryder AuthorDate: Thu, 19 May 2016 17:59:46 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 20 May 2016 11:43:57 -0300 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 Acked-by: Pawel Moll Cc: Alexander Shishkin Cc: Mark Rutland Cc: Peter Zijlstra Cc: Will Deacon Link: http://lkml.kernel.org/r/4268febaf32f47f322c166fb2fe98cfec7041e11.1463676839.git.chris.ryder@arm.com Signed-off-by: Arnaldo Carvalho de Melo --- 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 3d9f2ca..7e5a1e8 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)