From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753479AbdFSCxW (ORCPT ); Sun, 18 Jun 2017 22:53:22 -0400 Received: from mga09.intel.com ([134.134.136.24]:36642 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753258AbdFSCxU (ORCPT ); Sun, 18 Jun 2017 22:53:20 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,359,1493708400"; d="scan'208";a="275825844" From: Jin Yao To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, Jin Yao Subject: [PATCH v2 2/3] perf util: Check for fused instruction Date: Mon, 19 Jun 2017 10:55:57 +0800 Message-Id: <1497840958-4759-3-git-send-email-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497840958-4759-1-git-send-email-yao.jin@linux.intel.com> References: <1497840958-4759-1-git-send-email-yao.jin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Macro fusion merges two instructions to a single micro-op. Intel core platform performs this hardware optimization under limited circumstances. For example, CMP + JCC can be "fused" and executed /retired together. While with sampling this can result in the sample sometimes being on the JCC and sometimes on the CMP. So for the fused instruction pair, they could be considered together. In general, the fused instruction pairs are: cmp/test/add/sub/and/inc/dec + jcc. This patch adds an x86-specific function which checks if 2 instructions are in a "fused" pair. For non-x86 arch, the function is just NULL. Change-log: ----------- v2: Remove the origial weak function. Arnaldo points out that doing it as a weak function that will be overridden by the host arch doesn't work. So now it's implemented as an arch-specific function. v1: Initial post Signed-off-by: Jin Yao --- tools/perf/arch/x86/annotate/instructions.c | 18 ++++++++++++++++++ tools/perf/util/annotate.c | 10 ++++++++++ tools/perf/util/annotate.h | 1 + 3 files changed, 29 insertions(+) diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/arch/x86/annotate/instructions.c index c1625f2..bc6272c 100644 --- a/tools/perf/arch/x86/annotate/instructions.c +++ b/tools/perf/arch/x86/annotate/instructions.c @@ -76,3 +76,21 @@ static struct ins x86__instructions[] = { { .name = "xbeginq", .ops = &jump_ops, }, { .name = "retq", .ops = &ret_ops, }, }; + +static bool x86__ins_is_fused(const char *ins1, const char *ins2) +{ + if (strstr(ins2, "jmp")) + return false; + + if ((strstr(ins1, "cmp") && !strstr(ins1, "xchg")) || + strstr(ins1, "test") || + strstr(ins1, "add") || + strstr(ins1, "sub") || + strstr(ins1, "and") || + strstr(ins1, "inc") || + strstr(ins1, "dec")) { + return true; + } + + return false; +} diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index f21a105..bb40158 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -48,6 +48,7 @@ struct arch { bool initialized; void *priv; int (*init)(struct arch *arch); + bool (*ins_is_fused)(const char *insn1, const char *insn2); struct { char comment_char; char skip_functions_char; @@ -129,6 +130,7 @@ static struct arch architectures[] = { .name = "x86", .instructions = x86__instructions, .nr_instructions = ARRAY_SIZE(x86__instructions), + .ins_is_fused = x86__ins_is_fused, .objdump = { .comment_char = '#', }, @@ -171,6 +173,14 @@ int ins__scnprintf(struct ins *ins, char *bf, size_t size, return ins__raw_scnprintf(ins, bf, size, ops); } +bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2) +{ + if (!arch || !arch->ins_is_fused) + return false; + + return arch->ins_is_fused(ins1, ins2); +} + static int call__parse(struct arch *arch, struct ins_operands *ops, struct map *map) { char *endptr, *tok, *name; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 2105503..eb6ec40 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -53,6 +53,7 @@ bool ins__is_jump(const struct ins *ins); bool ins__is_call(const struct ins *ins); bool ins__is_ret(const struct ins *ins); int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops); +bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2); struct annotation; -- 2.7.4